Set prgname instead of program_class
[nijm-empathy.git] / src / empathy-chat.c
blobe0bcd813e74494b4183ef4d5fc1f6559892d1f3f
1 /*
2 * Copyright (C) 2007-2010 Collabora Ltd.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301 USA
19 * Authors: Xavier Claessens <xclaesse@gmail.com>
20 * Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
23 #include "config.h"
25 #include <glib/gi18n.h>
26 #include <libnotify/notify.h>
28 #include "empathy-bus-names.h"
29 #include "empathy-chat-manager.h"
30 #include "empathy-chat-resources.h"
31 #include "empathy-presence-manager.h"
32 #include "empathy-theme-manager.h"
33 #include "empathy-ui-utils.h"
34 #include "empathy-utils.h"
36 #define DEBUG_FLAG EMPATHY_DEBUG_CHAT
37 #include "empathy-debug.h"
39 /* Exit after $TIMEOUT seconds if not displaying any call window */
40 #define TIMEOUT 60
42 static GtkApplication *app = NULL;
43 static gboolean activated = FALSE;
44 static gboolean use_timer = TRUE;
46 static EmpathyChatManager *chat_mgr = NULL;
48 static void
49 displayed_chats_changed_cb (EmpathyChatManager *mgr,
50 guint nb_chats,
51 gpointer user_data)
53 DEBUG ("New chat count: %u", nb_chats);
55 if (nb_chats == 0)
56 g_application_release (G_APPLICATION (app));
57 else
58 g_application_hold (G_APPLICATION (app));
61 static void
62 activate_cb (GApplication *application)
64 if (activated)
65 return;
67 activated = TRUE;
68 empathy_gtk_init ();
70 if (!use_timer)
72 /* keep a 'ref' to the application */
73 g_application_hold (G_APPLICATION (application));
76 g_assert (chat_mgr == NULL);
77 chat_mgr = empathy_chat_manager_dup_singleton ();
79 g_signal_connect (chat_mgr, "displayed-chats-changed",
80 G_CALLBACK (displayed_chats_changed_cb), GUINT_TO_POINTER (1));
83 int
84 main (int argc,
85 char *argv[])
87 GOptionContext *optcontext;
88 GOptionEntry options[] = {
89 { NULL }
91 GResource *resource;
92 #ifdef ENABLE_DEBUG
93 TpDebugSender *debug_sender;
94 #endif
95 GError *error = NULL;
96 EmpathyPresenceManager *presence_mgr;
97 EmpathyThemeManager *theme_mgr;
98 gint retval;
100 optcontext = g_option_context_new (N_("- Empathy Chat Client"));
101 g_option_context_add_group (optcontext, gtk_get_option_group (FALSE));
102 g_option_context_add_main_entries (optcontext, options, GETTEXT_PACKAGE);
103 g_option_context_set_translation_domain (optcontext, GETTEXT_PACKAGE);
105 if (!g_option_context_parse (optcontext, &argc, &argv, &error))
107 g_print ("%s\nRun '%s --help' to see a full list of available command "
108 "line options.\n",
109 error->message, argv[0]);
110 g_warning ("Error in empathy-av init: %s", error->message);
111 return EXIT_FAILURE;
114 g_option_context_free (optcontext);
116 empathy_init ();
118 /* Make empathy and empathy-chat appear as the same app in gnome-shell */
119 g_set_prgname ("empathy");
120 gtk_window_set_default_icon_name ("empathy");
121 textdomain (GETTEXT_PACKAGE);
123 notify_init (_(PACKAGE_NAME));
125 resource = empathy_chat_get_resource ();
126 g_resources_register (resource);
128 app = gtk_application_new (EMPATHY_CHAT_BUS_NAME, G_APPLICATION_FLAGS_NONE);
129 g_signal_connect (app, "activate", G_CALLBACK (activate_cb), NULL);
131 #ifdef ENABLE_DEBUG
132 /* Set up debug sender */
133 debug_sender = tp_debug_sender_dup ();
134 g_log_set_default_handler (tp_debug_sender_log_handler, G_LOG_DOMAIN);
135 #endif
137 /* Setting up Idle */
138 presence_mgr = empathy_presence_manager_dup_singleton ();
140 /* Keep the theme manager alive as it does some caching */
141 theme_mgr = empathy_theme_manager_dup_singleton ();
143 if (g_getenv ("EMPATHY_PERSIST") != NULL)
145 DEBUG ("Disable timer");
147 use_timer = FALSE;
150 /* the inactivity timeout can only be set while the application is held */
151 g_application_hold (G_APPLICATION (app));
152 g_application_set_inactivity_timeout (G_APPLICATION (app), TIMEOUT * 1000);
153 g_application_release (G_APPLICATION (app));
155 DEBUG ("Waiting for text channels to handle");
157 retval = g_application_run (G_APPLICATION (app), argc, argv);
159 g_object_unref (app);
160 g_object_unref (presence_mgr);
161 g_object_unref (theme_mgr);
162 tp_clear_object (&chat_mgr);
164 #ifdef ENABLE_DEBUG
165 g_object_unref (debug_sender);
166 #endif
168 g_resources_unregister (resource);
169 g_resource_unref (resource);
171 notify_uninit ();
173 return retval;