diff options
author | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2013-04-05 19:35:09 +0800 |
---|---|---|
committer | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2013-04-05 20:10:57 +0800 |
commit | f451000063d5e20b337d2a8d7b0d7faf6429af6b (patch) | |
tree | 6e7b28aac0a4ed9000232adc3e73208ad4e0c5ce /src | |
parent | 3a39843acfea0204024761b7103305fa39f15244 (diff) | |
download | gsoc2013-empathy-f451000063d5e20b337d2a8d7b0d7faf6429af6b.tar.gz gsoc2013-empathy-f451000063d5e20b337d2a8d7b0d7faf6429af6b.tar.zst gsoc2013-empathy-f451000063d5e20b337d2a8d7b0d7faf6429af6b.zip |
EmpathyDebugger: Use application activate and keep platform data
https://bugzilla.gnome.org/show_bug.cgi?id=697197
Diffstat (limited to 'src')
-rw-r--r-- | src/empathy-debugger.c | 70 |
1 files changed, 51 insertions, 19 deletions
diff --git a/src/empathy-debugger.c b/src/empathy-debugger.c index abb73ac44..fb4ef1e4c 100644 --- a/src/empathy-debugger.c +++ b/src/empathy-debugger.c @@ -30,7 +30,7 @@ static GtkWidget *window = NULL; static gchar *service = NULL; static void -activate_cb (GApplication *app) +app_activate (GApplication *app) { if (window == NULL) { @@ -44,20 +44,31 @@ activate_cb (GApplication *app) gtk_window_present (GTK_WINDOW (window)); } - if (service != NULL) + if (!tp_str_empty (service)) empathy_debug_window_show (EMPATHY_DEBUG_WINDOW (window), service); } -static gint -command_line_cb (GApplication *application, - GApplicationCommandLine *command_line, - gpointer user_data) +static void +on_show_service_cb (GAction *action, + GVariant *parameter, + gpointer data) +{ + g_free (service); + service = g_variant_dup_string (parameter, NULL); +} + +static gboolean +local_cmdline (GApplication *app, + gchar ***arguments, + gint *exit_status) { GError *error = NULL; + GSimpleAction *action; gchar **argv; gint argc; - gint retval = 0; + gint i; + gboolean retval = TRUE; GOptionContext *optcontext; GOptionEntry options[] = { @@ -69,10 +80,18 @@ command_line_cb (GApplication *application, }; optcontext = g_option_context_new (N_("- Empathy Debugger")); - g_option_context_add_group (optcontext, gtk_get_option_group (TRUE)); + g_option_context_add_group (optcontext, gtk_get_option_group (FALSE)); g_option_context_add_main_entries (optcontext, options, GETTEXT_PACKAGE); g_option_context_set_translation_domain (optcontext, GETTEXT_PACKAGE); - argv = g_application_command_line_get_arguments (command_line, &argc); + + action = g_simple_action_new ("show-service", G_VARIANT_TYPE_STRING); + g_signal_connect (action, "activate", G_CALLBACK (on_show_service_cb), app); + g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (action)); + g_object_unref (action); + + argv = *arguments; + for (i = 0; argv[i] != NULL; i++) + argc++; if (!g_option_context_parse (optcontext, &argc, &argv, &error)) { @@ -80,13 +99,27 @@ command_line_cb (GApplication *application, "line options.\n", error->message, argv[0]); - retval = 1; + g_clear_error (&error); + *exit_status = EXIT_FAILURE; + } + else + { + if (g_application_register (app, NULL, &error)) + { + GVariant *parameter = g_variant_new_string (service ? service : ""); + g_action_group_activate_action (G_ACTION_GROUP (app), "show-service", parameter); + + g_application_activate (app); + } + else + { + g_warning("Impossible to register empathy-debugger: %s", error->message); + g_clear_error (&error); + *exit_status = EXIT_FAILURE; + } } g_option_context_free (optcontext); - g_strfreev (argv); - - g_application_activate (application); return retval; } @@ -96,16 +129,15 @@ main (int argc, char **argv) { GtkApplication *app; + GApplicationClass *app_class; gint retval; - gtk_init (&argc, &argv); - empathy_gtk_init (); textdomain (GETTEXT_PACKAGE); - app = gtk_application_new (EMPATHY_DEBUGGER_DBUS_NAME, - G_APPLICATION_HANDLES_COMMAND_LINE); - g_signal_connect (app, "activate", G_CALLBACK (activate_cb), NULL); - g_signal_connect (app, "command-line", G_CALLBACK (command_line_cb), NULL); + app = gtk_application_new (EMPATHY_DEBUGGER_DBUS_NAME, G_APPLICATION_FLAGS_NONE); + app_class = G_APPLICATION_CLASS (G_OBJECT_GET_CLASS (app)); + app_class->local_command_line = local_cmdline; + app_class->activate = app_activate; g_set_application_name (_("Empathy Debugger")); |