Skip to content

Instantly share code, notes, and snippets.

@onlyshk
Created August 8, 2010 13:55
Show Gist options
  • Save onlyshk/514048 to your computer and use it in GitHub Desktop.
Save onlyshk/514048 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;
struct stat stbuf;
if( il->dir_path && 0 == strcmp( path, il->dir_path ) )
return TRUE;
image_list_close( il );
if( stat( path, &stbuf ) == -1 )
return FALSE;
GFile* file = g_file_new_for_path (path);
GFileEnumerator* enumerator;
GFileInfo *info;
const char* file_path = NULL;
il->dir_path = g_strdup( path );
il->mtime = stbuf.st_mtime;
enumerator = g_file_enumerate_children(file,"standard::name,standard::content-type",
G_FILE_QUERY_INFO_NONE,generator_cancellable, NULL);
while ((info = g_file_enumerator_next_file (enumerator, generator_cancellable, error)) != NULL)
{
const char* mime = g_file_info_get_content_type(info);
if ((((strcmp(mime,"image/png") == 0) || strcmp(mime,"image/jpeg") == 0)
|| strcmp(mime,"image/gif") == 0))
{
file_path = g_file_info_get_name (info);
g_static_mutex_lock (&il->mutex);
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->list = g_list_reverse( il->list );
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