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>
26 #include <glib/gi18n.h>
29 #include <telepathy-glib/debug-sender.h>
31 #include <libempathy-gtk/empathy-ui-utils.h>
33 #include "empathy-streamed-media-window.h"
34 #include "empathy-streamed-media-factory.h"
36 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
37 #include <libempathy/empathy-debug.h>
41 /* Exit after $TIMEOUT seconds if not displaying any call window */
44 #define EMPATHY_AV_DBUS_NAME "org.gnome.Empathy.AudioVideo"
46 static GtkApplication *app = NULL;
47 static gboolean activated = FALSE;
48 static gboolean use_timer = TRUE;
50 static EmpathyStreamedMediaFactory *call_factory = NULL;
53 new_call_handler_cb (EmpathyStreamedMediaFactory *factory,
54 EmpathyStreamedMediaHandler *handler,
58 EmpathyStreamedMediaWindow *window;
60 DEBUG ("Create a new StreamedMedia window");
62 window = empathy_streamed_media_window_new (handler);
64 g_application_hold (G_APPLICATION (app));
66 g_signal_connect_swapped (window, "destroy",
67 G_CALLBACK (g_application_release), app);
69 gtk_widget_show (GTK_WIDGET (window));
73 activate_cb (GApplication *application)
84 /* keep a 'ref' to the application */
85 g_application_hold (G_APPLICATION (app));
88 g_assert (call_factory == NULL);
89 call_factory = empathy_streamed_media_factory_initialise ();
91 g_signal_connect (G_OBJECT (call_factory), "new-streamed-media-handler",
92 G_CALLBACK (new_call_handler_cb), NULL);
94 if (!empathy_streamed_media_factory_register (call_factory, &error))
96 g_critical ("Failed to register Handler: %s", error->message);
105 GOptionContext *optcontext;
106 GOptionEntry options[] = {
110 TpDebugSender *debug_sender;
112 GError *error = NULL;
116 g_thread_init (NULL);
118 optcontext = g_option_context_new (N_("- Empathy Audio/Video Client"));
119 g_option_context_add_group (optcontext, gst_init_get_option_group ());
120 g_option_context_add_group (optcontext, gtk_get_option_group (TRUE));
121 g_option_context_add_main_entries (optcontext, options, GETTEXT_PACKAGE);
123 if (!g_option_context_parse (optcontext, &argc, &argv, &error)) {
124 g_print ("%s\nRun '%s --help' to see a full list of available command "
126 error->message, argv[0]);
127 g_warning ("Error in empathy-av init: %s", error->message);
131 g_option_context_free (optcontext);
134 g_set_application_name (_("Empathy Audio/Video Client"));
135 g_setenv ("PULSE_PROP_media.role", "phone", TRUE);
137 /* Make empathy and empathy-av appear as the same app in gnome-shell */
138 gdk_set_program_class ("Empathy");
139 gtk_window_set_default_icon_name ("empathy");
140 textdomain (GETTEXT_PACKAGE);
142 app = gtk_application_new (EMPATHY_AV_DBUS_NAME, G_APPLICATION_FLAGS_NONE);
143 g_signal_connect (app, "activate", G_CALLBACK (activate_cb), NULL);
146 /* Set up debug sender */
147 debug_sender = tp_debug_sender_dup ();
148 g_log_set_default_handler (tp_debug_sender_log_handler, G_LOG_DOMAIN);
151 if (g_getenv ("EMPATHY_PERSIST") != NULL)
153 DEBUG ("Disable timer");
158 /* the inactivity timeout can only be set while the application is held */
159 g_application_hold (G_APPLICATION (app));
160 g_application_set_inactivity_timeout (G_APPLICATION (app), TIMEOUT * 1000);
161 g_application_release (G_APPLICATION (app));
163 retval = g_application_run (G_APPLICATION (app), argc, argv);
165 g_object_unref (app);
166 tp_clear_object (&call_factory);
169 g_object_unref (debug_sender);