asynchronous - C Glib GIO - How to list files asynchronously -


i creating simple file viewer using gtk, , want load new directory asynchronously, prevent hanging whole program while loading.

in gio api there g_file_enumerator_next_files_async function, allows asynchronously load files in blocks. how can tell, when directory listing finished? here code sample of i'm came with:

static void add_file_callback(gobject *direnum,                 gasyncresult *result,                 gpointer user_data){     gerror *error = null;     glist *file_list = g_file_enumerator_next_files_finish(                     g_file_enumerator(direnum),                     result, &error);         if( file_list == null ){         g_critical("unable add files list, error: %s", error->message);      }     glist *next;     gfileinfo *info;     gtktreeiter iter;     dirlist *list = (dirlist*)user_data;     while(file_list){         ...add file list     } }   int read_dir(const gchar *path, dirlist *list){     g_assert(list != null && list->store != null);     gtktreeiter iter;     gtk_list_store_clear(list->store);      list->path = path;      gfile *dir = g_file_new_for_path(path);     gfileenumerator *dirent = g_file_enumerate_children(dir,                                         "*",                                         g_file_query_info_nofollow_symlinks,                                         null,                                         null);     while( true ){ /* <============================== when end? */         g_file_enumerator_next_files_async(dirent,                         block_size,                         g_priority_default,                         null,                         add_file_callback,                         list);     }     g_file_enumerator_close(dirent, null, null);     g_object_unref(dirent);     g_object_unref(dir);      return 0; } 

from this g_file_enumerator_next_files_async reference:

the callback can called less num_files files in case of error or @ end of enumerator.

so if number of files callback receives less block_size, know have error or no more files available.

if happens, set flag loop in read_dir checks.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -