[gthumb] allow to rename the files in a catalog
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] allow to rename the files in a catalog
- Date: Sun, 5 Dec 2010 17:24:03 +0000 (UTC)
commit 4d9de164d3e02b6fc1c816ecb406e59c18dc5c70
Author: Paolo Bacchilega <paobac src gnome org>
Date: Sun Dec 5 16:34:43 2010 +0100
allow to rename the files in a catalog
[new feature]
extensions/catalogs/callbacks.c | 160 ++++++++++++++++++++++++++++++++++
extensions/catalogs/callbacks.h | 3 +
extensions/catalogs/main.c | 1 +
extensions/file_manager/callbacks.c | 2 +-
extensions/rename_series/callbacks.c | 56 ++----------
extensions/rename_series/callbacks.h | 8 +--
extensions/rename_series/main.c | 2 -
gthumb/gth-browser.c | 4 +-
gthumb/gth-file-source.c | 6 +-
gthumb/gth-file-source.h | 2 +-
gthumb/gth-main-default-hooks.c | 9 ++
11 files changed, 191 insertions(+), 62 deletions(-)
---
diff --git a/extensions/catalogs/callbacks.c b/extensions/catalogs/callbacks.c
index d5cb1e9..22ebfd8 100644
--- a/extensions/catalogs/callbacks.c
+++ b/extensions/catalogs/callbacks.c
@@ -34,6 +34,7 @@
#define BROWSER_DATA_KEY "catalogs-browser-data"
#define _RESPONSE_PROPERTIES 1
#define _RESPONSE_ORGANIZE 2
+#define UPDATE_RENAMED_FILES_DELAY 500
static const char *fixed_ui_info =
@@ -154,9 +155,14 @@ typedef struct {
guint monitor_events;
GtkWidget *properties_button;
GtkWidget *organize_button;
+ guint update_renamed_files_id;
+ GList *rename_data_list;
} BrowserData;
+static void rename_data_list_free (BrowserData *data);
+
+
static void
browser_data_free (BrowserData *data)
{
@@ -164,6 +170,12 @@ browser_data_free (BrowserData *data)
g_signal_handler_disconnect (gth_main_get_default_monitor (), data->monitor_events);
data->monitor_events = 0;
}
+ if (data->update_renamed_files_id != 0) {
+ g_source_remove (data->update_renamed_files_id);
+ data->update_renamed_files_id = 0;
+ }
+ rename_data_list_free (data);
+
g_free (data);
}
@@ -705,3 +717,151 @@ catalogs__gth_browser_update_extra_widget_cb (GthBrowser *browser)
}
}
}
+
+
+/* -- catalogs__gth_browser_file_renamed_cb -- */
+
+
+typedef struct {
+ GFile *location;
+ GList *files;
+ GList *new_files;
+} RenameData;
+
+
+static RenameData *
+rename_data_new (GFile *location)
+{
+ RenameData *rename_data;
+
+ rename_data = g_new0 (RenameData, 1);
+ rename_data->location = g_file_dup (location);
+
+ return rename_data;
+}
+
+
+static void
+rename_data_free (RenameData *rename_data)
+{
+ _g_object_list_unref (rename_data->files);
+ _g_object_list_unref (rename_data->new_files);
+ g_object_unref (rename_data->location);
+ g_free (rename_data);
+}
+
+
+static void
+rename_data_list_free (BrowserData *data)
+{
+ g_list_foreach (data->rename_data_list, (GFunc) rename_data_free, NULL);
+ g_list_free (data->rename_data_list);
+ data->rename_data_list = NULL;
+}
+
+
+static gboolean
+process_rename_data_list (gpointer user_data)
+{
+ BrowserData *data = user_data;
+ GList *scan;
+
+ g_source_remove (data->update_renamed_files_id);
+ data->update_renamed_files_id = 0;
+
+ for (scan = data->rename_data_list; scan; scan = scan->next) {
+ RenameData *rename_data = scan->data;
+ GthCatalog *catalog;
+ GList *scan_files;
+ GList *scan_new_files;
+ GFile *gio_file;
+ char *catalog_data;
+ gsize catalog_data_size;
+ GError *error = NULL;
+
+ catalog = gth_catalog_load_from_file (rename_data->location);
+
+ for (scan_files = rename_data->files, scan_new_files = rename_data->new_files;
+ scan_files && scan_new_files;
+ scan_files = scan_files->next, scan_new_files = scan_new_files->next)
+ {
+ GFile *file = scan_files->data;
+ GFile *new_file = scan_new_files->data;
+ int pos;
+
+ pos = gth_catalog_remove_file (catalog, file);
+ gth_catalog_insert_file (catalog, new_file, pos);
+ }
+
+ gio_file = gth_catalog_file_to_gio_file (rename_data->location);
+ catalog_data = gth_catalog_to_data (catalog, &catalog_data_size);
+ if (! g_write_file (gio_file,
+ FALSE,
+ G_FILE_CREATE_NONE,
+ catalog_data,
+ catalog_data_size,
+ NULL,
+ &error))
+ {
+ g_warning ("%s", error->message);
+ g_clear_error (&error);
+ }
+
+ g_free (catalog_data);
+ g_object_unref (gio_file);
+ g_object_unref (catalog);
+ }
+
+ rename_data_list_free (data);
+
+ return FALSE;
+}
+
+
+void
+catalogs__gth_browser_file_renamed_cb (GthBrowser *browser,
+ GFile *file,
+ GFile *new_file)
+{
+ GthFileStore *file_store;
+ BrowserData *data;
+ GFile *location;
+ GList *scan;
+ RenameData *rename_data;
+
+ if (! GTH_IS_FILE_SOURCE_CATALOGS (gth_browser_get_location_source (browser)))
+ return;
+
+ file_store = gth_browser_get_file_store (browser);
+ if (! gth_file_store_find (file_store, file, NULL))
+ return;
+
+ location = gth_browser_get_location (browser);
+ if (location == NULL)
+ return;
+
+ data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);
+
+ rename_data = NULL;
+ for (scan = data->rename_data_list; scan; scan = scan->next) {
+ RenameData *rename_data_scan = scan->data;
+ if (g_file_equal (rename_data_scan->location, location)) {
+ rename_data = rename_data_scan;
+ break;
+ }
+ }
+
+ if (rename_data == NULL) {
+ rename_data = rename_data_new (location);
+ data->rename_data_list = g_list_prepend (data->rename_data_list, rename_data);
+ }
+
+ rename_data->files = g_list_prepend (rename_data->files, g_file_dup (file));
+ rename_data->new_files = g_list_prepend (rename_data->new_files, g_file_dup (new_file));
+
+ if (data->update_renamed_files_id != 0)
+ g_source_remove (data->update_renamed_files_id);
+ data->update_renamed_files_id = g_timeout_add (UPDATE_RENAMED_FILES_DELAY,
+ process_rename_data_list,
+ data);
+}
diff --git a/extensions/catalogs/callbacks.h b/extensions/catalogs/callbacks.h
index bf81a92..6cb7f34 100644
--- a/extensions/catalogs/callbacks.h
+++ b/extensions/catalogs/callbacks.h
@@ -39,5 +39,8 @@ void catalogs__gth_browser_load_location_after_cb (GthBrowser *browse
GFile *location,
const GError *error);
void catalogs__gth_browser_update_extra_widget_cb (GthBrowser *browser);
+void catalogs__gth_browser_file_renamed_cb (GthBrowser *browser,
+ GFile *file,
+ GFile *new_file);
#endif /* CALLBACKS_H */
diff --git a/extensions/catalogs/main.c b/extensions/catalogs/main.c
index c7eb84b..cdc6663 100644
--- a/extensions/catalogs/main.c
+++ b/extensions/catalogs/main.c
@@ -119,6 +119,7 @@ gthumb_extension_activate (void)
gth_hook_add_callback ("gth-browser-folder-tree-popup-before", 10, G_CALLBACK (catalogs__gth_browser_folder_tree_popup_before_cb), NULL);
gth_hook_add_callback ("gth-browser-load-location-after", 10, G_CALLBACK (catalogs__gth_browser_load_location_after_cb), NULL);
gth_hook_add_callback ("gth-browser-update-extra-widget", 10, G_CALLBACK (catalogs__gth_browser_update_extra_widget_cb), NULL);
+ gth_hook_add_callback ("gth-browser-file-renamed", 10, G_CALLBACK (catalogs__gth_browser_file_renamed_cb), NULL);
}
diff --git a/extensions/file_manager/callbacks.c b/extensions/file_manager/callbacks.c
index d6fd923..db9fb42 100644
--- a/extensions/file_manager/callbacks.c
+++ b/extensions/file_manager/callbacks.c
@@ -487,7 +487,7 @@ void
fm__gth_browser_construct_cb (GthBrowser *browser)
{
BrowserData *data;
- GError *error;
+ GError *error = NULL;
GtkWidget *file_view;
g_return_if_fail (GTH_IS_BROWSER (browser));
diff --git a/extensions/rename_series/callbacks.c b/extensions/rename_series/callbacks.c
index 45350e1..1c50994 100644
--- a/extensions/rename_series/callbacks.c
+++ b/extensions/rename_series/callbacks.c
@@ -30,7 +30,7 @@
#define BROWSER_DATA_KEY "rename-series-browser-data"
-static const char *vfs_ui_info =
+static const char *fixed_ui_info =
"<ui>"
" <menubar name='MenuBar'>"
" <menu name='Edit' action='EditMenu'>"
@@ -52,7 +52,7 @@ static GtkActionEntry action_entries[] = {
typedef struct {
GtkActionGroup *action_group;
- guint vfs_merge_id;
+ guint fixed_merge_id;
} BrowserData;
@@ -79,6 +79,7 @@ void
rs__gth_browser_construct_cb (GthBrowser *browser)
{
BrowserData *data;
+ GError *error = NULL;
g_return_if_fail (GTH_IS_BROWSER (browser));
@@ -92,54 +93,13 @@ rs__gth_browser_construct_cb (GthBrowser *browser)
browser);
gtk_ui_manager_insert_action_group (gth_browser_get_ui_manager (browser), data->action_group, 0);
- g_object_set_data_full (G_OBJECT (browser), BROWSER_DATA_KEY, data, (GDestroyNotify) browser_data_free);
-}
-
-
-static void
-file_manager_update_ui (BrowserData *data,
- GthBrowser *browser)
-{
- if (GTH_IS_FILE_SOURCE_VFS (gth_browser_get_location_source (browser))) {
- if (data->vfs_merge_id == 0) {
- GError *local_error = NULL;
-
- data->vfs_merge_id = gtk_ui_manager_add_ui_from_string (gth_browser_get_ui_manager (browser), vfs_ui_info, -1, &local_error);
- if (data->vfs_merge_id == 0) {
- g_warning ("building ui failed: %s", local_error->message);
- g_error_free (local_error);
- }
- }
+ data->fixed_merge_id = gtk_ui_manager_add_ui_from_string (gth_browser_get_ui_manager (browser), fixed_ui_info, -1, &error);
+ if (data->fixed_merge_id == 0) {
+ g_warning ("building ui failed: %s", error->message);
+ g_error_free (error);
}
- else if (data->vfs_merge_id != 0) {
- gtk_ui_manager_remove_ui (gth_browser_get_ui_manager (browser), data->vfs_merge_id);
- data->vfs_merge_id = 0;
- }
-}
-
-
-void
-rs__gth_browser_set_current_page_cb (GthBrowser *browser)
-{
- BrowserData *data;
-
- data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);
- file_manager_update_ui (data, browser);
-}
-
-
-void
-rs__gth_browser_load_location_after_cb (GthBrowser *browser,
- GthFileData *location_data,
- const GError *error)
-{
- BrowserData *data;
- if ((location_data == NULL) || (error != NULL))
- return;
-
- data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);
- file_manager_update_ui (data, browser);
+ g_object_set_data_full (G_OBJECT (browser), BROWSER_DATA_KEY, data, (GDestroyNotify) browser_data_free);
}
diff --git a/extensions/rename_series/callbacks.h b/extensions/rename_series/callbacks.h
index b55a6d0..7598b52 100644
--- a/extensions/rename_series/callbacks.h
+++ b/extensions/rename_series/callbacks.h
@@ -24,11 +24,7 @@
#include <gthumb.h>
-void rs__gth_browser_construct_cb (GthBrowser *browser);
-void rs__gth_browser_set_current_page_cb (GthBrowser *browser);
-void rs__gth_browser_load_location_after_cb (GthBrowser *browser,
- GFile *location,
- GError *error);
-void rs__gth_browser_update_sensitivity_cb (GthBrowser *browser);
+void rs__gth_browser_construct_cb (GthBrowser *browser);
+void rs__gth_browser_update_sensitivity_cb (GthBrowser *browser);
#endif /* CALLBACKS_H */
diff --git a/extensions/rename_series/main.c b/extensions/rename_series/main.c
index 6fee814..d76a938 100644
--- a/extensions/rename_series/main.c
+++ b/extensions/rename_series/main.c
@@ -30,8 +30,6 @@ G_MODULE_EXPORT void
gthumb_extension_activate (void)
{
gth_hook_add_callback ("gth-browser-construct", 10, G_CALLBACK (rs__gth_browser_construct_cb), NULL);
- gth_hook_add_callback ("gth-browser-set-current-page", 10, G_CALLBACK (rs__gth_browser_set_current_page_cb), NULL);
- gth_hook_add_callback ("gth-browser-load-location-after", 10, G_CALLBACK (rs__gth_browser_load_location_after_cb), NULL);
gth_hook_add_callback ("gth-browser-update-sensitivity", 10, G_CALLBACK (rs__gth_browser_update_sensitivity_cb), NULL);
}
diff --git a/gthumb/gth-browser.c b/gthumb/gth-browser.c
index 9779acb..292ebd1 100644
--- a/gthumb/gth-browser.c
+++ b/gthumb/gth-browser.c
@@ -2966,13 +2966,15 @@ file_renamed_cb (GthMonitor *monitor,
RenameData *rename_data;
GList *list;
+ gth_hook_invoke ("gth-browser-file-renamed", browser, file, new_file);
+
rename_data = g_new0 (RenameData, 1);
rename_data->browser = browser;
rename_data->file_source = gth_main_get_file_source (new_file);
rename_data->file = g_file_dup (file);
rename_data->new_file = g_file_dup (new_file);
- list = g_list_prepend (NULL, new_file);
+ list = g_list_prepend (NULL, rename_data->new_file);
gth_file_source_read_attributes (rename_data->file_source,
list,
_gth_browser_get_list_attributes (browser, FALSE),
diff --git a/gthumb/gth-file-source.c b/gthumb/gth-file-source.c
index b31255d..6f80d2e 100644
--- a/gthumb/gth-file-source.c
+++ b/gthumb/gth-file-source.c
@@ -1093,14 +1093,14 @@ void
gth_file_source_rename (GthFileSource *file_source,
GFile *file,
GFile *new_file,
- ReadyCallback callback,
+ ReadyCallback ready_callback,
gpointer data)
{
if (gth_file_source_is_active (file_source)) {
- gth_file_source_queue_rename (file_source, file, new_file, callback, data);
+ gth_file_source_queue_rename (file_source, file, new_file, ready_callback, data);
return;
}
- GTH_FILE_SOURCE_GET_CLASS (G_OBJECT (file_source))->rename (file_source, file, new_file, callback, data);
+ GTH_FILE_SOURCE_GET_CLASS (G_OBJECT (file_source))->rename (file_source, file, new_file, ready_callback, data);
}
diff --git a/gthumb/gth-file-source.h b/gthumb/gth-file-source.h
index 84057c3..dbdd0d7 100644
--- a/gthumb/gth-file-source.h
+++ b/gthumb/gth-file-source.h
@@ -174,7 +174,7 @@ void gth_file_source_read_attributes (GthFileSource *file_sou
void gth_file_source_rename (GthFileSource *file_source,
GFile *file,
GFile *new_file,
- ReadyCallback ready_cb,
+ ReadyCallback ready_callback,
gpointer data);
void gth_file_source_copy (GthFileSource *file_source,
GthFileData *destination,
diff --git a/gthumb/gth-main-default-hooks.c b/gthumb/gth-main-default-hooks.c
index f7b4cc7..178a8cd 100644
--- a/gthumb/gth-main-default-hooks.c
+++ b/gthumb/gth-main-default-hooks.c
@@ -180,6 +180,15 @@ gth_main_register_default_hooks (void)
gth_hook_register ("gth-browser-update-extra-widget", 1);
/**
+ * Called when a file-renamed signal is received by a browser window.
+ *
+ * @browser (GthBrowser*): the window that received the signal.
+ * @file (GFile *): the file that was renamed.
+ * @new_file (GFile *): the new file.
+ */
+ gth_hook_register ("gth-browser-file-renamed", 3);
+
+ /**
* Called in _gdk_pixbuf_save_async
*
* @data (SavePixbufData*):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]