]> git.0d.be Git - empathy.git/blob - src/empathy-av.c
Merge branch 'sasl'
[empathy.git] / src / empathy-av.c
1 /*
2  * Copyright (C) 2007-2010 Collabora Ltd.
3  *
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.
8  *
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.
13  *
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
18  *
19  * Authors: Xavier Claessens <xclaesse@gmail.com>
20  *          Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
21  */
22
23 #include <config.h>
24
25 #include <glib.h>
26 #include <glib/gi18n.h>
27 #include <gtk/gtk.h>
28
29 #include <telepathy-glib/debug-sender.h>
30
31 #include <libempathy/empathy-call-factory.h>
32 #include <libempathy-gtk/empathy-ui-utils.h>
33
34 #include "empathy-call-window.h"
35
36 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
37 #include <libempathy/empathy-debug.h>
38
39 #include <gst/gst.h>
40
41 /* Exit after $TIMEOUT seconds if not displaying any call window */
42 #define TIMEOUT 60
43
44 #define EMPATHY_AV_DBUS_NAME "org.gnome.Empathy.AudioVideo"
45
46 static GtkApplication *app = NULL;
47 static gboolean activated = FALSE;
48 static gboolean use_timer = TRUE;
49
50 static EmpathyCallFactory *call_factory = NULL;
51
52 static void
53 new_call_handler_cb (EmpathyCallFactory *factory,
54     EmpathyCallHandler *handler,
55     gboolean outgoing,
56     gpointer user_data)
57 {
58   EmpathyCallWindow *window;
59
60   DEBUG ("Create a new call window");
61
62   window = empathy_call_window_new (handler);
63
64   g_application_hold (G_APPLICATION (app));
65
66   g_signal_connect_swapped (window, "destroy",
67       G_CALLBACK (g_application_release), app);
68
69   gtk_widget_show (GTK_WIDGET (window));
70 }
71
72 static void
73 activate_cb (GApplication *application)
74 {
75   GError *error = NULL;
76
77   if (activated)
78     return;
79
80   activated = TRUE;
81
82   if (!use_timer)
83     {
84       /* keep a 'ref' to the application */
85       g_application_hold (G_APPLICATION (app));
86     }
87
88   g_assert (call_factory == NULL);
89   call_factory = empathy_call_factory_initialise ();
90
91   g_signal_connect (G_OBJECT (call_factory), "new-call-handler",
92       G_CALLBACK (new_call_handler_cb), NULL);
93
94   if (!empathy_call_factory_register (call_factory, &error))
95     {
96       g_critical ("Failed to register Handler: %s", error->message);
97       g_error_free (error);
98     }
99 }
100
101 int
102 main (int argc,
103     char *argv[])
104 {
105   GOptionContext *optcontext;
106   GOptionEntry options[] = {
107       { NULL }
108   };
109 #ifdef ENABLE_DEBUG
110   TpDebugSender *debug_sender;
111 #endif
112   GError *error = NULL;
113   gint retval;
114
115   /* Init */
116   g_thread_init (NULL);
117
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);
122
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 "
125         "line options.\n",
126         error->message, argv[0]);
127     g_warning ("Error in empathy-av init: %s", error->message);
128     return EXIT_FAILURE;
129   }
130
131   g_option_context_free (optcontext);
132
133   empathy_gtk_init ();
134   g_set_application_name (_("Empathy Audio/Video Client"));
135   g_setenv ("PULSE_PROP_media.role", "phone", TRUE);
136
137   gtk_window_set_default_icon_name ("empathy");
138   textdomain (GETTEXT_PACKAGE);
139
140   app = gtk_application_new (EMPATHY_AV_DBUS_NAME, G_APPLICATION_FLAGS_NONE);
141   g_signal_connect (app, "activate", G_CALLBACK (activate_cb), NULL);
142
143 #ifdef ENABLE_DEBUG
144   /* Set up debug sender */
145   debug_sender = tp_debug_sender_dup ();
146   g_log_set_default_handler (tp_debug_sender_log_handler, G_LOG_DOMAIN);
147 #endif
148
149   if (g_getenv ("EMPATHY_PERSIST") != NULL)
150     {
151       DEBUG ("Disable timer");
152
153       use_timer = FALSE;
154     }
155
156   /* the inactivity timeout can only be set while the application is held */
157   g_application_hold (G_APPLICATION (app));
158   g_application_set_inactivity_timeout (G_APPLICATION (app), TIMEOUT * 1000);
159   g_application_release (G_APPLICATION (app));
160
161   retval = g_application_run (G_APPLICATION (app), argc, argv);
162
163   g_object_unref (app);
164   tp_clear_object (&call_factory);
165
166 #ifdef ENABLE_DEBUG
167   g_object_unref (debug_sender);
168 #endif
169
170   return retval;
171 }