2 * Copyright (C) 2007 Elliot Fairweather
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library 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 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 * Authors: Elliot Fairweather <elliot.fairweather@collabora.co.uk>
23 #include <libtelepathy/tp-chan.h>
25 #include <libmissioncontrol/mc-account.h>
26 #include <libmissioncontrol/mc-account-monitor.h>
27 #include <libmissioncontrol/mission-control.h>
29 #include <libempathy/empathy-contact.h>
30 #include <libempathy/empathy-tp-call.h>
31 #include <libempathy/empathy-chandler.h>
32 #include <libempathy/empathy-debug.h>
33 #include <libempathy/empathy-utils.h>
34 #include <libempathy-gtk/empathy-ui-utils.h>
36 #include "empathy-call-window.h"
38 #define DEBUG_DOMAIN "CallWindow"
43 GtkWidget *status_label;
44 GtkWidget *start_call_button;
45 GtkWidget *end_call_button;
46 GtkWidget *input_volume_scale;
47 GtkWidget *output_volume_scale;
48 GtkWidget *input_mute_button;
49 GtkWidget *output_mute_button;
50 GtkWidget *preview_video_frame;
51 GtkWidget *output_video_frame;
52 GtkWidget *preview_video_socket;
53 GtkWidget *output_video_socket;
54 GtkWidget *video_button;
55 GtkWidget *output_video_label;
60 guint timeout_event_id;
66 call_window_update_timer (gpointer data)
68 EmpathyCallWindow *window = data;
72 glong time, seconds, minutes, hours;
74 g_get_current_time (¤t);
77 then = (window->start_time).tv_sec;
89 str = g_strdup_printf ("Connected - %02ld : %02ld : %02ld", hours,
94 str = g_strdup_printf ("Connected - %02ld : %02ld", minutes, seconds);
97 gtk_label_set_text (GTK_LABEL (window->status_label), str);
105 call_window_stop_timeout (EmpathyCallWindow *window)
107 GMainContext *context;
110 context = g_main_context_default ();
112 empathy_debug (DEBUG_DOMAIN, "Timer stopped");
114 if (window->timeout_event_id)
116 source = g_main_context_find_source_by_id (context,
117 window->timeout_event_id);
118 g_source_destroy (source);
119 window->timeout_event_id = 0;
124 call_window_set_output_video_is_drawing (EmpathyCallWindow *window,
129 child = gtk_bin_get_child (GTK_BIN (window->output_video_frame));
131 empathy_debug (DEBUG_DOMAIN,
132 "Setting output video is drawing - %d", is_drawing);
136 if (!window->is_drawing)
140 gtk_container_remove (GTK_CONTAINER (window->output_video_frame),
143 gtk_container_add (GTK_CONTAINER (window->output_video_frame),
144 window->output_video_socket);
145 gtk_widget_show (window->output_video_socket);
146 empathy_tp_call_add_output_video (window->call,
147 gtk_socket_get_id (GTK_SOCKET (window->output_video_socket)));
148 window->is_drawing = is_drawing;
153 if (window->is_drawing)
155 empathy_tp_call_add_output_video (window->call, 0);
158 gtk_container_remove (GTK_CONTAINER (window->output_video_frame),
161 gtk_container_add (GTK_CONTAINER (window->output_video_frame),
162 window->output_video_label);
163 gtk_widget_show (window->output_video_label);
164 window->is_drawing = is_drawing;
170 call_window_delete_event_cb (GtkWidget *widget,
172 EmpathyCallWindow *window)
178 empathy_debug (DEBUG_DOMAIN, "Delete event occurred");
180 g_object_get (G_OBJECT (window->call), "status", &status, NULL);
182 if (status == EMPATHY_TP_CALL_STATUS_ACCEPTED)
184 dialog = gtk_message_dialog_new (GTK_WINDOW (window->window),
185 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
186 GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
187 "This call will be ended. Continue?");
189 result = gtk_dialog_run (GTK_DIALOG (dialog));
190 gtk_widget_destroy (dialog);
194 case GTK_RESPONSE_YES:
195 call_window_stop_timeout (window);
196 call_window_set_output_video_is_drawing (window, FALSE);
197 empathy_tp_call_close_channel (window->call);
198 empathy_tp_call_remove_preview_video (window->call,
199 gtk_socket_get_id (GTK_SOCKET (window->preview_video_socket)));
207 empathy_tp_call_remove_preview_video (window->call,
208 gtk_socket_get_id (GTK_SOCKET (window->preview_video_socket)));
214 call_window_video_button_toggled_cb (GtkWidget *button,
215 EmpathyCallWindow *window)
219 is_sending = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
221 empathy_debug (DEBUG_DOMAIN, "Send video toggled - %d", is_sending);
223 empathy_tp_call_request_video_stream_direction (window->call, is_sending);
227 call_window_status_changed_cb (EmpathyTpCall *call,
228 EmpathyCallWindow *window)
230 EmpathyContact *contact;
233 EmpathyTpCallStream *audio_stream;
234 EmpathyTpCallStream *video_stream;
235 gboolean is_incoming;
238 g_object_get (window->call,
240 "audio-stream", &audio_stream,
241 "video-stream", &video_stream,
244 if (video_stream->state > audio_stream->state)
245 stream_state = video_stream->state;
247 stream_state = audio_stream->state;
249 empathy_debug (DEBUG_DOMAIN, "Status changed - status: %d, stream state: %d",
250 status, stream_state);
252 if (window->timeout_event_id)
253 call_window_stop_timeout (window);
255 if (status == EMPATHY_TP_CALL_STATUS_CLOSED)
257 gtk_label_set_text (GTK_LABEL (window->status_label), "Closed");
258 gtk_widget_set_sensitive (window->end_call_button, FALSE);
259 gtk_widget_set_sensitive (window->start_call_button, FALSE);
261 call_window_set_output_video_is_drawing (window, FALSE);
263 else if (stream_state == TP_MEDIA_STREAM_STATE_DISCONNECTED)
264 gtk_label_set_text (GTK_LABEL (window->status_label), "Disconnected");
265 else if (status == EMPATHY_TP_CALL_STATUS_PENDING)
267 g_object_get (G_OBJECT (window->call), "contact", &contact, NULL);
269 title = g_strdup_printf ("%s - Empathy Call",
270 empathy_contact_get_name (contact));
271 gtk_window_set_title (GTK_WINDOW (window->window), title);
273 gtk_label_set_text (GTK_LABEL (window->status_label), "Ringing");
274 gtk_widget_set_sensitive (window->end_call_button, TRUE);
275 gtk_widget_set_sensitive (window->video_button, TRUE);
277 g_object_get (G_OBJECT (window->call), "is-incoming", &is_incoming, NULL);
279 gtk_widget_set_sensitive (window->start_call_button, TRUE);
281 g_signal_connect (GTK_OBJECT (window->video_button), "toggled",
282 G_CALLBACK (call_window_video_button_toggled_cb),
285 else if (status == EMPATHY_TP_CALL_STATUS_ACCEPTED)
287 if (stream_state == TP_MEDIA_STREAM_STATE_CONNECTING)
288 gtk_label_set_text (GTK_LABEL (window->status_label), "Connecting");
289 else if (stream_state == TP_MEDIA_STREAM_STATE_CONNECTED)
291 if ((window->start_time).tv_sec == 0)
292 g_get_current_time (&(window->start_time));
293 window->timeout_event_id = g_timeout_add (1000,
294 call_window_update_timer, window);
295 empathy_debug (DEBUG_DOMAIN, "Timer started");
301 call_window_receiving_video_cb (EmpathyTpCall *call,
302 gboolean receiving_video,
303 EmpathyCallWindow *window)
305 empathy_debug (DEBUG_DOMAIN, "Receiving video signal received");
307 call_window_set_output_video_is_drawing (window, receiving_video);
311 call_window_sending_video_cb (EmpathyTpCall *call,
312 gboolean sending_video,
313 EmpathyCallWindow *window)
315 empathy_debug (DEBUG_DOMAIN, "Sending video signal received");
317 g_signal_handlers_block_by_func (window->video_button,
318 call_window_video_button_toggled_cb, window);
319 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (window->video_button),
321 g_signal_handlers_unblock_by_func (window->video_button,
322 call_window_video_button_toggled_cb, window);
326 call_window_socket_realized_cb (GtkWidget *widget,
327 EmpathyCallWindow *window)
329 if (widget == window->preview_video_socket)
331 empathy_debug (DEBUG_DOMAIN, "Preview socket realized");
332 empathy_tp_call_add_preview_video (window->call,
333 gtk_socket_get_id (GTK_SOCKET (window->preview_video_socket)));
337 empathy_debug (DEBUG_DOMAIN, "Output socket realized");
342 call_window_start_call_button_clicked_cb (GtkWidget *widget,
343 EmpathyCallWindow *window)
346 gboolean is_incoming;
348 empathy_debug (DEBUG_DOMAIN, "Start call clicked");
350 gtk_widget_set_sensitive (window->start_call_button, FALSE);
351 g_object_get (G_OBJECT (window->call), "is-incoming", &is_incoming, NULL);
354 empathy_tp_call_accept_incoming_call (window->call);
355 send_video = gtk_toggle_button_get_active
356 (GTK_TOGGLE_BUTTON (window->video_button));
357 empathy_tp_call_request_video_stream_direction (window->call, send_video);
358 g_signal_connect (GTK_OBJECT (window->video_button), "toggled",
359 G_CALLBACK (call_window_video_button_toggled_cb), window);
364 call_window_end_call_button_clicked_cb (GtkWidget *widget,
365 EmpathyCallWindow *window)
367 empathy_debug (DEBUG_DOMAIN, "End call clicked");
369 call_window_set_output_video_is_drawing (window, FALSE);
370 empathy_tp_call_close_channel (window->call);
371 gtk_widget_set_sensitive (window->end_call_button, FALSE);
372 gtk_widget_set_sensitive (window->start_call_button, FALSE);
376 call_window_output_volume_changed_cb (GtkWidget *scale,
377 EmpathyCallWindow *window)
381 volume = (guint) gtk_range_get_value (GTK_RANGE (scale));
383 empathy_debug (DEBUG_DOMAIN, "Output volume changed - %u", volume);
385 empathy_tp_call_set_output_volume (window->call, volume);
389 call_window_output_mute_button_toggled_cb (GtkWidget *button,
390 EmpathyCallWindow *window)
394 is_muted = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
396 empathy_debug (DEBUG_DOMAIN, "Mute output toggled - %d", is_muted);
398 empathy_tp_call_mute_output (window->call, is_muted);
402 call_window_input_mute_button_toggled_cb (GtkWidget *button,
403 EmpathyCallWindow *window)
407 is_muted = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
409 empathy_debug (DEBUG_DOMAIN, "Mute input toggled - %d", is_muted);
411 empathy_tp_call_mute_input (window->call, is_muted);
415 call_window_destroy_cb (GtkWidget *widget,
416 EmpathyCallWindow *window)
418 g_signal_handlers_disconnect_by_func (window->call,
419 call_window_status_changed_cb, window);
420 g_signal_handlers_disconnect_by_func (window->call,
421 call_window_receiving_video_cb, window);
422 g_signal_handlers_disconnect_by_func (window->call,
423 call_window_sending_video_cb, window);
425 g_object_unref (window->call);
426 g_object_unref (window->output_video_socket);
427 g_object_unref (window->preview_video_socket);
428 g_object_unref (window->output_video_label);
430 g_slice_free (EmpathyCallWindow, window);
434 empathy_call_window_new (EmpathyTpCall *call)
436 EmpathyCallWindow *window;
441 g_return_val_if_fail (EMPATHY_IS_TP_CALL (call), NULL);
443 window = g_slice_new0 (EmpathyCallWindow);
444 window->call = g_object_ref (call);
446 filename = empathy_file_lookup ("empathy-call-window.glade", "src");
447 glade = empathy_glade_get_file (filename,
450 "window", &window->window,
451 "status_label", &window->status_label,
452 "start_call_button", &window->start_call_button,
453 "end_call_button", &window->end_call_button,
454 "input_volume_scale", &window->input_volume_scale,
455 "output_volume_scale", &window->output_volume_scale,
456 "input_mute_button", &window->input_mute_button,
457 "output_mute_button", &window->output_mute_button,
458 "preview_video_frame", &window->preview_video_frame,
459 "output_video_frame", &window->output_video_frame,
460 "video_button", &window->video_button,
464 empathy_glade_connect (glade,
466 "window", "destroy", call_window_destroy_cb,
467 "window", "delete_event", call_window_delete_event_cb,
468 "input_mute_button", "toggled", call_window_input_mute_button_toggled_cb,
469 "output_mute_button", "toggled", call_window_output_mute_button_toggled_cb,
470 "output_volume_scale", "value-changed", call_window_output_volume_changed_cb,
471 "start_call_button", "clicked", call_window_start_call_button_clicked_cb,
472 "end_call_button", "clicked", call_window_end_call_button_clicked_cb,
475 g_object_unref (glade);
477 /* Output video label */
478 window->output_video_label = g_object_ref (gtk_label_new ("No video output"));
479 gtk_container_add (GTK_CONTAINER (window->output_video_frame),
480 window->output_video_label);
481 gtk_widget_show (window->output_video_label);
483 /* Output video socket */
484 window->output_video_socket = g_object_ref (gtk_socket_new ());
485 g_signal_connect (GTK_OBJECT (window->output_video_socket), "realize",
486 G_CALLBACK (call_window_socket_realized_cb), window);
487 gtk_widget_show (window->output_video_socket);
489 /* Preview video socket */
490 window->preview_video_socket = g_object_ref (gtk_socket_new ());
491 g_signal_connect (GTK_OBJECT (window->preview_video_socket), "realize",
492 G_CALLBACK (call_window_socket_realized_cb), window);
493 gtk_container_add (GTK_CONTAINER (window->preview_video_frame),
494 window->preview_video_socket);
495 gtk_widget_show (window->preview_video_socket);
497 g_signal_connect (G_OBJECT (window->call), "status-changed",
498 G_CALLBACK (call_window_status_changed_cb),
500 g_signal_connect (G_OBJECT (window->call), "receiving-video",
501 G_CALLBACK (call_window_receiving_video_cb),
503 g_signal_connect (G_OBJECT (window->call), "sending-video",
504 G_CALLBACK (call_window_sending_video_cb),
507 window->is_drawing = FALSE;
509 g_object_get (G_OBJECT (window->call), "status", &status, NULL);
511 if (status == EMPATHY_TP_CALL_STATUS_READYING)
513 gtk_window_set_title (GTK_WINDOW (window->window), "Empathy Call");
514 gtk_label_set_text (GTK_LABEL (window->status_label), "Readying");
517 gtk_widget_show (window->window);
519 return window->window;