void load_file_list() { static const char *patterns[] = { #ifdef ENABLE_MP3 ".+[mM][pP][aA23]$", #endif #ifdef ENABLE_VORBIS ".+[oO][gG][gGaA]$", #endif NULL }; gint count; /* clear the form in the edit tab */ et_unload_file(); sb_printf(_("Scanning...")); cursor_set_wait(); /* flush pending operations before we start */ while (gtk_events_pending()) gtk_main_iteration(); /* rebuild the file list */ if (file_list) { g_elist_free_data(file_list); file_list = NULL; } scan_progress_start(); file_list = fu_get_file_list(working_dir->str, patterns, scan_progress_callback, gtk_toggle_button_get_active(cb_recurse), TRUE); scan_progress_stop(); /* update the interface */ update_tree_view(file_list); count = g_elist_length(file_list); switch (count) { case 0: sb_printf(_("No files found.")); break; case 1: sb_printf(_("1 file found.")); break; default: sb_printf(_("%d files found."), count); break; } cursor_set_normal(); }
GEList *fu_get_file_list( const gchar *dir_path, const gchar **patterns, fu_progress_callback callback, gboolean recurse, gboolean sort ) { GEList *result; chdir(dir_path); if (!recurse) { result = aux_file_list(NULL, NULL, ".", patterns, sort); if (callback != NULL) callback(1, (int)result->length); } else { GEList *dir_stack; GHashTable *dir_memory; gchar *cur_dir; int dircount = 0; result = g_elist_new(); dir_stack = g_elist_new(); dir_memory = g_hash_table_new(file_uid_hash, file_uid_equal); g_elist_push(dir_stack, g_strdup(".")); while (g_elist_length(dir_stack) > 0) { cur_dir = g_elist_pop(dir_stack); g_elist_concat(result, aux_file_list(dir_stack, dir_memory, cur_dir, patterns, sort)); g_free(cur_dir); dircount++; if (callback != NULL) if (callback(dircount, (int)result->length)) break; } g_elist_free_data(dir_stack); g_hash_table_free(dir_memory, TRUE, FALSE); } return result; }