[gthumb] GIO conversion of path_list_async functions, bug 525482
- From: Michael J. Chudobiak <mjc src gnome org>
- To: svn-commits-list gnome org
- Subject: [gthumb] GIO conversion of path_list_async functions, bug 525482
- Date: Tue, 2 Jun 2009 10:22:09 -0400 (EDT)
commit f03d938226cf76889a0ab3ec85ef35198341e7e2
Author: Marlodavampire <brooss teambb gmail com>
Date: Tue Jun 2 10:20:56 2009 -0400
GIO conversion of path_list_async functions, bug 525482
Move slow file classify code into an idle callback
Implement gcancellable for path list code
Remove GnomeVfsResult from PathListData
comments/formatting
---
libgthumb/file-utils.c | 165 +++++++++++++++++++++++++-----------------------
libgthumb/file-utils.h | 10 +--
src/gth-dir-list.c | 6 --
3 files changed, 91 insertions(+), 90 deletions(-)
diff --git a/libgthumb/file-utils.c b/libgthumb/file-utils.c
index dc348ee..798fbbb 100644
--- a/libgthumb/file-utils.c
+++ b/libgthumb/file-utils.c
@@ -79,13 +79,13 @@ path_list_data_new (void)
pli = g_new0 (PathListData, 1);
- pli->uri = NULL;
- pli->result = GNOME_VFS_OK;
+ pli->gfile = NULL;
+ pli->gfile_enum = NULL;
+ pli->cancelled = NULL;
pli->files = NULL;
pli->dirs = NULL;
pli->done_func = NULL;
pli->done_data = NULL;
- pli->interrupted = FALSE;
pli->hidden_files = NULL;
return pli;
@@ -97,8 +97,15 @@ path_list_data_free (PathListData *pli)
{
g_return_if_fail (pli != NULL);
- if (pli->uri != NULL)
- gnome_vfs_uri_unref (pli->uri);
+
+ if (pli->gfile != NULL)
+ g_object_unref (pli->gfile);
+
+ if (pli->gfile_enum != NULL)
+ g_object_unref (pli->gfile_enum);
+
+ if (pli->cancelled != NULL)
+ g_object_unref (pli->cancelled);
if (pli->files != NULL) {
g_list_foreach (pli->files, (GFunc) file_data_unref, NULL);
@@ -116,74 +123,80 @@ path_list_data_free (PathListData *pli)
g_free (pli);
}
-
-static void
-directory_load_cb (GnomeVFSAsyncHandle *handle,
- GnomeVFSResult result,
- GList *list,
- guint entries_read,
- gpointer data)
-{
- PathListData *pli;
- GList *node;
-
- pli = (PathListData *) data;
- pli->result = result;
-
- if (pli->interrupted) {
- gnome_vfs_async_cancel (handle);
- pli->interrupted = FALSE;
- path_list_data_free (pli);
- return;
- }
-
- for (node = list; node != NULL; node = node->next) {
- GnomeVFSFileInfo *info = node->data;
- GnomeVFSURI *full_uri = NULL;
- char *txt_uri;
- FileData *file;
-
- switch (info->type) {
- case GNOME_VFS_FILE_TYPE_REGULAR:
- if (g_hash_table_lookup (pli->hidden_files, info->name) != NULL)
- break;
- full_uri = gnome_vfs_uri_append_file_name (pli->uri, info->name);
- txt_uri = gnome_vfs_uri_to_string (full_uri, GNOME_VFS_URI_HIDE_NONE);
-
- file = file_data_new (txt_uri);
- file_data_update_mime_type (file, pli->fast_file_type);
+/* This function should be called by g_idle_add().
+ * It will add ITEMS_PER_NOTIFICATION per call to pli->files
+ * and return TRUE until all files are add or
+ * pli->cancelled is cancelled.
+ * On completion pli->done_func (gth_dir_list_change_to__step2)
+ * is called and FALSE is returned.
+ */
+gboolean
+path_list_classify_files_cb (gpointer data)
+{
+ GFile *child=NULL;
+ GFileInfo *info;
+ GError *error=NULL;
+ char *uri_txt;
+ FileData *file;
+
+ int count=0;
+ PathListData *pli = (PathListData *) data;
+ info = g_file_enumerator_next_file (pli->gfile_enum, NULL, &error);
+ while ((!(info == NULL)) && !g_cancellable_is_cancelled(pli->cancelled)) {
+ count++;
+ switch (g_file_info_get_file_type (info)) {
+ case G_FILE_TYPE_REGULAR:
+ child = g_file_get_child (pli->gfile, g_file_info_get_name (info));
+ uri_txt = g_file_get_uri (child);
+ file = file_data_new (uri_txt);
if ((pli->filter_func != NULL) && pli->filter_func (pli, file, pli->filter_data))
pli->files = g_list_prepend (pli->files, file);
else
- file_data_unref (file);
- g_free (txt_uri);
+ file_data_unref (file);
+ g_free (uri_txt);
+ g_object_unref (child);
break;
-
- case GNOME_VFS_FILE_TYPE_DIRECTORY:
- if (SPECIAL_DIR (info->name))
- break;
- if (g_hash_table_lookup (pli->hidden_files, info->name) != NULL)
- break;
- full_uri = gnome_vfs_uri_append_path (pli->uri, info->name);
- pli->dirs = g_list_prepend (pli->dirs, gnome_vfs_uri_to_string (full_uri, GNOME_VFS_URI_HIDE_NONE));
+ case G_FILE_TYPE_DIRECTORY:
+ child = g_file_get_child (pli->gfile, g_file_info_get_name (info));
+ uri_txt = g_file_get_uri (child);
+ pli->dirs = g_list_prepend (pli->dirs, uri_txt);
+ g_object_unref (child);
break;
-
default:
break;
}
- if (full_uri)
- gnome_vfs_uri_unref (full_uri);
+ if (count == ITEMS_PER_NOTIFICATION)
+ return TRUE;
+ else
+ info = g_file_enumerator_next_file (pli->gfile_enum, NULL, &error);
}
-
- if ((result == GNOME_VFS_ERROR_EOF) || (result != GNOME_VFS_OK)) {
- if (pli->done_func) {
- /* pli is deallocated in pli->done_func */
- pli->done_func (pli, pli->done_data);
- return;
- }
- path_list_data_free (pli);
+
+ if (pli->done_func) {
+
+ /* pli is deallocated in pli->done_func */
+ pli->done_func (pli, pli->done_data);
+ return FALSE;
}
+ path_list_data_free (pli);
+ return FALSE;
+}
+
+
+static void
+directory_load_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer data)
+{
+ PathListData *pli;
+ pli = (PathListData *) data;
+ GError *error = NULL;
+
+ pli->gfile_enum = g_file_enumerate_children_finish (pli->gfile, res, &error);
+
+ g_cancellable_reset (pli->cancelled);
+ g_idle_add (path_list_classify_files_cb, pli);
+
}
@@ -195,7 +208,6 @@ path_list_async_new (const char *uri,
PathListDoneFunc done_func,
gpointer done_data)
{
- GnomeVFSAsyncHandle *handle;
PathListData *pli;
PathListHandle *pl_handle;
@@ -206,9 +218,9 @@ path_list_async_new (const char *uri,
}
pli = path_list_data_new ();
+ pli->gfile = gfile_new (uri);
- pli->uri = new_uri_from_path (uri);
- if (pli->uri == NULL) {
+ if (pli->gfile == NULL) {
path_list_data_free (pli);
if (done_func != NULL)
(done_func) (NULL, done_data);
@@ -221,17 +233,15 @@ path_list_async_new (const char *uri,
pli->done_func = done_func;
pli->done_data = done_data;
pli->fast_file_type = fast_file_type;
-
- gnome_vfs_async_load_directory_uri (&handle,
- pli->uri,
- GNOME_VFS_FILE_INFO_FOLLOW_LINKS,
- ITEMS_PER_NOTIFICATION,
- GNOME_VFS_PRIORITY_DEFAULT,
- directory_load_cb,
- pli);
-
+ pli->cancelled = g_cancellable_new();
+ g_file_enumerate_children_async (pli->gfile,
+ "*",
+ G_FILE_QUERY_INFO_NONE,
+ G_PRIORITY_DEFAULT,
+ pli->cancelled,
+ directory_load_cb,
+ pli);
pl_handle = g_new (PathListHandle, 1);
- pl_handle->vfs_handle = handle;
pl_handle->pli_data = pli;
return pl_handle;
@@ -241,7 +251,7 @@ path_list_async_new (const char *uri,
void
path_list_async_interrupt (PathListHandle *handle)
{
- handle->pli_data->interrupted = TRUE;
+ g_cancellable_cancel (handle->pli_data->cancelled);
g_free (handle);
}
@@ -1476,8 +1486,7 @@ new_uri_from_path (const char *path)
return uri;
}
-
-
+
static char *
build_uri_2 (const char *s1,
const char *s2)
diff --git a/libgthumb/file-utils.h b/libgthumb/file-utils.h
index 45ae4f8..b7724f6 100644
--- a/libgthumb/file-utils.h
+++ b/libgthumb/file-utils.h
@@ -48,23 +48,20 @@ typedef gboolean (*PathListFilterFunc) (PathListData *pld, FileData *, gpointer
typedef void (*PathListDoneFunc) (PathListData *pld, gpointer data);
struct _PathListData {
- GnomeVFSURI *uri;
- GnomeVFSResult result;
+ GFile *gfile;
+ GFileEnumerator *gfile_enum;
GList *files; /* char* items. */
GList *dirs; /* char* items. */
PathListFilterFunc filter_func;
gpointer filter_data;
PathListDoneFunc done_func;
gpointer done_data;
- DoneFunc interrupt_func;
- gpointer interrupt_data;
- gboolean interrupted;
+ GCancellable *cancelled;
GHashTable *hidden_files;
gboolean fast_file_type;
};
typedef struct {
- GnomeVFSAsyncHandle *vfs_handle;
PathListData *pli_data;
} PathListHandle;
@@ -76,6 +73,7 @@ PathListHandle * path_list_async_new (const char *uri,
PathListDoneFunc done_func,
gpointer done_data);
void path_list_async_interrupt (PathListHandle *handle);
+gboolean path_list_classify_files_cb (gpointer data);
gboolean path_list_new (const char *path,
GList **files,
GList **dirs);
diff --git a/src/gth-dir-list.c b/src/gth-dir-list.c
index 65ef47f..9115f59 100644
--- a/src/gth-dir-list.c
+++ b/src/gth-dir-list.c
@@ -462,12 +462,6 @@ gth_dir_list_change_to__step2 (PathListData *pld,
dir_list->dir_load_handle = NULL;
}
- if (pld->result != GNOME_VFS_ERROR_EOF) {
- path_list_data_free (pld);
- g_signal_emit (dir_list, gth_dir_list_signals[DONE], 0, pld->result);
- return;
- }
-
/* Update path data. */
if (dir_list->old_dir != NULL) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]