gimp r26387 - in branches/gimp-2-4: . app/widgets



Author: neo
Date: Tue Aug  5 16:12:23 2008
New Revision: 26387
URL: http://svn.gnome.org/viewvc/gimp?rev=26387&view=rev

Log:
2008-08-05  Sven Neumann  <sven gimp org>

	Merged from trunk:

	* app/gui/gimpdbusservice.[ch]: keep a queue of D-Bus requests 
and
	work on them one after another instead of handling them all in
	parallel. Complements the fix for bug #546426.



Modified:
   branches/gimp-2-4/ChangeLog
   branches/gimp-2-4/app/widgets/gimpdbusservice.c
   branches/gimp-2-4/app/widgets/gimpdbusservice.h

Modified: branches/gimp-2-4/app/widgets/gimpdbusservice.c
==============================================================================
--- branches/gimp-2-4/app/widgets/gimpdbusservice.c	(original)
+++ branches/gimp-2-4/app/widgets/gimpdbusservice.c	Tue Aug  5 16:12:23 2008
@@ -36,15 +36,42 @@
 #include "gimpuimanager.c"
 
 
+typedef struct
+{
+  Gimp     *gimp;
+  gchar    *uri;
+  gboolean  as_new;
+} OpenData;
+
+
 static void  gimp_dbus_service_class_init (GimpDBusServiceClass *klass);
 static void  gimp_dbus_service_init       (GimpDBusService      *service);
+static void  gimp_dbus_service_dispose    (GObject              *object);
+static void  gimp_dbus_service_finalize   (GObject              *object);
+
+static void  gimp_dbus_service_queue_open (GimpDBusService      *service,
+                                           const gchar          *uri,
+                                           gboolean              as_new);
+
+static OpenData * gimp_dbus_service_open_data_new  (GimpDBusService *service,
+                                                    const gchar     *uri,
+                                                    gboolean         as_new);
+static void       gimp_dbus_service_open_data_free (OpenData        *data);
+
 
 G_DEFINE_TYPE (GimpDBusService, gimp_dbus_service, G_TYPE_OBJECT)
 
+#define parent_class gimp_dbus_service_parent_class
+
 
 static void
 gimp_dbus_service_class_init (GimpDBusServiceClass *klass)
 {
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->dispose  = gimp_dbus_service_dispose;
+  object_class->finalize = gimp_dbus_service_finalize;
+
   dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (klass),
                                    &dbus_glib_gimp_object_info);
 }
@@ -52,6 +79,7 @@
 static void
 gimp_dbus_service_init (GimpDBusService *service)
 {
+  service->queue = g_queue_new ();
 }
 
 GObject *
@@ -68,42 +96,37 @@
   return G_OBJECT (service);
 }
 
