Skip to content

Instantly share code, notes, and snippets.

@onlyshk
Created August 13, 2010 14:49
Show Gist options
  • Save onlyshk/522999 to your computer and use it in GitHub Desktop.
Save onlyshk/522999 to your computer and use it in GitHub Desktop.
gboolean image_list_open_dir( ImageList* il, const char* path,
GCancellable* generator_cancellable, GError** error )
{
const char* name = NULL;
if( il->dir_path && 0 == strcmp( path, il->dir_path ) )
return TRUE;
image_list_close( il );
GFile* file = g_file_new_for_path (path);
GFileEnumerator* enumerator;
GFileInfo *info;
const char* file_path;
const char* mime;
il->dir_path = g_strdup( path );
enumerator = g_file_enumerate_children(file,"standard::name,standard::content-type",
G_FILE_QUERY_INFO_NONE,generator_cancellable, NULL);
if (enumerator == NULL)
{
g_object_unref (file);
g_object_unref (enumerator);
g_object_unref (info);
return FALSE;
}
while ((info = g_file_enumerator_next_file (enumerator, generator_cancellable, error)) != NULL)
{
mime = g_file_info_get_content_type(info);
if (image_list_is_file_supported(mime))
{
g_static_mutex_lock (&il->mutex);
file_path = g_file_info_get_name (info);
il->list = g_list_insert_sorted( il->list, g_strdup(file_path), (GCompareFunc)comp_by_name);
g_static_mutex_unlock (&il->mutex);
}
g_object_unref(info);
}
il->current = il->list;
g_object_unref (file);
g_object_unref (enumerator);
return TRUE;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment