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 <farstream/fs-element-added-notifier.h>
42 #include <farstream/fs-utils.h>
44 #include <libempathy/empathy-camera-monitor.h>
45 #include <libempathy/empathy-gsettings.h>
46 #include <libempathy/empathy-request-util.h>
47 #include <libempathy/empathy-utils.h>
49 #include <libempathy-gtk/empathy-avatar-image.h>
50 #include <libempathy-gtk/empathy-dialpad-widget.h>
51 #include <libempathy-gtk/empathy-ui-utils.h>
52 #include <libempathy-gtk/empathy-sound-manager.h>
53 #include <libempathy-gtk/empathy-geometry.h>
54 #include <libempathy-gtk/empathy-images.h>
55 #include <libempathy-gtk/empathy-call-utils.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-about-dialog.h"
64 #include "empathy-audio-src.h"
65 #include "empathy-audio-sink.h"
66 #include "empathy-video-src.h"
67 #include "empathy-mic-menu.h"
68 #include "empathy-preferences.h"
69 #include "empathy-rounded-actor.h"
70 #include "empathy-rounded-rectangle.h"
71 #include "empathy-rounded-texture.h"
72 #include "empathy-camera-menu.h"
74 #define CONTENT_HBOX_SPACING 3
75 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 0
76 #define OVERLAY_MARGIN 6
78 #define REMOTE_VIDEO_DEFAULT_WIDTH 320
79 #define REMOTE_VIDEO_DEFAULT_HEIGHT 240
81 #define SELF_VIDEO_SECTION_WIDTH 120
82 #define SELF_VIDEO_SECTION_HEIGHT 90
83 #define SELF_VIDEO_SECTION_MARGIN 2
84 #define SELF_VIDEO_SECTION_BORDER SELF_VIDEO_SECTION_MARGIN*2
86 /* The avatar's default width and height are set to the same value because we
87 want a square icon. */
88 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT REMOTE_VIDEO_DEFAULT_HEIGHT
89 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH REMOTE_VIDEO_DEFAULT_HEIGHT
91 #define SMALL_TOOLBAR_SIZE 36
93 /* If an video input error occurs, the error message will start with "v4l" */
94 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
96 /* The time interval in milliseconds between 2 outgoing rings */
97 #define MS_BETWEEN_RING 500
99 /* The roundedness of preview box and placeholders */
100 #define PREVIEW_ROUND_FACTOR 16
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_spinner_actor;
156 GtkWidget *preview_spinner_widget;
157 GtkWidget *video_container;
158 GtkWidget *remote_user_avatar_widget;
159 GtkWidget *remote_user_avatar_toolbar;
160 GtkWidget *remote_user_name_toolbar;
161 GtkWidget *remote_user_status_toolbar;
162 GtkWidget *status_label;
163 GtkWidget *hangup_button;
164 GtkWidget *audio_call_button;
165 GtkWidget *video_call_button;
166 GtkWidget *mic_button;
167 GtkWidget *volume_button;
168 GtkWidget *camera_button;
169 GtkWidget *dialpad_button;
171 GtkWidget *bottom_toolbar;
172 ClutterActor *floating_toolbar;
174 GtkAction *menu_fullscreen;
175 GtkAction *menu_swap_camera;
177 ClutterState *transitions;
179 /* The main box covering all the stage, contaning remote avatar/video */
180 ClutterActor *video_box;
181 ClutterLayoutManager *video_layout;
183 /* A bin layout manager containing a bin for previews
184 * and the floating toolbar */
185 ClutterActor *overlay_bin;
186 ClutterLayoutManager *overlay_layout;
188 /* Bin layout for the previews */
189 ClutterActor *preview_box;
190 ClutterLayoutManager *preview_layout;
192 /* Coordinates of the preview drag event's start. */
193 PreviewPosition preview_pos;
195 /* We keep a reference on the hbox which contains the main content so we can
196 easilly repack everything when toggling fullscreen */
197 GtkWidget *content_hbox;
199 /* These are used to accept or reject an incoming call when the status
201 GtkWidget *incoming_call_dialog;
202 TpCallChannel *pending_channel;
203 TpChannelDispatchOperation *pending_cdo;
204 TpAddDispatchOperationContext *pending_context;
206 gulong video_output_motion_handler_id;
207 guint bus_message_source_id;
209 GtkWidget *dtmf_panel;
212 GtkWidget *details_vbox;
213 GtkWidget *vcodec_encoding_label;
214 GtkWidget *acodec_encoding_label;
215 GtkWidget *vcodec_decoding_label;
216 GtkWidget *acodec_decoding_label;
218 GtkWidget *audio_remote_candidate_label;
219 GtkWidget *audio_local_candidate_label;
220 GtkWidget *video_remote_candidate_label;
221 GtkWidget *video_local_candidate_label;
222 GtkWidget *video_remote_candidate_info_img;
223 GtkWidget *video_local_candidate_info_img;
224 GtkWidget *audio_remote_candidate_info_img;
225 GtkWidget *audio_local_candidate_info_img;
227 GstElement *video_input;
228 GstElement *video_preview_sink;
229 GstElement *video_output_sink;
230 GstElement *audio_input;
231 GstElement *audio_output;
232 gboolean audio_output_added;
233 GstElement *pipeline;
234 GstElement *video_tee;
244 gboolean call_started;
245 gboolean sending_video;
246 CameraState camera_state;
248 EmpathyCallWindowFullscreen *fullscreen;
249 gboolean is_fullscreen;
254 guint inactivity_src;
256 /* Those fields represent the state of the window before it actually was in
258 gboolean dialpad_was_visible_before_fs;
259 gint original_width_before_fs;
260 gint original_height_before_fs;
262 gint x, y, w, h, dialpad_width;
265 /* TRUE if the call should be started when the pipeline is playing */
266 gboolean start_call_when_playing;
267 /* TRUE if we requested to set the pipeline in the playing state */
268 gboolean pipeline_playing;
270 EmpathySoundManager *sound_mgr;
273 EmpathyMicMenu *mic_menu;
274 EmpathyCameraMenu *camera_menu;
279 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
281 static void empathy_call_window_realized_cb (GtkWidget *widget,
282 EmpathyCallWindow *window);
284 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
285 GdkEvent *event, EmpathyCallWindow *window);
287 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
288 GdkEventWindowState *event, EmpathyCallWindow *window);
290 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
293 static void empathy_call_window_hangup_cb (gpointer object,
294 EmpathyCallWindow *window);
296 static void empathy_call_window_fullscreen_cb (gpointer object,
297 EmpathyCallWindow *window);
299 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
301 static gboolean empathy_call_window_video_button_press_cb (
302 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
304 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
305 GdkEventKey *event, EmpathyCallWindow *window);
307 static gboolean empathy_call_window_video_output_motion_notify (
308 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
310 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
313 static void empathy_call_window_connect_handler (EmpathyCallWindow *self);
315 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
316 EmpathyCallWindow *window);
318 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
320 static void empathy_call_window_status_message (EmpathyCallWindow *window,
323 static gboolean empathy_call_window_bus_message (GstBus *bus,
324 GstMessage *message, gpointer user_data);
326 static gboolean empathy_call_window_update_timer (gpointer user_data);
329 make_background_transparent (GtkClutterActor *actor)
331 GdkRGBA transparent = { 0., 0., 0., 0. };
334 widget = gtk_clutter_actor_get_widget (actor);
335 gtk_widget_override_background_color (widget, GTK_STATE_FLAG_NORMAL, &transparent);
339 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
342 gtk_widget_set_visible (self->priv->hangup_button, show);
343 gtk_widget_set_visible (self->priv->audio_call_button, !show);
344 gtk_widget_set_visible (self->priv->video_call_button, !show);
348 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
349 EmpathyCallWindow *self)
351 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
352 empathy_call_window_restart_call (self);
356 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
357 EmpathyCallWindow *self)
359 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
360 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
361 empathy_call_window_restart_call (self);
365 dtmf_start_tone_cb (EmpathyDialpadWidget *dialpad,
367 EmpathyCallWindow *self)
372 g_object_get (self->priv->handler, "call-channel", &call, NULL);
374 tones[0] = tp_dtmf_event_to_char (event);
376 tp_call_channel_send_tones_async (call, tones, NULL, NULL, NULL);
378 g_object_unref (call);
382 empathy_call_window_show_video_output (EmpathyCallWindow *self,
385 if (self->priv->video_output != NULL)
386 g_object_set (self->priv->video_output, "visible", show, NULL);
388 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
390 clutter_actor_raise_top (self->priv->overlay_bin);
394 create_video_output_widget (EmpathyCallWindow *self)
396 EmpathyCallWindowPriv *priv = GET_PRIV (self);
398 g_assert (priv->video_output == NULL);
399 g_assert (priv->pipeline != NULL);
401 priv->video_output = clutter_texture_new ();
403 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
406 priv->video_output_sink = gst_element_factory_make ("cluttersink", NULL);
407 if (priv->video_output_sink == NULL)
408 g_error ("Missing cluttersink");
410 g_object_set (priv->video_output_sink, "texture", priv->video_output, NULL);
412 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
415 gtk_widget_add_events (priv->video_container,
416 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
417 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
418 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
422 create_video_input (EmpathyCallWindow *self)
424 EmpathyCallWindowPriv *priv = GET_PRIV (self);
426 g_assert (priv->video_input == NULL);
427 priv->video_input = empathy_video_src_new ();
428 gst_object_ref_sink (priv->video_input);
432 audio_control_volume_to_element (GBinding *binding,
433 const GValue *source_value,
434 GValue *target_value,
437 /* AudioControl volume is 0-255, with -1 for unknown */
440 hv = g_value_get_int (source_value);
445 g_value_set_double (target_value, hv/255.0);
451 element_volume_to_audio_control (GBinding *binding,
452 const GValue *source_value,
453 GValue *target_value,
458 ev = g_value_get_double (source_value);
459 ev = CLAMP (ev, 0.0, 1.0);
461 g_value_set_int (target_value, ev * 255);
466 audio_input_mute_notify_cb (GObject *obj, GParamSpec *spec,
467 EmpathyCallWindow *self)
470 g_object_get (obj, "mute", &muted, NULL);
472 self->priv->muted = muted;
473 if (muted && self->priv->transitions)
474 clutter_state_set_state (self->priv->transitions, "fade-in");
476 empathy_call_window_update_timer (self);
480 create_audio_input (EmpathyCallWindow *self)
482 EmpathyCallWindowPriv *priv = GET_PRIV (self);
484 g_assert (priv->audio_input == NULL);
485 priv->audio_input = empathy_audio_src_new ();
486 gst_object_ref_sink (priv->audio_input);
488 g_signal_connect (priv->audio_input, "notify::mute",
489 G_CALLBACK (audio_input_mute_notify_cb), self);
491 g_object_bind_property (priv->mic_button, "active",
492 priv->audio_input, "mute",
493 G_BINDING_BIDIRECTIONAL |
494 G_BINDING_INVERT_BOOLEAN | G_BINDING_SYNC_CREATE);
499 add_video_preview_to_pipeline (EmpathyCallWindow *self)
501 EmpathyCallWindowPriv *priv = GET_PRIV (self);
504 g_assert (priv->video_preview != NULL);
505 g_assert (priv->pipeline != NULL);
506 g_assert (priv->video_input != NULL);
507 g_assert (priv->video_tee != NULL);
509 preview = priv->video_preview_sink;
511 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
513 g_warning ("Could not add video input to pipeline");
517 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
519 g_warning ("Could not add video preview to pipeline");
523 if (!gst_element_link (priv->video_input, priv->video_tee))
525 g_warning ("Could not link video input to video tee");
529 if (!gst_element_link (priv->video_tee, preview))
531 g_warning ("Could not link video tee to video preview");
537 empathy_call_window_disable_camera_cb (GtkAction *action,
538 EmpathyCallWindow *self)
540 clutter_actor_destroy (self->priv->preview_hidden_button);
542 gtk_toggle_button_set_active (
543 GTK_TOGGLE_BUTTON (self->priv->camera_button), FALSE);
547 empathy_call_window_minimise_camera_cb (GtkAction *action,
548 EmpathyCallWindow *self)
550 clutter_actor_hide (self->priv->video_preview);
551 clutter_actor_show (self->priv->preview_hidden_button);
555 empathy_call_window_maximise_camera_cb (GtkAction *action,
556 EmpathyCallWindow *self)
558 clutter_actor_show (self->priv->video_preview);
559 clutter_actor_hide (self->priv->preview_hidden_button);
563 empathy_call_window_swap_camera_cb (GtkAction *action,
564 EmpathyCallWindow *self)
566 const GList *cameras, *l;
569 DEBUG ("Swapping the camera");
571 cameras = empathy_camera_monitor_get_cameras (self->priv->camera_monitor);
572 current_cam = empathy_video_src_dup_device (
573 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
575 for (l = cameras; l != NULL; l = l->next)
577 EmpathyCamera *camera = l->data;
579 if (!tp_strdiff (camera->device, current_cam))
584 next = l->next->data;
586 next = cameras->data;
588 /* EmpathyCameraMenu will update itself and do the actual change
590 g_settings_set_string (self->priv->settings,
591 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
598 g_free (current_cam);
602 empathy_call_window_camera_added_cb (EmpathyCameraMonitor *monitor,
603 EmpathyCamera *camera,
604 EmpathyCallWindow *self)
606 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
608 gtk_action_set_visible (self->priv->menu_swap_camera,
609 g_list_length ((GList *) cameras) >= 2);
613 empathy_call_window_camera_removed_cb (EmpathyCameraMonitor *monitor,
614 EmpathyCamera *camera,
615 EmpathyCallWindow *self)
617 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
619 gtk_action_set_visible (self->priv->menu_swap_camera,
620 g_list_length ((GList *) cameras) >= 2);
624 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
625 EmpathyCallWindow *self)
629 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
631 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
632 0, gtk_get_current_event_time ());
633 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
637 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
638 EmpathyCallWindow *self)
642 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
643 "/preview-hidden-menu");
644 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
645 0, gtk_get_current_event_time ());
646 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
649 static ClutterActor *
650 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
651 ClutterBinAlignment x,
652 ClutterBinAlignment y)
654 ClutterActor *rectangle;
656 rectangle = CLUTTER_ACTOR (empathy_rounded_rectangle_new (
657 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT,
658 PREVIEW_ROUND_FACTOR));
660 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->preview_layout),
662 clutter_actor_hide (rectangle);
668 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
672 self->priv->preview_layout = clutter_bin_layout_new (
673 CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_CENTER);
674 self->priv->preview_box = box = clutter_box_new (self->priv->preview_layout);
676 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->overlay_layout),
678 CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL);
680 self->priv->preview_rectangle1 =
681 empathy_call_window_create_preview_rectangle (self,
682 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
683 self->priv->preview_rectangle2 =
684 empathy_call_window_create_preview_rectangle (self,
685 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
686 self->priv->preview_rectangle3 =
687 empathy_call_window_create_preview_rectangle (self,
688 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
689 self->priv->preview_rectangle4 =
690 empathy_call_window_create_preview_rectangle (self,
691 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
695 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
698 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
699 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
700 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
701 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
705 empathy_call_window_get_preview_coordinates (EmpathyCallWindow *self,
710 guint ret_x = 0, ret_y = 0;
713 if (!clutter_actor_has_allocation (self->priv->preview_box))
716 clutter_actor_get_geometry (self->priv->preview_box, &box);
720 case PREVIEW_POS_TOP_LEFT:
721 ret_x = ret_y = SELF_VIDEO_SECTION_MARGIN;
723 case PREVIEW_POS_TOP_RIGHT:
724 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
725 - SELF_VIDEO_SECTION_WIDTH;
726 ret_y = SELF_VIDEO_SECTION_MARGIN;
728 case PREVIEW_POS_BOTTOM_LEFT:
729 ret_x = SELF_VIDEO_SECTION_MARGIN;
730 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
731 - SELF_VIDEO_SECTION_HEIGHT;
733 case PREVIEW_POS_BOTTOM_RIGHT:
734 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
735 - SELF_VIDEO_SECTION_WIDTH;
736 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
737 - SELF_VIDEO_SECTION_HEIGHT;
740 g_warn_if_reached ();
751 static PreviewPosition
752 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
757 PreviewPosition pos = PREVIEW_POS_NONE;
759 if (!clutter_actor_has_allocation (self->priv->preview_box))
762 clutter_actor_get_geometry (self->priv->preview_box, &box);
764 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
765 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
766 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
767 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
769 pos = PREVIEW_POS_TOP_LEFT;
771 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
772 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
773 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
774 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
776 pos = PREVIEW_POS_TOP_RIGHT;
778 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
779 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
780 box.height - SELF_VIDEO_SECTION_MARGIN >= event_y &&
781 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
783 pos = PREVIEW_POS_BOTTOM_LEFT;
785 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
786 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
787 box.height - 2 * SELF_VIDEO_SECTION_MARGIN >= event_y &&
788 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
790 pos = PREVIEW_POS_BOTTOM_RIGHT;
796 static ClutterActor *
797 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
800 ClutterActor *rectangle;
804 case PREVIEW_POS_TOP_LEFT:
805 rectangle = self->priv->preview_rectangle1;
807 case PREVIEW_POS_TOP_RIGHT:
808 rectangle = self->priv->preview_rectangle3;
810 case PREVIEW_POS_BOTTOM_LEFT:
811 rectangle = self->priv->preview_rectangle2;
813 case PREVIEW_POS_BOTTOM_RIGHT:
814 rectangle = self->priv->preview_rectangle4;
824 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
827 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->preview_layout);
829 DEBUG ("moving the video preview to %d", pos);
831 self->priv->preview_pos = pos;
835 case PREVIEW_POS_TOP_LEFT:
836 clutter_bin_layout_set_alignment (layout,
837 self->priv->video_preview,
838 CLUTTER_BIN_ALIGNMENT_START,
839 CLUTTER_BIN_ALIGNMENT_START);
841 case PREVIEW_POS_TOP_RIGHT:
842 clutter_bin_layout_set_alignment (layout,
843 self->priv->video_preview,
844 CLUTTER_BIN_ALIGNMENT_END,
845 CLUTTER_BIN_ALIGNMENT_START);
847 case PREVIEW_POS_BOTTOM_LEFT:
848 clutter_bin_layout_set_alignment (layout,
849 self->priv->video_preview,
850 CLUTTER_BIN_ALIGNMENT_START,
851 CLUTTER_BIN_ALIGNMENT_END);
853 case PREVIEW_POS_BOTTOM_RIGHT:
854 clutter_bin_layout_set_alignment (layout,
855 self->priv->video_preview,
856 CLUTTER_BIN_ALIGNMENT_END,
857 CLUTTER_BIN_ALIGNMENT_END);
860 g_warn_if_reached ();
863 g_settings_set_enum (self->priv->settings, "camera-position", pos);
867 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
870 ClutterActor *rectangle;
871 ClutterColor white = { 0xff, 0xff, 0xff, 0xff};
873 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
875 empathy_rounded_rectangle_set_border_width (
876 EMPATHY_ROUNDED_RECTANGLE (rectangle), 2 * SELF_VIDEO_SECTION_MARGIN);
877 empathy_rounded_rectangle_set_border_color (
878 EMPATHY_ROUNDED_RECTANGLE (rectangle), &white);
882 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
883 ClutterActor *rectangle)
885 ClutterColor white = { 0xff, 0xff, 0xff, 0xff}, darker;
887 clutter_color_shade (&white, 0.55, &darker);
889 empathy_rounded_rectangle_set_border_width (
890 EMPATHY_ROUNDED_RECTANGLE (rectangle), 1);
891 empathy_rounded_rectangle_set_border_color (
892 EMPATHY_ROUNDED_RECTANGLE (rectangle), &darker);
896 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
898 ClutterActor *rectangle;
900 rectangle = empathy_call_window_get_preview_rectangle (self,
901 self->priv->preview_pos);
903 /* We don't want to darken the rectangle where the preview
906 if (self->priv->preview_rectangle1 != rectangle)
907 empathy_call_window_darken_preview_rectangle (self,
908 self->priv->preview_rectangle1);
910 if (self->priv->preview_rectangle2 != rectangle)
911 empathy_call_window_darken_preview_rectangle (self,
912 self->priv->preview_rectangle2);
914 if (self->priv->preview_rectangle3 != rectangle)
915 empathy_call_window_darken_preview_rectangle (self,
916 self->priv->preview_rectangle3);
918 if (self->priv->preview_rectangle4 != rectangle)
919 empathy_call_window_darken_preview_rectangle (self,
920 self->priv->preview_rectangle4);
924 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
928 ClutterModifierType modifiers,
929 EmpathyCallWindow *self)
931 ClutterActor *stage = clutter_actor_get_stage (actor);
934 self->priv->drag_preview = clutter_clone_new (actor);
936 clutter_container_add_actor (CLUTTER_CONTAINER (stage),
937 self->priv->drag_preview);
939 clutter_actor_transform_stage_point (actor, event_x, event_y,
942 clutter_actor_set_position (self->priv->drag_preview,
943 event_x - rel_x, event_y - rel_y);
945 clutter_drag_action_set_drag_handle (action,
946 self->priv->drag_preview);
948 clutter_actor_set_opacity (actor, 0);
949 clutter_actor_hide (self->priv->preview_shown_button);
951 empathy_call_window_show_preview_rectangles (self, TRUE);
952 empathy_call_window_darken_preview_rectangles (self);
956 empathy_call_window_on_animation_completed_cb (ClutterAnimation *animation,
959 clutter_actor_set_opacity (actor, 255);
963 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
967 ClutterModifierType modifiers,
968 EmpathyCallWindow *self)
973 /* Get the position before destroying the drag actor, otherwise the
974 * preview_box allocation won't be valid and we won't be able to
975 * calculate the position. */
976 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
978 empathy_call_window_get_preview_coordinates (self,
979 pos != PREVIEW_POS_NONE ? pos : self->priv->preview_pos,
982 /* Move the preview to the destination and destroy it afterwards */
983 clutter_actor_animate (self->priv->drag_preview, CLUTTER_LINEAR, 500,
986 "signal-swapped-after::completed",
987 clutter_actor_destroy, self->priv->drag_preview,
988 "signal-swapped-after::completed",
989 clutter_actor_show, self->priv->preview_shown_button,
991 empathy_call_window_on_animation_completed_cb, actor,
994 self->priv->drag_preview = NULL;
996 if (pos != PREVIEW_POS_NONE)
997 empathy_call_window_move_video_preview (self, pos);
999 empathy_call_window_show_preview_rectangles (self, FALSE);
1003 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
1004 ClutterActor *actor,
1007 EmpathyCallWindow *self)
1009 PreviewPosition pos;
1010 gfloat event_x, event_y;
1012 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
1014 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
1016 if (pos != PREVIEW_POS_NONE)
1017 empathy_call_window_highlight_preview_rectangle (self, pos);
1019 empathy_call_window_darken_preview_rectangles (self);
1023 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
1024 ClutterCrossingEvent *event,
1025 EmpathyCallWindow *self)
1027 ClutterActor *rectangle;
1029 rectangle = empathy_call_window_get_preview_rectangle (self,
1030 self->priv->preview_pos);
1032 empathy_call_window_highlight_preview_rectangle (self,
1033 self->priv->preview_pos);
1035 clutter_actor_show (rectangle);
1041 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
1042 ClutterCrossingEvent *event,
1043 EmpathyCallWindow *self)
1045 ClutterActor *rectangle;
1047 rectangle = empathy_call_window_get_preview_rectangle (self,
1048 self->priv->preview_pos);
1050 empathy_call_window_darken_preview_rectangle (self, rectangle);
1052 clutter_actor_hide (rectangle);
1058 create_video_preview (EmpathyCallWindow *self)
1060 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1061 ClutterLayoutManager *layout;
1062 ClutterActor *preview;
1064 ClutterAction *action;
1066 PreviewPosition pos;
1068 g_assert (priv->video_preview == NULL);
1070 pos = g_settings_get_enum (priv->settings, "camera-position");
1072 preview = empathy_rounded_texture_new ();
1073 clutter_actor_set_size (preview,
1074 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1076 priv->video_preview_sink = gst_element_factory_make ("cluttersink", NULL);
1077 if (priv->video_preview_sink == NULL)
1078 g_error ("Missing cluttersink, check your clutter-gst installation");
1079 g_object_set (priv->video_preview_sink, "texture", preview, NULL);
1080 g_object_add_weak_pointer (G_OBJECT (priv->video_preview_sink), (gpointer) &priv->video_preview_sink);
1082 /* Add a little offset to the video preview */
1083 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1084 CLUTTER_BIN_ALIGNMENT_CENTER);
1085 priv->video_preview = clutter_box_new (layout);
1086 clutter_actor_set_size (priv->video_preview,
1087 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1088 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1090 /* Spinner for when changing the camera device */
1091 priv->preview_spinner_widget = gtk_spinner_new ();
1092 priv->preview_spinner_actor = empathy_rounded_actor_new (PREVIEW_ROUND_FACTOR);
1094 g_object_set (priv->preview_spinner_widget, "expand", TRUE, NULL);
1095 make_background_transparent (GTK_CLUTTER_ACTOR (priv->preview_spinner_actor));
1096 gtk_widget_show (priv->preview_spinner_widget);
1099 GTK_CONTAINER (gtk_clutter_actor_get_widget (
1100 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor))),
1101 priv->preview_spinner_widget);
1102 clutter_actor_set_size (priv->preview_spinner_actor,
1103 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1104 clutter_actor_set_opacity (priv->preview_spinner_actor, 128);
1105 clutter_actor_hide (priv->preview_spinner_actor);
1107 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1109 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1110 priv->preview_spinner_actor);
1112 g_object_set (priv->video_preview_sink,
1117 /* Translators: this is an "Info" label. It should be as short
1119 button = gtk_button_new_with_label (_("i"));
1120 priv->preview_shown_button = b = gtk_clutter_actor_new_with_contents (button);
1121 clutter_actor_set_size (b, 24, 24);
1122 clutter_actor_set_margin_right (b, 4);
1123 clutter_actor_set_margin_bottom (b, 2);
1124 make_background_transparent (GTK_CLUTTER_ACTOR (b));
1126 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout), b,
1127 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
1129 g_signal_connect (button, "clicked",
1130 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
1133 /* Translators: this is an "Info" label. It should be as short
1135 button = gtk_button_new_with_label (_("i"));
1136 priv->preview_hidden_button = b = gtk_clutter_actor_new_with_contents (button);
1137 clutter_actor_set_size (b, 24, 24);
1138 make_background_transparent (GTK_CLUTTER_ACTOR (b));
1140 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1141 priv->preview_hidden_button,
1142 CLUTTER_BIN_ALIGNMENT_START,
1143 CLUTTER_BIN_ALIGNMENT_END);
1145 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1147 clutter_actor_hide (priv->preview_hidden_button);
1149 g_signal_connect (button, "clicked",
1150 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
1153 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1154 priv->video_preview,
1155 CLUTTER_BIN_ALIGNMENT_START,
1156 CLUTTER_BIN_ALIGNMENT_END);
1158 empathy_call_window_move_video_preview (self, pos);
1160 action = clutter_drag_action_new ();
1161 g_signal_connect (action, "drag-begin",
1162 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1163 g_signal_connect (action, "drag-end",
1164 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1165 g_signal_connect (action, "drag-motion",
1166 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1168 g_signal_connect (preview, "enter-event",
1169 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1170 g_signal_connect (preview, "leave-event",
1171 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1173 clutter_actor_add_action (preview, action);
1174 clutter_actor_set_reactive (preview, TRUE);
1175 clutter_actor_set_reactive (priv->preview_shown_button, TRUE);
1179 empathy_call_window_start_camera_spinning (EmpathyCallWindow *self)
1181 clutter_actor_show (self->priv->preview_spinner_actor);
1182 gtk_spinner_start (GTK_SPINNER (self->priv->preview_spinner_widget));
1186 empathy_call_window_stop_camera_spinning (EmpathyCallWindow *self)
1188 clutter_actor_hide (self->priv->preview_spinner_actor);
1189 gtk_spinner_stop (GTK_SPINNER (self->priv->preview_spinner_widget));
1193 empathy_call_window_play_camera (EmpathyCallWindow *self,
1196 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1197 GstElement *preview;
1200 if (priv->video_preview == NULL)
1202 create_video_preview (self);
1203 add_video_preview_to_pipeline (self);
1208 state = GST_STATE_PLAYING;
1212 empathy_call_window_start_camera_spinning (self);
1213 state = GST_STATE_NULL;
1216 preview = priv->video_preview_sink;
1218 gst_element_set_state (preview, state);
1219 gst_element_set_state (priv->video_tee, state);
1220 gst_element_set_state (priv->video_input, state);
1224 display_video_preview (EmpathyCallWindow *self,
1227 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1229 if (priv->video_preview == NULL)
1231 create_video_preview (self);
1232 add_video_preview_to_pipeline (self);
1237 /* Display the video preview */
1238 DEBUG ("Show video preview");
1240 empathy_call_window_play_camera (self, TRUE);
1241 clutter_actor_show (priv->video_preview);
1242 clutter_actor_raise_top (priv->floating_toolbar);
1246 /* Hide the video preview */
1247 DEBUG ("Hide video preview");
1249 if (priv->video_preview != NULL)
1251 clutter_actor_hide (priv->video_preview);
1252 empathy_call_window_play_camera (self, FALSE);
1258 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1260 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1262 empathy_call_window_status_message (window, _("Connecting…"));
1263 priv->call_state = CONNECTING;
1265 /* Show the toolbar */
1266 clutter_state_set_state (priv->transitions, "fade-in");
1269 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1270 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1274 disable_camera (EmpathyCallWindow *self)
1276 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1278 if (priv->camera_state == CAMERA_STATE_OFF)
1281 DEBUG ("Disable camera");
1283 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1285 priv->camera_state = CAMERA_STATE_OFF;
1289 enable_camera (EmpathyCallWindow *self)
1291 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1293 if (priv->camera_state == CAMERA_STATE_ON)
1296 if (priv->video_input == NULL)
1298 DEBUG ("Can't enable camera, no input");
1302 DEBUG ("Enable camera");
1304 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1306 priv->camera_state = CAMERA_STATE_ON;
1310 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
1311 EmpathyCallWindow *self)
1313 if (gtk_toggle_tool_button_get_active (toggle))
1314 enable_camera (self);
1316 disable_camera (self);
1320 create_pipeline (EmpathyCallWindow *self)
1322 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1325 g_assert (priv->pipeline == NULL);
1327 priv->pipeline = gst_pipeline_new (NULL);
1328 priv->pipeline_playing = FALSE;
1330 priv->video_tee = gst_element_factory_make ("tee", NULL);
1331 gst_object_ref_sink (priv->video_tee);
1333 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1335 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1336 priv->bus_message_source_id = gst_bus_add_watch (bus,
1337 empathy_call_window_bus_message, self);
1339 g_object_unref (bus);
1343 empathy_call_window_settings_cb (GtkAction *action,
1344 EmpathyCallWindow *self)
1346 gchar *args = g_strdup_printf ("-p %s",
1347 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1349 empathy_launch_program (BIN_DIR, "empathy", args);
1355 empathy_call_window_contents_cb (GtkAction *action,
1356 EmpathyCallWindow *self)
1358 empathy_url_show (GTK_WIDGET (self), "help:empathy/audio-video");
1362 empathy_call_window_debug_cb (GtkAction *action,
1363 EmpathyCallWindow *self)
1365 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1369 empathy_call_window_about_cb (GtkAction *action,
1370 EmpathyCallWindow *self)
1372 empathy_about_dialog_new (GTK_WINDOW (self));
1376 empathy_call_window_toolbar_timeout (gpointer data)
1378 EmpathyCallWindow *self = data;
1380 /* We don't want to hide the toolbar if we're not in a call, as
1381 * to show the call status all the time. Also don't hide if we're muted
1382 * to prevent the awkward, talking when muted situation */
1383 if (self->priv->call_state != CONNECTING &&
1384 self->priv->call_state != DISCONNECTED &&
1386 clutter_state_set_state (self->priv->transitions, "fade-out");
1392 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1394 EmpathyCallWindow *self)
1396 clutter_state_set_state (self->priv->transitions, "fade-in");
1398 if (self->priv->inactivity_src > 0)
1399 g_source_remove (self->priv->inactivity_src);
1401 self->priv->inactivity_src = g_timeout_add_seconds (3,
1402 empathy_call_window_toolbar_timeout, self);
1408 empathy_call_window_configure_event_cb (GtkWidget *widget,
1410 EmpathyCallWindow *self)
1412 GdkWindow *gdk_window;
1413 GdkWindowState window_state;
1415 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1416 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1418 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1419 &self->priv->dialpad_width, NULL);
1421 gdk_window = gtk_widget_get_window (widget);
1422 window_state = gdk_window_get_state (gdk_window);
1423 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1429 empathy_call_window_destroyed_cb (GtkWidget *object,
1430 EmpathyCallWindow *self)
1432 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1434 /* Save the geometry as if the dialpad was hidden. */
1435 empathy_geometry_save_values (GTK_WINDOW (self),
1436 self->priv->x, self->priv->y,
1437 self->priv->w - self->priv->dialpad_width, self->priv->h,
1438 self->priv->maximized);
1443 empathy_call_window_incoming_call_response_cb (GtkDialog *dialog,
1445 EmpathyCallWindow *self)
1447 switch (response_id)
1449 case GTK_RESPONSE_ACCEPT:
1450 tp_channel_dispatch_operation_handle_with_async (
1451 self->priv->pending_cdo, EMPATHY_CALL_BUS_NAME, NULL, NULL);
1453 tp_clear_object (&self->priv->pending_cdo);
1454 tp_clear_object (&self->priv->pending_channel);
1455 tp_clear_object (&self->priv->pending_context);
1458 case GTK_RESPONSE_CANCEL:
1459 tp_channel_dispatch_operation_close_channels_async (
1460 self->priv->pending_cdo, NULL, NULL);
1462 empathy_call_window_status_message (self, _("Disconnected"));
1463 self->priv->call_state = DISCONNECTED;
1466 g_warn_if_reached ();
1471 empathy_call_window_set_state_ringing (EmpathyCallWindow *self)
1475 g_assert (self->priv->call_state != CONNECTED);
1477 video = tp_call_channel_has_initial_video (self->priv->pending_channel, NULL);
1479 empathy_call_window_status_message (self, _("Incoming call"));
1480 self->priv->call_state = RINGING;
1482 self->priv->incoming_call_dialog = gtk_message_dialog_new (
1483 GTK_WINDOW (self), GTK_DIALOG_MODAL,
1484 GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
1485 video ? _("Incoming video call from %s") : _("Incoming call from %s"),
1486 empathy_contact_get_alias (self->priv->contact));
1488 gtk_dialog_add_buttons (GTK_DIALOG (self->priv->incoming_call_dialog),
1489 _("Reject"), GTK_RESPONSE_CANCEL,
1490 _("Answer"), GTK_RESPONSE_ACCEPT,
1493 g_signal_connect (self->priv->incoming_call_dialog, "response",
1494 G_CALLBACK (empathy_call_window_incoming_call_response_cb), self);
1495 gtk_widget_show (self->priv->incoming_call_dialog);
1499 empathy_call_window_cdo_invalidated_cb (TpProxy *channel,
1503 EmpathyCallWindow *self)
1505 tp_clear_object (&self->priv->pending_cdo);
1506 tp_clear_object (&self->priv->pending_channel);
1507 tp_clear_object (&self->priv->pending_context);
1509 /* We don't know if the incoming call has been accepted or not, so we
1510 * assume it hasn't and if it has, we'll set the proper status when
1511 * we get the new handler. */
1512 empathy_call_window_status_message (self, _("Disconnected"));
1513 self->priv->call_state = DISCONNECTED;
1515 gtk_widget_destroy (self->priv->incoming_call_dialog);
1516 self->priv->incoming_call_dialog = NULL;
1520 empathy_call_window_start_ringing (EmpathyCallWindow *self,
1521 TpCallChannel *channel,
1522 TpChannelDispatchOperation *dispatch_operation,
1523 TpAddDispatchOperationContext *context)
1525 g_assert (self->priv->pending_channel == NULL);
1526 g_assert (self->priv->pending_context == NULL);
1527 g_assert (self->priv->pending_cdo == NULL);
1529 /* Start ringing and delay until the user answers or hangs. */
1530 self->priv->pending_channel = g_object_ref (channel);
1531 self->priv->pending_context = g_object_ref (context);
1532 self->priv->pending_cdo = g_object_ref (dispatch_operation);
1534 g_signal_connect (self->priv->pending_cdo, "invalidated",
1535 G_CALLBACK (empathy_call_window_cdo_invalidated_cb), self);
1537 empathy_call_window_set_state_ringing (self);
1538 tp_add_dispatch_operation_context_accept (context);
1542 empathy_call_window_init (EmpathyCallWindow *self)
1544 EmpathyCallWindowPriv *priv;
1546 GtkWidget *top_vbox;
1548 ClutterConstraint *constraint;
1549 ClutterActor *remote_avatar;
1550 ClutterColor black = { 0, 0, 0, 0 };
1551 ClutterMargin overlay_margin = { OVERLAY_MARGIN, OVERLAY_MARGIN,
1552 OVERLAY_MARGIN, OVERLAY_MARGIN };
1554 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1555 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1557 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1558 priv->timer = g_timer_new ();
1560 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1561 gui = empathy_builder_get_file (filename,
1562 "call_window_vbox", &top_vbox,
1563 "errors_vbox", &priv->errors_vbox,
1564 "pane", &priv->pane,
1565 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1566 "remote_user_status_toolbar", &priv->remote_user_status_toolbar,
1567 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1568 "status_label", &priv->status_label,
1569 "audiocall", &priv->audio_call_button,
1570 "videocall", &priv->video_call_button,
1571 "microphone", &priv->mic_button,
1572 "volume", &priv->volume_button,
1573 "camera", &priv->camera_button,
1574 "hangup", &priv->hangup_button,
1575 "dialpad", &priv->dialpad_button,
1576 "toolbar", &priv->toolbar,
1577 "bottom_toolbar", &priv->bottom_toolbar,
1578 "ui_manager", &priv->ui_manager,
1579 "menufullscreen", &priv->menu_fullscreen,
1580 "menupreviewswap", &priv->menu_swap_camera,
1581 "details_vbox", &priv->details_vbox,
1582 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1583 "acodec_encoding_label", &priv->acodec_encoding_label,
1584 "acodec_decoding_label", &priv->acodec_decoding_label,
1585 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1586 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1587 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1588 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1589 "video_local_candidate_label", &priv->video_local_candidate_label,
1590 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1591 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1592 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1593 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1597 empathy_builder_connect (gui, self,
1598 "hangup", "clicked", empathy_call_window_hangup_cb,
1599 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1600 "videocall", "clicked", empathy_call_window_video_call_cb,
1601 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1602 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1603 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1604 "menusettings", "activate", empathy_call_window_settings_cb,
1605 "menucontents", "activate", empathy_call_window_contents_cb,
1606 "menudebug", "activate", empathy_call_window_debug_cb,
1607 "menuabout", "activate", empathy_call_window_about_cb,
1608 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1609 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1610 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1611 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1614 empathy_set_css_provider (GTK_WIDGET (self));
1615 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1617 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1619 g_object_bind_property (priv->camera_monitor, "available",
1620 priv->camera_button, "sensitive",
1621 G_BINDING_SYNC_CREATE);
1623 g_signal_connect (priv->camera_monitor, "added",
1624 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1625 g_signal_connect (priv->camera_monitor, "removed",
1626 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1628 g_mutex_init (&priv->lock);
1630 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1632 priv->content_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,
1633 CONTENT_HBOX_SPACING);
1634 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1637 /* main contents remote avatar/video box */
1638 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_FILL,
1639 CLUTTER_BIN_ALIGNMENT_FILL);
1641 priv->video_box = clutter_box_new (priv->video_layout);
1643 priv->video_container = gtk_clutter_embed_new ();
1645 gtk_widget_set_size_request (priv->video_container,
1646 REMOTE_VIDEO_DEFAULT_WIDTH, REMOTE_VIDEO_DEFAULT_HEIGHT);
1648 /* Set the background black */
1649 clutter_stage_set_color (
1650 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1651 GTK_CLUTTER_EMBED (priv->video_container))),
1654 clutter_container_add (
1655 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1656 GTK_CLUTTER_EMBED (priv->video_container))),
1660 constraint = clutter_bind_constraint_new (
1661 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1662 CLUTTER_BIND_SIZE, 0);
1663 clutter_actor_add_constraint (priv->video_box, constraint);
1665 priv->remote_user_avatar_widget = gtk_image_new ();
1666 remote_avatar = gtk_clutter_actor_new_with_contents (
1667 priv->remote_user_avatar_widget);
1668 make_background_transparent (GTK_CLUTTER_ACTOR (remote_avatar));
1670 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1673 /* create the overlay bin */
1674 priv->overlay_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1675 CLUTTER_BIN_ALIGNMENT_CENTER);
1676 priv->overlay_bin = clutter_actor_new ();
1677 clutter_actor_set_layout_manager (priv->overlay_bin, priv->overlay_layout);
1679 clutter_actor_set_margin (priv->overlay_bin, &overlay_margin);
1681 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1683 CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL);
1685 empathy_call_window_create_preview_rectangles (self);
1687 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1688 priv->video_container, TRUE, TRUE,
1689 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1691 create_pipeline (self);
1692 create_video_output_widget (self);
1693 create_audio_input (self);
1694 create_video_input (self);
1696 priv->floating_toolbar = gtk_clutter_actor_new ();
1697 clutter_actor_set_reactive (priv->floating_toolbar, TRUE);
1698 make_background_transparent (GTK_CLUTTER_ACTOR (priv->floating_toolbar));
1700 gtk_style_context_add_class (
1701 gtk_widget_get_style_context (GTK_WIDGET (priv->bottom_toolbar)),
1702 GTK_STYLE_CLASS_OSD);
1703 gtk_widget_reparent (priv->bottom_toolbar,
1704 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1706 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->overlay_layout),
1707 priv->floating_toolbar,
1708 CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_END);
1710 clutter_actor_raise_top (priv->floating_toolbar);
1712 /* Transitions for the floating toolbar */
1713 priv->transitions = clutter_state_new ();
1715 /* all transitions last for 2s */
1716 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1718 /* transition from any state to "fade-out" state */
1719 clutter_state_set (priv->transitions, NULL, "fade-out",
1720 priv->floating_toolbar,
1721 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1724 /* transition from any state to "fade-in" state */
1725 clutter_state_set (priv->transitions, NULL, "fade-in",
1726 priv->floating_toolbar,
1727 "opacity", CLUTTER_EASE_OUT_QUAD, 255,
1730 /* put the actor into the "fade-in" state with no animation */
1731 clutter_state_warp_to_state (priv->transitions, "fade-in");
1733 /* The call will be started as soon the pipeline is playing */
1734 priv->start_call_when_playing = TRUE;
1736 priv->dtmf_panel = empathy_dialpad_widget_new ();
1737 g_signal_connect (priv->dtmf_panel, "start-tone",
1738 G_CALLBACK (dtmf_start_tone_cb), self);
1740 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1743 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1746 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1748 gtk_widget_show_all (top_vbox);
1750 gtk_widget_hide (priv->dtmf_panel);
1751 gtk_widget_hide (priv->details_vbox);
1753 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1755 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1756 priv->video_container);
1758 /* We hide the bottom toolbar after 3s of inactivity and show it
1759 * again on mouse movement */
1760 priv->inactivity_src = g_timeout_add_seconds (3,
1761 empathy_call_window_toolbar_timeout, self);
1763 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1764 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1766 g_signal_connect (G_OBJECT (self), "realize",
1767 G_CALLBACK (empathy_call_window_realized_cb), self);
1769 g_signal_connect (G_OBJECT (self), "delete-event",
1770 G_CALLBACK (empathy_call_window_delete_cb), self);
1772 g_signal_connect (G_OBJECT (self), "window-state-event",
1773 G_CALLBACK (empathy_call_window_state_event_cb), self);
1775 g_signal_connect (G_OBJECT (self), "key-press-event",
1776 G_CALLBACK (empathy_call_window_key_press_cb), self);
1778 g_signal_connect (self, "motion-notify-event",
1779 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1781 g_object_ref (priv->ui_manager);
1782 g_object_unref (gui);
1784 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1785 priv->mic_menu = empathy_mic_menu_new (self);
1786 priv->camera_menu = empathy_camera_menu_new (self);
1788 empathy_call_window_show_hangup_button (self, TRUE);
1790 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1791 /* These signals are used to track the window position and save it
1792 * when the window is destroyed. We need to do this as we don't want
1793 * the window geometry to be saved with the dialpad taken into account. */
1794 g_signal_connect (self, "destroy",
1795 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1796 g_signal_connect (self, "configure-event",
1797 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1798 g_signal_connect (self, "window-state-event",
1799 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1801 /* Don't display labels in both toolbars */
1802 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1805 /* Instead of specifying a width and a height, we specify only one size. That's
1806 because we want a square avatar icon. */
1808 init_contact_avatar_with_size (EmpathyContact *contact,
1809 GtkWidget *image_widget,
1812 GdkPixbuf *pixbuf_avatar = NULL;
1814 if (contact != NULL)
1816 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1820 if (pixbuf_avatar == NULL)
1822 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1823 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1826 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1828 if (pixbuf_avatar != NULL)
1829 g_object_unref (pixbuf_avatar);
1833 set_window_title (EmpathyCallWindow *self)
1835 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1838 if (priv->contact != NULL)
1840 /* translators: Call is a noun and %s is the contact name. This string
1841 * is used in the window title */
1842 tmp = g_strdup_printf (_("Call with %s"),
1843 empathy_contact_get_alias (priv->contact));
1844 gtk_window_set_title (GTK_WINDOW (self), tmp);
1849 g_warning ("Unknown remote contact!");
1854 set_remote_user_name (EmpathyCallWindow *self,
1855 EmpathyContact *contact)
1857 const gchar *alias = empathy_contact_get_alias (contact);
1858 const gchar *status = empathy_contact_get_status (contact);
1860 gtk_label_set_text (GTK_LABEL (self->priv->remote_user_name_toolbar), alias);
1862 if (status != NULL) {
1865 markup = g_markup_printf_escaped ("<small>%s</small>", status);
1866 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_status_toolbar),
1870 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_status_toolbar),
1876 contact_name_changed_cb (EmpathyContact *contact,
1878 EmpathyCallWindow *self)
1880 set_window_title (self);
1881 set_remote_user_name (self, contact);
1885 contact_presence_changed_cb (EmpathyContact *contact,
1887 EmpathyCallWindow *self)
1889 set_remote_user_name (self, contact);
1893 contact_avatar_changed_cb (EmpathyContact *contact,
1895 EmpathyCallWindow *self)
1898 GtkAllocation allocation;
1899 GtkWidget *avatar_widget;
1901 avatar_widget = self->priv->remote_user_avatar_widget;
1903 gtk_widget_get_allocation (avatar_widget, &allocation);
1904 size = allocation.height;
1908 /* the widget is not allocated yet, set a default size */
1909 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1910 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1913 init_contact_avatar_with_size (contact, avatar_widget, size);
1915 avatar_widget = self->priv->remote_user_avatar_toolbar;
1917 gtk_widget_get_allocation (avatar_widget, &allocation);
1918 size = allocation.height;
1922 /* the widget is not allocated yet, set a default size */
1923 size = SMALL_TOOLBAR_SIZE;
1926 init_contact_avatar_with_size (contact, avatar_widget, size);
1930 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1931 EmpathyCallHandler *handler)
1933 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1935 tp_g_signal_connect_object (priv->contact, "notify::name",
1936 G_CALLBACK (contact_name_changed_cb), self, 0);
1937 tp_g_signal_connect_object (priv->contact, "notify::avatar",
1938 G_CALLBACK (contact_avatar_changed_cb), self, 0);
1939 tp_g_signal_connect_object (priv->contact, "notify::presence",
1940 G_CALLBACK (contact_presence_changed_cb), self, 0);
1942 set_window_title (self);
1943 set_remote_user_name (self, priv->contact);
1945 init_contact_avatar_with_size (priv->contact,
1946 priv->remote_user_avatar_widget,
1947 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
1948 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
1950 init_contact_avatar_with_size (priv->contact,
1951 priv->remote_user_avatar_toolbar,
1952 SMALL_TOOLBAR_SIZE);
1954 /* The remote avatar is shown by default and will be hidden when we receive
1955 video from the remote side. */
1956 clutter_actor_hide (priv->video_output);
1957 gtk_widget_show (priv->remote_user_avatar_widget);
1961 update_send_codec (EmpathyCallWindow *self,
1964 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1971 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
1972 widget = priv->acodec_encoding_label;
1976 codec = empathy_call_handler_get_send_video_codec (priv->handler);
1977 widget = priv->vcodec_encoding_label;
1983 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
1984 gtk_label_set_text (GTK_LABEL (widget), tmp);
1989 send_audio_codec_notify_cb (GObject *object,
1993 EmpathyCallWindow *self = user_data;
1995 update_send_codec (self, TRUE);
1999 send_video_codec_notify_cb (GObject *object,
2003 EmpathyCallWindow *self = user_data;
2005 update_send_codec (self, FALSE);
2009 update_recv_codec (EmpathyCallWindow *self,
2012 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2015 GString *str = NULL;
2019 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
2020 widget = priv->acodec_decoding_label;
2024 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
2025 widget = priv->vcodec_decoding_label;
2031 for (l = codecs; l != NULL; l = g_list_next (l))
2033 FsCodec *codec = l->data;
2036 str = g_string_new (NULL);
2038 g_string_append (str, ", ");
2040 g_string_append_printf (str, "%s/%u", codec->encoding_name,
2044 gtk_label_set_text (GTK_LABEL (widget), str->str);
2045 g_string_free (str, TRUE);
2049 recv_audio_codecs_notify_cb (GObject *object,
2053 EmpathyCallWindow *self = user_data;
2055 update_recv_codec (self, TRUE);
2059 recv_video_codecs_notify_cb (GObject *object,
2063 EmpathyCallWindow *self = user_data;
2065 update_recv_codec (self, FALSE);
2068 static const gchar *
2069 candidate_type_to_str (FsCandidate *candidate)
2071 switch (candidate->type)
2073 case FS_CANDIDATE_TYPE_HOST:
2075 case FS_CANDIDATE_TYPE_SRFLX:
2076 return "server reflexive";
2077 case FS_CANDIDATE_TYPE_PRFLX:
2078 return "peer reflexive";
2079 case FS_CANDIDATE_TYPE_RELAY:
2081 case FS_CANDIDATE_TYPE_MULTICAST:
2088 static const gchar *
2089 candidate_type_to_desc (FsCandidate *candidate)
2091 switch (candidate->type)
2093 case FS_CANDIDATE_TYPE_HOST:
2094 return _("The IP address as seen by the machine");
2095 case FS_CANDIDATE_TYPE_SRFLX:
2096 return _("The IP address as seen by a server on the Internet");
2097 case FS_CANDIDATE_TYPE_PRFLX:
2098 return _("The IP address of the peer as seen by the other side");
2099 case FS_CANDIDATE_TYPE_RELAY:
2100 return _("The IP address of a relay server");
2101 case FS_CANDIDATE_TYPE_MULTICAST:
2102 return _("The IP address of the multicast group");
2109 update_candidat_widget (EmpathyCallWindow *self,
2112 FsCandidate *candidate)
2116 g_assert (candidate != NULL);
2117 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
2118 candidate->port, candidate_type_to_str (candidate));
2120 gtk_label_set_text (GTK_LABEL (label), str);
2121 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
2127 candidates_changed_cb (GObject *object,
2129 EmpathyCallWindow *self)
2131 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2132 FsCandidate *candidate = NULL;
2134 if (type == FS_MEDIA_TYPE_VIDEO)
2136 /* Update remote candidate */
2137 candidate = empathy_call_handler_get_video_remote_candidate (
2140 update_candidat_widget (self, priv->video_remote_candidate_label,
2141 priv->video_remote_candidate_info_img, candidate);
2143 /* Update local candidate */
2144 candidate = empathy_call_handler_get_video_local_candidate (
2147 update_candidat_widget (self, priv->video_local_candidate_label,
2148 priv->video_local_candidate_info_img, candidate);
2152 /* Update remote candidate */
2153 candidate = empathy_call_handler_get_audio_remote_candidate (
2156 update_candidat_widget (self, priv->audio_remote_candidate_label,
2157 priv->audio_remote_candidate_info_img, candidate);
2159 /* Update local candidate */
2160 candidate = empathy_call_handler_get_audio_local_candidate (
2163 update_candidat_widget (self, priv->audio_local_candidate_label,
2164 priv->audio_local_candidate_info_img, candidate);
2169 empathy_call_window_constructed (GObject *object)
2171 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2172 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2173 TpCallChannel *call;
2176 g_assert (priv->handler != NULL);
2178 g_object_get (priv->handler, "call-channel", &call, NULL);
2179 state = tp_call_channel_get_state (call, NULL, NULL, NULL);
2180 priv->outgoing = (state == TP_CALL_STATE_PENDING_INITIATOR);
2181 tp_clear_object (&call);
2183 priv->contact = empathy_call_handler_get_contact (priv->handler);
2184 g_assert (priv->contact != NULL);
2185 g_object_ref (priv->contact);
2187 if (!empathy_contact_can_voip_video (priv->contact))
2189 gtk_widget_set_sensitive (priv->video_call_button, FALSE);
2190 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2193 empathy_call_window_setup_avatars (self, priv->handler);
2194 empathy_call_window_set_state_connecting (self);
2196 if (!empathy_call_handler_has_initial_video (priv->handler))
2198 gtk_toggle_button_set_active (
2199 GTK_TOGGLE_BUTTON (priv->camera_button), FALSE);
2201 /* If call has InitialVideo, the preview will be started once the call has
2202 * been started (start_call()). */
2204 update_send_codec (self, TRUE);
2205 update_send_codec (self, FALSE);
2206 update_recv_codec (self, TRUE);
2207 update_recv_codec (self, FALSE);
2209 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2210 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2211 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2212 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2213 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2214 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2215 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2216 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2218 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2219 G_CALLBACK (candidates_changed_cb), self, 0);
2222 static void empathy_call_window_dispose (GObject *object);
2223 static void empathy_call_window_finalize (GObject *object);
2226 empathy_call_window_set_property (GObject *object,
2227 guint property_id, const GValue *value, GParamSpec *pspec)
2229 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2231 switch (property_id)
2233 case PROP_CALL_HANDLER:
2234 priv->handler = g_value_dup_object (value);
2237 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2242 empathy_call_window_get_property (GObject *object,
2243 guint property_id, GValue *value, GParamSpec *pspec)
2245 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2247 switch (property_id)
2249 case PROP_CALL_HANDLER:
2250 g_value_set_object (value, priv->handler);
2253 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2258 empathy_call_window_class_init (
2259 EmpathyCallWindowClass *empathy_call_window_class)
2261 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2262 GParamSpec *param_spec;
2264 g_type_class_add_private (empathy_call_window_class,
2265 sizeof (EmpathyCallWindowPriv));
2267 object_class->constructed = empathy_call_window_constructed;
2268 object_class->set_property = empathy_call_window_set_property;
2269 object_class->get_property = empathy_call_window_get_property;
2271 object_class->dispose = empathy_call_window_dispose;
2272 object_class->finalize = empathy_call_window_finalize;
2274 param_spec = g_param_spec_object ("handler",
2275 "handler", "The call handler",
2276 EMPATHY_TYPE_CALL_HANDLER,
2277 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2278 g_object_class_install_property (object_class,
2279 PROP_CALL_HANDLER, param_spec);
2283 empathy_call_window_dispose (GObject *object)
2285 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2286 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2288 if (priv->dispose_has_run)
2291 priv->dispose_has_run = TRUE;
2293 if (priv->handler != NULL)
2295 empathy_call_handler_stop_call (priv->handler);
2296 tp_clear_object (&priv->handler);
2299 if (priv->bus_message_source_id != 0)
2301 g_source_remove (priv->bus_message_source_id);
2302 priv->bus_message_source_id = 0;
2305 if (priv->got_video_src > 0)
2307 g_source_remove (priv->got_video_src);
2308 priv->got_video_src = 0;
2311 if (priv->inactivity_src > 0)
2313 g_source_remove (priv->inactivity_src);
2314 priv->inactivity_src = 0;
2317 tp_clear_object (&priv->pipeline);
2318 tp_clear_object (&priv->video_input);
2319 tp_clear_object (&priv->audio_input);
2320 tp_clear_object (&priv->video_tee);
2321 tp_clear_object (&priv->ui_manager);
2322 tp_clear_object (&priv->fullscreen);
2323 tp_clear_object (&priv->camera_monitor);
2324 tp_clear_object (&priv->settings);
2325 tp_clear_object (&priv->sound_mgr);
2326 tp_clear_object (&priv->mic_menu);
2327 tp_clear_object (&priv->camera_menu);
2328 tp_clear_object (&priv->transitions);
2330 g_list_free_full (priv->notifiers, g_object_unref);
2332 if (priv->timer_id != 0)
2333 g_source_remove (priv->timer_id);
2336 tp_clear_object (&priv->contact);
2338 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2342 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2344 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2346 if (priv->video_output_motion_handler_id != 0)
2348 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2349 priv->video_output_motion_handler_id);
2350 priv->video_output_motion_handler_id = 0;
2355 empathy_call_window_finalize (GObject *object)
2357 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2358 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2360 disconnect_video_output_motion_handler (self);
2362 /* free any data held directly by the object here */
2363 g_mutex_clear (&priv->lock);
2365 g_timer_destroy (priv->timer);
2367 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2372 empathy_call_window_new (EmpathyCallHandler *handler)
2374 return EMPATHY_CALL_WINDOW (
2375 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2379 empathy_call_window_present (EmpathyCallWindow *self,
2380 EmpathyCallHandler *handler)
2382 g_return_if_fail (EMPATHY_IS_CALL_HANDLER (handler));
2384 empathy_window_present (GTK_WINDOW (self));
2386 if (self->priv->call_state == DISCONNECTED)
2388 /* start a new call if one is not already in progress */
2389 tp_clear_object (&self->priv->handler);
2390 self->priv->handler = g_object_ref (handler);
2391 empathy_call_window_connect_handler (self);
2393 empathy_call_window_restart_call (self);
2398 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2399 GstElement *conference, gpointer user_data)
2401 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2402 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2403 FsElementAddedNotifier *notifier;
2406 DEBUG ("Conference added");
2408 /* Add notifier to set the various element properties as needed */
2409 notifier = fs_element_added_notifier_new ();
2410 keyfile = fs_utils_get_default_element_properties (conference);
2412 if (keyfile != NULL)
2413 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2415 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2417 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2419 gst_bin_add (GST_BIN (priv->pipeline), conference);
2420 gst_element_set_state (conference, GST_STATE_PLAYING);
2424 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2425 GstElement *conference, gpointer user_data)
2427 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2428 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2430 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2431 gst_element_set_state (conference, GST_STATE_NULL);
2435 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2437 GstStateChangeReturn state_change_return;
2438 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2440 if (priv->pipeline == NULL)
2443 if (priv->bus_message_source_id != 0)
2445 g_source_remove (priv->bus_message_source_id);
2446 priv->bus_message_source_id = 0;
2449 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2451 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2452 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2454 if (priv->pipeline != NULL)
2455 g_object_unref (priv->pipeline);
2456 priv->pipeline = NULL;
2458 if (priv->audio_output != NULL)
2459 g_object_unref (priv->audio_output);
2460 priv->audio_output = NULL;
2461 priv->audio_output_added = FALSE;
2463 if (priv->video_tee != NULL)
2464 g_object_unref (priv->video_tee);
2465 priv->video_tee = NULL;
2467 if (priv->video_preview != NULL)
2468 clutter_actor_destroy (priv->video_preview);
2469 priv->video_preview = NULL;
2471 /* If we destroy the preview while it's being dragged, we won't
2472 * get the ::drag-end signal, so manually destroy the clone */
2473 if (priv->drag_preview != NULL)
2475 clutter_actor_destroy (priv->drag_preview);
2476 empathy_call_window_show_preview_rectangles (self, FALSE);
2477 priv->drag_preview = NULL;
2480 priv->funnel = NULL;
2482 create_pipeline (self);
2483 /* Call will be started when user will hit the 'redial' button */
2484 priv->start_call_when_playing = FALSE;
2485 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2491 g_message ("Error: could not destroy pipeline. Closing call window");
2492 gtk_widget_destroy (GTK_WIDGET (self));
2499 reset_details_pane (EmpathyCallWindow *self)
2501 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2503 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2504 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2505 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2506 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2510 empathy_call_window_disconnected (EmpathyCallWindow *self,
2513 gboolean could_disconnect = FALSE;
2514 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2515 gboolean could_reset_pipeline;
2517 /* Leave full screen mode if needed */
2518 gtk_window_unfullscreen (GTK_WINDOW (self));
2520 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2521 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2523 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2525 if (priv->call_state == CONNECTING)
2526 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2528 if (priv->call_state != REDIALING)
2529 priv->call_state = DISCONNECTED;
2531 /* Show the toolbar */
2532 clutter_state_set_state (priv->transitions, "fade-in");
2534 if (could_reset_pipeline)
2536 g_mutex_lock (&priv->lock);
2538 g_timer_stop (priv->timer);
2540 if (priv->timer_id != 0)
2541 g_source_remove (priv->timer_id);
2544 g_mutex_unlock (&priv->lock);
2547 /* We are about to destroy the window, no need to update it or create
2548 * a video preview */
2551 empathy_call_window_status_message (self, _("Disconnected"));
2553 empathy_call_window_show_hangup_button (self, FALSE);
2555 /* Unsensitive the camera and mic button */
2556 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2557 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2559 /* Be sure that the mic button is enabled */
2560 gtk_toggle_button_set_active (
2561 GTK_TOGGLE_BUTTON (priv->mic_button), TRUE);
2563 if (priv->camera_state == CAMERA_STATE_ON)
2565 /* Restart the preview with the new pipeline. */
2566 display_video_preview (self, TRUE);
2569 /* destroy the video output; it will be recreated when we'll redial */
2570 disconnect_video_output_motion_handler (self);
2571 if (priv->video_output != NULL)
2572 clutter_actor_destroy (priv->video_output);
2573 priv->video_output = NULL;
2574 if (priv->got_video_src > 0)
2576 g_source_remove (priv->got_video_src);
2577 priv->got_video_src = 0;
2580 gtk_widget_show (priv->remote_user_avatar_widget);
2582 reset_details_pane (self);
2584 priv->sending_video = FALSE;
2585 priv->call_started = FALSE;
2587 could_disconnect = TRUE;
2589 /* TODO: display the self avatar of the preview (depends if the "Always
2590 * Show Video Preview" is enabled or not) */
2593 return could_disconnect;
2598 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2601 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2602 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2604 if (empathy_call_window_disconnected (self, TRUE) &&
2605 priv->call_state == REDIALING)
2606 empathy_call_window_restart_call (self);
2610 empathy_call_window_content_is_raw (TfContent *content)
2612 FsConference *conference;
2615 g_object_get (content, "fs-conference", &conference, NULL);
2616 g_assert (conference != NULL);
2618 /* FIXME: Ugly hack, update when moving a packetization property into
2620 israw = g_str_has_prefix (GST_OBJECT_NAME (conference), "fsrawconf");
2621 gst_object_unref (conference);
2627 empathy_call_window_content_removed_cb (EmpathyCallHandler *handler,
2629 EmpathyCallWindow *self)
2631 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2632 FsMediaType media_type;
2634 DEBUG ("removing content");
2636 g_object_get (content, "media-type", &media_type, NULL);
2639 * This assumes that there is only one video stream per channel...
2642 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2644 if (priv->funnel != NULL)
2648 output = priv->video_output_sink;
2650 gst_element_set_state (output, GST_STATE_NULL);
2651 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2653 gst_bin_remove (GST_BIN (priv->pipeline), output);
2654 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2655 priv->funnel = NULL;
2658 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2660 if (priv->audio_output != NULL)
2662 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2664 if (priv->audio_output_added)
2665 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2666 priv->audio_output = NULL;
2667 priv->audio_output_added = FALSE;
2672 g_assert_not_reached ();
2679 empathy_call_window_framerate_changed_cb (EmpathyCallHandler *handler,
2681 EmpathyCallWindow *self)
2683 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2685 DEBUG ("Framerate changed to %u", framerate);
2687 if (priv->video_input != NULL)
2688 empathy_video_src_set_framerate (priv->video_input, framerate);
2692 empathy_call_window_resolution_changed_cb (EmpathyCallHandler *handler,
2695 EmpathyCallWindow *self)
2697 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2699 DEBUG ("Resolution changed to %ux%u", width, height);
2701 if (priv->video_input != NULL)
2703 empathy_video_src_set_resolution (priv->video_input, width, height);
2707 /* Called with global lock held */
2709 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2711 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2715 if (priv->funnel == NULL)
2717 output = priv->video_output_sink;
2719 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2723 g_warning ("Could not create fsfunnel");
2727 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2729 gst_object_unref (priv->funnel);
2730 priv->funnel = NULL;
2731 g_warning ("Could not add funnel to pipeline");
2735 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2737 g_warning ("Could not add the video output widget to the pipeline");
2741 if (!gst_element_link (priv->funnel, output))
2743 g_warning ("Could not link output sink to funnel");
2744 goto error_output_added;
2747 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2749 g_warning ("Could not start video sink");
2750 goto error_output_added;
2753 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2755 g_warning ("Could not start funnel");
2756 goto error_output_added;
2760 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2763 g_warning ("Could not get request pad from funnel");
2770 gst_element_set_locked_state (priv->funnel, TRUE);
2771 gst_element_set_locked_state (output, TRUE);
2773 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2774 gst_element_set_state (output, GST_STATE_NULL);
2776 gst_bin_remove (GST_BIN (priv->pipeline), output);
2777 gst_element_set_locked_state (output, FALSE);
2781 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2782 priv->funnel = NULL;
2787 /* Called with global lock held */
2789 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self,
2792 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2794 GstPadTemplate *template;
2796 if (!priv->audio_output_added)
2798 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2800 g_warning ("Could not add audio sink to pipeline");
2801 g_object_unref (priv->audio_output);
2802 goto error_add_output;
2805 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2807 g_warning ("Could not start audio sink");
2812 template = gst_element_class_get_pad_template (
2813 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2815 pad = gst_element_request_pad (priv->audio_output,
2816 template, NULL, NULL);
2820 g_warning ("Could not get sink pad from sink");
2827 gst_element_set_locked_state (priv->audio_output, TRUE);
2828 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2829 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2830 priv->audio_output = NULL;
2838 empathy_call_window_update_timer (gpointer user_data)
2840 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2841 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2842 const gchar *status;
2846 time_ = g_timer_elapsed (priv->timer, NULL);
2848 if (priv->call_state == HELD)
2849 status = _("On hold");
2850 else if (!gtk_toggle_button_get_active (
2851 GTK_TOGGLE_BUTTON (priv->mic_button)))
2854 status = _("Duration");
2856 /* Translators: 'status - minutes:seconds' the caller has been connected */
2857 str = g_strdup_printf (_("%s — %d:%02dm"),
2859 (int) time_ / 60, (int) time_ % 60);
2860 empathy_call_window_status_message (self, str);
2868 EMP_RESPONSE_BALANCE
2872 on_error_infobar_response_cb (GtkInfoBar *info_bar,
2876 switch (response_id)
2878 case GTK_RESPONSE_CLOSE:
2879 gtk_widget_destroy (GTK_WIDGET (info_bar));
2881 case EMP_RESPONSE_BALANCE:
2882 empathy_url_show (GTK_WIDGET (info_bar),
2883 g_object_get_data (G_OBJECT (info_bar), "uri"));
2889 display_error (EmpathyCallWindow *self,
2893 const gchar *details,
2894 const gchar *button_text,
2896 gint button_response)
2898 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2899 GtkWidget *info_bar;
2900 GtkWidget *content_area;
2907 /* Create info bar */
2908 info_bar = gtk_info_bar_new ();
2910 if (button_text != NULL)
2912 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
2913 button_text, button_response);
2914 g_object_set_data_full (G_OBJECT (info_bar),
2915 "uri", g_strdup (uri), g_free);
2918 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
2919 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
2921 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2923 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2925 /* hbox containing the image and the messages vbox */
2926 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
2927 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2930 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2931 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
2933 /* vbox containing the main message and the details expander */
2934 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
2935 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
2938 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
2940 label = gtk_label_new (NULL);
2941 gtk_label_set_markup (GTK_LABEL (label), txt);
2942 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2943 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2946 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
2949 if (details != NULL)
2951 GtkWidget *expander;
2953 expander = gtk_expander_new (_("Technical Details"));
2955 txt = g_strdup_printf ("<i>%s</i>", details);
2957 label = gtk_label_new (NULL);
2958 gtk_label_set_markup (GTK_LABEL (label), txt);
2959 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2960 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
2963 gtk_container_add (GTK_CONTAINER (expander), label);
2964 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
2967 g_signal_connect (info_bar, "response",
2968 G_CALLBACK (on_error_infobar_response_cb), NULL);
2970 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
2971 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
2972 gtk_widget_show_all (info_bar);
2977 media_stream_error_to_txt (EmpathyCallWindow *self,
2978 TpCallChannel *call,
2980 TpMediaStreamError error)
2982 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2983 const gchar *cm = NULL;
2989 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
2991 return g_strdup_printf (
2992 _("%s's software does not understand any of the audio formats "
2993 "supported by your computer"),
2994 empathy_contact_get_alias (priv->contact));
2996 return g_strdup_printf (
2997 _("%s's software does not understand any of the video formats "
2998 "supported by your computer"),
2999 empathy_contact_get_alias (priv->contact));
3001 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
3002 return g_strdup_printf (
3003 _("Can't establish a connection to %s. "
3004 "One of you might be on a network that does not allow "
3005 "direct connections."),
3006 empathy_contact_get_alias (priv->contact));
3008 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
3009 return g_strdup (_("There was a failure on the network"));
3011 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
3013 return g_strdup (_("The audio formats necessary for this call "
3014 "are not installed on your computer"));
3016 return g_strdup (_("The video formats necessary for this call "
3017 "are not installed on your computer"));
3019 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
3020 tp_connection_parse_object_path (
3021 tp_channel_borrow_connection (TP_CHANNEL (call)),
3024 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
3025 "product=Telepathy&component=%s", cm);
3027 result = g_strdup_printf (
3028 _("Something unexpected happened in a Telepathy component. "
3029 "Please <a href=\"%s\">report this bug</a> and attach "
3030 "logs gathered from the 'Debug' window in the Help menu."), url);
3036 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
3037 return g_strdup (_("There was a failure in the call engine"));
3039 case TP_MEDIA_STREAM_ERROR_EOS:
3040 return g_strdup (_("The end of the stream was reached"));
3042 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
3049 empathy_call_window_stream_error (EmpathyCallWindow *self,
3050 TpCallChannel *call,
3059 desc = media_stream_error_to_txt (self, call, audio, code);
3062 /* No description, use the error message. That's not great as it's not
3063 * localized but it's better than nothing. */
3064 display_error (self, call, icon, title, msg, NULL);
3068 display_error (self, call, icon, title, desc, msg);
3074 empathy_call_window_audio_stream_error (TpCallChannel *call,
3077 EmpathyCallWindow *self)
3079 empathy_call_window_stream_error (self, call, TRUE, code, msg,
3080 "gnome-stock-mic", _("Can't establish audio stream"));
3084 empathy_call_window_video_stream_error (TpCallChannel *call,
3087 EmpathyCallWindow *self)
3089 empathy_call_window_stream_error (self, call, FALSE, code, msg,
3090 "camera-web", _("Can't establish video stream"));
3095 show_balance_error (EmpathyCallWindow *self)
3099 gchar *balance, *tmp;
3100 const gchar *uri, *currency;
3104 g_object_get (self->priv->handler,
3105 "call-channel", &call,
3108 conn = tp_channel_borrow_connection (call);
3109 g_object_unref (call);
3111 uri = tp_connection_get_balance_uri (conn);
3113 if (!tp_connection_get_balance (conn, &amount, &scale, ¤cy))
3115 /* unknown balance */
3116 balance = g_strdup ("(--)");
3120 char *money = empathy_format_currency (amount, scale, currency);
3122 balance = g_strdup_printf ("%s %s",
3127 tmp = g_strdup_printf (_("Your current balance is %s."), balance),
3129 display_error (self,
3131 _("Sorry, you don’t have enough credit for that call."),
3135 EMP_RESPONSE_BALANCE);
3142 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
3145 EmpathyCallWindow *self)
3147 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3148 TpCallChannel *call;
3149 gboolean can_send_video;
3151 if (state == TP_CALL_STATE_ENDED)
3153 DEBUG ("Call ended: %s", (reason != NULL && reason[0] != '\0') ? reason : "unspecified reason");
3154 empathy_call_window_disconnected (self, TRUE);
3155 if (!tp_strdiff (reason, TP_ERROR_STR_INSUFFICIENT_BALANCE))
3156 show_balance_error (self);
3160 if (state != TP_CALL_STATE_ACCEPTED)
3163 if (priv->call_state == CONNECTED)
3166 g_timer_start (priv->timer);
3167 priv->call_state = CONNECTED;
3169 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3171 can_send_video = priv->video_input != NULL &&
3172 empathy_contact_can_voip_video (priv->contact) &&
3173 empathy_camera_monitor_get_available (priv->camera_monitor);
3175 g_object_get (priv->handler, "call-channel", &call, NULL);
3177 if (tp_call_channel_has_dtmf (call))
3178 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
3180 if (priv->video_input == NULL)
3181 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
3183 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
3185 empathy_call_window_show_hangup_button (self, TRUE);
3187 gtk_widget_set_sensitive (priv->mic_button, TRUE);
3189 clutter_actor_hide (priv->video_output);
3190 gtk_widget_show (priv->remote_user_avatar_widget);
3192 g_object_unref (call);
3194 g_mutex_lock (&priv->lock);
3196 priv->timer_id = g_timeout_add_seconds (1,
3197 empathy_call_window_update_timer, self);
3199 g_mutex_unlock (&priv->lock);
3201 empathy_call_window_update_timer (self);
3203 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
3207 empathy_call_window_show_video_output_cb (gpointer user_data)
3209 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3211 if (self->priv->video_output != NULL)
3213 gtk_widget_hide (self->priv->remote_user_avatar_widget);
3214 clutter_actor_show (self->priv->video_output);
3215 clutter_actor_raise_top (self->priv->overlay_bin);
3222 empathy_call_window_check_video_cb (gpointer data)
3224 EmpathyCallWindow *self = data;
3226 if (self->priv->got_video)
3228 self->priv->got_video = FALSE;
3232 /* No video in the last N seconds, display the remote avatar */
3233 empathy_call_window_show_video_output (self, FALSE);
3238 /* Called from the streaming thread */
3240 empathy_call_window_video_probe_cb (GstPad *pad,
3241 GstMiniObject *mini_obj,
3242 EmpathyCallWindow *self)
3245 if (GST_IS_EVENT (mini_obj))
3248 if (G_UNLIKELY (!self->priv->got_video))
3250 /* show the remote video */
3251 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3252 empathy_call_window_show_video_output_cb,
3253 g_object_ref (self), g_object_unref);
3255 self->priv->got_video = TRUE;
3261 /* Called from the streaming thread */
3263 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
3264 TfContent *content, GstPad *src, gpointer user_data)
3266 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3267 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3268 gboolean retval = FALSE;
3273 g_mutex_lock (&priv->lock);
3275 g_object_get (content, "media-type", &media_type, NULL);
3279 case TP_MEDIA_STREAM_TYPE_AUDIO:
3280 pad = empathy_call_window_get_audio_sink_pad (self, content);
3282 case TP_MEDIA_STREAM_TYPE_VIDEO:
3283 g_idle_add (empathy_call_window_show_video_output_cb, self);
3284 pad = empathy_call_window_get_video_sink_pad (self);
3286 gst_pad_add_data_probe (src,
3287 G_CALLBACK (empathy_call_window_video_probe_cb), self);
3288 if (priv->got_video_src > 0)
3289 g_source_remove (priv->got_video_src);
3290 priv->got_video_src = g_timeout_add_seconds (1,
3291 empathy_call_window_check_video_cb, self);
3294 g_assert_not_reached ();
3300 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
3301 g_warning ("Could not link %s sink pad",
3302 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
3306 gst_object_unref (pad);
3310 /* If no sink could be linked, try to add fakesink to prevent the whole call
3315 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
3317 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
3319 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
3320 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
3321 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
3323 gst_element_set_locked_state (fakesink, TRUE);
3324 gst_element_set_state (fakesink, GST_STATE_NULL);
3325 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
3329 DEBUG ("Could not link real sink, linked fakesink instead");
3331 gst_object_unref (sinkpad);
3335 gst_object_unref (fakesink);
3340 g_mutex_unlock (&priv->lock);
3346 empathy_call_window_prepare_audio_output (EmpathyCallWindow *self,
3349 EmpathyCallWindowPriv *priv = self->priv;
3351 g_assert (priv->audio_output_added == FALSE);
3352 g_assert (priv->audio_output == FALSE);
3354 priv->audio_output = empathy_audio_sink_new ();
3355 g_object_ref_sink (priv->audio_output);
3357 /* volume button to output volume linking */
3358 g_object_bind_property (priv->audio_output, "volume",
3359 priv->volume_button, "value",
3360 G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
3362 g_object_bind_property_full (content, "requested-output-volume",
3363 priv->audio_output, "volume",
3365 audio_control_volume_to_element,
3366 element_volume_to_audio_control,
3369 /* Link volumes together, sync the current audio input volume property
3370 * back to farstream first */
3371 g_object_bind_property_full (priv->audio_output, "volume",
3372 content, "reported-output-volume",
3373 G_BINDING_SYNC_CREATE,
3374 element_volume_to_audio_control,
3375 audio_control_volume_to_element,
3378 /* For raw audio conferences assume that the producer of the raw data
3379 * has already processed it, so turn off any echo cancellation and any
3380 * other audio improvements that come with it */
3381 empathy_audio_sink_set_echo_cancel (
3382 EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3383 !empathy_call_window_content_is_raw (content));
3388 empathy_call_window_content_added_cb (EmpathyCallHandler *handler,
3389 TfContent *content, gpointer user_data)
3391 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3392 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3394 FsMediaType media_type;
3395 gboolean retval = FALSE;
3397 g_object_get (content, "media-type", &media_type, "sink-pad", &sink, NULL);
3398 g_assert (sink != NULL);
3402 case FS_MEDIA_TYPE_AUDIO:
3404 /* For raw audio conferences assume that the receiver of the raw data
3405 * wants it unprocessed, so turn off any echo cancellation and any
3406 * other audio improvements that come with it */
3407 empathy_audio_src_set_echo_cancel (
3408 EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3409 !empathy_call_window_content_is_raw (content));
3411 /* Link volumes together, sync the current audio input volume property
3412 * back to farstream first */
3413 g_object_bind_property_full (content, "requested-input-volume",
3414 priv->audio_input, "volume",
3416 audio_control_volume_to_element,
3417 element_volume_to_audio_control,
3420 g_object_bind_property_full (priv->audio_input, "volume",
3421 content, "reported-input-volume",
3422 G_BINDING_SYNC_CREATE,
3423 element_volume_to_audio_control,
3424 audio_control_volume_to_element,
3427 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
3429 g_warning ("Could not add audio source to pipeline");
3433 pad = gst_element_get_static_pad (priv->audio_input, "src");
3436 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3437 g_warning ("Could not get source pad from audio source");
3441 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3443 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3444 gst_object_unref (pad);
3445 g_warning ("Could not link audio source to farsight");
3448 gst_object_unref (pad);
3450 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3452 g_warning ("Could not start audio source");
3453 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3454 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3458 /* Prepare our audio output, not added yet though */
3459 empathy_call_window_prepare_audio_output (self, content);
3463 case FS_MEDIA_TYPE_VIDEO:
3464 if (priv->video_tee != NULL)
3466 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3467 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3469 g_warning ("Could not link video source input pipeline");
3472 gst_object_unref (pad);
3478 g_assert_not_reached ();
3481 gst_object_unref (sink);
3486 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3488 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3489 GstElement *preview;
3491 disable_camera (self);
3493 DEBUG ("remove video input");
3494 preview = priv->video_preview_sink;
3496 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3497 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3498 gst_element_set_state (preview, GST_STATE_NULL);
3500 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3503 g_object_unref (priv->video_input);
3504 priv->video_input = NULL;
3505 g_object_unref (priv->video_tee);
3506 priv->video_tee = NULL;
3507 clutter_actor_destroy (priv->video_preview);
3508 priv->video_preview = NULL;
3510 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3514 start_call (EmpathyCallWindow *self)
3516 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3518 priv->call_started = TRUE;
3519 empathy_call_handler_start_call (priv->handler,
3520 gtk_get_current_event_time ());
3522 if (empathy_call_handler_has_initial_video (priv->handler))
3524 TpCallChannel *call;
3527 g_object_get (priv->handler, "call-channel", &call, NULL);
3528 /* If the call channel isn't set yet we're requesting it, if we're
3529 * requesting it with initial video it should be PENDING_SEND when we get
3532 s = TP_SENDING_STATE_PENDING_SEND;
3534 s = empathy_call_channel_get_video_state (call);
3536 if (s == TP_SENDING_STATE_PENDING_SEND ||
3537 s == TP_SENDING_STATE_SENDING)
3539 /* Enable 'send video' buttons and display the preview */
3540 gtk_toggle_button_set_active (
3541 GTK_TOGGLE_BUTTON (priv->camera_button), TRUE);
3545 gtk_toggle_button_set_active (
3546 GTK_TOGGLE_BUTTON (priv->camera_button), FALSE);
3548 if (priv->video_preview == NULL)
3550 create_video_preview (self);
3551 add_video_preview_to_pipeline (self);
3556 g_object_unref (call);
3561 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3564 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3565 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3566 GstState newstate, pending;
3568 empathy_call_handler_bus_message (priv->handler, bus, message);
3570 switch (GST_MESSAGE_TYPE (message))
3572 case GST_MESSAGE_STATE_CHANGED:
3573 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3575 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3577 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3578 !priv->call_started)
3580 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3581 if (newstate == GST_STATE_PAUSED)
3583 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3584 priv->pipeline_playing = TRUE;
3586 if (priv->start_call_when_playing)
3590 if (priv->video_preview_sink != NULL &&
3591 GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_preview_sink))
3593 gst_message_parse_state_changed (message, NULL, &newstate,
3596 if (newstate == GST_STATE_PLAYING &&
3597 pending == GST_STATE_VOID_PENDING)
3598 empathy_call_window_stop_camera_spinning (self);
3601 case GST_MESSAGE_ERROR:
3603 GError *error = NULL;
3604 GstElement *gst_error;
3608 gst_message_parse_error (message, &error, &debug);
3609 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3611 g_message ("Element error: %s -- %s\n", error->message, debug);
3613 name = gst_element_get_name (gst_error);
3614 if (g_str_has_prefix (name, VIDEO_INPUT_ERROR_PREFIX))
3616 /* Remove the video input and continue */
3617 if (priv->video_input != NULL)
3618 empathy_call_window_remove_video_input (self);
3619 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3623 empathy_call_window_disconnected (self, TRUE);
3626 g_error_free (error);
3629 case GST_MESSAGE_UNKNOWN:
3630 case GST_MESSAGE_EOS:
3631 case GST_MESSAGE_WARNING:
3632 case GST_MESSAGE_INFO:
3633 case GST_MESSAGE_TAG:
3634 case GST_MESSAGE_BUFFERING:
3635 case GST_MESSAGE_STATE_DIRTY:
3636 case GST_MESSAGE_STEP_DONE:
3637 case GST_MESSAGE_CLOCK_PROVIDE:
3638 case GST_MESSAGE_CLOCK_LOST:
3639 case GST_MESSAGE_NEW_CLOCK:
3640 case GST_MESSAGE_STRUCTURE_CHANGE:
3641 case GST_MESSAGE_STREAM_STATUS:
3642 case GST_MESSAGE_APPLICATION:
3643 case GST_MESSAGE_ELEMENT:
3644 case GST_MESSAGE_SEGMENT_START:
3645 case GST_MESSAGE_SEGMENT_DONE:
3646 case GST_MESSAGE_DURATION:
3647 case GST_MESSAGE_ANY:
3656 empathy_call_window_members_changed_cb (TpCallChannel *call,
3657 GHashTable *updates,
3659 TpCallStateReason *reason,
3660 EmpathyCallWindow *self)
3662 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3663 GHashTableIter iter;
3664 gpointer key, value;
3665 gboolean held = FALSE;
3667 g_hash_table_iter_init (&iter, updates);
3668 while (g_hash_table_iter_next (&iter, &key, &value))
3670 if (GPOINTER_TO_INT (value) & TP_CALL_MEMBER_FLAG_HELD)
3672 /* This assumes this is a 1-1 call, otherwise one participant
3673 * putting the call on hold wouldn't mean the call is on hold
3681 priv->call_state = HELD;
3682 else if (priv->call_state == HELD)
3683 priv->call_state = CONNECTED;
3687 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3689 EmpathyCallWindow *self)
3691 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3692 TpCallChannel *call;
3694 g_object_get (priv->handler, "call-channel", &call, NULL);
3699 tp_g_signal_connect_object (call, "audio-stream-error",
3700 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3701 tp_g_signal_connect_object (call, "video-stream-error",
3702 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3705 tp_g_signal_connect_object (call, "members-changed",
3706 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3708 g_object_unref (call);
3712 empathy_call_window_connect_handler (EmpathyCallWindow *self)
3714 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3715 TpCallChannel *call;
3717 g_signal_connect (priv->handler, "state-changed",
3718 G_CALLBACK (empathy_call_window_state_changed_cb), self);
3719 g_signal_connect (priv->handler, "conference-added",
3720 G_CALLBACK (empathy_call_window_conference_added_cb), self);
3721 g_signal_connect (priv->handler, "conference-removed",
3722 G_CALLBACK (empathy_call_window_conference_removed_cb), self);
3723 g_signal_connect (priv->handler, "closed",
3724 G_CALLBACK (empathy_call_window_channel_closed_cb), self);
3725 g_signal_connect (priv->handler, "src-pad-added",
3726 G_CALLBACK (empathy_call_window_src_added_cb), self);
3727 g_signal_connect (priv->handler, "content-added",
3728 G_CALLBACK (empathy_call_window_content_added_cb), self);
3729 g_signal_connect (priv->handler, "content-removed",
3730 G_CALLBACK (empathy_call_window_content_removed_cb), self);
3732 /* We connect to ::call-channel unconditionally since we'll
3733 * get new channels if we hangup and redial or if we reuse the
3735 g_signal_connect (priv->handler, "notify::call-channel",
3736 G_CALLBACK (call_handler_notify_call_cb), self);
3738 g_signal_connect (priv->handler, "framerate-changed",
3739 G_CALLBACK (empathy_call_window_framerate_changed_cb), self);
3740 g_signal_connect (priv->handler, "resolution-changed",
3741 G_CALLBACK (empathy_call_window_resolution_changed_cb), self);
3743 g_object_get (priv->handler, "call-channel", &call, NULL);
3746 /* We won't get notify::call-channel for this channel, so
3747 * directly call the callback. */
3748 call_handler_notify_call_cb (priv->handler, NULL, self);
3749 g_object_unref (call);
3754 empathy_call_window_realized_cb (GtkWidget *widget,
3755 EmpathyCallWindow *self)
3759 /* Make the hangup button twice as wide */
3760 width = gtk_widget_get_allocated_width (self->priv->hangup_button);
3761 gtk_widget_set_size_request (self->priv->hangup_button, width * 2, -1);
3763 empathy_call_window_connect_handler (self);
3765 gst_element_set_state (self->priv->pipeline, GST_STATE_PAUSED);
3769 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3770 EmpathyCallWindow *window)
3772 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3774 if (priv->pipeline != NULL)
3776 if (priv->bus_message_source_id != 0)
3778 g_source_remove (priv->bus_message_source_id);
3779 priv->bus_message_source_id = 0;
3782 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3785 if (priv->call_state == CONNECTING)
3786 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3792 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3795 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3797 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3802 gtk_widget_hide (priv->dtmf_panel);
3803 gtk_widget_hide (menu);
3804 gtk_widget_hide (priv->toolbar);
3808 if (priv->dialpad_was_visible_before_fs)
3809 gtk_widget_show (priv->dtmf_panel);
3811 gtk_widget_show (menu);
3812 gtk_widget_show (priv->toolbar);
3814 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3815 priv->original_height_before_fs);
3820 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3822 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3824 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3825 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3827 if (priv->video_output != NULL)
3830 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3831 priv->video_output, TRUE, TRUE,
3832 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3839 empathy_call_window_state_event_cb (GtkWidget *widget,
3840 GdkEventWindowState *event, EmpathyCallWindow *window)
3842 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3844 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3845 gboolean set_fullscreen = event->new_window_state &
3846 GDK_WINDOW_STATE_FULLSCREEN;
3850 gboolean dialpad_was_visible;
3851 GtkAllocation allocation;
3852 gint original_width, original_height;
3854 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3855 original_width = allocation.width;
3856 original_height = allocation.height;
3858 g_object_get (priv->dtmf_panel,
3859 "visible", &dialpad_was_visible,
3862 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3863 priv->original_width_before_fs = original_width;
3864 priv->original_height_before_fs = original_height;
3866 if (priv->video_output_motion_handler_id == 0 &&
3867 priv->video_output != NULL)
3869 priv->video_output_motion_handler_id = g_signal_connect (
3870 G_OBJECT (priv->video_container), "motion-notify-event",
3871 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3877 disconnect_video_output_motion_handler (window);
3880 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3882 show_controls (window, set_fullscreen);
3883 show_borders (window, set_fullscreen);
3884 gtk_action_set_stock_id (priv->menu_fullscreen,
3885 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3886 priv->is_fullscreen = set_fullscreen;
3893 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3896 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3897 int w, h, dialpad_width;
3898 GtkAllocation allocation;
3900 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3901 w = allocation.width;
3902 h = allocation.height;
3904 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3908 gtk_widget_show (priv->dtmf_panel);
3914 gtk_widget_hide (priv->dtmf_panel);
3918 gtk_window_resize (GTK_WINDOW (window), w, h);
3922 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3925 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3926 TpCallChannel *call;
3928 priv->sending_video = (state == CAMERA_STATE_ON);
3930 if (state == CAMERA_STATE_ON)
3932 /* When we start sending video, we want to show the video preview by
3934 display_video_preview (window, TRUE);
3938 display_video_preview (window, FALSE);
3941 if (priv->call_state != CONNECTED)
3944 g_object_get (priv->handler, "call-channel", &call, NULL);
3945 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
3946 empathy_call_channel_send_video (call, priv->sending_video);
3947 g_object_unref (call);
3951 empathy_call_window_hangup_cb (gpointer object,
3952 EmpathyCallWindow *self)
3954 /* stopping the call will put it the ENDED state and
3955 * from state_changed_cb we'll reconfigure the window
3957 empathy_call_handler_stop_call (self->priv->handler);
3961 empathy_call_window_restart_call (EmpathyCallWindow *window)
3963 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3965 /* Remove error info bars */
3966 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
3967 (GtkCallback) gtk_widget_destroy, NULL);
3969 create_video_output_widget (window);
3970 priv->outgoing = TRUE;
3971 empathy_call_window_set_state_connecting (window);
3973 if (priv->pipeline_playing)
3974 start_call (window);
3976 /* call will be started when the pipeline is ready */
3977 priv->start_call_when_playing = TRUE;
3979 empathy_call_window_setup_avatars (window, priv->handler);
3981 empathy_call_window_show_hangup_button (window, TRUE);
3985 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
3986 EmpathyCallWindow *window)
3990 active = gtk_toggle_tool_button_get_active (button);
3992 empathy_call_window_show_dialpad (window, active);
3996 empathy_call_window_fullscreen_cb (gpointer object,
3997 EmpathyCallWindow *window)
3999 empathy_call_window_fullscreen_toggle (window);
4003 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
4005 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4007 if (priv->is_fullscreen)
4008 gtk_window_unfullscreen (GTK_WINDOW (window));
4010 gtk_window_fullscreen (GTK_WINDOW (window));
4014 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
4015 GdkEventButton *event, EmpathyCallWindow *window)
4017 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
4019 empathy_call_window_video_menu_popup (window, event->button);
4027 empathy_call_window_key_press_cb (GtkWidget *video_output,
4028 GdkEventKey *event, EmpathyCallWindow *window)
4030 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4032 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
4034 /* Since we are in fullscreen mode, toggling will bring us back to
4036 empathy_call_window_fullscreen_toggle (window);
4044 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
4045 GdkEventMotion *event, EmpathyCallWindow *window)
4047 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4049 if (priv->is_fullscreen)
4051 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
4053 /* Show the bottom toolbar */
4054 empathy_call_window_motion_notify_cb (NULL, NULL, window);
4061 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
4065 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4067 menu = gtk_ui_manager_get_widget (priv->ui_manager,
4069 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
4070 button, gtk_get_current_event_time ());
4071 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
4075 empathy_call_window_status_message (EmpathyCallWindow *self,
4078 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
4082 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
4084 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4086 return priv->ui_manager;
4089 EmpathyGstAudioSrc *
4090 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
4092 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4094 return (EmpathyGstAudioSrc *) priv->audio_input;
4097 EmpathyGstVideoSrc *
4098 empathy_call_window_get_video_src (EmpathyCallWindow *self)
4100 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);
4104 empathy_call_window_change_webcam (EmpathyCallWindow *self,
4105 const gchar *device)
4107 EmpathyGstVideoSrc *video;
4110 /* Restart the camera only if it's already running */
4111 running = (self->priv->video_preview != NULL);
4112 video = empathy_call_window_get_video_src (self);
4115 empathy_call_window_play_camera (self, FALSE);
4117 empathy_video_src_change_device (video, device);
4120 empathy_call_window_play_camera (self, TRUE);