]> git.0d.be Git - empathy.git/blob - src/empathy-call.c
Update Simplified Chinese help translation.
[empathy.git] / src / empathy-call.c
1 /*
2  * Copyright (C) 2007-2011 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 <clutter/clutter.h>
30 #include <clutter-gtk/clutter-gtk.h>
31 #include <clutter-gst/clutter-gst.h>
32
33 #include <telepathy-glib/debug-sender.h>
34
35 #include <telepathy-yell/telepathy-yell.h>
36
37 #include <libempathy-gtk/empathy-ui-utils.h>
38
39 #include "empathy-call-window.h"
40 #include "empathy-call-factory.h"
41
42 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
43 #include <libempathy/empathy-debug.h>
44
45 #include <gst/gst.h>
46
47 /* Exit after $TIMEOUT seconds if not displaying any call window */
48 #define TIMEOUT 60
49
50 #define EMPATHY_CALL_DBUS_NAME "org.gnome.Empathy.Call"
51
52 static GtkApplication *app = NULL;
53 static gboolean activated = FALSE;
54 static gboolean use_timer = TRUE;
55
56 static EmpathyCallFactory *call_factory = NULL;
57
58 static void
59 new_call_handler_cb (EmpathyCallFactory *factory,
60     EmpathyCallHandler *handler,
61     gboolean outgoing,
62     gpointer user_data)
63 {
64   EmpathyCallWindow *window;
65
66   DEBUG ("Create a new call window");
67
68   window = empathy_call_window_new (handler);
69
70   g_application_hold (G_APPLICATION (app));
71
72   g_signal_connect_swapped (window, "destroy",
73       G_CALLBACK (g_application_release), app);
74
75   gtk_widget_show (GTK_WIDGET (window));
76 }
77
78 static void
79 activate_cb (GApplication *application)
80 {
81   GError *error = NULL;
82
83   if (activated)
84     return;
85
86   activated = TRUE;
87
88   if (!use_timer)
89     {
90       /* keep a 'ref' to the application */
91       g_application_hold (G_APPLICATION (app));
92     }
93
94   g_assert (call_factory == NULL);
95   call_factory = empathy_call_factory_initialise ();
96
97   g_signal_connect (G_OBJECT (call_factory), "new-call-handler",
98       G_CALLBACK (new_call_handler_cb), NULL);
99
100   if (!empathy_call_factory_register (call_factory, &error))
101     {
102       g_critical ("Failed to register Handler: %s", error->message);
103       g_error_free (error);
104     }
105 }
106
107 int
108 main (int argc,
109     char *argv[])
110 {
111   GOptionContext *optcontext;
112   GOptionEntry options[] = {
113       { NULL }
114   };
115 #ifdef ENABLE_DEBUG
116   TpDebugSender *debug_sender;
117 #endif
118   GError *error = NULL;
119   gint retval;
120
121   /* Init */
122   g_thread_init (NULL);
123
124   optcontext = g_option_context_new (N_("- Empathy Audio/Video Client"));
125   g_option_context_add_group (optcontext, gst_init_get_option_group ());
126   g_option_context_add_group (optcontext, gtk_get_option_group (TRUE));
127   g_option_context_add_main_entries (optcontext, options, GETTEXT_PACKAGE);
128
129   if (!g_option_context_parse (optcontext, &argc, &argv, &error)) {
130     g_print ("%s\nRun '%s --help' to see a full list of available command "
131         "line options.\n",
132         error->message, argv[0]);
133     g_warning ("Error in empathy-call init: %s", error->message);
134     return EXIT_FAILURE;
135   }
136
137   g_option_context_free (optcontext);
138
139   tpy_cli_init ();
140
141   gtk_clutter_init (&argc, &argv);
142   clutter_gst_init (&argc, &argv);
143
144   empathy_gtk_init ();
145   g_set_application_name (_("Empathy Audio/Video Client"));
146   g_setenv ("PULSE_PROP_media.role", "phone", TRUE);
147
148   /* Make empathy and empathy-call appear as the same app in gnome-shell */
149   gdk_set_program_class ("Empathy");
150   gtk_window_set_default_icon_name ("empathy");
151   textdomain (GETTEXT_PACKAGE);
152
153   app = gtk_application_new (EMPATHY_CALL_DBUS_NAME, G_APPLICATION_FLAGS_NONE);
154   g_signal_connect (app, "activate", G_CALLBACK (activate_cb), NULL);
155
156 #ifdef ENABLE_DEBUG
157   /* Set up debug sender */
158   debug_sender = tp_debug_sender_dup ();
159   g_log_set_default_handler (tp_debug_sender_log_handler, G_LOG_DOMAIN);
160 #endif
161
162   if (g_getenv ("EMPATHY_PERSIST") != NULL)
163     {
164       DEBUG ("Disable timer");
165
166       use_timer = FALSE;
167     }
168
169   /* the inactivity timeout can only be set while the application is held */
170   g_application_hold (G_APPLICATION (app));
171   g_application_set_inactivity_timeout (G_APPLICATION (app), TIMEOUT * 1000);
172   g_application_release (G_APPLICATION (app));
173
174   retval = g_application_run (G_APPLICATION (app), argc, argv);
175
176   g_object_unref (app);
177   tp_clear_object (&call_factory);
178
179 #ifdef ENABLE_DEBUG
180   g_object_unref (debug_sender);
181 #endif
182
183   return retval;
184 }