2 * Copyright (C) 2007-2011 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>
25 #include <glib/gi18n.h>
26 #include <clutter-gtk/clutter-gtk.h>
27 #include <clutter-gst/clutter-gst.h>
28 #include <tp-account-widgets/tpaw-utils.h>
30 #ifdef CLUTTER_WINDOWING_X11
35 #include "empathy-bus-names.h"
36 #include "empathy-call-factory.h"
37 #include "empathy-call-window.h"
38 #include "empathy-ui-utils.h"
40 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
41 #include "empathy-debug.h"
43 /* Exit after $TIMEOUT seconds if not displaying any call window */
46 static GtkApplication
*app
= NULL
;
47 static gboolean activated
= FALSE
;
48 static gboolean use_timer
= TRUE
;
49 static guint inhibit_id
= 0;
51 static EmpathyCallFactory
*call_factory
= NULL
;
53 /* An EmpathyContact -> EmpathyCallWindow hash table for all existing
54 * Call windows. We own a ref on the EmpathyContacts. */
55 static GHashTable
*call_windows
;
58 call_window_destroyed_cb (GtkWidget
*window
,
59 EmpathyContact
*contact
)
61 g_hash_table_remove (call_windows
, contact
);
63 g_application_release (G_APPLICATION (app
));
67 find_window_for_handle (gpointer key
,
71 EmpathyContact
*contact
= key
;
72 guint handle
= GPOINTER_TO_UINT (user_data
);
74 if (handle
== empathy_contact_get_handle (contact
))
81 incoming_call_cb (EmpathyCallFactory
*factory
,
83 TpCallChannel
*channel
,
84 TpChannelDispatchOperation
*dispatch_operation
,
85 TpAddDispatchOperationContext
*context
,
88 EmpathyCallWindow
*window
= g_hash_table_find (call_windows
,
89 find_window_for_handle
, GUINT_TO_POINTER (handle
));
93 /* The window takes care of accepting or rejecting the context. */
94 empathy_call_window_start_ringing (window
,
95 channel
, dispatch_operation
, context
);
103 call_window_inhibit_cb (EmpathyCallWindow
*window
,
112 inhibit_id
= gtk_application_inhibit (GTK_APPLICATION (app
),
114 GTK_APPLICATION_INHIBIT_LOGOUT
| GTK_APPLICATION_INHIBIT_SWITCH
|
115 GTK_APPLICATION_INHIBIT_SUSPEND
| GTK_APPLICATION_INHIBIT_IDLE
,
123 gtk_application_uninhibit (GTK_APPLICATION (app
), inhibit_id
);
129 new_call_handler_cb (EmpathyCallFactory
*factory
,
130 EmpathyCallHandler
*handler
,
131 gint64 user_action_time
,
134 EmpathyCallWindow
*window
;
135 EmpathyContact
*contact
;
139 DEBUG ("Show the call window");
141 contact
= empathy_call_handler_get_contact (handler
);
143 window
= g_hash_table_lookup (call_windows
, contact
);
145 present
= tp_user_action_time_should_present (user_action_time
,
150 empathy_call_window_new_handler (window
, handler
, present
, x11_time
);
154 window
= empathy_call_window_new (handler
);
156 g_hash_table_insert (call_windows
, g_object_ref (contact
), window
);
157 g_application_hold (G_APPLICATION (app
));
158 g_signal_connect (window
, "destroy",
159 G_CALLBACK (call_window_destroyed_cb
), contact
);
160 g_signal_connect (window
, "inhibit",
161 G_CALLBACK (call_window_inhibit_cb
), NULL
);
163 gtk_widget_show (GTK_WIDGET (window
));
166 tpaw_window_present_with_time (GTK_WINDOW (window
), x11_time
);
171 activate_cb (GApplication
*application
)
173 GError
*error
= NULL
;
182 /* keep a 'ref' to the application */
183 g_application_hold (G_APPLICATION (app
));
186 g_assert (call_factory
== NULL
);
187 call_factory
= empathy_call_factory_initialise ();
189 g_signal_connect (G_OBJECT (call_factory
), "new-call-handler",
190 G_CALLBACK (new_call_handler_cb
), NULL
);
191 g_signal_connect (G_OBJECT (call_factory
), "incoming-call",
192 G_CALLBACK (incoming_call_cb
), NULL
);
194 if (!empathy_call_factory_register (call_factory
, &error
))
196 g_critical ("Failed to register Handler: %s", error
->message
);
197 g_error_free (error
);
205 GOptionContext
*optcontext
;
206 GOptionEntry options
[] = {
210 TpDebugSender
*debug_sender
;
212 GError
*error
= NULL
;
214 GtkSettings
*gtk_settings
;
216 g_setenv ("GST_DEBUG_DUMP_DOT_DIR", g_get_tmp_dir (), FALSE
);
218 #ifdef GDK_WINDOWING_X11
219 if (GDK_IS_X11_DISPLAY (gdk_display_get_default ())) {
220 /* We can't call clutter_gst_init() before gtk_clutter_init(), so no choice
221 * but to intiialise X11 threading ourself */
226 optcontext
= g_option_context_new (N_("- Empathy Audio/Video Client"));
227 g_option_context_add_group (optcontext
, gst_init_get_option_group ());
228 g_option_context_add_group (optcontext
, gtk_get_option_group (TRUE
));
229 g_option_context_add_group (optcontext
, cogl_get_option_group ());
230 g_option_context_add_group (optcontext
,
231 clutter_get_option_group_without_init ());
232 g_option_context_add_group (optcontext
, gtk_clutter_get_option_group ());
233 g_option_context_add_main_entries (optcontext
, options
, GETTEXT_PACKAGE
);
234 g_option_context_set_translation_domain (optcontext
, GETTEXT_PACKAGE
);
236 if (!g_option_context_parse (optcontext
, &argc
, &argv
, &error
)) {
237 g_print ("%s\nRun '%s --help' to see a full list of available command "
239 error
->message
, argv
[0]);
240 g_warning ("Error in empathy-call init: %s", error
->message
);
244 g_option_context_free (optcontext
);
246 clutter_gst_init (&argc
, &argv
);
249 textdomain (GETTEXT_PACKAGE
);
250 g_set_application_name (_("Empathy Audio/Video Client"));
252 /* Make empathy and empathy-call appear as the same app in gnome-shell */
253 g_set_prgname ("empathy");
254 gtk_window_set_default_icon_name ("empathy");
256 gtk_settings
= gtk_settings_get_default ();
257 g_object_set (G_OBJECT (gtk_settings
), "gtk-application-prefer-dark-theme",
260 app
= gtk_application_new (EMPATHY_CALL_BUS_NAME
, G_APPLICATION_FLAGS_NONE
);
261 g_signal_connect (app
, "activate", G_CALLBACK (activate_cb
), NULL
);
264 /* Set up debug sender */
265 debug_sender
= tp_debug_sender_dup ();
266 g_log_set_default_handler (tp_debug_sender_log_handler
, G_LOG_DOMAIN
);
269 if (g_getenv ("EMPATHY_PERSIST") != NULL
)
271 DEBUG ("Disable timer");
276 call_windows
= g_hash_table_new_full (g_direct_hash
, g_direct_equal
,
277 g_object_unref
, NULL
);
279 /* the inactivity timeout can only be set while the application is held */
280 g_application_hold (G_APPLICATION (app
));
281 g_application_set_inactivity_timeout (G_APPLICATION (app
), TIMEOUT
* 1000);
282 g_application_release (G_APPLICATION (app
));
284 retval
= g_application_run (G_APPLICATION (app
), argc
, argv
);
286 g_hash_table_unref (call_windows
);
287 g_object_unref (app
);
288 tp_clear_object (&call_factory
);
291 g_object_unref (debug_sender
);