[gthumb] monitor: use a more fine grained way to pause and resume notifications



commit 2950ef003bfac282ca47d45ac646d61b62c233b9
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Wed Jul 20 14:35:45 2011 +0200

    monitor: use a more fine grained way to pause and resume notifications

 extensions/edit_metadata/dlg-edit-metadata.c |   30 ++++++-
 gthumb/gth-main.c                            |    2 +-
 gthumb/gth-monitor.c                         |  119 +++++++++++++++++---------
 gthumb/gth-monitor.h                         |    6 +-
 4 files changed, 109 insertions(+), 48 deletions(-)
---
diff --git a/extensions/edit_metadata/dlg-edit-metadata.c b/extensions/edit_metadata/dlg-edit-metadata.c
index 11d7c1c..d0953f5 100644
--- a/extensions/edit_metadata/dlg-edit-metadata.c
+++ b/extensions/edit_metadata/dlg-edit-metadata.c
@@ -53,20 +53,32 @@ save_file_data_task_completed_cb (GthTask  *task,
 	GthMonitor *monitor;
 	GList      *scan;
 
-	gth_monitor_resume (gth_main_get_default_monitor ());
+	monitor = gth_main_get_default_monitor ();
+	for (scan = data->file_list; scan; scan = scan->next) {
+		GthFileData *file_data = scan->data;
+		GFile       *parent;
+
+		parent = g_file_get_parent (file_data->file);
+		if (G_LIKELY (parent != NULL)) {
+			gth_monitor_resume (monitor, parent);
+			g_object_unref (parent);
+		}
+	}
 
 	if (error != NULL) {
 		_gtk_error_dialog_from_gerror_show (GTK_WINDOW (data->dialog), _("Could not save the file metadata"), error);
 		return;
 	}
 
-	monitor = gth_main_get_default_monitor ();
 	for (scan = data->file_list; scan; scan = scan->next) {
 		GthFileData *file_data = scan->data;
 		GFile       *parent;
 		GList       *files;
 
 		parent = g_file_get_parent (file_data->file);
+		if (G_UNLIKELY (parent == NULL))
+			continue;
+
 		files = g_list_prepend (NULL, g_object_ref (file_data->file));
 		gth_monitor_folder_changed (monitor, parent, files, GTH_MONITOR_EVENT_CHANGED);
 		gth_monitor_metadata_changed (monitor, file_data);
@@ -85,6 +97,8 @@ edit_metadata_dialog__response_cb (GtkDialog *dialog,
 				   gpointer   user_data)
 {
 	DialogData *data = user_data;
+	GthMonitor *monitor;
+	GList      *scan;
 	GthTask    *task;
 
 	if (response != GTK_RESPONSE_OK) {
@@ -92,7 +106,17 @@ edit_metadata_dialog__response_cb (GtkDialog *dialog,
 		return;
 	}
 
-	gth_monitor_pause (gth_main_get_default_monitor ());
+	monitor = gth_main_get_default_monitor ();
+	for (scan = data->file_list; scan; scan = scan->next) {
+		GthFileData *file_data = scan->data;
+		GFile       *parent;
+
+		parent = g_file_get_parent (file_data->file);
+		if (G_LIKELY (parent != NULL)) {
+			gth_monitor_pause (monitor, parent);
+			g_object_unref (parent);
+		}
+	}
 
 	gth_edit_metadata_dialog_update_info (GTH_EDIT_METADATA_DIALOG (data->dialog), data->file_list);
 
diff --git a/gthumb/gth-main.c b/gthumb/gth-main.c
index 0f0dbe5..593e00d 100644
--- a/gthumb/gth-main.c
+++ b/gthumb/gth-main.c
@@ -1184,7 +1184,7 @@ gth_main_tags_changed (void)
 GthMonitor *
 gth_main_get_default_monitor (void)
 {
-	if (Main->priv->monitor != NULL)
+	if (G_LIKELY (Main->priv->monitor != NULL))
 		return Main->priv->monitor;
 
 	Main->priv->monitor = gth_monitor_new ();
diff --git a/gthumb/gth-monitor.c b/gthumb/gth-monitor.c
index b440517..3b3c342 100644
--- a/gthumb/gth-monitor.c
+++ b/gthumb/gth-monitor.c
@@ -45,7 +45,8 @@ enum {
 
 
 struct _GthMonitorPrivateData {
-	gboolean active;
+	gboolean    active;
+	GHashTable *paused_files;
 };
 
 
@@ -56,21 +57,20 @@ static guint monitor_signals[LAST_SIGNAL] = { 0 };
 static void
 gth_monitor_finalize (GObject *object)
 {
-	GthMonitor *monitor = GTH_MONITOR (object);
+	GthMonitor *self = GTH_MONITOR (object);
 
-	if (monitor->priv != NULL) {
-		g_free (monitor->priv);
-		monitor->priv = NULL;
-	}
+	g_hash_table_unref (self->priv->paused_files);
 
 	G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 
 static void
-gth_monitor_init (GthMonitor *monitor)
+gth_monitor_init (GthMonitor *self)
 {
-	monitor->priv = g_new0 (GthMonitorPrivateData, 1);
+	self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTH_TYPE_MONITOR, GthMonitorPrivateData);
+	self->priv->active = TRUE;
+	self->priv->paused_files = g_hash_table_new_full (g_file_hash, (GEqualFunc) g_file_equal, g_object_unref, NULL);
 }
 
 
@@ -80,6 +80,7 @@ gth_monitor_class_init (GthMonitorClass *class)
 	GObjectClass  *gobject_class;
 
 	parent_class = g_type_class_peek_parent (class);
+	g_type_class_add_private (class, sizeof (GthMonitorPrivateData));
 
 	gobject_class = (GObjectClass*) class;
 	gobject_class->finalize = gth_monitor_finalize;
@@ -213,72 +214,94 @@ gth_monitor_new (void)
 
 
 void
-gth_monitor_pause (GthMonitor *monitor)
+gth_monitor_pause (GthMonitor *self,
+		   GFile      *file)
 {
-	monitor->priv->active = FALSE;
+	int n;
+
+	g_return_if_fail (file != NULL);
+
+	n = GPOINTER_TO_INT (g_hash_table_lookup (self->priv->paused_files, file));
+	n += 1;
+	g_hash_table_insert (self->priv->paused_files, g_object_ref (file), GINT_TO_POINTER (n));
 }
 
 
 void
-gth_monitor_resume (GthMonitor *monitor)
+gth_monitor_resume (GthMonitor *self,
+		    GFile      *file)
 {
-	monitor->priv->active = TRUE;
+	int n;
+
+	g_return_if_fail (file != NULL);
+
+	n = GPOINTER_TO_INT (g_hash_table_lookup (self->priv->paused_files, file));
+	if (n == 0)
+		return;
+	n -= 1;
+	if (n > 0)
+		g_hash_table_insert (self->priv->paused_files, g_object_ref (file), GINT_TO_POINTER (n));
+	else
+		g_hash_table_remove (self->priv->paused_files, file);
 }
 
 
 void
-gth_monitor_icon_theme_changed (GthMonitor *monitor)
+gth_monitor_icon_theme_changed (GthMonitor *self)
 {
-	g_return_if_fail (GTH_IS_MONITOR (monitor));
+	g_return_if_fail (GTH_IS_MONITOR (self));
 
-	g_signal_emit (G_OBJECT (monitor),
+	g_signal_emit (G_OBJECT (self),
 		       monitor_signals[ICON_THEME_CHANGED],
 		       0);
 }
 
 
 void
-gth_monitor_bookmarks_changed (GthMonitor *monitor)
+gth_monitor_bookmarks_changed (GthMonitor *self)
 {
-	g_return_if_fail (GTH_IS_MONITOR (monitor));
+	g_return_if_fail (GTH_IS_MONITOR (self));
 
-	g_signal_emit (G_OBJECT (monitor),
+	g_signal_emit (G_OBJECT (self),
 		       monitor_signals[BOOKMARKS_CHANGED],
 		       0);
 }
 
 
 void
-gth_monitor_filters_changed (GthMonitor *monitor)
+gth_monitor_filters_changed (GthMonitor *self)
 {
-	g_return_if_fail (GTH_IS_MONITOR (monitor));
+	g_return_if_fail (GTH_IS_MONITOR (self));
 
-	g_signal_emit (G_OBJECT (monitor),
+	g_signal_emit (G_OBJECT (self),
 		       monitor_signals[FILTERS_CHANGED],
 		       0);
 }
 
 
 void
-gth_monitor_tags_changed (GthMonitor *monitor)
+gth_monitor_tags_changed (GthMonitor *self)
 {
-	g_return_if_fail (GTH_IS_MONITOR (monitor));
+	g_return_if_fail (GTH_IS_MONITOR (self));
 
-	g_signal_emit (G_OBJECT (monitor),
+	g_signal_emit (G_OBJECT (self),
 		       monitor_signals[TAGS_CHANGED],
 		       0);
 }
 
 
 void
-gth_monitor_folder_changed (GthMonitor      *monitor,
+gth_monitor_folder_changed (GthMonitor      *self,
 			    GFile           *parent,
 			    GList           *list,
 			    GthMonitorEvent  event)
 {
-	g_return_if_fail (GTH_IS_MONITOR (monitor));
+	g_return_if_fail (GTH_IS_MONITOR (self));
+
+	if (g_hash_table_lookup (self->priv->paused_files, parent) != NULL)
+		return;
 
-	g_signal_emit (G_OBJECT (monitor),
+	g_signal_emit (G_OBJECT (self),
 		       monitor_signals[FOLDER_CONTENT_CHANGED],
 		       0,
 		       parent,
@@ -289,14 +312,17 @@ gth_monitor_folder_changed (GthMonitor      *monitor,
 
 
 void
-gth_monitor_files_created_with_pos (GthMonitor *monitor,
+gth_monitor_files_created_with_pos (GthMonitor *self,
 				    GFile      *parent,
 				    GList      *list, /* GFile list */
 				    int         position)
 {
-	g_return_if_fail (GTH_IS_MONITOR (monitor));
+	g_return_if_fail (GTH_IS_MONITOR (self));
 
-	g_signal_emit (G_OBJECT (monitor),
+	if (g_hash_table_lookup (self->priv->paused_files, parent) != NULL)
+		return;
+
+	g_signal_emit (G_OBJECT (self),
 		       monitor_signals[FOLDER_CONTENT_CHANGED],
 		       0,
 		       parent,
@@ -307,13 +333,16 @@ gth_monitor_files_created_with_pos (GthMonitor *monitor,
 
 
 void
-gth_monitor_file_renamed (GthMonitor *monitor,
+gth_monitor_file_renamed (GthMonitor *self,
 			  GFile      *file,
 			  GFile      *new_file)
 {
-	g_return_if_fail (GTH_IS_MONITOR (monitor));
+	g_return_if_fail (GTH_IS_MONITOR (self));
+
+	if (g_hash_table_lookup (self->priv->paused_files, file) != NULL)
+		return;
 
-	g_signal_emit (G_OBJECT (monitor),
+	g_signal_emit (G_OBJECT (self),
 		       monitor_signals[FILE_RENAMED],
 		       0,
 		       file,
@@ -322,12 +351,15 @@ gth_monitor_file_renamed (GthMonitor *monitor,
 
 
 void
-gth_monitor_metadata_changed (GthMonitor  *monitor,
+gth_monitor_metadata_changed (GthMonitor  *self,
 			      GthFileData *file_data)
 {
-	g_return_if_fail (GTH_IS_MONITOR (monitor));
+	g_return_if_fail (GTH_IS_MONITOR (self));
 
-	g_signal_emit (G_OBJECT (monitor),
+	if (g_hash_table_lookup (self->priv->paused_files, file_data->file) != NULL)
+		return;
+
+	g_signal_emit (G_OBJECT (self),
 		       monitor_signals[METADATA_CHANGED],
 		       0,
 		       file_data);
@@ -335,24 +367,27 @@ gth_monitor_metadata_changed (GthMonitor  *monitor,
 
 
 void
-gth_monitor_file_entry_points_changed (GthMonitor *monitor)
+gth_monitor_file_entry_points_changed (GthMonitor *self)
 {
-	g_return_if_fail (GTH_IS_MONITOR (monitor));
+	g_return_if_fail (GTH_IS_MONITOR (self));
 
-	g_signal_emit (G_OBJECT (monitor),
+	g_signal_emit (G_OBJECT (self),
 		       monitor_signals[ENTRY_POINTS_CHANGED],
 		       0);
 }
 
 
 void
-gth_monitor_order_changed (GthMonitor *monitor,
+gth_monitor_order_changed (GthMonitor *self,
 			   GFile      *file,
 			   int        *new_order)
 {
-	g_return_if_fail (GTH_IS_MONITOR (monitor));
+	g_return_if_fail (GTH_IS_MONITOR (self));
+
+	if (g_hash_table_lookup (self->priv->paused_files, file) != NULL)
+		return;
 
-	g_signal_emit (G_OBJECT (monitor),
+	g_signal_emit (G_OBJECT (self),
 		       monitor_signals[ORDER_CHANGED],
 		       0,
 		       file,
diff --git a/gthumb/gth-monitor.h b/gthumb/gth-monitor.h
index dd40995..246a39f 100644
--- a/gthumb/gth-monitor.h
+++ b/gthumb/gth-monitor.h
@@ -81,8 +81,10 @@ struct _GthMonitorClass
 
 GType         gth_monitor_get_type                   (void);
 GthMonitor *  gth_monitor_new                        (void);
-void          gth_monitor_pause                      (GthMonitor      *monitor);
-void          gth_monitor_resume                     (GthMonitor      *monitor);
+void          gth_monitor_pause                      (GthMonitor      *monitor,
+						      GFile           *file);
+void          gth_monitor_resume                     (GthMonitor      *monitor,
+						      GFile           *file);
 void          gth_monitor_icon_theme_changed         (GthMonitor      *monitor);
 void          gth_monitor_bookmarks_changed          (GthMonitor      *monitor);
 void          gth_monitor_filters_changed            (GthMonitor      *monitor);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]