[Xfce4-commits] <xfce4-panel:devel> * Partly implements opening the panel dialog for a panel number, so we can send that for external plugins. Also implement it for the command line options. * Make Gtk init warnings more usefull.
Nick Schermer
nick at xfce.org
Tue Aug 11 20:22:57 CEST 2009
Updating branch refs/heads/devel
to fa9a56e6efad4763bb67a4fdafe6d754c8da80ab (commit)
from 23e092cf7a90e0b331d96af04b0c72adf7a6a716 (commit)
commit fa9a56e6efad4763bb67a4fdafe6d754c8da80ab
Author: Nick Schermer <nick at xfce.org>
Date: Tue Aug 12 21:00:03 2008 +0200
* Partly implements opening the panel dialog for a panel number, so
we can send that for external plugins. Also implement it for the
command line options.
* Make Gtk init warnings more usefull.
panel/main.c | 79 +++++++++++++++++++++++++++--------
panel/panel-dbus-client.c | 6 ++-
panel/panel-dbus-client.h | 2 +
panel/panel-dbus-service-infos.xml | 8 +++-
panel/panel-dbus-service.c | 14 +++++-
wrapper/main.c | 19 ++++++---
6 files changed, 97 insertions(+), 31 deletions(-)
diff --git a/panel/main.c b/panel/main.c
index 6ebe009..66abf8b 100644
--- a/panel/main.c
+++ b/panel/main.c
@@ -42,10 +42,12 @@
#include <panel/panel-dbus-service.h>
#include <panel/panel-dbus-client.h>
+#define PANEL_CALLBACK_OPTION G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, callback_handler
-static gboolean opt_preferences = FALSE;
-static gboolean opt_add_items = FALSE;
+
+static gint opt_preferences = -1;
+static gint opt_add_items = -1;
static gboolean opt_save = FALSE;
static gchar *opt_add = NULL;
static gboolean opt_restart = FALSE;
@@ -56,11 +58,19 @@ static gchar **opt_arguments = NULL;
+static gboolean callback_handler (const gchar *name,
+ const gchar *value,
+ gpointer user_data,
+ GError **error);
+static void signal_handler (gint signum);
+
+
+
/* command line options */
static GOptionEntry option_entries[] =
{
- { "preferences", 'p', 0, G_OPTION_ARG_NONE, &opt_preferences, N_("Show the 'Panel Preferences' dialog"), NULL },
- { "add-items", 'a', 0, G_OPTION_ARG_NONE, &opt_add_items, N_("Show the 'Add New Items' dialog"), NULL },
+ { "preferences", 'p', PANEL_CALLBACK_OPTION, N_("Show the 'Panel Preferences' dialog"), N_("Panel Number") },
+ { "add-items", 'a', PANEL_CALLBACK_OPTION, N_("Show the 'Add New Items' dialog"), N_("Panel Number") },
{ "save", 's', 0, G_OPTION_ARG_NONE, &opt_save, N_("Save the panel configuration"), NULL },
{ "add", '\0', 0, G_OPTION_ARG_STRING, &opt_add, N_("Add a new plugin to the panel"), N_("PLUGIN NAME") },
{ "restart", 'r', 0, G_OPTION_ARG_NONE, &opt_restart, N_("Restart the running panel instance"), NULL },
@@ -73,6 +83,37 @@ static GOptionEntry option_entries[] =
+static gboolean
+callback_handler (const gchar *name,
+ const gchar *value,
+ gpointer user_data,
+ GError **error)
+{
+ /* this should actually never happen */
+ if (G_UNLIKELY (name == NULL))
+ return FALSE;
+
+ switch (*(name + 1))
+ {
+ case 'p':
+ /* set the option */
+ opt_preferences = value ? MAX (0, atoi (value)) : 0;
+ break;
+
+ case 'a':
+ /* set the option */
+ opt_add_items = value ? MAX (0, atoi (value)) : 0;
+ break;
+
+ default:
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+
static void
signal_handler (gint signum)
{
@@ -113,20 +154,22 @@ main (gint argc, gchar **argv)
/* initialize gtk+ */
if (!gtk_init_with_args (&argc, &argv, _("[ARGUMENTS...]"), option_entries, GETTEXT_PACKAGE, &error))
{
- /* print an error message */
- if (error == NULL)
- {
- /* print warning */
- g_critical ("Failed to open display: %s", gdk_get_display_arg_name ());
- }
- else
+ if (G_LIKELY (error))
{
- /* print warning */
- g_critical (error->message);
+ /* print error */
+ g_print ("%s: %s.\n", G_LOG_DOMAIN, error->message);
+ g_print (_("Type '%s --help' for usage."), G_LOG_DOMAIN);
+ g_print ("\n");
/* cleanup */
g_error_free (error);
- }
+ }
+ else
+ {
+ g_error ("Unable to open display.");
+ }
+
+ return EXIT_FAILURE;
/* leave */
return EXIT_FAILURE;
@@ -144,17 +187,17 @@ main (gint argc, gchar **argv)
return EXIT_SUCCESS;
}
- else if (opt_preferences)
+ 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, &error);
+ result = panel_dbus_client_display_preferences_dialog (NULL, opt_preferences, &error);
goto dbus_return;
}
- else if (opt_add_items)
+ 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, &error);
+ result = panel_dbus_client_display_items_dialog (NULL, opt_add_items, &error);
goto dbus_return;
}
diff --git a/panel/panel-dbus-client.c b/panel/panel-dbus-client.c
index 05101ad..0e4cd38 100644
--- a/panel/panel-dbus-client.c
+++ b/panel/panel-dbus-client.c
@@ -65,6 +65,7 @@ panel_dbus_client_check_client_running (GError **error)
gboolean
panel_dbus_client_display_preferences_dialog (GdkScreen *screen,
+ guint active,
GError **error)
{
gchar *name;
@@ -87,7 +88,7 @@ panel_dbus_client_display_preferences_dialog (GdkScreen *screen,
name = gdk_screen_make_display_name (screen);
/* call */
- result = _panel_dbus_client_display_preferences_dialog (dbus_proxy, name, error);
+ result = _panel_dbus_client_display_preferences_dialog (dbus_proxy, name, active, error);
/* cleanup */
g_free (name);
@@ -100,6 +101,7 @@ panel_dbus_client_display_preferences_dialog (GdkScreen *screen,
gboolean
panel_dbus_client_display_items_dialog (GdkScreen *screen,
+ guint active,
GError **error)
{
gchar *name;
@@ -122,7 +124,7 @@ panel_dbus_client_display_items_dialog (GdkScreen *screen,
name = gdk_screen_make_display_name (screen);
/* call */
- result = _panel_dbus_client_display_items_dialog (dbus_proxy, name, error);
+ result = _panel_dbus_client_display_items_dialog (dbus_proxy, name, active, error);
/* cleanup */
g_free (name);
diff --git a/panel/panel-dbus-client.h b/panel/panel-dbus-client.h
index 38617d2..6b6193e 100644
--- a/panel/panel-dbus-client.h
+++ b/panel/panel-dbus-client.h
@@ -26,9 +26,11 @@
gboolean panel_dbus_client_check_client_running (GError **error);
gboolean panel_dbus_client_display_preferences_dialog (GdkScreen *screen,
+ guint active,
GError **error);
gboolean panel_dbus_client_display_items_dialog (GdkScreen *screen,
+ 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 5c08adb..3c88bb4 100644
--- a/panel/panel-dbus-service-infos.xml
+++ b/panel/panel-dbus-service-infos.xml
@@ -31,9 +31,12 @@
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="display" direction="in" type="s" />
+ <arg name="active" direction="in" type="u" />
</method>
<!--
@@ -43,7 +46,8 @@
to use the default screen of the panel.
-->
<method name="DisplayItemsDialog">
- <arg name="display" direction="in" type="s" />
+ <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 8d9c847..b204a9a 100644
--- a/panel/panel-dbus-service.c
+++ b/panel/panel-dbus-service.c
@@ -154,16 +154,22 @@ panel_dbus_service_finalize (GObject *object)
static gboolean
panel_dbus_service_display_preferences_dialog (PanelDBusService *service,
const gchar *display,
+ guint active,
GError **error)
{
+ PanelApplication *application;
+
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 */
- g_message ("open on screen %s", display);
+ /* get the current application */
+ application = panel_application_get ();
/* show the prefernces dialog */
- panel_preferences_dialog_show (NULL);
+ panel_preferences_dialog_show (panel_application_get_window (application, active));
+
+ /* release the application */
+ g_object_unref (G_OBJECT (application));
return TRUE;
}
@@ -173,12 +179,14 @@ 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 */
/* show the items dialog */
panel_item_dialog_show ();
diff --git a/wrapper/main.c b/wrapper/main.c
index d38d341..abc0c48 100644
--- a/wrapper/main.c
+++ b/wrapper/main.c
@@ -151,7 +151,7 @@ dbus_proxy_provider_move_item (XfcePanelPluginProvider *provider,
/* call */
if (!wrapper_dbus_client_set_property (dbus_proxy, xfce_panel_plugin_provider_get_id (provider),
- "MoveItem", NULL, NULL))
+ "MoveItem", NULL, &error))
{
g_critical ("DBus error: %s", error->message);
g_error_free (error);
@@ -173,7 +173,7 @@ dbus_proxy_provider_add_new_items (XfcePanelPluginProvider *provider,
name = gdk_screen_make_display_name (gtk_widget_get_screen (GTK_WIDGET (provider)));
/* call */
- if (!wrapper_dbus_client_display_items_dialog (dbus_proxy, name, NULL))
+ if (!wrapper_dbus_client_display_items_dialog (dbus_proxy, name, 0, &error))
{
g_critical ("DBus error: %s", error->message);
g_error_free (error);
@@ -198,7 +198,8 @@ dbus_proxy_provider_panel_preferences (XfcePanelPluginProvider *provider,
name = gdk_screen_make_display_name (gtk_widget_get_screen (GTK_WIDGET (provider)));
/* call */
- if (!wrapper_dbus_client_display_preferences_dialog (dbus_proxy, name, &error))
+ /* TODO implement active panel */
+ if (!wrapper_dbus_client_display_preferences_dialog (dbus_proxy, name, 0, &error))
{
g_critical ("DBus error: %s", error->message);
g_error_free (error);
@@ -214,12 +215,18 @@ 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 */
- wrapper_dbus_client_set_property (dbus_proxy,
- xfce_panel_plugin_provider_get_id (provider),
- "Remove", NULL, NULL);
+ if (!wrapper_dbus_client_set_property (dbus_proxy,
+ xfce_panel_plugin_provider_get_id (provider),
+ "Remove", NULL, &error))
+ {
+ g_critical ("DBus error: %s", error->message);
+ g_error_free (error);
+ }
}
More information about the Xfce4-commits
mailing list