[Xfce4-commits] <xfce4-panel:devel> * Implement provider signal in another way. We not use an enum for the different signal, this make the code a lot easier to read and smaller.
Nick Schermer
nick at xfce.org
Tue Aug 11 20:24:03 CEST 2009
Updating branch refs/heads/devel
to 83ab6d460952e9d2844a511d9ecd9285ee6d2f2a (commit)
from c0baf217b627465c2a7b3326584a89de9bb55715 (commit)
commit 83ab6d460952e9d2844a511d9ecd9285ee6d2f2a
Author: Nick Schermer <nick at xfce.org>
Date: Mon Aug 18 21:26:00 2008 +0200
* Implement provider signal in another way. We not use an enum for the
different signal, this make the code a lot easier to read and smaller.
libxfce4panel/xfce-panel-plugin-provider.c | 46 +------
libxfce4panel/xfce-panel-plugin-provider.h | 15 +++
libxfce4panel/xfce-panel-plugin.c | 26 ++--
panel/main.c | 4 +-
panel/panel-application.c | 87 +++++++++----
panel/panel-dbus-client.c | 34 +----
panel/panel-dbus-client.h | 6 +-
panel/panel-dbus-service-infos.xml | 12 +--
panel/panel-dbus-service.c | 34 +++---
panel/panel-plugin-external.c | 110 ++++++++++-------
wrapper/main.c | 186 ++++++++--------------------
11 files changed, 243 insertions(+), 317 deletions(-)
diff --git a/libxfce4panel/xfce-panel-plugin-provider.c b/libxfce4panel/xfce-panel-plugin-provider.c
index 0459a76..f95ab45 100644
--- a/libxfce4panel/xfce-panel-plugin-provider.c
+++ b/libxfce4panel/xfce-panel-plugin-provider.c
@@ -32,11 +32,7 @@
enum
{
- EXPAND_CHANGED,
- MOVE,
- ADD_NEW_ITEMS,
- PANEL_PREFERENCES,
- LOCK_PANEL,
+ PROVIDER_SIGNAL,
LAST_SIGNAL
};
@@ -86,45 +82,13 @@ xfce_panel_plugin_provider_base_init (gpointer klass)
if (G_UNLIKELY (!initialized))
{
- provider_signals[EXPAND_CHANGED] =
- g_signal_new (I_("expand-changed"),
+ provider_signals[PROVIDER_SIGNAL] =
+ g_signal_new (I_("provider-signal"),
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0, NULL, NULL,
- g_cclosure_marshal_VOID__BOOLEAN,
- G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
-
- provider_signals[MOVE] =
- g_signal_new (I_("move-item"),
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0, NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- provider_signals[ADD_NEW_ITEMS] =
- g_signal_new (I_("add-new-items"),
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0, NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- provider_signals[PANEL_PREFERENCES] =
- g_signal_new (I_("panel-preferences"),
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0, NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- provider_signals[LOCK_PANEL] =
- g_signal_new (I_("lock-panel"),
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- 0, NULL, NULL,
- g_cclosure_marshal_VOID__BOOLEAN,
- G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
+ g_cclosure_marshal_VOID__UINT,
+ G_TYPE_NONE, 1, G_TYPE_UINT);
/* initialization finished */
initialized = TRUE;
diff --git a/libxfce4panel/xfce-panel-plugin-provider.h b/libxfce4panel/xfce-panel-plugin-provider.h
index eb1ce93..239c0fe 100644
--- a/libxfce4panel/xfce-panel-plugin-provider.h
+++ b/libxfce4panel/xfce-panel-plugin-provider.h
@@ -27,6 +27,7 @@ G_BEGIN_DECLS
typedef struct _XfcePanelPluginProviderIface XfcePanelPluginProviderIface;
typedef struct _XfcePanelPluginProvider XfcePanelPluginProvider;
+typedef enum _ProviderSignal ProviderSignal;
typedef XfcePanelPluginProvider *(*PluginConstructFunc) (const gchar *name,
const gchar *id,
@@ -36,6 +37,20 @@ typedef XfcePanelPluginProvider *(*PluginConstructFunc) (const gchar *name,
+enum _ProviderSignal
+{
+ MOVE_PLUGIN,
+ EXPAND_PLUGIN,
+ COLLAPSE_PLUGIN,
+ LOCK_PANEL,
+ UNLOCK_PANEL,
+ REMOVE_PLUGIN,
+ ADD_NEW_ITEMS,
+ PANEL_PREFERENCES,
+};
+
+
+
#define XFCE_TYPE_PANEL_PLUGIN_PROVIDER (xfce_panel_plugin_provider_get_type ())
#define XFCE_PANEL_PLUGIN_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFCE_TYPE_PANEL_PLUGIN_PROVIDER, XfcePanelPluginProvider))
#define XFCE_IS_PANEL_PLUGIN_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XFCE_TYPE_PANEL_PLUGIN_PROVIDER))
diff --git a/libxfce4panel/xfce-panel-plugin.c b/libxfce4panel/xfce-panel-plugin.c
index f6cd7f2..270e90f 100644
--- a/libxfce4panel/xfce-panel-plugin.c
+++ b/libxfce4panel/xfce-panel-plugin.c
@@ -554,8 +554,8 @@ xfce_panel_plugin_menu_move (XfcePanelPlugin *plugin)
panel_return_if_fail (XFCE_IS_PANEL_PLUGIN (plugin));
panel_return_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (plugin));
- /* move the plugin (provider signal) */
- g_signal_emit_by_name (G_OBJECT (plugin), "move-item", 0);
+ /* move the plugin */
+ g_signal_emit_by_name (G_OBJECT (plugin), "provider-signal", MOVE_PLUGIN);
}
@@ -601,8 +601,8 @@ xfce_panel_plugin_menu_remove (XfcePanelPlugin *plugin)
g_free (filename);
}
- /* destroy the plugin */
- gtk_widget_destroy (GTK_WIDGET (plugin));
+ /* ask the panel or wrapper to remove the plugin */
+ g_signal_emit_by_name (G_OBJECT (plugin), "provider-signal", REMOVE_PLUGIN);
}
/* destroy */
@@ -617,8 +617,8 @@ xfce_panel_plugin_menu_add_items (XfcePanelPlugin *plugin)
panel_return_if_fail (XFCE_IS_PANEL_PLUGIN (plugin));
panel_return_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (plugin));
- /* open items dialog (provider signal) */
- g_signal_emit_by_name (G_OBJECT (plugin), "add-new-items", 0);
+ /* open items dialog */
+ g_signal_emit_by_name (G_OBJECT (plugin), "provider-signal", ADD_NEW_ITEMS);
}
@@ -629,8 +629,8 @@ xfce_panel_plugin_menu_panel_preferences (XfcePanelPlugin *plugin)
panel_return_if_fail (XFCE_IS_PANEL_PLUGIN (plugin));
panel_return_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (plugin));
- /* open preferences dialog (provider signal) */
- g_signal_emit_by_name (G_OBJECT (plugin), "panel-preferences", 0);
+ /* open preferences dialog */
+ g_signal_emit_by_name (G_OBJECT (plugin), "provider-signal", PANEL_PREFERENCES);
}
@@ -758,9 +758,9 @@ xfce_panel_plugin_unregister_menu (GtkMenu *menu,
/* decrease the counter */
plugin->priv->registered_menus--;
- /* emit signal to unlock the panel (provider signal) */
+ /* emit signal to unlock the panel */
if (G_LIKELY (plugin->priv->registered_menus == 0))
- g_signal_emit_by_name (G_OBJECT (plugin), "lock-panel", FALSE);
+ g_signal_emit_by_name (G_OBJECT (plugin), "provider-signal", UNLOCK_PANEL);
}
}
@@ -991,7 +991,7 @@ xfce_panel_plugin_set_expand (XfcePanelPlugin *plugin,
plugin->priv->expand = expand;
/* emit signal (in provider) */
- g_signal_emit_by_name (G_OBJECT (plugin), "expand-changed", expand);
+ g_signal_emit_by_name (G_OBJECT (plugin), "provider-signal", expand ? EXPAND_PLUGIN : COLLAPSE_PLUGIN);
}
}
@@ -1187,9 +1187,9 @@ xfce_panel_plugin_register_menu (XfcePanelPlugin *plugin,
/* connect signal to menu to decrease counter */
g_signal_connect (G_OBJECT (menu), "deactivate", G_CALLBACK (xfce_panel_plugin_unregister_menu), plugin);
- /* tell panel it needs to lock (provider signal) */
+ /* tell panel it needs to lock */
if (G_LIKELY (plugin->priv->registered_menus == 1))
- g_signal_emit_by_name (G_OBJECT (plugin), "lock-panel", TRUE);
+ g_signal_emit_by_name (G_OBJECT (plugin), "provider-signal", LOCK_PANEL);
}
diff --git a/panel/main.c b/panel/main.c
index 66abf8b..f3546cc 100644
--- a/panel/main.c
+++ b/panel/main.c
@@ -190,14 +190,14 @@ main (gint argc, gchar **argv)
else if (opt_preferences >= 0)
{
/* send a signal to the running instance to show the preferences dialog */
- result = panel_dbus_client_display_preferences_dialog (NULL, opt_preferences, &error);
+ result = panel_dbus_client_display_preferences_dialog (opt_preferences, &error);
goto dbus_return;
}
else if (opt_add_items >= 0)
{
/* send a signal to the running instance to show the add items dialog */
- result = panel_dbus_client_display_items_dialog (NULL, opt_add_items, &error);
+ result = panel_dbus_client_display_items_dialog (opt_add_items, &error);
goto dbus_return;
}
diff --git a/panel/panel-application.c b/panel/panel-application.c
index f5ae400..367671a 100644
--- a/panel/panel-application.c
+++ b/panel/panel-application.c
@@ -63,9 +63,6 @@ static void panel_application_load_end_element (GMarkupParseContext *c
const gchar *element_name,
gpointer user_data,
GError **error);
-static void panel_application_plugin_expand (GtkWidget *plugin,
- gboolean expand,
- PanelWindow *window);
static void panel_application_plugin_move (GtkWidget *item,
PanelApplication *application);
static gboolean panel_application_plugin_insert (PanelApplication *application,
@@ -521,25 +518,6 @@ panel_application_load_end_element (GMarkupParseContext *context,
static void
-panel_application_plugin_expand (GtkWidget *plugin,
- gboolean expand,
- PanelWindow *window)
-{
- GtkWidget *itembar;
-
- panel_return_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (plugin));
- panel_return_if_fail (PANEL_IS_WINDOW (window));
-
- /* get the itembar */
- itembar = gtk_bin_get_child (GTK_BIN (window));
-
- /* set new expand mode */
- panel_itembar_set_child_expand (PANEL_ITEMBAR (itembar), plugin, expand);
-}
-
-
-
-static void
panel_application_plugin_move_end (GtkWidget *item,
GdkDragContext *context,
PanelApplication *application)
@@ -592,6 +570,65 @@ panel_application_plugin_move (GtkWidget *item,
+static void
+panel_application_plugin_provider_signal (XfcePanelPluginProvider *provider,
+ ProviderSignal signal,
+ PanelApplication *application)
+{
+ GtkWidget *toplevel, *itembar;
+
+ panel_return_if_fail (PANEL_IS_APPLICATION (application));
+ panel_return_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (provider));
+
+ switch (signal)
+ {
+ case MOVE_PLUGIN:
+ /* invoke the move function */
+ panel_application_plugin_move (GTK_WIDGET (provider), application);
+ break;
+
+ case EXPAND_PLUGIN:
+ case COLLAPSE_PLUGIN:
+ /* get the itembar */
+ toplevel = gtk_widget_get_toplevel (GTK_WIDGET (provider));
+ itembar = gtk_bin_get_child (GTK_BIN (toplevel));
+
+ /* set new expand mode */
+ panel_itembar_set_child_expand (PANEL_ITEMBAR (itembar), GTK_WIDGET (provider), !!(signal == EXPAND_PLUGIN));
+ break;
+
+ case LOCK_PANEL:
+ case UNLOCK_PANEL:
+ /* TODO: implement */
+ break;
+
+ case REMOVE_PLUGIN:
+ /* destroy the plugin if it's a panel plugin (ie. not external) */
+ if (XFCE_IS_PANEL_PLUGIN (provider))
+ gtk_widget_destroy (GTK_WIDGET (provider));
+ break;
+
+ case ADD_NEW_ITEMS:
+ /* open the items dialog */
+ panel_item_dialog_show ();
+ break;
+
+ case PANEL_PREFERENCES:
+ /* get the panel window widget */
+ toplevel = gtk_widget_get_toplevel (GTK_WIDGET (provider));
+
+ /* open the panel preferences */
+ panel_preferences_dialog_show (PANEL_WINDOW (toplevel));
+ break;
+
+ default:
+ g_critical ("Reveived unknown signal %d", signal);
+ break;
+ }
+}
+
+
+
static gboolean
panel_application_plugin_insert (PanelApplication *application,
PanelWindow *window,
@@ -618,10 +655,8 @@ panel_application_plugin_insert (PanelApplication *application,
/* get the panel itembar */
itembar = gtk_bin_get_child (GTK_BIN (window));
- g_signal_connect (G_OBJECT (provider), "expand-changed", G_CALLBACK (panel_application_plugin_expand), window);
- g_signal_connect (G_OBJECT (provider), "move-item", G_CALLBACK (panel_application_plugin_move), application);
- g_signal_connect (G_OBJECT (provider), "add-new-items", G_CALLBACK (panel_item_dialog_show), NULL);
- g_signal_connect_swapped (G_OBJECT (provider), "panel-preferences", G_CALLBACK (panel_preferences_dialog_show), window);
+ /* add signal to monitor provider signals */
+ g_signal_connect (G_OBJECT (provider), "provider-signal", G_CALLBACK (panel_application_plugin_provider_signal), application);
/* add the item to the panel */
panel_itembar_insert (PANEL_ITEMBAR (itembar), GTK_WIDGET (provider), position);
diff --git a/panel/panel-dbus-client.c b/panel/panel-dbus-client.c
index 0e4cd38..d6f9572 100644
--- a/panel/panel-dbus-client.c
+++ b/panel/panel-dbus-client.c
@@ -64,34 +64,23 @@ panel_dbus_client_check_client_running (GError **error)
gboolean
-panel_dbus_client_display_preferences_dialog (GdkScreen *screen,
- guint active,
- GError **error)
+panel_dbus_client_display_preferences_dialog (guint active,
+ GError **error)
{
- gchar *name;
gboolean result;
DBusGProxy *dbus_proxy;
- panel_return_val_if_fail (screen == NULL || GDK_IS_SCREEN (screen), FALSE);
panel_return_val_if_fail (error == NULL || *error == NULL, FALSE);
- /* use default screen if none is defined */
- if (screen == NULL)
- screen = gdk_screen_get_default ();
-
/* get the proxy */
dbus_proxy = panel_dbus_client_get_proxy (error);
if (G_UNLIKELY (dbus_proxy == NULL))
return FALSE;
- /* get the display name */
- name = gdk_screen_make_display_name (screen);
-
/* call */
- result = _panel_dbus_client_display_preferences_dialog (dbus_proxy, name, active, error);
+ result = _panel_dbus_client_display_preferences_dialog (dbus_proxy, active, error);
/* cleanup */
- g_free (name);
g_object_unref (G_OBJECT (dbus_proxy));
return result;
@@ -100,34 +89,23 @@ panel_dbus_client_display_preferences_dialog (GdkScreen *screen,
gboolean
-panel_dbus_client_display_items_dialog (GdkScreen *screen,
- guint active,
- GError **error)
+panel_dbus_client_display_items_dialog (guint active,
+ GError **error)
{
- gchar *name;
gboolean result;
DBusGProxy *dbus_proxy;
- panel_return_val_if_fail (screen == NULL || GDK_IS_SCREEN (screen), FALSE);
panel_return_val_if_fail (error == NULL || *error == NULL, FALSE);
- /* use default screen if none is defined */
- if (screen == NULL)
- screen = gdk_screen_get_default ();
-
/* get the proxy */
dbus_proxy = panel_dbus_client_get_proxy (error);
if (G_UNLIKELY (dbus_proxy == NULL))
return FALSE;
- /* get the display name */
- name = gdk_screen_make_display_name (screen);
-
/* call */
- result = _panel_dbus_client_display_items_dialog (dbus_proxy, name, active, error);
+ result = _panel_dbus_client_display_items_dialog (dbus_proxy, active, error);
/* cleanup */
- g_free (name);
g_object_unref (G_OBJECT (dbus_proxy));
return result;
diff --git a/panel/panel-dbus-client.h b/panel/panel-dbus-client.h
index 6b6193e..5e9120d 100644
--- a/panel/panel-dbus-client.h
+++ b/panel/panel-dbus-client.h
@@ -25,12 +25,10 @@
gboolean panel_dbus_client_check_client_running (GError **error);
-gboolean panel_dbus_client_display_preferences_dialog (GdkScreen *screen,
- guint active,
+gboolean panel_dbus_client_display_preferences_dialog (guint active,
GError **error);
-gboolean panel_dbus_client_display_items_dialog (GdkScreen *screen,
- guint active,
+gboolean panel_dbus_client_display_items_dialog (guint active,
GError **error);
gboolean panel_dbus_client_save (GError **error);
diff --git a/panel/panel-dbus-service-infos.xml b/panel/panel-dbus-service-infos.xml
index 3c88bb4..c63e6ee 100644
--- a/panel/panel-dbus-service-infos.xml
+++ b/panel/panel-dbus-service-infos.xml
@@ -27,26 +27,22 @@
<annotation name="org.freedesktop.DBus.GLib.ClientCSymbol" value="_panel_dbus_client" />
<!--
- DisplayPreferencesDialog (display : STRING) : VOID
+ DisplayPreferencesDialog (active : UINT) : VOID
- display : The display on which to show the dialog or ""
- to use the default screen of the panel.
active : The active panel number in the dialog, starting
at zero.
-->
<method name="DisplayPreferencesDialog">
- <arg name="display" direction="in" type="s" />
<arg name="active" direction="in" type="u" />
</method>
<!--
- DisplayItemsDialog (display : STRING) : VOID
+ DisplayItemsDialog (active : UINT) : VOID
- display : The display on which to show the dialog or ""
- to use the default screen of the panel.
+ active : The active panel number in the dialog, starting
+ at zero.
-->
<method name="DisplayItemsDialog">
- <arg name="display" direction="in" type="s" />
<arg name="active" direction="in" type="u" />
</method>
diff --git a/panel/panel-dbus-service.c b/panel/panel-dbus-service.c
index 65986b2..c2492f2 100644
--- a/panel/panel-dbus-service.c
+++ b/panel/panel-dbus-service.c
@@ -154,7 +154,6 @@ panel_dbus_service_finalize (GObject *object)
static gboolean
panel_dbus_service_display_preferences_dialog (PanelDBusService *service,
- const gchar *display,
guint active,
GError **error)
{
@@ -179,15 +178,13 @@ panel_dbus_service_display_preferences_dialog (PanelDBusService *service,
static gboolean
panel_dbus_service_display_items_dialog (PanelDBusService *service,
- const gchar *display,
guint active,
GError **error)
{
panel_return_val_if_fail (PANEL_IS_DBUS_SERVICE (service), FALSE);
panel_return_val_if_fail (error == NULL || *error == NULL, FALSE);
- /* TODO: open/move the dialog to the correct screen */
- /* TODO: active window */
+ /* TODO: active window, set screen too */
/* show the items dialog */
panel_item_dialog_show ();
@@ -335,23 +332,22 @@ panel_dbus_service_set_property (PanelDBusService *service,
panel_return_val_if_fail (property != NULL, FALSE);
panel_return_val_if_fail (value && G_TYPE_CHECK_VALUE (value), FALSE);
- /* get the module factory */
- factory = panel_module_factory_get ();
-
- /* get the plugin */
- provider = panel_module_factory_get_plugin (factory, plugin_id);
- if (G_LIKELY (provider))
+ /* check if this is a plugin property change */
+ if (strcmp (property, "ProviderSignal") == 0)
{
- if (strcmp ("Expand", property) == 0)
- g_signal_emit_by_name (G_OBJECT (provider), "expand-changed", g_value_get_boolean (value));
- else if (strcmp ("MoveItem", property) == 0)
- g_signal_emit_by_name (G_OBJECT (provider), "move-item", 0);
- else if (strcmp ("Remove", property) == 0)
- gtk_widget_destroy (GTK_WIDGET (provider));
- }
+ /* get the module factory */
+ factory = panel_module_factory_get ();
- /* release the factory */
- g_object_unref (G_OBJECT (factory));
+ /* get the plugin from the factory */
+ provider = panel_module_factory_get_plugin (factory, plugin_id);
+
+ /* emit the signal for the local plugin provider */
+ if (G_LIKELY (provider))
+ g_signal_emit_by_name (G_OBJECT (provider), "provider-signal", g_value_get_uint (value));
+
+ /* release the factory */
+ g_object_unref (G_OBJECT (factory));
+ }
return TRUE;
}
diff --git a/panel/panel-plugin-external.c b/panel/panel-plugin-external.c
index dc6ce55..967a690 100644
--- a/panel/panel-plugin-external.c
+++ b/panel/panel-plugin-external.c
@@ -56,6 +56,8 @@ static void panel_plugin_external_set_screen_position (XfcePanelPluginPr
XfceScreenPosition screen_position);
static void panel_plugin_external_save (XfcePanelPluginProvider *provider);
static void panel_plugin_external_set_sensitive (PanelPluginExternal *external);
+static void panel_plugin_external_provider_signal (PanelPluginExternal *external,
+ ProviderSignal signal);
static void panel_plugin_external_set_property (PanelPluginExternal *external,
const gchar *property,
const GValue *value);
@@ -80,12 +82,9 @@ struct _PanelPluginExternal
/* the module */
PanelModule *module;
- /* process pid */
- GPid pid;
-
/* whether the plug is embedded */
guint plug_embedded : 1;
-
+
/* dbus message queue */
GSList *dbus_queue;
};
@@ -132,12 +131,14 @@ panel_plugin_external_init (PanelPluginExternal *external)
external->id = NULL;
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);
+
+ /* connect signal to monitor the remove plugin signal */
+ g_signal_connect (G_OBJECT (external), "provider-signal", G_CALLBACK (panel_plugin_external_provider_signal), NULL);
}
@@ -165,7 +166,7 @@ panel_plugin_external_finalize (GObject *object)
/* cleanup */
g_free (external->id);
g_strfreev (external->arguments);
-
+
/* free the queue */
for (li = external->dbus_queue; li != NULL; li = li->next)
{
@@ -227,12 +228,12 @@ panel_plugin_external_realize (GtkWidget *widget)
/* close the argv */
argv[argc - 1] = NULL;
-
+
/* get the widget screen */
screen = gtk_widget_get_screen (widget);
/* spawn the proccess */
- succeed = gdk_spawn_on_screen (screen, NULL, argv, NULL, 0, NULL, NULL, &external->pid, &error);
+ succeed = gdk_spawn_on_screen (screen, NULL, argv, NULL, 0, NULL, NULL, NULL, &error);
/* cleanup */
g_free (socket_id);
@@ -254,15 +255,18 @@ panel_plugin_external_realize (GtkWidget *widget)
static void
panel_plugin_external_unrealize (GtkWidget *widget)
{
- //PanelPluginExternal *external = PANEL_PLUGIN_EXTERNAL (widget);
- //GValue value = { 0, };
+ PanelPluginExternal *external = PANEL_PLUGIN_EXTERNAL (widget);
+ GValue value = { 0, };
/* create dummy value */
- //g_value_init (&value, G_TYPE_BOOLEAN);
- //g_value_set_boolean (&value, FALSE);
-
- /* send */
- //panel_dbus_service_set_plugin_property (external->id,
+ g_value_init (&value, G_TYPE_BOOLEAN);
+ g_value_set_boolean (&value, FALSE);
+
+ /* send (don't queue here) */
+ panel_dbus_service_set_plugin_property (external->id, "Quit", &value);
+
+ /* unset */
+ g_value_unset (&value);
return (*GTK_WIDGET_CLASS (panel_plugin_external_parent_class)->unrealize) (widget);
}
@@ -277,7 +281,11 @@ panel_plugin_external_plug_removed (GtkSocket *socket)
gint response;
gchar *filename, *path;
PanelWindow *window;
-
+
+ /* leave when the plugin was already removed */
+ if (external->plug_embedded == FALSE)
+ return FALSE;
+
/* plug has been removed */
external->plug_embedded = FALSE;
@@ -295,9 +303,6 @@ panel_plugin_external_plug_removed (GtkSocket *socket)
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
- /* reset the pid */
- external->pid = 0;
-
/* unrealize and hide the socket */
gtk_widget_unrealize (GTK_WIDGET (socket));
gtk_widget_hide (GTK_WIDGET (socket));
@@ -358,10 +363,10 @@ 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 */
@@ -372,7 +377,7 @@ panel_plugin_external_plug_added (GtkSocket *socket)
g_value_unset (&data->value);
g_slice_free (QueuedData, data);
}
-
+
/* free the list */
g_slist_free (external->dbus_queue);
external->dbus_queue = NULL;
@@ -409,11 +414,11 @@ panel_plugin_external_set_property (PanelPluginExternal *external,
const 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 */
@@ -426,12 +431,12 @@ panel_plugin_external_set_property (PanelPluginExternal *external,
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);
}
}
-
+
@@ -440,17 +445,17 @@ panel_plugin_external_set_size (XfcePanelPluginProvider *provider,
gint size)
{
GValue value = { 0, };
-
+
panel_return_if_fail (PANEL_IS_PLUGIN_EXTERNAL (provider));
panel_return_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (provider));
-
+
/* create a new value */
g_value_init (&value, G_TYPE_INT);
g_value_set_int (&value, size);
/* send the value */
panel_plugin_external_set_property (PANEL_PLUGIN_EXTERNAL (provider), "Size", &value);
-
+
/* unset */
g_value_unset (&value);
}
@@ -462,7 +467,7 @@ panel_plugin_external_set_orientation (XfcePanelPluginProvider *provider,
GtkOrientation orientation)
{
GValue value = { 0, };
-
+
panel_return_if_fail (PANEL_IS_PLUGIN_EXTERNAL (provider));
panel_return_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (provider));
@@ -472,7 +477,7 @@ panel_plugin_external_set_orientation (XfcePanelPluginProvider *provider,
/* send the value */
panel_plugin_external_set_property (PANEL_PLUGIN_EXTERNAL (provider), "Orientation", &value);
-
+
/* unset */
g_value_unset (&value);
}
@@ -484,7 +489,7 @@ panel_plugin_external_set_screen_position (XfcePanelPluginProvider *provider,
XfceScreenPosition screen_position)
{
GValue value = { 0, };
-
+
panel_return_if_fail (PANEL_IS_PLUGIN_EXTERNAL (provider));
panel_return_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (provider));
@@ -494,7 +499,7 @@ panel_plugin_external_set_screen_position (XfcePanelPluginProvider *provider,
/* send the value */
panel_plugin_external_set_property (PANEL_PLUGIN_EXTERNAL (provider), "ScreenPosition", &value);
-
+
/* unset */
g_value_unset (&value);
}
@@ -505,17 +510,17 @@ 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_plugin_external_set_property (PANEL_PLUGIN_EXTERNAL (provider), "Save", &value);
-
+
/* unset */
g_value_unset (&value);
}
@@ -526,22 +531,41 @@ static void
panel_plugin_external_set_sensitive (PanelPluginExternal *external)
{
GValue value = { 0, };
-
+
panel_return_if_fail (PANEL_IS_PLUGIN_EXTERNAL (external));
-
+
/* set the boolean */
g_value_init (&value, G_TYPE_BOOLEAN);
g_value_set_boolean (&value, GTK_WIDGET_IS_SENSITIVE (external));
/* send message */
panel_plugin_external_set_property (external, "Sensitive", &value);
-
+
/* unset */
g_value_unset (&value);
}
+static void
+panel_plugin_external_provider_signal (PanelPluginExternal *external,
+ ProviderSignal signal)
+{
+ panel_return_if_fail (PANEL_IS_PLUGIN_EXTERNAL (external));
+
+ /* only handle the remove signal, everything else is handles in the panel-application */
+ if (signal == REMOVE_PLUGIN)
+ {
+ /* we're forced removing the plugin, don't ask for a restart */
+ external->plug_embedded = FALSE;
+
+ /* destroy ourselfs, unrealize will close the plugin */
+ gtk_widget_destroy (GTK_WIDGET (external));
+ }
+}
+
+
+
XfcePanelPluginProvider *
panel_plugin_external_new (PanelModule *module,
const gchar *name,
@@ -572,7 +596,7 @@ panel_plugin_external_set_background_alpha (PanelPluginExternal *external,
gint percentage)
{
GValue value = { 0, };
-
+
panel_return_if_fail (PANEL_IS_PLUGIN_EXTERNAL (external));
/* set the boolean */
@@ -581,7 +605,7 @@ panel_plugin_external_set_background_alpha (PanelPluginExternal *external,
/* send message */
panel_plugin_external_set_property (external, "BackgroundAlpha", &value);
-
+
/* unset */
g_value_unset (&value);
}
@@ -593,7 +617,7 @@ panel_plugin_external_set_active_panel (PanelPluginExternal *external,
gboolean active)
{
GValue value = { 0, };
-
+
panel_return_if_fail (PANEL_IS_PLUGIN_EXTERNAL (external));
/* set the boolean */
@@ -602,7 +626,7 @@ panel_plugin_external_set_active_panel (PanelPluginExternal *external,
/* send message */
panel_plugin_external_set_property (external, "ActivePanel", &value);
-
+
/* unset */
g_value_unset (&value);
}
diff --git a/wrapper/main.c b/wrapper/main.c
index 9c57c24..fb09244 100644
--- a/wrapper/main.c
+++ b/wrapper/main.c
@@ -114,140 +114,65 @@ dbus_proxy_provider_property_changed (DBusGProxy *dbus_proxy,
static void
-dbus_proxy_provider_expand_changed (XfcePanelPluginProvider *provider,
- gboolean expand,
- DBusGProxy *dbus_proxy)
-{
- GValue value = { 0, };
- GError *error = NULL;
-
- panel_return_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (provider));
-
- /* init the value */
- g_value_init (&value, G_TYPE_BOOLEAN);
- g_value_set_boolean (&value, expand);
-
- /* call */
- if (!wrapper_dbus_client_set_property (dbus_proxy, xfce_panel_plugin_provider_get_id (provider),
- "Expand", &value, &error))
- {
- g_critical ("DBus error: %s", error->message);
- g_error_free (error);
- }
-
- /* unset */
- g_value_unset (&value);
-}
-
-
-
-static void
-dbus_proxy_provider_move_item (XfcePanelPluginProvider *provider,
- DBusGProxy *dbus_proxy)
-{
- GError *error = NULL;
-
- panel_return_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (provider));
-
- /* call */
- if (!wrapper_dbus_client_set_property (dbus_proxy, xfce_panel_plugin_provider_get_id (provider),
- "MoveItem", NULL, &error))
- {
- g_critical ("DBus error: %s", error->message);
- g_error_free (error);
- }
-}
-
-
-
-static void
-dbus_proxy_provider_add_new_items (XfcePanelPluginProvider *provider,
- DBusGProxy *dbus_proxy)
+dbus_proxy_provider_signal (XfcePanelPluginProvider *provider,
+ ProviderSignal signal,
+ DBusGProxy *dbus_proxy)
{
- gchar *name;
- GError *error = NULL;
- guint active_panel = 0;
- GValue value = { 0, };
-
- panel_return_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (provider));
-
- /* try to get the panel number of this plugin */
- if (wrapper_dbus_client_get_property (dbus_proxy, xfce_panel_plugin_provider_get_id (provider),
- "PanelNumber", &value, NULL))
- {
- /* set the panel number */
- active_panel = g_value_get_uint (&value);
-
- /* unset */
- g_value_unset (&value);
- }
-
- /* create a screen name */
- name = gdk_screen_make_display_name (gtk_widget_get_screen (GTK_WIDGET (provider)));
-
- /* call */
- if (!wrapper_dbus_client_display_items_dialog (dbus_proxy, name, 0, &error))
- {
- g_critical ("DBus error: %s", error->message);
- g_error_free (error);
- }
-
- /* cleanup */
- g_free (name);
-}
-
+ GValue value = { 0, };
+ GError *error = NULL;
+ const gchar *id;
+ guint active_panel = 0;
+ gboolean result = FALSE;
-
-static void
-dbus_proxy_provider_panel_preferences (XfcePanelPluginProvider *provider,
- DBusGProxy *dbus_proxy)
-{
- gchar *name;
- GError *error = NULL;
- guint active_panel = 0;
- GValue value = { 0, };
-
panel_return_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (provider));
- /* try to get the panel number of this plugin */
- if (wrapper_dbus_client_get_property (dbus_proxy, xfce_panel_plugin_provider_get_id (provider),
- "PanelNumber", &value, NULL))
- {
- /* set the panel number */
- active_panel = g_value_get_uint (&value);
+ /* get the plugin id */
+ id = xfce_panel_plugin_provider_get_id (provider);
- /* unset */
- g_value_unset (&value);
- }
-
- /* create a screen name */
- name = gdk_screen_make_display_name (gtk_widget_get_screen (GTK_WIDGET (provider)));
-
- /* call */
- if (!wrapper_dbus_client_display_preferences_dialog (dbus_proxy, name, 0, &error))
+ /* handle the signal */
+ switch (signal)
{
- g_critical ("DBus error: %s", error->message);
- g_error_free (error);
+ case MOVE_PLUGIN:
+ case REMOVE_PLUGIN:
+ case EXPAND_PLUGIN:
+ case COLLAPSE_PLUGIN:
+ case LOCK_PANEL:
+ case UNLOCK_PANEL:
+ /* initialize the value */
+ g_value_init (&value, G_TYPE_UINT);
+ g_value_set_uint (&value, signal);
+
+ /* invoke the method */
+ result = wrapper_dbus_client_set_property (dbus_proxy, id, "ProviderSignal", &value, &error);
+
+ /* unset */
+ g_value_unset (&value);
+ break;
+
+ case ADD_NEW_ITEMS:
+ case PANEL_PREFERENCES:
+ /* try to get the panel number of this plugin */
+ if (wrapper_dbus_client_get_property (dbus_proxy, id, "PanelNumber", &value, NULL))
+ {
+ /* set the panel number */
+ active_panel = g_value_get_uint (&value);
+ g_value_unset (&value);
+ }
+
+ /* invoke the methode */
+ if (signal == ADD_NEW_ITEMS)
+ result = wrapper_dbus_client_display_items_dialog (dbus_proxy, active_panel, &error);
+ else
+ result = wrapper_dbus_client_display_preferences_dialog (dbus_proxy, active_panel, &error);
+ break;
+
+ default:
+ g_critical ("Plugin '%s' received an unknown provider signal %d.", id, signal);
+ return;
}
- /* cleanup */
- g_free (name);
-}
-
-
-
-static void
-dbus_proxy_provider_remove (XfcePanelPluginProvider *provider,
- DBusGProxy *dbus_proxy)
-{
- GError *error = NULL;
-
- panel_return_if_fail (XFCE_IS_PANEL_PLUGIN_PROVIDER (provider));
-
- /* call */
- if (!wrapper_dbus_client_set_property (dbus_proxy,
- xfce_panel_plugin_provider_get_id (provider),
- "Remove", NULL, &error))
+ /* handle errors */
+ if (result == FALSE)
{
g_critical ("DBus error: %s", error->message);
g_error_free (error);
@@ -389,11 +314,7 @@ main (gint argc, gchar **argv)
g_object_set_qdata (G_OBJECT (provider), plug_quark, plug);
/* connect provider signals */
- g_signal_connect (G_OBJECT (provider), "expand-changed", G_CALLBACK (dbus_proxy_provider_expand_changed), dbus_proxy);
- g_signal_connect (G_OBJECT (provider), "move-item", G_CALLBACK (dbus_proxy_provider_move_item), dbus_proxy);
- g_signal_connect (G_OBJECT (provider), "add-new-items", G_CALLBACK (dbus_proxy_provider_add_new_items), dbus_proxy);
- g_signal_connect (G_OBJECT (provider), "panel-preferences", G_CALLBACK (dbus_proxy_provider_panel_preferences), dbus_proxy);
- g_signal_connect (G_OBJECT (provider), "destroy", G_CALLBACK (dbus_proxy_provider_remove), dbus_proxy);
+ g_signal_connect (G_OBJECT (provider), "provider-signal", G_CALLBACK (dbus_proxy_provider_signal), dbus_proxy);
/* connect dbus property change signal */
dbus_g_proxy_connect_signal (dbus_proxy, "PropertyChanged", G_CALLBACK (dbus_proxy_provider_property_changed), provider, NULL);
@@ -418,9 +339,8 @@ main (gint argc, gchar **argv)
/* close the module */
g_module_close (module);
- /* release dbus */
+ /* release dbus proxy, connection is shared, so no need to unref it */
g_object_unref (G_OBJECT (dbus_proxy));
- g_object_unref (G_OBJECT (dbus_connection));
return EXIT_SUCCESS;
}
More information about the Xfce4-commits
mailing list