-typedef struct
-{
-  Gimp     *gimp;
-  gchar    *uri;
-  gboolean  as_new;
-} IdleData;
-
-static IdleData *
-gimp_dbus_service_open_idle_new (GimpDBusService *service,
-                                 const gchar     *uri,
-                                 gboolean         as_new)
+static void
+gimp_dbus_service_dispose (GObject *object)
 {
-  IdleData *data = g_slice_new (IdleData);
+  GimpDBusService *service = GIMP_DBUS_SERVICE (object);
 
-  data->gimp   = g_object_ref (service->gimp);
-  data->uri    = g_strdup (uri);
-  data->as_new = as_new;
+  if (service->source)
+    {
+      g_source_remove (g_source_get_id (service->source));
+      service->source = NULL;
+    }
+
+  while (! g_queue_is_empty (service->queue))
+    {
+      gimp_dbus_service_open_data_free (g_queue_pop_head (service->queue));
+    }
 
-  return data;
+  G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
 static void
-gimp_dbus_service_open_idle_free (IdleData *data)
+gimp_dbus_service_finalize (GObject *object)
 {
-  g_object_unref (data->gimp);
-  g_free (data->uri);
+  GimpDBusService *service = GIMP_DBUS_SERVICE (object);
 
-  g_slice_free (IdleData, data);
-}
-
-static gboolean
-gimp_dbus_service_open_idle (IdleData *data)
-{
-  file_open_from_command_line (data->gimp, data->uri, data->as_new);
+  if (service->queue)
+    {
+      g_queue_free (service->queue);
+      service->queue = NULL;
+    }
 
-  return FALSE;
+  G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
 gboolean
@@ -116,10 +139,7 @@
   g_return_val_if_fail (uri != NULL, FALSE);
   g_return_val_if_fail (success != NULL, FALSE);
 
-  g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
-                   (GSourceFunc) gimp_dbus_service_open_idle,
-                   gimp_dbus_service_open_idle_new (service, uri, FALSE),
-                   (GDestroyNotify) gimp_dbus_service_open_idle_free);
+  gimp_dbus_service_queue_open (service, uri, FALSE);
 
   /*  The call always succeeds as it is handled in one way or another.
    *  Even presenting an error message is considered success ;-)
@@ -139,10 +159,7 @@
   g_return_val_if_fail (uri != NULL, FALSE);
   g_return_val_if_fail (success != NULL, FALSE);
 
-  g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
-                   (GSourceFunc) gimp_dbus_service_open_idle,
-                   gimp_dbus_service_open_idle_new (service, uri, TRUE),
-                   (GDestroyNotify) gimp_dbus_service_open_idle_free);
+  gimp_dbus_service_queue_open (service, uri, TRUE);
 
   /*  The call always succeeds as it is handled in one way or another.
    *  Even presenting an error message is considered success ;-)
@@ -170,5 +187,63 @@
   return TRUE;
 }
 
+static OpenData *
+gimp_dbus_service_open_data_new (GimpDBusService *service,
+                                 const gchar     *uri,
+                                 gboolean         as_new)
+{
+  OpenData *data = g_slice_new (OpenData);
+
+  data->gimp   = g_object_ref (service->gimp);
+  data->uri    = g_strdup (uri);
+  data->as_new = as_new;
+
+  return data;
+}
+
+static void
+gimp_dbus_service_open_data_free (OpenData *data)
+{
+  g_object_unref (data->gimp);
+  g_free (data->uri);
+
+  g_slice_free (OpenData, data);
+}
+
+static gboolean
+gimp_dbus_service_open_idle (GQueue *queue)
+{
+  OpenData *data = g_queue_pop_tail (queue);
+
+  if (data)
+    {
+      file_open_from_command_line (data->gimp, data->uri, data->as_new);
+      gimp_dbus_service_open_data_free (data);
+
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
+static void
+gimp_dbus_service_queue_open (GimpDBusService *service,
+                              const gchar     *uri,
+                              gboolean         as_new)
+{
+  g_queue_push_tail (service->queue,
+                     gimp_dbus_service_open_data_new (service, uri, as_new));
+
+  if (! service->source)
+    {
+      service->source = g_idle_source_new ();
+
+      g_source_set_callback (service->source,
+                             (GSourceFunc) gimp_dbus_service_open_idle,
+                             service->queue, NULL);
+      g_source_attach (service->source, NULL);
+      g_source_unref (service->source);
+    }
+}
 
 #endif /* HAVE_DBUS_GLIB */

Modified: branches/gimp-2-4/app/widgets/gimpdbusservice.h
==============================================================================
--- branches/gimp-2-4/app/widgets/gimpdbusservice.h	(original)
+++ branches/gimp-2-4/app/widgets/gimpdbusservice.h	Tue Aug  5 16:12:23 2008
@@ -46,6 +46,8 @@
   GObject  parent_instance;
 
   Gimp    *gimp;
+  GQueue  *queue;
+  GSource *source;
 };
 
 struct _GimpDBusServiceClass



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