[Xfce4-commits] <xfce4-panel:devel> Allow sending a plugin-event without value.

Nick Schermer noreply at xfce.org
Thu Dec 3 10:24:01 CET 2009


Updating branch refs/heads/devel
         to 437dd0843cd04cd27e8e0f9ae48ed7a7e34a48b5 (commit)
       from 47808ab61034a96c26cd8a30cf063714d6457e37 (commit)

commit 437dd0843cd04cd27e8e0f9ae48ed7a7e34a48b5
Author: Nick Schermer <nick at xfce.org>
Date:   Wed Dec 2 19:39:34 2009 +0100

    Allow sending a plugin-event without value.

 libxfce4panel/xfce-panel-plugin-provider.c |    2 +
 libxfce4panel/xfce-panel-plugin.c          |    2 +-
 panel/panel-dbus-client.c                  |   48 +++++++++++++++++++---------
 panel/panel-dbus-service.c                 |   10 +++++-
 panel/panel-plugin-external.c              |   13 +++++++-
 plugins/launcher/launcher.c                |    2 +
 plugins/windowmenu/windowmenu.c            |    2 +
 wrapper/main.c                             |   21 ++++++++----
 8 files changed, 75 insertions(+), 25 deletions(-)

diff --git a/libxfce4panel/xfce-panel-plugin-provider.c b/libxfce4panel/xfce-panel-plugin-provider.c
index 12309f7..90971a2 100644
--- a/libxfce4panel/xfce-panel-plugin-provider.c
+++ b/libxfce4panel/xfce-panel-plugin-provider.c
@@ -211,6 +211,8 @@ xfce_panel_plugin_provider_remote_event (XfcePanelPluginProvider *provider,
                                          const GValue            *value)
 {
   panel_return_val_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (provider), TRUE);
+  panel_return_val_if_fail (name != NULL, TRUE);
+  panel_return_val_if_fail (value == NULL || G_IS_VALUE (value), TRUE);
 
   return (*XFCE_PANEL_PLUGIN_PROVIDER_GET_IFACE (provider)->remote_event) (provider, name, value);
 }
