2 * empathy-call-window.c - Source for EmpathyCallWindow
3 * Copyright (C) 2008-2011 Collabora Ltd.
4 * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk>
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.
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.
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
28 #include <gdk/gdkkeysyms.h>
31 #include <glib/gi18n.h>
33 #include <clutter/clutter.h>
34 #include <clutter-gtk/clutter-gtk.h>
35 #include <clutter-gst/clutter-gst.h>
37 #include <telepathy-glib/util.h>
38 #include <telepathy-farstream/telepathy-farstream.h>
39 #include <telepathy-glib/util.h>
41 #include <gst/farsight/fs-element-added-notifier.h>
42 #include <gst/farsight/fs-utils.h>
44 #include <libempathy/empathy-camera-monitor.h>
45 #include <libempathy/empathy-gsettings.h>
46 #include <libempathy/empathy-tp-contact-factory.h>
47 #include <libempathy/empathy-request-util.h>
48 #include <libempathy/empathy-utils.h>
50 #include <libempathy-gtk/empathy-avatar-image.h>
51 #include <libempathy-gtk/empathy-dialpad-widget.h>
52 #include <libempathy-gtk/empathy-ui-utils.h>
53 #include <libempathy-gtk/empathy-sound-manager.h>
54 #include <libempathy-gtk/empathy-geometry.h>
55 #include <libempathy-gtk/empathy-images.h>
57 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
58 #include <libempathy/empathy-debug.h>
60 #include "empathy-call-window.h"
61 #include "empathy-call-window-fullscreen.h"
62 #include "empathy-call-factory.h"
63 #include "empathy-video-widget.h"
64 #include "empathy-about-dialog.h"
65 #include "empathy-audio-src.h"
66 #include "empathy-audio-sink.h"
67 #include "empathy-video-src.h"
68 #include "empathy-mic-menu.h"
69 #include "empathy-preferences.h"
70 #include "empathy-rounded-actor.h"
71 #include "empathy-rounded-rectangle.h"
72 #include "empathy-rounded-texture.h"
73 #include "empathy-camera-menu.h"
75 #define CONTENT_HBOX_BORDER_WIDTH 6
76 #define CONTENT_HBOX_SPACING 3
77 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
79 #define SELF_VIDEO_SECTION_WIDTH 120
80 #define SELF_VIDEO_SECTION_HEIGHT 90
81 #define SELF_VIDEO_SECTION_MARGIN 10
83 #define FLOATING_TOOLBAR_OPACITY 192
84 #define FLOATING_TOOLBAR_WIDTH 280
85 #define FLOATING_TOOLBAR_HEIGHT 36
86 #define FLOATING_TOOLBAR_SPACING 20
88 /* The avatar's default width and height are set to the same value because we
89 want a square icon. */
90 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
91 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
92 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
94 #define SMALL_TOOLBAR_SIZE 36
96 /* If an video input error occurs, the error message will start with "v4l" */
97 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
99 /* The time interval in milliseconds between 2 outgoing rings */
100 #define MS_BETWEEN_RING 500
102 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
105 PROP_CALL_HANDLER = 1,
109 RINGING, /* Incoming call */
110 CONNECTING, /* Outgoing call */
111 CONNECTED, /* Connected */
112 HELD, /* Connected, but on hold */
113 DISCONNECTED, /* Disconnected */
114 REDIALING /* Redialing (special case of CONNECTING) */
118 CAMERA_STATE_OFF = 0,
124 PREVIEW_POS_TOP_LEFT,
125 PREVIEW_POS_TOP_RIGHT,
126 PREVIEW_POS_BOTTOM_LEFT,
127 PREVIEW_POS_BOTTOM_RIGHT,
130 struct _EmpathyCallWindowPriv
132 gboolean dispose_has_run;
133 EmpathyCallHandler *handler;
135 EmpathyContact *contact;
137 EmpathyCameraMonitor *camera_monitor;
142 GtkUIManager *ui_manager;
143 GtkWidget *errors_vbox;
144 /* widget displays the video received from the remote user. This widget is
145 * alive only during call. */
146 ClutterActor *video_output;
147 ClutterActor *video_preview;
148 ClutterActor *drag_preview;
149 ClutterActor *preview_shown_button;
150 ClutterActor *preview_hidden_button;
151 ClutterActor *preview_rectangle1;
152 ClutterActor *preview_rectangle2;
153 ClutterActor *preview_rectangle3;
154 ClutterActor *preview_rectangle4;
155 ClutterActor *preview_rectangle_box1;
156 ClutterActor *preview_rectangle_box2;
157 ClutterActor *preview_rectangle_box3;
158 ClutterActor *preview_rectangle_box4;
159 ClutterActor *preview_spinner_actor;
160 GtkWidget *preview_spinner_widget;
161 GtkWidget *video_container;
162 GtkWidget *remote_user_avatar_widget;
163 GtkWidget *remote_user_avatar_toolbar;
164 GtkWidget *remote_user_name_toolbar;
165 GtkWidget *status_label;
166 GtkWidget *hangup_button;
167 GtkWidget *audio_call_button;
168 GtkWidget *video_call_button;
169 GtkWidget *mic_button;
170 GtkWidget *volume_button;
171 GtkWidget *camera_button;
172 GtkWidget *dialpad_button;
174 GtkWidget *bottom_toolbar;
175 ClutterActor *floating_toolbar;
177 GtkAction *menu_fullscreen;
178 GtkAction *menu_swap_camera;
180 ClutterState *transitions;
182 /* The box that contains self and remote avatar and video
183 input/output. When we redial, we destroy and re-create the box */
184 ClutterActor *video_box;
185 ClutterLayoutManager *video_layout;
187 /* Coordinates of the preview drag event's start. */
188 PreviewPosition preview_pos;
190 /* We keep a reference on the hbox which contains the main content so we can
191 easilly repack everything when toggling fullscreen */
192 GtkWidget *content_hbox;
194 /* These are used to accept or reject an incoming call when the status
196 GtkWidget *incoming_call_dialog;
197 TpyCallChannel *pending_channel;
198 TpChannelDispatchOperation *pending_cdo;
199 TpAddDispatchOperationContext *pending_context;
201 gulong video_output_motion_handler_id;
202 guint bus_message_source_id;
204 /* String that contains the queued tones to send after the current ones
207 gboolean sending_tones;
208 GtkWidget *dtmf_panel;
211 GtkWidget *details_vbox;
212 GtkWidget *vcodec_encoding_label;
213 GtkWidget *acodec_encoding_label;
214 GtkWidget *vcodec_decoding_label;
215 GtkWidget *acodec_decoding_label;
217 GtkWidget *audio_remote_candidate_label;
218 GtkWidget *audio_local_candidate_label;
219 GtkWidget *video_remote_candidate_label;
220 GtkWidget *video_local_candidate_label;
221 GtkWidget *video_remote_candidate_info_img;
222 GtkWidget *video_local_candidate_info_img;
223 GtkWidget *audio_remote_candidate_info_img;
224 GtkWidget *audio_local_candidate_info_img;
226 GstElement *video_input;
227 GstElement *video_preview_sink;
228 GstElement *video_output_sink;
229 GstElement *audio_input;
230 GstElement *audio_output;
231 gboolean audio_output_added;
232 GstElement *pipeline;
233 GstElement *video_tee;
243 gboolean call_started;
244 gboolean sending_video;
245 CameraState camera_state;
247 EmpathyCallWindowFullscreen *fullscreen;
248 gboolean is_fullscreen;
253 guint inactivity_src;
255 /* Those fields represent the state of the window before it actually was in
257 gboolean dialpad_was_visible_before_fs;
258 gint original_width_before_fs;
259 gint original_height_before_fs;
261 gint x, y, w, h, dialpad_width;
264 /* TRUE if the call should be started when the pipeline is playing */
265 gboolean start_call_when_playing;
266 /* TRUE if we requested to set the pipeline in the playing state */
267 gboolean pipeline_playing;
269 EmpathySoundManager *sound_mgr;
272 EmpathyMicMenu *mic_menu;
273 EmpathyCameraMenu *camera_menu;
276 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
278 static void empathy_call_window_realized_cb (GtkWidget *widget,
279 EmpathyCallWindow *window);
281 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
282 GdkEvent *event, EmpathyCallWindow *window);
284 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
285 GdkEventWindowState *event, EmpathyCallWindow *window);
287 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
290 static void empathy_call_window_hangup_cb (gpointer object,
291 EmpathyCallWindow *window);
293 static void empathy_call_window_fullscreen_cb (gpointer object,
294 EmpathyCallWindow *window);
296 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
298 static gboolean empathy_call_window_video_button_press_cb (
299 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
301 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
302 GdkEventKey *event, EmpathyCallWindow *window);
304 static gboolean empathy_call_window_video_output_motion_notify (
305 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
307 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
310 static void empathy_call_window_connect_handler (EmpathyCallWindow *self);
312 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
313 EmpathyCallWindow *window);
315 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
317 static void empathy_call_window_status_message (EmpathyCallWindow *window,
320 static gboolean empathy_call_window_bus_message (GstBus *bus,
321 GstMessage *message, gpointer user_data);
324 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
327 gtk_widget_set_visible (self->priv->hangup_button, show);
328 gtk_widget_set_visible (self->priv->audio_call_button, !show);
329 gtk_widget_set_visible (self->priv->video_call_button, !show);
333 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
334 EmpathyCallWindow *self)
336 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
337 empathy_call_window_restart_call (self);
341 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
342 EmpathyCallWindow *self)
344 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
345 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
346 empathy_call_window_restart_call (self);
350 empathy_call_window_emit_tones (EmpathyCallWindow *self)
354 if (tp_str_empty (self->priv->tones->str))
357 g_object_get (self->priv->handler, "call-channel", &channel, NULL);
359 DEBUG ("Emitting multiple tones: %s", self->priv->tones->str);
361 tp_cli_channel_interface_dtmf_call_multiple_tones (channel, -1,
362 self->priv->tones->str,
363 NULL, NULL, NULL, NULL);
365 self->priv->sending_tones = TRUE;
367 g_string_set_size (self->priv->tones, 0);
369 g_object_unref (channel);
373 empathy_call_window_maybe_emit_tones (EmpathyCallWindow *self)
375 if (self->priv->sending_tones)
378 empathy_call_window_emit_tones (self);
382 empathy_call_window_tones_stopped_cb (TpChannel *proxy,
383 gboolean arg_cancelled,
385 GObject *weak_object)
387 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
389 self->priv->sending_tones = FALSE;
391 empathy_call_window_emit_tones (self);
395 dtmf_start_tone_cb (EmpathyDialpadWidget *dialpad,
397 EmpathyCallWindow *self)
399 EmpathyCallWindowPriv *priv = GET_PRIV (self);
401 g_string_append_c (priv->tones, tp_dtmf_event_to_char (event));
403 empathy_call_window_maybe_emit_tones (self);
407 empathy_call_window_raise_actors (EmpathyCallWindow *self)
409 clutter_actor_raise_top (self->priv->floating_toolbar);
411 clutter_actor_raise_top (self->priv->preview_rectangle_box1);
412 clutter_actor_raise_top (self->priv->preview_rectangle_box2);
413 clutter_actor_raise_top (self->priv->preview_rectangle_box3);
414 clutter_actor_raise_top (self->priv->preview_rectangle_box4);
418 empathy_call_window_show_video_output (EmpathyCallWindow *self,
421 if (self->priv->video_output != NULL)
422 g_object_set (self->priv->video_output, "visible", show, NULL);
424 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
426 empathy_call_window_raise_actors (self);
430 create_video_output_widget (EmpathyCallWindow *self)
432 EmpathyCallWindowPriv *priv = GET_PRIV (self);
434 g_assert (priv->video_output == NULL);
435 g_assert (priv->pipeline != NULL);
437 priv->video_output = clutter_texture_new ();
439 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
442 priv->video_output_sink = clutter_gst_video_sink_new (
443 CLUTTER_TEXTURE (priv->video_output));
445 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
448 gtk_widget_add_events (priv->video_container,
449 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
450 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
451 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
455 create_video_input (EmpathyCallWindow *self)
457 EmpathyCallWindowPriv *priv = GET_PRIV (self);
459 g_assert (priv->video_input == NULL);
460 priv->video_input = empathy_video_src_new ();
461 gst_object_ref (priv->video_input);
462 gst_object_sink (priv->video_input);
466 audio_control_volume_to_element (GBinding *binding,
467 const GValue *source_value,
468 GValue *target_value,
471 /* AudioControl volume is 0-255, with -1 for unknown */
474 hv = g_value_get_int (source_value);
479 g_value_set_double (target_value, hv/255.0);
485 element_volume_to_audio_control (GBinding *binding,
486 const GValue *source_value,
487 GValue *target_value,
492 ev = g_value_get_double (source_value);
493 ev = CLAMP (ev, 0.0, 1.0);
495 g_value_set_int (target_value, ev * 255);
500 create_audio_input (EmpathyCallWindow *self)
502 EmpathyCallWindowPriv *priv = GET_PRIV (self);
504 g_assert (priv->audio_input == NULL);
505 priv->audio_input = empathy_audio_src_new ();
506 gst_object_ref (priv->audio_input);
507 gst_object_sink (priv->audio_input);
509 g_object_bind_property (priv->mic_button, "active",
510 priv->audio_input, "mute",
511 G_BINDING_BIDIRECTIONAL |
512 G_BINDING_INVERT_BOOLEAN | G_BINDING_SYNC_CREATE);
516 add_video_preview_to_pipeline (EmpathyCallWindow *self)
518 EmpathyCallWindowPriv *priv = GET_PRIV (self);
521 g_assert (priv->video_preview != NULL);
522 g_assert (priv->pipeline != NULL);
523 g_assert (priv->video_input != NULL);
524 g_assert (priv->video_tee != NULL);
526 preview = priv->video_preview_sink;
528 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
530 g_warning ("Could not add video input to pipeline");
534 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
536 g_warning ("Could not add video preview to pipeline");
540 if (!gst_element_link (priv->video_input, priv->video_tee))
542 g_warning ("Could not link video input to video tee");
546 if (!gst_element_link (priv->video_tee, preview))
548 g_warning ("Could not link video tee to video preview");
554 empathy_call_window_disable_camera_cb (GtkAction *action,
555 EmpathyCallWindow *self)
557 clutter_actor_destroy (self->priv->preview_hidden_button);
559 gtk_toggle_tool_button_set_active (
560 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
564 empathy_call_window_minimise_camera_cb (GtkAction *action,
565 EmpathyCallWindow *self)
567 clutter_actor_hide (self->priv->video_preview);
568 clutter_actor_show (self->priv->preview_hidden_button);
572 empathy_call_window_maximise_camera_cb (GtkAction *action,
573 EmpathyCallWindow *self)
575 clutter_actor_show (self->priv->video_preview);
576 clutter_actor_hide (self->priv->preview_hidden_button);
580 empathy_call_window_swap_camera_cb (GtkAction *action,
581 EmpathyCallWindow *self)
583 const GList *cameras, *l;
586 DEBUG ("Swapping the camera");
588 cameras = empathy_camera_monitor_get_cameras (self->priv->camera_monitor);
589 current_cam = empathy_video_src_dup_device (
590 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
592 for (l = cameras; l != NULL; l = l->next)
594 EmpathyCamera *camera = l->data;
596 if (!tp_strdiff (camera->device, current_cam))
601 next = l->next->data;
603 next = cameras->data;
605 /* EmpathyCameraMenu will update itself and do the actual change
607 g_settings_set_string (self->priv->settings,
608 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
615 g_free (current_cam);
619 empathy_call_window_camera_added_cb (EmpathyCameraMonitor *monitor,
620 EmpathyCamera *camera,
621 EmpathyCallWindow *self)
623 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
625 gtk_action_set_visible (self->priv->menu_swap_camera,
626 g_list_length ((GList *) cameras) >= 2);
630 empathy_call_window_camera_removed_cb (EmpathyCameraMonitor *monitor,
631 EmpathyCamera *camera,
632 EmpathyCallWindow *self)
634 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
636 gtk_action_set_visible (self->priv->menu_swap_camera,
637 g_list_length ((GList *) cameras) >= 2);
641 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
642 EmpathyCallWindow *self)
646 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
648 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
649 0, gtk_get_current_event_time ());
650 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
654 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
655 EmpathyCallWindow *self)
659 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
660 "/preview-hidden-menu");
661 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
662 0, gtk_get_current_event_time ());
663 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
666 static ClutterActor *
667 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
669 ClutterBinAlignment x,
670 ClutterBinAlignment y)
672 ClutterLayoutManager *layout1, *layout2;
673 ClutterActor *rectangle;
674 ClutterActor *box1, *box2;
676 layout1 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
677 CLUTTER_BIN_ALIGNMENT_START);
679 box1 = clutter_box_new (layout1);
683 rectangle = empathy_rounded_rectangle_new (
684 SELF_VIDEO_SECTION_WIDTH + 5,
685 SELF_VIDEO_SECTION_HEIGHT + 5);
687 clutter_actor_set_size (box1,
688 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
689 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
690 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
692 layout2 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
693 CLUTTER_BIN_ALIGNMENT_CENTER);
695 /* We have a box with the margins and the video in the middle inside
696 * a bigger box with an extra bottom margin so we're not on top of
697 * the floating toolbar. */
698 box2 = clutter_box_new (layout2);
700 clutter_actor_set_size (box2,
701 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
702 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
704 clutter_container_add_actor (CLUTTER_CONTAINER (box1), box2);
705 clutter_container_add_actor (CLUTTER_CONTAINER (box2), rectangle);
707 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->video_layout),
710 clutter_actor_hide (rectangle);
716 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
718 self->priv->preview_rectangle1 =
719 empathy_call_window_create_preview_rectangle (self,
720 &self->priv->preview_rectangle_box1,
721 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
722 self->priv->preview_rectangle2 =
723 empathy_call_window_create_preview_rectangle (self,
724 &self->priv->preview_rectangle_box2,
725 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
726 self->priv->preview_rectangle3 =
727 empathy_call_window_create_preview_rectangle (self,
728 &self->priv->preview_rectangle_box3,
729 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
730 self->priv->preview_rectangle4 =
731 empathy_call_window_create_preview_rectangle (self,
732 &self->priv->preview_rectangle_box4,
733 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
737 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
740 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
741 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
742 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
743 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
747 empathy_call_window_get_preview_coordinates (EmpathyCallWindow *self,
752 guint ret_x = 0, ret_y = 0;
755 if (!clutter_actor_has_allocation (self->priv->video_box))
758 clutter_actor_get_geometry (self->priv->video_box, &box);
762 case PREVIEW_POS_TOP_LEFT:
763 ret_x = ret_y = SELF_VIDEO_SECTION_MARGIN;
765 case PREVIEW_POS_TOP_RIGHT:
766 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
767 - SELF_VIDEO_SECTION_WIDTH;
768 ret_y = SELF_VIDEO_SECTION_MARGIN;
770 case PREVIEW_POS_BOTTOM_LEFT:
771 ret_x = SELF_VIDEO_SECTION_MARGIN;
772 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
773 - SELF_VIDEO_SECTION_HEIGHT
774 - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING;
776 case PREVIEW_POS_BOTTOM_RIGHT:
777 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
778 - SELF_VIDEO_SECTION_WIDTH;
779 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
780 - SELF_VIDEO_SECTION_HEIGHT - FLOATING_TOOLBAR_HEIGHT
781 - FLOATING_TOOLBAR_SPACING;
784 g_warn_if_reached ();
795 static PreviewPosition
796 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
801 PreviewPosition pos = PREVIEW_POS_NONE;
803 if (!clutter_actor_has_allocation (self->priv->video_box))
806 clutter_actor_get_geometry (self->priv->video_box, &box);
808 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
809 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
810 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
811 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
813 pos = PREVIEW_POS_TOP_LEFT;
815 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
816 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
817 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
818 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
820 pos = PREVIEW_POS_TOP_RIGHT;
822 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
823 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
824 box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
825 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
827 pos = PREVIEW_POS_BOTTOM_LEFT;
829 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
830 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
831 box.height - SELF_VIDEO_SECTION_MARGIN - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
832 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
834 pos = PREVIEW_POS_BOTTOM_RIGHT;
840 static ClutterActor *
841 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
844 ClutterActor *rectangle;
848 case PREVIEW_POS_TOP_LEFT:
849 rectangle = self->priv->preview_rectangle1;
851 case PREVIEW_POS_TOP_RIGHT:
852 rectangle = self->priv->preview_rectangle3;
854 case PREVIEW_POS_BOTTOM_LEFT:
855 rectangle = self->priv->preview_rectangle2;
857 case PREVIEW_POS_BOTTOM_RIGHT:
858 rectangle = self->priv->preview_rectangle4;
868 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
871 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->video_layout);
873 DEBUG ("moving the video preview to %d", pos);
875 self->priv->preview_pos = pos;
879 case PREVIEW_POS_TOP_LEFT:
880 clutter_bin_layout_set_alignment (layout,
881 self->priv->video_preview,
882 CLUTTER_BIN_ALIGNMENT_START,
883 CLUTTER_BIN_ALIGNMENT_START);
885 case PREVIEW_POS_TOP_RIGHT:
886 clutter_bin_layout_set_alignment (layout,
887 self->priv->video_preview,
888 CLUTTER_BIN_ALIGNMENT_END,
889 CLUTTER_BIN_ALIGNMENT_START);
891 case PREVIEW_POS_BOTTOM_LEFT:
892 clutter_bin_layout_set_alignment (layout,
893 self->priv->video_preview,
894 CLUTTER_BIN_ALIGNMENT_START,
895 CLUTTER_BIN_ALIGNMENT_END);
897 case PREVIEW_POS_BOTTOM_RIGHT:
898 clutter_bin_layout_set_alignment (layout,
899 self->priv->video_preview,
900 CLUTTER_BIN_ALIGNMENT_END,
901 CLUTTER_BIN_ALIGNMENT_END);
904 g_warn_if_reached ();
907 g_settings_set_enum (self->priv->settings, "camera-position", pos);
911 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
914 ClutterActor *rectangle;
916 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
918 empathy_rounded_rectangle_set_border_width (
919 EMPATHY_ROUNDED_RECTANGLE (rectangle), 5);
920 empathy_rounded_rectangle_set_border_color (
921 EMPATHY_ROUNDED_RECTANGLE (rectangle), CLUTTER_COLOR_Red);
925 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
926 ClutterActor *rectangle)
928 empathy_rounded_rectangle_set_border_width (
929 EMPATHY_ROUNDED_RECTANGLE (rectangle), 1);
930 empathy_rounded_rectangle_set_border_color (
931 EMPATHY_ROUNDED_RECTANGLE (rectangle), CLUTTER_COLOR_Black);
935 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
937 ClutterActor *rectangle;
939 rectangle = empathy_call_window_get_preview_rectangle (self,
940 self->priv->preview_pos);
942 /* We don't want to darken the rectangle where the preview
945 if (self->priv->preview_rectangle1 != rectangle)
946 empathy_call_window_darken_preview_rectangle (self,
947 self->priv->preview_rectangle1);
949 if (self->priv->preview_rectangle2 != rectangle)
950 empathy_call_window_darken_preview_rectangle (self,
951 self->priv->preview_rectangle2);
953 if (self->priv->preview_rectangle3 != rectangle)
954 empathy_call_window_darken_preview_rectangle (self,
955 self->priv->preview_rectangle3);
957 if (self->priv->preview_rectangle4 != rectangle)
958 empathy_call_window_darken_preview_rectangle (self,
959 self->priv->preview_rectangle4);
963 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
967 ClutterModifierType modifiers,
968 EmpathyCallWindow *self)
970 ClutterActor *stage = clutter_actor_get_stage (actor);
973 self->priv->drag_preview = clutter_clone_new (actor);
975 clutter_container_add_actor (CLUTTER_CONTAINER (stage),
976 self->priv->drag_preview);
978 clutter_actor_transform_stage_point (actor, event_x, event_y,
981 clutter_actor_set_position (self->priv->drag_preview,
982 event_x - rel_x, event_y - rel_y);
984 clutter_drag_action_set_drag_handle (action,
985 self->priv->drag_preview);
987 clutter_actor_set_opacity (actor, 0);
988 clutter_actor_hide (self->priv->preview_shown_button);
990 empathy_call_window_show_preview_rectangles (self, TRUE);
991 empathy_call_window_darken_preview_rectangles (self);
995 empathy_call_window_on_animation_completed_cb (ClutterAnimation *animation,
998 clutter_actor_set_opacity (actor, 255);
1002 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
1003 ClutterActor *actor,
1006 ClutterModifierType modifiers,
1007 EmpathyCallWindow *self)
1009 PreviewPosition pos;
1012 /* Get the position before destroying the drag actor, otherwise the
1013 * preview_box allocation won't be valid and we won't be able to
1014 * calculate the position. */
1015 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
1017 empathy_call_window_get_preview_coordinates (self,
1018 pos != PREVIEW_POS_NONE ? pos : self->priv->preview_pos,
1021 /* Move the preview to the destination and destroy it afterwards */
1022 clutter_actor_animate (self->priv->drag_preview, CLUTTER_LINEAR, 500,
1025 "signal-swapped-after::completed",
1026 clutter_actor_destroy, self->priv->drag_preview,
1027 "signal-swapped-after::completed",
1028 clutter_actor_show, self->priv->preview_shown_button,
1029 "signal::completed",
1030 empathy_call_window_on_animation_completed_cb, actor,
1033 self->priv->drag_preview = NULL;
1035 if (pos != PREVIEW_POS_NONE)
1036 empathy_call_window_move_video_preview (self, pos);
1038 empathy_call_window_show_preview_rectangles (self, FALSE);
1042 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
1043 ClutterActor *actor,
1046 EmpathyCallWindow *self)
1048 PreviewPosition pos;
1049 gfloat event_x, event_y;
1051 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
1053 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
1055 if (pos != PREVIEW_POS_NONE)
1056 empathy_call_window_highlight_preview_rectangle (self, pos);
1058 empathy_call_window_darken_preview_rectangles (self);
1062 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
1063 ClutterCrossingEvent *event,
1064 EmpathyCallWindow *self)
1066 ClutterActor *rectangle;
1068 rectangle = empathy_call_window_get_preview_rectangle (self,
1069 self->priv->preview_pos);
1071 empathy_call_window_highlight_preview_rectangle (self,
1072 self->priv->preview_pos);
1074 clutter_actor_show (rectangle);
1080 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
1081 ClutterCrossingEvent *event,
1082 EmpathyCallWindow *self)
1084 ClutterActor *rectangle;
1086 rectangle = empathy_call_window_get_preview_rectangle (self,
1087 self->priv->preview_pos);
1089 empathy_call_window_darken_preview_rectangle (self, rectangle);
1091 clutter_actor_hide (rectangle);
1097 create_video_preview (EmpathyCallWindow *self)
1099 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1100 ClutterLayoutManager *layout, *layout_center, *layout_end;
1101 ClutterActor *preview;
1104 ClutterAction *action;
1106 PreviewPosition pos;
1107 GdkRGBA transparent = { 0., 0., 0., 0. };
1109 g_assert (priv->video_preview == NULL);
1111 pos = g_settings_get_enum (priv->settings, "camera-position");
1113 preview = empathy_rounded_texture_new ();
1114 clutter_actor_set_size (preview,
1115 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1116 priv->video_preview_sink = clutter_gst_video_sink_new (
1117 CLUTTER_TEXTURE (preview));
1119 /* Add a little offset to the video preview */
1120 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1121 CLUTTER_BIN_ALIGNMENT_START);
1122 priv->video_preview = clutter_box_new (layout);
1123 clutter_actor_set_size (priv->video_preview,
1124 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1125 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
1126 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
1128 /* Spinner for when changing the camera device */
1129 priv->preview_spinner_widget = gtk_spinner_new ();
1130 priv->preview_spinner_actor = empathy_rounded_actor_new ();
1131 empathy_rounded_actor_set_round_factor (
1132 EMPATHY_ROUNDED_ACTOR (priv->preview_spinner_actor), 16);
1134 g_object_set (priv->preview_spinner_widget, "expand", TRUE, NULL);
1135 gtk_widget_override_background_color (
1136 gtk_clutter_actor_get_widget (
1137 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor)),
1138 GTK_STATE_FLAG_NORMAL, &transparent);
1139 gtk_widget_show (priv->preview_spinner_widget);
1142 GTK_CONTAINER (gtk_clutter_actor_get_widget (
1143 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor))),
1144 priv->preview_spinner_widget);
1145 clutter_actor_set_size (priv->preview_spinner_actor,
1146 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1147 clutter_actor_set_opacity (priv->preview_spinner_actor, 128);
1148 clutter_actor_hide (priv->preview_spinner_actor);
1150 /* We have a box with the margins and the video in the middle inside
1151 * a bigger box with an extra bottom margin so we're not on top of
1152 * the floating toolbar. */
1153 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1154 CLUTTER_BIN_ALIGNMENT_CENTER);
1155 box = clutter_box_new (layout_center);
1156 clutter_actor_set_size (box,
1157 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1158 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1160 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
1161 clutter_container_add_actor (CLUTTER_CONTAINER (box),
1162 priv->preview_spinner_actor);
1163 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1165 g_object_set (priv->video_preview_sink,
1170 /* Translators: this is an "Info" label. It should be as short
1172 button = gtk_button_new_with_label (_("i"));
1173 priv->preview_shown_button = b = empathy_rounded_actor_new ();
1175 GTK_CONTAINER (gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (b))),
1177 clutter_actor_set_size (b, 24, 24);
1179 layout_end = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_END,
1180 CLUTTER_BIN_ALIGNMENT_END);
1181 box = clutter_box_new (layout_end);
1182 clutter_actor_set_size (box,
1183 SELF_VIDEO_SECTION_WIDTH,
1184 SELF_VIDEO_SECTION_HEIGHT + SELF_VIDEO_SECTION_MARGIN);
1186 clutter_container_add_actor (CLUTTER_CONTAINER (box), b);
1187 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1189 g_signal_connect (button, "clicked",
1190 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
1193 /* Translators: this is an "Info" label. It should be as short
1195 button = gtk_button_new_with_label (_("i"));
1196 b = empathy_rounded_actor_new ();
1198 GTK_CONTAINER (gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (b))),
1200 clutter_actor_set_size (b, 24, 24);
1201 priv->preview_hidden_button = b;
1203 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1204 priv->preview_hidden_button,
1205 CLUTTER_BIN_ALIGNMENT_START,
1206 CLUTTER_BIN_ALIGNMENT_END);
1208 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1210 clutter_actor_hide (priv->preview_hidden_button);
1212 g_signal_connect (button, "clicked",
1213 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
1216 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1217 priv->video_preview,
1218 CLUTTER_BIN_ALIGNMENT_START,
1219 CLUTTER_BIN_ALIGNMENT_END);
1221 empathy_call_window_move_video_preview (self, pos);
1223 action = clutter_drag_action_new ();
1224 g_signal_connect (action, "drag-begin",
1225 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1226 g_signal_connect (action, "drag-end",
1227 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1228 g_signal_connect (action, "drag-motion",
1229 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1231 g_signal_connect (preview, "enter-event",
1232 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1233 g_signal_connect (preview, "leave-event",
1234 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1236 clutter_actor_add_action (preview, action);
1237 clutter_actor_set_reactive (preview, TRUE);
1238 clutter_actor_set_reactive (priv->preview_shown_button, TRUE);
1242 empathy_call_window_start_camera_spinning (EmpathyCallWindow *self)
1244 clutter_actor_show (self->priv->preview_spinner_actor);
1245 gtk_spinner_start (GTK_SPINNER (self->priv->preview_spinner_widget));
1249 empathy_call_window_stop_camera_spinning (EmpathyCallWindow *self)
1251 clutter_actor_hide (self->priv->preview_spinner_actor);
1252 gtk_spinner_stop (GTK_SPINNER (self->priv->preview_spinner_widget));
1256 empathy_call_window_play_camera (EmpathyCallWindow *self,
1259 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1260 GstElement *preview;
1263 if (priv->video_preview == NULL)
1265 create_video_preview (self);
1266 add_video_preview_to_pipeline (self);
1271 state = GST_STATE_PLAYING;
1275 empathy_call_window_start_camera_spinning (self);
1276 state = GST_STATE_NULL;
1279 preview = priv->video_preview_sink;
1281 gst_element_set_state (preview, state);
1282 gst_element_set_state (priv->video_tee, state);
1283 gst_element_set_state (priv->video_input, state);
1287 display_video_preview (EmpathyCallWindow *self,
1290 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1292 if (priv->video_preview == NULL)
1294 create_video_preview (self);
1295 add_video_preview_to_pipeline (self);
1300 /* Display the video preview */
1301 DEBUG ("Show video preview");
1303 empathy_call_window_play_camera (self, TRUE);
1304 clutter_actor_show (priv->video_preview);
1305 clutter_actor_raise_top (priv->floating_toolbar);
1309 /* Hide the video preview */
1310 DEBUG ("Hide video preview");
1312 if (priv->video_preview != NULL)
1314 clutter_actor_hide (priv->video_preview);
1315 empathy_call_window_play_camera (self, FALSE);
1321 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1323 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1325 empathy_call_window_status_message (window, _("Connecting…"));
1326 priv->call_state = CONNECTING;
1328 /* Show the toolbar */
1329 clutter_state_set_state (priv->transitions, "fade-in");
1332 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1333 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1337 disable_camera (EmpathyCallWindow *self)
1339 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1341 if (priv->camera_state == CAMERA_STATE_OFF)
1344 DEBUG ("Disable camera");
1346 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1348 priv->camera_state = CAMERA_STATE_OFF;
1352 enable_camera (EmpathyCallWindow *self)
1354 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1356 if (priv->camera_state == CAMERA_STATE_ON)
1359 if (priv->video_input == NULL)
1361 DEBUG ("Can't enable camera, no input");
1365 DEBUG ("Enable camera");
1367 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1369 priv->camera_state = CAMERA_STATE_ON;
1373 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
1374 EmpathyCallWindow *self)
1376 if (gtk_toggle_tool_button_get_active (toggle))
1377 enable_camera (self);
1379 disable_camera (self);
1383 create_pipeline (EmpathyCallWindow *self)
1385 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1388 g_assert (priv->pipeline == NULL);
1390 priv->pipeline = gst_pipeline_new (NULL);
1391 priv->pipeline_playing = FALSE;
1393 priv->video_tee = gst_element_factory_make ("tee", NULL);
1394 gst_object_ref (priv->video_tee);
1395 gst_object_sink (priv->video_tee);
1397 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1399 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1400 priv->bus_message_source_id = gst_bus_add_watch (bus,
1401 empathy_call_window_bus_message, self);
1403 g_object_unref (bus);
1407 empathy_call_window_settings_cb (GtkAction *action,
1408 EmpathyCallWindow *self)
1410 gchar *args = g_strdup_printf ("-p %s",
1411 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1413 empathy_launch_program (BIN_DIR, "empathy", args);
1419 empathy_call_window_contents_cb (GtkAction *action,
1420 EmpathyCallWindow *self)
1422 empathy_url_show (GTK_WIDGET (self), "ghelp:empathy?audio-video");
1426 empathy_call_window_debug_cb (GtkAction *action,
1427 EmpathyCallWindow *self)
1429 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1433 empathy_call_window_about_cb (GtkAction *action,
1434 EmpathyCallWindow *self)
1436 empathy_about_dialog_new (GTK_WINDOW (self));
1440 empathy_call_window_toolbar_timeout (gpointer data)
1442 EmpathyCallWindow *self = data;
1444 /* We don't want to hide the toolbar if we're not in a call, as
1445 * to show the call status all the time. */
1446 if (self->priv->call_state != CONNECTING &&
1447 self->priv->call_state != DISCONNECTED)
1448 clutter_state_set_state (self->priv->transitions, "fade-out");
1454 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1456 EmpathyCallWindow *self)
1458 clutter_state_set_state (self->priv->transitions, "fade-in");
1460 if (self->priv->inactivity_src > 0)
1461 g_source_remove (self->priv->inactivity_src);
1463 self->priv->inactivity_src = g_timeout_add_seconds (3,
1464 empathy_call_window_toolbar_timeout, self);
1470 empathy_call_window_configure_event_cb (GtkWidget *widget,
1472 EmpathyCallWindow *self)
1474 GdkWindow *gdk_window;
1475 GdkWindowState window_state;
1477 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1478 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1480 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1481 &self->priv->dialpad_width, NULL);
1483 gdk_window = gtk_widget_get_window (widget);
1484 window_state = gdk_window_get_state (gdk_window);
1485 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1491 empathy_call_window_destroyed_cb (GtkWidget *object,
1492 EmpathyCallWindow *self)
1494 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1496 /* Save the geometry as if the dialpad was hidden. */
1497 empathy_geometry_save_values (GTK_WINDOW (self),
1498 self->priv->x, self->priv->y,
1499 self->priv->w - self->priv->dialpad_width, self->priv->h,
1500 self->priv->maximized);
1505 empathy_call_window_stage_allocation_changed_cb (ClutterActor *stage,
1507 ClutterBindConstraint *constraint)
1509 ClutterActorBox allocation;
1511 clutter_actor_get_allocation_box (stage, &allocation);
1513 clutter_bind_constraint_set_offset (constraint,
1514 allocation.y2 - allocation.y1 -
1515 FLOATING_TOOLBAR_SPACING - FLOATING_TOOLBAR_HEIGHT);
1519 empathy_call_window_incoming_call_response_cb (GtkDialog *dialog,
1521 EmpathyCallWindow *self)
1523 switch (response_id)
1525 case GTK_RESPONSE_ACCEPT:
1526 tp_channel_dispatch_operation_handle_with_async (
1527 self->priv->pending_cdo, EMPATHY_CALL_BUS_NAME, NULL, NULL);
1529 tp_clear_object (&self->priv->pending_cdo);
1530 tp_clear_object (&self->priv->pending_channel);
1531 tp_clear_object (&self->priv->pending_context);
1534 case GTK_RESPONSE_CANCEL:
1535 tp_channel_dispatch_operation_close_channels_async (
1536 self->priv->pending_cdo, NULL, NULL);
1538 empathy_call_window_status_message (self, _("Disconnected"));
1539 self->priv->call_state = DISCONNECTED;
1542 g_warn_if_reached ();
1547 empathy_call_window_set_state_ringing (EmpathyCallWindow *self)
1551 g_assert (self->priv->call_state != CONNECTED);
1553 video = tpy_call_channel_has_initial_video (self->priv->pending_channel);
1555 empathy_call_window_status_message (self, _("Incoming call"));
1556 self->priv->call_state = RINGING;
1558 self->priv->incoming_call_dialog = gtk_message_dialog_new (
1559 GTK_WINDOW (self), GTK_DIALOG_MODAL,
1560 GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
1561 video ? _("Incoming video call from %s") : _("Incoming call from %s"),
1562 empathy_contact_get_alias (self->priv->contact));
1564 gtk_dialog_add_buttons (GTK_DIALOG (self->priv->incoming_call_dialog),
1565 _("Reject"), GTK_RESPONSE_CANCEL,
1566 _("Answer"), GTK_RESPONSE_ACCEPT,
1569 g_signal_connect (self->priv->incoming_call_dialog, "response",
1570 G_CALLBACK (empathy_call_window_incoming_call_response_cb), self);
1571 gtk_widget_show (self->priv->incoming_call_dialog);
1575 empathy_call_window_cdo_invalidated_cb (TpProxy *channel,
1579 EmpathyCallWindow *self)
1581 tp_clear_object (&self->priv->pending_cdo);
1582 tp_clear_object (&self->priv->pending_channel);
1583 tp_clear_object (&self->priv->pending_context);
1585 /* We don't know if the incoming call has been accepted or not, so we
1586 * assume it hasn't and if it has, we'll set the proper status when
1587 * we get the new handler. */
1588 empathy_call_window_status_message (self, _("Disconnected"));
1589 self->priv->call_state = DISCONNECTED;
1591 gtk_widget_destroy (self->priv->incoming_call_dialog);
1592 self->priv->incoming_call_dialog = NULL;
1596 empathy_call_window_start_ringing (EmpathyCallWindow *self,
1597 TpyCallChannel *channel,
1598 TpChannelDispatchOperation *dispatch_operation,
1599 TpAddDispatchOperationContext *context)
1601 g_assert (self->priv->pending_channel == NULL);
1602 g_assert (self->priv->pending_context == NULL);
1603 g_assert (self->priv->pending_cdo == NULL);
1605 /* Start ringing and delay until the user answers or hangs. */
1606 self->priv->pending_channel = g_object_ref (channel);
1607 self->priv->pending_context = g_object_ref (context);
1608 self->priv->pending_cdo = g_object_ref (dispatch_operation);
1610 g_signal_connect (self->priv->pending_cdo, "invalidated",
1611 G_CALLBACK (empathy_call_window_cdo_invalidated_cb), self);
1613 empathy_call_window_set_state_ringing (self);
1614 tp_add_dispatch_operation_context_accept (context);
1618 empathy_call_window_init (EmpathyCallWindow *self)
1620 EmpathyCallWindowPriv *priv;
1622 GtkWidget *top_vbox;
1624 ClutterConstraint *constraint;
1625 ClutterActor *remote_avatar;
1626 GtkStyleContext *context;
1630 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1631 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1633 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1635 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1636 gui = empathy_builder_get_file (filename,
1637 "call_window_vbox", &top_vbox,
1638 "errors_vbox", &priv->errors_vbox,
1639 "pane", &priv->pane,
1640 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1641 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1642 "status_label", &priv->status_label,
1643 "audiocall", &priv->audio_call_button,
1644 "videocall", &priv->video_call_button,
1645 "microphone", &priv->mic_button,
1646 "volume", &priv->volume_button,
1647 "camera", &priv->camera_button,
1648 "hangup", &priv->hangup_button,
1649 "dialpad", &priv->dialpad_button,
1650 "toolbar", &priv->toolbar,
1651 "bottom_toolbar", &priv->bottom_toolbar,
1652 "ui_manager", &priv->ui_manager,
1653 "menufullscreen", &priv->menu_fullscreen,
1654 "menupreviewswap", &priv->menu_swap_camera,
1655 "details_vbox", &priv->details_vbox,
1656 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1657 "acodec_encoding_label", &priv->acodec_encoding_label,
1658 "acodec_decoding_label", &priv->acodec_decoding_label,
1659 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1660 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1661 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1662 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1663 "video_local_candidate_label", &priv->video_local_candidate_label,
1664 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1665 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1666 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1667 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1671 empathy_builder_connect (gui, self,
1672 "hangup", "clicked", empathy_call_window_hangup_cb,
1673 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1674 "videocall", "clicked", empathy_call_window_video_call_cb,
1675 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1676 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1677 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1678 "menusettings", "activate", empathy_call_window_settings_cb,
1679 "menucontents", "activate", empathy_call_window_contents_cb,
1680 "menudebug", "activate", empathy_call_window_debug_cb,
1681 "menuabout", "activate", empathy_call_window_about_cb,
1682 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1683 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1684 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1685 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1688 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1690 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1692 g_object_bind_property (priv->camera_monitor, "available",
1693 priv->camera_button, "sensitive",
1694 G_BINDING_SYNC_CREATE);
1696 g_signal_connect (priv->camera_monitor, "added",
1697 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1698 g_signal_connect (priv->camera_monitor, "removed",
1699 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1701 priv->lock = g_mutex_new ();
1703 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1705 priv->content_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,
1706 CONTENT_HBOX_SPACING);
1707 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1708 CONTENT_HBOX_BORDER_WIDTH);
1709 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1712 /* avatar/video box */
1713 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1714 CLUTTER_BIN_ALIGNMENT_CENTER);
1716 priv->video_box = clutter_box_new (priv->video_layout);
1718 priv->video_container = gtk_clutter_embed_new ();
1720 gtk_widget_set_size_request (priv->video_container,
1721 EMPATHY_VIDEO_WIDGET_DEFAULT_WIDTH, EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT);
1723 /* Set the background color to that of the rest of the window */
1724 context = gtk_widget_get_style_context (priv->content_hbox);
1725 gtk_style_context_get_background_color (context,
1726 GTK_STATE_FLAG_NORMAL, &rgba);
1727 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1728 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1729 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1730 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1731 clutter_stage_set_color (
1732 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1733 GTK_CLUTTER_EMBED (priv->video_container))),
1736 clutter_container_add (
1737 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1738 GTK_CLUTTER_EMBED (priv->video_container))),
1742 constraint = clutter_bind_constraint_new (
1743 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1744 CLUTTER_BIND_SIZE, 0);
1745 clutter_actor_add_constraint (priv->video_box, constraint);
1747 priv->remote_user_avatar_widget = gtk_image_new ();
1748 remote_avatar = gtk_clutter_actor_new_with_contents (
1749 priv->remote_user_avatar_widget);
1751 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1754 empathy_call_window_create_preview_rectangles (self);
1756 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1757 priv->video_container, TRUE, TRUE,
1758 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1760 create_pipeline (self);
1761 create_video_output_widget (self);
1762 create_audio_input (self);
1763 create_video_input (self);
1765 priv->floating_toolbar = empathy_rounded_actor_new ();
1767 gtk_widget_reparent (priv->bottom_toolbar,
1768 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1770 constraint = clutter_bind_constraint_new (
1771 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1774 clutter_actor_add_constraint (priv->floating_toolbar, constraint);
1777 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1778 "notify::allocation",
1779 G_CALLBACK (empathy_call_window_stage_allocation_changed_cb),
1782 clutter_actor_set_size (priv->floating_toolbar,
1783 FLOATING_TOOLBAR_WIDTH, FLOATING_TOOLBAR_HEIGHT);
1784 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1786 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1787 priv->floating_toolbar,
1788 CLUTTER_BIN_ALIGNMENT_CENTER,
1789 CLUTTER_BIN_ALIGNMENT_END);
1791 clutter_actor_raise_top (priv->floating_toolbar);
1793 /* Transitions for the floating toolbar */
1794 priv->transitions = clutter_state_new ();
1796 /* all transitions last for 2s */
1797 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1799 /* transition from any state to "fade-out" state */
1800 clutter_state_set (priv->transitions, NULL, "fade-out",
1801 priv->floating_toolbar,
1802 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1805 /* transition from any state to "fade-in" state */
1806 clutter_state_set (priv->transitions, NULL, "fade-in",
1807 priv->floating_toolbar,
1808 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1811 /* put the actor into the "fade-in" state with no animation */
1812 clutter_state_warp_to_state (priv->transitions, "fade-in");
1814 /* The call will be started as soon the pipeline is playing */
1815 priv->start_call_when_playing = TRUE;
1817 priv->dtmf_panel = empathy_dialpad_widget_new ();
1818 g_signal_connect (priv->dtmf_panel, "start-tone",
1819 G_CALLBACK (dtmf_start_tone_cb), self);
1821 priv->tones = g_string_new ("");
1823 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1826 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1829 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1831 gtk_widget_show_all (top_vbox);
1833 gtk_widget_hide (priv->dtmf_panel);
1834 gtk_widget_hide (priv->details_vbox);
1836 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1838 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1839 priv->video_container);
1841 /* We hide the bottom toolbar after 3s of inactivity and show it
1842 * again on mouse movement */
1843 priv->inactivity_src = g_timeout_add_seconds (3,
1844 empathy_call_window_toolbar_timeout, self);
1846 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1847 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1849 g_signal_connect (G_OBJECT (self), "realize",
1850 G_CALLBACK (empathy_call_window_realized_cb), self);
1852 g_signal_connect (G_OBJECT (self), "delete-event",
1853 G_CALLBACK (empathy_call_window_delete_cb), self);
1855 g_signal_connect (G_OBJECT (self), "window-state-event",
1856 G_CALLBACK (empathy_call_window_state_event_cb), self);
1858 g_signal_connect (G_OBJECT (self), "key-press-event",
1859 G_CALLBACK (empathy_call_window_key_press_cb), self);
1861 g_signal_connect (self, "motion-notify-event",
1862 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1864 priv->timer = g_timer_new ();
1866 g_object_ref (priv->ui_manager);
1867 g_object_unref (gui);
1869 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1870 priv->mic_menu = empathy_mic_menu_new (self);
1871 priv->camera_menu = empathy_camera_menu_new (self);
1873 empathy_call_window_show_hangup_button (self, TRUE);
1875 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1876 /* These signals are used to track the window position and save it
1877 * when the window is destroyed. We need to do this as we don't want
1878 * the window geometry to be saved with the dialpad taken into account. */
1879 g_signal_connect (self, "destroy",
1880 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1881 g_signal_connect (self, "configure-event",
1882 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1883 g_signal_connect (self, "window-state-event",
1884 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1886 /* Don't display labels in both toolbars */
1887 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1890 /* Instead of specifying a width and a height, we specify only one size. That's
1891 because we want a square avatar icon. */
1893 init_contact_avatar_with_size (EmpathyContact *contact,
1894 GtkWidget *image_widget,
1897 GdkPixbuf *pixbuf_avatar = NULL;
1899 if (contact != NULL)
1901 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1905 if (pixbuf_avatar == NULL)
1907 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1908 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1911 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1913 if (pixbuf_avatar != NULL)
1914 g_object_unref (pixbuf_avatar);
1918 set_window_title (EmpathyCallWindow *self)
1920 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1923 if (priv->contact != NULL)
1925 /* translators: Call is a noun and %s is the contact name. This string
1926 * is used in the window title */
1927 tmp = g_strdup_printf (_("Call with %s"),
1928 empathy_contact_get_alias (priv->contact));
1929 gtk_window_set_title (GTK_WINDOW (self), tmp);
1934 g_warning ("Unknown remote contact!");
1939 set_remote_user_name (EmpathyCallWindow *self,
1940 EmpathyContact *contact)
1942 const gchar *alias = empathy_contact_get_alias (contact);
1943 const gchar *status = empathy_contact_get_status (contact);
1946 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1947 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1953 contact_name_changed_cb (EmpathyContact *contact,
1955 EmpathyCallWindow *self)
1957 set_window_title (self);
1958 set_remote_user_name (self, contact);
1962 contact_presence_changed_cb (EmpathyContact *contact,
1964 EmpathyCallWindow *self)
1966 set_remote_user_name (self, contact);
1970 contact_avatar_changed_cb (EmpathyContact *contact,
1972 EmpathyCallWindow *self)
1975 GtkAllocation allocation;
1976 GtkWidget *avatar_widget;
1978 avatar_widget = self->priv->remote_user_avatar_widget;
1980 gtk_widget_get_allocation (avatar_widget, &allocation);
1981 size = allocation.height;
1985 /* the widget is not allocated yet, set a default size */
1986 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1987 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1990 init_contact_avatar_with_size (contact, avatar_widget, size);
1992 avatar_widget = self->priv->remote_user_avatar_toolbar;
1994 gtk_widget_get_allocation (avatar_widget, &allocation);
1995 size = allocation.height;
1999 /* the widget is not allocated yet, set a default size */
2000 size = SMALL_TOOLBAR_SIZE;
2003 init_contact_avatar_with_size (contact, avatar_widget, size);
2007 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
2008 EmpathyCallHandler *handler)
2010 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2012 tp_g_signal_connect_object (priv->contact, "notify::name",
2013 G_CALLBACK (contact_name_changed_cb), self, 0);
2014 tp_g_signal_connect_object (priv->contact, "notify::avatar",
2015 G_CALLBACK (contact_avatar_changed_cb), self, 0);
2016 tp_g_signal_connect_object (priv->contact, "notify::presence",
2017 G_CALLBACK (contact_presence_changed_cb), self, 0);
2019 set_window_title (self);
2020 set_remote_user_name (self, priv->contact);
2022 init_contact_avatar_with_size (priv->contact,
2023 priv->remote_user_avatar_widget,
2024 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
2025 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
2027 init_contact_avatar_with_size (priv->contact,
2028 priv->remote_user_avatar_toolbar,
2029 SMALL_TOOLBAR_SIZE);
2031 /* The remote avatar is shown by default and will be hidden when we receive
2032 video from the remote side. */
2033 clutter_actor_hide (priv->video_output);
2034 gtk_widget_show (priv->remote_user_avatar_widget);
2038 update_send_codec (EmpathyCallWindow *self,
2041 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2048 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
2049 widget = priv->acodec_encoding_label;
2053 codec = empathy_call_handler_get_send_video_codec (priv->handler);
2054 widget = priv->vcodec_encoding_label;
2060 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
2061 gtk_label_set_text (GTK_LABEL (widget), tmp);
2066 send_audio_codec_notify_cb (GObject *object,
2070 EmpathyCallWindow *self = user_data;
2072 update_send_codec (self, TRUE);
2076 send_video_codec_notify_cb (GObject *object,
2080 EmpathyCallWindow *self = user_data;
2082 update_send_codec (self, FALSE);
2086 update_recv_codec (EmpathyCallWindow *self,
2089 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2092 GString *str = NULL;
2096 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
2097 widget = priv->acodec_decoding_label;
2101 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
2102 widget = priv->vcodec_decoding_label;
2108 for (l = codecs; l != NULL; l = g_list_next (l))
2110 FsCodec *codec = l->data;
2113 str = g_string_new (NULL);
2115 g_string_append (str, ", ");
2117 g_string_append_printf (str, "%s/%u", codec->encoding_name,
2121 gtk_label_set_text (GTK_LABEL (widget), str->str);
2122 g_string_free (str, TRUE);
2126 recv_audio_codecs_notify_cb (GObject *object,
2130 EmpathyCallWindow *self = user_data;
2132 update_recv_codec (self, TRUE);
2136 recv_video_codecs_notify_cb (GObject *object,
2140 EmpathyCallWindow *self = user_data;
2142 update_recv_codec (self, FALSE);
2145 static const gchar *
2146 candidate_type_to_str (FsCandidate *candidate)
2148 switch (candidate->type)
2150 case FS_CANDIDATE_TYPE_HOST:
2152 case FS_CANDIDATE_TYPE_SRFLX:
2153 return "server reflexive";
2154 case FS_CANDIDATE_TYPE_PRFLX:
2155 return "peer reflexive";
2156 case FS_CANDIDATE_TYPE_RELAY:
2158 case FS_CANDIDATE_TYPE_MULTICAST:
2165 static const gchar *
2166 candidate_type_to_desc (FsCandidate *candidate)
2168 switch (candidate->type)
2170 case FS_CANDIDATE_TYPE_HOST:
2171 return _("The IP address as seen by the machine");
2172 case FS_CANDIDATE_TYPE_SRFLX:
2173 return _("The IP address as seen by a server on the Internet");
2174 case FS_CANDIDATE_TYPE_PRFLX:
2175 return _("The IP address of the peer as seen by the other side");
2176 case FS_CANDIDATE_TYPE_RELAY:
2177 return _("The IP address of a relay server");
2178 case FS_CANDIDATE_TYPE_MULTICAST:
2179 return _("The IP address of the multicast group");
2186 update_candidat_widget (EmpathyCallWindow *self,
2189 FsCandidate *candidate)
2193 g_assert (candidate != NULL);
2194 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
2195 candidate->port, candidate_type_to_str (candidate));
2197 gtk_label_set_text (GTK_LABEL (label), str);
2198 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
2204 candidates_changed_cb (GObject *object,
2206 EmpathyCallWindow *self)
2208 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2209 FsCandidate *candidate = NULL;
2211 if (type == FS_MEDIA_TYPE_VIDEO)
2213 /* Update remote candidate */
2214 candidate = empathy_call_handler_get_video_remote_candidate (
2217 update_candidat_widget (self, priv->video_remote_candidate_label,
2218 priv->video_remote_candidate_info_img, candidate);
2220 /* Update local candidate */
2221 candidate = empathy_call_handler_get_video_local_candidate (
2224 update_candidat_widget (self, priv->video_local_candidate_label,
2225 priv->video_local_candidate_info_img, candidate);
2229 /* Update remote candidate */
2230 candidate = empathy_call_handler_get_audio_remote_candidate (
2233 update_candidat_widget (self, priv->audio_remote_candidate_label,
2234 priv->audio_remote_candidate_info_img, candidate);
2236 /* Update local candidate */
2237 candidate = empathy_call_handler_get_audio_local_candidate (
2240 update_candidat_widget (self, priv->audio_local_candidate_label,
2241 priv->audio_local_candidate_info_img, candidate);
2246 empathy_call_window_constructed (GObject *object)
2248 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2249 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2250 TpyCallChannel *call;
2253 g_assert (priv->handler != NULL);
2255 g_object_get (priv->handler, "call-channel", &call, NULL);
2256 state = tpy_call_channel_get_state (call, NULL, NULL);
2257 priv->outgoing = (state == TPY_CALL_STATE_PENDING_INITIATOR);
2258 tp_clear_object (&call);
2260 g_object_get (priv->handler, "target-contact", &priv->contact, NULL);
2261 g_assert (priv->contact != NULL);
2263 if (!empathy_contact_can_voip_video (priv->contact))
2265 gtk_widget_set_sensitive (priv->video_call_button, FALSE);
2266 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2269 empathy_call_window_setup_avatars (self, priv->handler);
2270 empathy_call_window_set_state_connecting (self);
2272 if (!empathy_call_handler_has_initial_video (priv->handler))
2274 gtk_toggle_tool_button_set_active (
2275 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2277 /* If call has InitialVideo, the preview will be started once the call has
2278 * been started (start_call()). */
2280 update_send_codec (self, TRUE);
2281 update_send_codec (self, FALSE);
2282 update_recv_codec (self, TRUE);
2283 update_recv_codec (self, FALSE);
2285 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2286 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2287 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2288 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2289 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2290 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2291 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2292 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2294 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2295 G_CALLBACK (candidates_changed_cb), self, 0);
2298 static void empathy_call_window_dispose (GObject *object);
2299 static void empathy_call_window_finalize (GObject *object);
2302 empathy_call_window_set_property (GObject *object,
2303 guint property_id, const GValue *value, GParamSpec *pspec)
2305 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2307 switch (property_id)
2309 case PROP_CALL_HANDLER:
2310 priv->handler = g_value_dup_object (value);
2313 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2318 empathy_call_window_get_property (GObject *object,
2319 guint property_id, GValue *value, GParamSpec *pspec)
2321 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2323 switch (property_id)
2325 case PROP_CALL_HANDLER:
2326 g_value_set_object (value, priv->handler);
2329 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2334 empathy_call_window_class_init (
2335 EmpathyCallWindowClass *empathy_call_window_class)
2337 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2338 GParamSpec *param_spec;
2340 g_type_class_add_private (empathy_call_window_class,
2341 sizeof (EmpathyCallWindowPriv));
2343 object_class->constructed = empathy_call_window_constructed;
2344 object_class->set_property = empathy_call_window_set_property;
2345 object_class->get_property = empathy_call_window_get_property;
2347 object_class->dispose = empathy_call_window_dispose;
2348 object_class->finalize = empathy_call_window_finalize;
2350 param_spec = g_param_spec_object ("handler",
2351 "handler", "The call handler",
2352 EMPATHY_TYPE_CALL_HANDLER,
2353 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2354 g_object_class_install_property (object_class,
2355 PROP_CALL_HANDLER, param_spec);
2359 empathy_call_window_dispose (GObject *object)
2361 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2362 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2364 if (priv->dispose_has_run)
2367 priv->dispose_has_run = TRUE;
2369 if (priv->handler != NULL)
2371 empathy_call_handler_stop_call (priv->handler);
2372 tp_clear_object (&priv->handler);
2375 if (priv->bus_message_source_id != 0)
2377 g_source_remove (priv->bus_message_source_id);
2378 priv->bus_message_source_id = 0;
2381 if (priv->got_video_src > 0)
2383 g_source_remove (priv->got_video_src);
2384 priv->got_video_src = 0;
2387 if (priv->inactivity_src > 0)
2389 g_source_remove (priv->inactivity_src);
2390 priv->inactivity_src = 0;
2393 tp_clear_object (&priv->pipeline);
2394 tp_clear_object (&priv->video_input);
2395 tp_clear_object (&priv->audio_input);
2396 tp_clear_object (&priv->video_tee);
2397 tp_clear_object (&priv->ui_manager);
2398 tp_clear_object (&priv->fullscreen);
2399 tp_clear_object (&priv->camera_monitor);
2400 tp_clear_object (&priv->settings);
2401 tp_clear_object (&priv->sound_mgr);
2402 tp_clear_object (&priv->mic_menu);
2403 tp_clear_object (&priv->camera_menu);
2405 g_list_free_full (priv->notifiers, g_object_unref);
2407 if (priv->timer_id != 0)
2408 g_source_remove (priv->timer_id);
2411 if (priv->contact != NULL)
2413 g_signal_handlers_disconnect_by_func (priv->contact,
2414 contact_name_changed_cb, self);
2415 priv->contact = NULL;
2418 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2422 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2424 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2426 if (priv->video_output_motion_handler_id != 0)
2428 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2429 priv->video_output_motion_handler_id);
2430 priv->video_output_motion_handler_id = 0;
2435 empathy_call_window_finalize (GObject *object)
2437 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2438 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2440 disconnect_video_output_motion_handler (self);
2442 /* free any data held directly by the object here */
2443 g_mutex_free (priv->lock);
2445 g_timer_destroy (priv->timer);
2447 g_string_free (priv->tones, TRUE);
2449 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2454 empathy_call_window_new (EmpathyCallHandler *handler)
2456 return EMPATHY_CALL_WINDOW (
2457 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2461 empathy_call_window_present (EmpathyCallWindow *self,
2462 EmpathyCallHandler *handler)
2464 g_return_if_fail (EMPATHY_IS_CALL_HANDLER (handler));
2466 tp_clear_object (&self->priv->handler);
2467 self->priv->handler = g_object_ref (handler);
2468 empathy_call_window_connect_handler (self);
2470 empathy_window_present (GTK_WINDOW (self));
2471 empathy_call_window_restart_call (self);
2475 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2476 GstElement *conference, gpointer user_data)
2478 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2479 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2480 FsElementAddedNotifier *notifier;
2483 DEBUG ("Conference added");
2485 /* Add notifier to set the various element properties as needed */
2486 notifier = fs_element_added_notifier_new ();
2487 keyfile = fs_utils_get_default_element_properties (conference);
2489 if (keyfile != NULL)
2490 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2492 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2494 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2496 gst_bin_add (GST_BIN (priv->pipeline), conference);
2497 gst_element_set_state (conference, GST_STATE_PLAYING);
2501 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2502 GstElement *conference, gpointer user_data)
2504 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2505 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2507 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2508 gst_element_set_state (conference, GST_STATE_NULL);
2512 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2514 GstStateChangeReturn state_change_return;
2515 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2517 if (priv->pipeline == NULL)
2520 if (priv->bus_message_source_id != 0)
2522 g_source_remove (priv->bus_message_source_id);
2523 priv->bus_message_source_id = 0;
2526 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2528 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2529 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2531 if (priv->pipeline != NULL)
2532 g_object_unref (priv->pipeline);
2533 priv->pipeline = NULL;
2535 if (priv->audio_output != NULL)
2536 g_object_unref (priv->audio_output);
2537 priv->audio_output = NULL;
2538 priv->audio_output_added = FALSE;
2540 if (priv->video_tee != NULL)
2541 g_object_unref (priv->video_tee);
2542 priv->video_tee = NULL;
2544 if (priv->video_preview != NULL)
2545 clutter_actor_destroy (priv->video_preview);
2546 priv->video_preview = NULL;
2548 /* If we destroy the preview while it's being dragged, we won't
2549 * get the ::drag-end signal, so manually destroy the clone */
2550 if (priv->drag_preview != NULL)
2552 clutter_actor_destroy (priv->drag_preview);
2553 empathy_call_window_show_preview_rectangles (self, FALSE);
2554 priv->drag_preview = NULL;
2557 priv->funnel = NULL;
2559 create_pipeline (self);
2560 /* Call will be started when user will hit the 'redial' button */
2561 priv->start_call_when_playing = FALSE;
2562 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2568 g_message ("Error: could not destroy pipeline. Closing call window");
2569 gtk_widget_destroy (GTK_WIDGET (self));
2576 reset_details_pane (EmpathyCallWindow *self)
2578 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2580 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2581 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2582 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2583 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2587 empathy_call_window_disconnected (EmpathyCallWindow *self,
2590 gboolean could_disconnect = FALSE;
2591 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2592 gboolean could_reset_pipeline;
2594 /* Leave full screen mode if needed */
2595 gtk_window_unfullscreen (GTK_WINDOW (self));
2597 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2598 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2600 priv->sending_tones = FALSE;
2601 g_string_set_size (priv->tones, 0);
2603 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2605 if (priv->call_state == CONNECTING)
2606 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2608 if (priv->call_state != REDIALING)
2609 priv->call_state = DISCONNECTED;
2611 /* Show the toolbar */
2612 clutter_state_set_state (priv->transitions, "fade-in");
2614 if (could_reset_pipeline)
2616 g_mutex_lock (priv->lock);
2618 g_timer_stop (priv->timer);
2620 if (priv->timer_id != 0)
2621 g_source_remove (priv->timer_id);
2624 g_mutex_unlock (priv->lock);
2627 /* We are about to destroy the window, no need to update it or create
2628 * a video preview */
2631 empathy_call_window_status_message (self, _("Disconnected"));
2633 empathy_call_window_show_hangup_button (self, FALSE);
2635 /* Unsensitive the camera and mic button */
2636 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2637 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2639 /* Be sure that the mic button is enabled */
2640 gtk_toggle_tool_button_set_active (
2641 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2643 if (priv->camera_state == CAMERA_STATE_ON)
2645 /* Restart the preview with the new pipeline. */
2646 display_video_preview (self, TRUE);
2649 /* destroy the video output; it will be recreated when we'll redial */
2650 disconnect_video_output_motion_handler (self);
2651 if (priv->video_output != NULL)
2652 clutter_actor_destroy (priv->video_output);
2653 priv->video_output = NULL;
2654 if (priv->got_video_src > 0)
2656 g_source_remove (priv->got_video_src);
2657 priv->got_video_src = 0;
2660 gtk_widget_show (priv->remote_user_avatar_widget);
2662 reset_details_pane (self);
2664 priv->sending_video = FALSE;
2665 priv->call_started = FALSE;
2667 could_disconnect = TRUE;
2669 /* TODO: display the self avatar of the preview (depends if the "Always
2670 * Show Video Preview" is enabled or not) */
2673 return could_disconnect;
2678 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2681 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2682 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2684 if (empathy_call_window_disconnected (self, TRUE) &&
2685 priv->call_state == REDIALING)
2686 empathy_call_window_restart_call (self);
2690 empathy_call_window_content_is_raw (TfContent *content)
2692 FsConference *conference;
2695 g_object_get (content, "fs-conference", &conference, NULL);
2696 g_assert (conference != NULL);
2698 /* FIXME: Ugly hack, update when moving a packetization property into
2700 israw = g_str_has_prefix (GST_OBJECT_NAME (conference), "fsrawconf");
2701 gst_object_unref (conference);
2707 empathy_call_window_content_removed_cb (EmpathyCallHandler *handler,
2709 EmpathyCallWindow *self)
2711 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2712 FsMediaType media_type;
2714 DEBUG ("removing content");
2716 g_object_get (content, "media-type", &media_type, NULL);
2719 * This assumes that there is only one video stream per channel...
2722 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2724 if (priv->funnel != NULL)
2728 output = priv->video_output_sink;
2730 gst_element_set_state (output, GST_STATE_NULL);
2731 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2733 gst_bin_remove (GST_BIN (priv->pipeline), output);
2734 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2735 priv->funnel = NULL;
2738 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2740 if (priv->audio_output != NULL)
2742 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2744 if (priv->audio_output_added)
2745 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2746 priv->audio_output = NULL;
2747 priv->audio_output_added = FALSE;
2752 g_assert_not_reached ();
2759 empathy_call_window_framerate_changed_cb (EmpathyCallHandler *handler,
2761 EmpathyCallWindow *self)
2763 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2765 DEBUG ("Framerate changed to %u", framerate);
2767 if (priv->video_input != NULL)
2768 empathy_video_src_set_framerate (priv->video_input, framerate);
2772 empathy_call_window_resolution_changed_cb (EmpathyCallHandler *handler,
2775 EmpathyCallWindow *self)
2777 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2779 DEBUG ("Resolution changed to %ux%u", width, height);
2781 if (priv->video_input != NULL)
2783 empathy_video_src_set_resolution (priv->video_input, width, height);
2787 /* Called with global lock held */
2789 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2791 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2795 if (priv->funnel == NULL)
2797 output = priv->video_output_sink;
2799 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2803 g_warning ("Could not create fsfunnel");
2807 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2809 gst_object_unref (priv->funnel);
2810 priv->funnel = NULL;
2811 g_warning ("Could not add funnel to pipeline");
2815 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2817 g_warning ("Could not add the video output widget to the pipeline");
2821 if (!gst_element_link (priv->funnel, output))
2823 g_warning ("Could not link output sink to funnel");
2824 goto error_output_added;
2827 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2829 g_warning ("Could not start video sink");
2830 goto error_output_added;
2833 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2835 g_warning ("Could not start funnel");
2836 goto error_output_added;
2840 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2843 g_warning ("Could not get request pad from funnel");
2850 gst_element_set_locked_state (priv->funnel, TRUE);
2851 gst_element_set_locked_state (output, TRUE);
2853 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2854 gst_element_set_state (output, GST_STATE_NULL);
2856 gst_bin_remove (GST_BIN (priv->pipeline), output);
2857 gst_element_set_locked_state (output, FALSE);
2861 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2862 priv->funnel = NULL;
2867 /* Called with global lock held */
2869 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self,
2872 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2874 GstPadTemplate *template;
2876 if (!priv->audio_output_added)
2878 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2880 g_warning ("Could not add audio sink to pipeline");
2881 g_object_unref (priv->audio_output);
2882 goto error_add_output;
2885 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2887 g_warning ("Could not start audio sink");
2892 template = gst_element_class_get_pad_template (
2893 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2895 pad = gst_element_request_pad (priv->audio_output,
2896 template, NULL, NULL);
2900 g_warning ("Could not get sink pad from sink");
2907 gst_element_set_locked_state (priv->audio_output, TRUE);
2908 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2909 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2910 priv->audio_output = NULL;
2918 empathy_call_window_update_timer (gpointer user_data)
2920 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2921 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2922 const gchar *status;
2926 time_ = g_timer_elapsed (priv->timer, NULL);
2928 if (priv->call_state == HELD)
2929 status = _("On hold");
2930 else if (!gtk_toggle_tool_button_get_active (
2931 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2934 status = _("Duration");
2936 /* Translators: 'status - minutes:seconds' the caller has been connected */
2937 str = g_strdup_printf (_("%s — %d:%02dm"),
2939 (int) time_ / 60, (int) time_ % 60);
2940 empathy_call_window_status_message (self, str);
2948 EMP_RESPONSE_BALANCE
2952 on_error_infobar_response_cb (GtkInfoBar *info_bar,
2956 switch (response_id)
2958 case GTK_RESPONSE_CLOSE:
2959 gtk_widget_destroy (GTK_WIDGET (info_bar));
2961 case EMP_RESPONSE_BALANCE:
2962 empathy_url_show (GTK_WIDGET (info_bar),
2963 g_object_get_data (G_OBJECT (info_bar), "uri"));
2969 display_error (EmpathyCallWindow *self,
2973 const gchar *details,
2974 const gchar *button_text,
2976 gint button_response)
2978 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2979 GtkWidget *info_bar;
2980 GtkWidget *content_area;
2987 /* Create info bar */
2988 info_bar = gtk_info_bar_new ();
2990 if (button_text != NULL)
2992 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
2993 button_text, button_response);
2994 g_object_set_data_full (G_OBJECT (info_bar),
2995 "uri", g_strdup (uri), g_free);
2998 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
2999 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
3001 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
3003 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
3005 /* hbox containing the image and the messages vbox */
3006 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
3007 gtk_container_add (GTK_CONTAINER (content_area), hbox);
3010 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
3011 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
3013 /* vbox containing the main message and the details expander */
3014 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
3015 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
3018 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
3020 label = gtk_label_new (NULL);
3021 gtk_label_set_markup (GTK_LABEL (label), txt);
3022 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
3023 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
3026 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
3029 if (details != NULL)
3031 GtkWidget *expander;
3033 expander = gtk_expander_new (_("Technical Details"));
3035 txt = g_strdup_printf ("<i>%s</i>", details);
3037 label = gtk_label_new (NULL);
3038 gtk_label_set_markup (GTK_LABEL (label), txt);
3039 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
3040 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
3043 gtk_container_add (GTK_CONTAINER (expander), label);
3044 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
3047 g_signal_connect (info_bar, "response",
3048 G_CALLBACK (on_error_infobar_response_cb), NULL);
3050 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
3051 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
3052 gtk_widget_show_all (info_bar);
3057 media_stream_error_to_txt (EmpathyCallWindow *self,
3058 TpyCallChannel *call,
3060 TpMediaStreamError error)
3062 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3063 const gchar *cm = NULL;
3069 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
3071 return g_strdup_printf (
3072 _("%s's software does not understand any of the audio formats "
3073 "supported by your computer"),
3074 empathy_contact_get_alias (priv->contact));
3076 return g_strdup_printf (
3077 _("%s's software does not understand any of the video formats "
3078 "supported by your computer"),
3079 empathy_contact_get_alias (priv->contact));
3081 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
3082 return g_strdup_printf (
3083 _("Can't establish a connection to %s. "
3084 "One of you might be on a network that does not allow "
3085 "direct connections."),
3086 empathy_contact_get_alias (priv->contact));
3088 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
3089 return g_strdup (_("There was a failure on the network"));
3091 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
3093 return g_strdup (_("The audio formats necessary for this call "
3094 "are not installed on your computer"));
3096 return g_strdup (_("The video formats necessary for this call "
3097 "are not installed on your computer"));
3099 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
3100 tp_connection_parse_object_path (
3101 tp_channel_borrow_connection (TP_CHANNEL (call)),
3104 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
3105 "product=Telepathy&component=%s", cm);
3107 result = g_strdup_printf (
3108 _("Something unexpected happened in a Telepathy component. "
3109 "Please <a href=\"%s\">report this bug</a> and attach "
3110 "logs gathered from the 'Debug' window in the Help menu."), url);
3116 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
3117 return g_strdup (_("There was a failure in the call engine"));
3119 case TP_MEDIA_STREAM_ERROR_EOS:
3120 return g_strdup (_("The end of the stream was reached"));
3122 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
3129 empathy_call_window_stream_error (EmpathyCallWindow *self,
3130 TpyCallChannel *call,
3139 desc = media_stream_error_to_txt (self, call, audio, code);
3142 /* No description, use the error message. That's not great as it's not
3143 * localized but it's better than nothing. */
3144 display_error (self, call, icon, title, msg, NULL);
3148 display_error (self, call, icon, title, desc, msg);
3154 empathy_call_window_audio_stream_error (TpyCallChannel *call,
3157 EmpathyCallWindow *self)
3159 empathy_call_window_stream_error (self, call, TRUE, code, msg,
3160 "gnome-stock-mic", _("Can't establish audio stream"));
3164 empathy_call_window_video_stream_error (TpyCallChannel *call,
3167 EmpathyCallWindow *self)
3169 empathy_call_window_stream_error (self, call, FALSE, code, msg,
3170 "camera-web", _("Can't establish video stream"));
3175 show_balance_error (EmpathyCallWindow *self)
3179 gchar *balance, *tmp;
3180 const gchar *uri, *currency;
3184 g_object_get (self->priv->handler,
3185 "call-channel", &call,
3188 conn = tp_channel_borrow_connection (call);
3189 g_object_unref (call);
3191 uri = tp_connection_get_balance_uri (conn);
3193 if (!tp_connection_get_balance (conn, &amount, &scale, ¤cy))
3195 /* unknown balance */
3196 balance = g_strdup ("(--)");
3200 char *money = empathy_format_currency (amount, scale, currency);
3202 balance = g_strdup_printf ("%s %s",
3207 tmp = g_strdup_printf (_("Your current balance is %s."), balance),
3209 display_error (self,
3211 _("Sorry, you don’t have enough credit for that call."),
3215 EMP_RESPONSE_BALANCE);
3222 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
3225 EmpathyCallWindow *self)
3227 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3228 TpyCallChannel *call;
3229 gboolean can_send_video;
3231 if (state == TPY_CALL_STATE_ENDED &&
3232 !tp_strdiff (reason, TP_ERROR_STR_INSUFFICIENT_BALANCE))
3234 show_balance_error (self);
3238 if (state != TPY_CALL_STATE_ACCEPTED)
3241 if (priv->call_state == CONNECTED)
3244 g_timer_start (priv->timer);
3245 priv->call_state = CONNECTED;
3247 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3249 can_send_video = priv->video_input != NULL &&
3250 empathy_contact_can_voip_video (priv->contact) &&
3251 empathy_camera_monitor_get_available (priv->camera_monitor);
3253 g_object_get (priv->handler, "call-channel", &call, NULL);
3255 if (tpy_call_channel_has_dtmf (call))
3256 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
3258 if (priv->video_input == NULL)
3259 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
3261 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
3263 empathy_call_window_show_hangup_button (self, TRUE);
3265 gtk_widget_set_sensitive (priv->mic_button, TRUE);
3267 clutter_actor_hide (priv->video_output);
3268 gtk_widget_show (priv->remote_user_avatar_widget);
3270 g_object_unref (call);
3272 g_mutex_lock (priv->lock);
3274 priv->timer_id = g_timeout_add_seconds (1,
3275 empathy_call_window_update_timer, self);
3277 g_mutex_unlock (priv->lock);
3279 empathy_call_window_update_timer (self);
3281 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
3285 empathy_call_window_show_video_output_cb (gpointer user_data)
3287 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3289 if (self->priv->video_output != NULL)
3291 gtk_widget_hide (self->priv->remote_user_avatar_widget);
3292 clutter_actor_show (self->priv->video_output);
3293 empathy_call_window_raise_actors (self);
3300 empathy_call_window_check_video_cb (gpointer data)
3302 EmpathyCallWindow *self = data;
3304 if (self->priv->got_video)
3306 self->priv->got_video = FALSE;
3310 /* No video in the last N seconds, display the remote avatar */
3311 empathy_call_window_show_video_output (self, FALSE);
3316 /* Called from the streaming thread */
3318 empathy_call_window_video_probe_cb (GstPad *pad,
3319 GstMiniObject *mini_obj,
3320 EmpathyCallWindow *self)
3323 if (GST_IS_EVENT (mini_obj))
3326 if (G_UNLIKELY (!self->priv->got_video))
3328 /* show the remote video */
3329 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3330 empathy_call_window_show_video_output_cb,
3331 g_object_ref (self), g_object_unref);
3333 self->priv->got_video = TRUE;
3339 /* Called from the streaming thread */
3341 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
3342 TfContent *content, GstPad *src, gpointer user_data)
3344 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3345 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3346 gboolean retval = FALSE;
3351 g_mutex_lock (priv->lock);
3353 g_object_get (content, "media-type", &media_type, NULL);
3357 case TP_MEDIA_STREAM_TYPE_AUDIO:
3358 pad = empathy_call_window_get_audio_sink_pad (self, content);
3360 case TP_MEDIA_STREAM_TYPE_VIDEO:
3361 g_idle_add (empathy_call_window_show_video_output_cb, self);
3362 pad = empathy_call_window_get_video_sink_pad (self);
3364 gst_pad_add_data_probe (src,
3365 G_CALLBACK (empathy_call_window_video_probe_cb), self);
3366 if (priv->got_video_src > 0)
3367 g_source_remove (priv->got_video_src);
3368 priv->got_video_src = g_timeout_add_seconds (1,
3369 empathy_call_window_check_video_cb, self);
3372 g_assert_not_reached ();
3378 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
3379 g_warning ("Could not link %s sink pad",
3380 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
3384 gst_object_unref (pad);
3388 /* If no sink could be linked, try to add fakesink to prevent the whole call
3393 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
3395 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
3397 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
3398 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
3399 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
3401 gst_element_set_locked_state (fakesink, TRUE);
3402 gst_element_set_state (fakesink, GST_STATE_NULL);
3403 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
3407 DEBUG ("Could not link real sink, linked fakesink instead");
3409 gst_object_unref (sinkpad);
3413 gst_object_unref (fakesink);
3418 g_mutex_unlock (priv->lock);
3424 empathy_call_window_prepare_audio_output (EmpathyCallWindow *self,
3427 EmpathyCallWindowPriv *priv = self->priv;
3429 g_assert (priv->audio_output_added == FALSE);
3430 g_assert (priv->audio_output == FALSE);
3432 priv->audio_output = empathy_audio_sink_new ();
3433 g_object_ref_sink (priv->audio_output);
3435 /* volume button to output volume linking */
3436 g_object_bind_property (priv->audio_output, "volume",
3437 priv->volume_button, "value",
3438 G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
3440 g_object_bind_property_full (content, "requested-output-volume",
3441 priv->audio_output, "volume",
3443 audio_control_volume_to_element,
3444 element_volume_to_audio_control,
3447 /* Link volumes together, sync the current audio input volume property
3448 * back to farstream first */
3449 g_object_bind_property_full (priv->audio_output, "volume",
3450 content, "reported-output-volume",
3451 G_BINDING_SYNC_CREATE,
3452 element_volume_to_audio_control,
3453 audio_control_volume_to_element,
3456 /* For raw audio conferences assume that the producer of the raw data
3457 * has already processed it, so turn off any echo cancellation and any
3458 * other audio improvements that come with it */
3459 empathy_audio_sink_set_echo_cancel (
3460 EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3461 !empathy_call_window_content_is_raw (content));
3466 empathy_call_window_content_added_cb (EmpathyCallHandler *handler,
3467 TfContent *content, gpointer user_data)
3469 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3470 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3472 FsMediaType media_type;
3473 gboolean retval = FALSE;
3475 g_object_get (content, "media-type", &media_type, "sink-pad", &sink, NULL);
3476 g_assert (sink != NULL);
3480 case FS_MEDIA_TYPE_AUDIO:
3482 /* For raw audio conferences assume that the receiver of the raw data
3483 * wants it unprocessed, so turn off any echo cancellation and any
3484 * other audio improvements that come with it */
3485 empathy_audio_src_set_echo_cancel (
3486 EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3487 !empathy_call_window_content_is_raw (content));
3489 /* Link volumes together, sync the current audio input volume property
3490 * back to farstream first */
3491 g_object_bind_property_full (content, "requested-input-volume",
3492 priv->audio_input, "volume",
3494 audio_control_volume_to_element,
3495 element_volume_to_audio_control,
3498 g_object_bind_property_full (priv->audio_input, "volume",
3499 content, "reported-input-volume",
3500 G_BINDING_SYNC_CREATE,
3501 element_volume_to_audio_control,
3502 audio_control_volume_to_element,
3505 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
3507 g_warning ("Could not add audio source to pipeline");
3511 pad = gst_element_get_static_pad (priv->audio_input, "src");
3514 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3515 g_warning ("Could not get source pad from audio source");
3519 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3521 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3522 g_warning ("Could not link audio source to farsight");
3526 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3528 g_warning ("Could not start audio source");
3529 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3530 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3534 /* Prepare our audio output, not added yet though */
3535 empathy_call_window_prepare_audio_output (self, content);
3539 case FS_MEDIA_TYPE_VIDEO:
3540 if (priv->video_tee != NULL)
3542 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3543 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3545 g_warning ("Could not link video source input pipeline");
3548 gst_object_unref (pad);
3554 g_assert_not_reached ();
3557 gst_object_unref (sink);
3562 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3564 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3565 GstElement *preview;
3567 disable_camera (self);
3569 DEBUG ("remove video input");
3570 preview = priv->video_preview_sink;
3572 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3573 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3574 gst_element_set_state (preview, GST_STATE_NULL);
3576 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3579 g_object_unref (priv->video_input);
3580 priv->video_input = NULL;
3581 g_object_unref (priv->video_tee);
3582 priv->video_tee = NULL;
3583 clutter_actor_destroy (priv->video_preview);
3584 priv->video_preview = NULL;
3586 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3590 start_call (EmpathyCallWindow *self)
3592 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3594 priv->call_started = TRUE;
3595 empathy_call_handler_start_call (priv->handler,
3596 gtk_get_current_event_time ());
3598 if (empathy_call_handler_has_initial_video (priv->handler))
3600 TpyCallChannel *call;
3603 g_object_get (priv->handler, "call-channel", &call, NULL);
3604 /* If the call channel isn't set yet we're requesting it, if we're
3605 * requesting it with initial video it should be PENDING_SEND when we get
3608 s = TPY_SENDING_STATE_PENDING_SEND;
3610 s = tpy_call_channel_get_video_state (call);
3612 if (s == TPY_SENDING_STATE_PENDING_SEND ||
3613 s == TPY_SENDING_STATE_SENDING)
3615 /* Enable 'send video' buttons and display the preview */
3616 gtk_toggle_tool_button_set_active (
3617 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
3621 gtk_toggle_tool_button_set_active (
3622 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
3624 if (priv->video_preview == NULL)
3626 create_video_preview (self);
3627 add_video_preview_to_pipeline (self);
3632 g_object_unref (call);
3637 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3640 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3641 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3642 GstState newstate, pending;
3644 empathy_call_handler_bus_message (priv->handler, bus, message);
3646 switch (GST_MESSAGE_TYPE (message))
3648 case GST_MESSAGE_STATE_CHANGED:
3649 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3651 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3653 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3654 !priv->call_started)
3656 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3657 if (newstate == GST_STATE_PAUSED)
3659 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3660 priv->pipeline_playing = TRUE;
3662 if (priv->start_call_when_playing)
3666 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_preview_sink))
3668 gst_message_parse_state_changed (message, NULL, &newstate,
3671 if (newstate == GST_STATE_PLAYING &&
3672 pending == GST_STATE_VOID_PENDING)
3673 empathy_call_window_stop_camera_spinning (self);
3676 case GST_MESSAGE_ERROR:
3678 GError *error = NULL;
3679 GstElement *gst_error;
3682 gst_message_parse_error (message, &error, &debug);
3683 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3685 g_message ("Element error: %s -- %s\n", error->message, debug);
3687 if (g_str_has_prefix (gst_element_get_name (gst_error),
3688 VIDEO_INPUT_ERROR_PREFIX))
3690 /* Remove the video input and continue */
3691 if (priv->video_input != NULL)
3692 empathy_call_window_remove_video_input (self);
3693 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3697 empathy_call_window_disconnected (self, TRUE);
3699 g_error_free (error);
3702 case GST_MESSAGE_UNKNOWN:
3703 case GST_MESSAGE_EOS:
3704 case GST_MESSAGE_WARNING:
3705 case GST_MESSAGE_INFO:
3706 case GST_MESSAGE_TAG:
3707 case GST_MESSAGE_BUFFERING:
3708 case GST_MESSAGE_STATE_DIRTY:
3709 case GST_MESSAGE_STEP_DONE:
3710 case GST_MESSAGE_CLOCK_PROVIDE:
3711 case GST_MESSAGE_CLOCK_LOST:
3712 case GST_MESSAGE_NEW_CLOCK:
3713 case GST_MESSAGE_STRUCTURE_CHANGE:
3714 case GST_MESSAGE_STREAM_STATUS:
3715 case GST_MESSAGE_APPLICATION:
3716 case GST_MESSAGE_ELEMENT:
3717 case GST_MESSAGE_SEGMENT_START:
3718 case GST_MESSAGE_SEGMENT_DONE:
3719 case GST_MESSAGE_DURATION:
3720 case GST_MESSAGE_ANY:
3729 empathy_call_window_members_changed_cb (TpyCallChannel *call,
3730 GHashTable *members,
3731 EmpathyCallWindow *self)
3733 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3734 GHashTableIter iter;
3735 gpointer key, value;
3736 gboolean held = FALSE;
3738 g_hash_table_iter_init (&iter, members);
3739 while (g_hash_table_iter_next (&iter, &key, &value))
3741 if (GPOINTER_TO_INT (value) & TPY_CALL_MEMBER_FLAG_HELD)
3743 /* This assumes this is a 1-1 call, otherwise one participant
3744 * putting the call on hold wouldn't mean the call is on hold
3752 priv->call_state = HELD;
3753 else if (priv->call_state == HELD)
3754 priv->call_state = CONNECTED;
3758 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3760 EmpathyCallWindow *self)
3762 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3763 TpyCallChannel *call;
3765 g_object_get (priv->handler, "call-channel", &call, NULL);
3770 tp_g_signal_connect_object (call, "audio-stream-error",
3771 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3772 tp_g_signal_connect_object (call, "video-stream-error",
3773 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3776 tp_g_signal_connect_object (call, "members-changed",
3777 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3779 tp_cli_channel_interface_dtmf_connect_to_stopped_tones (TP_CHANNEL (call),
3780 empathy_call_window_tones_stopped_cb, self, NULL,
3781 G_OBJECT (call), NULL);
3783 g_object_unref (call);
3787 empathy_call_window_connect_handler (EmpathyCallWindow *self)
3789 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3790 TpyCallChannel *call;
3792 g_signal_connect (priv->handler, "state-changed",
3793 G_CALLBACK (empathy_call_window_state_changed_cb), self);
3794 g_signal_connect (priv->handler, "conference-added",
3795 G_CALLBACK (empathy_call_window_conference_added_cb), self);
3796 g_signal_connect (priv->handler, "conference-removed",
3797 G_CALLBACK (empathy_call_window_conference_removed_cb), self);
3798 g_signal_connect (priv->handler, "closed",
3799 G_CALLBACK (empathy_call_window_channel_closed_cb), self);
3800 g_signal_connect (priv->handler, "src-pad-added",
3801 G_CALLBACK (empathy_call_window_src_added_cb), self);
3802 g_signal_connect (priv->handler, "content-added",
3803 G_CALLBACK (empathy_call_window_content_added_cb), self);
3804 g_signal_connect (priv->handler, "content-removed",
3805 G_CALLBACK (empathy_call_window_content_removed_cb), self);
3807 /* We connect to ::call-channel unconditionally since we'll
3808 * get new channels if we hangup and redial or if we reuse the
3810 g_signal_connect (priv->handler, "notify::call-channel",
3811 G_CALLBACK (call_handler_notify_call_cb), self);
3813 g_signal_connect (priv->handler, "framerate-changed",
3814 G_CALLBACK (empathy_call_window_framerate_changed_cb), self);
3815 g_signal_connect (priv->handler, "resolution-changed",
3816 G_CALLBACK (empathy_call_window_resolution_changed_cb), self);
3818 g_object_get (priv->handler, "call-channel", &call, NULL);
3821 /* We won't get notify::call-channel for this channel, so
3822 * directly call the callback. */
3823 call_handler_notify_call_cb (priv->handler, NULL, self);
3824 g_object_unref (call);
3829 empathy_call_window_realized_cb (GtkWidget *widget,
3830 EmpathyCallWindow *self)
3834 /* Make the hangup button twice as wide */
3835 width = gtk_widget_get_allocated_width (self->priv->hangup_button);
3836 gtk_widget_set_size_request (self->priv->hangup_button, width * 2, -1);
3838 empathy_call_window_connect_handler (self);
3840 gst_element_set_state (self->priv->pipeline, GST_STATE_PAUSED);
3844 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3845 EmpathyCallWindow *window)
3847 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3849 if (priv->pipeline != NULL)
3851 if (priv->bus_message_source_id != 0)
3853 g_source_remove (priv->bus_message_source_id);
3854 priv->bus_message_source_id = 0;
3857 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3860 if (priv->call_state == CONNECTING)
3861 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3867 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3870 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3872 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3877 gtk_widget_hide (priv->dtmf_panel);
3878 gtk_widget_hide (menu);
3879 gtk_widget_hide (priv->toolbar);
3883 if (priv->dialpad_was_visible_before_fs)
3884 gtk_widget_show (priv->dtmf_panel);
3886 gtk_widget_show (menu);
3887 gtk_widget_show (priv->toolbar);
3889 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3890 priv->original_height_before_fs);
3895 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3897 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3899 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
3900 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
3901 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3902 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3904 if (priv->video_output != NULL)
3907 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3908 priv->video_output, TRUE, TRUE,
3909 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3916 empathy_call_window_state_event_cb (GtkWidget *widget,
3917 GdkEventWindowState *event, EmpathyCallWindow *window)
3919 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3921 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3922 gboolean set_fullscreen = event->new_window_state &
3923 GDK_WINDOW_STATE_FULLSCREEN;
3927 gboolean dialpad_was_visible;
3928 GtkAllocation allocation;
3929 gint original_width, original_height;
3931 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3932 original_width = allocation.width;
3933 original_height = allocation.height;
3935 g_object_get (priv->dtmf_panel,
3936 "visible", &dialpad_was_visible,
3939 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3940 priv->original_width_before_fs = original_width;
3941 priv->original_height_before_fs = original_height;
3943 if (priv->video_output_motion_handler_id == 0 &&
3944 priv->video_output != NULL)
3946 priv->video_output_motion_handler_id = g_signal_connect (
3947 G_OBJECT (priv->video_container), "motion-notify-event",
3948 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3954 disconnect_video_output_motion_handler (window);
3957 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3959 show_controls (window, set_fullscreen);
3960 show_borders (window, set_fullscreen);
3961 gtk_action_set_stock_id (priv->menu_fullscreen,
3962 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3963 priv->is_fullscreen = set_fullscreen;
3970 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3973 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3974 int w, h, dialpad_width;
3975 GtkAllocation allocation;
3977 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3978 w = allocation.width;
3979 h = allocation.height;
3981 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3985 gtk_widget_show (priv->dtmf_panel);
3991 gtk_widget_hide (priv->dtmf_panel);
3995 gtk_window_resize (GTK_WINDOW (window), w, h);
3999 empathy_call_window_set_send_video (EmpathyCallWindow *window,
4002 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4003 TpyCallChannel *call;
4005 priv->sending_video = (state == CAMERA_STATE_ON);
4007 if (state == CAMERA_STATE_ON)
4009 /* When we start sending video, we want to show the video preview by
4011 display_video_preview (window, TRUE);
4015 display_video_preview (window, FALSE);
4018 if (priv->call_state != CONNECTED)
4021 g_object_get (priv->handler, "call-channel", &call, NULL);
4022 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
4023 tpy_call_channel_send_video (call, priv->sending_video);
4024 g_object_unref (call);
4028 empathy_call_window_hangup_cb (gpointer object,
4029 EmpathyCallWindow *self)
4031 empathy_call_handler_stop_call (self->priv->handler);
4033 empathy_call_window_disconnected (self, TRUE);
4037 empathy_call_window_restart_call (EmpathyCallWindow *window)
4039 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4041 /* Remove error info bars */
4042 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
4043 (GtkCallback) gtk_widget_destroy, NULL);
4045 create_video_output_widget (window);
4046 priv->outgoing = TRUE;
4047 empathy_call_window_set_state_connecting (window);
4049 if (priv->pipeline_playing)
4050 start_call (window);
4052 /* call will be started when the pipeline is ready */
4053 priv->start_call_when_playing = TRUE;
4055 empathy_call_window_setup_avatars (window, priv->handler);
4057 empathy_call_window_show_hangup_button (window, TRUE);
4061 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
4062 EmpathyCallWindow *window)
4066 active = gtk_toggle_tool_button_get_active (button);
4068 empathy_call_window_show_dialpad (window, active);
4072 empathy_call_window_fullscreen_cb (gpointer object,
4073 EmpathyCallWindow *window)
4075 empathy_call_window_fullscreen_toggle (window);
4079 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
4081 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4083 if (priv->is_fullscreen)
4084 gtk_window_unfullscreen (GTK_WINDOW (window));
4086 gtk_window_fullscreen (GTK_WINDOW (window));
4090 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
4091 GdkEventButton *event, EmpathyCallWindow *window)
4093 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
4095 empathy_call_window_video_menu_popup (window, event->button);
4103 empathy_call_window_key_press_cb (GtkWidget *video_output,
4104 GdkEventKey *event, EmpathyCallWindow *window)
4106 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4108 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
4110 /* Since we are in fullscreen mode, toggling will bring us back to
4112 empathy_call_window_fullscreen_toggle (window);
4120 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
4121 GdkEventMotion *event, EmpathyCallWindow *window)
4123 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4125 if (priv->is_fullscreen)
4127 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
4129 /* Show the bottom toolbar */
4130 empathy_call_window_motion_notify_cb (NULL, NULL, window);
4137 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
4141 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4143 menu = gtk_ui_manager_get_widget (priv->ui_manager,
4145 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
4146 button, gtk_get_current_event_time ());
4147 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
4151 empathy_call_window_status_message (EmpathyCallWindow *self,
4154 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
4158 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
4160 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4162 return priv->ui_manager;
4165 EmpathyGstAudioSrc *
4166 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
4168 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4170 return (EmpathyGstAudioSrc *) priv->audio_input;
4173 EmpathyGstVideoSrc *
4174 empathy_call_window_get_video_src (EmpathyCallWindow *self)
4176 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);
4180 empathy_call_window_change_webcam (EmpathyCallWindow *self,
4181 const gchar *device)
4183 EmpathyGstVideoSrc *video;
4186 /* Restart the camera only if it's already running */
4187 running = (self->priv->video_preview != NULL);
4188 video = empathy_call_window_get_video_src (self);
4191 empathy_call_window_play_camera (self, FALSE);
4193 empathy_video_src_change_device (video, device);
4196 empathy_call_window_play_camera (self, TRUE);