]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-call-window.c
Set call window title to contact name
[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
28 #include <libempathy/empathy-debug.h>
29
30 #include "empathy-call-window.h"
31 #include "empathy-ui-utils.h"
32
33 #define DEBUG_DOMAIN "CallWindow"
34
35 typedef struct {
36         GtkWidget     *window;
37         GtkWidget     *input_volume_scale;
38         GtkWidget     *output_volume_scale;
39         GtkWidget     *input_mute_togglebutton;
40         GtkWidget     *output_mute_togglebutton;
41         GtkWidget     *preview_video_frame;
42         GtkWidget     *output_video_frame;
43         GtkWidget     *preview_video_socket;
44         GtkWidget     *output_video_socket;
45         GtkWidget     *send_video_checkbutton;
46
47         EmpathyTpCall *call;
48 } EmpathyCallWindow;
49
50 static void
51 call_window_output_volume_changed_cb (GtkWidget         *scale,
52                                       EmpathyCallWindow *window)
53 {
54         guint volume;
55
56         volume = (guint) gtk_range_get_value (GTK_RANGE (scale));
57         empathy_tp_call_set_output_volume (window->call, volume);
58 }
59
60
61 static void
62 call_window_output_mute_toggled_cb (GtkWidget         *button,
63                                     EmpathyCallWindow *window)
64 {
65         gboolean is_muted;
66
67         is_muted = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
68         empathy_tp_call_mute_output (window->call, is_muted);
69 }
70
71
72 static void
73 call_window_input_mute_toggled_cb (GtkWidget         *button,
74                                    EmpathyCallWindow *window)
75 {
76         gboolean is_muted;
77
78         is_muted = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
79         empathy_tp_call_mute_input (window->call, is_muted);
80 }
81
82
83 static void
84 call_window_send_video_toggled_cb (GtkWidget         *button,
85                                    EmpathyCallWindow *window)
86 {
87         gboolean is_sending;
88
89         is_sending = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
90         empathy_tp_call_send_video (window->call, is_sending);
91 }
92
93 static void
94 call_window_capabilities_notify_cb (EmpathyContact    *contact,
95                                     GParamSpec        *param,
96                                     EmpathyCallWindow *window)
97 {
98         EmpathyCapabilities capabilities;
99
100         capabilities = empathy_contact_get_capabilities (contact);
101         empathy_tp_call_request_streams (window->call,
102                                          capabilities & EMPATHY_CAPABILITIES_AUDIO,
103                                          capabilities & EMPATHY_CAPABILITIES_VIDEO);
104 }
105
106 static void
107 call_window_name_notify_cb (EmpathyContact    *contact,
108                             GParamSpec        *param,
109                             EmpathyCallWindow *window)
110 {
111         const gchar *name;
112         gchar       *title;
113
114         name = empathy_contact_get_name (contact);
115         title = g_strdup_printf (_("Call from %s"), name);
116         gtk_window_set_title (GTK_WINDOW (window->window), title);
117         g_free (title);
118 }
119
120 static void
121 call_window_status_notify_cb (EmpathyTpCall     *call,
122                               GParamSpec        *param,
123                               EmpathyCallWindow *window)
124 {
125         guint status;
126
127         status = empathy_tp_call_get_status (call);
128         empathy_debug (DEBUG_DOMAIN, "Status changed to %d",
129                        status);
130
131         if (status == EMPATHY_TP_CALL_STATUS_RINGING) {
132                 if (empathy_tp_call_is_incoming (window->call)) {
133                         empathy_tp_call_accept (window->call);
134                 } else {
135                         EmpathyContact *contact;
136
137                         contact = empathy_tp_call_get_contact (call);
138                         g_signal_connect (contact, "notify::capabilities",
139                                           G_CALLBACK (call_window_capabilities_notify_cb),
140                                           window);
141                         g_signal_connect (contact, "notify::name",
142                                           G_CALLBACK (call_window_name_notify_cb),
143                                           window);
144                         call_window_capabilities_notify_cb (contact, NULL, window);
145                         call_window_name_notify_cb (contact, NULL, window);
146                 }
147         }
148
149         if (status == EMPATHY_TP_CALL_STATUS_RUNNING) {
150                 empathy_tp_call_set_output_window (window->call,
151                         gtk_socket_get_id (GTK_SOCKET (window->output_video_socket)));
152         }
153 }
154
155 static void
156 call_window_destroy_cb (GtkWidget         *widget,
157                         EmpathyCallWindow *window)
158 {
159         g_object_unref (window->call);
160         g_slice_free (EmpathyCallWindow, window);
161 }
162
163 GtkWidget *
164 empathy_call_window_show (EmpathyTpCall *call)
165 {
166         EmpathyCallWindow *window;
167         GladeXML          *glade;
168
169         window = g_slice_new0 (EmpathyCallWindow);
170
171         glade = empathy_glade_get_file ("empathy-call-window.glade",
172                                         "window",
173                                         NULL,
174                                         "window", &window->window,
175                                         "input_volume_scale", &window->input_volume_scale,
176                                         "output_volume_scale", &window->output_volume_scale,
177                                         "input_mute_togglebutton", &window->input_mute_togglebutton,
178                                         "output_mute_togglebutton", &window->output_mute_togglebutton,
179                                         "preview_video_frame", &window->preview_video_frame,
180                                         "output_video_frame", &window->output_video_frame,
181                                         "send_video_checkbutton", &window->send_video_checkbutton,
182                                         NULL);
183
184         empathy_glade_connect (glade,
185                                window,
186                                "window", "destroy", call_window_destroy_cb,
187                                "input_mute_togglebutton", "toggled", call_window_input_mute_toggled_cb,
188                                "output_mute_togglebutton", "toggled", call_window_output_mute_toggled_cb,
189                                "output_volume_scale", "value-changed", call_window_output_volume_changed_cb,
190                                "send_video_checkbutton", "toggled", call_window_send_video_toggled_cb,
191                                NULL);
192         g_object_unref (glade);
193
194         /* Set output window socket */
195         window->output_video_socket = gtk_socket_new ();
196         gtk_widget_show (window->output_video_socket);
197         gtk_container_add (GTK_CONTAINER (window->output_video_frame),
198                            window->output_video_socket);
199
200         /* Set preview window socket */
201         window->preview_video_socket = gtk_socket_new ();
202         gtk_widget_show (window->preview_video_socket);
203         gtk_container_add (GTK_CONTAINER (window->preview_video_frame),
204                            window->preview_video_socket);
205
206         /* Setup TpCall */
207         window->call = g_object_ref (call);
208         empathy_tp_call_add_preview_window (window->call,
209                 gtk_socket_get_id (GTK_SOCKET (window->preview_video_socket)));
210         g_signal_connect (window->call, "notify::status",
211                           G_CALLBACK (call_window_status_notify_cb),
212                           window);
213
214         gtk_widget_show (window->window);
215
216         return window->window;
217 }
218