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