]> git.0d.be Git - empathy.git/blob - src/empathy-debugger.c
Merge branch '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 activate_cb (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 (service != NULL)
48     empathy_debug_window_show (EMPATHY_DEBUG_WINDOW (window),
49         service);
50 }
51
52 static gint
53 command_line_cb (GApplication *application,
54     GApplicationCommandLine *command_line,
55     gpointer user_data)
56 {
57   GError *error = NULL;
58   gchar **argv;
59   gint argc;
60   gint retval = 0;
61
62   GOptionContext *optcontext;
63   GOptionEntry options[] = {
64       { "show-service", 's',
65         0, G_OPTION_ARG_STRING, &service,
66         N_("Show a particular service"),
67         NULL },
68       { NULL }
69   };
70
71   optcontext = g_option_context_new (N_("- Empathy Debugger"));
72   g_option_context_add_group (optcontext, gtk_get_option_group (TRUE));
73   g_option_context_add_main_entries (optcontext, options, GETTEXT_PACKAGE);
74   g_option_context_set_translation_domain (optcontext, GETTEXT_PACKAGE);
75   argv = g_application_command_line_get_arguments (command_line, &argc);
76
77   if (!g_option_context_parse (optcontext, &argc, &argv, &error))
78     {
79       g_print ("%s\nRun '%s --help' to see a full list of available command "
80           "line options.\n",
81           error->message, argv[0]);
82
83       retval = 1;
84     }
85
86   g_option_context_free (optcontext);
87   g_strfreev (argv);
88
89   g_application_activate (application);
90
91   return retval;
92 }
93
94 int
95 main (int argc,
96     char **argv)
97 {
98   GtkApplication *app;
99   gint retval;
100
101   gtk_init (&argc, &argv);
102   empathy_gtk_init ();
103   textdomain (GETTEXT_PACKAGE);
104
105   app = gtk_application_new (EMPATHY_DEBUGGER_DBUS_NAME,
106       G_APPLICATION_HANDLES_COMMAND_LINE);
107   g_signal_connect (app, "activate", G_CALLBACK (activate_cb), NULL);
108   g_signal_connect (app, "command-line", G_CALLBACK (command_line_cb), NULL);
109
110   g_set_application_name (_("Empathy Debugger"));
111
112   /* Make empathy and empathy-debugger appear as the same app in gnome-shell */
113   gdk_set_program_class ("Empathy");
114   gtk_window_set_default_icon_name ("empathy");
115
116   retval = g_application_run (G_APPLICATION (app), argc, argv);
117
118   g_object_unref (app);
119
120   return retval;
121 }