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
22 #include "empathy-call-window.h"
24 #include <glib/gi18n.h>
25 #include <telepathy-farstream/telepathy-farstream.h>
26 #include <farstream/fs-element-added-notifier.h>
27 #include <farstream/fs-utils.h>
28 #include <tp-account-widgets/tpaw-builder.h>
29 #include <tp-account-widgets/tpaw-camera-monitor.h>
30 #include <tp-account-widgets/tpaw-images.h>
31 #include <tp-account-widgets/tpaw-pixbuf-utils.h>
32 #include <tp-account-widgets/tpaw-utils.h>
33 #include <telepathy-glib/telepathy-glib-dbus.h>
35 #include "empathy-about-dialog.h"
36 #include "empathy-audio-sink.h"
37 #include "empathy-call-utils.h"
38 #include "empathy-call-window-fullscreen.h"
39 #include "empathy-camera-menu.h"
40 #include "empathy-dialpad-widget.h"
41 #include "empathy-geometry.h"
42 #include "empathy-gsettings.h"
43 #include "empathy-images.h"
44 #include "empathy-mic-menu.h"
45 #include "empathy-preferences.h"
46 #include "empathy-request-util.h"
47 #include "empathy-rounded-actor.h"
48 #include "empathy-rounded-rectangle.h"
49 #include "empathy-rounded-texture.h"
50 #include "empathy-sound-manager.h"
51 #include "empathy-ui-utils.h"
52 #include "empathy-utils.h"
54 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
55 #include "empathy-debug.h"
57 #define CONTENT_HBOX_SPACING 3
58 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 0
59 #define OVERLAY_MARGIN 6
61 #define REMOTE_VIDEO_DEFAULT_WIDTH 320
62 #define REMOTE_VIDEO_DEFAULT_HEIGHT 240
64 #define SELF_VIDEO_SECTION_WIDTH 120
65 #define SELF_VIDEO_SECTION_HEIGHT 90
66 #define SELF_VIDEO_SECTION_MARGIN 2
67 #define SELF_VIDEO_SECTION_BORDER SELF_VIDEO_SECTION_MARGIN*2
69 /* The avatar's default width and height are set to the same value because we
70 want a square icon. */
71 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT REMOTE_VIDEO_DEFAULT_HEIGHT
72 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH REMOTE_VIDEO_DEFAULT_HEIGHT
74 #define SMALL_TOOLBAR_SIZE 36
76 /* If an video input error occurs, the error message will start with "v4l" */
77 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
79 /* The time interval in milliseconds between 2 outgoing rings */
80 #define MS_BETWEEN_RING 500
82 /* The roundedness of preview box and placeholders */
83 #define PREVIEW_ROUND_FACTOR 16
85 #define PREVIEW_BUTTON_OPACITY 180
87 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
90 PROP_CALL_HANDLER = 1,
98 static guint signals[LAST_SIGNAL];
101 RINGING, /* Incoming call */
102 CONNECTING, /* Outgoing call */
103 CONNECTED, /* Connected */
104 HELD, /* Connected, but on hold */
105 DISCONNECTED, /* Disconnected */
106 REDIALING /* Redialing (special case of CONNECTING) */
110 CAMERA_STATE_OFF = 0,
116 PREVIEW_POS_TOP_LEFT,
117 PREVIEW_POS_TOP_RIGHT,
118 PREVIEW_POS_BOTTOM_LEFT,
119 PREVIEW_POS_BOTTOM_RIGHT,
122 struct _EmpathyCallWindowPriv
124 gboolean dispose_has_run;
125 EmpathyCallHandler *handler;
127 EmpathyContact *contact;
129 TpawCameraMonitor *camera_monitor;
131 CallState call_state;
134 GtkUIManager *ui_manager;
135 GtkWidget *errors_vbox;
136 /* widget displays the video received from the remote user. This widget is
137 * alive only during call. */
138 ClutterActor *video_output;
139 ClutterActor *video_preview;
140 ClutterActor *drag_preview;
141 ClutterActor *preview_shown_button;
142 ClutterActor *preview_hidden_button;
143 ClutterActor *preview_rectangle1;
144 ClutterActor *preview_rectangle2;
145 ClutterActor *preview_rectangle3;
146 ClutterActor *preview_rectangle4;
147 ClutterActor *preview_spinner_actor;
148 GtkWidget *preview_spinner_widget;
149 GtkWidget *video_container;
150 GtkWidget *remote_user_avatar_widget;
151 GtkWidget *remote_user_avatar_toolbar;
152 GtkWidget *remote_user_name_toolbar;
153 GtkWidget *remote_user_status_toolbar;
154 GtkWidget *status_label;
155 GtkWidget *hangup_button;
156 GtkWidget *audio_call_button;
157 GtkWidget *video_call_button;
158 GtkWidget *mic_button;
159 GtkWidget *microphone_icon;
160 GtkWidget *volume_button;
161 GtkWidget *camera_button;
162 GtkWidget *dialpad_button;
164 GtkWidget *bottom_toolbar;
165 ClutterActor *floating_toolbar;
167 GtkAction *menu_fullscreen;
168 GtkAction *menu_swap_camera;
170 ClutterState *transitions;
172 /* The main box covering all the stage, contaning remote avatar/video */
173 ClutterActor *video_box;
174 ClutterLayoutManager *video_layout;
176 /* A bin layout manager containing a bin for previews
177 * and the floating toolbar */
178 ClutterActor *overlay_bin;
179 ClutterLayoutManager *overlay_layout;
181 /* Bin layout for the previews */
182 ClutterActor *preview_box;
183 ClutterLayoutManager *preview_layout;
185 /* Coordinates of the preview drag event's start. */
186 PreviewPosition preview_pos;
188 /* We keep a reference on the hbox which contains the main content so we can
189 easilly repack everything when toggling fullscreen */
190 GtkWidget *content_hbox;
192 /* These are used to accept or reject an incoming call when the status
194 GtkWidget *incoming_call_dialog;
195 TpCallChannel *pending_channel;
196 TpChannelDispatchOperation *pending_cdo;
197 TpAddDispatchOperationContext *pending_context;
199 gulong video_output_motion_handler_id;
200 guint bus_message_source_id;
202 GtkWidget *dtmf_panel;
205 GtkWidget *details_vbox;
206 GtkWidget *vcodec_encoding_label;
207 GtkWidget *acodec_encoding_label;
208 GtkWidget *vcodec_decoding_label;
209 GtkWidget *acodec_decoding_label;
211 GtkWidget *audio_remote_candidate_label;
212 GtkWidget *audio_local_candidate_label;
213 GtkWidget *video_remote_candidate_label;
214 GtkWidget *video_local_candidate_label;
215 GtkWidget *video_remote_candidate_info_img;
216 GtkWidget *video_local_candidate_info_img;
217 GtkWidget *audio_remote_candidate_info_img;
218 GtkWidget *audio_local_candidate_info_img;
220 GstElement *video_input;
221 GstElement *video_preview_sink;
222 GstElement *video_output_sink;
223 GstElement *audio_input;
224 GstElement *audio_output;
225 gboolean audio_output_added;
226 GstElement *pipeline;
227 GstElement *video_tee;
237 gboolean call_started;
238 gboolean sending_video;
239 CameraState camera_state;
241 EmpathyCallWindowFullscreen *fullscreen;
242 gboolean is_fullscreen;
247 guint inactivity_src;
249 /* Those fields represent the state of the window before it actually was in
251 gboolean dialpad_was_visible_before_fs;
252 gint original_width_before_fs;
253 gint original_height_before_fs;
255 gint x, y, w, h, dialpad_width;
258 /* TRUE if the call should be started when the pipeline is playing */
259 gboolean start_call_when_playing;
260 /* TRUE if we requested to set the pipeline in the playing state */
261 gboolean pipeline_playing;
263 EmpathySoundManager *sound_mgr;
266 EmpathyMicMenu *mic_menu;
267 EmpathyCameraMenu *camera_menu;
272 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
274 static void empathy_call_window_realized_cb (GtkWidget *widget,
275 EmpathyCallWindow *window);
277 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
278 GdkEvent *event, EmpathyCallWindow *window);
280 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
281 GdkEventWindowState *event, EmpathyCallWindow *window);
283 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
286 static void empathy_call_window_hangup_cb (gpointer object,
287 EmpathyCallWindow *window);
289 static void empathy_call_window_fullscreen_cb (gpointer object,
290 EmpathyCallWindow *window);
292 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
294 static gboolean empathy_call_window_video_button_press_cb (
295 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
297 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
298 GdkEventKey *event, EmpathyCallWindow *window);
300 static gboolean empathy_call_window_video_output_motion_notify (
301 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
303 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
306 static void empathy_call_window_connect_handler (EmpathyCallWindow *self);
308 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
309 EmpathyCallWindow *window);
311 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
313 static void empathy_call_window_status_message (EmpathyCallWindow *window,
316 static gboolean empathy_call_window_bus_message (GstBus *bus,
317 GstMessage *message, gpointer user_data);
319 static gboolean empathy_call_window_update_timer (gpointer user_data);
322 make_background_transparent (GtkClutterActor *actor)
324 GdkRGBA transparent = { 0., 0., 0., 0. };
327 widget = gtk_clutter_actor_get_widget (actor);
328 gtk_widget_override_background_color (widget, GTK_STATE_FLAG_NORMAL, &transparent);
332 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
335 gtk_widget_set_visible (self->priv->hangup_button, show);
336 gtk_widget_set_visible (self->priv->audio_call_button, !show);
337 gtk_widget_set_visible (self->priv->video_call_button, !show);
341 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
342 EmpathyCallWindow *self)
344 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
345 empathy_call_window_restart_call (self);
349 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
350 EmpathyCallWindow *self)
352 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
353 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
354 empathy_call_window_restart_call (self);
358 dtmf_start_tone_cb (EmpathyDialpadWidget *dialpad,
360 EmpathyCallWindow *self)
365 g_object_get (self->priv->handler, "call-channel", &call, NULL);
367 tones[0] = tp_dtmf_event_to_char (event);
369 tp_call_channel_send_tones_async (call, tones, NULL, NULL, NULL);
371 g_object_unref (call);
375 empathy_call_window_show_video_output (EmpathyCallWindow *self,
378 if (self->priv->video_output != NULL)
379 g_object_set (self->priv->video_output, "visible", show, NULL);
381 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
383 clutter_actor_raise_top (self->priv->overlay_bin);
387 create_video_output_widget (EmpathyCallWindow *self)
389 EmpathyCallWindowPriv *priv = GET_PRIV (self);
391 g_assert (priv->video_output == NULL);
392 g_assert (priv->pipeline != NULL);
394 priv->video_output = clutter_texture_new ();
396 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
399 priv->video_output_sink = gst_element_factory_make ("cluttersink", NULL);
400 if (priv->video_output_sink == NULL)
401 g_error ("Missing cluttersink");
403 g_object_set (priv->video_output_sink, "texture", priv->video_output, NULL);
405 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
408 gtk_widget_add_events (priv->video_container,
409 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
410 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
411 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
415 create_video_input (EmpathyCallWindow *self)
417 EmpathyCallWindowPriv *priv = GET_PRIV (self);
419 g_assert (priv->video_input == NULL);
420 priv->video_input = empathy_video_src_new ();
421 gst_object_ref_sink (priv->video_input);
425 audio_control_volume_to_element (GBinding *binding,
426 const GValue *source_value,
427 GValue *target_value,
430 /* AudioControl volume is 0-255, with -1 for unknown */
433 hv = g_value_get_int (source_value);
438 g_value_set_double (target_value, hv/255.0);
444 element_volume_to_audio_control (GBinding *binding,
445 const GValue *source_value,
446 GValue *target_value,
451 ev = g_value_get_double (source_value);
452 ev = CLAMP (ev, 0.0, 1.0);
454 g_value_set_int (target_value, ev * 255);
459 audio_input_mute_notify_cb (GObject *obj, GParamSpec *spec,
460 EmpathyCallWindow *self)
463 g_object_get (obj, "mute", &muted, NULL);
465 self->priv->muted = muted;
466 if (muted && self->priv->transitions)
467 clutter_state_set_state (self->priv->transitions, "fade-in");
471 gtk_image_set_from_icon_name (GTK_IMAGE (self->priv->microphone_icon),
472 EMPATHY_IMAGE_MIC_MUTED, GTK_ICON_SIZE_MENU);
476 gtk_image_set_from_icon_name (GTK_IMAGE (self->priv->microphone_icon),
477 EMPATHY_IMAGE_MIC, GTK_ICON_SIZE_MENU);
480 empathy_call_window_update_timer (self);
484 create_audio_input (EmpathyCallWindow *self)
486 EmpathyCallWindowPriv *priv = GET_PRIV (self);
488 g_assert (priv->audio_input == NULL);
489 priv->audio_input = empathy_audio_src_new ();
490 gst_object_ref_sink (priv->audio_input);
492 g_signal_connect (priv->audio_input, "notify::mute",
493 G_CALLBACK (audio_input_mute_notify_cb), self);
497 add_video_preview_to_pipeline (EmpathyCallWindow *self)
499 EmpathyCallWindowPriv *priv = GET_PRIV (self);
502 g_assert (priv->video_preview != NULL);
503 g_assert (priv->pipeline != NULL);
504 g_assert (priv->video_input != NULL);
505 g_assert (priv->video_tee != NULL);
507 preview = priv->video_preview_sink;
509 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
511 g_warning ("Could not add video input to pipeline");
515 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
517 g_warning ("Could not add video preview to pipeline");
521 if (!gst_element_link (priv->video_input, priv->video_tee))
523 g_warning ("Could not link video input to video tee");
527 if (!gst_element_link (priv->video_tee, preview))
529 g_warning ("Could not link video tee to video preview");
535 empathy_call_window_disable_camera_cb (GtkAction *action,
536 EmpathyCallWindow *self)
538 clutter_actor_destroy (self->priv->preview_hidden_button);
540 gtk_toggle_button_set_active (
541 GTK_TOGGLE_BUTTON (self->priv->camera_button), FALSE);
545 empathy_call_window_minimise_camera_cb (GtkAction *action,
546 EmpathyCallWindow *self)
548 clutter_actor_hide (self->priv->video_preview);
549 clutter_actor_show (self->priv->preview_hidden_button);
553 empathy_call_window_maximise_camera_cb (GtkAction *action,
554 EmpathyCallWindow *self)
556 clutter_actor_show (self->priv->video_preview);
557 clutter_actor_hide (self->priv->preview_hidden_button);
561 empathy_call_window_swap_camera_cb (GtkAction *action,
562 EmpathyCallWindow *self)
564 const GList *cameras, *l;
567 DEBUG ("Swapping the camera");
569 cameras = tpaw_camera_monitor_get_cameras (self->priv->camera_monitor);
570 current_cam = empathy_video_src_dup_device (
571 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
573 for (l = cameras; l != NULL; l = l->next)
575 TpawCamera *camera = l->data;
577 if (!tp_strdiff (camera->device, current_cam))
582 next = l->next->data;
584 next = cameras->data;
586 /* EmpathyCameraMenu will update itself and do the actual change
588 g_settings_set_string (self->priv->settings,
589 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
596 g_free (current_cam);
600 empathy_call_window_update_swap_camera (EmpathyCallWindow *self)
602 const GList *cameras = tpaw_camera_monitor_get_cameras (
603 self->priv->camera_monitor);
605 gtk_action_set_visible (self->priv->menu_swap_camera,
606 g_list_length ((GList *) cameras) >= 2);
610 empathy_call_window_camera_added_cb (TpawCameraMonitor *monitor,
612 EmpathyCallWindow *self)
614 empathy_call_window_update_swap_camera (self);
618 empathy_call_window_camera_removed_cb (TpawCameraMonitor *monitor,
620 EmpathyCallWindow *self)
622 empathy_call_window_update_swap_camera (self);
626 empathy_call_window_preview_button_clicked_cb (ClutterClickAction *action,
628 EmpathyCallWindow *self)
632 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
634 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
635 0, gtk_get_current_event_time ());
636 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
640 empathy_call_window_preview_hidden_button_clicked_cb (
641 ClutterClickAction *action,
643 EmpathyCallWindow *self)
647 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
648 "/preview-hidden-menu");
649 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
650 0, gtk_get_current_event_time ());
651 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
654 static ClutterActor *
655 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
656 ClutterBinAlignment x,
657 ClutterBinAlignment y)
659 ClutterActor *rectangle;
661 rectangle = CLUTTER_ACTOR (empathy_rounded_rectangle_new (
662 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT,
663 PREVIEW_ROUND_FACTOR));
665 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->preview_layout),
667 clutter_actor_hide (rectangle);
673 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
677 self->priv->preview_layout = clutter_bin_layout_new (
678 CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_CENTER);
679 self->priv->preview_box = box = clutter_box_new (self->priv->preview_layout);
681 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->overlay_layout),
683 CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL);
685 self->priv->preview_rectangle1 =
686 empathy_call_window_create_preview_rectangle (self,
687 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
688 self->priv->preview_rectangle2 =
689 empathy_call_window_create_preview_rectangle (self,
690 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
691 self->priv->preview_rectangle3 =
692 empathy_call_window_create_preview_rectangle (self,
693 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
694 self->priv->preview_rectangle4 =
695 empathy_call_window_create_preview_rectangle (self,
696 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
700 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
703 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
704 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
705 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
706 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
710 empathy_call_window_get_preview_coordinates (EmpathyCallWindow *self,
715 guint ret_x = 0, ret_y = 0;
718 if (!clutter_actor_has_allocation (self->priv->preview_box))
721 clutter_actor_get_geometry (self->priv->preview_box, &box);
725 case PREVIEW_POS_TOP_LEFT:
726 ret_x = ret_y = SELF_VIDEO_SECTION_MARGIN;
728 case PREVIEW_POS_TOP_RIGHT:
729 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
730 - SELF_VIDEO_SECTION_WIDTH;
731 ret_y = SELF_VIDEO_SECTION_MARGIN;
733 case PREVIEW_POS_BOTTOM_LEFT:
734 ret_x = SELF_VIDEO_SECTION_MARGIN;
735 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
736 - SELF_VIDEO_SECTION_HEIGHT;
738 case PREVIEW_POS_BOTTOM_RIGHT:
739 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
740 - SELF_VIDEO_SECTION_WIDTH;
741 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
742 - SELF_VIDEO_SECTION_HEIGHT;
745 g_warn_if_reached ();
756 static PreviewPosition
757 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
762 PreviewPosition pos = PREVIEW_POS_NONE;
764 if (!clutter_actor_has_allocation (self->priv->preview_box))
767 clutter_actor_get_geometry (self->priv->preview_box, &box);
769 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
770 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
771 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
772 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
774 pos = PREVIEW_POS_TOP_LEFT;
776 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
777 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
778 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
779 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
781 pos = PREVIEW_POS_TOP_RIGHT;
783 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
784 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
785 box.height - SELF_VIDEO_SECTION_MARGIN >= event_y &&
786 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
788 pos = PREVIEW_POS_BOTTOM_LEFT;
790 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
791 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
792 box.height - 2 * SELF_VIDEO_SECTION_MARGIN >= event_y &&
793 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
795 pos = PREVIEW_POS_BOTTOM_RIGHT;
801 static ClutterActor *
802 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
805 ClutterActor *rectangle;
809 case PREVIEW_POS_TOP_LEFT:
810 rectangle = self->priv->preview_rectangle1;
812 case PREVIEW_POS_TOP_RIGHT:
813 rectangle = self->priv->preview_rectangle3;
815 case PREVIEW_POS_BOTTOM_LEFT:
816 rectangle = self->priv->preview_rectangle2;
818 case PREVIEW_POS_BOTTOM_RIGHT:
819 rectangle = self->priv->preview_rectangle4;
829 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
832 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->preview_layout);
834 DEBUG ("moving the video preview to %d", pos);
836 self->priv->preview_pos = pos;
840 case PREVIEW_POS_TOP_LEFT:
841 clutter_bin_layout_set_alignment (layout,
842 self->priv->video_preview,
843 CLUTTER_BIN_ALIGNMENT_START,
844 CLUTTER_BIN_ALIGNMENT_START);
846 case PREVIEW_POS_TOP_RIGHT:
847 clutter_bin_layout_set_alignment (layout,
848 self->priv->video_preview,
849 CLUTTER_BIN_ALIGNMENT_END,
850 CLUTTER_BIN_ALIGNMENT_START);
852 case PREVIEW_POS_BOTTOM_LEFT:
853 clutter_bin_layout_set_alignment (layout,
854 self->priv->video_preview,
855 CLUTTER_BIN_ALIGNMENT_START,
856 CLUTTER_BIN_ALIGNMENT_END);
858 case PREVIEW_POS_BOTTOM_RIGHT:
859 clutter_bin_layout_set_alignment (layout,
860 self->priv->video_preview,
861 CLUTTER_BIN_ALIGNMENT_END,
862 CLUTTER_BIN_ALIGNMENT_END);
865 g_warn_if_reached ();
868 g_settings_set_enum (self->priv->settings, "camera-position", pos);
872 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
875 ClutterActor *rectangle;
876 ClutterColor white = { 0xff, 0xff, 0xff, 0xff};
878 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
880 empathy_rounded_rectangle_set_border_width (
881 EMPATHY_ROUNDED_RECTANGLE (rectangle), 2 * SELF_VIDEO_SECTION_MARGIN);
882 empathy_rounded_rectangle_set_border_color (
883 EMPATHY_ROUNDED_RECTANGLE (rectangle), &white);
887 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
888 ClutterActor *rectangle)
890 ClutterColor white = { 0xff, 0xff, 0xff, 0xff}, darker;
892 clutter_color_shade (&white, 0.55, &darker);
894 empathy_rounded_rectangle_set_border_width (
895 EMPATHY_ROUNDED_RECTANGLE (rectangle), 1);
896 empathy_rounded_rectangle_set_border_color (
897 EMPATHY_ROUNDED_RECTANGLE (rectangle), &darker);
901 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
903 ClutterActor *rectangle;
905 rectangle = empathy_call_window_get_preview_rectangle (self,
906 self->priv->preview_pos);
908 /* We don't want to darken the rectangle where the preview
911 if (self->priv->preview_rectangle1 != rectangle)
912 empathy_call_window_darken_preview_rectangle (self,
913 self->priv->preview_rectangle1);
915 if (self->priv->preview_rectangle2 != rectangle)
916 empathy_call_window_darken_preview_rectangle (self,
917 self->priv->preview_rectangle2);
919 if (self->priv->preview_rectangle3 != rectangle)
920 empathy_call_window_darken_preview_rectangle (self,
921 self->priv->preview_rectangle3);
923 if (self->priv->preview_rectangle4 != rectangle)
924 empathy_call_window_darken_preview_rectangle (self,
925 self->priv->preview_rectangle4);
929 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
933 ClutterModifierType modifiers,
934 EmpathyCallWindow *self)
936 ClutterActor *stage = clutter_actor_get_stage (actor);
939 self->priv->drag_preview = clutter_clone_new (actor);
941 clutter_container_add_actor (CLUTTER_CONTAINER (stage),
942 self->priv->drag_preview);
944 clutter_actor_transform_stage_point (actor, event_x, event_y,
947 clutter_actor_set_position (self->priv->drag_preview,
948 event_x - rel_x, event_y - rel_y);
950 clutter_drag_action_set_drag_handle (action,
951 self->priv->drag_preview);
953 clutter_actor_set_opacity (actor, 0);
954 clutter_actor_hide (self->priv->preview_shown_button);
956 empathy_call_window_show_preview_rectangles (self, TRUE);
957 empathy_call_window_darken_preview_rectangles (self);
961 empathy_call_window_on_animation_completed_cb (ClutterAnimation *animation,
964 clutter_actor_set_opacity (actor, 255);
968 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
972 ClutterModifierType modifiers,
973 EmpathyCallWindow *self)
978 /* Get the position before destroying the drag actor, otherwise the
979 * preview_box allocation won't be valid and we won't be able to
980 * calculate the position. */
981 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
983 empathy_call_window_get_preview_coordinates (self,
984 pos != PREVIEW_POS_NONE ? pos : self->priv->preview_pos,
987 /* Move the preview to the destination and destroy it afterwards */
988 clutter_actor_animate (self->priv->drag_preview, CLUTTER_LINEAR, 500,
991 "signal-swapped-after::completed",
992 clutter_actor_destroy, self->priv->drag_preview,
993 "signal-swapped-after::completed",
994 clutter_actor_show, self->priv->preview_shown_button,
996 empathy_call_window_on_animation_completed_cb, actor,
999 self->priv->drag_preview = NULL;
1001 if (pos != PREVIEW_POS_NONE)
1002 empathy_call_window_move_video_preview (self, pos);
1004 empathy_call_window_show_preview_rectangles (self, FALSE);
1008 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
1009 ClutterActor *actor,
1012 EmpathyCallWindow *self)
1014 PreviewPosition pos;
1015 gfloat event_x, event_y;
1017 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
1019 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
1021 if (pos != PREVIEW_POS_NONE)
1022 empathy_call_window_highlight_preview_rectangle (self, pos);
1024 empathy_call_window_darken_preview_rectangles (self);
1028 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
1029 ClutterCrossingEvent *event,
1030 EmpathyCallWindow *self)
1032 ClutterActor *rectangle;
1034 rectangle = empathy_call_window_get_preview_rectangle (self,
1035 self->priv->preview_pos);
1037 empathy_call_window_highlight_preview_rectangle (self,
1038 self->priv->preview_pos);
1040 clutter_actor_show (rectangle);
1046 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
1047 ClutterCrossingEvent *event,
1048 EmpathyCallWindow *self)
1050 ClutterActor *rectangle;
1052 rectangle = empathy_call_window_get_preview_rectangle (self,
1053 self->priv->preview_pos);
1055 empathy_call_window_darken_preview_rectangle (self, rectangle);
1057 clutter_actor_hide (rectangle);
1063 create_video_preview (EmpathyCallWindow *self)
1065 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1066 ClutterLayoutManager *layout;
1067 ClutterActor *preview;
1069 ClutterAction *action;
1070 PreviewPosition pos;
1072 g_assert (priv->video_preview == NULL);
1074 pos = g_settings_get_enum (priv->settings, "camera-position");
1076 preview = empathy_rounded_texture_new ();
1077 clutter_actor_set_size (preview,
1078 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1080 priv->video_preview_sink = gst_element_factory_make ("cluttersink", NULL);
1081 if (priv->video_preview_sink == NULL)
1082 g_error ("Missing cluttersink, check your clutter-gst installation");
1083 g_object_set (priv->video_preview_sink, "texture", preview, NULL);
1084 g_object_add_weak_pointer (G_OBJECT (priv->video_preview_sink), (gpointer) &priv->video_preview_sink);
1086 /* Add a little offset to the video preview */
1087 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1088 CLUTTER_BIN_ALIGNMENT_CENTER);
1089 priv->video_preview = clutter_box_new (layout);
1090 clutter_actor_set_size (priv->video_preview,
1091 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1092 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1094 /* Spinner for when changing the camera device */
1095 priv->preview_spinner_widget = gtk_spinner_new ();
1096 priv->preview_spinner_actor = empathy_rounded_actor_new (PREVIEW_ROUND_FACTOR);
1098 g_object_set (priv->preview_spinner_widget, "expand", TRUE, NULL);
1099 make_background_transparent (GTK_CLUTTER_ACTOR (priv->preview_spinner_actor));
1100 gtk_widget_show (priv->preview_spinner_widget);
1103 GTK_CONTAINER (gtk_clutter_actor_get_widget (
1104 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor))),
1105 priv->preview_spinner_widget);
1106 clutter_actor_set_size (priv->preview_spinner_actor,
1107 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1108 clutter_actor_set_opacity (priv->preview_spinner_actor, 128);
1109 clutter_actor_hide (priv->preview_spinner_actor);
1111 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1113 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1114 priv->preview_spinner_actor);
1116 g_object_set (priv->video_preview_sink,
1122 priv->preview_shown_button = b = gtk_clutter_actor_new_with_contents (
1123 gtk_image_new_from_icon_name ("emblem-system-symbolic",
1124 GTK_ICON_SIZE_MENU));
1125 clutter_actor_set_margin_right (b, 4);
1126 clutter_actor_set_margin_bottom (b, 2);
1127 clutter_actor_set_opacity (b, PREVIEW_BUTTON_OPACITY);
1128 make_background_transparent (GTK_CLUTTER_ACTOR (b));
1130 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout), b,
1131 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
1133 action = clutter_click_action_new ();
1134 clutter_actor_add_action (b, action);
1135 g_signal_connect (action, "clicked",
1136 G_CALLBACK (empathy_call_window_preview_button_clicked_cb), self);
1138 /* Preview hidden */
1139 priv->preview_hidden_button = b = gtk_clutter_actor_new_with_contents (
1140 gtk_image_new_from_icon_name ("emblem-system-symbolic",
1141 GTK_ICON_SIZE_MENU));
1142 make_background_transparent (GTK_CLUTTER_ACTOR (b));
1144 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1145 priv->preview_hidden_button,
1146 CLUTTER_BIN_ALIGNMENT_START,
1147 CLUTTER_BIN_ALIGNMENT_END);
1149 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1151 clutter_actor_hide (priv->preview_hidden_button);
1153 action = clutter_click_action_new ();
1154 clutter_actor_add_action (b, action);
1155 g_signal_connect (action, "clicked",
1156 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb), self);
1158 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1159 priv->video_preview,
1160 CLUTTER_BIN_ALIGNMENT_START,
1161 CLUTTER_BIN_ALIGNMENT_END);
1163 empathy_call_window_move_video_preview (self, pos);
1165 action = clutter_drag_action_new ();
1166 g_signal_connect (action, "drag-begin",
1167 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1168 g_signal_connect (action, "drag-end",
1169 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1170 g_signal_connect (action, "drag-motion",
1171 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1173 g_signal_connect (preview, "enter-event",
1174 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1175 g_signal_connect (preview, "leave-event",
1176 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1178 clutter_actor_add_action (preview, action);
1179 clutter_actor_set_reactive (preview, TRUE);
1180 clutter_actor_set_reactive (priv->preview_shown_button, TRUE);
1184 empathy_call_window_start_camera_spinning (EmpathyCallWindow *self)
1186 clutter_actor_show (self->priv->preview_spinner_actor);
1187 gtk_spinner_start (GTK_SPINNER (self->priv->preview_spinner_widget));
1191 empathy_call_window_stop_camera_spinning (EmpathyCallWindow *self)
1193 clutter_actor_hide (self->priv->preview_spinner_actor);
1194 gtk_spinner_stop (GTK_SPINNER (self->priv->preview_spinner_widget));
1198 empathy_call_window_play_camera (EmpathyCallWindow *self,
1201 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1202 GstElement *preview;
1205 if (priv->video_preview == NULL)
1207 create_video_preview (self);
1208 add_video_preview_to_pipeline (self);
1213 state = GST_STATE_PLAYING;
1217 empathy_call_window_start_camera_spinning (self);
1218 state = GST_STATE_NULL;
1221 preview = priv->video_preview_sink;
1223 gst_element_set_state (preview, state);
1224 gst_element_set_state (priv->video_tee, state);
1225 gst_element_set_state (priv->video_input, state);
1229 display_video_preview (EmpathyCallWindow *self,
1232 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1234 if (priv->video_preview == NULL)
1236 create_video_preview (self);
1237 add_video_preview_to_pipeline (self);
1242 /* Display the video preview */
1243 DEBUG ("Show video preview");
1245 empathy_call_window_play_camera (self, TRUE);
1246 clutter_actor_show (priv->video_preview);
1247 clutter_actor_raise_top (priv->floating_toolbar);
1251 /* Hide the video preview */
1252 DEBUG ("Hide video preview");
1254 if (priv->video_preview != NULL)
1256 clutter_actor_hide (priv->video_preview);
1257 empathy_call_window_play_camera (self, FALSE);
1263 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1265 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1267 empathy_call_window_status_message (window, _("Connecting…"));
1268 priv->call_state = CONNECTING;
1270 /* Show the toolbar */
1271 clutter_state_set_state (priv->transitions, "fade-in");
1274 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1275 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1279 disable_camera (EmpathyCallWindow *self)
1281 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1283 if (priv->camera_state == CAMERA_STATE_OFF)
1286 DEBUG ("Disable camera");
1288 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1290 priv->camera_state = CAMERA_STATE_OFF;
1294 enable_camera (EmpathyCallWindow *self)
1296 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1298 if (priv->camera_state == CAMERA_STATE_ON)
1301 if (priv->video_input == NULL)
1303 DEBUG ("Can't enable camera, no input");
1307 DEBUG ("Enable camera");
1309 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1311 priv->camera_state = CAMERA_STATE_ON;
1315 empathy_call_window_camera_toggled_cb (GtkToggleButton *toggle,
1316 EmpathyCallWindow *self)
1318 if (gtk_toggle_button_get_active (toggle))
1319 enable_camera (self);
1321 disable_camera (self);
1325 create_pipeline (EmpathyCallWindow *self)
1327 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1330 g_assert (priv->pipeline == NULL);
1332 priv->pipeline = gst_pipeline_new (NULL);
1333 priv->pipeline_playing = FALSE;
1335 priv->video_tee = gst_element_factory_make ("tee", NULL);
1336 gst_object_ref_sink (priv->video_tee);
1338 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1340 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1341 priv->bus_message_source_id = gst_bus_add_watch (bus,
1342 empathy_call_window_bus_message, self);
1344 g_object_unref (bus);
1348 empathy_call_window_settings_cb (GtkAction *action,
1349 EmpathyCallWindow *self)
1351 gchar *args = g_strdup_printf ("-p %s",
1352 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1354 empathy_launch_program (BIN_DIR, "empathy", args);
1360 empathy_call_window_contents_cb (GtkAction *action,
1361 EmpathyCallWindow *self)
1363 empathy_url_show (GTK_WIDGET (self), "help:empathy/audio-video");
1367 show_png (GPid pid, gint status, gpointer user_data)
1369 gtk_show_uri (NULL, (gchar *) user_data, GDK_CURRENT_TIME, NULL);
1370 g_spawn_close_pid (pid);
1375 empathy_call_window_debug_gst_cb (GtkAction *action,
1376 EmpathyCallWindow *self)
1378 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1379 GDateTime *date_time;
1381 const gchar *dot_dir;
1382 const gchar *prgname;
1388 if (priv->pipeline == NULL)
1389 DEBUG ("No pipeline");
1391 date_time = g_date_time_new_now_utc ();
1392 prgname = g_get_prgname ();
1393 filename = g_strdup_printf ("%s-%" G_GINT64_FORMAT, prgname,
1394 g_date_time_to_unix (date_time));
1396 GST_DEBUG_BIN_TO_DOT_FILE (GST_BIN (priv->pipeline),
1397 GST_DEBUG_GRAPH_SHOW_ALL, filename);
1399 dot_dir = g_getenv ("GST_DEBUG_DUMP_DOT_DIR");
1400 dot_cmd = g_strdup_printf ("dot -Tpng -o %s.png %s.dot",
1403 g_shell_parse_argv (dot_cmd, &argc, &argv, NULL);
1405 if (g_spawn_async (dot_dir,
1408 G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
1414 gchar *uri = g_strdup_printf ("file://%s/%s.png", dot_dir, filename);
1415 g_child_watch_add (dot_pid, show_png, uri);
1421 g_date_time_unref (date_time);
1425 empathy_call_window_debug_tp_cb (GtkAction *action,
1426 EmpathyCallWindow *self)
1428 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1432 empathy_call_window_about_cb (GtkAction *action,
1433 EmpathyCallWindow *self)
1435 empathy_about_dialog_new (GTK_WINDOW (self));
1439 empathy_call_window_toolbar_timeout (gpointer data)
1441 EmpathyCallWindow *self = data;
1443 /* We don't want to hide the toolbar if we're not in a call, as
1444 * to show the call status all the time. Also don't hide if we're muted
1445 * to prevent the awkward, talking when muted situation */
1446 if (self->priv->call_state != CONNECTING &&
1447 self->priv->call_state != DISCONNECTED &&
1449 clutter_state_set_state (self->priv->transitions, "fade-out");
1455 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1457 EmpathyCallWindow *self)
1459 clutter_state_set_state (self->priv->transitions, "fade-in");
1461 if (self->priv->inactivity_src > 0)
1462 g_source_remove (self->priv->inactivity_src);
1464 self->priv->inactivity_src = g_timeout_add_seconds (3,
1465 empathy_call_window_toolbar_timeout, self);
1471 empathy_call_window_configure_event_cb (GtkWidget *widget,
1473 EmpathyCallWindow *self)
1475 GdkWindow *gdk_window;
1476 GdkWindowState window_state;
1478 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1479 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1481 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1482 &self->priv->dialpad_width, NULL);
1484 gdk_window = gtk_widget_get_window (widget);
1485 window_state = gdk_window_get_state (gdk_window);
1486 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1492 empathy_call_window_destroyed_cb (GtkWidget *object,
1493 EmpathyCallWindow *self)
1495 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1497 /* Save the geometry as if the dialpad was hidden. */
1498 empathy_geometry_save_values (GTK_WINDOW (self),
1499 self->priv->x, self->priv->y,
1500 self->priv->w - self->priv->dialpad_width, self->priv->h,
1501 self->priv->maximized);
1506 empathy_call_window_incoming_call_response_cb (GtkDialog *dialog,
1508 EmpathyCallWindow *self)
1510 switch (response_id)
1512 case GTK_RESPONSE_ACCEPT:
1513 tp_channel_dispatch_operation_handle_with_time_async (
1514 self->priv->pending_cdo, EMPATHY_CALL_BUS_NAME,
1515 empathy_get_current_action_time (), NULL, NULL);
1517 tp_clear_object (&self->priv->pending_cdo);
1518 tp_clear_object (&self->priv->pending_channel);
1519 tp_clear_object (&self->priv->pending_context);
1522 case GTK_RESPONSE_CANCEL:
1523 tp_channel_dispatch_operation_close_channels_async (
1524 self->priv->pending_cdo, NULL, NULL);
1526 empathy_call_window_status_message (self, _("Disconnected"));
1527 self->priv->call_state = DISCONNECTED;
1530 g_warn_if_reached ();
1535 empathy_call_window_set_state_ringing (EmpathyCallWindow *self)
1539 g_assert (self->priv->call_state != CONNECTED);
1541 video = tp_call_channel_has_initial_video (self->priv->pending_channel, NULL);
1543 empathy_call_window_status_message (self, _("Incoming call"));
1544 self->priv->call_state = RINGING;
1546 self->priv->incoming_call_dialog = gtk_message_dialog_new (
1547 GTK_WINDOW (self), GTK_DIALOG_MODAL,
1548 GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
1549 video ? _("Incoming video call from %s") : _("Incoming call from %s"),
1550 empathy_contact_get_alias (self->priv->contact));
1552 gtk_dialog_add_buttons (GTK_DIALOG (self->priv->incoming_call_dialog),
1553 _("Reject"), GTK_RESPONSE_CANCEL,
1554 _("Answer"), GTK_RESPONSE_ACCEPT,
1557 g_signal_connect (self->priv->incoming_call_dialog, "response",
1558 G_CALLBACK (empathy_call_window_incoming_call_response_cb), self);
1559 gtk_widget_show (self->priv->incoming_call_dialog);
1563 empathy_call_window_cdo_invalidated_cb (TpProxy *channel,
1567 EmpathyCallWindow *self)
1569 tp_clear_object (&self->priv->pending_cdo);
1570 tp_clear_object (&self->priv->pending_channel);
1571 tp_clear_object (&self->priv->pending_context);
1573 /* We don't know if the incoming call has been accepted or not, so we
1574 * assume it hasn't and if it has, we'll set the proper status when
1575 * we get the new handler. */
1576 empathy_call_window_status_message (self, _("Disconnected"));
1577 self->priv->call_state = DISCONNECTED;
1579 gtk_widget_destroy (self->priv->incoming_call_dialog);
1580 self->priv->incoming_call_dialog = NULL;
1584 empathy_call_window_start_ringing (EmpathyCallWindow *self,
1585 TpCallChannel *channel,
1586 TpChannelDispatchOperation *dispatch_operation,
1587 TpAddDispatchOperationContext *context)
1589 g_assert (self->priv->pending_channel == NULL);
1590 g_assert (self->priv->pending_context == NULL);
1591 g_assert (self->priv->pending_cdo == NULL);
1593 /* Start ringing and delay until the user answers or hangs. */
1594 self->priv->pending_channel = g_object_ref (channel);
1595 self->priv->pending_context = g_object_ref (context);
1596 self->priv->pending_cdo = g_object_ref (dispatch_operation);
1598 g_signal_connect (self->priv->pending_cdo, "invalidated",
1599 G_CALLBACK (empathy_call_window_cdo_invalidated_cb), self);
1601 empathy_call_window_set_state_ringing (self);
1602 tp_add_dispatch_operation_context_accept (context);
1606 mic_button_clicked (GtkWidget *button,
1607 EmpathyCallWindow *self)
1609 /* Toggle the muted state. We rely on audio_input_mute_notify_cb to update
1611 empathy_audio_src_set_mute (EMPATHY_GST_AUDIO_SRC (self->priv->audio_input),
1612 !self->priv->muted);
1616 empathy_call_window_init (EmpathyCallWindow *self)
1618 EmpathyCallWindowPriv *priv;
1620 GtkWidget *top_vbox;
1622 ClutterConstraint *constraint;
1623 ClutterActor *remote_avatar;
1624 ClutterColor black = { 0, 0, 0, 0 };
1625 ClutterMargin overlay_margin = { OVERLAY_MARGIN, OVERLAY_MARGIN,
1626 OVERLAY_MARGIN, OVERLAY_MARGIN };
1628 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1629 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1631 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1632 priv->timer = g_timer_new ();
1634 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1635 gui = tpaw_builder_get_file (filename,
1636 "call_window_vbox", &top_vbox,
1637 "errors_vbox", &priv->errors_vbox,
1638 "pane", &priv->pane,
1639 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1640 "remote_user_status_toolbar", &priv->remote_user_status_toolbar,
1641 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1642 "status_label", &priv->status_label,
1643 "audiocall", &priv->audio_call_button,
1644 "videocall", &priv->video_call_button,
1645 "microphone", &priv->mic_button,
1646 "microphone_icon", &priv->microphone_icon,
1647 "volume", &priv->volume_button,
1648 "camera", &priv->camera_button,
1649 "hangup", &priv->hangup_button,
1650 "dialpad", &priv->dialpad_button,
1651 "toolbar", &priv->toolbar,
1652 "bottom_toolbar", &priv->bottom_toolbar,
1653 "ui_manager", &priv->ui_manager,
1654 "menufullscreen", &priv->menu_fullscreen,
1655 "menupreviewswap", &priv->menu_swap_camera,
1656 "details_vbox", &priv->details_vbox,
1657 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1658 "acodec_encoding_label", &priv->acodec_encoding_label,
1659 "acodec_decoding_label", &priv->acodec_decoding_label,
1660 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1661 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1662 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1663 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1664 "video_local_candidate_label", &priv->video_local_candidate_label,
1665 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1666 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1667 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1668 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1672 tpaw_builder_connect (gui, self,
1673 "hangup", "clicked", empathy_call_window_hangup_cb,
1674 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1675 "videocall", "clicked", empathy_call_window_video_call_cb,
1676 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1677 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1678 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1679 "menusettings", "activate", empathy_call_window_settings_cb,
1680 "menucontents", "activate", empathy_call_window_contents_cb,
1681 "menudebuggst", "activate", empathy_call_window_debug_gst_cb,
1682 "menudebugtp", "activate", empathy_call_window_debug_tp_cb,
1683 "menuabout", "activate", empathy_call_window_about_cb,
1684 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1685 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1686 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1687 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1690 empathy_set_css_provider (GTK_WIDGET (self));
1691 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1693 priv->camera_monitor = tpaw_camera_monitor_dup_singleton ();
1694 empathy_call_window_update_swap_camera (self);
1696 g_object_bind_property (priv->camera_monitor, "available",
1697 priv->camera_button, "sensitive",
1698 G_BINDING_SYNC_CREATE);
1700 g_signal_connect (priv->camera_monitor, "added",
1701 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1702 g_signal_connect (priv->camera_monitor, "removed",
1703 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1705 g_signal_connect (priv->mic_button, "clicked",
1706 G_CALLBACK (mic_button_clicked), self);
1708 g_mutex_init (&priv->lock);
1710 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1712 priv->content_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,
1713 CONTENT_HBOX_SPACING);
1714 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1717 /* main contents remote avatar/video box */
1718 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_FILL,
1719 CLUTTER_BIN_ALIGNMENT_FILL);
1721 priv->video_box = clutter_box_new (priv->video_layout);
1723 priv->video_container = gtk_clutter_embed_new ();
1725 gtk_widget_set_size_request (priv->video_container,
1726 REMOTE_VIDEO_DEFAULT_WIDTH, REMOTE_VIDEO_DEFAULT_HEIGHT);
1728 /* Set the background black */
1729 clutter_stage_set_color (
1730 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1731 GTK_CLUTTER_EMBED (priv->video_container))),
1734 clutter_container_add (
1735 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1736 GTK_CLUTTER_EMBED (priv->video_container))),
1740 constraint = clutter_bind_constraint_new (
1741 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1742 CLUTTER_BIND_SIZE, 0);
1743 clutter_actor_add_constraint (priv->video_box, constraint);
1745 priv->remote_user_avatar_widget = gtk_image_new ();
1746 remote_avatar = gtk_clutter_actor_new_with_contents (
1747 priv->remote_user_avatar_widget);
1748 make_background_transparent (GTK_CLUTTER_ACTOR (remote_avatar));
1750 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1753 /* create the overlay bin */
1754 priv->overlay_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1755 CLUTTER_BIN_ALIGNMENT_CENTER);
1756 priv->overlay_bin = clutter_actor_new ();
1757 clutter_actor_set_layout_manager (priv->overlay_bin, priv->overlay_layout);
1759 clutter_actor_set_margin (priv->overlay_bin, &overlay_margin);
1761 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1763 CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL);
1765 empathy_call_window_create_preview_rectangles (self);
1767 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1768 priv->video_container, TRUE, TRUE,
1769 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1771 create_pipeline (self);
1772 create_video_output_widget (self);
1773 create_audio_input (self);
1774 create_video_input (self);
1776 priv->floating_toolbar = gtk_clutter_actor_new ();
1777 clutter_actor_set_reactive (priv->floating_toolbar, TRUE);
1778 make_background_transparent (GTK_CLUTTER_ACTOR (priv->floating_toolbar));
1780 gtk_style_context_add_class (
1781 gtk_widget_get_style_context (GTK_WIDGET (priv->bottom_toolbar)),
1782 GTK_STYLE_CLASS_OSD);
1783 gtk_widget_reparent (priv->bottom_toolbar,
1784 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1786 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->overlay_layout),
1787 priv->floating_toolbar,
1788 CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_END);
1790 clutter_actor_raise_top (priv->floating_toolbar);
1792 /* Transitions for the floating toolbar */
1793 priv->transitions = clutter_state_new ();
1795 /* all transitions last for 2s */
1796 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1798 /* transition from any state to "fade-out" state */
1799 clutter_state_set (priv->transitions, NULL, "fade-out",
1800 priv->floating_toolbar,
1801 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1804 /* transition from any state to "fade-in" state */
1805 clutter_state_set (priv->transitions, NULL, "fade-in",
1806 priv->floating_toolbar,
1807 "opacity", CLUTTER_EASE_OUT_QUAD, 255,
1810 /* put the actor into the "fade-in" state with no animation */
1811 clutter_state_warp_to_state (priv->transitions, "fade-in");
1813 /* The call will be started as soon the pipeline is playing */
1814 priv->start_call_when_playing = TRUE;
1816 priv->dtmf_panel = empathy_dialpad_widget_new ();
1817 g_signal_connect (priv->dtmf_panel, "start-tone",
1818 G_CALLBACK (dtmf_start_tone_cb), self);
1820 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1823 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1826 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1828 gtk_widget_show_all (top_vbox);
1830 gtk_widget_hide (priv->dtmf_panel);
1831 gtk_widget_hide (priv->details_vbox);
1833 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1835 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1836 priv->video_container);
1838 /* We hide the bottom toolbar after 3s of inactivity and show it
1839 * again on mouse movement */
1840 priv->inactivity_src = g_timeout_add_seconds (3,
1841 empathy_call_window_toolbar_timeout, self);
1843 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1844 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1846 g_signal_connect (G_OBJECT (self), "realize",
1847 G_CALLBACK (empathy_call_window_realized_cb), self);
1849 g_signal_connect (G_OBJECT (self), "delete-event",
1850 G_CALLBACK (empathy_call_window_delete_cb), self);
1852 g_signal_connect (G_OBJECT (self), "window-state-event",
1853 G_CALLBACK (empathy_call_window_state_event_cb), self);
1855 g_signal_connect (G_OBJECT (self), "key-press-event",
1856 G_CALLBACK (empathy_call_window_key_press_cb), self);
1858 g_signal_connect (self, "motion-notify-event",
1859 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1861 g_object_ref (priv->ui_manager);
1862 g_object_unref (gui);
1864 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1865 priv->mic_menu = empathy_mic_menu_new (self);
1866 priv->camera_menu = empathy_camera_menu_new (self);
1868 empathy_call_window_show_hangup_button (self, TRUE);
1870 gtk_window_set_default_size (GTK_WINDOW (self), 580, 480);
1872 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1873 /* These signals are used to track the window position and save it
1874 * when the window is destroyed. We need to do this as we don't want
1875 * the window geometry to be saved with the dialpad taken into account. */
1876 g_signal_connect (self, "destroy",
1877 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1878 g_signal_connect (self, "configure-event",
1879 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1880 g_signal_connect (self, "window-state-event",
1881 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1883 /* Don't display labels in both toolbars */
1884 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1887 /* Instead of specifying a width and a height, we specify only one size. That's
1888 because we want a square avatar icon. */
1890 init_contact_avatar_with_size (EmpathyContact *contact,
1891 GtkWidget *image_widget,
1894 GdkPixbuf *pixbuf_avatar = NULL;
1896 if (contact != NULL)
1898 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1902 if (pixbuf_avatar == NULL)
1904 pixbuf_avatar = tpaw_pixbuf_from_icon_name_sized (
1905 TPAW_IMAGE_AVATAR_DEFAULT, size);
1908 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1910 if (pixbuf_avatar != NULL)
1911 g_object_unref (pixbuf_avatar);
1915 set_window_title (EmpathyCallWindow *self)
1917 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1920 if (priv->contact != NULL)
1922 /* translators: Call is a noun and %s is the contact name. This string
1923 * is used in the window title */
1924 tmp = g_strdup_printf (_("Call with %s"),
1925 empathy_contact_get_alias (priv->contact));
1926 gtk_window_set_title (GTK_WINDOW (self), tmp);
1931 g_warning ("Unknown remote contact!");
1936 set_remote_user_name (EmpathyCallWindow *self,
1937 EmpathyContact *contact)
1939 const gchar *alias = empathy_contact_get_alias (contact);
1940 const gchar *status = empathy_contact_get_status (contact);
1942 gtk_label_set_text (GTK_LABEL (self->priv->remote_user_name_toolbar), alias);
1944 if (status != NULL) {
1947 markup = g_markup_printf_escaped ("<small>%s</small>", status);
1948 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_status_toolbar),
1952 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_status_toolbar),
1958 contact_name_changed_cb (EmpathyContact *contact,
1960 EmpathyCallWindow *self)
1962 set_window_title (self);
1963 set_remote_user_name (self, contact);
1967 contact_presence_changed_cb (EmpathyContact *contact,
1969 EmpathyCallWindow *self)
1971 set_remote_user_name (self, contact);
1975 contact_avatar_changed_cb (EmpathyContact *contact,
1977 EmpathyCallWindow *self)
1980 GtkAllocation allocation;
1981 GtkWidget *avatar_widget;
1983 avatar_widget = self->priv->remote_user_avatar_widget;
1985 gtk_widget_get_allocation (avatar_widget, &allocation);
1986 size = allocation.height;
1990 /* the widget is not allocated yet, set a default size */
1991 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1992 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1995 init_contact_avatar_with_size (contact, avatar_widget, size);
1997 avatar_widget = self->priv->remote_user_avatar_toolbar;
1999 gtk_widget_get_allocation (avatar_widget, &allocation);
2000 size = allocation.height;
2004 /* the widget is not allocated yet, set a default size */
2005 size = SMALL_TOOLBAR_SIZE;
2008 init_contact_avatar_with_size (contact, avatar_widget, size);
2012 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
2013 EmpathyCallHandler *handler)
2015 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2017 tp_g_signal_connect_object (priv->contact, "notify::name",
2018 G_CALLBACK (contact_name_changed_cb), self, 0);
2019 tp_g_signal_connect_object (priv->contact, "notify::avatar",
2020 G_CALLBACK (contact_avatar_changed_cb), self, 0);
2021 tp_g_signal_connect_object (priv->contact, "notify::presence",
2022 G_CALLBACK (contact_presence_changed_cb), self, 0);
2024 set_window_title (self);
2025 set_remote_user_name (self, priv->contact);
2027 init_contact_avatar_with_size (priv->contact,
2028 priv->remote_user_avatar_widget,
2029 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
2030 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
2032 init_contact_avatar_with_size (priv->contact,
2033 priv->remote_user_avatar_toolbar,
2034 SMALL_TOOLBAR_SIZE);
2036 /* The remote avatar is shown by default and will be hidden when we receive
2037 video from the remote side. */
2038 clutter_actor_hide (priv->video_output);
2039 gtk_widget_show (priv->remote_user_avatar_widget);
2043 update_send_codec (EmpathyCallWindow *self,
2046 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2053 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
2054 widget = priv->acodec_encoding_label;
2058 codec = empathy_call_handler_get_send_video_codec (priv->handler);
2059 widget = priv->vcodec_encoding_label;
2065 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
2066 gtk_label_set_text (GTK_LABEL (widget), tmp);
2071 send_audio_codec_notify_cb (GObject *object,
2075 EmpathyCallWindow *self = user_data;
2077 update_send_codec (self, TRUE);
2081 send_video_codec_notify_cb (GObject *object,
2085 EmpathyCallWindow *self = user_data;
2087 update_send_codec (self, FALSE);
2091 update_recv_codec (EmpathyCallWindow *self,
2094 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2097 GString *str = NULL;
2101 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
2102 widget = priv->acodec_decoding_label;
2106 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
2107 widget = priv->vcodec_decoding_label;
2113 for (l = codecs; l != NULL; l = g_list_next (l))
2115 FsCodec *codec = l->data;
2118 str = g_string_new (NULL);
2120 g_string_append (str, ", ");
2122 g_string_append_printf (str, "%s/%u", codec->encoding_name,
2126 gtk_label_set_text (GTK_LABEL (widget), str->str);
2127 g_string_free (str, TRUE);
2131 recv_audio_codecs_notify_cb (GObject *object,
2135 EmpathyCallWindow *self = user_data;
2137 update_recv_codec (self, TRUE);
2141 recv_video_codecs_notify_cb (GObject *object,
2145 EmpathyCallWindow *self = user_data;
2147 update_recv_codec (self, FALSE);
2150 static const gchar *
2151 candidate_type_to_str (FsCandidate *candidate)
2153 switch (candidate->type)
2155 case FS_CANDIDATE_TYPE_HOST:
2157 case FS_CANDIDATE_TYPE_SRFLX:
2158 return "server reflexive";
2159 case FS_CANDIDATE_TYPE_PRFLX:
2160 return "peer reflexive";
2161 case FS_CANDIDATE_TYPE_RELAY:
2163 case FS_CANDIDATE_TYPE_MULTICAST:
2170 static const gchar *
2171 candidate_type_to_desc (FsCandidate *candidate)
2173 switch (candidate->type)
2175 case FS_CANDIDATE_TYPE_HOST:
2176 return _("The IP address as seen by the machine");
2177 case FS_CANDIDATE_TYPE_SRFLX:
2178 return _("The IP address as seen by a server on the Internet");
2179 case FS_CANDIDATE_TYPE_PRFLX:
2180 return _("The IP address of the peer as seen by the other side");
2181 case FS_CANDIDATE_TYPE_RELAY:
2182 return _("The IP address of a relay server");
2183 case FS_CANDIDATE_TYPE_MULTICAST:
2184 return _("The IP address of the multicast group");
2191 update_candidat_widget (EmpathyCallWindow *self,
2194 FsCandidate *candidate)
2198 g_assert (candidate != NULL);
2199 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
2200 candidate->port, candidate_type_to_str (candidate));
2202 gtk_label_set_text (GTK_LABEL (label), str);
2203 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
2209 candidates_changed_cb (GObject *object,
2211 EmpathyCallWindow *self)
2213 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2214 FsCandidate *candidate = NULL;
2216 if (type == FS_MEDIA_TYPE_VIDEO)
2218 /* Update remote candidate */
2219 candidate = empathy_call_handler_get_video_remote_candidate (
2222 update_candidat_widget (self, priv->video_remote_candidate_label,
2223 priv->video_remote_candidate_info_img, candidate);
2225 /* Update local candidate */
2226 candidate = empathy_call_handler_get_video_local_candidate (
2229 update_candidat_widget (self, priv->video_local_candidate_label,
2230 priv->video_local_candidate_info_img, candidate);
2234 /* Update remote candidate */
2235 candidate = empathy_call_handler_get_audio_remote_candidate (
2238 update_candidat_widget (self, priv->audio_remote_candidate_label,
2239 priv->audio_remote_candidate_info_img, candidate);
2241 /* Update local candidate */
2242 candidate = empathy_call_handler_get_audio_local_candidate (
2245 update_candidat_widget (self, priv->audio_local_candidate_label,
2246 priv->audio_local_candidate_info_img, candidate);
2251 empathy_call_window_constructed (GObject *object)
2253 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2254 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2255 TpCallChannel *call;
2258 g_assert (priv->handler != NULL);
2260 g_object_get (priv->handler, "call-channel", &call, NULL);
2261 state = tp_call_channel_get_state (call, NULL, NULL, NULL);
2262 priv->outgoing = (state == TP_CALL_STATE_PENDING_INITIATOR);
2263 tp_clear_object (&call);
2265 priv->contact = empathy_call_handler_get_contact (priv->handler);
2266 g_assert (priv->contact != NULL);
2267 g_object_ref (priv->contact);
2269 if (!empathy_contact_can_voip_video (priv->contact))
2271 gtk_widget_set_sensitive (priv->video_call_button, FALSE);
2272 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2275 empathy_call_window_setup_avatars (self, priv->handler);
2276 empathy_call_window_set_state_connecting (self);
2278 if (!empathy_call_handler_has_initial_video (priv->handler))
2280 gtk_toggle_button_set_active (
2281 GTK_TOGGLE_BUTTON (priv->camera_button), FALSE);
2283 /* If call has InitialVideo, the preview will be started once the call has
2284 * been started (start_call()). */
2286 update_send_codec (self, TRUE);
2287 update_send_codec (self, FALSE);
2288 update_recv_codec (self, TRUE);
2289 update_recv_codec (self, FALSE);
2291 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2292 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2293 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2294 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2295 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2296 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2297 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2298 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2300 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2301 G_CALLBACK (candidates_changed_cb), self, 0);
2304 static void empathy_call_window_dispose (GObject *object);
2305 static void empathy_call_window_finalize (GObject *object);
2308 empathy_call_window_set_property (GObject *object,
2309 guint property_id, const GValue *value, GParamSpec *pspec)
2311 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2313 switch (property_id)
2315 case PROP_CALL_HANDLER:
2316 priv->handler = g_value_dup_object (value);
2319 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2324 empathy_call_window_get_property (GObject *object,
2325 guint property_id, GValue *value, GParamSpec *pspec)
2327 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2329 switch (property_id)
2331 case PROP_CALL_HANDLER:
2332 g_value_set_object (value, priv->handler);
2335 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2340 empathy_call_window_class_init (
2341 EmpathyCallWindowClass *empathy_call_window_class)
2343 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2344 GParamSpec *param_spec;
2346 g_type_class_add_private (empathy_call_window_class,
2347 sizeof (EmpathyCallWindowPriv));
2349 object_class->constructed = empathy_call_window_constructed;
2350 object_class->set_property = empathy_call_window_set_property;
2351 object_class->get_property = empathy_call_window_get_property;
2353 object_class->dispose = empathy_call_window_dispose;
2354 object_class->finalize = empathy_call_window_finalize;
2356 param_spec = g_param_spec_object ("handler",
2357 "handler", "The call handler",
2358 EMPATHY_TYPE_CALL_HANDLER,
2359 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2360 g_object_class_install_property (object_class,
2361 PROP_CALL_HANDLER, param_spec);
2363 signals[SIG_INHIBIT] = g_signal_new ("inhibit",
2364 G_OBJECT_CLASS_TYPE (empathy_call_window_class),
2366 0, NULL, NULL, NULL,
2372 empathy_call_window_dispose (GObject *object)
2374 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2375 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2377 if (priv->dispose_has_run)
2380 priv->dispose_has_run = TRUE;
2382 if (priv->handler != NULL)
2384 empathy_call_handler_stop_call (priv->handler);
2385 tp_clear_object (&priv->handler);
2388 if (priv->bus_message_source_id != 0)
2390 g_source_remove (priv->bus_message_source_id);
2391 priv->bus_message_source_id = 0;
2394 if (priv->got_video_src > 0)
2396 g_source_remove (priv->got_video_src);
2397 priv->got_video_src = 0;
2400 if (priv->inactivity_src > 0)
2402 g_source_remove (priv->inactivity_src);
2403 priv->inactivity_src = 0;
2406 tp_clear_object (&priv->pipeline);
2407 tp_clear_object (&priv->video_input);
2408 tp_clear_object (&priv->audio_input);
2409 tp_clear_object (&priv->video_tee);
2410 tp_clear_object (&priv->ui_manager);
2411 tp_clear_object (&priv->fullscreen);
2412 tp_clear_object (&priv->camera_monitor);
2413 tp_clear_object (&priv->settings);
2414 tp_clear_object (&priv->sound_mgr);
2415 tp_clear_object (&priv->mic_menu);
2416 tp_clear_object (&priv->camera_menu);
2417 tp_clear_object (&priv->transitions);
2419 g_list_free_full (priv->notifiers, g_object_unref);
2421 if (priv->timer_id != 0)
2422 g_source_remove (priv->timer_id);
2425 tp_clear_object (&priv->contact);
2427 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2431 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2433 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2435 if (priv->video_output_motion_handler_id != 0)
2437 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2438 priv->video_output_motion_handler_id);
2439 priv->video_output_motion_handler_id = 0;
2444 empathy_call_window_finalize (GObject *object)
2446 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2447 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2449 disconnect_video_output_motion_handler (self);
2451 /* free any data held directly by the object here */
2452 g_mutex_clear (&priv->lock);
2454 g_timer_destroy (priv->timer);
2456 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2461 empathy_call_window_new (EmpathyCallHandler *handler)
2463 return EMPATHY_CALL_WINDOW (
2464 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2468 empathy_call_window_new_handler (EmpathyCallWindow *self,
2469 EmpathyCallHandler *handler,
2473 g_return_if_fail (EMPATHY_IS_CALL_HANDLER (handler));
2476 tpaw_window_present_with_time (GTK_WINDOW (self), x11_time);
2478 if (self->priv->call_state == DISCONNECTED)
2480 /* start a new call if one is not already in progress */
2481 tp_clear_object (&self->priv->handler);
2482 self->priv->handler = g_object_ref (handler);
2483 empathy_call_window_connect_handler (self);
2485 empathy_call_window_restart_call (self);
2490 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2491 GstElement *conference, gpointer user_data)
2493 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2494 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2495 FsElementAddedNotifier *notifier;
2498 DEBUG ("Conference added");
2500 /* Add notifier to set the various element properties as needed */
2501 notifier = fs_element_added_notifier_new ();
2502 keyfile = fs_utils_get_default_element_properties (conference);
2504 if (keyfile != NULL)
2505 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2507 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2509 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2511 gst_bin_add (GST_BIN (priv->pipeline), conference);
2512 gst_element_set_state (conference, GST_STATE_PLAYING);
2516 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2517 GstElement *conference, gpointer user_data)
2519 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2520 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2522 g_list_free_full (priv->notifiers, g_object_unref);
2523 priv->notifiers = NULL;
2525 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2526 gst_element_set_state (conference, GST_STATE_NULL);
2530 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2532 GstStateChangeReturn state_change_return;
2533 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2535 if (priv->pipeline == NULL)
2538 if (priv->bus_message_source_id != 0)
2540 g_source_remove (priv->bus_message_source_id);
2541 priv->bus_message_source_id = 0;
2544 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2546 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2547 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2549 if (priv->pipeline != NULL)
2550 g_object_unref (priv->pipeline);
2551 priv->pipeline = NULL;
2553 if (priv->audio_output != NULL)
2554 g_object_unref (priv->audio_output);
2555 priv->audio_output = NULL;
2556 priv->audio_output_added = FALSE;
2558 if (priv->video_tee != NULL)
2559 g_object_unref (priv->video_tee);
2560 priv->video_tee = NULL;
2562 if (priv->video_preview != NULL)
2563 clutter_actor_destroy (priv->video_preview);
2564 priv->video_preview = NULL;
2566 /* If we destroy the preview while it's being dragged, we won't
2567 * get the ::drag-end signal, so manually destroy the clone */
2568 if (priv->drag_preview != NULL)
2570 clutter_actor_destroy (priv->drag_preview);
2571 empathy_call_window_show_preview_rectangles (self, FALSE);
2572 priv->drag_preview = NULL;
2575 priv->funnel = NULL;
2577 create_pipeline (self);
2578 /* Call will be started when user will hit the 'redial' button */
2579 priv->start_call_when_playing = FALSE;
2580 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2586 g_message ("Error: could not destroy pipeline. Closing call window");
2587 gtk_widget_destroy (GTK_WIDGET (self));
2594 reset_details_pane (EmpathyCallWindow *self)
2596 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2598 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2599 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2600 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2601 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2605 empathy_call_window_disconnected (EmpathyCallWindow *self,
2608 gboolean could_disconnect = FALSE;
2609 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2610 gboolean could_reset_pipeline;
2612 /* Leave full screen mode if needed */
2613 gtk_window_unfullscreen (GTK_WINDOW (self));
2615 g_signal_emit (self, signals[SIG_INHIBIT], 0, FALSE);
2617 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2618 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2620 /* Create the video input and then turn on the camera
2621 * menu, so that the active camera gets marked as such.
2623 if (priv->video_input == NULL)
2624 create_video_input (self);
2625 empathy_camera_menu_set_sensitive (priv->camera_menu, TRUE);
2627 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2629 if (priv->call_state == CONNECTING)
2630 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2632 if (priv->call_state != REDIALING)
2633 priv->call_state = DISCONNECTED;
2635 /* Show the toolbar */
2636 clutter_state_set_state (priv->transitions, "fade-in");
2638 if (could_reset_pipeline)
2640 g_mutex_lock (&priv->lock);
2642 g_timer_stop (priv->timer);
2644 if (priv->timer_id != 0)
2645 g_source_remove (priv->timer_id);
2648 g_mutex_unlock (&priv->lock);
2651 /* We are about to destroy the window, no need to update it or create
2652 * a video preview */
2655 empathy_call_window_status_message (self, _("Disconnected"));
2657 empathy_call_window_show_hangup_button (self, FALSE);
2659 /* Unsensitive the camera and mic button */
2660 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2661 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2663 /* Be sure that the mic button is enabled */
2664 empathy_audio_src_set_mute (
2665 EMPATHY_GST_AUDIO_SRC (self->priv->audio_input), FALSE);
2667 if (priv->camera_state == CAMERA_STATE_ON)
2669 /* Restart the preview with the new pipeline. */
2670 display_video_preview (self, TRUE);
2673 /* destroy the video output; it will be recreated when we'll redial */
2674 disconnect_video_output_motion_handler (self);
2675 if (priv->video_output != NULL)
2676 clutter_actor_destroy (priv->video_output);
2677 priv->video_output = NULL;
2678 if (priv->got_video_src > 0)
2680 g_source_remove (priv->got_video_src);
2681 priv->got_video_src = 0;
2684 gtk_widget_show (priv->remote_user_avatar_widget);
2686 reset_details_pane (self);
2688 priv->sending_video = FALSE;
2689 priv->call_started = FALSE;
2691 could_disconnect = TRUE;
2693 /* TODO: display the self avatar of the preview (depends if the "Always
2694 * Show Video Preview" is enabled or not) */
2697 return could_disconnect;
2702 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2705 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2706 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2708 if (empathy_call_window_disconnected (self, TRUE) &&
2709 priv->call_state == REDIALING)
2710 empathy_call_window_restart_call (self);
2714 empathy_call_window_content_is_raw (TfContent *content)
2716 FsConference *conference;
2719 g_object_get (content, "fs-conference", &conference, NULL);
2720 g_assert (conference != NULL);
2722 /* FIXME: Ugly hack, update when moving a packetization property into
2724 israw = g_str_has_prefix (GST_OBJECT_NAME (conference), "fsrawconf");
2725 gst_object_unref (conference);
2731 empathy_call_window_content_removed_cb (EmpathyCallHandler *handler,
2733 EmpathyCallWindow *self)
2735 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2736 FsMediaType media_type;
2738 DEBUG ("removing content");
2740 g_object_get (content, "media-type", &media_type, NULL);
2743 * This assumes that there is only one video stream per channel...
2746 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2748 if (priv->funnel != NULL)
2752 output = priv->video_output_sink;
2754 gst_element_set_state (output, GST_STATE_NULL);
2755 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2757 gst_bin_remove (GST_BIN (priv->pipeline), output);
2758 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2759 priv->funnel = NULL;
2762 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2764 if (priv->audio_output != NULL)
2766 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2768 if (priv->audio_output_added)
2769 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2770 priv->audio_output = NULL;
2771 priv->audio_output_added = FALSE;
2776 g_assert_not_reached ();
2783 empathy_call_window_framerate_changed_cb (EmpathyCallHandler *handler,
2785 EmpathyCallWindow *self)
2787 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2789 DEBUG ("Framerate changed to %u", framerate);
2791 if (priv->video_input != NULL)
2792 empathy_video_src_set_framerate (priv->video_input, framerate);
2796 empathy_call_window_resolution_changed_cb (EmpathyCallHandler *handler,
2799 EmpathyCallWindow *self)
2801 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2803 DEBUG ("Resolution changed to %ux%u", width, height);
2805 if (priv->video_input != NULL)
2807 empathy_video_src_set_resolution (priv->video_input, width, height);
2811 /* Called with global lock held */
2813 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2815 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2819 if (priv->funnel == NULL)
2821 output = priv->video_output_sink;
2822 priv->funnel = gst_element_factory_make ("funnel", NULL);
2826 g_warning ("Could not create video funnel");
2830 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2832 gst_object_unref (priv->funnel);
2833 priv->funnel = NULL;
2834 g_warning ("Could not add funnel to pipeline");
2838 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2840 g_warning ("Could not add the video output widget to the pipeline");
2844 if (!gst_element_link (priv->funnel, output))
2846 g_warning ("Could not link output sink to funnel");
2847 goto error_output_added;
2850 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2852 g_warning ("Could not start video sink");
2853 goto error_output_added;
2856 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2858 g_warning ("Could not start funnel");
2859 goto error_output_added;
2862 pad = gst_element_get_request_pad (priv->funnel, "sink_%u");
2865 g_warning ("Could not get request pad from funnel");
2872 gst_element_set_locked_state (priv->funnel, TRUE);
2873 gst_element_set_locked_state (output, TRUE);
2875 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2876 gst_element_set_state (output, GST_STATE_NULL);
2878 gst_bin_remove (GST_BIN (priv->pipeline), output);
2879 gst_element_set_locked_state (output, FALSE);
2883 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2884 priv->funnel = NULL;
2889 /* Called with global lock held */
2891 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self,
2894 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2896 GstPadTemplate *template;
2898 if (!priv->audio_output_added)
2900 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2902 g_warning ("Could not add audio sink to pipeline");
2903 g_object_unref (priv->audio_output);
2904 goto error_add_output;
2907 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2909 g_warning ("Could not start audio sink");
2912 priv->audio_output_added = TRUE;
2915 template = gst_element_class_get_pad_template (
2916 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2918 pad = gst_element_request_pad (priv->audio_output,
2919 template, NULL, NULL);
2923 g_warning ("Could not get sink pad from sink");
2930 gst_element_set_locked_state (priv->audio_output, TRUE);
2931 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2932 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2933 priv->audio_output = NULL;
2941 empathy_call_window_update_timer (gpointer user_data)
2943 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2944 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2945 const gchar *status;
2949 time_ = g_timer_elapsed (priv->timer, NULL);
2951 if (priv->call_state == HELD)
2952 status = _("On hold");
2953 else if (priv->call_state == DISCONNECTED)
2954 status = _("Disconnected");
2955 else if (priv->muted)
2958 status = _("Duration");
2960 /* Translators: 'status - minutes:seconds' the caller has been connected */
2961 str = g_strdup_printf (_("%s — %d:%02dm"),
2963 (int) time_ / 60, (int) time_ % 60);
2964 empathy_call_window_status_message (self, str);
2972 EMP_RESPONSE_BALANCE
2976 on_error_infobar_response_cb (GtkInfoBar *info_bar,
2980 switch (response_id)
2982 case GTK_RESPONSE_CLOSE:
2983 gtk_widget_destroy (GTK_WIDGET (info_bar));
2985 case EMP_RESPONSE_BALANCE:
2986 empathy_url_show (GTK_WIDGET (info_bar),
2987 g_object_get_data (G_OBJECT (info_bar), "uri"));
2993 display_error (EmpathyCallWindow *self,
2997 const gchar *details,
2998 const gchar *button_text,
3000 gint button_response)
3002 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3003 GtkWidget *info_bar;
3004 GtkWidget *content_area;
3011 /* Create info bar */
3012 info_bar = gtk_info_bar_new ();
3014 if (button_text != NULL)
3016 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
3017 button_text, button_response);
3018 g_object_set_data_full (G_OBJECT (info_bar),
3019 "uri", g_strdup (uri), g_free);
3022 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
3023 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
3025 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
3027 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
3029 /* hbox containing the image and the messages vbox */
3030 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
3031 gtk_container_add (GTK_CONTAINER (content_area), hbox);
3034 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
3035 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
3037 /* vbox containing the main message and the details expander */
3038 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
3039 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
3042 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
3044 label = gtk_label_new (NULL);
3045 gtk_label_set_markup (GTK_LABEL (label), txt);
3046 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
3047 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
3050 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
3053 if (details != NULL)
3055 GtkWidget *expander;
3057 expander = gtk_expander_new (_("Technical Details"));
3059 txt = g_strdup_printf ("<i>%s</i>", details);
3061 label = gtk_label_new (NULL);
3062 gtk_label_set_markup (GTK_LABEL (label), txt);
3063 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
3064 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
3067 gtk_container_add (GTK_CONTAINER (expander), label);
3068 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
3071 g_signal_connect (info_bar, "response",
3072 G_CALLBACK (on_error_infobar_response_cb), NULL);
3074 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
3075 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
3076 gtk_widget_show_all (info_bar);
3081 media_stream_error_to_txt (EmpathyCallWindow *self,
3082 TpCallChannel *call,
3084 TpMediaStreamError error)
3086 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3087 const gchar *cm = NULL;
3093 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
3095 return g_strdup_printf (
3096 _("%s's software does not understand any of the audio formats "
3097 "supported by your computer"),
3098 empathy_contact_get_alias (priv->contact));
3100 return g_strdup_printf (
3101 _("%s's software does not understand any of the video formats "
3102 "supported by your computer"),
3103 empathy_contact_get_alias (priv->contact));
3105 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
3106 return g_strdup_printf (
3107 _("Can't establish a connection to %s. "
3108 "One of you might be on a network that does not allow "
3109 "direct connections."),
3110 empathy_contact_get_alias (priv->contact));
3112 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
3113 return g_strdup (_("There was a failure on the network"));
3115 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
3117 return g_strdup (_("The audio formats necessary for this call "
3118 "are not installed on your computer"));
3120 return g_strdup (_("The video formats necessary for this call "
3121 "are not installed on your computer"));
3123 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
3124 tp_connection_parse_object_path (
3125 tp_channel_get_connection (TP_CHANNEL (call)),
3128 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
3129 "product=Telepathy&component=%s", cm);
3131 result = g_strdup_printf (
3132 _("Something unexpected happened in a Telepathy component. "
3133 "Please <a href=\"%s\">report this bug</a> and attach "
3134 "logs gathered from the 'Debug' window in the Help menu."), url);
3140 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
3141 return g_strdup (_("There was a failure in the call engine"));
3143 case TP_MEDIA_STREAM_ERROR_EOS:
3144 return g_strdup (_("The end of the stream was reached"));
3146 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
3153 empathy_call_window_stream_error (EmpathyCallWindow *self,
3154 TpCallChannel *call,
3163 desc = media_stream_error_to_txt (self, call, audio, code);
3166 /* No description, use the error message. That's not great as it's not
3167 * localized but it's better than nothing. */
3168 display_error (self, call, icon, title, msg, NULL);
3172 display_error (self, call, icon, title, desc, msg);
3178 empathy_call_window_audio_stream_error (TpCallChannel *call,
3181 EmpathyCallWindow *self)
3183 empathy_call_window_stream_error (self, call, TRUE, code, msg,
3184 "gnome-stock-mic", _("Can't establish audio stream"));
3188 empathy_call_window_video_stream_error (TpCallChannel *call,
3191 EmpathyCallWindow *self)
3193 empathy_call_window_stream_error (self, call, FALSE, code, msg,
3194 "camera-web", _("Can't establish video stream"));
3199 show_balance_error (EmpathyCallWindow *self)
3203 gchar *balance, *tmp;
3204 const gchar *uri, *currency;
3208 g_object_get (self->priv->handler,
3209 "call-channel", &call,
3212 conn = tp_channel_get_connection (call);
3213 g_object_unref (call);
3215 uri = tp_connection_get_balance_uri (conn);
3217 if (!tp_connection_get_balance (conn, &amount, &scale, ¤cy))
3219 /* unknown balance */
3220 balance = g_strdup ("(--)");
3224 char *money = empathy_format_currency (amount, scale, currency);
3226 balance = g_strdup_printf ("%s %s",
3231 tmp = g_strdup_printf (_("Your current balance is %s."), balance),
3233 display_error (self,
3235 _("Sorry, you don’t have enough credit for that call."),
3239 EMP_RESPONSE_BALANCE);
3246 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
3249 EmpathyCallWindow *self)
3251 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3252 TpCallChannel *call;
3253 gboolean can_send_video;
3255 if (state == TP_CALL_STATE_ENDED)
3257 DEBUG ("Call ended: %s", (reason != NULL && reason[0] != '\0') ? reason : "unspecified reason");
3258 empathy_call_window_disconnected (self, TRUE);
3259 if (!tp_strdiff (reason, TP_ERROR_STR_INSUFFICIENT_BALANCE))
3260 show_balance_error (self);
3264 if (state != TP_CALL_STATE_ACCEPTED)
3267 if (priv->call_state == CONNECTED)
3270 g_timer_start (priv->timer);
3271 priv->call_state = CONNECTED;
3273 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3275 can_send_video = priv->video_input != NULL &&
3276 empathy_contact_can_voip_video (priv->contact) &&
3277 tpaw_camera_monitor_get_available (priv->camera_monitor);
3279 g_object_get (priv->handler, "call-channel", &call, NULL);
3281 if (tp_call_channel_has_dtmf (call))
3282 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
3284 if (priv->video_input == NULL)
3285 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
3287 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
3289 empathy_call_window_show_hangup_button (self, TRUE);
3291 gtk_widget_set_sensitive (priv->mic_button, TRUE);
3293 clutter_actor_hide (priv->video_output);
3294 gtk_widget_show (priv->remote_user_avatar_widget);
3296 g_object_unref (call);
3298 g_mutex_lock (&priv->lock);
3300 priv->timer_id = g_timeout_add_seconds (1,
3301 empathy_call_window_update_timer, self);
3303 g_mutex_unlock (&priv->lock);
3305 empathy_call_window_update_timer (self);
3307 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
3311 empathy_call_window_show_video_output_cb (gpointer user_data)
3313 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3315 if (self->priv->video_output != NULL)
3317 gtk_widget_hide (self->priv->remote_user_avatar_widget);
3318 clutter_actor_show (self->priv->video_output);
3319 clutter_actor_raise_top (self->priv->overlay_bin);
3326 empathy_call_window_check_video_cb (gpointer data)
3328 EmpathyCallWindow *self = data;
3330 if (self->priv->got_video)
3332 self->priv->got_video = FALSE;
3336 /* No video in the last N seconds, display the remote avatar */
3337 empathy_call_window_show_video_output (self, FALSE);
3342 /* Called from the streaming thread */
3343 static GstPadProbeReturn
3344 empathy_call_window_video_probe_cb (GstPad *pad,
3345 GstPadProbeInfo *info,
3348 EmpathyCallWindow *self = user_data;
3350 if (G_UNLIKELY (!self->priv->got_video))
3352 /* show the remote video */
3353 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3354 empathy_call_window_show_video_output_cb,
3355 g_object_ref (self), g_object_unref);
3357 self->priv->got_video = TRUE;
3360 return GST_PAD_PROBE_OK;
3363 /* Called from the streaming thread */
3365 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
3366 TfContent *content, GstPad *src, gpointer user_data)
3368 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3369 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3370 gboolean retval = FALSE;
3375 g_mutex_lock (&priv->lock);
3377 g_object_get (content, "media-type", &media_type, NULL);
3381 case TP_MEDIA_STREAM_TYPE_AUDIO:
3382 pad = empathy_call_window_get_audio_sink_pad (self, content);
3384 case TP_MEDIA_STREAM_TYPE_VIDEO:
3385 g_idle_add (empathy_call_window_show_video_output_cb, self);
3386 pad = empathy_call_window_get_video_sink_pad (self);
3388 gst_pad_add_probe (src,
3389 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_BUFFER_LIST,
3390 empathy_call_window_video_probe_cb, self, NULL);
3392 if (priv->got_video_src > 0)
3393 g_source_remove (priv->got_video_src);
3394 priv->got_video_src = g_timeout_add_seconds (1,
3395 empathy_call_window_check_video_cb, self);
3398 g_assert_not_reached ();
3404 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
3405 g_warning ("Could not link %s sink pad",
3406 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
3410 gst_object_unref (pad);
3414 /* If no sink could be linked, try to add fakesink to prevent the whole call
3419 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
3421 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
3423 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
3424 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
3425 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
3427 gst_element_set_locked_state (fakesink, TRUE);
3428 gst_element_set_state (fakesink, GST_STATE_NULL);
3429 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
3433 DEBUG ("Could not link real sink, linked fakesink instead");
3435 gst_object_unref (sinkpad);
3439 gst_object_unref (fakesink);
3444 g_mutex_unlock (&priv->lock);
3450 empathy_call_window_prepare_audio_output (EmpathyCallWindow *self,
3453 EmpathyCallWindowPriv *priv = self->priv;
3455 g_assert (priv->audio_output_added == FALSE);
3456 g_assert (priv->audio_output == FALSE);
3458 priv->audio_output = empathy_audio_sink_new ();
3459 g_object_ref_sink (priv->audio_output);
3461 /* volume button to output volume linking */
3462 g_object_bind_property (priv->audio_output, "volume",
3463 priv->volume_button, "value",
3464 G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
3466 g_object_bind_property_full (content, "requested-output-volume",
3467 priv->audio_output, "volume",
3469 audio_control_volume_to_element,
3470 element_volume_to_audio_control,
3473 /* Link volumes together, sync the current audio input volume property
3474 * back to farstream first */
3475 g_object_bind_property_full (priv->audio_output, "volume",
3476 content, "reported-output-volume",
3477 G_BINDING_SYNC_CREATE,
3478 element_volume_to_audio_control,
3479 audio_control_volume_to_element,
3482 /* For raw audio conferences assume that the producer of the raw data
3483 * has already processed it, so turn off any echo cancellation and any
3484 * other audio improvements that come with it */
3485 empathy_audio_sink_set_echo_cancel (
3486 EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3487 !empathy_call_window_content_is_raw (content));
3492 empathy_call_window_content_added_cb (EmpathyCallHandler *handler,
3493 TfContent *content, gpointer user_data)
3495 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3496 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3498 FsMediaType media_type;
3499 gboolean retval = FALSE;
3501 g_object_get (content, "media-type", &media_type, "sink-pad", &sink, NULL);
3502 g_assert (sink != NULL);
3506 case FS_MEDIA_TYPE_AUDIO:
3508 /* For raw audio conferences assume that the receiver of the raw data
3509 * wants it unprocessed, so turn off any echo cancellation and any
3510 * other audio improvements that come with it */
3511 empathy_audio_src_set_echo_cancel (
3512 EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3513 !empathy_call_window_content_is_raw (content));
3515 /* Link volumes together, sync the current audio input volume property
3516 * back to farstream first */
3517 g_object_bind_property_full (content, "requested-input-volume",
3518 priv->audio_input, "volume",
3520 audio_control_volume_to_element,
3521 element_volume_to_audio_control,
3524 g_object_bind_property_full (priv->audio_input, "volume",
3525 content, "reported-input-volume",
3526 G_BINDING_SYNC_CREATE,
3527 element_volume_to_audio_control,
3528 audio_control_volume_to_element,
3531 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
3533 g_warning ("Could not add audio source to pipeline");
3537 pad = gst_element_get_static_pad (priv->audio_input, "src");
3540 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3541 g_warning ("Could not get source pad from audio source");
3545 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3547 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3548 gst_object_unref (pad);
3549 g_warning ("Could not link audio source to farsight");
3552 gst_object_unref (pad);
3554 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3556 g_warning ("Could not start audio source");
3557 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3558 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3562 /* Prepare our audio output, not added yet though */
3563 empathy_call_window_prepare_audio_output (self, content);
3567 case FS_MEDIA_TYPE_VIDEO:
3568 if (priv->video_tee != NULL)
3570 pad = gst_element_get_request_pad (priv->video_tee, "src_%u");
3571 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3573 g_warning ("Could not link video source input pipeline");
3576 gst_object_unref (pad);
3582 g_assert_not_reached ();
3585 gst_object_unref (sink);
3590 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3592 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3593 GstElement *preview;
3595 disable_camera (self);
3597 DEBUG ("remove video input");
3598 preview = priv->video_preview_sink;
3600 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3601 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3602 gst_element_set_state (preview, GST_STATE_NULL);
3604 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3607 g_object_unref (priv->video_input);
3608 priv->video_input = NULL;
3609 g_object_unref (priv->video_tee);
3610 priv->video_tee = NULL;
3611 clutter_actor_destroy (priv->video_preview);
3612 priv->video_preview = NULL;
3614 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3615 empathy_camera_menu_set_sensitive (priv->camera_menu, FALSE);
3619 start_call (EmpathyCallWindow *self)
3621 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3623 g_signal_emit (self, signals[SIG_INHIBIT], 0, TRUE);
3625 priv->call_started = TRUE;
3626 empathy_call_handler_start_call (priv->handler,
3627 gtk_get_current_event_time ());
3629 if (empathy_call_handler_has_initial_video (priv->handler))
3631 TpCallChannel *call;
3634 g_object_get (priv->handler, "call-channel", &call, NULL);
3635 /* If the call channel isn't set yet we're requesting it, if we're
3636 * requesting it with initial video it should be PENDING_SEND when we get
3639 s = TP_SENDING_STATE_PENDING_SEND;
3641 s = empathy_call_channel_get_video_state (call);
3643 if (s == TP_SENDING_STATE_PENDING_SEND ||
3644 s == TP_SENDING_STATE_SENDING)
3646 /* Enable 'send video' buttons and display the preview */
3647 gtk_toggle_button_set_active (
3648 GTK_TOGGLE_BUTTON (priv->camera_button), TRUE);
3652 gtk_toggle_button_set_active (
3653 GTK_TOGGLE_BUTTON (priv->camera_button), FALSE);
3655 if (priv->video_preview == NULL)
3657 create_video_preview (self);
3658 add_video_preview_to_pipeline (self);
3663 g_object_unref (call);
3668 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3671 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3672 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3673 GstState newstate, pending;
3675 empathy_call_handler_bus_message (priv->handler, bus, message);
3677 switch (GST_MESSAGE_TYPE (message))
3679 case GST_MESSAGE_STATE_CHANGED:
3680 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3682 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3684 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3685 !priv->call_started)
3687 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3688 if (newstate == GST_STATE_PAUSED)
3690 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3691 priv->pipeline_playing = TRUE;
3693 if (priv->start_call_when_playing)
3697 if (priv->video_preview_sink != NULL &&
3698 GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_preview_sink))
3700 gst_message_parse_state_changed (message, NULL, &newstate,
3703 if (newstate == GST_STATE_PLAYING &&
3704 pending == GST_STATE_VOID_PENDING)
3705 empathy_call_window_stop_camera_spinning (self);
3708 case GST_MESSAGE_ERROR:
3710 GError *error = NULL;
3711 GstElement *gst_error;
3715 gst_message_parse_error (message, &error, &debug);
3716 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3718 g_message ("Element error: %s -- %s\n", error->message, debug);
3720 name = gst_element_get_name (gst_error);
3721 if (g_str_has_prefix (name, VIDEO_INPUT_ERROR_PREFIX))
3723 /* Remove the video input and continue */
3724 if (priv->video_input != NULL)
3725 empathy_call_window_remove_video_input (self);
3726 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3730 empathy_call_window_disconnected (self, TRUE);
3733 g_error_free (error);
3736 case GST_MESSAGE_UNKNOWN:
3737 case GST_MESSAGE_EOS:
3738 case GST_MESSAGE_WARNING:
3739 case GST_MESSAGE_INFO:
3740 case GST_MESSAGE_TAG:
3741 case GST_MESSAGE_BUFFERING:
3742 case GST_MESSAGE_STATE_DIRTY:
3743 case GST_MESSAGE_STEP_DONE:
3744 case GST_MESSAGE_CLOCK_PROVIDE:
3745 case GST_MESSAGE_CLOCK_LOST:
3746 case GST_MESSAGE_NEW_CLOCK:
3747 case GST_MESSAGE_STRUCTURE_CHANGE:
3748 case GST_MESSAGE_STREAM_STATUS:
3749 case GST_MESSAGE_APPLICATION:
3750 case GST_MESSAGE_ELEMENT:
3751 case GST_MESSAGE_SEGMENT_START:
3752 case GST_MESSAGE_SEGMENT_DONE:
3753 case GST_MESSAGE_DURATION:
3754 case GST_MESSAGE_ANY:
3763 empathy_call_window_members_changed_cb (TpCallChannel *call,
3764 GHashTable *updates,
3766 TpCallStateReason *reason,
3767 EmpathyCallWindow *self)
3769 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3770 GHashTableIter iter;
3771 gpointer key, value;
3772 gboolean held = FALSE;
3774 g_hash_table_iter_init (&iter, updates);
3775 while (g_hash_table_iter_next (&iter, &key, &value))
3777 if (GPOINTER_TO_INT (value) & TP_CALL_MEMBER_FLAG_HELD)
3779 /* This assumes this is a 1-1 call, otherwise one participant
3780 * putting the call on hold wouldn't mean the call is on hold
3788 priv->call_state = HELD;
3789 else if (priv->call_state == HELD)
3790 priv->call_state = CONNECTED;
3794 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3796 EmpathyCallWindow *self)
3798 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3799 TpCallChannel *call;
3801 g_object_get (priv->handler, "call-channel", &call, NULL);
3806 tp_g_signal_connect_object (call, "audio-stream-error",
3807 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3808 tp_g_signal_connect_object (call, "video-stream-error",
3809 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3812 tp_g_signal_connect_object (call, "members-changed",
3813 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3815 g_object_unref (call);
3819 empathy_call_window_connect_handler (EmpathyCallWindow *self)
3821 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3822 TpCallChannel *call;
3824 g_signal_connect (priv->handler, "state-changed",
3825 G_CALLBACK (empathy_call_window_state_changed_cb), self);
3826 g_signal_connect (priv->handler, "conference-added",
3827 G_CALLBACK (empathy_call_window_conference_added_cb), self);
3828 g_signal_connect (priv->handler, "conference-removed",
3829 G_CALLBACK (empathy_call_window_conference_removed_cb), self);
3830 g_signal_connect (priv->handler, "closed",
3831 G_CALLBACK (empathy_call_window_channel_closed_cb), self);
3832 g_signal_connect (priv->handler, "src-pad-added",
3833 G_CALLBACK (empathy_call_window_src_added_cb), self);
3834 g_signal_connect (priv->handler, "content-added",
3835 G_CALLBACK (empathy_call_window_content_added_cb), self);
3836 g_signal_connect (priv->handler, "content-removed",
3837 G_CALLBACK (empathy_call_window_content_removed_cb), self);
3839 /* We connect to ::call-channel unconditionally since we'll
3840 * get new channels if we hangup and redial or if we reuse the
3842 g_signal_connect (priv->handler, "notify::call-channel",
3843 G_CALLBACK (call_handler_notify_call_cb), self);
3845 g_signal_connect (priv->handler, "framerate-changed",
3846 G_CALLBACK (empathy_call_window_framerate_changed_cb), self);
3847 g_signal_connect (priv->handler, "resolution-changed",
3848 G_CALLBACK (empathy_call_window_resolution_changed_cb), self);
3850 g_object_get (priv->handler, "call-channel", &call, NULL);
3853 /* We won't get notify::call-channel for this channel, so
3854 * directly call the callback. */
3855 call_handler_notify_call_cb (priv->handler, NULL, self);
3856 g_object_unref (call);
3861 empathy_call_window_realized_cb (GtkWidget *widget,
3862 EmpathyCallWindow *self)
3866 /* Make the hangup button twice as wide */
3867 width = gtk_widget_get_allocated_width (self->priv->hangup_button);
3868 gtk_widget_set_size_request (self->priv->hangup_button, width * 2, -1);
3870 empathy_call_window_connect_handler (self);
3872 gst_element_set_state (self->priv->pipeline, GST_STATE_PAUSED);
3876 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3877 EmpathyCallWindow *window)
3879 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3881 if (priv->pipeline != NULL)
3883 if (priv->bus_message_source_id != 0)
3885 g_source_remove (priv->bus_message_source_id);
3886 priv->bus_message_source_id = 0;
3889 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3892 if (priv->call_state == CONNECTING)
3893 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3899 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3902 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3904 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3909 gtk_widget_hide (priv->dtmf_panel);
3910 gtk_widget_hide (menu);
3911 gtk_widget_hide (priv->toolbar);
3915 if (priv->dialpad_was_visible_before_fs)
3916 gtk_widget_show (priv->dtmf_panel);
3918 gtk_widget_show (menu);
3919 gtk_widget_show (priv->toolbar);
3921 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3922 priv->original_height_before_fs);
3927 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3929 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3931 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3932 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3934 if (priv->video_output != NULL)
3937 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3938 priv->video_output, TRUE, TRUE,
3939 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3946 empathy_call_window_state_event_cb (GtkWidget *widget,
3947 GdkEventWindowState *event, EmpathyCallWindow *window)
3949 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3951 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3952 gboolean set_fullscreen = event->new_window_state &
3953 GDK_WINDOW_STATE_FULLSCREEN;
3957 gboolean dialpad_was_visible;
3958 GtkAllocation allocation;
3959 gint original_width, original_height;
3961 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3962 original_width = allocation.width;
3963 original_height = allocation.height;
3965 g_object_get (priv->dtmf_panel,
3966 "visible", &dialpad_was_visible,
3969 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3970 priv->original_width_before_fs = original_width;
3971 priv->original_height_before_fs = original_height;
3973 if (priv->video_output_motion_handler_id == 0 &&
3974 priv->video_output != NULL)
3976 priv->video_output_motion_handler_id = g_signal_connect (
3977 G_OBJECT (priv->video_container), "motion-notify-event",
3978 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3984 disconnect_video_output_motion_handler (window);
3987 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3989 show_controls (window, set_fullscreen);
3990 show_borders (window, set_fullscreen);
3991 gtk_action_set_stock_id (priv->menu_fullscreen,
3992 (set_fullscreen ? "view-restore" : "view-fullscreen"));
3993 priv->is_fullscreen = set_fullscreen;
4000 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
4003 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4004 int w, h, dialpad_width;
4005 GtkAllocation allocation;
4007 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
4008 w = allocation.width;
4009 h = allocation.height;
4011 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
4015 gtk_widget_show (priv->dtmf_panel);
4021 gtk_widget_hide (priv->dtmf_panel);
4025 gtk_window_resize (GTK_WINDOW (window), w, h);
4029 empathy_call_window_set_send_video (EmpathyCallWindow *window,
4032 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4033 TpCallChannel *call;
4035 priv->sending_video = (state == CAMERA_STATE_ON);
4037 if (state == CAMERA_STATE_ON)
4039 /* When we start sending video, we want to show the video preview by
4041 display_video_preview (window, TRUE);
4045 display_video_preview (window, FALSE);
4048 if (priv->call_state != CONNECTED)
4051 g_object_get (priv->handler, "call-channel", &call, NULL);
4052 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
4053 empathy_call_channel_send_video (call, priv->sending_video);
4054 g_object_unref (call);
4058 empathy_call_window_hangup_cb (gpointer object,
4059 EmpathyCallWindow *self)
4061 /* stopping the call will put it the ENDED state and
4062 * from state_changed_cb we'll reconfigure the window
4064 empathy_call_handler_stop_call (self->priv->handler);
4068 empathy_call_window_restart_call (EmpathyCallWindow *window)
4070 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4072 /* Remove error info bars */
4073 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
4074 (GtkCallback) gtk_widget_destroy, NULL);
4076 create_video_output_widget (window);
4077 priv->outgoing = TRUE;
4078 empathy_call_window_set_state_connecting (window);
4080 if (priv->pipeline_playing)
4081 start_call (window);
4083 /* call will be started when the pipeline is ready */
4084 priv->start_call_when_playing = TRUE;
4086 empathy_call_window_setup_avatars (window, priv->handler);
4088 empathy_call_window_show_hangup_button (window, TRUE);
4092 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
4093 EmpathyCallWindow *window)
4097 active = gtk_toggle_tool_button_get_active (button);
4099 empathy_call_window_show_dialpad (window, active);
4103 empathy_call_window_fullscreen_cb (gpointer object,
4104 EmpathyCallWindow *window)
4106 empathy_call_window_fullscreen_toggle (window);
4110 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
4112 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4114 if (priv->is_fullscreen)
4115 gtk_window_unfullscreen (GTK_WINDOW (window));
4117 gtk_window_fullscreen (GTK_WINDOW (window));
4121 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
4122 GdkEventButton *event, EmpathyCallWindow *window)
4124 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
4126 empathy_call_window_video_menu_popup (window, event->button);
4134 empathy_call_window_key_press_cb (GtkWidget *video_output,
4135 GdkEventKey *event, EmpathyCallWindow *window)
4137 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4140 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
4142 /* Since we are in fullscreen mode, toggling will bring us back to
4144 empathy_call_window_fullscreen_toggle (window);
4148 key = gdk_keyval_to_unicode (event->keyval);
4169 gtk_toggle_tool_button_set_active (
4170 GTK_TOGGLE_TOOL_BUTTON (priv->dialpad_button), TRUE);
4172 empathy_dialpad_widget_press_key (
4173 EMPATHY_DIALPAD_WIDGET (priv->dtmf_panel), key);
4179 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
4180 GdkEventMotion *event, EmpathyCallWindow *window)
4182 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4184 if (priv->is_fullscreen)
4186 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
4188 /* Show the bottom toolbar */
4189 empathy_call_window_motion_notify_cb (NULL, NULL, window);
4196 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
4200 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4202 menu = gtk_ui_manager_get_widget (priv->ui_manager,
4204 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
4205 button, gtk_get_current_event_time ());
4206 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
4210 empathy_call_window_status_message (EmpathyCallWindow *self,
4213 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
4217 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
4219 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4221 return priv->ui_manager;
4224 EmpathyGstAudioSrc *
4225 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
4227 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4229 return (EmpathyGstAudioSrc *) priv->audio_input;
4232 EmpathyGstVideoSrc *
4233 empathy_call_window_get_video_src (EmpathyCallWindow *self)
4235 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);
4239 empathy_call_window_change_webcam (EmpathyCallWindow *self,
4240 const gchar *device)
4242 EmpathyGstVideoSrc *video;
4245 /* Restart the camera only if it's already running */
4246 running = (self->priv->video_preview != NULL);
4247 video = empathy_call_window_get_video_src (self);
4250 empathy_call_window_play_camera (self, FALSE);
4252 empathy_video_src_change_device (video, device);
4255 empathy_call_window_play_camera (self, TRUE);