From ab0576f1f00172c4edc71595b0c2c9dd9ce94068 Mon Sep 17 00:00:00 2001 From: Emanuele Aina Date: Fri, 1 Mar 2013 11:45:04 +0100 Subject: [PATCH] shell: Expose panel launching with DBus-activation Turn Control Center in a DBus-activable service and export a 'launch-panel' GAction which accepts a tuple containing the id of the desired panel and its parameters as a GVariant array. The snippet below show how the custom shortcuts section of the keyboard panel can be invoked by a external programs through DBus: GVariantBuilder *flags = g_variant_builder_new (G_VARIANT_TYPE_VARDICT); GVariantBuilder *params = g_variant_builder_new (G_VARIANT_TYPE ("av")); g_variant_builder_add (params, "v", g_variant_builder_end (flags)); g_variant_builder_add (params, "v", g_variant_new_string ("shortcuts")); g_variant_builder_add (params, "v", g_variant_new_string ("custom")); GVariant *v = g_variant_new ("(s@av)", "keyboard", g_variant_builder_end (params)); GApplication *gnomecc = g_application_new (id, G_APPLICATION_IS_LAUNCHER); if (!g_application_register (gnomecc, NULL, &error)) g_error ("Failed to register launcher for %s: %s", id, error->message); g_action_group_activate_action (G_ACTION_GROUP (gnomecc), "launch-panel", v); https://bugzilla.gnome.org/show_bug.cgi?id=696054 --- shell/Makefile.am | 10 +++++++- shell/cc-application.c | 30 ++++++++++++++++++++++++ shell/org.gnome.ControlCenter.service.in | 3 +++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 shell/org.gnome.ControlCenter.service.in diff --git a/shell/Makefile.am b/shell/Makefile.am index f9f9070de..68b70e91a 100644 --- a/shell/Makefile.am +++ b/shell/Makefile.am @@ -86,6 +86,13 @@ endif AM_CPPFLAGS = -DGNOMELOCALEDIR="\"$(datadir)/locale\"" +# Dbus service file +servicefiledir = $(datadir)/dbus-1/services +servicefile_in_files = org.gnome.ControlCenter.service.in +servicefile_DATA = $(servicefile_in_files:.service.in=.service) +$(servicefile_DATA): $(servicefile_in_files) Makefile + $(AM_V_GEN) sed -e 's|[@]bindir[@]|$(bindir)|' $< > $@ + sysdir = $(datadir)/applications sys_in_files = gnome-control-center.desktop.in sys_DATA = $(sys_in_files:.desktop.in=.desktop) @@ -99,10 +106,11 @@ completions/gnome-control-center: completions/gnome-control-center.in list-panel EXTRA_DIST = \ gnome-control-center.desktop.in.in \ + $(servicefile_in_files) \ $(completion_in_files) \ list-panel.sh -CLEANFILES = $(BUILT_SOURCES) $(completion_DATA) +CLEANFILES = $(BUILT_SOURCES) $(completion_DATA) $(servicefile_DATA) DISTCLEANFILES = gnome-control-center.desktop gnome-control-center.desktop.in noinst_PROGRAMS = test-hostname diff --git a/shell/cc-application.c b/shell/cc-application.c index 172345860..86f1c2d5c 100644 --- a/shell/cc-application.c +++ b/shell/cc-application.c @@ -95,6 +95,27 @@ help_activated (GSimpleAction *action, GDK_CURRENT_TIME, NULL); } +static void +launch_panel_activated (GSimpleAction *action, + GVariant *parameter, + gpointer user_data) +{ + CcApplication *self = CC_APPLICATION (user_data); + GError *error = NULL; + gchar *panel_id; + GVariant *parameters; + + g_variant_get (parameter, "(&s@av)", &panel_id, ¶meters); + g_debug ("gnome-control-center: 'launch-panel' activated for panel '%s' with %"G_GSIZE_FORMAT" arguments", + panel_id, g_variant_n_children (parameters)); + if (!cc_shell_set_active_panel_from_id (CC_SHELL (self->priv->window), panel_id, parameters, &error)) + { + g_warning ("Failed to activate the '%s' panel: %s", panel_id, error->message); + g_error_free (error); + } + g_variant_unref (parameters); +} + static int cc_application_command_line (GApplication *application, GApplicationCommandLine *command_line) @@ -280,6 +301,15 @@ cc_application_startup (GApplication *application) g_signal_connect (action, "activate", G_CALLBACK (cc_application_quit), self); g_object_unref (action); + /* Launch panel by id. The parameter is a (panel_id, array_of_panel_parameters) + * tuple. The GVariant-containing array usually is just the same array of + * strings that would be generated by passing panel-specific arguments on + * the command line. */ + action = g_simple_action_new ("launch-panel", G_VARIANT_TYPE ("(sav)")); + g_action_map_add_action (G_ACTION_MAP (application), G_ACTION (action)); + g_signal_connect (action, "activate", G_CALLBACK (launch_panel_activated), self); + g_object_unref (action); + menu = g_menu_new (); section = g_menu_new (); diff --git a/shell/org.gnome.ControlCenter.service.in b/shell/org.gnome.ControlCenter.service.in new file mode 100644 index 000000000..a51512957 --- /dev/null +++ b/shell/org.gnome.ControlCenter.service.in @@ -0,0 +1,3 @@ +[D-BUS Service] +Name=org.gnome.ControlCenter +Exec=@bindir@/gnome-control-center