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>
34 #include "empathy-about-dialog.h"
35 #include "empathy-audio-sink.h"
36 #include "empathy-call-utils.h"
37 #include "empathy-call-window-fullscreen.h"
38 #include "empathy-camera-menu.h"
39 #include "empathy-dialpad-widget.h"
40 #include "empathy-geometry.h"
41 #include "empathy-gsettings.h"
42 #include "empathy-images.h"
43 #include "empathy-mic-menu.h"
44 #include "empathy-preferences.h"
45 #include "empathy-request-util.h"
46 #include "empathy-rounded-actor.h"
47 #include "empathy-rounded-rectangle.h"
48 #include "empathy-rounded-texture.h"
49 #include "empathy-sound-manager.h"
50 #include "empathy-ui-utils.h"
51 #include "empathy-utils.h"
53 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
54 #include "empathy-debug.h"
56 #define CONTENT_HBOX_SPACING 3
57 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 0
58 #define OVERLAY_MARGIN 6
60 #define REMOTE_VIDEO_DEFAULT_WIDTH 320
61 #define REMOTE_VIDEO_DEFAULT_HEIGHT 240
63 #define SELF_VIDEO_SECTION_WIDTH 120
64 #define SELF_VIDEO_SECTION_HEIGHT 90
65 #define SELF_VIDEO_SECTION_MARGIN 2
66 #define SELF_VIDEO_SECTION_BORDER SELF_VIDEO_SECTION_MARGIN*2
68 /* The avatar's default width and height are set to the same value because we
69 want a square icon. */
70 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT REMOTE_VIDEO_DEFAULT_HEIGHT
71 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH REMOTE_VIDEO_DEFAULT_HEIGHT
73 #define SMALL_TOOLBAR_SIZE 36
75 /* If an video input error occurs, the error message will start with "v4l" */
76 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
78 /* The time interval in milliseconds between 2 outgoing rings */
79 #define MS_BETWEEN_RING 500
81 /* The roundedness of preview box and placeholders */
82 #define PREVIEW_ROUND_FACTOR 16
84 #define PREVIEW_BUTTON_OPACITY 180
86 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
89 PROP_CALL_HANDLER = 1,
97 static guint signals[LAST_SIGNAL];
100 RINGING, /* Incoming call */
101 CONNECTING, /* Outgoing call */
102 CONNECTED, /* Connected */
103 HELD, /* Connected, but on hold */
104 DISCONNECTED, /* Disconnected */
105 REDIALING /* Redialing (special case of CONNECTING) */
109 CAMERA_STATE_OFF = 0,
115 PREVIEW_POS_TOP_LEFT,
116 PREVIEW_POS_TOP_RIGHT,
117 PREVIEW_POS_BOTTOM_LEFT,
118 PREVIEW_POS_BOTTOM_RIGHT,
121 struct _EmpathyCallWindowPriv
123 gboolean dispose_has_run;
124 EmpathyCallHandler *handler;
126 EmpathyContact *contact;
128 TpawCameraMonitor *camera_monitor;
130 CallState call_state;
133 GtkUIManager *ui_manager;
134 GtkWidget *errors_vbox;
135 /* widget displays the video received from the remote user. This widget is
136 * alive only during call. */
137 ClutterActor *video_output;
138 ClutterActor *video_preview;
139 ClutterActor *drag_preview;
140 ClutterActor *preview_shown_button;
141 ClutterActor *preview_hidden_button;
142 ClutterActor *preview_rectangle1;
143 ClutterActor *preview_rectangle2;
144 ClutterActor *preview_rectangle3;
145 ClutterActor *preview_rectangle4;
146 ClutterActor *preview_spinner_actor;
147 GtkWidget *preview_spinner_widget;
148 GtkWidget *video_container;
149 GtkWidget *remote_user_avatar_widget;
150 GtkWidget *remote_user_avatar_toolbar;
151 GtkWidget *remote_user_name_toolbar;
152 GtkWidget *remote_user_status_toolbar;
153 GtkWidget *status_label;
154 GtkWidget *hangup_button;
155 GtkWidget *audio_call_button;
156 GtkWidget *video_call_button;
157 GtkWidget *mic_button;
158 GtkWidget *microphone_icon;
159 GtkWidget *volume_button;
160 GtkWidget *camera_button;
161 GtkWidget *dialpad_button;
163 GtkWidget *bottom_toolbar;
164 ClutterActor *floating_toolbar;
166 GtkAction *menu_fullscreen;
167 GtkAction *menu_swap_camera;
169 ClutterState *transitions;
171 /* The main box covering all the stage, contaning remote avatar/video */
172 ClutterActor *video_box;
173 ClutterLayoutManager *video_layout;
175 /* A bin layout manager containing a bin for previews
176 * and the floating toolbar */
177 ClutterActor *overlay_bin;
178 ClutterLayoutManager *overlay_layout;
180 /* Bin layout for the previews */
181 ClutterActor *preview_box;
182 ClutterLayoutManager *preview_layout;
184 /* Coordinates of the preview drag event's start. */
185 PreviewPosition preview_pos;
187 /* We keep a reference on the hbox which contains the main content so we can
188 easilly repack everything when toggling fullscreen */
189 GtkWidget *content_hbox;
191 /* These are used to accept or reject an incoming call when the status
193 GtkWidget *incoming_call_dialog;
194 TpCallChannel *pending_channel;
195 TpChannelDispatchOperation *pending_cdo;
196 TpAddDispatchOperationContext *pending_context;
198 gulong video_output_motion_handler_id;
199 guint bus_message_source_id;
201 GtkWidget *dtmf_panel;
204 GtkWidget *details_vbox;
205 GtkWidget *vcodec_encoding_label;
206 GtkWidget *acodec_encoding_label;
207 GtkWidget *vcodec_decoding_label;
208 GtkWidget *acodec_decoding_label;
210 GtkWidget *audio_remote_candidate_label;
211 GtkWidget *audio_local_candidate_label;
212 GtkWidget *video_remote_candidate_label;
213 GtkWidget *video_local_candidate_label;
214 GtkWidget *video_remote_candidate_info_img;
215 GtkWidget *video_local_candidate_info_img;
216 GtkWidget *audio_remote_candidate_info_img;
217 GtkWidget *audio_local_candidate_info_img;
219 GstElement *video_input;
220 GstElement *video_preview_sink;
221 GstElement *video_output_sink;
222 GstElement *audio_input;
223 GstElement *audio_output;
224 gboolean audio_output_added;
225 GstElement *pipeline;
226 GstElement *video_tee;
236 gboolean call_started;
237 gboolean sending_video;
238 CameraState camera_state;
240 EmpathyCallWindowFullscreen *fullscreen;
241 gboolean is_fullscreen;
246 guint inactivity_src;
248 /* Those fields represent the state of the window before it actually was in
250 gboolean dialpad_was_visible_before_fs;
251 gint original_width_before_fs;
252 gint original_height_before_fs;
254 gint x, y, w, h, dialpad_width;
257 /* TRUE if the call should be started when the pipeline is playing */
258 gboolean start_call_when_playing;
259 /* TRUE if we requested to set the pipeline in the playing state */
260 gboolean pipeline_playing;
262 EmpathySoundManager *sound_mgr;
265 EmpathyMicMenu *mic_menu;
266 EmpathyCameraMenu *camera_menu;
271 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
273 static void empathy_call_window_realized_cb (GtkWidget *widget,
274 EmpathyCallWindow *window);
276 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
277 GdkEvent *event, EmpathyCallWindow *window);
279 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
280 GdkEventWindowState *event, EmpathyCallWindow *window);
282 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
285 static void empathy_call_window_hangup_cb (gpointer object,
286 EmpathyCallWindow *window);
288 static void empathy_call_window_fullscreen_cb (gpointer object,
289 EmpathyCallWindow *window);
291 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
293 static gboolean empathy_call_window_video_button_press_cb (
294 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
296 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
297 GdkEventKey *event, EmpathyCallWindow *window);
299 static gboolean empathy_call_window_video_output_motion_notify (
300 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
302 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
305 static void empathy_call_window_connect_handler (EmpathyCallWindow *self);
307 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
308 EmpathyCallWindow *window);
310 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
312 static void empathy_call_window_status_message (EmpathyCallWindow *window,
315 static gboolean empathy_call_window_bus_message (GstBus *bus,
316 GstMessage *message, gpointer user_data);
318 static gboolean empathy_call_window_update_timer (gpointer user_data);
321 make_background_transparent (GtkClutterActor *actor)
323 GdkRGBA transparent = { 0., 0., 0., 0. };
326 widget = gtk_clutter_actor_get_widget (actor);
327 gtk_widget_override_background_color (widget, GTK_STATE_FLAG_NORMAL, &transparent);
331 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
334 gtk_widget_set_visible (self->priv->hangup_button, show);
335 gtk_widget_set_visible (self->priv->audio_call_button, !show);
336 gtk_widget_set_visible (self->priv->video_call_button, !show);
340 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
341 EmpathyCallWindow *self)
343 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
344 empathy_call_window_restart_call (self);
348 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
349 EmpathyCallWindow *self)
351 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
352 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
353 empathy_call_window_restart_call (self);
357 dtmf_start_tone_cb (EmpathyDialpadWidget *dialpad,
359 EmpathyCallWindow *self)
364 g_object_get (self->priv->handler, "call-channel", &call, NULL);
366 tones[0] = tp_dtmf_event_to_char (event);
368 tp_call_channel_send_tones_async (call, tones, NULL, NULL, NULL);
370 g_object_unref (call);
374 empathy_call_window_show_video_output (EmpathyCallWindow *self,
377 if (self->priv->video_output != NULL)
378 g_object_set (self->priv->video_output, "visible", show, NULL);
380 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
382 clutter_actor_raise_top (self->priv->overlay_bin);
386 create_video_output_widget (EmpathyCallWindow *self)
388 EmpathyCallWindowPriv *priv = GET_PRIV (self);
390 g_assert (priv->video_output == NULL);
391 g_assert (priv->pipeline != NULL);
393 priv->video_output = clutter_texture_new ();
395 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
398 priv->video_output_sink = gst_element_factory_make ("cluttersink", NULL);
399 if (priv->video_output_sink == NULL)
400 g_error ("Missing cluttersink");
402 g_object_set (priv->video_output_sink, "texture", priv->video_output, NULL);
404 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
407 gtk_widget_add_events (priv->video_container,
408 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
409 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
410 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
414 create_video_input (EmpathyCallWindow *self)
416 EmpathyCallWindowPriv *priv = GET_PRIV (self);
418 g_assert (priv->video_input == NULL);
419 priv->video_input = empathy_video_src_new ();
420 gst_object_ref_sink (priv->video_input);
424 audio_control_volume_to_element (GBinding *binding,
425 const GValue *source_value,
426 GValue *target_value,
429 /* AudioControl volume is 0-255, with -1 for unknown */
432 hv = g_value_get_int (source_value);
437 g_value_set_double (target_value, hv/255.0);
443 element_volume_to_audio_control (GBinding *binding,
444 const GValue *source_value,
445 GValue *target_value,
450 ev = g_value_get_double (source_value);
451 ev = CLAMP (ev, 0.0, 1.0);
453 g_value_set_int (target_value, ev * 255);
458 audio_input_mute_notify_cb (GObject *obj, GParamSpec *spec,
459 EmpathyCallWindow *self)
462 g_object_get (obj, "mute", &muted, NULL);
464 self->priv->muted = muted;
465 if (muted && self->priv->transitions)
466 clutter_state_set_state (self->priv->transitions, "fade-in");
470 gtk_image_set_from_icon_name (GTK_IMAGE (self->priv->microphone_icon),
471 EMPATHY_IMAGE_MIC_MUTED, GTK_ICON_SIZE_MENU);
475 gtk_image_set_from_icon_name (GTK_IMAGE (self->priv->microphone_icon),
476 EMPATHY_IMAGE_MIC, GTK_ICON_SIZE_MENU);
479 empathy_call_window_update_timer (self);
483 create_audio_input (EmpathyCallWindow *self)
485 EmpathyCallWindowPriv *priv = GET_PRIV (self);
487 g_assert (priv->audio_input == NULL);
488 priv->audio_input = empathy_audio_src_new ();
489 gst_object_ref_sink (priv->audio_input);
491 g_signal_connect (priv->audio_input, "notify::mute",
492 G_CALLBACK (audio_input_mute_notify_cb), self);
496 add_video_preview_to_pipeline (EmpathyCallWindow *self)
498 EmpathyCallWindowPriv *priv = GET_PRIV (self);
501 g_assert (priv->video_preview != NULL);
502 g_assert (priv->pipeline != NULL);
503 g_assert (priv->video_input != NULL);
504 g_assert (priv->video_tee != NULL);
506 preview = priv->video_preview_sink;
508 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
510 g_warning ("Could not add video input to pipeline");
514 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
516 g_warning ("Could not add video preview to pipeline");
520 if (!gst_element_link (priv->video_input, priv->video_tee))
522 g_warning ("Could not link video input to video tee");
526 if (!gst_element_link (priv->video_tee, preview))
528 g_warning ("Could not link video tee to video preview");
534 empathy_call_window_disable_camera_cb (GtkAction *action,
535 EmpathyCallWindow *self)
537 clutter_actor_destroy (self->priv->preview_hidden_button);
539 gtk_toggle_button_set_active (
540 GTK_TOGGLE_BUTTON (self->priv->camera_button), FALSE);
544 empathy_call_window_minimise_camera_cb (GtkAction *action,
545 EmpathyCallWindow *self)
547 clutter_actor_hide (self->priv->video_preview);
548 clutter_actor_show (self->priv->preview_hidden_button);
552 empathy_call_window_maximise_camera_cb (GtkAction *action,
553 EmpathyCallWindow *self)
555 clutter_actor_show (self->priv->video_preview);
556 clutter_actor_hide (self->priv->preview_hidden_button);
560 empathy_call_window_swap_camera_cb (GtkAction *action,
561 EmpathyCallWindow *self)
563 const GList *cameras, *l;
566 DEBUG ("Swapping the camera");
568 cameras = tpaw_camera_monitor_get_cameras (self->priv->camera_monitor);
569 current_cam = empathy_video_src_dup_device (
570 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
572 for (l = cameras; l != NULL; l = l->next)
574 TpawCamera *camera = l->data;
576 if (!tp_strdiff (camera->device, current_cam))
581 next = l->next->data;
583 next = cameras->data;
585 /* EmpathyCameraMenu will update itself and do the actual change
587 g_settings_set_string (self->priv->settings,
588 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
595 g_free (current_cam);
599 empathy_call_window_update_swap_camera (EmpathyCallWindow *self)
601 const GList *cameras = tpaw_camera_monitor_get_cameras (
602 self->priv->camera_monitor);
604 gtk_action_set_visible (self->priv->menu_swap_camera,
605 g_list_length ((GList *) cameras) >= 2);
609 empathy_call_window_camera_added_cb (TpawCameraMonitor *monitor,
611 EmpathyCallWindow *self)
613 empathy_call_window_update_swap_camera (self);
617 empathy_call_window_camera_removed_cb (TpawCameraMonitor *monitor,
619 EmpathyCallWindow *self)
621 empathy_call_window_update_swap_camera (self);
625 empathy_call_window_preview_button_clicked_cb (ClutterClickAction *action,
627 EmpathyCallWindow *self)
631 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
633 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
634 0, gtk_get_current_event_time ());
635 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
639 empathy_call_window_preview_hidden_button_clicked_cb (
640 ClutterClickAction *action,
642 EmpathyCallWindow *self)
646 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
647 "/preview-hidden-menu");
648 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
649 0, gtk_get_current_event_time ());
650 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
653 static ClutterActor *
654 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
655 ClutterBinAlignment x,
656 ClutterBinAlignment y)
658 ClutterActor *rectangle;
660 rectangle = CLUTTER_ACTOR (empathy_rounded_rectangle_new (
661 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT,
662 PREVIEW_ROUND_FACTOR));
664 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->preview_layout),
666 clutter_actor_hide (rectangle);
672 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
676 self->priv->preview_layout = clutter_bin_layout_new (
677 CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_CENTER);
678 self->priv->preview_box = box = clutter_box_new (self->priv->preview_layout);
680 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->overlay_layout),
682 CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL);
684 self->priv->preview_rectangle1 =
685 empathy_call_window_create_preview_rectangle (self,
686 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
687 self->priv->preview_rectangle2 =
688 empathy_call_window_create_preview_rectangle (self,
689 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
690 self->priv->preview_rectangle3 =
691 empathy_call_window_create_preview_rectangle (self,
692 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
693 self->priv->preview_rectangle4 =
694 empathy_call_window_create_preview_rectangle (self,
695 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
699 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
702 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
703 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
704 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
705 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
709 empathy_call_window_get_preview_coordinates (EmpathyCallWindow *self,
714 guint ret_x = 0, ret_y = 0;
717 if (!clutter_actor_has_allocation (self->priv->preview_box))
720 clutter_actor_get_geometry (self->priv->preview_box, &box);
724 case PREVIEW_POS_TOP_LEFT:
725 ret_x = ret_y = SELF_VIDEO_SECTION_MARGIN;
727 case PREVIEW_POS_TOP_RIGHT:
728 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
729 - SELF_VIDEO_SECTION_WIDTH;
730 ret_y = SELF_VIDEO_SECTION_MARGIN;
732 case PREVIEW_POS_BOTTOM_LEFT:
733 ret_x = SELF_VIDEO_SECTION_MARGIN;
734 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
735 - SELF_VIDEO_SECTION_HEIGHT;
737 case PREVIEW_POS_BOTTOM_RIGHT:
738 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
739 - SELF_VIDEO_SECTION_WIDTH;
740 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
741 - SELF_VIDEO_SECTION_HEIGHT;
744 g_warn_if_reached ();
755 static PreviewPosition
756 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
761 PreviewPosition pos = PREVIEW_POS_NONE;
763 if (!clutter_actor_has_allocation (self->priv->preview_box))
766 clutter_actor_get_geometry (self->priv->preview_box, &box);
768 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
769 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
770 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
771 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
773 pos = PREVIEW_POS_TOP_LEFT;
775 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
776 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
777 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
778 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
780 pos = PREVIEW_POS_TOP_RIGHT;
782 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
783 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
784 box.height - SELF_VIDEO_SECTION_MARGIN >= event_y &&
785 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
787 pos = PREVIEW_POS_BOTTOM_LEFT;
789 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
790 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
791 box.height - 2 * SELF_VIDEO_SECTION_MARGIN >= event_y &&
792 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
794 pos = PREVIEW_POS_BOTTOM_RIGHT;
800 static ClutterActor *
801 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
804 ClutterActor *rectangle;
808 case PREVIEW_POS_TOP_LEFT:
809 rectangle = self->priv->preview_rectangle1;
811 case PREVIEW_POS_TOP_RIGHT:
812 rectangle = self->priv->preview_rectangle3;
814 case PREVIEW_POS_BOTTOM_LEFT:
815 rectangle = self->priv->preview_rectangle2;
817 case PREVIEW_POS_BOTTOM_RIGHT:
818 rectangle = self->priv->preview_rectangle4;
828 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
831 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->preview_layout);
833 DEBUG ("moving the video preview to %d", pos);
835 self->priv->preview_pos = pos;
839 case PREVIEW_POS_TOP_LEFT:
840 clutter_bin_layout_set_alignment (layout,
841 self->priv->video_preview,
842 CLUTTER_BIN_ALIGNMENT_START,
843 CLUTTER_BIN_ALIGNMENT_START);
845 case PREVIEW_POS_TOP_RIGHT:
846 clutter_bin_layout_set_alignment (layout,
847 self->priv->video_preview,
848 CLUTTER_BIN_ALIGNMENT_END,
849 CLUTTER_BIN_ALIGNMENT_START);
851 case PREVIEW_POS_BOTTOM_LEFT:
852 clutter_bin_layout_set_alignment (layout,
853 self->priv->video_preview,
854 CLUTTER_BIN_ALIGNMENT_START,
855 CLUTTER_BIN_ALIGNMENT_END);
857 case PREVIEW_POS_BOTTOM_RIGHT:
858 clutter_bin_layout_set_alignment (layout,
859 self->priv->video_preview,
860 CLUTTER_BIN_ALIGNMENT_END,
861 CLUTTER_BIN_ALIGNMENT_END);
864 g_warn_if_reached ();
867 g_settings_set_enum (self->priv->settings, "camera-position", pos);
871 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
874 ClutterActor *rectangle;
875 ClutterColor white = { 0xff, 0xff, 0xff, 0xff};
877 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
879 empathy_rounded_rectangle_set_border_width (
880 EMPATHY_ROUNDED_RECTANGLE (rectangle), 2 * SELF_VIDEO_SECTION_MARGIN);
881 empathy_rounded_rectangle_set_border_color (
882 EMPATHY_ROUNDED_RECTANGLE (rectangle), &white);
886 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
887 ClutterActor *rectangle)
889 ClutterColor white = { 0xff, 0xff, 0xff, 0xff}, darker;
891 clutter_color_shade (&white, 0.55, &darker);
893 empathy_rounded_rectangle_set_border_width (
894 EMPATHY_ROUNDED_RECTANGLE (rectangle), 1);
895 empathy_rounded_rectangle_set_border_color (
896 EMPATHY_ROUNDED_RECTANGLE (rectangle), &darker);
900 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
902 ClutterActor *rectangle;
904 rectangle = empathy_call_window_get_preview_rectangle (self,
905 self->priv->preview_pos);
907 /* We don't want to darken the rectangle where the preview
910 if (self->priv->preview_rectangle1 != rectangle)
911 empathy_call_window_darken_preview_rectangle (self,
912 self->priv->preview_rectangle1);
914 if (self->priv->preview_rectangle2 != rectangle)
915 empathy_call_window_darken_preview_rectangle (self,
916 self->priv->preview_rectangle2);
918 if (self->priv->preview_rectangle3 != rectangle)
919 empathy_call_window_darken_preview_rectangle (self,
920 self->priv->preview_rectangle3);
922 if (self->priv->preview_rectangle4 != rectangle)
923 empathy_call_window_darken_preview_rectangle (self,
924 self->priv->preview_rectangle4);
928 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
932 ClutterModifierType modifiers,
933 EmpathyCallWindow *self)
935 ClutterActor *stage = clutter_actor_get_stage (actor);
938 self->priv->drag_preview = clutter_clone_new (actor);
940 clutter_container_add_actor (CLUTTER_CONTAINER (stage),
941 self->priv->drag_preview);
943 clutter_actor_transform_stage_point (actor, event_x, event_y,
946 clutter_actor_set_position (self->priv->drag_preview,
947 event_x - rel_x, event_y - rel_y);
949 clutter_drag_action_set_drag_handle (action,
950 self->priv->drag_preview);
952 clutter_actor_set_opacity (actor, 0);
953 clutter_actor_hide (self->priv->preview_shown_button);
955 empathy_call_window_show_preview_rectangles (self, TRUE);
956 empathy_call_window_darken_preview_rectangles (self);
960 empathy_call_window_on_animation_completed_cb (ClutterAnimation *animation,
963 clutter_actor_set_opacity (actor, 255);
967 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
971 ClutterModifierType modifiers,
972 EmpathyCallWindow *self)
977 /* Get the position before destroying the drag actor, otherwise the
978 * preview_box allocation won't be valid and we won't be able to
979 * calculate the position. */
980 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
982 empathy_call_window_get_preview_coordinates (self,
983 pos != PREVIEW_POS_NONE ? pos : self->priv->preview_pos,
986 /* Move the preview to the destination and destroy it afterwards */
987 clutter_actor_animate (self->priv->drag_preview, CLUTTER_LINEAR, 500,
990 "signal-swapped-after::completed",
991 clutter_actor_destroy, self->priv->drag_preview,
992 "signal-swapped-after::completed",
993 clutter_actor_show, self->priv->preview_shown_button,
995 empathy_call_window_on_animation_completed_cb, actor,
998 self->priv->drag_preview = NULL;
1000 if (pos != PREVIEW_POS_NONE)
1001 empathy_call_window_move_video_preview (self, pos);
1003 empathy_call_window_show_preview_rectangles (self, FALSE);
1007 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
1008 ClutterActor *actor,
1011 EmpathyCallWindow *self)
1013 PreviewPosition pos;
1014 gfloat event_x, event_y;
1016 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
1018 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
1020 if (pos != PREVIEW_POS_NONE)
1021 empathy_call_window_highlight_preview_rectangle (self, pos);
1023 empathy_call_window_darken_preview_rectangles (self);
1027 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
1028 ClutterCrossingEvent *event,
1029 EmpathyCallWindow *self)
1031 ClutterActor *rectangle;
1033 rectangle = empathy_call_window_get_preview_rectangle (self,
1034 self->priv->preview_pos);
1036 empathy_call_window_highlight_preview_rectangle (self,
1037 self->priv->preview_pos);
1039 clutter_actor_show (rectangle);
1045 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
1046 ClutterCrossingEvent *event,
1047 EmpathyCallWindow *self)
1049 ClutterActor *rectangle;
1051 rectangle = empathy_call_window_get_preview_rectangle (self,
1052 self->priv->preview_pos);
1054 empathy_call_window_darken_preview_rectangle (self, rectangle);
1056 clutter_actor_hide (rectangle);
1062 create_video_preview (EmpathyCallWindow *self)
1064 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1065 ClutterLayoutManager *layout;
1066 ClutterActor *preview;
1068 ClutterAction *action;
1069 PreviewPosition pos;
1071 g_assert (priv->video_preview == NULL);
1073 pos = g_settings_get_enum (priv->settings, "camera-position");
1075 preview = empathy_rounded_texture_new ();
1076 clutter_actor_set_size (preview,
1077 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1079 priv->video_preview_sink = gst_element_factory_make ("cluttersink", NULL);
1080 if (priv->video_preview_sink == NULL)
1081 g_error ("Missing cluttersink, check your clutter-gst installation");
1082 g_object_set (priv->video_preview_sink, "texture", preview, NULL);
1083 g_object_add_weak_pointer (G_OBJECT (priv->video_preview_sink), (gpointer) &priv->video_preview_sink);
1085 /* Add a little offset to the video preview */
1086 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1087 CLUTTER_BIN_ALIGNMENT_CENTER);
1088 priv->video_preview = clutter_box_new (layout);
1089 clutter_actor_set_size (priv->video_preview,
1090 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1091 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1093 /* Spinner for when changing the camera device */
1094 priv->preview_spinner_widget = gtk_spinner_new ();
1095 priv->preview_spinner_actor = empathy_rounded_actor_new (PREVIEW_ROUND_FACTOR);
1097 g_object_set (priv->preview_spinner_widget, "expand", TRUE, NULL);
1098 make_background_transparent (GTK_CLUTTER_ACTOR (priv->preview_spinner_actor));
1099 gtk_widget_show (priv->preview_spinner_widget);
1102 GTK_CONTAINER (gtk_clutter_actor_get_widget (
1103 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor))),
1104 priv->preview_spinner_widget);
1105 clutter_actor_set_size (priv->preview_spinner_actor,
1106 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1107 clutter_actor_set_opacity (priv->preview_spinner_actor, 128);
1108 clutter_actor_hide (priv->preview_spinner_actor);
1110 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1112 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1113 priv->preview_spinner_actor);
1115 g_object_set (priv->video_preview_sink,
1121 priv->preview_shown_button = b = gtk_clutter_actor_new_with_contents (
1122 gtk_image_new_from_icon_name ("emblem-system-symbolic",
1123 GTK_ICON_SIZE_MENU));
1124 clutter_actor_set_margin_right (b, 4);
1125 clutter_actor_set_margin_bottom (b, 2);
1126 clutter_actor_set_opacity (b, PREVIEW_BUTTON_OPACITY);
1127 make_background_transparent (GTK_CLUTTER_ACTOR (b));
1129 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout), b,
1130 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
1132 action = clutter_click_action_new ();
1133 clutter_actor_add_action (b, action);
1134 g_signal_connect (action, "clicked",
1135 G_CALLBACK (empathy_call_window_preview_button_clicked_cb), self);
1137 /* Preview hidden */
1138 priv->preview_hidden_button = b = gtk_clutter_actor_new_with_contents (
1139 gtk_image_new_from_icon_name ("emblem-system-symbolic",
1140 GTK_ICON_SIZE_MENU));
1141 make_background_transparent (GTK_CLUTTER_ACTOR (b));
1143 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1144 priv->preview_hidden_button,
1145 CLUTTER_BIN_ALIGNMENT_START,
1146 CLUTTER_BIN_ALIGNMENT_END);
1148 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1150 clutter_actor_hide (priv->preview_hidden_button);
1152 action = clutter_click_action_new ();
1153 clutter_actor_add_action (b, action);
1154 g_signal_connect (action, "clicked",
1155 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb), self);
1157 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1158 priv->video_preview,
1159 CLUTTER_BIN_ALIGNMENT_START,
1160 CLUTTER_BIN_ALIGNMENT_END);
1162 empathy_call_window_move_video_preview (self, pos);
1164 action = clutter_drag_action_new ();
1165 g_signal_connect (action, "drag-begin",
1166 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1167 g_signal_connect (action, "drag-end",
1168 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1169 g_signal_connect (action, "drag-motion",
1170 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1172 g_signal_connect (preview, "enter-event",
1173 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1174 g_signal_connect (preview, "leave-event",
1175 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1177 clutter_actor_add_action (preview, action);
1178 clutter_actor_set_reactive (preview, TRUE);
1179 clutter_actor_set_reactive (priv->preview_shown_button, TRUE);
1183 empathy_call_window_start_camera_spinning (EmpathyCallWindow *self)
1185 clutter_actor_show (self->priv->preview_spinner_actor);
1186 gtk_spinner_start (GTK_SPINNER (self->priv->preview_spinner_widget));
1190 empathy_call_window_stop_camera_spinning (EmpathyCallWindow *self)
1192 clutter_actor_hide (self->priv->preview_spinner_actor);
1193 gtk_spinner_stop (GTK_SPINNER (self->priv->preview_spinner_widget));
1197 empathy_call_window_play_camera (EmpathyCallWindow *self,
1200 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1201 GstElement *preview;
1204 if (priv->video_preview == NULL)
1206 create_video_preview (self);
1207 add_video_preview_to_pipeline (self);
1212 state = GST_STATE_PLAYING;
1216 empathy_call_window_start_camera_spinning (self);
1217 state = GST_STATE_NULL;
1220 preview = priv->video_preview_sink;
1222 gst_element_set_state (preview, state);
1223 gst_element_set_state (priv->video_tee, state);
1224 gst_element_set_state (priv->video_input, state);
1228 display_video_preview (EmpathyCallWindow *self,
1231 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1233 if (priv->video_preview == NULL)
1235 create_video_preview (self);
1236 add_video_preview_to_pipeline (self);
1241 /* Display the video preview */
1242 DEBUG ("Show video preview");
1244 empathy_call_window_play_camera (self, TRUE);
1245 clutter_actor_show (priv->video_preview);
1246 clutter_actor_raise_top (priv->floating_toolbar);
1250 /* Hide the video preview */
1251 DEBUG ("Hide video preview");
1253 if (priv->video_preview != NULL)
1255 clutter_actor_hide (priv->video_preview);
1256 empathy_call_window_play_camera (self, FALSE);
1262 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1264 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1266 empathy_call_window_status_message (window, _("Connecting…"));
1267 priv->call_state = CONNECTING;
1269 /* Show the toolbar */
1270 clutter_state_set_state (priv->transitions, "fade-in");
1273 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1274 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1278 disable_camera (EmpathyCallWindow *self)
1280 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1282 if (priv->camera_state == CAMERA_STATE_OFF)
1285 DEBUG ("Disable camera");
1287 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1289 priv->camera_state = CAMERA_STATE_OFF;
1293 enable_camera (EmpathyCallWindow *self)
1295 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1297 if (priv->camera_state == CAMERA_STATE_ON)
1300 if (priv->video_input == NULL)
1302 DEBUG ("Can't enable camera, no input");
1306 DEBUG ("Enable camera");
1308 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1310 priv->camera_state = CAMERA_STATE_ON;
1314 empathy_call_window_camera_toggled_cb (GtkToggleButton *toggle,
1315 EmpathyCallWindow *self)
1317 if (gtk_toggle_button_get_active (toggle))
1318 enable_camera (self);
1320 disable_camera (self);
1324 create_pipeline (EmpathyCallWindow *self)
1326 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1329 g_assert (priv->pipeline == NULL);
1331 priv->pipeline = gst_pipeline_new (NULL);
1332 priv->pipeline_playing = FALSE;
1334 priv->video_tee = gst_element_factory_make ("tee", NULL);
1335 gst_object_ref_sink (priv->video_tee);
1337 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1339 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1340 priv->bus_message_source_id = gst_bus_add_watch (bus,
1341 empathy_call_window_bus_message, self);
1343 g_object_unref (bus);
1347 empathy_call_window_settings_cb (GtkAction *action,
1348 EmpathyCallWindow *self)
1350 gchar *args = g_strdup_printf ("-p %s",
1351 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1353 empathy_launch_program (BIN_DIR, "empathy", args);
1359 empathy_call_window_contents_cb (GtkAction *action,
1360 EmpathyCallWindow *self)
1362 empathy_url_show (GTK_WIDGET (self), "help:empathy/audio-video");
1366 show_png (GPid pid, gint status, gpointer user_data)
1368 gtk_show_uri (NULL, (gchar *) user_data, GDK_CURRENT_TIME, NULL);
1369 g_spawn_close_pid (pid);
1374 empathy_call_window_debug_gst_cb (GtkAction *action,
1375 EmpathyCallWindow *self)
1377 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1378 GDateTime *date_time;
1380 const gchar *dot_dir;
1381 const gchar *prgname;
1387 if (priv->pipeline == NULL)
1388 DEBUG ("No pipeline");
1390 date_time = g_date_time_new_now_utc ();
1391 prgname = g_get_prgname ();
1392 filename = g_strdup_printf ("%s-%" G_GINT64_FORMAT, prgname,
1393 g_date_time_to_unix (date_time));
1395 GST_DEBUG_BIN_TO_DOT_FILE (GST_BIN (priv->pipeline),
1396 GST_DEBUG_GRAPH_SHOW_ALL, filename);
1398 dot_dir = g_getenv ("GST_DEBUG_DUMP_DOT_DIR");
1399 dot_cmd = g_strdup_printf ("dot -Tpng -o %s.png %s.dot",
1402 g_shell_parse_argv (dot_cmd, &argc, &argv, NULL);
1404 if (g_spawn_async (dot_dir,
1407 G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
1413 gchar *uri = g_strdup_printf ("file://%s/%s.png", dot_dir, filename);
1414 g_child_watch_add (dot_pid, show_png, uri);
1420 g_date_time_unref (date_time);
1424 empathy_call_window_debug_tp_cb (GtkAction *action,
1425 EmpathyCallWindow *self)
1427 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1431 empathy_call_window_about_cb (GtkAction *action,
1432 EmpathyCallWindow *self)
1434 empathy_about_dialog_new (GTK_WINDOW (self));
1438 empathy_call_window_toolbar_timeout (gpointer data)
1440 EmpathyCallWindow *self = data;
1442 /* We don't want to hide the toolbar if we're not in a call, as
1443 * to show the call status all the time. Also don't hide if we're muted
1444 * to prevent the awkward, talking when muted situation */
1445 if (self->priv->call_state != CONNECTING &&
1446 self->priv->call_state != DISCONNECTED &&
1448 clutter_state_set_state (self->priv->transitions, "fade-out");
1454 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1456 EmpathyCallWindow *self)
1458 clutter_state_set_state (self->priv->transitions, "fade-in");
1460 if (self->priv->inactivity_src > 0)
1461 g_source_remove (self->priv->inactivity_src);
1463 self->priv->inactivity_src = g_timeout_add_seconds (3,
1464 empathy_call_window_toolbar_timeout, self);
1470 empathy_call_window_configure_event_cb (GtkWidget *widget,
1472 EmpathyCallWindow *self)
1474 GdkWindow *gdk_window;
1475 GdkWindowState window_state;
1477 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1478 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1480 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1481 &self->priv->dialpad_width, NULL);
1483 gdk_window = gtk_widget_get_window (widget);
1484 window_state = gdk_window_get_state (gdk_window);
1485 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1491 empathy_call_window_destroyed_cb (GtkWidget *object,
1492 EmpathyCallWindow *self)
1494 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1496 /* Save the geometry as if the dialpad was hidden. */
1497 empathy_geometry_save_values (GTK_WINDOW (self),
1498 self->priv->x, self->priv->y,
1499 self->priv->w - self->priv->dialpad_width, self->priv->h,
1500 self->priv->maximized);
1505 empathy_call_window_incoming_call_response_cb (GtkDialog *dialog,
1507 EmpathyCallWindow *self)
1509 switch (response_id)
1511 case GTK_RESPONSE_ACCEPT:
1512 tp_channel_dispatch_operation_handle_with_async (
1513 self->priv->pending_cdo, EMPATHY_CALL_BUS_NAME, NULL, NULL);
1515 tp_clear_object (&self->priv->pending_cdo);
1516 tp_clear_object (&self->priv->pending_channel);
1517 tp_clear_object (&self->priv->pending_context);
1520 case GTK_RESPONSE_CANCEL:
1521 tp_channel_dispatch_operation_close_channels_async (
1522 self->priv->pending_cdo, NULL, NULL);
1524 empathy_call_window_status_message (self, _("Disconnected"));
1525 self->priv->call_state = DISCONNECTED;
1528 g_warn_if_reached ();
1533 empathy_call_window_set_state_ringing (EmpathyCallWindow *self)
1537 g_assert (self->priv->call_state != CONNECTED);
1539 video = tp_call_channel_has_initial_video (self->priv->pending_channel, NULL);
1541 empathy_call_window_status_message (self, _("Incoming call"));
1542 self->priv->call_state = RINGING;
1544 self->priv->incoming_call_dialog = gtk_message_dialog_new (
1545 GTK_WINDOW (self), GTK_DIALOG_MODAL,
1546 GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
1547 video ? _("Incoming video call from %s") : _("Incoming call from %s"),
1548 empathy_contact_get_alias (self->priv->contact));
1550 gtk_dialog_add_buttons (GTK_DIALOG (self->priv->incoming_call_dialog),
1551 _("Reject"), GTK_RESPONSE_CANCEL,
1552 _("Answer"), GTK_RESPONSE_ACCEPT,
1555 g_signal_connect (self->priv->incoming_call_dialog, "response",
1556 G_CALLBACK (empathy_call_window_incoming_call_response_cb), self);
1557 gtk_widget_show (self->priv->incoming_call_dialog);
1561 empathy_call_window_cdo_invalidated_cb (TpProxy *channel,
1565 EmpathyCallWindow *self)
1567 tp_clear_object (&self->priv->pending_cdo);
1568 tp_clear_object (&self->priv->pending_channel);
1569 tp_clear_object (&self->priv->pending_context);
1571 /* We don't know if the incoming call has been accepted or not, so we
1572 * assume it hasn't and if it has, we'll set the proper status when
1573 * we get the new handler. */
1574 empathy_call_window_status_message (self, _("Disconnected"));
1575 self->priv->call_state = DISCONNECTED;
1577 gtk_widget_destroy (self->priv->incoming_call_dialog);
1578 self->priv->incoming_call_dialog = NULL;
1582 empathy_call_window_start_ringing (EmpathyCallWindow *self,
1583 TpCallChannel *channel,
1584 TpChannelDispatchOperation *dispatch_operation,
1585 TpAddDispatchOperationContext *context)
1587 g_assert (self->priv->pending_channel == NULL);
1588 g_assert (self->priv->pending_context == NULL);
1589 g_assert (self->priv->pending_cdo == NULL);
1591 /* Start ringing and delay until the user answers or hangs. */
1592 self->priv->pending_channel = g_object_ref (channel);
1593 self->priv->pending_context = g_object_ref (context);
1594 self->priv->pending_cdo = g_object_ref (dispatch_operation);
1596 g_signal_connect (self->priv->pending_cdo, "invalidated",
1597 G_CALLBACK (empathy_call_window_cdo_invalidated_cb), self);
1599 empathy_call_window_set_state_ringing (self);
1600 tp_add_dispatch_operation_context_accept (context);
1604 mic_button_clicked (GtkWidget *button,
1605 EmpathyCallWindow *self)
1607 /* Toggle the muted state. We rely on audio_input_mute_notify_cb to update
1609 empathy_audio_src_set_mute (EMPATHY_GST_AUDIO_SRC (self->priv->audio_input),
1610 !self->priv->muted);
1614 empathy_call_window_init (EmpathyCallWindow *self)
1616 EmpathyCallWindowPriv *priv;
1618 GtkWidget *top_vbox;
1620 ClutterConstraint *constraint;
1621 ClutterActor *remote_avatar;
1622 ClutterColor black = { 0, 0, 0, 0 };
1623 ClutterMargin overlay_margin = { OVERLAY_MARGIN, OVERLAY_MARGIN,
1624 OVERLAY_MARGIN, OVERLAY_MARGIN };
1626 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1627 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1629 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1630 priv->timer = g_timer_new ();
1632 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1633 gui = tpaw_builder_get_file (filename,
1634 "call_window_vbox", &top_vbox,
1635 "errors_vbox", &priv->errors_vbox,
1636 "pane", &priv->pane,
1637 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1638 "remote_user_status_toolbar", &priv->remote_user_status_toolbar,
1639 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1640 "status_label", &priv->status_label,
1641 "audiocall", &priv->audio_call_button,
1642 "videocall", &priv->video_call_button,
1643 "microphone", &priv->mic_button,
1644 "microphone_icon", &priv->microphone_icon,
1645 "volume", &priv->volume_button,
1646 "camera", &priv->camera_button,
1647 "hangup", &priv->hangup_button,
1648 "dialpad", &priv->dialpad_button,
1649 "toolbar", &priv->toolbar,
1650 "bottom_toolbar", &priv->bottom_toolbar,
1651 "ui_manager", &priv->ui_manager,
1652 "menufullscreen", &priv->menu_fullscreen,
1653 "menupreviewswap", &priv->menu_swap_camera,
1654 "details_vbox", &priv->details_vbox,
1655 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1656 "acodec_encoding_label", &priv->acodec_encoding_label,
1657 "acodec_decoding_label", &priv->acodec_decoding_label,
1658 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1659 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1660 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1661 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1662 "video_local_candidate_label", &priv->video_local_candidate_label,
1663 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1664 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1665 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1666 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1670 tpaw_builder_connect (gui, self,
1671 "hangup", "clicked", empathy_call_window_hangup_cb,
1672 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1673 "videocall", "clicked", empathy_call_window_video_call_cb,
1674 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1675 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1676 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1677 "menusettings", "activate", empathy_call_window_settings_cb,
1678 "menucontents", "activate", empathy_call_window_contents_cb,
1679 "menudebuggst", "activate", empathy_call_window_debug_gst_cb,
1680 "menudebugtp", "activate", empathy_call_window_debug_tp_cb,
1681 "menuabout", "activate", empathy_call_window_about_cb,
1682 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1683 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1684 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1685 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1688 empathy_set_css_provider (GTK_WIDGET (self));
1689 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1691 priv->camera_monitor = tpaw_camera_monitor_dup_singleton ();
1692 empathy_call_window_update_swap_camera (self);
1694 g_object_bind_property (priv->camera_monitor, "available",
1695 priv->camera_button, "sensitive",
1696 G_BINDING_SYNC_CREATE);
1698 g_signal_connect (priv->camera_monitor, "added",
1699 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1700 g_signal_connect (priv->camera_monitor, "removed",
1701 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1703 g_signal_connect (priv->mic_button, "clicked",
1704 G_CALLBACK (mic_button_clicked), self);
1706 g_mutex_init (&priv->lock);
1708 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1710 priv->content_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,
1711 CONTENT_HBOX_SPACING);
1712 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1715 /* main contents remote avatar/video box */
1716 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_FILL,
1717 CLUTTER_BIN_ALIGNMENT_FILL);
1719 priv->video_box = clutter_box_new (priv->video_layout);
1721 priv->video_container = gtk_clutter_embed_new ();
1723 gtk_widget_set_size_request (priv->video_container,
1724 REMOTE_VIDEO_DEFAULT_WIDTH, REMOTE_VIDEO_DEFAULT_HEIGHT);
1726 /* Set the background black */
1727 clutter_stage_set_color (
1728 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1729 GTK_CLUTTER_EMBED (priv->video_container))),
1732 clutter_container_add (
1733 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1734 GTK_CLUTTER_EMBED (priv->video_container))),
1738 constraint = clutter_bind_constraint_new (
1739 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1740 CLUTTER_BIND_SIZE, 0);
1741 clutter_actor_add_constraint (priv->video_box, constraint);
1743 priv->remote_user_avatar_widget = gtk_image_new ();
1744 remote_avatar = gtk_clutter_actor_new_with_contents (
1745 priv->remote_user_avatar_widget);
1746 make_background_transparent (GTK_CLUTTER_ACTOR (remote_avatar));
1748 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1751 /* create the overlay bin */
1752 priv->overlay_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1753 CLUTTER_BIN_ALIGNMENT_CENTER);
1754 priv->overlay_bin = clutter_actor_new ();
1755 clutter_actor_set_layout_manager (priv->overlay_bin, priv->overlay_layout);
1757 clutter_actor_set_margin (priv->overlay_bin, &overlay_margin);
1759 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1761 CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL);
1763 empathy_call_window_create_preview_rectangles (self);
1765 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1766 priv->video_container, TRUE, TRUE,
1767 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1769 create_pipeline (self);
1770 create_video_output_widget (self);
1771 create_audio_input (self);
1772 create_video_input (self);
1774 priv->floating_toolbar = gtk_clutter_actor_new ();
1775 clutter_actor_set_reactive (priv->floating_toolbar, TRUE);
1776 make_background_transparent (GTK_CLUTTER_ACTOR (priv->floating_toolbar));
1778 gtk_style_context_add_class (
1779 gtk_widget_get_style_context (GTK_WIDGET (priv->bottom_toolbar)),
1780 GTK_STYLE_CLASS_OSD);
1781 gtk_widget_reparent (priv->bottom_toolbar,
1782 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1784 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->overlay_layout),
1785 priv->floating_toolbar,
1786 CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_END);
1788 clutter_actor_raise_top (priv->floating_toolbar);
1790 /* Transitions for the floating toolbar */
1791 priv->transitions = clutter_state_new ();
1793 /* all transitions last for 2s */
1794 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1796 /* transition from any state to "fade-out" state */
1797 clutter_state_set (priv->transitions, NULL, "fade-out",
1798 priv->floating_toolbar,
1799 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1802 /* transition from any state to "fade-in" state */
1803 clutter_state_set (priv->transitions, NULL, "fade-in",
1804 priv->floating_toolbar,
1805 "opacity", CLUTTER_EASE_OUT_QUAD, 255,
1808 /* put the actor into the "fade-in" state with no animation */
1809 clutter_state_warp_to_state (priv->transitions, "fade-in");
1811 /* The call will be started as soon the pipeline is playing */
1812 priv->start_call_when_playing = TRUE;
1814 priv->dtmf_panel = empathy_dialpad_widget_new ();
1815 g_signal_connect (priv->dtmf_panel, "start-tone",
1816 G_CALLBACK (dtmf_start_tone_cb), self);
1818 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1821 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1824 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1826 gtk_widget_show_all (top_vbox);
1828 gtk_widget_hide (priv->dtmf_panel);
1829 gtk_widget_hide (priv->details_vbox);
1831 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1833 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1834 priv->video_container);
1836 /* We hide the bottom toolbar after 3s of inactivity and show it
1837 * again on mouse movement */
1838 priv->inactivity_src = g_timeout_add_seconds (3,
1839 empathy_call_window_toolbar_timeout, self);
1841 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1842 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1844 g_signal_connect (G_OBJECT (self), "realize",
1845 G_CALLBACK (empathy_call_window_realized_cb), self);
1847 g_signal_connect (G_OBJECT (self), "delete-event",
1848 G_CALLBACK (empathy_call_window_delete_cb), self);
1850 g_signal_connect (G_OBJECT (self), "window-state-event",
1851 G_CALLBACK (empathy_call_window_state_event_cb), self);
1853 g_signal_connect (G_OBJECT (self), "key-press-event",
1854 G_CALLBACK (empathy_call_window_key_press_cb), self);
1856 g_signal_connect (self, "motion-notify-event",
1857 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1859 g_object_ref (priv->ui_manager);
1860 g_object_unref (gui);
1862 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1863 priv->mic_menu = empathy_mic_menu_new (self);
1864 priv->camera_menu = empathy_camera_menu_new (self);
1866 empathy_call_window_show_hangup_button (self, TRUE);
1868 gtk_window_set_default_size (GTK_WINDOW (self), 580, 480);
1870 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1871 /* These signals are used to track the window position and save it
1872 * when the window is destroyed. We need to do this as we don't want
1873 * the window geometry to be saved with the dialpad taken into account. */
1874 g_signal_connect (self, "destroy",
1875 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1876 g_signal_connect (self, "configure-event",
1877 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1878 g_signal_connect (self, "window-state-event",
1879 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1881 /* Don't display labels in both toolbars */
1882 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1885 /* Instead of specifying a width and a height, we specify only one size. That's
1886 because we want a square avatar icon. */
1888 init_contact_avatar_with_size (EmpathyContact *contact,
1889 GtkWidget *image_widget,
1892 GdkPixbuf *pixbuf_avatar = NULL;
1894 if (contact != NULL)
1896 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1900 if (pixbuf_avatar == NULL)
1902 pixbuf_avatar = tpaw_pixbuf_from_icon_name_sized (
1903 TPAW_IMAGE_AVATAR_DEFAULT, size);
1906 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1908 if (pixbuf_avatar != NULL)
1909 g_object_unref (pixbuf_avatar);
1913 set_window_title (EmpathyCallWindow *self)
1915 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1918 if (priv->contact != NULL)
1920 /* translators: Call is a noun and %s is the contact name. This string
1921 * is used in the window title */
1922 tmp = g_strdup_printf (_("Call with %s"),
1923 empathy_contact_get_alias (priv->contact));
1924 gtk_window_set_title (GTK_WINDOW (self), tmp);
1929 g_warning ("Unknown remote contact!");
1934 set_remote_user_name (EmpathyCallWindow *self,
1935 EmpathyContact *contact)
1937 const gchar *alias = empathy_contact_get_alias (contact);
1938 const gchar *status = empathy_contact_get_status (contact);
1940 gtk_label_set_text (GTK_LABEL (self->priv->remote_user_name_toolbar), alias);
1942 if (status != NULL) {
1945 markup = g_markup_printf_escaped ("<small>%s</small>", status);
1946 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_status_toolbar),
1950 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_status_toolbar),
1956 contact_name_changed_cb (EmpathyContact *contact,
1958 EmpathyCallWindow *self)
1960 set_window_title (self);
1961 set_remote_user_name (self, contact);
1965 contact_presence_changed_cb (EmpathyContact *contact,
1967 EmpathyCallWindow *self)
1969 set_remote_user_name (self, contact);
1973 contact_avatar_changed_cb (EmpathyContact *contact,
1975 EmpathyCallWindow *self)
1978 GtkAllocation allocation;
1979 GtkWidget *avatar_widget;
1981 avatar_widget = self->priv->remote_user_avatar_widget;
1983 gtk_widget_get_allocation (avatar_widget, &allocation);
1984 size = allocation.height;
1988 /* the widget is not allocated yet, set a default size */
1989 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1990 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1993 init_contact_avatar_with_size (contact, avatar_widget, size);
1995 avatar_widget = self->priv->remote_user_avatar_toolbar;
1997 gtk_widget_get_allocation (avatar_widget, &allocation);
1998 size = allocation.height;
2002 /* the widget is not allocated yet, set a default size */
2003 size = SMALL_TOOLBAR_SIZE;
2006 init_contact_avatar_with_size (contact, avatar_widget, size);
2010 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
2011 EmpathyCallHandler *handler)
2013 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2015 tp_g_signal_connect_object (priv->contact, "notify::name",
2016 G_CALLBACK (contact_name_changed_cb), self, 0);
2017 tp_g_signal_connect_object (priv->contact, "notify::avatar",
2018 G_CALLBACK (contact_avatar_changed_cb), self, 0);
2019 tp_g_signal_connect_object (priv->contact, "notify::presence",
2020 G_CALLBACK (contact_presence_changed_cb), self, 0);
2022 set_window_title (self);
2023 set_remote_user_name (self, priv->contact);
2025 init_contact_avatar_with_size (priv->contact,
2026 priv->remote_user_avatar_widget,
2027 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
2028 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
2030 init_contact_avatar_with_size (priv->contact,
2031 priv->remote_user_avatar_toolbar,
2032 SMALL_TOOLBAR_SIZE);
2034 /* The remote avatar is shown by default and will be hidden when we receive
2035 video from the remote side. */
2036 clutter_actor_hide (priv->video_output);
2037 gtk_widget_show (priv->remote_user_avatar_widget);
2041 update_send_codec (EmpathyCallWindow *self,
2044 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2051 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
2052 widget = priv->acodec_encoding_label;
2056 codec = empathy_call_handler_get_send_video_codec (priv->handler);
2057 widget = priv->vcodec_encoding_label;
2063 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
2064 gtk_label_set_text (GTK_LABEL (widget), tmp);
2069 send_audio_codec_notify_cb (GObject *object,
2073 EmpathyCallWindow *self = user_data;
2075 update_send_codec (self, TRUE);
2079 send_video_codec_notify_cb (GObject *object,
2083 EmpathyCallWindow *self = user_data;
2085 update_send_codec (self, FALSE);
2089 update_recv_codec (EmpathyCallWindow *self,
2092 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2095 GString *str = NULL;
2099 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
2100 widget = priv->acodec_decoding_label;
2104 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
2105 widget = priv->vcodec_decoding_label;
2111 for (l = codecs; l != NULL; l = g_list_next (l))
2113 FsCodec *codec = l->data;
2116 str = g_string_new (NULL);
2118 g_string_append (str, ", ");
2120 g_string_append_printf (str, "%s/%u", codec->encoding_name,
2124 gtk_label_set_text (GTK_LABEL (widget), str->str);
2125 g_string_free (str, TRUE);
2129 recv_audio_codecs_notify_cb (GObject *object,
2133 EmpathyCallWindow *self = user_data;
2135 update_recv_codec (self, TRUE);
2139 recv_video_codecs_notify_cb (GObject *object,
2143 EmpathyCallWindow *self = user_data;
2145 update_recv_codec (self, FALSE);
2148 static const gchar *
2149 candidate_type_to_str (FsCandidate *candidate)
2151 switch (candidate->type)
2153 case FS_CANDIDATE_TYPE_HOST:
2155 case FS_CANDIDATE_TYPE_SRFLX:
2156 return "server reflexive";
2157 case FS_CANDIDATE_TYPE_PRFLX:
2158 return "peer reflexive";
2159 case FS_CANDIDATE_TYPE_RELAY:
2161 case FS_CANDIDATE_TYPE_MULTICAST:
2168 static const gchar *
2169 candidate_type_to_desc (FsCandidate *candidate)
2171 switch (candidate->type)
2173 case FS_CANDIDATE_TYPE_HOST:
2174 return _("The IP address as seen by the machine");
2175 case FS_CANDIDATE_TYPE_SRFLX:
2176 return _("The IP address as seen by a server on the Internet");
2177 case FS_CANDIDATE_TYPE_PRFLX:
2178 return _("The IP address of the peer as seen by the other side");
2179 case FS_CANDIDATE_TYPE_RELAY:
2180 return _("The IP address of a relay server");
2181 case FS_CANDIDATE_TYPE_MULTICAST:
2182 return _("The IP address of the multicast group");
2189 update_candidat_widget (EmpathyCallWindow *self,
2192 FsCandidate *candidate)
2196 g_assert (candidate != NULL);
2197 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
2198 candidate->port, candidate_type_to_str (candidate));
2200 gtk_label_set_text (GTK_LABEL (label), str);
2201 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
2207 candidates_changed_cb (GObject *object,
2209 EmpathyCallWindow *self)
2211 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2212 FsCandidate *candidate = NULL;
2214 if (type == FS_MEDIA_TYPE_VIDEO)
2216 /* Update remote candidate */
2217 candidate = empathy_call_handler_get_video_remote_candidate (
2220 update_candidat_widget (self, priv->video_remote_candidate_label,
2221 priv->video_remote_candidate_info_img, candidate);
2223 /* Update local candidate */
2224 candidate = empathy_call_handler_get_video_local_candidate (
2227 update_candidat_widget (self, priv->video_local_candidate_label,
2228 priv->video_local_candidate_info_img, candidate);
2232 /* Update remote candidate */
2233 candidate = empathy_call_handler_get_audio_remote_candidate (
2236 update_candidat_widget (self, priv->audio_remote_candidate_label,
2237 priv->audio_remote_candidate_info_img, candidate);
2239 /* Update local candidate */
2240 candidate = empathy_call_handler_get_audio_local_candidate (
2243 update_candidat_widget (self, priv->audio_local_candidate_label,
2244 priv->audio_local_candidate_info_img, candidate);
2249 empathy_call_window_constructed (GObject *object)
2251 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2252 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2253 TpCallChannel *call;
2256 g_assert (priv->handler != NULL);
2258 g_object_get (priv->handler, "call-channel", &call, NULL);
2259 state = tp_call_channel_get_state (call, NULL, NULL, NULL);
2260 priv->outgoing = (state == TP_CALL_STATE_PENDING_INITIATOR);
2261 tp_clear_object (&call);
2263 priv->contact = empathy_call_handler_get_contact (priv->handler);
2264 g_assert (priv->contact != NULL);
2265 g_object_ref (priv->contact);
2267 if (!empathy_contact_can_voip_video (priv->contact))
2269 gtk_widget_set_sensitive (priv->video_call_button, FALSE);
2270 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2273 empathy_call_window_setup_avatars (self, priv->handler);
2274 empathy_call_window_set_state_connecting (self);
2276 if (!empathy_call_handler_has_initial_video (priv->handler))
2278 gtk_toggle_button_set_active (
2279 GTK_TOGGLE_BUTTON (priv->camera_button), FALSE);
2281 /* If call has InitialVideo, the preview will be started once the call has
2282 * been started (start_call()). */
2284 update_send_codec (self, TRUE);
2285 update_send_codec (self, FALSE);
2286 update_recv_codec (self, TRUE);
2287 update_recv_codec (self, FALSE);
2289 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2290 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2291 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2292 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2293 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2294 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2295 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2296 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2298 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2299 G_CALLBACK (candidates_changed_cb), self, 0);
2302 static void empathy_call_window_dispose (GObject *object);
2303 static void empathy_call_window_finalize (GObject *object);
2306 empathy_call_window_set_property (GObject *object,
2307 guint property_id, const GValue *value, GParamSpec *pspec)
2309 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2311 switch (property_id)
2313 case PROP_CALL_HANDLER:
2314 priv->handler = g_value_dup_object (value);
2317 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2322 empathy_call_window_get_property (GObject *object,
2323 guint property_id, GValue *value, GParamSpec *pspec)
2325 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2327 switch (property_id)
2329 case PROP_CALL_HANDLER:
2330 g_value_set_object (value, priv->handler);
2333 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2338 empathy_call_window_class_init (
2339 EmpathyCallWindowClass *empathy_call_window_class)
2341 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2342 GParamSpec *param_spec;
2344 g_type_class_add_private (empathy_call_window_class,
2345 sizeof (EmpathyCallWindowPriv));
2347 object_class->constructed = empathy_call_window_constructed;
2348 object_class->set_property = empathy_call_window_set_property;
2349 object_class->get_property = empathy_call_window_get_property;
2351 object_class->dispose = empathy_call_window_dispose;
2352 object_class->finalize = empathy_call_window_finalize;
2354 param_spec = g_param_spec_object ("handler",
2355 "handler", "The call handler",
2356 EMPATHY_TYPE_CALL_HANDLER,
2357 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2358 g_object_class_install_property (object_class,
2359 PROP_CALL_HANDLER, param_spec);
2361 signals[SIG_INHIBIT] = g_signal_new ("inhibit",
2362 G_OBJECT_CLASS_TYPE (empathy_call_window_class),
2364 0, NULL, NULL, NULL,
2370 empathy_call_window_dispose (GObject *object)
2372 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2373 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2375 if (priv->dispose_has_run)
2378 priv->dispose_has_run = TRUE;
2380 if (priv->handler != NULL)
2382 empathy_call_handler_stop_call (priv->handler);
2383 tp_clear_object (&priv->handler);
2386 if (priv->bus_message_source_id != 0)
2388 g_source_remove (priv->bus_message_source_id);
2389 priv->bus_message_source_id = 0;
2392 if (priv->got_video_src > 0)
2394 g_source_remove (priv->got_video_src);
2395 priv->got_video_src = 0;
2398 if (priv->inactivity_src > 0)
2400 g_source_remove (priv->inactivity_src);
2401 priv->inactivity_src = 0;
2404 tp_clear_object (&priv->pipeline);
2405 tp_clear_object (&priv->video_input);
2406 tp_clear_object (&priv->audio_input);
2407 tp_clear_object (&priv->video_tee);
2408 tp_clear_object (&priv->ui_manager);
2409 tp_clear_object (&priv->fullscreen);
2410 tp_clear_object (&priv->camera_monitor);
2411 tp_clear_object (&priv->settings);
2412 tp_clear_object (&priv->sound_mgr);
2413 tp_clear_object (&priv->mic_menu);
2414 tp_clear_object (&priv->camera_menu);
2415 tp_clear_object (&priv->transitions);
2417 g_list_free_full (priv->notifiers, g_object_unref);
2419 if (priv->timer_id != 0)
2420 g_source_remove (priv->timer_id);
2423 tp_clear_object (&priv->contact);
2425 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2429 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2431 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2433 if (priv->video_output_motion_handler_id != 0)
2435 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2436 priv->video_output_motion_handler_id);
2437 priv->video_output_motion_handler_id = 0;
2442 empathy_call_window_finalize (GObject *object)
2444 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2445 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2447 disconnect_video_output_motion_handler (self);
2449 /* free any data held directly by the object here */
2450 g_mutex_clear (&priv->lock);
2452 g_timer_destroy (priv->timer);
2454 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2459 empathy_call_window_new (EmpathyCallHandler *handler)
2461 return EMPATHY_CALL_WINDOW (
2462 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2466 empathy_call_window_new_handler (EmpathyCallWindow *self,
2467 EmpathyCallHandler *handler,
2471 g_return_if_fail (EMPATHY_IS_CALL_HANDLER (handler));
2474 tpaw_window_present_with_time (GTK_WINDOW (self), x11_time);
2476 if (self->priv->call_state == DISCONNECTED)
2478 /* start a new call if one is not already in progress */
2479 tp_clear_object (&self->priv->handler);
2480 self->priv->handler = g_object_ref (handler);
2481 empathy_call_window_connect_handler (self);
2483 empathy_call_window_restart_call (self);
2488 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2489 GstElement *conference, gpointer user_data)
2491 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2492 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2493 FsElementAddedNotifier *notifier;
2496 DEBUG ("Conference added");
2498 /* Add notifier to set the various element properties as needed */
2499 notifier = fs_element_added_notifier_new ();
2500 keyfile = fs_utils_get_default_element_properties (conference);
2502 if (keyfile != NULL)
2503 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2505 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2507 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2509 gst_bin_add (GST_BIN (priv->pipeline), conference);
2510 gst_element_set_state (conference, GST_STATE_PLAYING);
2514 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2515 GstElement *conference, gpointer user_data)
2517 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2518 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2520 g_list_free_full (priv->notifiers, g_object_unref);
2521 priv->notifiers = NULL;
2523 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2524 gst_element_set_state (conference, GST_STATE_NULL);
2528 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2530 GstStateChangeReturn state_change_return;
2531 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2533 if (priv->pipeline == NULL)
2536 if (priv->bus_message_source_id != 0)
2538 g_source_remove (priv->bus_message_source_id);
2539 priv->bus_message_source_id = 0;
2542 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2544 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2545 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2547 if (priv->pipeline != NULL)
2548 g_object_unref (priv->pipeline);
2549 priv->pipeline = NULL;
2551 if (priv->audio_output != NULL)
2552 g_object_unref (priv->audio_output);
2553 priv->audio_output = NULL;
2554 priv->audio_output_added = FALSE;
2556 if (priv->video_tee != NULL)
2557 g_object_unref (priv->video_tee);
2558 priv->video_tee = NULL;
2560 if (priv->video_preview != NULL)
2561 clutter_actor_destroy (priv->video_preview);
2562 priv->video_preview = NULL;
2564 /* If we destroy the preview while it's being dragged, we won't
2565 * get the ::drag-end signal, so manually destroy the clone */
2566 if (priv->drag_preview != NULL)
2568 clutter_actor_destroy (priv->drag_preview);
2569 empathy_call_window_show_preview_rectangles (self, FALSE);
2570 priv->drag_preview = NULL;
2573 priv->funnel = NULL;
2575 create_pipeline (self);
2576 /* Call will be started when user will hit the 'redial' button */
2577 priv->start_call_when_playing = FALSE;
2578 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2584 g_message ("Error: could not destroy pipeline. Closing call window");
2585 gtk_widget_destroy (GTK_WIDGET (self));
2592 reset_details_pane (EmpathyCallWindow *self)
2594 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2596 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2597 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2598 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2599 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2603 empathy_call_window_disconnected (EmpathyCallWindow *self,
2606 gboolean could_disconnect = FALSE;
2607 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2608 gboolean could_reset_pipeline;
2610 /* Leave full screen mode if needed */
2611 gtk_window_unfullscreen (GTK_WINDOW (self));
2613 g_signal_emit (self, signals[SIG_INHIBIT], 0, FALSE);
2615 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2616 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2618 /* Create the video input and then turn on the camera
2619 * menu, so that the active camera gets marked as such.
2621 if (priv->video_input == NULL)
2622 create_video_input (self);
2623 empathy_camera_menu_set_sensitive (priv->camera_menu, TRUE);
2625 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2627 if (priv->call_state == CONNECTING)
2628 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2630 if (priv->call_state != REDIALING)
2631 priv->call_state = DISCONNECTED;
2633 /* Show the toolbar */
2634 clutter_state_set_state (priv->transitions, "fade-in");
2636 if (could_reset_pipeline)
2638 g_mutex_lock (&priv->lock);
2640 g_timer_stop (priv->timer);
2642 if (priv->timer_id != 0)
2643 g_source_remove (priv->timer_id);
2646 g_mutex_unlock (&priv->lock);
2649 /* We are about to destroy the window, no need to update it or create
2650 * a video preview */
2653 empathy_call_window_status_message (self, _("Disconnected"));
2655 empathy_call_window_show_hangup_button (self, FALSE);
2657 /* Unsensitive the camera and mic button */
2658 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2659 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2661 /* Be sure that the mic button is enabled */
2662 empathy_audio_src_set_mute (
2663 EMPATHY_GST_AUDIO_SRC (self->priv->audio_input), FALSE);
2665 if (priv->camera_state == CAMERA_STATE_ON)
2667 /* Restart the preview with the new pipeline. */
2668 display_video_preview (self, TRUE);
2671 /* destroy the video output; it will be recreated when we'll redial */
2672 disconnect_video_output_motion_handler (self);
2673 if (priv->video_output != NULL)
2674 clutter_actor_destroy (priv->video_output);
2675 priv->video_output = NULL;
2676 if (priv->got_video_src > 0)
2678 g_source_remove (priv->got_video_src);
2679 priv->got_video_src = 0;
2682 gtk_widget_show (priv->remote_user_avatar_widget);
2684 reset_details_pane (self);
2686 priv->sending_video = FALSE;
2687 priv->call_started = FALSE;
2689 could_disconnect = TRUE;
2691 /* TODO: display the self avatar of the preview (depends if the "Always
2692 * Show Video Preview" is enabled or not) */
2695 return could_disconnect;
2700 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2703 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2704 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2706 if (empathy_call_window_disconnected (self, TRUE) &&
2707 priv->call_state == REDIALING)
2708 empathy_call_window_restart_call (self);
2712 empathy_call_window_content_is_raw (TfContent *content)
2714 FsConference *conference;
2717 g_object_get (content, "fs-conference", &conference, NULL);
2718 g_assert (conference != NULL);
2720 /* FIXME: Ugly hack, update when moving a packetization property into
2722 israw = g_str_has_prefix (GST_OBJECT_NAME (conference), "fsrawconf");
2723 gst_object_unref (conference);
2729 empathy_call_window_content_removed_cb (EmpathyCallHandler *handler,
2731 EmpathyCallWindow *self)
2733 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2734 FsMediaType media_type;
2736 DEBUG ("removing content");
2738 g_object_get (content, "media-type", &media_type, NULL);
2741 * This assumes that there is only one video stream per channel...
2744 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2746 if (priv->funnel != NULL)
2750 output = priv->video_output_sink;
2752 gst_element_set_state (output, GST_STATE_NULL);
2753 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2755 gst_bin_remove (GST_BIN (priv->pipeline), output);
2756 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2757 priv->funnel = NULL;
2760 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2762 if (priv->audio_output != NULL)
2764 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2766 if (priv->audio_output_added)
2767 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2768 priv->audio_output = NULL;
2769 priv->audio_output_added = FALSE;
2774 g_assert_not_reached ();
2781 empathy_call_window_framerate_changed_cb (EmpathyCallHandler *handler,
2783 EmpathyCallWindow *self)
2785 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2787 DEBUG ("Framerate changed to %u", framerate);
2789 if (priv->video_input != NULL)
2790 empathy_video_src_set_framerate (priv->video_input, framerate);
2794 empathy_call_window_resolution_changed_cb (EmpathyCallHandler *handler,
2797 EmpathyCallWindow *self)
2799 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2801 DEBUG ("Resolution changed to %ux%u", width, height);
2803 if (priv->video_input != NULL)
2805 empathy_video_src_set_resolution (priv->video_input, width, height);
2809 /* Called with global lock held */
2811 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2813 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2817 if (priv->funnel == NULL)
2819 output = priv->video_output_sink;
2821 priv->funnel = gst_element_factory_make ("funnel", NULL);
2823 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2828 g_warning ("Could not create video funnel");
2832 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2834 gst_object_unref (priv->funnel);
2835 priv->funnel = NULL;
2836 g_warning ("Could not add funnel to pipeline");
2840 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2842 g_warning ("Could not add the video output widget to the pipeline");
2846 if (!gst_element_link (priv->funnel, output))
2848 g_warning ("Could not link output sink to funnel");
2849 goto error_output_added;
2852 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2854 g_warning ("Could not start video sink");
2855 goto error_output_added;
2858 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2860 g_warning ("Could not start funnel");
2861 goto error_output_added;
2865 pad = gst_element_get_request_pad (priv->funnel, "sink_%u");
2867 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2871 g_warning ("Could not get request pad from funnel");
2878 gst_element_set_locked_state (priv->funnel, TRUE);
2879 gst_element_set_locked_state (output, TRUE);
2881 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2882 gst_element_set_state (output, GST_STATE_NULL);
2884 gst_bin_remove (GST_BIN (priv->pipeline), output);
2885 gst_element_set_locked_state (output, FALSE);
2889 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2890 priv->funnel = NULL;
2895 /* Called with global lock held */
2897 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self,
2900 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2902 GstPadTemplate *template;
2904 if (!priv->audio_output_added)
2906 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2908 g_warning ("Could not add audio sink to pipeline");
2909 g_object_unref (priv->audio_output);
2910 goto error_add_output;
2913 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2915 g_warning ("Could not start audio sink");
2918 priv->audio_output_added = TRUE;
2921 template = gst_element_class_get_pad_template (
2922 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2924 pad = gst_element_request_pad (priv->audio_output,
2925 template, NULL, NULL);
2929 g_warning ("Could not get sink pad from sink");
2936 gst_element_set_locked_state (priv->audio_output, TRUE);
2937 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2938 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2939 priv->audio_output = NULL;
2947 empathy_call_window_update_timer (gpointer user_data)
2949 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2950 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2951 const gchar *status;
2955 time_ = g_timer_elapsed (priv->timer, NULL);
2957 if (priv->call_state == HELD)
2958 status = _("On hold");
2959 else if (priv->call_state == DISCONNECTED)
2960 status = _("Disconnected");
2961 else if (priv->muted)
2964 status = _("Duration");
2966 /* Translators: 'status - minutes:seconds' the caller has been connected */
2967 str = g_strdup_printf (_("%s — %d:%02dm"),
2969 (int) time_ / 60, (int) time_ % 60);
2970 empathy_call_window_status_message (self, str);
2978 EMP_RESPONSE_BALANCE
2982 on_error_infobar_response_cb (GtkInfoBar *info_bar,
2986 switch (response_id)
2988 case GTK_RESPONSE_CLOSE:
2989 gtk_widget_destroy (GTK_WIDGET (info_bar));
2991 case EMP_RESPONSE_BALANCE:
2992 empathy_url_show (GTK_WIDGET (info_bar),
2993 g_object_get_data (G_OBJECT (info_bar), "uri"));
2999 display_error (EmpathyCallWindow *self,
3003 const gchar *details,
3004 const gchar *button_text,
3006 gint button_response)
3008 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3009 GtkWidget *info_bar;
3010 GtkWidget *content_area;
3017 /* Create info bar */
3018 info_bar = gtk_info_bar_new ();
3020 if (button_text != NULL)
3022 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
3023 button_text, button_response);
3024 g_object_set_data_full (G_OBJECT (info_bar),
3025 "uri", g_strdup (uri), g_free);
3028 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
3029 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
3031 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
3033 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
3035 /* hbox containing the image and the messages vbox */
3036 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
3037 gtk_container_add (GTK_CONTAINER (content_area), hbox);
3040 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
3041 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
3043 /* vbox containing the main message and the details expander */
3044 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
3045 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
3048 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
3050 label = gtk_label_new (NULL);
3051 gtk_label_set_markup (GTK_LABEL (label), txt);
3052 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
3053 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
3056 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
3059 if (details != NULL)
3061 GtkWidget *expander;
3063 expander = gtk_expander_new (_("Technical Details"));
3065 txt = g_strdup_printf ("<i>%s</i>", details);
3067 label = gtk_label_new (NULL);
3068 gtk_label_set_markup (GTK_LABEL (label), txt);
3069 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
3070 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
3073 gtk_container_add (GTK_CONTAINER (expander), label);
3074 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
3077 g_signal_connect (info_bar, "response",
3078 G_CALLBACK (on_error_infobar_response_cb), NULL);
3080 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
3081 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
3082 gtk_widget_show_all (info_bar);
3087 media_stream_error_to_txt (EmpathyCallWindow *self,
3088 TpCallChannel *call,
3090 TpMediaStreamError error)
3092 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3093 const gchar *cm = NULL;
3099 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
3101 return g_strdup_printf (
3102 _("%s's software does not understand any of the audio formats "
3103 "supported by your computer"),
3104 empathy_contact_get_alias (priv->contact));
3106 return g_strdup_printf (
3107 _("%s's software does not understand any of the video formats "
3108 "supported by your computer"),
3109 empathy_contact_get_alias (priv->contact));
3111 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
3112 return g_strdup_printf (
3113 _("Can't establish a connection to %s. "
3114 "One of you might be on a network that does not allow "
3115 "direct connections."),
3116 empathy_contact_get_alias (priv->contact));
3118 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
3119 return g_strdup (_("There was a failure on the network"));
3121 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
3123 return g_strdup (_("The audio formats necessary for this call "
3124 "are not installed on your computer"));
3126 return g_strdup (_("The video formats necessary for this call "
3127 "are not installed on your computer"));
3129 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
3130 tp_connection_parse_object_path (
3131 tp_channel_get_connection (TP_CHANNEL (call)),
3134 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
3135 "product=Telepathy&component=%s", cm);
3137 result = g_strdup_printf (
3138 _("Something unexpected happened in a Telepathy component. "
3139 "Please <a href=\"%s\">report this bug</a> and attach "
3140 "logs gathered from the 'Debug' window in the Help menu."), url);
3146 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
3147 return g_strdup (_("There was a failure in the call engine"));
3149 case TP_MEDIA_STREAM_ERROR_EOS:
3150 return g_strdup (_("The end of the stream was reached"));
3152 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
3159 empathy_call_window_stream_error (EmpathyCallWindow *self,
3160 TpCallChannel *call,
3169 desc = media_stream_error_to_txt (self, call, audio, code);
3172 /* No description, use the error message. That's not great as it's not
3173 * localized but it's better than nothing. */
3174 display_error (self, call, icon, title, msg, NULL);
3178 display_error (self, call, icon, title, desc, msg);
3184 empathy_call_window_audio_stream_error (TpCallChannel *call,
3187 EmpathyCallWindow *self)
3189 empathy_call_window_stream_error (self, call, TRUE, code, msg,
3190 "gnome-stock-mic", _("Can't establish audio stream"));
3194 empathy_call_window_video_stream_error (TpCallChannel *call,
3197 EmpathyCallWindow *self)
3199 empathy_call_window_stream_error (self, call, FALSE, code, msg,
3200 "camera-web", _("Can't establish video stream"));
3205 show_balance_error (EmpathyCallWindow *self)
3209 gchar *balance, *tmp;
3210 const gchar *uri, *currency;
3214 g_object_get (self->priv->handler,
3215 "call-channel", &call,
3218 conn = tp_channel_get_connection (call);
3219 g_object_unref (call);
3221 uri = tp_connection_get_balance_uri (conn);
3223 if (!tp_connection_get_balance (conn, &amount, &scale, ¤cy))
3225 /* unknown balance */
3226 balance = g_strdup ("(--)");
3230 char *money = empathy_format_currency (amount, scale, currency);
3232 balance = g_strdup_printf ("%s %s",
3237 tmp = g_strdup_printf (_("Your current balance is %s."), balance),
3239 display_error (self,
3241 _("Sorry, you don’t have enough credit for that call."),
3245 EMP_RESPONSE_BALANCE);
3252 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
3255 EmpathyCallWindow *self)
3257 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3258 TpCallChannel *call;
3259 gboolean can_send_video;
3261 if (state == TP_CALL_STATE_ENDED)
3263 DEBUG ("Call ended: %s", (reason != NULL && reason[0] != '\0') ? reason : "unspecified reason");
3264 empathy_call_window_disconnected (self, TRUE);
3265 if (!tp_strdiff (reason, TP_ERROR_STR_INSUFFICIENT_BALANCE))
3266 show_balance_error (self);
3270 if (state != TP_CALL_STATE_ACCEPTED)
3273 if (priv->call_state == CONNECTED)
3276 g_timer_start (priv->timer);
3277 priv->call_state = CONNECTED;
3279 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3281 can_send_video = priv->video_input != NULL &&
3282 empathy_contact_can_voip_video (priv->contact) &&
3283 tpaw_camera_monitor_get_available (priv->camera_monitor);
3285 g_object_get (priv->handler, "call-channel", &call, NULL);
3287 if (tp_call_channel_has_dtmf (call))
3288 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
3290 if (priv->video_input == NULL)
3291 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
3293 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
3295 empathy_call_window_show_hangup_button (self, TRUE);
3297 gtk_widget_set_sensitive (priv->mic_button, TRUE);
3299 clutter_actor_hide (priv->video_output);
3300 gtk_widget_show (priv->remote_user_avatar_widget);
3302 g_object_unref (call);
3304 g_mutex_lock (&priv->lock);
3306 priv->timer_id = g_timeout_add_seconds (1,
3307 empathy_call_window_update_timer, self);
3309 g_mutex_unlock (&priv->lock);
3311 empathy_call_window_update_timer (self);
3313 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
3317 empathy_call_window_show_video_output_cb (gpointer user_data)
3319 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3321 if (self->priv->video_output != NULL)
3323 gtk_widget_hide (self->priv->remote_user_avatar_widget);
3324 clutter_actor_show (self->priv->video_output);
3325 clutter_actor_raise_top (self->priv->overlay_bin);
3332 empathy_call_window_check_video_cb (gpointer data)
3334 EmpathyCallWindow *self = data;
3336 if (self->priv->got_video)
3338 self->priv->got_video = FALSE;
3342 /* No video in the last N seconds, display the remote avatar */
3343 empathy_call_window_show_video_output (self, FALSE);
3348 /* Called from the streaming thread */
3350 static GstPadProbeReturn
3351 empathy_call_window_video_probe_cb (GstPad *pad,
3352 GstPadProbeInfo *info,
3355 EmpathyCallWindow *self = user_data;
3357 if (G_UNLIKELY (!self->priv->got_video))
3359 /* show the remote video */
3360 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3361 empathy_call_window_show_video_output_cb,
3362 g_object_ref (self), g_object_unref);
3364 self->priv->got_video = TRUE;
3367 return GST_PAD_PROBE_OK;
3371 empathy_call_window_video_probe_cb (GstPad *pad,
3372 GstMiniObject *mini_obj,
3373 EmpathyCallWindow *self)
3376 if (GST_IS_EVENT (mini_obj))
3379 if (G_UNLIKELY (!self->priv->got_video))
3381 /* show the remote video */
3382 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3383 empathy_call_window_show_video_output_cb,
3384 g_object_ref (self), g_object_unref);
3386 self->priv->got_video = TRUE;
3393 /* Called from the streaming thread */
3395 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
3396 TfContent *content, GstPad *src, gpointer user_data)
3398 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3399 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3400 gboolean retval = FALSE;
3405 g_mutex_lock (&priv->lock);
3407 g_object_get (content, "media-type", &media_type, NULL);
3411 case TP_MEDIA_STREAM_TYPE_AUDIO:
3412 pad = empathy_call_window_get_audio_sink_pad (self, content);
3414 case TP_MEDIA_STREAM_TYPE_VIDEO:
3415 g_idle_add (empathy_call_window_show_video_output_cb, self);
3416 pad = empathy_call_window_get_video_sink_pad (self);
3419 gst_pad_add_probe (src,
3420 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_BUFFER_LIST,
3421 empathy_call_window_video_probe_cb, self, NULL);
3423 gst_pad_add_data_probe (src,
3424 G_CALLBACK (empathy_call_window_video_probe_cb), self);
3426 if (priv->got_video_src > 0)
3427 g_source_remove (priv->got_video_src);
3428 priv->got_video_src = g_timeout_add_seconds (1,
3429 empathy_call_window_check_video_cb, self);
3432 g_assert_not_reached ();
3438 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
3439 g_warning ("Could not link %s sink pad",
3440 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
3444 gst_object_unref (pad);
3448 /* If no sink could be linked, try to add fakesink to prevent the whole call
3453 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
3455 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
3457 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
3458 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
3459 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
3461 gst_element_set_locked_state (fakesink, TRUE);
3462 gst_element_set_state (fakesink, GST_STATE_NULL);
3463 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
3467 DEBUG ("Could not link real sink, linked fakesink instead");
3469 gst_object_unref (sinkpad);
3473 gst_object_unref (fakesink);
3478 g_mutex_unlock (&priv->lock);
3484 empathy_call_window_prepare_audio_output (EmpathyCallWindow *self,
3487 EmpathyCallWindowPriv *priv = self->priv;
3489 g_assert (priv->audio_output_added == FALSE);
3490 g_assert (priv->audio_output == FALSE);
3492 priv->audio_output = empathy_audio_sink_new ();
3493 g_object_ref_sink (priv->audio_output);
3495 /* volume button to output volume linking */
3496 g_object_bind_property (priv->audio_output, "volume",
3497 priv->volume_button, "value",
3498 G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
3500 g_object_bind_property_full (content, "requested-output-volume",
3501 priv->audio_output, "volume",
3503 audio_control_volume_to_element,
3504 element_volume_to_audio_control,
3507 /* Link volumes together, sync the current audio input volume property
3508 * back to farstream first */
3509 g_object_bind_property_full (priv->audio_output, "volume",
3510 content, "reported-output-volume",
3511 G_BINDING_SYNC_CREATE,
3512 element_volume_to_audio_control,
3513 audio_control_volume_to_element,
3516 /* For raw audio conferences assume that the producer of the raw data
3517 * has already processed it, so turn off any echo cancellation and any
3518 * other audio improvements that come with it */
3519 empathy_audio_sink_set_echo_cancel (
3520 EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3521 !empathy_call_window_content_is_raw (content));
3526 empathy_call_window_content_added_cb (EmpathyCallHandler *handler,
3527 TfContent *content, gpointer user_data)
3529 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3530 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3532 FsMediaType media_type;
3533 gboolean retval = FALSE;
3535 g_object_get (content, "media-type", &media_type, "sink-pad", &sink, NULL);
3536 g_assert (sink != NULL);
3540 case FS_MEDIA_TYPE_AUDIO:
3542 /* For raw audio conferences assume that the receiver of the raw data
3543 * wants it unprocessed, so turn off any echo cancellation and any
3544 * other audio improvements that come with it */
3545 empathy_audio_src_set_echo_cancel (
3546 EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3547 !empathy_call_window_content_is_raw (content));
3549 /* Link volumes together, sync the current audio input volume property
3550 * back to farstream first */
3551 g_object_bind_property_full (content, "requested-input-volume",
3552 priv->audio_input, "volume",
3554 audio_control_volume_to_element,
3555 element_volume_to_audio_control,
3558 g_object_bind_property_full (priv->audio_input, "volume",
3559 content, "reported-input-volume",
3560 G_BINDING_SYNC_CREATE,
3561 element_volume_to_audio_control,
3562 audio_control_volume_to_element,
3565 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
3567 g_warning ("Could not add audio source to pipeline");
3571 pad = gst_element_get_static_pad (priv->audio_input, "src");
3574 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3575 g_warning ("Could not get source pad from audio source");
3579 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3581 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3582 gst_object_unref (pad);
3583 g_warning ("Could not link audio source to farsight");
3586 gst_object_unref (pad);
3588 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3590 g_warning ("Could not start audio source");
3591 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3592 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3596 /* Prepare our audio output, not added yet though */
3597 empathy_call_window_prepare_audio_output (self, content);
3601 case FS_MEDIA_TYPE_VIDEO:
3602 if (priv->video_tee != NULL)
3605 pad = gst_element_get_request_pad (priv->video_tee, "src_%u");
3607 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3609 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3611 g_warning ("Could not link video source input pipeline");
3614 gst_object_unref (pad);
3620 g_assert_not_reached ();
3623 gst_object_unref (sink);
3628 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3630 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3631 GstElement *preview;
3633 disable_camera (self);
3635 DEBUG ("remove video input");
3636 preview = priv->video_preview_sink;
3638 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3639 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3640 gst_element_set_state (preview, GST_STATE_NULL);
3642 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3645 g_object_unref (priv->video_input);
3646 priv->video_input = NULL;
3647 g_object_unref (priv->video_tee);
3648 priv->video_tee = NULL;
3649 clutter_actor_destroy (priv->video_preview);
3650 priv->video_preview = NULL;
3652 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3653 empathy_camera_menu_set_sensitive (priv->camera_menu, FALSE);
3657 start_call (EmpathyCallWindow *self)
3659 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3661 g_signal_emit (self, signals[SIG_INHIBIT], 0, TRUE);
3663 priv->call_started = TRUE;
3664 empathy_call_handler_start_call (priv->handler,
3665 gtk_get_current_event_time ());
3667 if (empathy_call_handler_has_initial_video (priv->handler))
3669 TpCallChannel *call;
3672 g_object_get (priv->handler, "call-channel", &call, NULL);
3673 /* If the call channel isn't set yet we're requesting it, if we're
3674 * requesting it with initial video it should be PENDING_SEND when we get
3677 s = TP_SENDING_STATE_PENDING_SEND;
3679 s = empathy_call_channel_get_video_state (call);
3681 if (s == TP_SENDING_STATE_PENDING_SEND ||
3682 s == TP_SENDING_STATE_SENDING)
3684 /* Enable 'send video' buttons and display the preview */
3685 gtk_toggle_button_set_active (
3686 GTK_TOGGLE_BUTTON (priv->camera_button), TRUE);
3690 gtk_toggle_button_set_active (
3691 GTK_TOGGLE_BUTTON (priv->camera_button), FALSE);
3693 if (priv->video_preview == NULL)
3695 create_video_preview (self);
3696 add_video_preview_to_pipeline (self);
3701 g_object_unref (call);
3706 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3709 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3710 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3711 GstState newstate, pending;
3713 empathy_call_handler_bus_message (priv->handler, bus, message);
3715 switch (GST_MESSAGE_TYPE (message))
3717 case GST_MESSAGE_STATE_CHANGED:
3718 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3720 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3722 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3723 !priv->call_started)
3725 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3726 if (newstate == GST_STATE_PAUSED)
3728 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3729 priv->pipeline_playing = TRUE;
3731 if (priv->start_call_when_playing)
3735 if (priv->video_preview_sink != NULL &&
3736 GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_preview_sink))
3738 gst_message_parse_state_changed (message, NULL, &newstate,
3741 if (newstate == GST_STATE_PLAYING &&
3742 pending == GST_STATE_VOID_PENDING)
3743 empathy_call_window_stop_camera_spinning (self);
3746 case GST_MESSAGE_ERROR:
3748 GError *error = NULL;
3749 GstElement *gst_error;
3753 gst_message_parse_error (message, &error, &debug);
3754 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3756 g_message ("Element error: %s -- %s\n", error->message, debug);
3758 name = gst_element_get_name (gst_error);
3759 if (g_str_has_prefix (name, VIDEO_INPUT_ERROR_PREFIX))
3761 /* Remove the video input and continue */
3762 if (priv->video_input != NULL)
3763 empathy_call_window_remove_video_input (self);
3764 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3768 empathy_call_window_disconnected (self, TRUE);
3771 g_error_free (error);
3774 case GST_MESSAGE_UNKNOWN:
3775 case GST_MESSAGE_EOS:
3776 case GST_MESSAGE_WARNING:
3777 case GST_MESSAGE_INFO:
3778 case GST_MESSAGE_TAG:
3779 case GST_MESSAGE_BUFFERING:
3780 case GST_MESSAGE_STATE_DIRTY:
3781 case GST_MESSAGE_STEP_DONE:
3782 case GST_MESSAGE_CLOCK_PROVIDE:
3783 case GST_MESSAGE_CLOCK_LOST:
3784 case GST_MESSAGE_NEW_CLOCK:
3785 case GST_MESSAGE_STRUCTURE_CHANGE:
3786 case GST_MESSAGE_STREAM_STATUS:
3787 case GST_MESSAGE_APPLICATION:
3788 case GST_MESSAGE_ELEMENT:
3789 case GST_MESSAGE_SEGMENT_START:
3790 case GST_MESSAGE_SEGMENT_DONE:
3791 case GST_MESSAGE_DURATION:
3792 case GST_MESSAGE_ANY:
3801 empathy_call_window_members_changed_cb (TpCallChannel *call,
3802 GHashTable *updates,
3804 TpCallStateReason *reason,
3805 EmpathyCallWindow *self)
3807 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3808 GHashTableIter iter;
3809 gpointer key, value;
3810 gboolean held = FALSE;
3812 g_hash_table_iter_init (&iter, updates);
3813 while (g_hash_table_iter_next (&iter, &key, &value))
3815 if (GPOINTER_TO_INT (value) & TP_CALL_MEMBER_FLAG_HELD)
3817 /* This assumes this is a 1-1 call, otherwise one participant
3818 * putting the call on hold wouldn't mean the call is on hold
3826 priv->call_state = HELD;
3827 else if (priv->call_state == HELD)
3828 priv->call_state = CONNECTED;
3832 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3834 EmpathyCallWindow *self)
3836 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3837 TpCallChannel *call;
3839 g_object_get (priv->handler, "call-channel", &call, NULL);
3844 tp_g_signal_connect_object (call, "audio-stream-error",
3845 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3846 tp_g_signal_connect_object (call, "video-stream-error",
3847 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3850 tp_g_signal_connect_object (call, "members-changed",
3851 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3853 g_object_unref (call);
3857 empathy_call_window_connect_handler (EmpathyCallWindow *self)
3859 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3860 TpCallChannel *call;
3862 g_signal_connect (priv->handler, "state-changed",
3863 G_CALLBACK (empathy_call_window_state_changed_cb), self);
3864 g_signal_connect (priv->handler, "conference-added",
3865 G_CALLBACK (empathy_call_window_conference_added_cb), self);
3866 g_signal_connect (priv->handler, "conference-removed",
3867 G_CALLBACK (empathy_call_window_conference_removed_cb), self);
3868 g_signal_connect (priv->handler, "closed",
3869 G_CALLBACK (empathy_call_window_channel_closed_cb), self);
3870 g_signal_connect (priv->handler, "src-pad-added",
3871 G_CALLBACK (empathy_call_window_src_added_cb), self);
3872 g_signal_connect (priv->handler, "content-added",
3873 G_CALLBACK (empathy_call_window_content_added_cb), self);
3874 g_signal_connect (priv->handler, "content-removed",
3875 G_CALLBACK (empathy_call_window_content_removed_cb), self);
3877 /* We connect to ::call-channel unconditionally since we'll
3878 * get new channels if we hangup and redial or if we reuse the
3880 g_signal_connect (priv->handler, "notify::call-channel",
3881 G_CALLBACK (call_handler_notify_call_cb), self);
3883 g_signal_connect (priv->handler, "framerate-changed",
3884 G_CALLBACK (empathy_call_window_framerate_changed_cb), self);
3885 g_signal_connect (priv->handler, "resolution-changed",
3886 G_CALLBACK (empathy_call_window_resolution_changed_cb), self);
3888 g_object_get (priv->handler, "call-channel", &call, NULL);
3891 /* We won't get notify::call-channel for this channel, so
3892 * directly call the callback. */
3893 call_handler_notify_call_cb (priv->handler, NULL, self);
3894 g_object_unref (call);
3899 empathy_call_window_realized_cb (GtkWidget *widget,
3900 EmpathyCallWindow *self)
3904 /* Make the hangup button twice as wide */
3905 width = gtk_widget_get_allocated_width (self->priv->hangup_button);
3906 gtk_widget_set_size_request (self->priv->hangup_button, width * 2, -1);
3908 empathy_call_window_connect_handler (self);
3910 gst_element_set_state (self->priv->pipeline, GST_STATE_PAUSED);
3914 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3915 EmpathyCallWindow *window)
3917 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3919 if (priv->pipeline != NULL)
3921 if (priv->bus_message_source_id != 0)
3923 g_source_remove (priv->bus_message_source_id);
3924 priv->bus_message_source_id = 0;
3927 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3930 if (priv->call_state == CONNECTING)
3931 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3937 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3940 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3942 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3947 gtk_widget_hide (priv->dtmf_panel);
3948 gtk_widget_hide (menu);
3949 gtk_widget_hide (priv->toolbar);
3953 if (priv->dialpad_was_visible_before_fs)
3954 gtk_widget_show (priv->dtmf_panel);
3956 gtk_widget_show (menu);
3957 gtk_widget_show (priv->toolbar);
3959 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3960 priv->original_height_before_fs);
3965 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3967 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3969 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3970 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3972 if (priv->video_output != NULL)
3975 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3976 priv->video_output, TRUE, TRUE,
3977 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3984 empathy_call_window_state_event_cb (GtkWidget *widget,
3985 GdkEventWindowState *event, EmpathyCallWindow *window)
3987 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3989 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3990 gboolean set_fullscreen = event->new_window_state &
3991 GDK_WINDOW_STATE_FULLSCREEN;
3995 gboolean dialpad_was_visible;
3996 GtkAllocation allocation;
3997 gint original_width, original_height;
3999 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
4000 original_width = allocation.width;
4001 original_height = allocation.height;
4003 g_object_get (priv->dtmf_panel,
4004 "visible", &dialpad_was_visible,
4007 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
4008 priv->original_width_before_fs = original_width;
4009 priv->original_height_before_fs = original_height;
4011 if (priv->video_output_motion_handler_id == 0 &&
4012 priv->video_output != NULL)
4014 priv->video_output_motion_handler_id = g_signal_connect (
4015 G_OBJECT (priv->video_container), "motion-notify-event",
4016 G_CALLBACK (empathy_call_window_video_output_motion_notify),
4022 disconnect_video_output_motion_handler (window);
4025 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
4027 show_controls (window, set_fullscreen);
4028 show_borders (window, set_fullscreen);
4029 gtk_action_set_stock_id (priv->menu_fullscreen,
4030 (set_fullscreen ? "view-restore" : "view-fullscreen"));
4031 priv->is_fullscreen = set_fullscreen;
4038 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
4041 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4042 int w, h, dialpad_width;
4043 GtkAllocation allocation;
4045 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
4046 w = allocation.width;
4047 h = allocation.height;
4049 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
4053 gtk_widget_show (priv->dtmf_panel);
4059 gtk_widget_hide (priv->dtmf_panel);
4063 gtk_window_resize (GTK_WINDOW (window), w, h);
4067 empathy_call_window_set_send_video (EmpathyCallWindow *window,
4070 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4071 TpCallChannel *call;
4073 priv->sending_video = (state == CAMERA_STATE_ON);
4075 if (state == CAMERA_STATE_ON)
4077 /* When we start sending video, we want to show the video preview by
4079 display_video_preview (window, TRUE);
4083 display_video_preview (window, FALSE);
4086 if (priv->call_state != CONNECTED)
4089 g_object_get (priv->handler, "call-channel", &call, NULL);
4090 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
4091 empathy_call_channel_send_video (call, priv->sending_video);
4092 g_object_unref (call);
4096 empathy_call_window_hangup_cb (gpointer object,
4097 EmpathyCallWindow *self)
4099 /* stopping the call will put it the ENDED state and
4100 * from state_changed_cb we'll reconfigure the window
4102 empathy_call_handler_stop_call (self->priv->handler);
4106 empathy_call_window_restart_call (EmpathyCallWindow *window)
4108 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4110 /* Remove error info bars */
4111 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
4112 (GtkCallback) gtk_widget_destroy, NULL);
4114 create_video_output_widget (window);
4115 priv->outgoing = TRUE;
4116 empathy_call_window_set_state_connecting (window);
4118 if (priv->pipeline_playing)
4119 start_call (window);
4121 /* call will be started when the pipeline is ready */
4122 priv->start_call_when_playing = TRUE;
4124 empathy_call_window_setup_avatars (window, priv->handler);
4126 empathy_call_window_show_hangup_button (window, TRUE);
4130 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
4131 EmpathyCallWindow *window)
4135 active = gtk_toggle_tool_button_get_active (button);
4137 empathy_call_window_show_dialpad (window, active);
4141 empathy_call_window_fullscreen_cb (gpointer object,
4142 EmpathyCallWindow *window)
4144 empathy_call_window_fullscreen_toggle (window);
4148 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
4150 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4152 if (priv->is_fullscreen)
4153 gtk_window_unfullscreen (GTK_WINDOW (window));
4155 gtk_window_fullscreen (GTK_WINDOW (window));
4159 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
4160 GdkEventButton *event, EmpathyCallWindow *window)
4162 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
4164 empathy_call_window_video_menu_popup (window, event->button);
4172 empathy_call_window_key_press_cb (GtkWidget *video_output,
4173 GdkEventKey *event, EmpathyCallWindow *window)
4175 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4178 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
4180 /* Since we are in fullscreen mode, toggling will bring us back to
4182 empathy_call_window_fullscreen_toggle (window);
4186 key = gdk_keyval_to_unicode (event->keyval);
4207 gtk_toggle_tool_button_set_active (
4208 GTK_TOGGLE_TOOL_BUTTON (priv->dialpad_button), TRUE);
4210 empathy_dialpad_widget_press_key (
4211 EMPATHY_DIALPAD_WIDGET (priv->dtmf_panel), key);
4217 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
4218 GdkEventMotion *event, EmpathyCallWindow *window)
4220 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4222 if (priv->is_fullscreen)
4224 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
4226 /* Show the bottom toolbar */
4227 empathy_call_window_motion_notify_cb (NULL, NULL, window);
4234 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
4238 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4240 menu = gtk_ui_manager_get_widget (priv->ui_manager,
4242 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
4243 button, gtk_get_current_event_time ());
4244 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
4248 empathy_call_window_status_message (EmpathyCallWindow *self,
4251 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
4255 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
4257 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4259 return priv->ui_manager;
4262 EmpathyGstAudioSrc *
4263 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
4265 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4267 return (EmpathyGstAudioSrc *) priv->audio_input;
4270 EmpathyGstVideoSrc *
4271 empathy_call_window_get_video_src (EmpathyCallWindow *self)
4273 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);
4277 empathy_call_window_change_webcam (EmpathyCallWindow *self,
4278 const gchar *device)
4280 EmpathyGstVideoSrc *video;
4283 /* Restart the camera only if it's already running */
4284 running = (self->priv->video_preview != NULL);
4285 video = empathy_call_window_get_video_src (self);
4288 empathy_call_window_play_camera (self, FALSE);
4290 empathy_video_src_change_device (video, device);
4293 empathy_call_window_play_camera (self, TRUE);