diff --git a/libxfce4panel/xfce-panel-plugin.c b/libxfce4panel/xfce-panel-plugin.c
index a38300c..5d9f157 100644
--- a/libxfce4panel/xfce-panel-plugin.c
+++ b/libxfce4panel/xfce-panel-plugin.c
@@ -1250,7 +1250,7 @@ xfce_panel_plugin_remote_event (XfcePanelPluginProvider *provider,
 
   panel_return_val_if_fail (XFCE_IS_PANEL_PLUGIN (provider), TRUE);
   panel_return_val_if_fail (name != NULL, TRUE);
-  panel_return_val_if_fail (G_IS_VALUE (value), TRUE);
+  panel_return_val_if_fail (value == NULL || G_IS_VALUE (value), TRUE);
 
   g_signal_emit (G_OBJECT (provider), plugin_signals[REMOTE_EVENT], 0,
                  name, value, &stop_emission);
diff --git a/panel/panel-dbus-client.c b/panel/panel-dbus-client.c
index 03716f5..8dc86a1 100644
--- a/panel/panel-dbus-client.c
+++ b/panel/panel-dbus-client.c
@@ -218,6 +218,7 @@ panel_dbus_client_plugin_event (const gchar  *plugin_event,
   gchar      **tokens;
   GType        type;
   GValue       value = { 0, };
+  guint        n_tokens;
 
   panel_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
@@ -226,10 +227,25 @@ panel_dbus_client_plugin_event (const gchar  *plugin_event,
     return FALSE;
 
   tokens = g_strsplit (plugin_event, ":", -1);
-  if (G_LIKELY (g_strv_length (tokens) == N_TOKENS
-                && IS_STRING (tokens[VALUE])
-                && IS_STRING (tokens[NAME])
-                && *tokens[NAME] != SIGNAL_PREFIX))
+  n_tokens = g_strv_length (tokens);
+
+  if (!(n_tokens == 2 || n_tokens == N_TOKENS)
+      || !IS_STRING (tokens[PLUGIN_NAME])
+      || !IS_STRING (tokens[NAME])
+      || *tokens[NAME] == SIGNAL_PREFIX)
+    {
+      g_set_error_literal (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
+                           _("Invalid plugin event syntax specified. "
+                             "Use PLUGIN-NAME:NAME[:TYPE:VALUE]."));
+      goto out;
+    }
+  else if (n_tokens == 2)
+    {
+      /* set noop value, recognized by the dbus service as %NULL value */
+      g_value_init (&value, G_TYPE_UCHAR);
+      g_value_set_uchar (&value, '\0');
+    }
+  else if (n_tokens == N_TOKENS)
     {
       type = panel_dbus_client_gtype_from_string (tokens[TYPE]);
       if (G_LIKELY (type != G_TYPE_NONE))
@@ -248,14 +264,6 @@ panel_dbus_client_plugin_event (const gchar  *plugin_event,
             g_value_set_uint (&value, strtol (tokens[VALUE], NULL, 0));
           else
             panel_assert_not_reached ();
-
-          result = _panel_dbus_client_plugin_event (dbus_proxy,
-                                                    tokens[PLUGIN_NAME],
-                                                    tokens[NAME],
-                                                    &value,
-                                                    error);
-
-          g_value_unset (&value);
         }
       else
         {
@@ -263,15 +271,25 @@ panel_dbus_client_plugin_event (const gchar  *plugin_event,
                        _("Invalid hint type \"%s\". Valid types "
                          "are bool, double, int, string and uint."),
                        tokens[TYPE]);
+          goto out;
         }
     }
   else
     {
-      g_set_error_literal (error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE,
-                           _("Invalid plugin event syntax specified. "
-                             "Use PLUGIN-NAME:NAME:TYPE:VALUE."));
+      panel_assert_not_reached ();
+      goto out;
     }
 
+  /* send value over dbus */
+  panel_return_val_if_fail (G_IS_VALUE (&value), FALSE);
+  result = _panel_dbus_client_plugin_event (dbus_proxy,
+                                            tokens[PLUGIN_NAME],
+                                            tokens[NAME],
+                                            &value,
+                                            error);
+  g_value_unset (&value);
+
+out:
   g_strfreev (tokens);
   g_object_unref (G_OBJECT (dbus_proxy));
 
diff --git a/panel/panel-dbus-service.c b/panel/panel-dbus-service.c
index 32ae188..fd65121 100644
--- a/panel/panel-dbus-service.c
+++ b/panel/panel-dbus-service.c
@@ -255,6 +255,7 @@ panel_dbus_service_plugin_event (PanelDBusService  *service,
 {
   GSList             *plugins, *li;
   PanelModuleFactory *factory;
+  const GValue       *real_value = value;
 
   panel_return_val_if_fail (PANEL_IS_DBUS_SERVICE (service), FALSE);
   panel_return_val_if_fail (error == NULL || *error == NULL, FALSE);
@@ -262,6 +263,13 @@ panel_dbus_service_plugin_event (PanelDBusService  *service,
   panel_return_val_if_fail (name != NULL, FALSE);
   panel_return_val_if_fail (G_IS_VALUE (value), FALSE);
 
+  /* if no type and value is send with the signal we send a char type
+   * with nul value */
+  g_message ("%s", G_VALUE_TYPE_NAME (value));
+  if (G_VALUE_HOLDS_UCHAR (value)
+      && g_value_get_uchar (value) == '\0')
+    real_value = NULL;
+
   factory = panel_module_factory_get ();
 
   plugins = panel_module_factory_get_plugins (factory, plugin_name);
@@ -269,7 +277,7 @@ panel_dbus_service_plugin_event (PanelDBusService  *service,
   for (li = plugins; li != NULL; li = li->next)
     {
       panel_return_val_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (li->data), FALSE);
-      if (xfce_panel_plugin_provider_remote_event (li->data, name, value))
+      if (xfce_panel_plugin_provider_remote_event (li->data, name, real_value))
         break;
     }
 
diff --git a/panel/panel-plugin-external.c b/panel/panel-plugin-external.c
index ee2dbc9..22b00a3 100644
--- a/panel/panel-plugin-external.c
+++ b/panel/panel-plugin-external.c
@@ -818,13 +818,24 @@ panel_plugin_external_remote_event (XfcePanelPluginProvider *provider,
                                     const gchar             *name,
                                     const GValue            *value)
 {
+  GValue        noop_value = { 0, };
+  const GValue *real_value = value;
+
   panel_return_val_if_fail (PANEL_IS_PLUGIN_EXTERNAL (provider), TRUE);
   panel_return_val_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (provider), TRUE);
+  panel_return_val_if_fail (value == NULL || G_IS_VALUE (value), FALSE);
 
   /* TODO handle the return value */
 
+  if (value == NULL)
+    {
+      g_value_init (&noop_value, G_TYPE_UCHAR);
+      g_value_set_uchar (&noop_value, '\0');
+      real_value = &noop_value;
+    }
+
   panel_plugin_external_queue_add (PANEL_PLUGIN_EXTERNAL (provider),
-                                   FALSE, name, value);
+                                   FALSE, name, real_value);
 
   return TRUE;
 }
diff --git a/plugins/launcher/launcher.c b/plugins/launcher/launcher.c
index 9eba83e..1827916 100644
--- a/plugins/launcher/launcher.c
+++ b/plugins/launcher/launcher.c
@@ -1029,6 +1029,8 @@ launcher_plugin_remote_event (XfcePanelPlugin *panel_plugin,
 {
   LauncherPlugin *plugin = XFCE_LAUNCHER_PLUGIN (panel_plugin);
 
+  panel_return_val_if_fail (value == NULL || G_IS_VALUE (value), FALSE);
+
   if (exo_str_is_equal (name, "popup")
       && LIST_HAS_TWO_OR_MORE_ENTRIES (plugin->items)
       && (plugin->menu == NULL || !GTK_WIDGET_VISIBLE (plugin->menu)))
diff --git a/plugins/windowmenu/windowmenu.c b/plugins/windowmenu/windowmenu.c
index 211137d..b56de43 100644
--- a/plugins/windowmenu/windowmenu.c
+++ b/plugins/windowmenu/windowmenu.c
@@ -526,6 +526,8 @@ window_menu_plugin_remote_event (XfcePanelPlugin *panel_plugin,
   WindowMenuPlugin *plugin = XFCE_WINDOW_MENU_PLUGIN (panel_plugin);
   GdkEventButton    event;
 
+  panel_return_val_if_fail (value == NULL || G_IS_VALUE (value), FALSE);
+
   if (strcmp (name, "popup") == 0
       && GTK_WIDGET_VISIBLE (panel_plugin)
       && !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (plugin->button)))
diff --git a/wrapper/main.c b/wrapper/main.c
index 426fcf7..da9af43 100644
--- a/wrapper/main.c
+++ b/wrapper/main.c
@@ -60,12 +60,13 @@ wrapper_gproxy_set (DBusGProxy              *dbus_gproxy,
                     const GPtrArray         *array,
                     XfcePanelPluginProvider *provider)
 {
-  WrapperPlug *plug;
-  guint        i;
-  GValue      *value;
-  gchar       *property;
-  guint        reply_id;
-  GValue       msg = { 0, };
+  WrapperPlug  *plug;
+  guint         i;
+  GValue       *value;
+  gchar        *property;
+  guint         reply_id;
+  GValue        msg = { 0, };
+  const GValue *real_value;
 
   panel_return_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (provider));
 
@@ -112,7 +113,13 @@ wrapper_gproxy_set (DBusGProxy              *dbus_gproxy,
         }
       else
         {
-          xfce_panel_plugin_provider_remote_event (provider, property, value);
+          if (G_VALUE_HOLDS_UCHAR (value)
+              && g_value_get_uchar (value) == '\0')
+            real_value = NULL;
+          else
+            real_value = value;
+
+          xfce_panel_plugin_provider_remote_event (provider, property, real_value);
         }
 
       g_free (property);



More information about the Xfce4-commits mailing list