Add a way for panels to receive additional arguments.

This patch introduces the "argv" property to CcPanel. Panels that
wish to handle extra arguments shall override it and act
appropriately in the constructor.

https://bugzilla.gnome.org/show_bug.cgi?id=657093
This commit is contained in:
Giovanni Campagna 2011-08-22 14:22:37 +02:00
parent 67a28bb629
commit 1f9ae38c2f
7 changed files with 35 additions and 10 deletions

View file

@ -58,6 +58,7 @@ enum
{
PROP_0,
PROP_SHELL,
PROP_ARGV
};
G_DEFINE_ABSTRACT_TYPE (CcPanel, cc_panel, GTK_TYPE_BIN)
@ -79,6 +80,13 @@ cc_panel_set_property (GObject *object,
panel->priv->shell = g_value_get_object (value);
break;
case PROP_ARGV:
{
gchar **argv = g_value_get_boxed (value);
if (argv && argv[0])
g_warning ("Ignoring additional argument %s", argv[0]);
break;
}
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -199,6 +207,13 @@ cc_panel_class_init (CcPanelClass *klass)
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS
| G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property (object_class, PROP_SHELL, pspec);
pspec = g_param_spec_boxed ("argv",
"Argument vector",
"Additional arguments passed on the command line",
G_TYPE_STRV,
G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_property (object_class, PROP_ARGV, pspec);
}
static void

View file

@ -184,6 +184,7 @@ cc_shell_set_active_panel (CcShell *shell,
gboolean
cc_shell_set_active_panel_from_id (CcShell *shell,
const gchar *id,
const gchar **argv,
GError **error)
{
CcShellClass *class;
@ -202,7 +203,7 @@ cc_shell_set_active_panel_from_id (CcShell *shell,
}
else
{
return class->set_active_panel_from_id (shell, id, error);
return class->set_active_panel_from_id (shell, id, argv, error);
}
}

View file

@ -86,6 +86,7 @@ struct _CcShellClass
/* vfuncs */
gboolean (*set_active_panel_from_id) (CcShell *shell,
const gchar *id,
const gchar **argv,
GError **error);
GtkWidget * (*get_toplevel) (CcShell *shell);
};
@ -97,6 +98,7 @@ void cc_shell_set_active_panel (CcShell *shell,
CcPanel *panel);
gboolean cc_shell_set_active_panel_from_id (CcShell *shell,
const gchar *id,
const gchar **argv,
GError **error);
GtkWidget * cc_shell_get_toplevel (CcShell *shell);

View file

@ -63,7 +63,7 @@ layout_link_clicked (GtkLinkButton *button,
GError *error = NULL;
shell = cc_panel_get_shell (panel);
if (cc_shell_set_active_panel_from_id (shell, "region", &error) == FALSE)
if (cc_shell_set_active_panel_from_id (shell, "region", NULL, &error) == FALSE)
{
g_warning ("Failed to activate Region panel: %s", error->message);
g_error_free (error);

View file

@ -587,7 +587,7 @@ hearing_sound_preferences_clicked (GtkButton *button,
CcShell *shell;
shell = cc_panel_get_shell (CC_PANEL (panel));
cc_shell_set_active_panel_from_id (shell, "sound", NULL);
cc_shell_set_active_panel_from_id (shell, "sound", NULL, NULL);
}
static void
@ -639,7 +639,7 @@ typing_keyboard_preferences_clicked (GtkButton *button,
CcShell *shell;
shell = cc_panel_get_shell (CC_PANEL (panel));
cc_shell_set_active_panel_from_id (shell, "keyboard", NULL);
cc_shell_set_active_panel_from_id (shell, "keyboard", NULL, NULL);
}
static void
@ -709,7 +709,7 @@ pointing_mouse_preferences_clicked_cb (GtkButton *button,
CcShell *shell;
shell = cc_panel_get_shell (CC_PANEL (panel));
cc_shell_set_active_panel_from_id (shell, "mouse", NULL);
cc_shell_set_active_panel_from_id (shell, "mouse", NULL, NULL);
}
static void

View file

@ -127,7 +127,12 @@ application_command_line_cb (GApplication *application,
start_id = start_panels[0];
if (!cc_shell_set_active_panel_from_id (CC_SHELL (shell), start_id, &err))
if (start_panels[1])
g_debug ("Extra argument: %s", start_panels[1]);
else
g_debug ("No extra argument");
if (!cc_shell_set_active_panel_from_id (CC_SHELL (shell), start_id, (const gchar**)start_panels+1, &err))
{
g_warning ("Could not load setting panel \"%s\": %s", start_id,
(err) ? err->message : "Unknown error");

View file

@ -111,6 +111,7 @@ get_icon_name_from_g_icon (GIcon *gicon)
static void
activate_panel (GnomeControlCenter *shell,
const gchar *id,
const gchar **argv,
const gchar *desktop_file,
const gchar *name,
GIcon *gicon)
@ -153,7 +154,7 @@ activate_panel (GnomeControlCenter *shell,
const gchar *icon_name;
/* create the panel plugin */
panel = g_object_new (panel_type, "shell", shell, NULL);
panel = g_object_new (panel_type, "shell", shell, "argv", argv, NULL);
gtk_lock_button_set_permission (GTK_LOCK_BUTTON (priv->lock_button),
cc_panel_get_permission (CC_PANEL (panel)));
@ -234,7 +235,7 @@ item_activated_cb (CcShellCategoryView *view,
{
GError *err = NULL;
if (!cc_shell_set_active_panel_from_id (CC_SHELL (shell), id, &err))
if (!cc_shell_set_active_panel_from_id (CC_SHELL (shell), id, NULL, &err))
{
/* TODO: show message to user */
if (err)
@ -797,6 +798,7 @@ notebook_switch_page_cb (GtkNotebook *book,
static gboolean
_shell_set_active_panel_from_id (CcShell *shell,
const gchar *start_id,
const gchar **argv,
GError **err)
{
GtkTreeIter iter;
@ -852,8 +854,8 @@ _shell_set_active_panel_from_id (CcShell *shell,
{
gtk_notebook_remove_page (GTK_NOTEBOOK (priv->notebook), CAPPLET_PAGE);
activate_panel (GNOME_CONTROL_CENTER (shell), start_id, desktop, name,
gicon);
activate_panel (GNOME_CONTROL_CENTER (shell), start_id, argv, desktop,
name, gicon);
g_free (name);
g_free (desktop);