]> git.0d.be Git - empathy.git/blob - src/empathy-debugger.c
remove released flag
[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-bus-names.h"
25 #include "empathy-debug-window.h"
26 #include "empathy-ui-utils.h"
27
28 static GtkWidget *window = NULL;
29 static gchar *service = NULL;
30
31 static void
32 app_activate (GApplication *app)
33 {
34   if (window == NULL)
35     {
36       window = empathy_debug_window_new (NULL);
37
38       gtk_application_add_window (GTK_APPLICATION (app),
39           GTK_WINDOW (window));
40     }
41   else
42     {
43       gtk_window_present (GTK_WINDOW (window));
44     }
45
46   if (!tp_str_empty (service))
47     empathy_debug_window_show (EMPATHY_DEBUG_WINDOW (window),
48         service);
49 }
50
51 static void
52 on_show_service_cb (GAction  *action,
53     GVariant *parameter,
54     gpointer  data)
55 {
56   g_free (service);
57   service = g_variant_dup_string (parameter, NULL);
58 }
59
60 static gboolean
61 local_cmdline (GApplication *app,
62     gchar ***arguments,
63     gint *exit_status)
64 {
65   GError *error = NULL;
66   GSimpleAction *action;
67   gchar **argv;
68   gint argc = 0;
69   gint i;
70   gboolean retval = TRUE;
71
72   GOptionContext *optcontext;
73   GOptionEntry options[] = {
74       { "show-service", 's',
75         0, G_OPTION_ARG_STRING, &service,
76         N_("Show a particular service"),
77         NULL },
78       { NULL }
79   };
80
81   optcontext = g_option_context_new (N_("- Empathy Debugger"));
82   g_option_context_add_group (optcontext, gtk_get_option_group (FALSE));
83   g_option_context_add_main_entries (optcontext, options, GETTEXT_PACKAGE);
84   g_option_context_set_translation_domain (optcontext, GETTEXT_PACKAGE);
85
86   action = g_simple_action_new ("show-service", G_VARIANT_TYPE_STRING);
87   g_signal_connect (action, "activate", G_CALLBACK (on_show_service_cb), app);
88   g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (action));
89   g_object_unref (action);
90
91   argv = *arguments;
92   for (i = 0; argv[i] != NULL; i++)
93     argc++;
94
95   if (!g_option_context_parse (optcontext, &argc, &argv, &error))
96     {
97       g_print ("%s\nRun '%s --help' to see a full list of available command "
98           "line options.\n",
99           error->message, argv[0]);
100
101       g_clear_error (&error);
102       *exit_status = EXIT_FAILURE;
103     }
104   else
105     {
106       if (g_application_register (app, NULL, &error))
107         {
108           GVariant *parameter = g_variant_new_string (service ? service : "");
109           g_action_group_activate_action (G_ACTION_GROUP (app), "show-service", parameter);
110
111           g_application_activate (app);
112         }
113       else
114         {
115           g_warning ("Impossible to register empathy-debugger: %s", error->message);
116           g_clear_error (&error);
117           *exit_status = EXIT_FAILURE;
118         }
119     }
120
121   g_option_context_free (optcontext);
122
123   return retval;
124 }
125
126 int
127 main (int argc,
128     char **argv)
129 {
130   GtkApplication *app;
131   GApplicationClass *app_class;
132   gint retval;
133
134   textdomain (GETTEXT_PACKAGE);
135
136   app = gtk_application_new (EMPATHY_DEBUGGER_BUS_NAME, G_APPLICATION_FLAGS_NONE);
137   app_class = G_APPLICATION_CLASS (G_OBJECT_GET_CLASS (app));
138   app_class->local_command_line = local_cmdline;
139   app_class->activate = app_activate;
140
141   g_set_application_name (_("Empathy Debugger"));
142
143   /* Make empathy and empathy-debugger appear as the same app in gnome-shell */
144   gdk_set_program_class ("Empathy");
145   gtk_window_set_default_icon_name ("empathy");
146
147   retval = g_application_run (G_APPLICATION (app), argc, argv);
148
149   g_object_unref (app);
150
151   return retval;
152 }