[Xfce4-commits] <xfce4-panel:devel> * Make dbus code work. Added a property change queue with is flushed when the external plugin is embedded.

Nick Schermer nick at xfce.org
Tue Aug 11 20:22:49 CEST 2009


Updating branch refs/heads/devel
         to 9177fcda2d222cbc2130de5129d21ddb7bad0de1 (commit)
       from 72702322d575d556cc8419c1943a07adafc4d7a3 (commit)

commit 9177fcda2d222cbc2130de5129d21ddb7bad0de1
Author: Nick Schermer <nick at xfce.org>
Date:   Sat Aug 9 19:25:05 2008 +0200

    * Make dbus code work. Added a property change queue
      with is flushed when the external plugin is embedded.

 panel/panel-application.c     |   21 -------
 panel/panel-dbus-service.c    |   15 +----
 panel/panel-module-factory.c  |   28 ++++++++-
 panel/panel-plugin-external.c |  134 ++++++++++++++++++++++++++++++++++-------
 panel/panel-private.c         |    1 +
 wrapper/main.c                |   22 +------
 6 files changed, 147 insertions(+), 74 deletions(-)

diff --git a/panel/panel-application.c b/panel/panel-application.c
index 15666b8..f5ae400 100644
--- a/panel/panel-application.c
+++ b/panel/panel-application.c
@@ -24,9 +24,6 @@
 #ifdef HAVE_STDLIB_H
 #include <stdlib.h>
 #endif
-#ifdef HAVE_TIME_H
-#include <time.h>
-#endif
 
 #include <exo/exo.h>
 #include <libxfce4util/libxfce4util.h>
@@ -224,20 +221,6 @@ panel_application_finalize (GObject *object)
 
 
 
