[gthumb/ext] implemented catalog reordering
- From: Paolo Bacchilega <paobac src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gthumb/ext] implemented catalog reordering
- Date: Mon, 24 Aug 2009 16:40:02 +0000 (UTC)
commit b018ad9f4dbd05de00cf3b5bff5c3d2abadacf96
Author: Paolo Bacchilega <paobac src gnome org>
Date: Mon Aug 24 01:19:15 2009 +0200
implemented catalog reordering
extensions/catalogs/gth-catalog.c | 35 +++++++++++++++--------
extensions/catalogs/gth-catalog.h | 4 +-
extensions/catalogs/gth-file-source-catalogs.c | 36 ++++++++++++++---------
3 files changed, 47 insertions(+), 28 deletions(-)
---
diff --git a/extensions/catalogs/gth-catalog.c b/extensions/catalogs/gth-catalog.c
index 3b475a1..aedb730 100644
--- a/extensions/catalogs/gth-catalog.c
+++ b/extensions/catalogs/gth-catalog.c
@@ -319,7 +319,7 @@ gth_catalog_get_file_list (GthCatalog *catalog)
}
-void
+gboolean
gth_catalog_insert_file (GthCatalog *catalog,
int pos,
GFile *file)
@@ -327,25 +327,36 @@ gth_catalog_insert_file (GthCatalog *catalog,
GList *link;
link = g_list_find_custom (catalog->priv->file_list, file, (GCompareFunc) _g_file_cmp_uris);
- if (link == NULL)
- catalog->priv->file_list = g_list_insert (catalog->priv->file_list, g_file_dup (file), pos);
+ if (link != NULL)
+ return FALSE;
+
+ catalog->priv->file_list = g_list_insert (catalog->priv->file_list, g_file_dup (file), pos);
+
+ return TRUE;
}
-void
+int
gth_catalog_remove_file (GthCatalog *catalog,
GFile *file)
{
- GList *link;
+ GList *scan;
+ int i = 0;
- g_return_if_fail (file != NULL);
+ g_return_val_if_fail (catalog != NULL, -1);
+ g_return_val_if_fail (file != NULL, -1);
- link = g_list_find_custom (catalog->priv->file_list, file, (GCompareFunc) _g_file_cmp_uris);
- if (link != NULL) {
- catalog->priv->file_list = g_list_remove_link (catalog->priv->file_list, link);
- g_object_unref ((GFile *) link->data);
- g_list_free (link);
- }
+ for (scan = catalog->priv->file_list; scan; scan = scan->next, i++)
+ if (g_file_equal ((GFile *) scan->data, file))
+ break;
+
+ if (scan == NULL)
+ return -1;
+
+ catalog->priv->file_list = g_list_remove_link (catalog->priv->file_list, scan);
+ _g_object_list_unref (scan);
+
+ return i;
}
diff --git a/extensions/catalogs/gth-catalog.h b/extensions/catalogs/gth-catalog.h
index f0ad571..4774ff9 100644
--- a/extensions/catalogs/gth-catalog.h
+++ b/extensions/catalogs/gth-catalog.h
@@ -84,10 +84,10 @@ char * gth_catalog_to_data (GthCatalog *catalog,
void gth_catalog_set_file_list (GthCatalog *catalog,
GList *file_list);
GList * gth_catalog_get_file_list (GthCatalog *catalog);
-void gth_catalog_insert_file (GthCatalog *catalog,
+gboolean gth_catalog_insert_file (GthCatalog *catalog,
int pos,
GFile *file);
-void gth_catalog_remove_file (GthCatalog *catalog,
+int gth_catalog_remove_file (GthCatalog *catalog,
GFile *file);
void gth_catalog_list_async (GthCatalog *catalog,
const char *attributes,
diff --git a/extensions/catalogs/gth-file-source-catalogs.c b/extensions/catalogs/gth-file-source-catalogs.c
index f94f561..7dc179b 100644
--- a/extensions/catalogs/gth-file-source-catalogs.c
+++ b/extensions/catalogs/gth-file-source-catalogs.c
@@ -494,8 +494,6 @@ reorder_buffer_ready_cb (void *buffer,
g_free (buffer);
- reorder_data->callback (G_OBJECT (reorder_data->file_source), error, reorder_data->data);
-
parent = g_file_get_parent (reorder_data->destination->file);
files = g_list_append (NULL, reorder_data->destination->file);
gth_monitor_folder_changed (gth_main_get_default_monitor (),
@@ -503,6 +501,8 @@ reorder_buffer_ready_cb (void *buffer,
files,
GTH_MONITOR_EVENT_CHANGED);
+ reorder_data->callback (G_OBJECT (reorder_data->file_source), error, reorder_data->data);
+
g_list_free (files);
g_object_unref (parent);
reorder_data_free (reorder_data);
@@ -510,6 +510,25 @@ reorder_buffer_ready_cb (void *buffer,
static void
+reorder_catalog_list (GthCatalog *catalog,
+ GList *file_list,
+ int dest_pos)
+{
+ GList *scan;
+
+ for (scan = file_list; scan; scan = scan->next) {
+ int file_pos = gth_catalog_remove_file (catalog, (GFile *) scan->data);
+ if (file_pos < dest_pos)
+ dest_pos--;
+ }
+
+ for (scan = file_list; scan; scan = scan->next)
+ if (gth_catalog_insert_file (catalog, dest_pos, (GFile *) scan->data))
+ dest_pos++;
+}
+
+
+static void
reorder_catalog_ready_cb (GObject *object,
GError *error,
gpointer user_data)
@@ -527,18 +546,7 @@ reorder_catalog_ready_cb (GObject *object,
}
catalog = (GthCatalog *) object;
-
- /* FIXME: reorder the file list here */
-
- {
- GList *scan;
-
- for (scan = gth_catalog_get_file_list (catalog); scan; scan = scan->next) {
- GFile *file = scan->data;
-
- g_print ("==> %s\n", g_file_get_uri (file));
- }
- }
+ reorder_catalog_list (catalog, reorder_data->file_list, reorder_data->dest_pos);
buffer = gth_catalog_to_data (catalog, &buffer_size);
gio_file = gth_file_source_to_gio_file (reorder_data->file_source, reorder_data->destination->file);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]