]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-call-window.c
Revert "merge git work"
[empathy.git] / libempathy-gtk / empathy-call-window.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2007 Elliot Fairweather
4  * Copyright (C) 2007 Collabora Ltd.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  * Authors: Elliot Fairweather <elliot.fairweather@collabora.co.uk>
21  *          Xavier Claessens <xclaesse@gmail.com>
22  */
23
24 #include "config.h"
25
26 #include <gtk/gtk.h>
27 #include <glib/gi18n.h>
28
29 #include <libempathy/empathy-debug.h>
30
31 #include "empathy-call-window.h"
32 #include "empathy-ui-utils.h"
33
34 #define DEBUG_DOMAIN "CallWindow"
35
36 typedef struct {
37         GtkWidget     *window;
38         GtkWidget     *input_volume_scale;
39         GtkWidget     *output_volume_scale;
40         GtkWidget     *input_mute_togglebutton;
41         GtkWidget     *output_mute_togglebutton;
42         GtkWidget     *preview_video_frame;
43         GtkWidget     *output_video_frame;
44         GtkWidget     *preview_video_socket;
45         GtkWidget     *output_video_socket;
46         GtkWidget     *send_video_checkbutton;
47
48         EmpathyTpCall *call;
49 } EmpathyCallWindow;
50
51 static void
52 call_window_output_volume_changed_cb (GtkWidget         *scale,
53                                       EmpathyCallWindow *window)
54 {
55         guint volume;
56
57         volume = (guint) gtk_range_get_value (GTK_RANGE (scale));
58         empathy_tp_call_set_output_volume (window->call, volume);
59 }
60
61
62 static void
63 call_window_output_mute_toggled_cb (GtkWidget         *button,
64                                     EmpathyCallWindow *window)
65 {
66         gboolean is_muted;
67
68         is_muted = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
69         empathy_tp_call_mute_output (window->call, is_muted);
70 }
71
72
73 static void
74 call_window_input_mute_toggled_cb (GtkWidget         *button,
75                                    EmpathyCallWindow *window)
76 {
77         gboolean is_muted;
78
79         is_muted = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
80         empathy_tp_call_mute_input (window->call, is_muted);
81 }
82
83
84 static void
85 call_window_send_video_toggled_cb (GtkWidget         *button,
86                                    EmpathyCallWindow *window)
87 {
88         gboolean is_sending;
89
90         is_sending = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
91         empathy_tp_call_send_video (window->call, is_sending);
92 }
93
94 static void
95 call_window_capabilities_notify_cb (EmpathyContact    *contact,
96                                     GParamSpec        *param,
97                                     EmpathyCallWindow *window)
98 {
99         EmpathyCapabilities capabilities;
100
101         capabilities = empathy_contact_get_capabilities (contact);
102         empathy_tp_call_request_streams (window->call,
103                                          capabilities & EMPATHY_CAPABILITIES_AUDIO,
104                                          capabilities & EMPATHY_CAPABILITIES_VIDEO);
105 }
106
107 static void
108 call_window_name_notify_cb (EmpathyContact    *contact,
109                             GParamSpec        *param,
110                             EmpathyCallWindow *window)
111 {
112         const gchar *name;
113         gchar       *title;
114
115         name = empathy_contact_get_name (contact);
116         title = g_strdup_printf (_("Call from %s"), name);
117         gtk_window_set_title (GTK_WINDOW (window->window), title);
118         g_free (title);
119 }
120
121 static void
122 call_window_status_notify_cb (EmpathyTpCall     *call,
123                               GParamSpec        *param,
124                               EmpathyCallWindow *window)
125 {
126         guint status;
127
128         status = empathy_tp_call_get_status (call);
129         empathy_debug (DEBUG_DOMAIN, "Status changed to %d",
130                        status);
131
132         if (status == EMPATHY_TP_CALL_STATUS_RINGING) {
133                 if (empathy_tp_call_is_incoming (window->call)) {
134                         empathy_tp_call_accept (window->call);
135                 } else {
136                         EmpathyContact *contact;
137
138                         contact = empathy_tp_call_get_contact (call);
139                         g_signal_connect (contact, "notify::capabilities",
140                                           G_CALLBACK (call_window_capabilities_notify_cb),
141                                           window);
142                         g_signal_connect (contact, "notify::name",
143                                           G_CALLBACK (call_window_name_notify_cb),
144                                           window);
145                         call_window_capabilities_notify_cb (contact, NULL, window);
146                         call_window_name_notify_cb (contact, NULL, window);
147                 }
148         }
149
150         if (status == EMPATHY_TP_CALL_STATUS_RUNNING) {
151                 empathy_tp_call_set_output_window (window->call,
152                         gtk_socket_get_id (GTK_SOCKET (window->output_video_socket)));
153         }
154 }
155
156 static void
157 call_window_destroy_cb (GtkWidget         *widget,
158                         EmpathyCallWindow *window)
159 {
160         g_object_unref (window->call);
161         g_slice_free (EmpathyCallWindow, window);
162 }
163
164 GtkWidget *
165 empathy_call_window_show (EmpathyTpCall *call)
166 {
167         EmpathyCallWindow *window;
168         GladeXML          *glade;
169
170         window = g_slice_new0 (EmpathyCallWindow);
171
172         glade = empathy_glade_get_file ("empathy-call-window.glade",
173                                         "window",
174                                         NULL,
175                                         "window", &window->window,
176                                         "input_volume_scale", &window->input_volume_scale,
177                                         "output_volume_scale", &window->output_volume_scale,
178                                         "input_mute_togglebutton", &window->input_mute_togglebutton,
179                                         "output_mute_togglebutton", &window->output_mute_togglebutton,
180                                         "preview_video_frame", &window->preview_video_frame,
181                                         "output_video_frame", &window->output_video_frame,
182                                         "send_video_checkbutton", &window->send_video_checkbutton,
183                                         NULL);
184
185         empathy_glade_connect (glade,
186                                window,
187                                "window", "destroy", call_window_destroy_cb,
188                                "input_mute_togglebutton", "toggled", call_window_input_mute_toggled_cb,
189                                "output_mute_togglebutton", "toggled", call_window_output_mute_toggled_cb,
190                                "output_volume_scale", "value-changed", call_window_output_volume_changed_cb,
191                                "send_video_checkbutton", "toggled", call_window_send_video_toggled_cb,
192                                NULL);
193         g_object_unref (glade);
194
195         /* Set output window socket */
196         window->output_video_socket = gtk_socket_new ();
197         gtk_widget_show (window->output_video_socket);
198         gtk_container_add (GTK_CONTAINER (window->output_video_frame),
199                            window->output_video_socket);
200
201         /* Set preview window socket */
202         window->preview_video_socket = gtk_socket_new ();
203         gtk_widget_show (window->preview_video_socket);
204         gtk_container_add (GTK_CONTAINER (window->preview_video_frame),
205                            window->preview_video_socket);
206
207         /* Setup TpCall */
208         window->call = g_object_ref (call);
209         empathy_tp_call_add_preview_window (window->call,
210                 gtk_socket_get_id (GTK_SOCKET (window->preview_video_socket)));
211         g_signal_connect (window->call, "notify::status",
212                           G_CALLBACK (call_window_status_notify_cb),
213                           window);
214
215         gtk_widget_show (window->window);
216
217         return window->window;
218 }
219