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
23 #include <glib/gi18n.h>
25 #include <telepathy-farstream/telepathy-farstream.h>
27 #include <farstream/fs-element-added-notifier.h>
28 #include <farstream/fs-utils.h>
30 #include <libempathy/empathy-camera-monitor.h>
31 #include <libempathy/empathy-gsettings.h>
32 #include <libempathy/empathy-request-util.h>
33 #include <libempathy/empathy-utils.h>
35 #include <libempathy-gtk/empathy-dialpad-widget.h>
36 #include <libempathy-gtk/empathy-ui-utils.h>
37 #include <libempathy-gtk/empathy-sound-manager.h>
38 #include <libempathy-gtk/empathy-geometry.h>
39 #include <libempathy-gtk/empathy-images.h>
40 #include <libempathy-gtk/empathy-call-utils.h>
42 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
43 #include <libempathy/empathy-debug.h>
45 #include "empathy-call-window-fullscreen.h"
46 #include "empathy-about-dialog.h"
47 #include "empathy-audio-sink.h"
48 #include "empathy-mic-menu.h"
49 #include "empathy-preferences.h"
50 #include "empathy-rounded-actor.h"
51 #include "empathy-rounded-rectangle.h"
52 #include "empathy-rounded-texture.h"
53 #include "empathy-camera-menu.h"
55 #define CONTENT_HBOX_SPACING 3
56 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 0
57 #define OVERLAY_MARGIN 6
59 #define REMOTE_VIDEO_DEFAULT_WIDTH 320
60 #define REMOTE_VIDEO_DEFAULT_HEIGHT 240
62 #define SELF_VIDEO_SECTION_WIDTH 120
63 #define SELF_VIDEO_SECTION_HEIGHT 90
64 #define SELF_VIDEO_SECTION_MARGIN 2
65 #define SELF_VIDEO_SECTION_BORDER SELF_VIDEO_SECTION_MARGIN*2
67 /* The avatar's default width and height are set to the same value because we
68 want a square icon. */
69 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT REMOTE_VIDEO_DEFAULT_HEIGHT
70 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH REMOTE_VIDEO_DEFAULT_HEIGHT
72 #define SMALL_TOOLBAR_SIZE 36
74 /* If an video input error occurs, the error message will start with "v4l" */
75 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
77 /* The time interval in milliseconds between 2 outgoing rings */
78 #define MS_BETWEEN_RING 500
80 /* The roundedness of preview box and placeholders */
81 #define PREVIEW_ROUND_FACTOR 16
83 #define PREVIEW_BUTTON_OPACITY 180
85 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
88 PROP_CALL_HANDLER = 1,
96 static guint signals[LAST_SIGNAL];
99 RINGING, /* Incoming call */
100 CONNECTING, /* Outgoing call */
101 CONNECTED, /* Connected */
102 HELD, /* Connected, but on hold */
103 DISCONNECTED, /* Disconnected */
104 REDIALING /* Redialing (special case of CONNECTING) */
108 CAMERA_STATE_OFF = 0,
114 PREVIEW_POS_TOP_LEFT,
115 PREVIEW_POS_TOP_RIGHT,
116 PREVIEW_POS_BOTTOM_LEFT,
117 PREVIEW_POS_BOTTOM_RIGHT,
120 struct _EmpathyCallWindowPriv
122 gboolean dispose_has_run;
123 EmpathyCallHandler *handler;
125 EmpathyContact *contact;
127 EmpathyCameraMonitor *camera_monitor;
129 CallState call_state;
132 GtkUIManager *ui_manager;
133 GtkWidget *errors_vbox;
134 /* widget displays the video received from the remote user. This widget is
135 * alive only during call. */
136 ClutterActor *video_output;
137 ClutterActor *video_preview;
138 ClutterActor *drag_preview;
139 ClutterActor *preview_shown_button;
140 ClutterActor *preview_hidden_button;
141 ClutterActor *preview_rectangle1;
142 ClutterActor *preview_rectangle2;
143 ClutterActor *preview_rectangle3;
144 ClutterActor *preview_rectangle4;
145 ClutterActor *preview_spinner_actor;
146 GtkWidget *preview_spinner_widget;
147 GtkWidget *video_container;
148 GtkWidget *remote_user_avatar_widget;
149 GtkWidget *remote_user_avatar_toolbar;
150 GtkWidget *remote_user_name_toolbar;
151 GtkWidget *remote_user_status_toolbar;
152 GtkWidget *status_label;
153 GtkWidget *hangup_button;
154 GtkWidget *audio_call_button;
155 GtkWidget *video_call_button;
156 GtkWidget *mic_button;
157 GtkWidget *microphone_icon;
158 GtkWidget *volume_button;
159 GtkWidget *camera_button;
160 GtkWidget *dialpad_button;
162 GtkWidget *bottom_toolbar;
163 ClutterActor *floating_toolbar;
165 GtkAction *menu_fullscreen;
166 GtkAction *menu_swap_camera;
168 ClutterState *transitions;
170 /* The main box covering all the stage, contaning remote avatar/video */
171 ClutterActor *video_box;
172 ClutterLayoutManager *video_layout;
174 /* A bin layout manager containing a bin for previews
175 * and the floating toolbar */
176 ClutterActor *overlay_bin;
177 ClutterLayoutManager *overlay_layout;
179 /* Bin layout for the previews */
180 ClutterActor *preview_box;
181 ClutterLayoutManager *preview_layout;
183 /* Coordinates of the preview drag event's start. */
184 PreviewPosition preview_pos;
186 /* We keep a reference on the hbox which contains the main content so we can
187 easilly repack everything when toggling fullscreen */
188 GtkWidget *content_hbox;
190 /* These are used to accept or reject an incoming call when the status
192 GtkWidget *incoming_call_dialog;
193 TpCallChannel *pending_channel;
194 TpChannelDispatchOperation *pending_cdo;
195 TpAddDispatchOperationContext *pending_context;
197 gulong video_output_motion_handler_id;
198 guint bus_message_source_id;
200 GtkWidget *dtmf_panel;
203 GtkWidget *details_vbox;
204 GtkWidget *vcodec_encoding_label;
205 GtkWidget *acodec_encoding_label;
206 GtkWidget *vcodec_decoding_label;
207 GtkWidget *acodec_decoding_label;
209 GtkWidget *audio_remote_candidate_label;
210 GtkWidget *audio_local_candidate_label;
211 GtkWidget *video_remote_candidate_label;
212 GtkWidget *video_local_candidate_label;
213 GtkWidget *video_remote_candidate_info_img;
214 GtkWidget *video_local_candidate_info_img;
215 GtkWidget *audio_remote_candidate_info_img;
216 GtkWidget *audio_local_candidate_info_img;
218 GstElement *video_input;
219 GstElement *video_preview_sink;
220 GstElement *video_output_sink;
221 GstElement *audio_input;
222 GstElement *audio_output;
223 gboolean audio_output_added;
224 GstElement *pipeline;
225 GstElement *video_tee;
235 gboolean call_started;
236 gboolean sending_video;
237 CameraState camera_state;
239 EmpathyCallWindowFullscreen *fullscreen;
240 gboolean is_fullscreen;
245 guint inactivity_src;
247 /* Those fields represent the state of the window before it actually was in
249 gboolean dialpad_was_visible_before_fs;
250 gint original_width_before_fs;
251 gint original_height_before_fs;
253 gint x, y, w, h, dialpad_width;
256 /* TRUE if the call should be started when the pipeline is playing */
257 gboolean start_call_when_playing;
258 /* TRUE if we requested to set the pipeline in the playing state */
259 gboolean pipeline_playing;
261 EmpathySoundManager *sound_mgr;
264 EmpathyMicMenu *mic_menu;
265 EmpathyCameraMenu *camera_menu;
270 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
272 static void empathy_call_window_realized_cb (GtkWidget *widget,
273 EmpathyCallWindow *window);
275 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
276 GdkEvent *event, EmpathyCallWindow *window);
278 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
279 GdkEventWindowState *event, EmpathyCallWindow *window);
281 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
284 static void empathy_call_window_hangup_cb (gpointer object,
285 EmpathyCallWindow *window);
287 static void empathy_call_window_fullscreen_cb (gpointer object,
288 EmpathyCallWindow *window);
290 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
292 static gboolean empathy_call_window_video_button_press_cb (
293 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
295 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
296 GdkEventKey *event, EmpathyCallWindow *window);
298 static gboolean empathy_call_window_video_output_motion_notify (
299 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
301 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
304 static void empathy_call_window_connect_handler (EmpathyCallWindow *self);
306 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
307 EmpathyCallWindow *window);
309 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
311 static void empathy_call_window_status_message (EmpathyCallWindow *window,
314 static gboolean empathy_call_window_bus_message (GstBus *bus,
315 GstMessage *message, gpointer user_data);
317 static gboolean empathy_call_window_update_timer (gpointer user_data);
320 make_background_transparent (GtkClutterActor *actor)
322 GdkRGBA transparent = { 0., 0., 0., 0. };
325 widget = gtk_clutter_actor_get_widget (actor);
326 gtk_widget_override_background_color (widget, GTK_STATE_FLAG_NORMAL, &transparent);
330 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
333 gtk_widget_set_visible (self->priv->hangup_button, show);
334 gtk_widget_set_visible (self->priv->audio_call_button, !show);
335 gtk_widget_set_visible (self->priv->video_call_button, !show);
339 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
340 EmpathyCallWindow *self)
342 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
343 empathy_call_window_restart_call (self);
347 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
348 EmpathyCallWindow *self)
350 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
351 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
352 empathy_call_window_restart_call (self);
356 dtmf_start_tone_cb (EmpathyDialpadWidget *dialpad,
358 EmpathyCallWindow *self)
363 g_object_get (self->priv->handler, "call-channel", &call, NULL);
365 tones[0] = tp_dtmf_event_to_char (event);
367 tp_call_channel_send_tones_async (call, tones, NULL, NULL, NULL);
369 g_object_unref (call);
373 empathy_call_window_show_video_output (EmpathyCallWindow *self,
376 if (self->priv->video_output != NULL)
377 g_object_set (self->priv->video_output, "visible", show, NULL);
379 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
381 clutter_actor_raise_top (self->priv->overlay_bin);
385 create_video_output_widget (EmpathyCallWindow *self)
387 EmpathyCallWindowPriv *priv = GET_PRIV (self);
389 g_assert (priv->video_output == NULL);
390 g_assert (priv->pipeline != NULL);
392 priv->video_output = clutter_texture_new ();
394 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
397 priv->video_output_sink = gst_element_factory_make ("cluttersink", NULL);
398 if (priv->video_output_sink == NULL)
399 g_error ("Missing cluttersink");
401 g_object_set (priv->video_output_sink, "texture", priv->video_output, NULL);
403 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
406 gtk_widget_add_events (priv->video_container,
407 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
408 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
409 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
413 create_video_input (EmpathyCallWindow *self)
415 EmpathyCallWindowPriv *priv = GET_PRIV (self);
417 g_assert (priv->video_input == NULL);
418 priv->video_input = empathy_video_src_new ();
419 gst_object_ref_sink (priv->video_input);
423 audio_control_volume_to_element (GBinding *binding,
424 const GValue *source_value,
425 GValue *target_value,
428 /* AudioControl volume is 0-255, with -1 for unknown */
431 hv = g_value_get_int (source_value);
436 g_value_set_double (target_value, hv/255.0);
442 element_volume_to_audio_control (GBinding *binding,
443 const GValue *source_value,
444 GValue *target_value,
449 ev = g_value_get_double (source_value);
450 ev = CLAMP (ev, 0.0, 1.0);
452 g_value_set_int (target_value, ev * 255);
457 audio_input_mute_notify_cb (GObject *obj, GParamSpec *spec,
458 EmpathyCallWindow *self)
461 g_object_get (obj, "mute", &muted, NULL);
463 self->priv->muted = muted;
464 if (muted && self->priv->transitions)
465 clutter_state_set_state (self->priv->transitions, "fade-in");
469 gtk_image_set_from_icon_name (GTK_IMAGE (self->priv->microphone_icon),
470 EMPATHY_IMAGE_MIC_MUTED, GTK_ICON_SIZE_MENU);
474 gtk_image_set_from_icon_name (GTK_IMAGE (self->priv->microphone_icon),
475 EMPATHY_IMAGE_MIC, GTK_ICON_SIZE_MENU);
478 empathy_call_window_update_timer (self);
482 create_audio_input (EmpathyCallWindow *self)
484 EmpathyCallWindowPriv *priv = GET_PRIV (self);
486 g_assert (priv->audio_input == NULL);
487 priv->audio_input = empathy_audio_src_new ();
488 gst_object_ref_sink (priv->audio_input);
490 g_signal_connect (priv->audio_input, "notify::mute",
491 G_CALLBACK (audio_input_mute_notify_cb), self);
495 add_video_preview_to_pipeline (EmpathyCallWindow *self)
497 EmpathyCallWindowPriv *priv = GET_PRIV (self);
500 g_assert (priv->video_preview != NULL);
501 g_assert (priv->pipeline != NULL);
502 g_assert (priv->video_input != NULL);
503 g_assert (priv->video_tee != NULL);
505 preview = priv->video_preview_sink;
507 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
509 g_warning ("Could not add video input to pipeline");
513 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
515 g_warning ("Could not add video preview to pipeline");
519 if (!gst_element_link (priv->video_input, priv->video_tee))
521 g_warning ("Could not link video input to video tee");
525 if (!gst_element_link (priv->video_tee, preview))
527 g_warning ("Could not link video tee to video preview");
533 empathy_call_window_disable_camera_cb (GtkAction *action,
534 EmpathyCallWindow *self)
536 clutter_actor_destroy (self->priv->preview_hidden_button);
538 gtk_toggle_button_set_active (
539 GTK_TOGGLE_BUTTON (self->priv->camera_button), FALSE);
543 empathy_call_window_minimise_camera_cb (GtkAction *action,
544 EmpathyCallWindow *self)
546 clutter_actor_hide (self->priv->video_preview);
547 clutter_actor_show (self->priv->preview_hidden_button);
551 empathy_call_window_maximise_camera_cb (GtkAction *action,
552 EmpathyCallWindow *self)
554 clutter_actor_show (self->priv->video_preview);
555 clutter_actor_hide (self->priv->preview_hidden_button);
559 empathy_call_window_swap_camera_cb (GtkAction *action,
560 EmpathyCallWindow *self)
562 const GList *cameras, *l;
565 DEBUG ("Swapping the camera");
567 cameras = empathy_camera_monitor_get_cameras (self->priv->camera_monitor);
568 current_cam = empathy_video_src_dup_device (
569 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
571 for (l = cameras; l != NULL; l = l->next)
573 EmpathyCamera *camera = l->data;
575 if (!tp_strdiff (camera->device, current_cam))
580 next = l->next->data;
582 next = cameras->data;
584 /* EmpathyCameraMenu will update itself and do the actual change
586 g_settings_set_string (self->priv->settings,
587 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
594 g_free (current_cam);
598 empathy_call_window_camera_added_cb (EmpathyCameraMonitor *monitor,
599 EmpathyCamera *camera,
600 EmpathyCallWindow *self)
602 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
604 gtk_action_set_visible (self->priv->menu_swap_camera,
605 g_list_length ((GList *) cameras) >= 2);
609 empathy_call_window_camera_removed_cb (EmpathyCameraMonitor *monitor,
610 EmpathyCamera *camera,
611 EmpathyCallWindow *self)
613 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
615 gtk_action_set_visible (self->priv->menu_swap_camera,
616 g_list_length ((GList *) cameras) >= 2);
620 empathy_call_window_preview_button_clicked_cb (ClutterClickAction *action,
622 EmpathyCallWindow *self)
626 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
628 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
629 0, gtk_get_current_event_time ());
630 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
634 empathy_call_window_preview_hidden_button_clicked_cb (
635 ClutterClickAction *action,
637 EmpathyCallWindow *self)
641 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
642 "/preview-hidden-menu");
643 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
644 0, gtk_get_current_event_time ());
645 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
648 static ClutterActor *
649 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
650 ClutterBinAlignment x,
651 ClutterBinAlignment y)
653 ClutterActor *rectangle;
655 rectangle = CLUTTER_ACTOR (empathy_rounded_rectangle_new (
656 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT,
657 PREVIEW_ROUND_FACTOR));
659 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->preview_layout),
661 clutter_actor_hide (rectangle);
667 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
671 self->priv->preview_layout = clutter_bin_layout_new (
672 CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_CENTER);
673 self->priv->preview_box = box = clutter_box_new (self->priv->preview_layout);
675 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->overlay_layout),
677 CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL);
679 self->priv->preview_rectangle1 =
680 empathy_call_window_create_preview_rectangle (self,
681 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
682 self->priv->preview_rectangle2 =
683 empathy_call_window_create_preview_rectangle (self,
684 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
685 self->priv->preview_rectangle3 =
686 empathy_call_window_create_preview_rectangle (self,
687 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
688 self->priv->preview_rectangle4 =
689 empathy_call_window_create_preview_rectangle (self,
690 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
694 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
697 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
698 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
699 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
700 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
704 empathy_call_window_get_preview_coordinates (EmpathyCallWindow *self,
709 guint ret_x = 0, ret_y = 0;
712 if (!clutter_actor_has_allocation (self->priv->preview_box))
715 clutter_actor_get_geometry (self->priv->preview_box, &box);
719 case PREVIEW_POS_TOP_LEFT:
720 ret_x = ret_y = SELF_VIDEO_SECTION_MARGIN;
722 case PREVIEW_POS_TOP_RIGHT:
723 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
724 - SELF_VIDEO_SECTION_WIDTH;
725 ret_y = SELF_VIDEO_SECTION_MARGIN;
727 case PREVIEW_POS_BOTTOM_LEFT:
728 ret_x = SELF_VIDEO_SECTION_MARGIN;
729 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
730 - SELF_VIDEO_SECTION_HEIGHT;
732 case PREVIEW_POS_BOTTOM_RIGHT:
733 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
734 - SELF_VIDEO_SECTION_WIDTH;
735 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
736 - SELF_VIDEO_SECTION_HEIGHT;
739 g_warn_if_reached ();
750 static PreviewPosition
751 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
756 PreviewPosition pos = PREVIEW_POS_NONE;
758 if (!clutter_actor_has_allocation (self->priv->preview_box))
761 clutter_actor_get_geometry (self->priv->preview_box, &box);
763 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
764 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
765 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
766 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
768 pos = PREVIEW_POS_TOP_LEFT;
770 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
771 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
772 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
773 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
775 pos = PREVIEW_POS_TOP_RIGHT;
777 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
778 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
779 box.height - SELF_VIDEO_SECTION_MARGIN >= event_y &&
780 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
782 pos = PREVIEW_POS_BOTTOM_LEFT;
784 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
785 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
786 box.height - 2 * SELF_VIDEO_SECTION_MARGIN >= event_y &&
787 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
789 pos = PREVIEW_POS_BOTTOM_RIGHT;
795 static ClutterActor *
796 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
799 ClutterActor *rectangle;
803 case PREVIEW_POS_TOP_LEFT:
804 rectangle = self->priv->preview_rectangle1;
806 case PREVIEW_POS_TOP_RIGHT:
807 rectangle = self->priv->preview_rectangle3;
809 case PREVIEW_POS_BOTTOM_LEFT:
810 rectangle = self->priv->preview_rectangle2;
812 case PREVIEW_POS_BOTTOM_RIGHT:
813 rectangle = self->priv->preview_rectangle4;
823 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
826 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->preview_layout);
828 DEBUG ("moving the video preview to %d", pos);
830 self->priv->preview_pos = pos;
834 case PREVIEW_POS_TOP_LEFT:
835 clutter_bin_layout_set_alignment (layout,
836 self->priv->video_preview,
837 CLUTTER_BIN_ALIGNMENT_START,
838 CLUTTER_BIN_ALIGNMENT_START);
840 case PREVIEW_POS_TOP_RIGHT:
841 clutter_bin_layout_set_alignment (layout,
842 self->priv->video_preview,
843 CLUTTER_BIN_ALIGNMENT_END,
844 CLUTTER_BIN_ALIGNMENT_START);
846 case PREVIEW_POS_BOTTOM_LEFT:
847 clutter_bin_layout_set_alignment (layout,
848 self->priv->video_preview,
849 CLUTTER_BIN_ALIGNMENT_START,
850 CLUTTER_BIN_ALIGNMENT_END);
852 case PREVIEW_POS_BOTTOM_RIGHT:
853 clutter_bin_layout_set_alignment (layout,
854 self->priv->video_preview,
855 CLUTTER_BIN_ALIGNMENT_END,
856 CLUTTER_BIN_ALIGNMENT_END);
859 g_warn_if_reached ();
862 g_settings_set_enum (self->priv->settings, "camera-position", pos);
866 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
869 ClutterActor *rectangle;
870 ClutterColor white = { 0xff, 0xff, 0xff, 0xff};
872 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
874 empathy_rounded_rectangle_set_border_width (
875 EMPATHY_ROUNDED_RECTANGLE (rectangle), 2 * SELF_VIDEO_SECTION_MARGIN);
876 empathy_rounded_rectangle_set_border_color (
877 EMPATHY_ROUNDED_RECTANGLE (rectangle), &white);
881 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
882 ClutterActor *rectangle)
884 ClutterColor white = { 0xff, 0xff, 0xff, 0xff}, darker;
886 clutter_color_shade (&white, 0.55, &darker);
888 empathy_rounded_rectangle_set_border_width (
889 EMPATHY_ROUNDED_RECTANGLE (rectangle), 1);
890 empathy_rounded_rectangle_set_border_color (
891 EMPATHY_ROUNDED_RECTANGLE (rectangle), &darker);
895 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
897 ClutterActor *rectangle;
899 rectangle = empathy_call_window_get_preview_rectangle (self,
900 self->priv->preview_pos);
902 /* We don't want to darken the rectangle where the preview
905 if (self->priv->preview_rectangle1 != rectangle)
906 empathy_call_window_darken_preview_rectangle (self,
907 self->priv->preview_rectangle1);
909 if (self->priv->preview_rectangle2 != rectangle)
910 empathy_call_window_darken_preview_rectangle (self,
911 self->priv->preview_rectangle2);
913 if (self->priv->preview_rectangle3 != rectangle)
914 empathy_call_window_darken_preview_rectangle (self,
915 self->priv->preview_rectangle3);
917 if (self->priv->preview_rectangle4 != rectangle)
918 empathy_call_window_darken_preview_rectangle (self,
919 self->priv->preview_rectangle4);
923 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
927 ClutterModifierType modifiers,
928 EmpathyCallWindow *self)
930 ClutterActor *stage = clutter_actor_get_stage (actor);
933 self->priv->drag_preview = clutter_clone_new (actor);
935 clutter_container_add_actor (CLUTTER_CONTAINER (stage),
936 self->priv->drag_preview);
938 clutter_actor_transform_stage_point (actor, event_x, event_y,
941 clutter_actor_set_position (self->priv->drag_preview,
942 event_x - rel_x, event_y - rel_y);
944 clutter_drag_action_set_drag_handle (action,
945 self->priv->drag_preview);
947 clutter_actor_set_opacity (actor, 0);
948 clutter_actor_hide (self->priv->preview_shown_button);
950 empathy_call_window_show_preview_rectangles (self, TRUE);
951 empathy_call_window_darken_preview_rectangles (self);
955 empathy_call_window_on_animation_completed_cb (ClutterAnimation *animation,
958 clutter_actor_set_opacity (actor, 255);
962 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
966 ClutterModifierType modifiers,
967 EmpathyCallWindow *self)
972 /* Get the position before destroying the drag actor, otherwise the
973 * preview_box allocation won't be valid and we won't be able to
974 * calculate the position. */
975 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
977 empathy_call_window_get_preview_coordinates (self,
978 pos != PREVIEW_POS_NONE ? pos : self->priv->preview_pos,
981 /* Move the preview to the destination and destroy it afterwards */
982 clutter_actor_animate (self->priv->drag_preview, CLUTTER_LINEAR, 500,
985 "signal-swapped-after::completed",
986 clutter_actor_destroy, self->priv->drag_preview,
987 "signal-swapped-after::completed",
988 clutter_actor_show, self->priv->preview_shown_button,
990 empathy_call_window_on_animation_completed_cb, actor,
993 self->priv->drag_preview = NULL;
995 if (pos != PREVIEW_POS_NONE)
996 empathy_call_window_move_video_preview (self, pos);
998 empathy_call_window_show_preview_rectangles (self, FALSE);
1002 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
1003 ClutterActor *actor,
1006 EmpathyCallWindow *self)
1008 PreviewPosition pos;
1009 gfloat event_x, event_y;
1011 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
1013 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
1015 if (pos != PREVIEW_POS_NONE)
1016 empathy_call_window_highlight_preview_rectangle (self, pos);
1018 empathy_call_window_darken_preview_rectangles (self);
1022 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
1023 ClutterCrossingEvent *event,
1024 EmpathyCallWindow *self)
1026 ClutterActor *rectangle;
1028 rectangle = empathy_call_window_get_preview_rectangle (self,
1029 self->priv->preview_pos);
1031 empathy_call_window_highlight_preview_rectangle (self,
1032 self->priv->preview_pos);
1034 clutter_actor_show (rectangle);
1040 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
1041 ClutterCrossingEvent *event,
1042 EmpathyCallWindow *self)
1044 ClutterActor *rectangle;
1046 rectangle = empathy_call_window_get_preview_rectangle (self,
1047 self->priv->preview_pos);
1049 empathy_call_window_darken_preview_rectangle (self, rectangle);
1051 clutter_actor_hide (rectangle);
1057 create_video_preview (EmpathyCallWindow *self)
1059 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1060 ClutterLayoutManager *layout;
1061 ClutterActor *preview;
1063 ClutterAction *action;
1064 PreviewPosition pos;
1066 g_assert (priv->video_preview == NULL);
1068 pos = g_settings_get_enum (priv->settings, "camera-position");
1070 preview = empathy_rounded_texture_new ();
1071 clutter_actor_set_size (preview,
1072 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1074 priv->video_preview_sink = gst_element_factory_make ("cluttersink", NULL);
1075 if (priv->video_preview_sink == NULL)
1076 g_error ("Missing cluttersink, check your clutter-gst installation");
1077 g_object_set (priv->video_preview_sink, "texture", preview, NULL);
1078 g_object_add_weak_pointer (G_OBJECT (priv->video_preview_sink), (gpointer) &priv->video_preview_sink);
1080 /* Add a little offset to the video preview */
1081 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1082 CLUTTER_BIN_ALIGNMENT_CENTER);
1083 priv->video_preview = clutter_box_new (layout);
1084 clutter_actor_set_size (priv->video_preview,
1085 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1086 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1088 /* Spinner for when changing the camera device */
1089 priv->preview_spinner_widget = gtk_spinner_new ();
1090 priv->preview_spinner_actor = empathy_rounded_actor_new (PREVIEW_ROUND_FACTOR);
1092 g_object_set (priv->preview_spinner_widget, "expand", TRUE, NULL);
1093 make_background_transparent (GTK_CLUTTER_ACTOR (priv->preview_spinner_actor));
1094 gtk_widget_show (priv->preview_spinner_widget);
1097 GTK_CONTAINER (gtk_clutter_actor_get_widget (
1098 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor))),
1099 priv->preview_spinner_widget);
1100 clutter_actor_set_size (priv->preview_spinner_actor,
1101 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1102 clutter_actor_set_opacity (priv->preview_spinner_actor, 128);
1103 clutter_actor_hide (priv->preview_spinner_actor);
1105 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1107 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1108 priv->preview_spinner_actor);
1110 g_object_set (priv->video_preview_sink,
1116 priv->preview_shown_button = b = gtk_clutter_actor_new_with_contents (
1117 gtk_image_new_from_icon_name ("emblem-system-symbolic",
1118 GTK_ICON_SIZE_MENU));
1119 clutter_actor_set_margin_right (b, 4);
1120 clutter_actor_set_margin_bottom (b, 2);
1121 clutter_actor_set_opacity (b, PREVIEW_BUTTON_OPACITY);
1122 make_background_transparent (GTK_CLUTTER_ACTOR (b));
1124 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout), b,
1125 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
1127 action = clutter_click_action_new ();
1128 clutter_actor_add_action (b, action);
1129 g_signal_connect (action, "clicked",
1130 G_CALLBACK (empathy_call_window_preview_button_clicked_cb), self);
1132 /* Preview hidden */
1133 priv->preview_hidden_button = b = gtk_clutter_actor_new_with_contents (
1134 gtk_image_new_from_icon_name ("emblem-system-symbolic",
1135 GTK_ICON_SIZE_MENU));
1136 make_background_transparent (GTK_CLUTTER_ACTOR (b));
1138 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1139 priv->preview_hidden_button,
1140 CLUTTER_BIN_ALIGNMENT_START,
1141 CLUTTER_BIN_ALIGNMENT_END);
1143 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1145 clutter_actor_hide (priv->preview_hidden_button);
1147 action = clutter_click_action_new ();
1148 clutter_actor_add_action (b, action);
1149 g_signal_connect (action, "clicked",
1150 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb), self);
1152 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1153 priv->video_preview,
1154 CLUTTER_BIN_ALIGNMENT_START,
1155 CLUTTER_BIN_ALIGNMENT_END);
1157 empathy_call_window_move_video_preview (self, pos);
1159 action = clutter_drag_action_new ();
1160 g_signal_connect (action, "drag-begin",
1161 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1162 g_signal_connect (action, "drag-end",
1163 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1164 g_signal_connect (action, "drag-motion",
1165 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1167 g_signal_connect (preview, "enter-event",
1168 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1169 g_signal_connect (preview, "leave-event",
1170 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1172 clutter_actor_add_action (preview, action);
1173 clutter_actor_set_reactive (preview, TRUE);
1174 clutter_actor_set_reactive (priv->preview_shown_button, TRUE);
1178 empathy_call_window_start_camera_spinning (EmpathyCallWindow *self)
1180 clutter_actor_show (self->priv->preview_spinner_actor);
1181 gtk_spinner_start (GTK_SPINNER (self->priv->preview_spinner_widget));
1185 empathy_call_window_stop_camera_spinning (EmpathyCallWindow *self)
1187 clutter_actor_hide (self->priv->preview_spinner_actor);
1188 gtk_spinner_stop (GTK_SPINNER (self->priv->preview_spinner_widget));
1192 empathy_call_window_play_camera (EmpathyCallWindow *self,
1195 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1196 GstElement *preview;
1199 if (priv->video_preview == NULL)
1201 create_video_preview (self);
1202 add_video_preview_to_pipeline (self);
1207 state = GST_STATE_PLAYING;
1211 empathy_call_window_start_camera_spinning (self);
1212 state = GST_STATE_NULL;
1215 preview = priv->video_preview_sink;
1217 gst_element_set_state (preview, state);
1218 gst_element_set_state (priv->video_tee, state);
1219 gst_element_set_state (priv->video_input, state);
1223 display_video_preview (EmpathyCallWindow *self,
1226 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1228 if (priv->video_preview == NULL)
1230 create_video_preview (self);
1231 add_video_preview_to_pipeline (self);
1236 /* Display the video preview */
1237 DEBUG ("Show video preview");
1239 empathy_call_window_play_camera (self, TRUE);
1240 clutter_actor_show (priv->video_preview);
1241 clutter_actor_raise_top (priv->floating_toolbar);
1245 /* Hide the video preview */
1246 DEBUG ("Hide video preview");
1248 if (priv->video_preview != NULL)
1250 clutter_actor_hide (priv->video_preview);
1251 empathy_call_window_play_camera (self, FALSE);
1257 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1259 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1261 empathy_call_window_status_message (window, _("Connecting…"));
1262 priv->call_state = CONNECTING;
1264 /* Show the toolbar */
1265 clutter_state_set_state (priv->transitions, "fade-in");
1268 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1269 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1273 disable_camera (EmpathyCallWindow *self)
1275 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1277 if (priv->camera_state == CAMERA_STATE_OFF)
1280 DEBUG ("Disable camera");
1282 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1284 priv->camera_state = CAMERA_STATE_OFF;
1288 enable_camera (EmpathyCallWindow *self)
1290 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1292 if (priv->camera_state == CAMERA_STATE_ON)
1295 if (priv->video_input == NULL)
1297 DEBUG ("Can't enable camera, no input");
1301 DEBUG ("Enable camera");
1303 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1305 priv->camera_state = CAMERA_STATE_ON;
1309 empathy_call_window_camera_toggled_cb (GtkToggleButton *toggle,
1310 EmpathyCallWindow *self)
1312 if (gtk_toggle_button_get_active (toggle))
1313 enable_camera (self);
1315 disable_camera (self);
1319 create_pipeline (EmpathyCallWindow *self)
1321 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1324 g_assert (priv->pipeline == NULL);
1326 priv->pipeline = gst_pipeline_new (NULL);
1327 priv->pipeline_playing = FALSE;
1329 priv->video_tee = gst_element_factory_make ("tee", NULL);
1330 gst_object_ref_sink (priv->video_tee);
1332 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1334 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1335 priv->bus_message_source_id = gst_bus_add_watch (bus,
1336 empathy_call_window_bus_message, self);
1338 g_object_unref (bus);
1342 empathy_call_window_settings_cb (GtkAction *action,
1343 EmpathyCallWindow *self)
1345 gchar *args = g_strdup_printf ("-p %s",
1346 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1348 empathy_launch_program (BIN_DIR, "empathy", args);
1354 empathy_call_window_contents_cb (GtkAction *action,
1355 EmpathyCallWindow *self)
1357 empathy_url_show (GTK_WIDGET (self), "help:empathy/audio-video");
1361 show_png (GPid pid, gint status, gpointer user_data)
1363 gtk_show_uri (NULL, (gchar *) user_data, GDK_CURRENT_TIME, NULL);
1364 g_spawn_close_pid (pid);
1369 empathy_call_window_debug_gst_cb (GtkAction *action,
1370 EmpathyCallWindow *self)
1372 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1373 GDateTime *date_time;
1375 const gchar *dot_dir;
1376 const gchar *prgname;
1382 if (priv->pipeline == NULL)
1383 DEBUG ("No pipeline");
1385 date_time = g_date_time_new_now_utc ();
1386 prgname = g_get_prgname ();
1387 filename = g_strdup_printf ("%s-%" G_GINT64_FORMAT, prgname,
1388 g_date_time_to_unix (date_time));
1390 GST_DEBUG_BIN_TO_DOT_FILE (GST_BIN (priv->pipeline),
1391 GST_DEBUG_GRAPH_SHOW_ALL, filename);
1393 dot_dir = g_getenv ("GST_DEBUG_DUMP_DOT_DIR");
1394 dot_cmd = g_strdup_printf ("dot -Tpng -o %s.png %s.dot",
1397 g_shell_parse_argv (dot_cmd, &argc, &argv, NULL);
1399 if (g_spawn_async (dot_dir,
1402 G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
1408 gchar *uri = g_strdup_printf ("file://%s/%s.png", dot_dir, filename);
1409 g_child_watch_add (dot_pid, show_png, uri);
1415 g_date_time_unref (date_time);
1419 empathy_call_window_debug_tp_cb (GtkAction *action,
1420 EmpathyCallWindow *self)
1422 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1426 empathy_call_window_about_cb (GtkAction *action,
1427 EmpathyCallWindow *self)
1429 empathy_about_dialog_new (GTK_WINDOW (self));
1433 empathy_call_window_toolbar_timeout (gpointer data)
1435 EmpathyCallWindow *self = data;
1437 /* We don't want to hide the toolbar if we're not in a call, as
1438 * to show the call status all the time. Also don't hide if we're muted
1439 * to prevent the awkward, talking when muted situation */
1440 if (self->priv->call_state != CONNECTING &&
1441 self->priv->call_state != DISCONNECTED &&
1443 clutter_state_set_state (self->priv->transitions, "fade-out");
1449 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1451 EmpathyCallWindow *self)
1453 clutter_state_set_state (self->priv->transitions, "fade-in");
1455 if (self->priv->inactivity_src > 0)
1456 g_source_remove (self->priv->inactivity_src);
1458 self->priv->inactivity_src = g_timeout_add_seconds (3,
1459 empathy_call_window_toolbar_timeout, self);
1465 empathy_call_window_configure_event_cb (GtkWidget *widget,
1467 EmpathyCallWindow *self)
1469 GdkWindow *gdk_window;
1470 GdkWindowState window_state;
1472 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1473 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1475 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1476 &self->priv->dialpad_width, NULL);
1478 gdk_window = gtk_widget_get_window (widget);
1479 window_state = gdk_window_get_state (gdk_window);
1480 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1486 empathy_call_window_destroyed_cb (GtkWidget *object,
1487 EmpathyCallWindow *self)
1489 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1491 /* Save the geometry as if the dialpad was hidden. */
1492 empathy_geometry_save_values (GTK_WINDOW (self),
1493 self->priv->x, self->priv->y,
1494 self->priv->w - self->priv->dialpad_width, self->priv->h,
1495 self->priv->maximized);
1500 empathy_call_window_incoming_call_response_cb (GtkDialog *dialog,
1502 EmpathyCallWindow *self)
1504 switch (response_id)
1506 case GTK_RESPONSE_ACCEPT:
1507 tp_channel_dispatch_operation_handle_with_async (
1508 self->priv->pending_cdo, EMPATHY_CALL_BUS_NAME, NULL, NULL);
1510 tp_clear_object (&self->priv->pending_cdo);
1511 tp_clear_object (&self->priv->pending_channel);
1512 tp_clear_object (&self->priv->pending_context);
1515 case GTK_RESPONSE_CANCEL:
1516 tp_channel_dispatch_operation_close_channels_async (
1517 self->priv->pending_cdo, NULL, NULL);
1519 empathy_call_window_status_message (self, _("Disconnected"));
1520 self->priv->call_state = DISCONNECTED;
1523 g_warn_if_reached ();
1528 empathy_call_window_set_state_ringing (EmpathyCallWindow *self)
1532 g_assert (self->priv->call_state != CONNECTED);
1534 video = tp_call_channel_has_initial_video (self->priv->pending_channel, NULL);
1536 empathy_call_window_status_message (self, _("Incoming call"));
1537 self->priv->call_state = RINGING;
1539 self->priv->incoming_call_dialog = gtk_message_dialog_new (
1540 GTK_WINDOW (self), GTK_DIALOG_MODAL,
1541 GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
1542 video ? _("Incoming video call from %s") : _("Incoming call from %s"),
1543 empathy_contact_get_alias (self->priv->contact));
1545 gtk_dialog_add_buttons (GTK_DIALOG (self->priv->incoming_call_dialog),
1546 _("Reject"), GTK_RESPONSE_CANCEL,
1547 _("Answer"), GTK_RESPONSE_ACCEPT,
1550 g_signal_connect (self->priv->incoming_call_dialog, "response",
1551 G_CALLBACK (empathy_call_window_incoming_call_response_cb), self);
1552 gtk_widget_show (self->priv->incoming_call_dialog);
1556 empathy_call_window_cdo_invalidated_cb (TpProxy *channel,
1560 EmpathyCallWindow *self)
1562 tp_clear_object (&self->priv->pending_cdo);
1563 tp_clear_object (&self->priv->pending_channel);
1564 tp_clear_object (&self->priv->pending_context);
1566 /* We don't know if the incoming call has been accepted or not, so we
1567 * assume it hasn't and if it has, we'll set the proper status when
1568 * we get the new handler. */
1569 empathy_call_window_status_message (self, _("Disconnected"));
1570 self->priv->call_state = DISCONNECTED;
1572 gtk_widget_destroy (self->priv->incoming_call_dialog);
1573 self->priv->incoming_call_dialog = NULL;
1577 empathy_call_window_start_ringing (EmpathyCallWindow *self,
1578 TpCallChannel *channel,
1579 TpChannelDispatchOperation *dispatch_operation,
1580 TpAddDispatchOperationContext *context)
1582 g_assert (self->priv->pending_channel == NULL);
1583 g_assert (self->priv->pending_context == NULL);
1584 g_assert (self->priv->pending_cdo == NULL);
1586 /* Start ringing and delay until the user answers or hangs. */
1587 self->priv->pending_channel = g_object_ref (channel);
1588 self->priv->pending_context = g_object_ref (context);
1589 self->priv->pending_cdo = g_object_ref (dispatch_operation);
1591 g_signal_connect (self->priv->pending_cdo, "invalidated",
1592 G_CALLBACK (empathy_call_window_cdo_invalidated_cb), self);
1594 empathy_call_window_set_state_ringing (self);
1595 tp_add_dispatch_operation_context_accept (context);
1599 mic_button_clicked (GtkWidget *button,
1600 EmpathyCallWindow *self)
1602 /* Toggle the muted state. We rely on audio_input_mute_notify_cb to update
1604 empathy_audio_src_set_mute (EMPATHY_GST_AUDIO_SRC (self->priv->audio_input),
1605 !self->priv->muted);
1609 empathy_call_window_init (EmpathyCallWindow *self)
1611 EmpathyCallWindowPriv *priv;
1613 GtkWidget *top_vbox;
1615 ClutterConstraint *constraint;
1616 ClutterActor *remote_avatar;
1617 ClutterColor black = { 0, 0, 0, 0 };
1618 ClutterMargin overlay_margin = { OVERLAY_MARGIN, OVERLAY_MARGIN,
1619 OVERLAY_MARGIN, OVERLAY_MARGIN };
1621 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1622 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1624 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1625 priv->timer = g_timer_new ();
1627 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1628 gui = empathy_builder_get_file (filename,
1629 "call_window_vbox", &top_vbox,
1630 "errors_vbox", &priv->errors_vbox,
1631 "pane", &priv->pane,
1632 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1633 "remote_user_status_toolbar", &priv->remote_user_status_toolbar,
1634 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1635 "status_label", &priv->status_label,
1636 "audiocall", &priv->audio_call_button,
1637 "videocall", &priv->video_call_button,
1638 "microphone", &priv->mic_button,
1639 "microphone_icon", &priv->microphone_icon,
1640 "volume", &priv->volume_button,
1641 "camera", &priv->camera_button,
1642 "hangup", &priv->hangup_button,
1643 "dialpad", &priv->dialpad_button,
1644 "toolbar", &priv->toolbar,
1645 "bottom_toolbar", &priv->bottom_toolbar,
1646 "ui_manager", &priv->ui_manager,
1647 "menufullscreen", &priv->menu_fullscreen,
1648 "menupreviewswap", &priv->menu_swap_camera,
1649 "details_vbox", &priv->details_vbox,
1650 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1651 "acodec_encoding_label", &priv->acodec_encoding_label,
1652 "acodec_decoding_label", &priv->acodec_decoding_label,
1653 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1654 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1655 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1656 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1657 "video_local_candidate_label", &priv->video_local_candidate_label,
1658 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1659 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1660 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1661 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1665 empathy_builder_connect (gui, self,
1666 "hangup", "clicked", empathy_call_window_hangup_cb,
1667 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1668 "videocall", "clicked", empathy_call_window_video_call_cb,
1669 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1670 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1671 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1672 "menusettings", "activate", empathy_call_window_settings_cb,
1673 "menucontents", "activate", empathy_call_window_contents_cb,
1674 "menudebuggst", "activate", empathy_call_window_debug_gst_cb,
1675 "menudebugtp", "activate", empathy_call_window_debug_tp_cb,
1676 "menuabout", "activate", empathy_call_window_about_cb,
1677 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1678 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1679 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1680 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1683 empathy_set_css_provider (GTK_WIDGET (self));
1684 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1686 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1688 g_object_bind_property (priv->camera_monitor, "available",
1689 priv->camera_button, "sensitive",
1690 G_BINDING_SYNC_CREATE);
1692 g_signal_connect (priv->camera_monitor, "added",
1693 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1694 g_signal_connect (priv->camera_monitor, "removed",
1695 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1697 g_signal_connect (priv->mic_button, "clicked",
1698 G_CALLBACK (mic_button_clicked), self);
1700 g_mutex_init (&priv->lock);
1702 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1704 priv->content_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,
1705 CONTENT_HBOX_SPACING);
1706 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1709 /* main contents remote avatar/video box */
1710 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_FILL,
1711 CLUTTER_BIN_ALIGNMENT_FILL);
1713 priv->video_box = clutter_box_new (priv->video_layout);
1715 priv->video_container = gtk_clutter_embed_new ();
1717 gtk_widget_set_size_request (priv->video_container,
1718 REMOTE_VIDEO_DEFAULT_WIDTH, REMOTE_VIDEO_DEFAULT_HEIGHT);
1720 /* Set the background black */
1721 clutter_stage_set_color (
1722 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1723 GTK_CLUTTER_EMBED (priv->video_container))),
1726 clutter_container_add (
1727 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1728 GTK_CLUTTER_EMBED (priv->video_container))),
1732 constraint = clutter_bind_constraint_new (
1733 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1734 CLUTTER_BIND_SIZE, 0);
1735 clutter_actor_add_constraint (priv->video_box, constraint);
1737 priv->remote_user_avatar_widget = gtk_image_new ();
1738 remote_avatar = gtk_clutter_actor_new_with_contents (
1739 priv->remote_user_avatar_widget);
1740 make_background_transparent (GTK_CLUTTER_ACTOR (remote_avatar));
1742 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1745 /* create the overlay bin */
1746 priv->overlay_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1747 CLUTTER_BIN_ALIGNMENT_CENTER);
1748 priv->overlay_bin = clutter_actor_new ();
1749 clutter_actor_set_layout_manager (priv->overlay_bin, priv->overlay_layout);
1751 clutter_actor_set_margin (priv->overlay_bin, &overlay_margin);
1753 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1755 CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL);
1757 empathy_call_window_create_preview_rectangles (self);
1759 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1760 priv->video_container, TRUE, TRUE,
1761 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1763 create_pipeline (self);
1764 create_video_output_widget (self);
1765 create_audio_input (self);
1766 create_video_input (self);
1768 priv->floating_toolbar = gtk_clutter_actor_new ();
1769 clutter_actor_set_reactive (priv->floating_toolbar, TRUE);
1770 make_background_transparent (GTK_CLUTTER_ACTOR (priv->floating_toolbar));
1772 gtk_style_context_add_class (
1773 gtk_widget_get_style_context (GTK_WIDGET (priv->bottom_toolbar)),
1774 GTK_STYLE_CLASS_OSD);
1775 gtk_widget_reparent (priv->bottom_toolbar,
1776 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1778 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->overlay_layout),
1779 priv->floating_toolbar,
1780 CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_END);
1782 clutter_actor_raise_top (priv->floating_toolbar);
1784 /* Transitions for the floating toolbar */
1785 priv->transitions = clutter_state_new ();
1787 /* all transitions last for 2s */
1788 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1790 /* transition from any state to "fade-out" state */
1791 clutter_state_set (priv->transitions, NULL, "fade-out",
1792 priv->floating_toolbar,
1793 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1796 /* transition from any state to "fade-in" state */
1797 clutter_state_set (priv->transitions, NULL, "fade-in",
1798 priv->floating_toolbar,
1799 "opacity", CLUTTER_EASE_OUT_QUAD, 255,
1802 /* put the actor into the "fade-in" state with no animation */
1803 clutter_state_warp_to_state (priv->transitions, "fade-in");
1805 /* The call will be started as soon the pipeline is playing */
1806 priv->start_call_when_playing = TRUE;
1808 priv->dtmf_panel = empathy_dialpad_widget_new ();
1809 g_signal_connect (priv->dtmf_panel, "start-tone",
1810 G_CALLBACK (dtmf_start_tone_cb), self);
1812 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1815 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1818 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1820 gtk_widget_show_all (top_vbox);
1822 gtk_widget_hide (priv->dtmf_panel);
1823 gtk_widget_hide (priv->details_vbox);
1825 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1827 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1828 priv->video_container);
1830 /* We hide the bottom toolbar after 3s of inactivity and show it
1831 * again on mouse movement */
1832 priv->inactivity_src = g_timeout_add_seconds (3,
1833 empathy_call_window_toolbar_timeout, self);
1835 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1836 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1838 g_signal_connect (G_OBJECT (self), "realize",
1839 G_CALLBACK (empathy_call_window_realized_cb), self);
1841 g_signal_connect (G_OBJECT (self), "delete-event",
1842 G_CALLBACK (empathy_call_window_delete_cb), self);
1844 g_signal_connect (G_OBJECT (self), "window-state-event",
1845 G_CALLBACK (empathy_call_window_state_event_cb), self);
1847 g_signal_connect (G_OBJECT (self), "key-press-event",
1848 G_CALLBACK (empathy_call_window_key_press_cb), self);
1850 g_signal_connect (self, "motion-notify-event",
1851 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1853 g_object_ref (priv->ui_manager);
1854 g_object_unref (gui);
1856 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1857 priv->mic_menu = empathy_mic_menu_new (self);
1858 priv->camera_menu = empathy_camera_menu_new (self);
1860 empathy_call_window_show_hangup_button (self, TRUE);
1862 gtk_window_set_default_size (GTK_WINDOW (self), 580, 480);
1864 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1865 /* These signals are used to track the window position and save it
1866 * when the window is destroyed. We need to do this as we don't want
1867 * the window geometry to be saved with the dialpad taken into account. */
1868 g_signal_connect (self, "destroy",
1869 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1870 g_signal_connect (self, "configure-event",
1871 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1872 g_signal_connect (self, "window-state-event",
1873 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1875 /* Don't display labels in both toolbars */
1876 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1879 /* Instead of specifying a width and a height, we specify only one size. That's
1880 because we want a square avatar icon. */
1882 init_contact_avatar_with_size (EmpathyContact *contact,
1883 GtkWidget *image_widget,
1886 GdkPixbuf *pixbuf_avatar = NULL;
1888 if (contact != NULL)
1890 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1894 if (pixbuf_avatar == NULL)
1896 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1897 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1900 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1902 if (pixbuf_avatar != NULL)
1903 g_object_unref (pixbuf_avatar);
1907 set_window_title (EmpathyCallWindow *self)
1909 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1912 if (priv->contact != NULL)
1914 /* translators: Call is a noun and %s is the contact name. This string
1915 * is used in the window title */
1916 tmp = g_strdup_printf (_("Call with %s"),
1917 empathy_contact_get_alias (priv->contact));
1918 gtk_window_set_title (GTK_WINDOW (self), tmp);
1923 g_warning ("Unknown remote contact!");
1928 set_remote_user_name (EmpathyCallWindow *self,
1929 EmpathyContact *contact)
1931 const gchar *alias = empathy_contact_get_alias (contact);
1932 const gchar *status = empathy_contact_get_status (contact);
1934 gtk_label_set_text (GTK_LABEL (self->priv->remote_user_name_toolbar), alias);
1936 if (status != NULL) {
1939 markup = g_markup_printf_escaped ("<small>%s</small>", status);
1940 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_status_toolbar),
1944 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_status_toolbar),
1950 contact_name_changed_cb (EmpathyContact *contact,
1952 EmpathyCallWindow *self)
1954 set_window_title (self);
1955 set_remote_user_name (self, contact);
1959 contact_presence_changed_cb (EmpathyContact *contact,
1961 EmpathyCallWindow *self)
1963 set_remote_user_name (self, contact);
1967 contact_avatar_changed_cb (EmpathyContact *contact,
1969 EmpathyCallWindow *self)
1972 GtkAllocation allocation;
1973 GtkWidget *avatar_widget;
1975 avatar_widget = self->priv->remote_user_avatar_widget;
1977 gtk_widget_get_allocation (avatar_widget, &allocation);
1978 size = allocation.height;
1982 /* the widget is not allocated yet, set a default size */
1983 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1984 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1987 init_contact_avatar_with_size (contact, avatar_widget, size);
1989 avatar_widget = self->priv->remote_user_avatar_toolbar;
1991 gtk_widget_get_allocation (avatar_widget, &allocation);
1992 size = allocation.height;
1996 /* the widget is not allocated yet, set a default size */
1997 size = SMALL_TOOLBAR_SIZE;
2000 init_contact_avatar_with_size (contact, avatar_widget, size);
2004 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
2005 EmpathyCallHandler *handler)
2007 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2009 tp_g_signal_connect_object (priv->contact, "notify::name",
2010 G_CALLBACK (contact_name_changed_cb), self, 0);
2011 tp_g_signal_connect_object (priv->contact, "notify::avatar",
2012 G_CALLBACK (contact_avatar_changed_cb), self, 0);
2013 tp_g_signal_connect_object (priv->contact, "notify::presence",
2014 G_CALLBACK (contact_presence_changed_cb), self, 0);
2016 set_window_title (self);
2017 set_remote_user_name (self, priv->contact);
2019 init_contact_avatar_with_size (priv->contact,
2020 priv->remote_user_avatar_widget,
2021 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
2022 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
2024 init_contact_avatar_with_size (priv->contact,
2025 priv->remote_user_avatar_toolbar,
2026 SMALL_TOOLBAR_SIZE);
2028 /* The remote avatar is shown by default and will be hidden when we receive
2029 video from the remote side. */
2030 clutter_actor_hide (priv->video_output);
2031 gtk_widget_show (priv->remote_user_avatar_widget);
2035 update_send_codec (EmpathyCallWindow *self,
2038 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2045 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
2046 widget = priv->acodec_encoding_label;
2050 codec = empathy_call_handler_get_send_video_codec (priv->handler);
2051 widget = priv->vcodec_encoding_label;
2057 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
2058 gtk_label_set_text (GTK_LABEL (widget), tmp);
2063 send_audio_codec_notify_cb (GObject *object,
2067 EmpathyCallWindow *self = user_data;
2069 update_send_codec (self, TRUE);
2073 send_video_codec_notify_cb (GObject *object,
2077 EmpathyCallWindow *self = user_data;
2079 update_send_codec (self, FALSE);
2083 update_recv_codec (EmpathyCallWindow *self,
2086 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2089 GString *str = NULL;
2093 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
2094 widget = priv->acodec_decoding_label;
2098 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
2099 widget = priv->vcodec_decoding_label;
2105 for (l = codecs; l != NULL; l = g_list_next (l))
2107 FsCodec *codec = l->data;
2110 str = g_string_new (NULL);
2112 g_string_append (str, ", ");
2114 g_string_append_printf (str, "%s/%u", codec->encoding_name,
2118 gtk_label_set_text (GTK_LABEL (widget), str->str);
2119 g_string_free (str, TRUE);
2123 recv_audio_codecs_notify_cb (GObject *object,
2127 EmpathyCallWindow *self = user_data;
2129 update_recv_codec (self, TRUE);
2133 recv_video_codecs_notify_cb (GObject *object,
2137 EmpathyCallWindow *self = user_data;
2139 update_recv_codec (self, FALSE);
2142 static const gchar *
2143 candidate_type_to_str (FsCandidate *candidate)
2145 switch (candidate->type)
2147 case FS_CANDIDATE_TYPE_HOST:
2149 case FS_CANDIDATE_TYPE_SRFLX:
2150 return "server reflexive";
2151 case FS_CANDIDATE_TYPE_PRFLX:
2152 return "peer reflexive";
2153 case FS_CANDIDATE_TYPE_RELAY:
2155 case FS_CANDIDATE_TYPE_MULTICAST:
2162 static const gchar *
2163 candidate_type_to_desc (FsCandidate *candidate)
2165 switch (candidate->type)
2167 case FS_CANDIDATE_TYPE_HOST:
2168 return _("The IP address as seen by the machine");
2169 case FS_CANDIDATE_TYPE_SRFLX:
2170 return _("The IP address as seen by a server on the Internet");
2171 case FS_CANDIDATE_TYPE_PRFLX:
2172 return _("The IP address of the peer as seen by the other side");
2173 case FS_CANDIDATE_TYPE_RELAY:
2174 return _("The IP address of a relay server");
2175 case FS_CANDIDATE_TYPE_MULTICAST:
2176 return _("The IP address of the multicast group");
2183 update_candidat_widget (EmpathyCallWindow *self,
2186 FsCandidate *candidate)
2190 g_assert (candidate != NULL);
2191 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
2192 candidate->port, candidate_type_to_str (candidate));
2194 gtk_label_set_text (GTK_LABEL (label), str);
2195 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
2201 candidates_changed_cb (GObject *object,
2203 EmpathyCallWindow *self)
2205 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2206 FsCandidate *candidate = NULL;
2208 if (type == FS_MEDIA_TYPE_VIDEO)
2210 /* Update remote candidate */
2211 candidate = empathy_call_handler_get_video_remote_candidate (
2214 update_candidat_widget (self, priv->video_remote_candidate_label,
2215 priv->video_remote_candidate_info_img, candidate);
2217 /* Update local candidate */
2218 candidate = empathy_call_handler_get_video_local_candidate (
2221 update_candidat_widget (self, priv->video_local_candidate_label,
2222 priv->video_local_candidate_info_img, candidate);
2226 /* Update remote candidate */
2227 candidate = empathy_call_handler_get_audio_remote_candidate (
2230 update_candidat_widget (self, priv->audio_remote_candidate_label,
2231 priv->audio_remote_candidate_info_img, candidate);
2233 /* Update local candidate */
2234 candidate = empathy_call_handler_get_audio_local_candidate (
2237 update_candidat_widget (self, priv->audio_local_candidate_label,
2238 priv->audio_local_candidate_info_img, candidate);
2243 empathy_call_window_constructed (GObject *object)
2245 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2246 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2247 TpCallChannel *call;
2250 g_assert (priv->handler != NULL);
2252 g_object_get (priv->handler, "call-channel", &call, NULL);
2253 state = tp_call_channel_get_state (call, NULL, NULL, NULL);
2254 priv->outgoing = (state == TP_CALL_STATE_PENDING_INITIATOR);
2255 tp_clear_object (&call);
2257 priv->contact = empathy_call_handler_get_contact (priv->handler);
2258 g_assert (priv->contact != NULL);
2259 g_object_ref (priv->contact);
2261 if (!empathy_contact_can_voip_video (priv->contact))
2263 gtk_widget_set_sensitive (priv->video_call_button, FALSE);
2264 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2267 empathy_call_window_setup_avatars (self, priv->handler);
2268 empathy_call_window_set_state_connecting (self);
2270 if (!empathy_call_handler_has_initial_video (priv->handler))
2272 gtk_toggle_button_set_active (
2273 GTK_TOGGLE_BUTTON (priv->camera_button), FALSE);
2275 /* If call has InitialVideo, the preview will be started once the call has
2276 * been started (start_call()). */
2278 update_send_codec (self, TRUE);
2279 update_send_codec (self, FALSE);
2280 update_recv_codec (self, TRUE);
2281 update_recv_codec (self, FALSE);
2283 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2284 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2285 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2286 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2287 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2288 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2289 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2290 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2292 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2293 G_CALLBACK (candidates_changed_cb), self, 0);
2296 static void empathy_call_window_dispose (GObject *object);
2297 static void empathy_call_window_finalize (GObject *object);
2300 empathy_call_window_set_property (GObject *object,
2301 guint property_id, const GValue *value, GParamSpec *pspec)
2303 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2305 switch (property_id)
2307 case PROP_CALL_HANDLER:
2308 priv->handler = g_value_dup_object (value);
2311 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2316 empathy_call_window_get_property (GObject *object,
2317 guint property_id, GValue *value, GParamSpec *pspec)
2319 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2321 switch (property_id)
2323 case PROP_CALL_HANDLER:
2324 g_value_set_object (value, priv->handler);
2327 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2332 empathy_call_window_class_init (
2333 EmpathyCallWindowClass *empathy_call_window_class)
2335 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2336 GParamSpec *param_spec;
2338 g_type_class_add_private (empathy_call_window_class,
2339 sizeof (EmpathyCallWindowPriv));
2341 object_class->constructed = empathy_call_window_constructed;
2342 object_class->set_property = empathy_call_window_set_property;
2343 object_class->get_property = empathy_call_window_get_property;
2345 object_class->dispose = empathy_call_window_dispose;
2346 object_class->finalize = empathy_call_window_finalize;
2348 param_spec = g_param_spec_object ("handler",
2349 "handler", "The call handler",
2350 EMPATHY_TYPE_CALL_HANDLER,
2351 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2352 g_object_class_install_property (object_class,
2353 PROP_CALL_HANDLER, param_spec);
2355 signals[SIG_INHIBIT] = g_signal_new ("inhibit",
2356 G_OBJECT_CLASS_TYPE (empathy_call_window_class),
2358 0, NULL, NULL, NULL,
2364 empathy_call_window_dispose (GObject *object)
2366 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2367 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2369 if (priv->dispose_has_run)
2372 priv->dispose_has_run = TRUE;
2374 if (priv->handler != NULL)
2376 empathy_call_handler_stop_call (priv->handler);
2377 tp_clear_object (&priv->handler);
2380 if (priv->bus_message_source_id != 0)
2382 g_source_remove (priv->bus_message_source_id);
2383 priv->bus_message_source_id = 0;
2386 if (priv->got_video_src > 0)
2388 g_source_remove (priv->got_video_src);
2389 priv->got_video_src = 0;
2392 if (priv->inactivity_src > 0)
2394 g_source_remove (priv->inactivity_src);
2395 priv->inactivity_src = 0;
2398 tp_clear_object (&priv->pipeline);
2399 tp_clear_object (&priv->video_input);
2400 tp_clear_object (&priv->audio_input);
2401 tp_clear_object (&priv->video_tee);
2402 tp_clear_object (&priv->ui_manager);
2403 tp_clear_object (&priv->fullscreen);
2404 tp_clear_object (&priv->camera_monitor);
2405 tp_clear_object (&priv->settings);
2406 tp_clear_object (&priv->sound_mgr);
2407 tp_clear_object (&priv->mic_menu);
2408 tp_clear_object (&priv->camera_menu);
2409 tp_clear_object (&priv->transitions);
2411 g_list_free_full (priv->notifiers, g_object_unref);
2413 if (priv->timer_id != 0)
2414 g_source_remove (priv->timer_id);
2417 tp_clear_object (&priv->contact);
2419 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2423 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2425 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2427 if (priv->video_output_motion_handler_id != 0)
2429 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2430 priv->video_output_motion_handler_id);
2431 priv->video_output_motion_handler_id = 0;
2436 empathy_call_window_finalize (GObject *object)
2438 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2439 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2441 disconnect_video_output_motion_handler (self);
2443 /* free any data held directly by the object here */
2444 g_mutex_clear (&priv->lock);
2446 g_timer_destroy (priv->timer);
2448 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2453 empathy_call_window_new (EmpathyCallHandler *handler)
2455 return EMPATHY_CALL_WINDOW (
2456 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2460 empathy_call_window_present (EmpathyCallWindow *self,
2461 EmpathyCallHandler *handler)
2463 g_return_if_fail (EMPATHY_IS_CALL_HANDLER (handler));
2465 empathy_window_present (GTK_WINDOW (self));
2467 if (self->priv->call_state == DISCONNECTED)
2469 /* start a new call if one is not already in progress */
2470 tp_clear_object (&self->priv->handler);
2471 self->priv->handler = g_object_ref (handler);
2472 empathy_call_window_connect_handler (self);
2474 empathy_call_window_restart_call (self);
2479 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2480 GstElement *conference, gpointer user_data)
2482 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2483 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2484 FsElementAddedNotifier *notifier;
2487 DEBUG ("Conference added");
2489 /* Add notifier to set the various element properties as needed */
2490 notifier = fs_element_added_notifier_new ();
2491 keyfile = fs_utils_get_default_element_properties (conference);
2493 if (keyfile != NULL)
2494 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2496 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2498 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2500 gst_bin_add (GST_BIN (priv->pipeline), conference);
2501 gst_element_set_state (conference, GST_STATE_PLAYING);
2505 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2506 GstElement *conference, gpointer user_data)
2508 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2509 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2511 g_list_free_full (priv->notifiers, g_object_unref);
2512 priv->notifiers = NULL;
2514 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2515 gst_element_set_state (conference, GST_STATE_NULL);
2519 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2521 GstStateChangeReturn state_change_return;
2522 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2524 if (priv->pipeline == NULL)
2527 if (priv->bus_message_source_id != 0)
2529 g_source_remove (priv->bus_message_source_id);
2530 priv->bus_message_source_id = 0;
2533 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2535 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2536 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2538 if (priv->pipeline != NULL)
2539 g_object_unref (priv->pipeline);
2540 priv->pipeline = NULL;
2542 if (priv->audio_output != NULL)
2543 g_object_unref (priv->audio_output);
2544 priv->audio_output = NULL;
2545 priv->audio_output_added = FALSE;
2547 if (priv->video_tee != NULL)
2548 g_object_unref (priv->video_tee);
2549 priv->video_tee = NULL;
2551 if (priv->video_preview != NULL)
2552 clutter_actor_destroy (priv->video_preview);
2553 priv->video_preview = NULL;
2555 /* If we destroy the preview while it's being dragged, we won't
2556 * get the ::drag-end signal, so manually destroy the clone */
2557 if (priv->drag_preview != NULL)
2559 clutter_actor_destroy (priv->drag_preview);
2560 empathy_call_window_show_preview_rectangles (self, FALSE);
2561 priv->drag_preview = NULL;
2564 priv->funnel = NULL;
2566 create_pipeline (self);
2567 /* Call will be started when user will hit the 'redial' button */
2568 priv->start_call_when_playing = FALSE;
2569 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2575 g_message ("Error: could not destroy pipeline. Closing call window");
2576 gtk_widget_destroy (GTK_WIDGET (self));
2583 reset_details_pane (EmpathyCallWindow *self)
2585 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2587 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2588 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2589 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2590 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2594 empathy_call_window_disconnected (EmpathyCallWindow *self,
2597 gboolean could_disconnect = FALSE;
2598 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2599 gboolean could_reset_pipeline;
2601 /* Leave full screen mode if needed */
2602 gtk_window_unfullscreen (GTK_WINDOW (self));
2604 g_signal_emit (self, signals[SIG_INHIBIT], 0, FALSE);
2606 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2607 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2609 /* Create the video input and then turn on the camera
2610 * menu, so that the active camera gets marked as such.
2612 if (priv->video_input == NULL)
2613 create_video_input (self);
2614 empathy_camera_menu_set_sensitive (priv->camera_menu, TRUE);
2616 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2618 if (priv->call_state == CONNECTING)
2619 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2621 if (priv->call_state != REDIALING)
2622 priv->call_state = DISCONNECTED;
2624 /* Show the toolbar */
2625 clutter_state_set_state (priv->transitions, "fade-in");
2627 if (could_reset_pipeline)
2629 g_mutex_lock (&priv->lock);
2631 g_timer_stop (priv->timer);
2633 if (priv->timer_id != 0)
2634 g_source_remove (priv->timer_id);
2637 g_mutex_unlock (&priv->lock);
2640 /* We are about to destroy the window, no need to update it or create
2641 * a video preview */
2644 empathy_call_window_status_message (self, _("Disconnected"));
2646 empathy_call_window_show_hangup_button (self, FALSE);
2648 /* Unsensitive the camera and mic button */
2649 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2650 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2652 /* Be sure that the mic button is enabled */
2653 empathy_audio_src_set_mute (
2654 EMPATHY_GST_AUDIO_SRC (self->priv->audio_input), FALSE);
2656 if (priv->camera_state == CAMERA_STATE_ON)
2658 /* Restart the preview with the new pipeline. */
2659 display_video_preview (self, TRUE);
2662 /* destroy the video output; it will be recreated when we'll redial */
2663 disconnect_video_output_motion_handler (self);
2664 if (priv->video_output != NULL)
2665 clutter_actor_destroy (priv->video_output);
2666 priv->video_output = NULL;
2667 if (priv->got_video_src > 0)
2669 g_source_remove (priv->got_video_src);
2670 priv->got_video_src = 0;
2673 gtk_widget_show (priv->remote_user_avatar_widget);
2675 reset_details_pane (self);
2677 priv->sending_video = FALSE;
2678 priv->call_started = FALSE;
2680 could_disconnect = TRUE;
2682 /* TODO: display the self avatar of the preview (depends if the "Always
2683 * Show Video Preview" is enabled or not) */
2686 return could_disconnect;
2691 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2694 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2695 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2697 if (empathy_call_window_disconnected (self, TRUE) &&
2698 priv->call_state == REDIALING)
2699 empathy_call_window_restart_call (self);
2703 empathy_call_window_content_is_raw (TfContent *content)
2705 FsConference *conference;
2708 g_object_get (content, "fs-conference", &conference, NULL);
2709 g_assert (conference != NULL);
2711 /* FIXME: Ugly hack, update when moving a packetization property into
2713 israw = g_str_has_prefix (GST_OBJECT_NAME (conference), "fsrawconf");
2714 gst_object_unref (conference);
2720 empathy_call_window_content_removed_cb (EmpathyCallHandler *handler,
2722 EmpathyCallWindow *self)
2724 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2725 FsMediaType media_type;
2727 DEBUG ("removing content");
2729 g_object_get (content, "media-type", &media_type, NULL);
2732 * This assumes that there is only one video stream per channel...
2735 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2737 if (priv->funnel != NULL)
2741 output = priv->video_output_sink;
2743 gst_element_set_state (output, GST_STATE_NULL);
2744 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2746 gst_bin_remove (GST_BIN (priv->pipeline), output);
2747 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2748 priv->funnel = NULL;
2751 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2753 if (priv->audio_output != NULL)
2755 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2757 if (priv->audio_output_added)
2758 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2759 priv->audio_output = NULL;
2760 priv->audio_output_added = FALSE;
2765 g_assert_not_reached ();
2772 empathy_call_window_framerate_changed_cb (EmpathyCallHandler *handler,
2774 EmpathyCallWindow *self)
2776 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2778 DEBUG ("Framerate changed to %u", framerate);
2780 if (priv->video_input != NULL)
2781 empathy_video_src_set_framerate (priv->video_input, framerate);
2785 empathy_call_window_resolution_changed_cb (EmpathyCallHandler *handler,
2788 EmpathyCallWindow *self)
2790 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2792 DEBUG ("Resolution changed to %ux%u", width, height);
2794 if (priv->video_input != NULL)
2796 empathy_video_src_set_resolution (priv->video_input, width, height);
2800 /* Called with global lock held */
2802 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2804 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2808 if (priv->funnel == NULL)
2810 output = priv->video_output_sink;
2812 priv->funnel = gst_element_factory_make ("funnel", NULL);
2814 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2819 g_warning ("Could not create video funnel");
2823 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2825 gst_object_unref (priv->funnel);
2826 priv->funnel = NULL;
2827 g_warning ("Could not add funnel to pipeline");
2831 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2833 g_warning ("Could not add the video output widget to the pipeline");
2837 if (!gst_element_link (priv->funnel, output))
2839 g_warning ("Could not link output sink to funnel");
2840 goto error_output_added;
2843 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2845 g_warning ("Could not start video sink");
2846 goto error_output_added;
2849 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2851 g_warning ("Could not start funnel");
2852 goto error_output_added;
2856 pad = gst_element_get_request_pad (priv->funnel, "sink_%u");
2858 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2862 g_warning ("Could not get request pad from funnel");
2869 gst_element_set_locked_state (priv->funnel, TRUE);
2870 gst_element_set_locked_state (output, TRUE);
2872 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2873 gst_element_set_state (output, GST_STATE_NULL);
2875 gst_bin_remove (GST_BIN (priv->pipeline), output);
2876 gst_element_set_locked_state (output, FALSE);
2880 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2881 priv->funnel = NULL;
2886 /* Called with global lock held */
2888 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self,
2891 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2893 GstPadTemplate *template;
2895 if (!priv->audio_output_added)
2897 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2899 g_warning ("Could not add audio sink to pipeline");
2900 g_object_unref (priv->audio_output);
2901 goto error_add_output;
2904 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2906 g_warning ("Could not start audio sink");
2911 template = gst_element_class_get_pad_template (
2912 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2914 pad = gst_element_request_pad (priv->audio_output,
2915 template, NULL, NULL);
2919 g_warning ("Could not get sink pad from sink");
2926 gst_element_set_locked_state (priv->audio_output, TRUE);
2927 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2928 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2929 priv->audio_output = NULL;
2937 empathy_call_window_update_timer (gpointer user_data)
2939 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2940 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2941 const gchar *status;
2945 time_ = g_timer_elapsed (priv->timer, NULL);
2947 if (priv->call_state == HELD)
2948 status = _("On hold");
2949 else if (priv->call_state == DISCONNECTED)
2950 status = _("Disconnected");
2951 else if (priv->muted)
2954 status = _("Duration");
2956 /* Translators: 'status - minutes:seconds' the caller has been connected */
2957 str = g_strdup_printf (_("%s — %d:%02dm"),
2959 (int) time_ / 60, (int) time_ % 60);
2960 empathy_call_window_status_message (self, str);
2968 EMP_RESPONSE_BALANCE
2972 on_error_infobar_response_cb (GtkInfoBar *info_bar,
2976 switch (response_id)
2978 case GTK_RESPONSE_CLOSE:
2979 gtk_widget_destroy (GTK_WIDGET (info_bar));
2981 case EMP_RESPONSE_BALANCE:
2982 empathy_url_show (GTK_WIDGET (info_bar),
2983 g_object_get_data (G_OBJECT (info_bar), "uri"));
2989 display_error (EmpathyCallWindow *self,
2993 const gchar *details,
2994 const gchar *button_text,
2996 gint button_response)
2998 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2999 GtkWidget *info_bar;
3000 GtkWidget *content_area;
3007 /* Create info bar */
3008 info_bar = gtk_info_bar_new ();
3010 if (button_text != NULL)
3012 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
3013 button_text, button_response);
3014 g_object_set_data_full (G_OBJECT (info_bar),
3015 "uri", g_strdup (uri), g_free);
3018 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
3019 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
3021 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
3023 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
3025 /* hbox containing the image and the messages vbox */
3026 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
3027 gtk_container_add (GTK_CONTAINER (content_area), hbox);
3030 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
3031 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
3033 /* vbox containing the main message and the details expander */
3034 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
3035 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
3038 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
3040 label = gtk_label_new (NULL);
3041 gtk_label_set_markup (GTK_LABEL (label), txt);
3042 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
3043 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
3046 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
3049 if (details != NULL)
3051 GtkWidget *expander;
3053 expander = gtk_expander_new (_("Technical Details"));
3055 txt = g_strdup_printf ("<i>%s</i>", details);
3057 label = gtk_label_new (NULL);
3058 gtk_label_set_markup (GTK_LABEL (label), txt);
3059 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
3060 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
3063 gtk_container_add (GTK_CONTAINER (expander), label);
3064 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
3067 g_signal_connect (info_bar, "response",
3068 G_CALLBACK (on_error_infobar_response_cb), NULL);
3070 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
3071 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
3072 gtk_widget_show_all (info_bar);
3077 media_stream_error_to_txt (EmpathyCallWindow *self,
3078 TpCallChannel *call,
3080 TpMediaStreamError error)
3082 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3083 const gchar *cm = NULL;
3089 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
3091 return g_strdup_printf (
3092 _("%s's software does not understand any of the audio formats "
3093 "supported by your computer"),
3094 empathy_contact_get_alias (priv->contact));
3096 return g_strdup_printf (
3097 _("%s's software does not understand any of the video formats "
3098 "supported by your computer"),
3099 empathy_contact_get_alias (priv->contact));
3101 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
3102 return g_strdup_printf (
3103 _("Can't establish a connection to %s. "
3104 "One of you might be on a network that does not allow "
3105 "direct connections."),
3106 empathy_contact_get_alias (priv->contact));
3108 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
3109 return g_strdup (_("There was a failure on the network"));
3111 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
3113 return g_strdup (_("The audio formats necessary for this call "
3114 "are not installed on your computer"));
3116 return g_strdup (_("The video formats necessary for this call "
3117 "are not installed on your computer"));
3119 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
3120 tp_connection_parse_object_path (
3121 tp_channel_get_connection (TP_CHANNEL (call)),
3124 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
3125 "product=Telepathy&component=%s", cm);
3127 result = g_strdup_printf (
3128 _("Something unexpected happened in a Telepathy component. "
3129 "Please <a href=\"%s\">report this bug</a> and attach "
3130 "logs gathered from the 'Debug' window in the Help menu."), url);
3136 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
3137 return g_strdup (_("There was a failure in the call engine"));
3139 case TP_MEDIA_STREAM_ERROR_EOS:
3140 return g_strdup (_("The end of the stream was reached"));
3142 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
3149 empathy_call_window_stream_error (EmpathyCallWindow *self,
3150 TpCallChannel *call,
3159 desc = media_stream_error_to_txt (self, call, audio, code);
3162 /* No description, use the error message. That's not great as it's not
3163 * localized but it's better than nothing. */
3164 display_error (self, call, icon, title, msg, NULL);
3168 display_error (self, call, icon, title, desc, msg);
3174 empathy_call_window_audio_stream_error (TpCallChannel *call,
3177 EmpathyCallWindow *self)
3179 empathy_call_window_stream_error (self, call, TRUE, code, msg,
3180 "gnome-stock-mic", _("Can't establish audio stream"));
3184 empathy_call_window_video_stream_error (TpCallChannel *call,
3187 EmpathyCallWindow *self)
3189 empathy_call_window_stream_error (self, call, FALSE, code, msg,
3190 "camera-web", _("Can't establish video stream"));
3195 show_balance_error (EmpathyCallWindow *self)
3199 gchar *balance, *tmp;
3200 const gchar *uri, *currency;
3204 g_object_get (self->priv->handler,
3205 "call-channel", &call,
3208 conn = tp_channel_get_connection (call);
3209 g_object_unref (call);
3211 uri = tp_connection_get_balance_uri (conn);
3213 if (!tp_connection_get_balance (conn, &amount, &scale, ¤cy))
3215 /* unknown balance */
3216 balance = g_strdup ("(--)");
3220 char *money = empathy_format_currency (amount, scale, currency);
3222 balance = g_strdup_printf ("%s %s",
3227 tmp = g_strdup_printf (_("Your current balance is %s."), balance),
3229 display_error (self,
3231 _("Sorry, you don’t have enough credit for that call."),
3235 EMP_RESPONSE_BALANCE);
3242 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
3245 EmpathyCallWindow *self)
3247 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3248 TpCallChannel *call;
3249 gboolean can_send_video;
3251 if (state == TP_CALL_STATE_ENDED)
3253 DEBUG ("Call ended: %s", (reason != NULL && reason[0] != '\0') ? reason : "unspecified reason");
3254 empathy_call_window_disconnected (self, TRUE);
3255 if (!tp_strdiff (reason, TP_ERROR_STR_INSUFFICIENT_BALANCE))
3256 show_balance_error (self);
3260 if (state != TP_CALL_STATE_ACCEPTED)
3263 if (priv->call_state == CONNECTED)
3266 g_timer_start (priv->timer);
3267 priv->call_state = CONNECTED;
3269 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3271 can_send_video = priv->video_input != NULL &&
3272 empathy_contact_can_voip_video (priv->contact) &&
3273 empathy_camera_monitor_get_available (priv->camera_monitor);
3275 g_object_get (priv->handler, "call-channel", &call, NULL);
3277 if (tp_call_channel_has_dtmf (call))
3278 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
3280 if (priv->video_input == NULL)
3281 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
3283 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
3285 empathy_call_window_show_hangup_button (self, TRUE);
3287 gtk_widget_set_sensitive (priv->mic_button, TRUE);
3289 clutter_actor_hide (priv->video_output);
3290 gtk_widget_show (priv->remote_user_avatar_widget);
3292 g_object_unref (call);
3294 g_mutex_lock (&priv->lock);
3296 priv->timer_id = g_timeout_add_seconds (1,
3297 empathy_call_window_update_timer, self);
3299 g_mutex_unlock (&priv->lock);
3301 empathy_call_window_update_timer (self);
3303 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
3307 empathy_call_window_show_video_output_cb (gpointer user_data)
3309 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3311 if (self->priv->video_output != NULL)
3313 gtk_widget_hide (self->priv->remote_user_avatar_widget);
3314 clutter_actor_show (self->priv->video_output);
3315 clutter_actor_raise_top (self->priv->overlay_bin);
3322 empathy_call_window_check_video_cb (gpointer data)
3324 EmpathyCallWindow *self = data;
3326 if (self->priv->got_video)
3328 self->priv->got_video = FALSE;
3332 /* No video in the last N seconds, display the remote avatar */
3333 empathy_call_window_show_video_output (self, FALSE);
3338 /* Called from the streaming thread */
3340 static GstPadProbeReturn
3341 empathy_call_window_video_probe_cb (GstPad *pad,
3342 GstPadProbeInfo *info,
3345 EmpathyCallWindow *self = user_data;
3347 if (G_UNLIKELY (!self->priv->got_video))
3349 /* show the remote video */
3350 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3351 empathy_call_window_show_video_output_cb,
3352 g_object_ref (self), g_object_unref);
3354 self->priv->got_video = TRUE;
3357 return GST_PAD_PROBE_OK;
3361 empathy_call_window_video_probe_cb (GstPad *pad,
3362 GstMiniObject *mini_obj,
3363 EmpathyCallWindow *self)
3366 if (GST_IS_EVENT (mini_obj))
3369 if (G_UNLIKELY (!self->priv->got_video))
3371 /* show the remote video */
3372 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3373 empathy_call_window_show_video_output_cb,
3374 g_object_ref (self), g_object_unref);
3376 self->priv->got_video = TRUE;
3383 /* Called from the streaming thread */
3385 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
3386 TfContent *content, GstPad *src, gpointer user_data)
3388 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3389 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3390 gboolean retval = FALSE;
3395 g_mutex_lock (&priv->lock);
3397 g_object_get (content, "media-type", &media_type, NULL);
3401 case TP_MEDIA_STREAM_TYPE_AUDIO:
3402 pad = empathy_call_window_get_audio_sink_pad (self, content);
3404 case TP_MEDIA_STREAM_TYPE_VIDEO:
3405 g_idle_add (empathy_call_window_show_video_output_cb, self);
3406 pad = empathy_call_window_get_video_sink_pad (self);
3409 gst_pad_add_probe (src,
3410 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_BUFFER_LIST,
3411 empathy_call_window_video_probe_cb, self, NULL);
3413 gst_pad_add_data_probe (src,
3414 G_CALLBACK (empathy_call_window_video_probe_cb), self);
3416 if (priv->got_video_src > 0)
3417 g_source_remove (priv->got_video_src);
3418 priv->got_video_src = g_timeout_add_seconds (1,
3419 empathy_call_window_check_video_cb, self);
3422 g_assert_not_reached ();
3428 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
3429 g_warning ("Could not link %s sink pad",
3430 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
3434 gst_object_unref (pad);
3438 /* If no sink could be linked, try to add fakesink to prevent the whole call
3443 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
3445 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
3447 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
3448 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
3449 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
3451 gst_element_set_locked_state (fakesink, TRUE);
3452 gst_element_set_state (fakesink, GST_STATE_NULL);
3453 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
3457 DEBUG ("Could not link real sink, linked fakesink instead");
3459 gst_object_unref (sinkpad);
3463 gst_object_unref (fakesink);
3468 g_mutex_unlock (&priv->lock);
3474 empathy_call_window_prepare_audio_output (EmpathyCallWindow *self,
3477 EmpathyCallWindowPriv *priv = self->priv;
3479 g_assert (priv->audio_output_added == FALSE);
3480 g_assert (priv->audio_output == FALSE);
3482 priv->audio_output = empathy_audio_sink_new ();
3483 g_object_ref_sink (priv->audio_output);
3485 /* volume button to output volume linking */
3486 g_object_bind_property (priv->audio_output, "volume",
3487 priv->volume_button, "value",
3488 G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
3490 g_object_bind_property_full (content, "requested-output-volume",
3491 priv->audio_output, "volume",
3493 audio_control_volume_to_element,
3494 element_volume_to_audio_control,
3497 /* Link volumes together, sync the current audio input volume property
3498 * back to farstream first */
3499 g_object_bind_property_full (priv->audio_output, "volume",
3500 content, "reported-output-volume",
3501 G_BINDING_SYNC_CREATE,
3502 element_volume_to_audio_control,
3503 audio_control_volume_to_element,
3506 /* For raw audio conferences assume that the producer of the raw data
3507 * has already processed it, so turn off any echo cancellation and any
3508 * other audio improvements that come with it */
3509 empathy_audio_sink_set_echo_cancel (
3510 EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3511 !empathy_call_window_content_is_raw (content));
3516 empathy_call_window_content_added_cb (EmpathyCallHandler *handler,
3517 TfContent *content, gpointer user_data)
3519 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3520 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3522 FsMediaType media_type;
3523 gboolean retval = FALSE;
3525 g_object_get (content, "media-type", &media_type, "sink-pad", &sink, NULL);
3526 g_assert (sink != NULL);
3530 case FS_MEDIA_TYPE_AUDIO:
3532 /* For raw audio conferences assume that the receiver of the raw data
3533 * wants it unprocessed, so turn off any echo cancellation and any
3534 * other audio improvements that come with it */
3535 empathy_audio_src_set_echo_cancel (
3536 EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3537 !empathy_call_window_content_is_raw (content));
3539 /* Link volumes together, sync the current audio input volume property
3540 * back to farstream first */
3541 g_object_bind_property_full (content, "requested-input-volume",
3542 priv->audio_input, "volume",
3544 audio_control_volume_to_element,
3545 element_volume_to_audio_control,
3548 g_object_bind_property_full (priv->audio_input, "volume",
3549 content, "reported-input-volume",
3550 G_BINDING_SYNC_CREATE,
3551 element_volume_to_audio_control,
3552 audio_control_volume_to_element,
3555 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
3557 g_warning ("Could not add audio source to pipeline");
3561 pad = gst_element_get_static_pad (priv->audio_input, "src");
3564 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3565 g_warning ("Could not get source pad from audio source");
3569 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3571 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3572 gst_object_unref (pad);
3573 g_warning ("Could not link audio source to farsight");
3576 gst_object_unref (pad);
3578 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3580 g_warning ("Could not start audio source");
3581 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3582 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3586 /* Prepare our audio output, not added yet though */
3587 empathy_call_window_prepare_audio_output (self, content);
3591 case FS_MEDIA_TYPE_VIDEO:
3592 if (priv->video_tee != NULL)
3595 pad = gst_element_get_request_pad (priv->video_tee, "src_%u");
3597 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3599 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3601 g_warning ("Could not link video source input pipeline");
3604 gst_object_unref (pad);
3610 g_assert_not_reached ();
3613 gst_object_unref (sink);
3618 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3620 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3621 GstElement *preview;
3623 disable_camera (self);
3625 DEBUG ("remove video input");
3626 preview = priv->video_preview_sink;
3628 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3629 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3630 gst_element_set_state (preview, GST_STATE_NULL);
3632 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3635 g_object_unref (priv->video_input);
3636 priv->video_input = NULL;
3637 g_object_unref (priv->video_tee);
3638 priv->video_tee = NULL;
3639 clutter_actor_destroy (priv->video_preview);
3640 priv->video_preview = NULL;
3642 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3643 empathy_camera_menu_set_sensitive (priv->camera_menu, FALSE);
3647 start_call (EmpathyCallWindow *self)
3649 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3651 g_signal_emit (self, signals[SIG_INHIBIT], 0, TRUE);
3653 priv->call_started = TRUE;
3654 empathy_call_handler_start_call (priv->handler,
3655 gtk_get_current_event_time ());
3657 if (empathy_call_handler_has_initial_video (priv->handler))
3659 TpCallChannel *call;
3662 g_object_get (priv->handler, "call-channel", &call, NULL);
3663 /* If the call channel isn't set yet we're requesting it, if we're
3664 * requesting it with initial video it should be PENDING_SEND when we get
3667 s = TP_SENDING_STATE_PENDING_SEND;
3669 s = empathy_call_channel_get_video_state (call);
3671 if (s == TP_SENDING_STATE_PENDING_SEND ||
3672 s == TP_SENDING_STATE_SENDING)
3674 /* Enable 'send video' buttons and display the preview */
3675 gtk_toggle_button_set_active (
3676 GTK_TOGGLE_BUTTON (priv->camera_button), TRUE);
3680 gtk_toggle_button_set_active (
3681 GTK_TOGGLE_BUTTON (priv->camera_button), FALSE);
3683 if (priv->video_preview == NULL)
3685 create_video_preview (self);
3686 add_video_preview_to_pipeline (self);
3691 g_object_unref (call);
3696 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3699 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3700 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3701 GstState newstate, pending;
3703 empathy_call_handler_bus_message (priv->handler, bus, message);
3705 switch (GST_MESSAGE_TYPE (message))
3707 case GST_MESSAGE_STATE_CHANGED:
3708 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3710 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3712 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3713 !priv->call_started)
3715 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3716 if (newstate == GST_STATE_PAUSED)
3718 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3719 priv->pipeline_playing = TRUE;
3721 if (priv->start_call_when_playing)
3725 if (priv->video_preview_sink != NULL &&
3726 GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_preview_sink))
3728 gst_message_parse_state_changed (message, NULL, &newstate,
3731 if (newstate == GST_STATE_PLAYING &&
3732 pending == GST_STATE_VOID_PENDING)
3733 empathy_call_window_stop_camera_spinning (self);
3736 case GST_MESSAGE_ERROR:
3738 GError *error = NULL;
3739 GstElement *gst_error;
3743 gst_message_parse_error (message, &error, &debug);
3744 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3746 g_message ("Element error: %s -- %s\n", error->message, debug);
3748 name = gst_element_get_name (gst_error);
3749 if (g_str_has_prefix (name, VIDEO_INPUT_ERROR_PREFIX))
3751 /* Remove the video input and continue */
3752 if (priv->video_input != NULL)
3753 empathy_call_window_remove_video_input (self);
3754 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3758 empathy_call_window_disconnected (self, TRUE);
3761 g_error_free (error);
3764 case GST_MESSAGE_UNKNOWN:
3765 case GST_MESSAGE_EOS:
3766 case GST_MESSAGE_WARNING:
3767 case GST_MESSAGE_INFO:
3768 case GST_MESSAGE_TAG:
3769 case GST_MESSAGE_BUFFERING:
3770 case GST_MESSAGE_STATE_DIRTY:
3771 case GST_MESSAGE_STEP_DONE:
3772 case GST_MESSAGE_CLOCK_PROVIDE:
3773 case GST_MESSAGE_CLOCK_LOST:
3774 case GST_MESSAGE_NEW_CLOCK:
3775 case GST_MESSAGE_STRUCTURE_CHANGE:
3776 case GST_MESSAGE_STREAM_STATUS:
3777 case GST_MESSAGE_APPLICATION:
3778 case GST_MESSAGE_ELEMENT:
3779 case GST_MESSAGE_SEGMENT_START:
3780 case GST_MESSAGE_SEGMENT_DONE:
3781 case GST_MESSAGE_DURATION:
3782 case GST_MESSAGE_ANY:
3791 empathy_call_window_members_changed_cb (TpCallChannel *call,
3792 GHashTable *updates,
3794 TpCallStateReason *reason,
3795 EmpathyCallWindow *self)
3797 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3798 GHashTableIter iter;
3799 gpointer key, value;
3800 gboolean held = FALSE;
3802 g_hash_table_iter_init (&iter, updates);
3803 while (g_hash_table_iter_next (&iter, &key, &value))
3805 if (GPOINTER_TO_INT (value) & TP_CALL_MEMBER_FLAG_HELD)
3807 /* This assumes this is a 1-1 call, otherwise one participant
3808 * putting the call on hold wouldn't mean the call is on hold
3816 priv->call_state = HELD;
3817 else if (priv->call_state == HELD)
3818 priv->call_state = CONNECTED;
3822 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3824 EmpathyCallWindow *self)
3826 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3827 TpCallChannel *call;
3829 g_object_get (priv->handler, "call-channel", &call, NULL);
3834 tp_g_signal_connect_object (call, "audio-stream-error",
3835 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3836 tp_g_signal_connect_object (call, "video-stream-error",
3837 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3840 tp_g_signal_connect_object (call, "members-changed",
3841 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3843 g_object_unref (call);
3847 empathy_call_window_connect_handler (EmpathyCallWindow *self)
3849 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3850 TpCallChannel *call;
3852 g_signal_connect (priv->handler, "state-changed",
3853 G_CALLBACK (empathy_call_window_state_changed_cb), self);
3854 g_signal_connect (priv->handler, "conference-added",
3855 G_CALLBACK (empathy_call_window_conference_added_cb), self);
3856 g_signal_connect (priv->handler, "conference-removed",
3857 G_CALLBACK (empathy_call_window_conference_removed_cb), self);
3858 g_signal_connect (priv->handler, "closed",
3859 G_CALLBACK (empathy_call_window_channel_closed_cb), self);
3860 g_signal_connect (priv->handler, "src-pad-added",
3861 G_CALLBACK (empathy_call_window_src_added_cb), self);
3862 g_signal_connect (priv->handler, "content-added",
3863 G_CALLBACK (empathy_call_window_content_added_cb), self);
3864 g_signal_connect (priv->handler, "content-removed",
3865 G_CALLBACK (empathy_call_window_content_removed_cb), self);
3867 /* We connect to ::call-channel unconditionally since we'll
3868 * get new channels if we hangup and redial or if we reuse the
3870 g_signal_connect (priv->handler, "notify::call-channel",
3871 G_CALLBACK (call_handler_notify_call_cb), self);
3873 g_signal_connect (priv->handler, "framerate-changed",
3874 G_CALLBACK (empathy_call_window_framerate_changed_cb), self);
3875 g_signal_connect (priv->handler, "resolution-changed",
3876 G_CALLBACK (empathy_call_window_resolution_changed_cb), self);
3878 g_object_get (priv->handler, "call-channel", &call, NULL);
3881 /* We won't get notify::call-channel for this channel, so
3882 * directly call the callback. */
3883 call_handler_notify_call_cb (priv->handler, NULL, self);
3884 g_object_unref (call);
3889 empathy_call_window_realized_cb (GtkWidget *widget,
3890 EmpathyCallWindow *self)
3894 /* Make the hangup button twice as wide */
3895 width = gtk_widget_get_allocated_width (self->priv->hangup_button);
3896 gtk_widget_set_size_request (self->priv->hangup_button, width * 2, -1);
3898 empathy_call_window_connect_handler (self);
3900 gst_element_set_state (self->priv->pipeline, GST_STATE_PAUSED);
3904 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3905 EmpathyCallWindow *window)
3907 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3909 if (priv->pipeline != NULL)
3911 if (priv->bus_message_source_id != 0)
3913 g_source_remove (priv->bus_message_source_id);
3914 priv->bus_message_source_id = 0;
3917 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3920 if (priv->call_state == CONNECTING)
3921 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3927 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3930 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3932 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3937 gtk_widget_hide (priv->dtmf_panel);
3938 gtk_widget_hide (menu);
3939 gtk_widget_hide (priv->toolbar);
3943 if (priv->dialpad_was_visible_before_fs)
3944 gtk_widget_show (priv->dtmf_panel);
3946 gtk_widget_show (menu);
3947 gtk_widget_show (priv->toolbar);
3949 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3950 priv->original_height_before_fs);
3955 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3957 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3959 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3960 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3962 if (priv->video_output != NULL)
3965 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3966 priv->video_output, TRUE, TRUE,
3967 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3974 empathy_call_window_state_event_cb (GtkWidget *widget,
3975 GdkEventWindowState *event, EmpathyCallWindow *window)
3977 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3979 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3980 gboolean set_fullscreen = event->new_window_state &
3981 GDK_WINDOW_STATE_FULLSCREEN;
3985 gboolean dialpad_was_visible;
3986 GtkAllocation allocation;
3987 gint original_width, original_height;
3989 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3990 original_width = allocation.width;
3991 original_height = allocation.height;
3993 g_object_get (priv->dtmf_panel,
3994 "visible", &dialpad_was_visible,
3997 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3998 priv->original_width_before_fs = original_width;
3999 priv->original_height_before_fs = original_height;
4001 if (priv->video_output_motion_handler_id == 0 &&
4002 priv->video_output != NULL)
4004 priv->video_output_motion_handler_id = g_signal_connect (
4005 G_OBJECT (priv->video_container), "motion-notify-event",
4006 G_CALLBACK (empathy_call_window_video_output_motion_notify),
4012 disconnect_video_output_motion_handler (window);
4015 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
4017 show_controls (window, set_fullscreen);
4018 show_borders (window, set_fullscreen);
4019 gtk_action_set_stock_id (priv->menu_fullscreen,
4020 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
4021 priv->is_fullscreen = set_fullscreen;
4028 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
4031 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4032 int w, h, dialpad_width;
4033 GtkAllocation allocation;
4035 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
4036 w = allocation.width;
4037 h = allocation.height;
4039 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
4043 gtk_widget_show (priv->dtmf_panel);
4049 gtk_widget_hide (priv->dtmf_panel);
4053 gtk_window_resize (GTK_WINDOW (window), w, h);
4057 empathy_call_window_set_send_video (EmpathyCallWindow *window,
4060 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4061 TpCallChannel *call;
4063 priv->sending_video = (state == CAMERA_STATE_ON);
4065 if (state == CAMERA_STATE_ON)
4067 /* When we start sending video, we want to show the video preview by
4069 display_video_preview (window, TRUE);
4073 display_video_preview (window, FALSE);
4076 if (priv->call_state != CONNECTED)
4079 g_object_get (priv->handler, "call-channel", &call, NULL);
4080 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
4081 empathy_call_channel_send_video (call, priv->sending_video);
4082 g_object_unref (call);
4086 empathy_call_window_hangup_cb (gpointer object,
4087 EmpathyCallWindow *self)
4089 /* stopping the call will put it the ENDED state and
4090 * from state_changed_cb we'll reconfigure the window
4092 empathy_call_handler_stop_call (self->priv->handler);
4096 empathy_call_window_restart_call (EmpathyCallWindow *window)
4098 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4100 /* Remove error info bars */
4101 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
4102 (GtkCallback) gtk_widget_destroy, NULL);
4104 create_video_output_widget (window);
4105 priv->outgoing = TRUE;
4106 empathy_call_window_set_state_connecting (window);
4108 if (priv->pipeline_playing)
4109 start_call (window);
4111 /* call will be started when the pipeline is ready */
4112 priv->start_call_when_playing = TRUE;
4114 empathy_call_window_setup_avatars (window, priv->handler);
4116 empathy_call_window_show_hangup_button (window, TRUE);
4120 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
4121 EmpathyCallWindow *window)
4125 active = gtk_toggle_tool_button_get_active (button);
4127 empathy_call_window_show_dialpad (window, active);
4131 empathy_call_window_fullscreen_cb (gpointer object,
4132 EmpathyCallWindow *window)
4134 empathy_call_window_fullscreen_toggle (window);
4138 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
4140 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4142 if (priv->is_fullscreen)
4143 gtk_window_unfullscreen (GTK_WINDOW (window));
4145 gtk_window_fullscreen (GTK_WINDOW (window));
4149 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
4150 GdkEventButton *event, EmpathyCallWindow *window)
4152 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
4154 empathy_call_window_video_menu_popup (window, event->button);
4162 empathy_call_window_key_press_cb (GtkWidget *video_output,
4163 GdkEventKey *event, EmpathyCallWindow *window)
4165 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4168 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
4170 /* Since we are in fullscreen mode, toggling will bring us back to
4172 empathy_call_window_fullscreen_toggle (window);
4176 key = gdk_keyval_to_unicode (event->keyval);
4197 gtk_toggle_tool_button_set_active (
4198 GTK_TOGGLE_TOOL_BUTTON (priv->dialpad_button), TRUE);
4200 empathy_dialpad_widget_press_key (
4201 EMPATHY_DIALPAD_WIDGET (priv->dtmf_panel), key);
4207 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
4208 GdkEventMotion *event, EmpathyCallWindow *window)
4210 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4212 if (priv->is_fullscreen)
4214 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
4216 /* Show the bottom toolbar */
4217 empathy_call_window_motion_notify_cb (NULL, NULL, window);
4224 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
4228 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4230 menu = gtk_ui_manager_get_widget (priv->ui_manager,
4232 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
4233 button, gtk_get_current_event_time ());
4234 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
4238 empathy_call_window_status_message (EmpathyCallWindow *self,
4241 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
4245 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
4247 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4249 return priv->ui_manager;
4252 EmpathyGstAudioSrc *
4253 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
4255 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4257 return (EmpathyGstAudioSrc *) priv->audio_input;
4260 EmpathyGstVideoSrc *
4261 empathy_call_window_get_video_src (EmpathyCallWindow *self)
4263 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);
4267 empathy_call_window_change_webcam (EmpathyCallWindow *self,
4268 const gchar *device)
4270 EmpathyGstVideoSrc *video;
4273 /* Restart the camera only if it's already running */
4274 running = (self->priv->video_preview != NULL);
4275 video = empathy_call_window_get_video_src (self);
4278 empathy_call_window_play_camera (self, FALSE);
4280 empathy_video_src_change_device (video, device);
4283 empathy_call_window_play_camera (self, TRUE);