]> git.0d.be Git - empathy.git/blob - src/empathy-debugger.c
Merge remote-tracking branch 'origin/gnome-3-8'
[empathy.git] / src / empathy-debugger.c
1 /*
2  * Copyright (C) 2005-2007 Imendio AB
3  * Copyright (C) 2007-2010 Collabora Ltd.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  */
19
20 #include "config.h"
21
22 #include <glib/gi18n.h>
23
24 #include "empathy-debug-window.h"
25 #include "empathy-ui-utils.h"
26
27 #define EMPATHY_DEBUGGER_DBUS_NAME "org.gnome.Empathy.Debugger"
28
29 static GtkWidget *window = NULL;
30 static gchar *service = NULL;
31
32 static void
33 app_activate (GApplication *app)
34 {
35   if (window == NULL)
36     {
37       window = empathy_debug_window_new (NULL);
38
39       gtk_application_add_window (GTK_APPLICATION (app),
40           GTK_WINDOW (window));
41     }
42   else
43     {
44       gtk_window_present (GTK_WINDOW (window));
45     }
46
47   if (!tp_str_empty (service))
48     empathy_debug_window_show (EMPATHY_DEBUG_WINDOW (window),
49         service);
50 }
51
52 static void
53 on_show_service_cb (GAction  *action,
54     GVariant *parameter,
55     gpointer  data)
56 {
57   g_free (service);
58   service = g_variant_dup_string (parameter, NULL);
59 }
60
61 static gboolean
62 local_cmdline (GApplication *app,
63     gchar ***arguments,
64     gint *exit_status)
65 {
66   GError *error = NULL;
67   GSimpleAction *action;
68   gchar **argv;
69   gint argc;
70   gint i;
71   gboolean retval = TRUE;
72
73   GOptionContext *optcontext;
74   GOptionEntry options[] = {
75       { "show-service", 's',
76         0, G_OPTION_ARG_STRING, &service,
77         N_("Show a particular service"),
78         NULL },
79       { NULL }
80   };
81
82   optcontext = g_option_context_new (N_("- Empathy Debugger"));
83   g_option_context_add_group (optcontext, gtk_get_option_group (FALSE));
84   g_option_context_add_main_entries (optcontext, options, GETTEXT_PACKAGE);
85   g_option_context_set_translation_domain (optcontext, GETTEXT_PACKAGE);
86
87   action = g_simple_action_new ("show-service", G_VARIANT_TYPE_STRING);
88   g_signal_connect (action, "activate", G_CALLBACK (on_show_service_cb), app);
89   g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (action));
90   g_object_unref (action);
91
92   argv = *arguments;
93   for (i = 0; argv[i] != NULL; i++)
94     argc++;
95
96   if (!g_option_context_parse (optcontext, &argc, &argv, &error))
97     {
98       g_print ("%s\nRun '%s --help' to see a full list of available command "
99           "line options.\n",
100           error->message, argv[0]);
101
102       g_clear_error (&error);
103       *exit_status = EXIT_FAILURE;
104     }
105   else
106     {
107       if (g_application_register (app, NULL, &error))
108         {
109           GVariant *parameter = g_variant_new_string (service ? service : "");
110           g_action_group_activate_action (G_ACTION_GROUP (app), "show-service", parameter);
111
112           g_application_activate (app);
113         }
114       else
115         {
116           g_warning("Impossible to register empathy-debugger: %s", error->message);
117           g_clear_error (&error);
118           *exit_status = EXIT_FAILURE;
119         }
120     }
121
122   g_option_context_free (optcontext);
123
124   return retval;
125 }
126
127 int
128 main (int argc,
129     char **argv)
130 {
131   GtkApplication *app;
132   GApplicationClass *app_class;
133   gint retval;
134
135   textdomain (GETTEXT_PACKAGE);
136
137   app = gtk_application_new (EMPATHY_DEBUGGER_DBUS_NAME, G_APPLICATION_FLAGS_NONE);
138   app_class = G_APPLICATION_CLASS (G_OBJECT_GET_CLASS (app));
139   app_class->local_command_line = local_cmdline;
140   app_class->activate = app_activate;
141
142   g_set_application_name (_("Empathy Debugger"));
143
144   /* Make empathy and empathy-debugger appear as the same app in gnome-shell */
145   gdk_set_program_class ("Empathy");
146   gtk_window_set_default_icon_name ("empathy");
147
148   retval = g_application_run (G_APPLICATION (app), argc, argv);
149
150   g_object_unref (app);
151
152   return retval;
153 }