-static const gchar *
-panel_application_get_unique_id (void)
-{
-  static gint  counter = 0;
-  static gchar id[30];
-
-  /* create a unique if of the current time and counter */
-  g_snprintf (id, sizeof (id), "%ld%d", time (NULL), counter++);
-
-  return id;
-}
-
-
-
 static void
 panel_application_load (PanelApplication *application)
 {
@@ -627,10 +610,6 @@ panel_application_plugin_insert (PanelApplication  *application,
   panel_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
   panel_return_val_if_fail (name != NULL, FALSE);
 
-  /* create a new unique id if needed */
-  if (id == NULL)
-    id = panel_application_get_unique_id ();
-
   /* create a new panel plugin */
   provider = panel_module_factory_create_plugin (application->factory, screen, name, id, arguments);
 
diff --git a/panel/panel-dbus-service.c b/panel/panel-dbus-service.c
index 2ca764f..b1717ca 100644
--- a/panel/panel-dbus-service.c
+++ b/panel/panel-dbus-service.c
@@ -344,24 +344,17 @@ panel_dbus_service_set_plugin_property (const gchar  *plugin_id,
                                         const GValue *value)
 {
   PanelDBusService *service;
-  GValue            dummy_value = { 0, };
   
-  /* create dummy value */
-  if (value == NULL)
-    g_value_init (&dummy_value, G_TYPE_INT);
+  panel_return_if_fail (plugin_id && *plugin_id != '\0');
+  panel_return_if_fail (property && *property != '\0');
+  panel_return_if_fail (value && G_TYPE_CHECK_VALUE (value));
   
   /* get the dbus service */
   service = panel_dbus_service_get ();
-  
-  g_message ("Set plugin '%s' property '%s'", plugin_id, property);
 
   /* emit the signal */
   g_signal_emit (G_OBJECT (service), dbus_service_signals[PROPERTY_CHANGED],
-                 0, plugin_id, property, value ? value : &dummy_value);
-
-  /* unset dummy value */
-  if (value == NULL)
-    g_value_unset (&dummy_value);
+                 0, plugin_id, property, value);
 
   /* release */
   g_object_unref (G_OBJECT (service));
diff --git a/panel/panel-module-factory.c b/panel/panel-module-factory.c
index 35e372c..52af740 100644
--- a/panel/panel-module-factory.c
+++ b/panel/panel-module-factory.c
@@ -25,6 +25,10 @@
 #include <string.h>
 #endif
 
+#ifdef HAVE_TIME_H
+#include <time.h>
+#endif
+
 #include <exo/exo.h>
 #include <libxfce4util/libxfce4util.h>
 #include <libxfce4panel/libxfce4panel.h>
@@ -61,7 +65,7 @@ struct _PanelModuleFactory
 
   /* hash table of loaded modules */
   GHashTable *modules;
-  
+
   /* table table with created panel plugins */
   GHashTable *plugins;
 
@@ -327,6 +331,21 @@ panel_module_factory_get_modules_foreach (gpointer key,
 #endif
 
 
+
+static const gchar *
+panel_module_factory_get_unique_id (void)
+{
+  static gint  counter = 0;
+  static gchar id[30];
+
+  /* create a unique if of the current time and counter */
+  g_snprintf (id, sizeof (id), "%ld%d", time (NULL), counter++);
+
+  return id;
+}
+
+
+
 GList *
 panel_module_factory_get_modules (PanelModuleFactory *factory)
 {
@@ -367,7 +386,7 @@ panel_module_factory_get_plugin (PanelModuleFactory *factory,
 {
   panel_return_val_if_fail (PANEL_IS_MODULE_FACTORY (factory), NULL);
   panel_return_val_if_fail (id != NULL, NULL);
-  
+
   return g_hash_table_lookup (factory->plugins, id);
 }
 
@@ -386,7 +405,6 @@ panel_module_factory_create_plugin (PanelModuleFactory  *factory,
   panel_return_val_if_fail (PANEL_IS_MODULE_FACTORY (factory), NULL);
   panel_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
   panel_return_val_if_fail (name != NULL, NULL);
-  panel_return_val_if_fail (id != NULL, NULL);
 
   /* find the module in the hash table */
   module = g_hash_table_lookup (factory->modules, name);
@@ -398,6 +416,10 @@ panel_module_factory_create_plugin (PanelModuleFactory  *factory,
       return NULL;
     }
 
+  /* make sure this plugin has a unique id */
+  while (id == NULL || g_hash_table_lookup (factory->plugins, id) != NULL)
+    id = panel_module_factory_get_unique_id ();
+
   /* create the new module */
   provider = panel_module_create_plugin (module, screen, name, id, arguments);
 
diff --git a/panel/panel-plugin-external.c b/panel/panel-plugin-external.c
index a571917..5dd50b8 100644
--- a/panel/panel-plugin-external.c
+++ b/panel/panel-plugin-external.c
@@ -45,6 +45,7 @@ static void         panel_plugin_external_finalize            (GObject
 static void         panel_plugin_external_realize             (GtkWidget                    *widget);
 static void         panel_plugin_external_unrealize           (GtkWidget                    *widget);
 static gboolean     panel_plugin_external_plug_removed        (GtkSocket                    *socket);
+static void         panel_plugin_external_plug_added          (GtkSocket                    *socket);
 static const gchar *panel_plugin_external_get_name            (XfcePanelPluginProvider      *provider);
 static const gchar *panel_plugin_external_get_id              (XfcePanelPluginProvider      *provider);
 static void         panel_plugin_external_set_size            (XfcePanelPluginProvider      *provider,
@@ -57,6 +58,7 @@ static void         panel_plugin_external_save                (XfcePanelPluginPr
 static void         panel_plugin_external_set_sensitive       (PanelPluginExternal          *external);
 
 
+
 struct _PanelPluginExternalClass
 {
   GtkSocketClass __parent__;
@@ -77,11 +79,20 @@ struct _PanelPluginExternal
 
   /* process pid */
   GPid              pid;
+  
+  /* whether the plug is embedded */
+  guint             plug_embedded : 1;
+  
+  /* dbus message queue */
+  GSList           *dbus_queue;
 };
 
-
-
-static GdkAtom message_atom = GDK_NONE;
+typedef struct
+{
+  const gchar *property;
+  GValue       value;
+}
+QueuedData;
 
 
 
@@ -106,9 +117,7 @@ panel_plugin_external_class_init (PanelPluginExternalClass *klass)
 
   gtksocket_class = GTK_SOCKET_CLASS (klass);
   gtksocket_class->plug_removed = panel_plugin_external_plug_removed;
-
-  /* initialize the global message atom */
-  message_atom = gdk_atom_intern_static_string ("XFCE_PANEL_PLUGIN");
+  gtksocket_class->plug_added = panel_plugin_external_plug_added;
 }
 
 
@@ -121,6 +130,8 @@ panel_plugin_external_init (PanelPluginExternal *external)
   external->module = NULL;
   external->arguments = NULL;
   external->pid = 0;
+  external->dbus_queue = NULL;
+  external->plug_embedded = FALSE;
 
   /* signal to pass gtk_widget_set_sensitive() changes to the remote window */
   g_signal_connect (G_OBJECT (external), "notify::sensitive", G_CALLBACK (panel_plugin_external_set_sensitive), NULL);
@@ -145,10 +156,21 @@ static void
 panel_plugin_external_finalize (GObject *object)
 {
   PanelPluginExternal *external = PANEL_PLUGIN_EXTERNAL (object);
+  GSList              *li;
+  QueuedData          *data;
 
   /* cleanup */
   g_free (external->id);
   g_strfreev (external->arguments);
+  
+  /* free the queue */
+  for (li = external->dbus_queue; li != NULL; li = li->next)
+    {
+      data = li->data;
+      g_value_unset (&data->value);
+      g_slice_free (QueuedData, data);
+    }
+  g_slist_free (external->dbus_queue);
 
   /* release the module */
   g_object_unref (G_OBJECT (external->module));
@@ -247,6 +269,9 @@ panel_plugin_external_plug_removed (GtkSocket *socket)
   gint                 response;
   gchar               *filename, *path;
   PanelWindow         *window;
+  
+  /* plug has been removed */
+  external->plug_embedded = FALSE;
 
   /* create dialog */
   dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (socket))),
@@ -314,14 +339,40 @@ panel_plugin_external_plug_removed (GtkSocket *socket)
       gtk_widget_destroy (GTK_WIDGET (socket));
     }
 
-  /* process other events */
-  if (GTK_SOCKET_CLASS (panel_plugin_external_parent_class)->plug_removed)
-    return (*GTK_SOCKET_CLASS (panel_plugin_external_parent_class)->plug_removed) (socket);
   return FALSE;
 }
 
 
 
+static void
+panel_plugin_external_plug_added (GtkSocket *socket)
+{
+  PanelPluginExternal *external = PANEL_PLUGIN_EXTERNAL (socket);
+  GSList              *li;
+  QueuedData          *data;
+  
+  /* plug has been added */
+  external->plug_embedded = TRUE;
+  
+  if (G_LIKELY (external->dbus_queue))
+    {
+      /* flush the queue */
+      for (li = external->dbus_queue; li != NULL; li = li->next)
+        {
+          data = li->data;
+          panel_dbus_service_set_plugin_property (external->id, data->property, &data->value);
+          g_value_unset (&data->value);
+          g_slice_free (QueuedData, data);
+        }
+      
+      /* free the list */
+      g_slist_free (external->dbus_queue);
+      external->dbus_queue = NULL;
+    }
+}
+
+
+
 static const gchar *
 panel_plugin_external_get_name (XfcePanelPluginProvider *provider)
 {
@@ -345,6 +396,38 @@ panel_plugin_external_get_id (XfcePanelPluginProvider *provider)
 
 
 static void
+panel_plugin_external_set_property (PanelPluginExternal *external,
+                                    const gchar         *property,
+                                    GValue              *value)
+{
+  QueuedData *data;
+  
+  panel_return_if_fail (PANEL_IS_PLUGIN_EXTERNAL (external));
+  panel_return_if_fail (value && G_TYPE_CHECK_VALUE (value));
+  panel_return_if_fail (property != NULL && *property != '\0');
+  
+  if (G_LIKELY (external->plug_embedded))
+    {
+      /* directly send the new property */
+      panel_dbus_service_set_plugin_property (external->id, property, value);
+    }
+  else
+    {
+      /* queue the property */
+      data = g_slice_new0 (QueuedData);
+      data->property = property;
+      g_value_init (&data->value, G_VALUE_TYPE (value));
+      g_value_copy (value, &data->value);
+      
+      /* add to the queue */
+      external->dbus_queue = g_slist_append (external->dbus_queue, data);
+    }
+}
+                                    
+
+
+
+static void
 panel_plugin_external_set_size (XfcePanelPluginProvider *provider,
                                 gint                     size)
 {
@@ -353,12 +436,12 @@ panel_plugin_external_set_size (XfcePanelPluginProvider *provider,
   panel_return_if_fail (PANEL_IS_PLUGIN_EXTERNAL (provider));
   panel_return_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (provider));
   
-  /* set the size */
+  /* create a new value */
   g_value_init (&value, G_TYPE_INT);
   g_value_set_int (&value, size);
-  
+
   /* send the value */
-  panel_dbus_service_set_plugin_property (PANEL_PLUGIN_EXTERNAL (provider)->id, "Size", &value);
+  panel_plugin_external_set_property (PANEL_PLUGIN_EXTERNAL (provider), "Size", &value);
   
   /* unset */
   g_value_unset (&value);
@@ -375,13 +458,13 @@ panel_plugin_external_set_orientation (XfcePanelPluginProvider *provider,
   panel_return_if_fail (PANEL_IS_PLUGIN_EXTERNAL (provider));
   panel_return_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (provider));
 
-  /* set the orientation */
+  /* create a new value */
   g_value_init (&value, G_TYPE_UINT);
   g_value_set_uint (&value, orientation);
 
   /* send the value */
-  panel_dbus_service_set_plugin_property (PANEL_PLUGIN_EXTERNAL (provider)->id, "Orientation", &value);
-
+  panel_plugin_external_set_property (PANEL_PLUGIN_EXTERNAL (provider), "Orientation", &value);
+  
   /* unset */
   g_value_unset (&value);
 }
@@ -402,8 +485,8 @@ panel_plugin_external_set_screen_position (XfcePanelPluginProvider *provider,
   g_value_set_uint (&value, screen_position);
 
   /* send the value */
-  panel_dbus_service_set_plugin_property (PANEL_PLUGIN_EXTERNAL (provider)->id, "ScreenPosition", &value);
-
+  panel_plugin_external_set_property (PANEL_PLUGIN_EXTERNAL (provider), "ScreenPosition", &value);
+  
   /* unset */
   g_value_unset (&value);
 }
@@ -413,11 +496,20 @@ panel_plugin_external_set_screen_position (XfcePanelPluginProvider *provider,
 static void
 panel_plugin_external_save (XfcePanelPluginProvider *provider)
 {
+  GValue value = { 0, };
+  
   panel_return_if_fail (PANEL_IS_PLUGIN_EXTERNAL (provider));
   panel_return_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (provider));
+  
+  /* create dummy value */
+  g_value_init (&value, G_TYPE_BOOLEAN);
+  g_value_set_boolean (&value, FALSE);
 
   /* send signal to wrapper */
-  panel_dbus_service_set_plugin_property (PANEL_PLUGIN_EXTERNAL (provider)->id, "Save", NULL);
+  panel_plugin_external_set_property (PANEL_PLUGIN_EXTERNAL (provider), "Save", &value);
+  
+  /* unset */
+  g_value_unset (&value);
 }
 
 
@@ -434,7 +526,7 @@ panel_plugin_external_set_sensitive (PanelPluginExternal *external)
   g_value_set_boolean (&value, GTK_WIDGET_IS_SENSITIVE (external));
 
   /* send message */
-  panel_dbus_service_set_plugin_property (external->id, "Sensitive", &value);
+  panel_plugin_external_set_property (external, "Sensitive", &value);
   
   /* unset */
   g_value_unset (&value);
@@ -480,7 +572,7 @@ panel_plugin_external_set_background_alpha (PanelPluginExternal *external,
   g_value_set_int (&value, percentage);
 
   /* send message */
-  panel_dbus_service_set_plugin_property (external->id, "BackgroundAlpha", &value);
+  panel_plugin_external_set_property (external, "BackgroundAlpha", &value);
   
   /* unset */
   g_value_unset (&value);
@@ -501,7 +593,7 @@ panel_plugin_external_set_active_panel (PanelPluginExternal *external,
   g_value_set_boolean (&value, active);
 
   /* send message */
-  panel_dbus_service_set_plugin_property (external->id, "ActivePanel", &value);
+  panel_plugin_external_set_property (external, "ActivePanel", &value);
   
   /* unset */
   g_value_unset (&value);
diff --git a/panel/panel-private.c b/panel/panel-private.c
index d336a7c..6798fbf 100644
--- a/panel/panel-private.c
+++ b/panel/panel-private.c
@@ -21,6 +21,7 @@
 #include <libxfce4panel/libxfce4panel.h>
 
 
+
 #if !GTK_CHECK_VERSION (2,12,0)
 void
 _widget_set_tooltip_text (GtkWidget   *widget,
diff --git a/wrapper/main.c b/wrapper/main.c
index 6e7c5e8..c16bb67 100644
--- a/wrapper/main.c
+++ b/wrapper/main.c
@@ -76,15 +76,14 @@ dbus_proxy_provider_property_changed (DBusGProxy              *dbus_proxy,
   WrapperPlug *plug;
 
   panel_return_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (provider));
+  panel_return_if_fail (value && G_TYPE_CHECK_VALUE (value));
 
   /* check if the signal is for this panel */
-  if (strcmp (plugin_id, xfce_panel_plugin_provider_get_id (provider)) != 0)
+  if (!plugin_id || strcmp (plugin_id, xfce_panel_plugin_provider_get_id (provider)) != 0)
     return;
 
-  g_message ("Wrapper %s received property %s", plugin_id, property);
-
   /* handle the property */
-  if (G_UNLIKELY (property == NULL))
+  if (G_UNLIKELY (property == NULL || *property == '\0'))
     g_message ("External plugin '%s' received null property", plugin_id);
   else if (strcmp (property, "Size") == 0)
     xfce_panel_plugin_provider_set_size (provider, g_value_get_int (value));
@@ -216,7 +215,6 @@ main (gint argc, gchar **argv)
   DBusGConnection         *dbus_connection;
   DBusGProxy              *dbus_proxy;
   WrapperPlug             *plug;
-  GValue                   value = { 0, };
 
   /* set translation domain */
   xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
@@ -337,7 +335,6 @@ main (gint argc, gchar **argv)
 
       /* create the wrapper plug (a gtk plug with transparency capabilities) */
       plug = wrapper_plug_new (opt_socket_id);
-      gtk_container_add (GTK_CONTAINER (plug), GTK_WIDGET (provider));
       g_object_set_qdata (G_OBJECT (provider), plug_quark, plug);
 
       /* connect provider signals */
@@ -351,24 +348,13 @@ main (gint argc, gchar **argv)
       dbus_g_proxy_connect_signal (dbus_proxy, "PropertyChanged", G_CALLBACK (dbus_proxy_provider_property_changed), provider, NULL);
 
       /* show the plugin */
+      gtk_container_add (GTK_CONTAINER (plug), GTK_WIDGET (provider));
       gtk_widget_show (GTK_WIDGET (plug));
       gtk_widget_show (GTK_WIDGET (provider));
 
-      /* register the plugin */
-      g_value_init (&value, G_TYPE_STRING);
-      g_value_set_static_string (&value, opt_id);
-      wrapper_dbus_client_set_property (dbus_proxy, "XfcePanel", "RegisterPlugin", &value, NULL);
-      g_value_unset (&value);
-
       /* enter the main loop */
       gtk_main ();
 
-      /* unregister the plugin */
-      g_value_init (&value, G_TYPE_STRING);
-      g_value_set_static_string (&value, opt_id);
-      wrapper_dbus_client_set_property (dbus_proxy, "XfcePanel", "UnregisterPlugin", &value, NULL);
-      g_value_unset (&value);
-
       /* destroy the plug and provider */
       gtk_widget_destroy (GTK_WIDGET (plug));
     }



More information about the Xfce4-commits mailing list