]> git.0d.be Git - empathy.git/blob - src/empathy-av.c
Updated Galician translations
[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 static guint nb_windows = 0;
45 static guint timeout_id = 0;
46 static gboolean use_timer = TRUE;
47
48 static gboolean
49 timeout_cb (gpointer data)
50 {
51   DEBUG ("Timing out; exiting");
52
53   gtk_main_quit ();
54   return FALSE;
55 }
56
57 static void
58 start_timer (void)
59 {
60   if (!use_timer)
61     return;
62
63   if (timeout_id != 0)
64     return;
65
66   DEBUG ("Start timer");
67
68   timeout_id = g_timeout_add_seconds (TIMEOUT, timeout_cb, NULL);
69 }
70
71 static void
72 stop_timer (void)
73 {
74   if (timeout_id == 0)
75     return;
76
77   DEBUG ("Stop timer");
78
79   g_source_remove (timeout_id);
80   timeout_id = 0;
81 }
82
83 static void
84 call_window_destroy_cb (EmpathyCallWindow *window,
85     gpointer user_data)
86 {
87   nb_windows--;
88
89   if (nb_windows > 0)
90     return;
91
92   start_timer ();
93 }
94
95 static void
96 new_call_handler_cb (EmpathyCallFactory *factory,
97     EmpathyCallHandler *handler,
98     gboolean outgoing,
99     gpointer user_data)
100 {
101   EmpathyCallWindow *window;
102
103   DEBUG ("Create a new call window");
104
105   window = empathy_call_window_new (handler);
106
107   nb_windows++;
108   stop_timer ();
109
110   g_signal_connect (window, "destroy",
111       G_CALLBACK (call_window_destroy_cb), NULL);
112
113   gtk_widget_show (GTK_WIDGET (window));
114 }
115
116 int
117 main (int argc,
118     char *argv[])
119 {
120   GOptionContext *optcontext;
121   GOptionEntry options[] = {
122       { NULL }
123   };
124 #ifdef ENABLE_DEBUG
125   TpDebugSender *debug_sender;
126 #endif
127   EmpathyCallFactory *call_factory;
128   GError *error = NULL;
129
130   /* Init */
131   g_thread_init (NULL);
132
133   optcontext = g_option_context_new (N_("- Empathy Audio/Video Client"));
134   g_option_context_add_group (optcontext, gst_init_get_option_group ());
135   g_option_context_add_group (optcontext, gtk_get_option_group (TRUE));
136   g_option_context_add_main_entries (optcontext, options, GETTEXT_PACKAGE);
137
138   if (!g_option_context_parse (optcontext, &argc, &argv, &error)) {
139     g_print ("%s\nRun '%s --help' to see a full list of available command "
140         "line options.\n",
141         error->message, argv[0]);
142     g_warning ("Error in empathy-av init: %s", error->message);
143     return EXIT_FAILURE;
144   }
145
146   g_option_context_free (optcontext);
147
148   empathy_gtk_init ();
149   g_set_application_name (_("Empathy Audio/Video Client"));
150   g_setenv ("PULSE_PROP_media.role", "phone", TRUE);
151
152   gtk_window_set_default_icon_name ("empathy");
153   textdomain (GETTEXT_PACKAGE);
154
155 #ifdef ENABLE_DEBUG
156   /* Set up debug sender */
157   debug_sender = tp_debug_sender_dup ();
158   g_log_set_default_handler (tp_debug_sender_log_handler, G_LOG_DOMAIN);
159 #endif
160
161   call_factory = empathy_call_factory_initialise ();
162
163   g_signal_connect (G_OBJECT (call_factory), "new-call-handler",
164       G_CALLBACK (new_call_handler_cb), NULL);
165
166   if (!empathy_call_factory_register (call_factory, &error))
167     {
168       g_critical ("Failed to register Handler: %s", error->message);
169       g_error_free (error);
170       return EXIT_FAILURE;
171     }
172
173   if (g_getenv ("EMPATHY_PERSIST") != NULL)
174     {
175       DEBUG ("Disable timer");
176
177       use_timer = FALSE;
178     }
179
180   start_timer ();
181
182   gtk_main ();
183
184   g_object_unref (call_factory);
185
186 #ifdef ENABLE_DEBUG
187   g_object_unref (debug_sender);
188 #endif
189
190   return EXIT_SUCCESS;
191 }