2 * empathy-call-window.c - Source for EmpathyCallWindow
3 * Copyright (C) 2008-2011 Collabora Ltd.
4 * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #include <gdk/gdkkeysyms.h>
31 #include <glib/gi18n.h>
33 #include <clutter/clutter.h>
34 #include <clutter-gtk/clutter-gtk.h>
35 #include <clutter-gst/clutter-gst.h>
37 #include <telepathy-farstream/telepathy-farstream.h>
38 #include <telepathy-glib/telepathy-glib.h>
40 #include <farstream/fs-element-added-notifier.h>
41 #include <farstream/fs-utils.h>
43 #include <libempathy/empathy-camera-monitor.h>
44 #include <libempathy/empathy-gsettings.h>
45 #include <libempathy/empathy-request-util.h>
46 #include <libempathy/empathy-utils.h>
48 #include <libempathy-gtk/empathy-avatar-image.h>
49 #include <libempathy-gtk/empathy-dialpad-widget.h>
50 #include <libempathy-gtk/empathy-ui-utils.h>
51 #include <libempathy-gtk/empathy-sound-manager.h>
52 #include <libempathy-gtk/empathy-geometry.h>
53 #include <libempathy-gtk/empathy-images.h>
54 #include <libempathy-gtk/empathy-call-utils.h>
56 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
57 #include <libempathy/empathy-debug.h>
59 #include "empathy-call-window.h"
60 #include "empathy-call-window-fullscreen.h"
61 #include "empathy-call-factory.h"
62 #include "empathy-about-dialog.h"
63 #include "empathy-audio-src.h"
64 #include "empathy-audio-sink.h"
65 #include "empathy-video-src.h"
66 #include "empathy-mic-menu.h"
67 #include "empathy-preferences.h"
68 #include "empathy-rounded-actor.h"
69 #include "empathy-rounded-rectangle.h"
70 #include "empathy-rounded-texture.h"
71 #include "empathy-camera-menu.h"
73 #define CONTENT_HBOX_SPACING 3
74 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 0
75 #define OVERLAY_MARGIN 6
77 #define REMOTE_VIDEO_DEFAULT_WIDTH 320
78 #define REMOTE_VIDEO_DEFAULT_HEIGHT 240
80 #define SELF_VIDEO_SECTION_WIDTH 120
81 #define SELF_VIDEO_SECTION_HEIGHT 90
82 #define SELF_VIDEO_SECTION_MARGIN 2
83 #define SELF_VIDEO_SECTION_BORDER SELF_VIDEO_SECTION_MARGIN*2
85 /* The avatar's default width and height are set to the same value because we
86 want a square icon. */
87 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT REMOTE_VIDEO_DEFAULT_HEIGHT
88 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH REMOTE_VIDEO_DEFAULT_HEIGHT
90 #define SMALL_TOOLBAR_SIZE 36
92 /* If an video input error occurs, the error message will start with "v4l" */
93 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
95 /* The time interval in milliseconds between 2 outgoing rings */
96 #define MS_BETWEEN_RING 500
98 /* The roundedness of preview box and placeholders */
99 #define PREVIEW_ROUND_FACTOR 16
101 #define PREVIEW_BUTTON_OPACITY 180
103 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
106 PROP_CALL_HANDLER = 1,
114 static guint signals[LAST_SIGNAL];
117 RINGING, /* Incoming call */
118 CONNECTING, /* Outgoing call */
119 CONNECTED, /* Connected */
120 HELD, /* Connected, but on hold */
121 DISCONNECTED, /* Disconnected */
122 REDIALING /* Redialing (special case of CONNECTING) */
126 CAMERA_STATE_OFF = 0,
132 PREVIEW_POS_TOP_LEFT,
133 PREVIEW_POS_TOP_RIGHT,
134 PREVIEW_POS_BOTTOM_LEFT,
135 PREVIEW_POS_BOTTOM_RIGHT,
138 struct _EmpathyCallWindowPriv
140 gboolean dispose_has_run;
141 EmpathyCallHandler *handler;
143 EmpathyContact *contact;
145 EmpathyCameraMonitor *camera_monitor;
147 CallState call_state;
150 GtkUIManager *ui_manager;
151 GtkWidget *errors_vbox;
152 /* widget displays the video received from the remote user. This widget is
153 * alive only during call. */
154 ClutterActor *video_output;
155 ClutterActor *video_preview;
156 ClutterActor *drag_preview;
157 ClutterActor *preview_shown_button;
158 ClutterActor *preview_hidden_button;
159 ClutterActor *preview_rectangle1;
160 ClutterActor *preview_rectangle2;
161 ClutterActor *preview_rectangle3;
162 ClutterActor *preview_rectangle4;
163 ClutterActor *preview_spinner_actor;
164 GtkWidget *preview_spinner_widget;
165 GtkWidget *video_container;
166 GtkWidget *remote_user_avatar_widget;
167 GtkWidget *remote_user_avatar_toolbar;
168 GtkWidget *remote_user_name_toolbar;
169 GtkWidget *remote_user_status_toolbar;
170 GtkWidget *status_label;
171 GtkWidget *hangup_button;
172 GtkWidget *audio_call_button;
173 GtkWidget *video_call_button;
174 GtkWidget *mic_button;
175 GtkWidget *microphone_icon;
176 GtkWidget *volume_button;
177 GtkWidget *camera_button;
178 GtkWidget *dialpad_button;
180 GtkWidget *bottom_toolbar;
181 ClutterActor *floating_toolbar;
183 GtkAction *menu_fullscreen;
184 GtkAction *menu_swap_camera;
186 ClutterState *transitions;
188 /* The main box covering all the stage, contaning remote avatar/video */
189 ClutterActor *video_box;
190 ClutterLayoutManager *video_layout;
192 /* A bin layout manager containing a bin for previews
193 * and the floating toolbar */
194 ClutterActor *overlay_bin;
195 ClutterLayoutManager *overlay_layout;
197 /* Bin layout for the previews */
198 ClutterActor *preview_box;
199 ClutterLayoutManager *preview_layout;
201 /* Coordinates of the preview drag event's start. */
202 PreviewPosition preview_pos;
204 /* We keep a reference on the hbox which contains the main content so we can
205 easilly repack everything when toggling fullscreen */
206 GtkWidget *content_hbox;
208 /* These are used to accept or reject an incoming call when the status
210 GtkWidget *incoming_call_dialog;
211 TpCallChannel *pending_channel;
212 TpChannelDispatchOperation *pending_cdo;
213 TpAddDispatchOperationContext *pending_context;
215 gulong video_output_motion_handler_id;
216 guint bus_message_source_id;
218 GtkWidget *dtmf_panel;
221 GtkWidget *details_vbox;
222 GtkWidget *vcodec_encoding_label;
223 GtkWidget *acodec_encoding_label;
224 GtkWidget *vcodec_decoding_label;
225 GtkWidget *acodec_decoding_label;
227 GtkWidget *audio_remote_candidate_label;
228 GtkWidget *audio_local_candidate_label;
229 GtkWidget *video_remote_candidate_label;
230 GtkWidget *video_local_candidate_label;
231 GtkWidget *video_remote_candidate_info_img;
232 GtkWidget *video_local_candidate_info_img;
233 GtkWidget *audio_remote_candidate_info_img;
234 GtkWidget *audio_local_candidate_info_img;
236 GstElement *video_input;
237 GstElement *video_preview_sink;
238 GstElement *video_output_sink;
239 GstElement *audio_input;
240 GstElement *audio_output;
241 gboolean audio_output_added;
242 GstElement *pipeline;
243 GstElement *video_tee;
253 gboolean call_started;
254 gboolean sending_video;
255 CameraState camera_state;
257 EmpathyCallWindowFullscreen *fullscreen;
258 gboolean is_fullscreen;
263 guint inactivity_src;
265 /* Those fields represent the state of the window before it actually was in
267 gboolean dialpad_was_visible_before_fs;
268 gint original_width_before_fs;
269 gint original_height_before_fs;
271 gint x, y, w, h, dialpad_width;
274 /* TRUE if the call should be started when the pipeline is playing */
275 gboolean start_call_when_playing;
276 /* TRUE if we requested to set the pipeline in the playing state */
277 gboolean pipeline_playing;
279 EmpathySoundManager *sound_mgr;
282 EmpathyMicMenu *mic_menu;
283 EmpathyCameraMenu *camera_menu;
288 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
290 static void empathy_call_window_realized_cb (GtkWidget *widget,
291 EmpathyCallWindow *window);
293 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
294 GdkEvent *event, EmpathyCallWindow *window);
296 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
297 GdkEventWindowState *event, EmpathyCallWindow *window);
299 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
302 static void empathy_call_window_hangup_cb (gpointer object,
303 EmpathyCallWindow *window);
305 static void empathy_call_window_fullscreen_cb (gpointer object,
306 EmpathyCallWindow *window);
308 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
310 static gboolean empathy_call_window_video_button_press_cb (
311 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
313 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
314 GdkEventKey *event, EmpathyCallWindow *window);
316 static gboolean empathy_call_window_video_output_motion_notify (
317 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
319 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
322 static void empathy_call_window_connect_handler (EmpathyCallWindow *self);
324 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
325 EmpathyCallWindow *window);
327 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
329 static void empathy_call_window_status_message (EmpathyCallWindow *window,
332 static gboolean empathy_call_window_bus_message (GstBus *bus,
333 GstMessage *message, gpointer user_data);
335 static gboolean empathy_call_window_update_timer (gpointer user_data);
338 make_background_transparent (GtkClutterActor *actor)
340 GdkRGBA transparent = { 0., 0., 0., 0. };
343 widget = gtk_clutter_actor_get_widget (actor);
344 gtk_widget_override_background_color (widget, GTK_STATE_FLAG_NORMAL, &transparent);
348 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
351 gtk_widget_set_visible (self->priv->hangup_button, show);
352 gtk_widget_set_visible (self->priv->audio_call_button, !show);
353 gtk_widget_set_visible (self->priv->video_call_button, !show);
357 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
358 EmpathyCallWindow *self)
360 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
361 empathy_call_window_restart_call (self);
365 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
366 EmpathyCallWindow *self)
368 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
369 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
370 empathy_call_window_restart_call (self);
374 dtmf_start_tone_cb (EmpathyDialpadWidget *dialpad,
376 EmpathyCallWindow *self)
381 g_object_get (self->priv->handler, "call-channel", &call, NULL);
383 tones[0] = tp_dtmf_event_to_char (event);
385 tp_call_channel_send_tones_async (call, tones, NULL, NULL, NULL);
387 g_object_unref (call);
391 empathy_call_window_show_video_output (EmpathyCallWindow *self,
394 if (self->priv->video_output != NULL)
395 g_object_set (self->priv->video_output, "visible", show, NULL);
397 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
399 clutter_actor_raise_top (self->priv->overlay_bin);
403 create_video_output_widget (EmpathyCallWindow *self)
405 EmpathyCallWindowPriv *priv = GET_PRIV (self);
407 g_assert (priv->video_output == NULL);
408 g_assert (priv->pipeline != NULL);
410 priv->video_output = clutter_texture_new ();
412 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
415 priv->video_output_sink = gst_element_factory_make ("cluttersink", NULL);
416 if (priv->video_output_sink == NULL)
417 g_error ("Missing cluttersink");
419 g_object_set (priv->video_output_sink, "texture", priv->video_output, NULL);
421 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
424 gtk_widget_add_events (priv->video_container,
425 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
426 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
427 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
431 create_video_input (EmpathyCallWindow *self)
433 EmpathyCallWindowPriv *priv = GET_PRIV (self);
435 g_assert (priv->video_input == NULL);
436 priv->video_input = empathy_video_src_new ();
437 gst_object_ref_sink (priv->video_input);
441 audio_control_volume_to_element (GBinding *binding,
442 const GValue *source_value,
443 GValue *target_value,
446 /* AudioControl volume is 0-255, with -1 for unknown */
449 hv = g_value_get_int (source_value);
454 g_value_set_double (target_value, hv/255.0);
460 element_volume_to_audio_control (GBinding *binding,
461 const GValue *source_value,
462 GValue *target_value,
467 ev = g_value_get_double (source_value);
468 ev = CLAMP (ev, 0.0, 1.0);
470 g_value_set_int (target_value, ev * 255);
475 audio_input_mute_notify_cb (GObject *obj, GParamSpec *spec,
476 EmpathyCallWindow *self)
479 g_object_get (obj, "mute", &muted, NULL);
481 self->priv->muted = muted;
482 if (muted && self->priv->transitions)
483 clutter_state_set_state (self->priv->transitions, "fade-in");
487 gtk_image_set_from_icon_name (GTK_IMAGE (self->priv->microphone_icon),
488 EMPATHY_IMAGE_MIC_MUTED, GTK_ICON_SIZE_MENU);
492 gtk_image_set_from_icon_name (GTK_IMAGE (self->priv->microphone_icon),
493 EMPATHY_IMAGE_MIC, GTK_ICON_SIZE_MENU);
496 empathy_call_window_update_timer (self);
500 create_audio_input (EmpathyCallWindow *self)
502 EmpathyCallWindowPriv *priv = GET_PRIV (self);
504 g_assert (priv->audio_input == NULL);
505 priv->audio_input = empathy_audio_src_new ();
506 gst_object_ref_sink (priv->audio_input);
508 g_signal_connect (priv->audio_input, "notify::mute",
509 G_CALLBACK (audio_input_mute_notify_cb), self);
513 add_video_preview_to_pipeline (EmpathyCallWindow *self)
515 EmpathyCallWindowPriv *priv = GET_PRIV (self);
518 g_assert (priv->video_preview != NULL);
519 g_assert (priv->pipeline != NULL);
520 g_assert (priv->video_input != NULL);
521 g_assert (priv->video_tee != NULL);
523 preview = priv->video_preview_sink;
525 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
527 g_warning ("Could not add video input to pipeline");
531 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
533 g_warning ("Could not add video preview to pipeline");
537 if (!gst_element_link (priv->video_input, priv->video_tee))
539 g_warning ("Could not link video input to video tee");
543 if (!gst_element_link (priv->video_tee, preview))
545 g_warning ("Could not link video tee to video preview");
551 empathy_call_window_disable_camera_cb (GtkAction *action,
552 EmpathyCallWindow *self)
554 clutter_actor_destroy (self->priv->preview_hidden_button);
556 gtk_toggle_button_set_active (
557 GTK_TOGGLE_BUTTON (self->priv->camera_button), FALSE);
561 empathy_call_window_minimise_camera_cb (GtkAction *action,
562 EmpathyCallWindow *self)
564 clutter_actor_hide (self->priv->video_preview);
565 clutter_actor_show (self->priv->preview_hidden_button);
569 empathy_call_window_maximise_camera_cb (GtkAction *action,
570 EmpathyCallWindow *self)
572 clutter_actor_show (self->priv->video_preview);
573 clutter_actor_hide (self->priv->preview_hidden_button);
577 empathy_call_window_swap_camera_cb (GtkAction *action,
578 EmpathyCallWindow *self)
580 const GList *cameras, *l;
583 DEBUG ("Swapping the camera");
585 cameras = empathy_camera_monitor_get_cameras (self->priv->camera_monitor);
586 current_cam = empathy_video_src_dup_device (
587 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
589 for (l = cameras; l != NULL; l = l->next)
591 EmpathyCamera *camera = l->data;
593 if (!tp_strdiff (camera->device, current_cam))
598 next = l->next->data;
600 next = cameras->data;
602 /* EmpathyCameraMenu will update itself and do the actual change
604 g_settings_set_string (self->priv->settings,
605 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
612 g_free (current_cam);
616 empathy_call_window_camera_added_cb (EmpathyCameraMonitor *monitor,
617 EmpathyCamera *camera,
618 EmpathyCallWindow *self)
620 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
622 gtk_action_set_visible (self->priv->menu_swap_camera,
623 g_list_length ((GList *) cameras) >= 2);
627 empathy_call_window_camera_removed_cb (EmpathyCameraMonitor *monitor,
628 EmpathyCamera *camera,
629 EmpathyCallWindow *self)
631 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
633 gtk_action_set_visible (self->priv->menu_swap_camera,
634 g_list_length ((GList *) cameras) >= 2);
638 empathy_call_window_preview_button_clicked_cb (ClutterClickAction *action,
640 EmpathyCallWindow *self)
644 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
646 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
647 0, gtk_get_current_event_time ());
648 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
652 empathy_call_window_preview_hidden_button_clicked_cb (
653 ClutterClickAction *action,
655 EmpathyCallWindow *self)
659 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
660 "/preview-hidden-menu");
661 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
662 0, gtk_get_current_event_time ());
663 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
666 static ClutterActor *
667 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
668 ClutterBinAlignment x,
669 ClutterBinAlignment y)
671 ClutterActor *rectangle;
673 rectangle = CLUTTER_ACTOR (empathy_rounded_rectangle_new (
674 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT,
675 PREVIEW_ROUND_FACTOR));
677 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->preview_layout),
679 clutter_actor_hide (rectangle);
685 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
689 self->priv->preview_layout = clutter_bin_layout_new (
690 CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_CENTER);
691 self->priv->preview_box = box = clutter_box_new (self->priv->preview_layout);
693 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->overlay_layout),
695 CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL);
697 self->priv->preview_rectangle1 =
698 empathy_call_window_create_preview_rectangle (self,
699 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
700 self->priv->preview_rectangle2 =
701 empathy_call_window_create_preview_rectangle (self,
702 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
703 self->priv->preview_rectangle3 =
704 empathy_call_window_create_preview_rectangle (self,
705 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
706 self->priv->preview_rectangle4 =
707 empathy_call_window_create_preview_rectangle (self,
708 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
712 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
715 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
716 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
717 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
718 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
722 empathy_call_window_get_preview_coordinates (EmpathyCallWindow *self,
727 guint ret_x = 0, ret_y = 0;
730 if (!clutter_actor_has_allocation (self->priv->preview_box))
733 clutter_actor_get_geometry (self->priv->preview_box, &box);
737 case PREVIEW_POS_TOP_LEFT:
738 ret_x = ret_y = SELF_VIDEO_SECTION_MARGIN;
740 case PREVIEW_POS_TOP_RIGHT:
741 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
742 - SELF_VIDEO_SECTION_WIDTH;
743 ret_y = SELF_VIDEO_SECTION_MARGIN;
745 case PREVIEW_POS_BOTTOM_LEFT:
746 ret_x = SELF_VIDEO_SECTION_MARGIN;
747 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
748 - SELF_VIDEO_SECTION_HEIGHT;
750 case PREVIEW_POS_BOTTOM_RIGHT:
751 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
752 - SELF_VIDEO_SECTION_WIDTH;
753 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
754 - SELF_VIDEO_SECTION_HEIGHT;
757 g_warn_if_reached ();
768 static PreviewPosition
769 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
774 PreviewPosition pos = PREVIEW_POS_NONE;
776 if (!clutter_actor_has_allocation (self->priv->preview_box))
779 clutter_actor_get_geometry (self->priv->preview_box, &box);
781 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
782 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
783 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
784 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
786 pos = PREVIEW_POS_TOP_LEFT;
788 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
789 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
790 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
791 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
793 pos = PREVIEW_POS_TOP_RIGHT;
795 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
796 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
797 box.height - SELF_VIDEO_SECTION_MARGIN >= event_y &&
798 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
800 pos = PREVIEW_POS_BOTTOM_LEFT;
802 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
803 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
804 box.height - 2 * SELF_VIDEO_SECTION_MARGIN >= event_y &&
805 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_HEIGHT))
807 pos = PREVIEW_POS_BOTTOM_RIGHT;
813 static ClutterActor *
814 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
817 ClutterActor *rectangle;
821 case PREVIEW_POS_TOP_LEFT:
822 rectangle = self->priv->preview_rectangle1;
824 case PREVIEW_POS_TOP_RIGHT:
825 rectangle = self->priv->preview_rectangle3;
827 case PREVIEW_POS_BOTTOM_LEFT:
828 rectangle = self->priv->preview_rectangle2;
830 case PREVIEW_POS_BOTTOM_RIGHT:
831 rectangle = self->priv->preview_rectangle4;
841 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
844 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->preview_layout);
846 DEBUG ("moving the video preview to %d", pos);
848 self->priv->preview_pos = pos;
852 case PREVIEW_POS_TOP_LEFT:
853 clutter_bin_layout_set_alignment (layout,
854 self->priv->video_preview,
855 CLUTTER_BIN_ALIGNMENT_START,
856 CLUTTER_BIN_ALIGNMENT_START);
858 case PREVIEW_POS_TOP_RIGHT:
859 clutter_bin_layout_set_alignment (layout,
860 self->priv->video_preview,
861 CLUTTER_BIN_ALIGNMENT_END,
862 CLUTTER_BIN_ALIGNMENT_START);
864 case PREVIEW_POS_BOTTOM_LEFT:
865 clutter_bin_layout_set_alignment (layout,
866 self->priv->video_preview,
867 CLUTTER_BIN_ALIGNMENT_START,
868 CLUTTER_BIN_ALIGNMENT_END);
870 case PREVIEW_POS_BOTTOM_RIGHT:
871 clutter_bin_layout_set_alignment (layout,
872 self->priv->video_preview,
873 CLUTTER_BIN_ALIGNMENT_END,
874 CLUTTER_BIN_ALIGNMENT_END);
877 g_warn_if_reached ();
880 g_settings_set_enum (self->priv->settings, "camera-position", pos);
884 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
887 ClutterActor *rectangle;
888 ClutterColor white = { 0xff, 0xff, 0xff, 0xff};
890 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
892 empathy_rounded_rectangle_set_border_width (
893 EMPATHY_ROUNDED_RECTANGLE (rectangle), 2 * SELF_VIDEO_SECTION_MARGIN);
894 empathy_rounded_rectangle_set_border_color (
895 EMPATHY_ROUNDED_RECTANGLE (rectangle), &white);
899 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
900 ClutterActor *rectangle)
902 ClutterColor white = { 0xff, 0xff, 0xff, 0xff}, darker;
904 clutter_color_shade (&white, 0.55, &darker);
906 empathy_rounded_rectangle_set_border_width (
907 EMPATHY_ROUNDED_RECTANGLE (rectangle), 1);
908 empathy_rounded_rectangle_set_border_color (
909 EMPATHY_ROUNDED_RECTANGLE (rectangle), &darker);
913 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
915 ClutterActor *rectangle;
917 rectangle = empathy_call_window_get_preview_rectangle (self,
918 self->priv->preview_pos);
920 /* We don't want to darken the rectangle where the preview
923 if (self->priv->preview_rectangle1 != rectangle)
924 empathy_call_window_darken_preview_rectangle (self,
925 self->priv->preview_rectangle1);
927 if (self->priv->preview_rectangle2 != rectangle)
928 empathy_call_window_darken_preview_rectangle (self,
929 self->priv->preview_rectangle2);
931 if (self->priv->preview_rectangle3 != rectangle)
932 empathy_call_window_darken_preview_rectangle (self,
933 self->priv->preview_rectangle3);
935 if (self->priv->preview_rectangle4 != rectangle)
936 empathy_call_window_darken_preview_rectangle (self,
937 self->priv->preview_rectangle4);
941 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
945 ClutterModifierType modifiers,
946 EmpathyCallWindow *self)
948 ClutterActor *stage = clutter_actor_get_stage (actor);
951 self->priv->drag_preview = clutter_clone_new (actor);
953 clutter_container_add_actor (CLUTTER_CONTAINER (stage),
954 self->priv->drag_preview);
956 clutter_actor_transform_stage_point (actor, event_x, event_y,
959 clutter_actor_set_position (self->priv->drag_preview,
960 event_x - rel_x, event_y - rel_y);
962 clutter_drag_action_set_drag_handle (action,
963 self->priv->drag_preview);
965 clutter_actor_set_opacity (actor, 0);
966 clutter_actor_hide (self->priv->preview_shown_button);
968 empathy_call_window_show_preview_rectangles (self, TRUE);
969 empathy_call_window_darken_preview_rectangles (self);
973 empathy_call_window_on_animation_completed_cb (ClutterAnimation *animation,
976 clutter_actor_set_opacity (actor, 255);
980 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
984 ClutterModifierType modifiers,
985 EmpathyCallWindow *self)
990 /* Get the position before destroying the drag actor, otherwise the
991 * preview_box allocation won't be valid and we won't be able to
992 * calculate the position. */
993 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
995 empathy_call_window_get_preview_coordinates (self,
996 pos != PREVIEW_POS_NONE ? pos : self->priv->preview_pos,
999 /* Move the preview to the destination and destroy it afterwards */
1000 clutter_actor_animate (self->priv->drag_preview, CLUTTER_LINEAR, 500,
1003 "signal-swapped-after::completed",
1004 clutter_actor_destroy, self->priv->drag_preview,
1005 "signal-swapped-after::completed",
1006 clutter_actor_show, self->priv->preview_shown_button,
1007 "signal::completed",
1008 empathy_call_window_on_animation_completed_cb, actor,
1011 self->priv->drag_preview = NULL;
1013 if (pos != PREVIEW_POS_NONE)
1014 empathy_call_window_move_video_preview (self, pos);
1016 empathy_call_window_show_preview_rectangles (self, FALSE);
1020 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
1021 ClutterActor *actor,
1024 EmpathyCallWindow *self)
1026 PreviewPosition pos;
1027 gfloat event_x, event_y;
1029 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
1031 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
1033 if (pos != PREVIEW_POS_NONE)
1034 empathy_call_window_highlight_preview_rectangle (self, pos);
1036 empathy_call_window_darken_preview_rectangles (self);
1040 empathy_call_window_preview_enter_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_highlight_preview_rectangle (self,
1050 self->priv->preview_pos);
1052 clutter_actor_show (rectangle);
1058 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
1059 ClutterCrossingEvent *event,
1060 EmpathyCallWindow *self)
1062 ClutterActor *rectangle;
1064 rectangle = empathy_call_window_get_preview_rectangle (self,
1065 self->priv->preview_pos);
1067 empathy_call_window_darken_preview_rectangle (self, rectangle);
1069 clutter_actor_hide (rectangle);
1075 create_video_preview (EmpathyCallWindow *self)
1077 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1078 ClutterLayoutManager *layout;
1079 ClutterActor *preview;
1081 ClutterAction *action;
1082 PreviewPosition pos;
1084 g_assert (priv->video_preview == NULL);
1086 pos = g_settings_get_enum (priv->settings, "camera-position");
1088 preview = empathy_rounded_texture_new ();
1089 clutter_actor_set_size (preview,
1090 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1092 priv->video_preview_sink = gst_element_factory_make ("cluttersink", NULL);
1093 if (priv->video_preview_sink == NULL)
1094 g_error ("Missing cluttersink, check your clutter-gst installation");
1095 g_object_set (priv->video_preview_sink, "texture", preview, NULL);
1096 g_object_add_weak_pointer (G_OBJECT (priv->video_preview_sink), (gpointer) &priv->video_preview_sink);
1098 /* Add a little offset to the video preview */
1099 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1100 CLUTTER_BIN_ALIGNMENT_CENTER);
1101 priv->video_preview = clutter_box_new (layout);
1102 clutter_actor_set_size (priv->video_preview,
1103 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1104 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1106 /* Spinner for when changing the camera device */
1107 priv->preview_spinner_widget = gtk_spinner_new ();
1108 priv->preview_spinner_actor = empathy_rounded_actor_new (PREVIEW_ROUND_FACTOR);
1110 g_object_set (priv->preview_spinner_widget, "expand", TRUE, NULL);
1111 make_background_transparent (GTK_CLUTTER_ACTOR (priv->preview_spinner_actor));
1112 gtk_widget_show (priv->preview_spinner_widget);
1115 GTK_CONTAINER (gtk_clutter_actor_get_widget (
1116 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor))),
1117 priv->preview_spinner_widget);
1118 clutter_actor_set_size (priv->preview_spinner_actor,
1119 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1120 clutter_actor_set_opacity (priv->preview_spinner_actor, 128);
1121 clutter_actor_hide (priv->preview_spinner_actor);
1123 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1125 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview),
1126 priv->preview_spinner_actor);
1128 g_object_set (priv->video_preview_sink,
1134 priv->preview_shown_button = b = gtk_clutter_actor_new_with_contents (
1135 gtk_image_new_from_icon_name ("emblem-system-symbolic",
1136 GTK_ICON_SIZE_MENU));
1137 clutter_actor_set_margin_right (b, 4);
1138 clutter_actor_set_margin_bottom (b, 2);
1139 clutter_actor_set_opacity (b, PREVIEW_BUTTON_OPACITY);
1140 make_background_transparent (GTK_CLUTTER_ACTOR (b));
1142 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (layout), b,
1143 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
1145 action = clutter_click_action_new ();
1146 clutter_actor_add_action (b, action);
1147 g_signal_connect (action, "clicked",
1148 G_CALLBACK (empathy_call_window_preview_button_clicked_cb), self);
1150 /* Preview hidden */
1151 priv->preview_hidden_button = b = gtk_clutter_actor_new_with_contents (
1152 gtk_image_new_from_icon_name ("emblem-system-symbolic",
1153 GTK_ICON_SIZE_MENU));
1154 make_background_transparent (GTK_CLUTTER_ACTOR (b));
1156 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1157 priv->preview_hidden_button,
1158 CLUTTER_BIN_ALIGNMENT_START,
1159 CLUTTER_BIN_ALIGNMENT_END);
1161 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1163 clutter_actor_hide (priv->preview_hidden_button);
1165 action = clutter_click_action_new ();
1166 clutter_actor_add_action (b, action);
1167 g_signal_connect (action, "clicked",
1168 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb), self);
1170 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->preview_layout),
1171 priv->video_preview,
1172 CLUTTER_BIN_ALIGNMENT_START,
1173 CLUTTER_BIN_ALIGNMENT_END);
1175 empathy_call_window_move_video_preview (self, pos);
1177 action = clutter_drag_action_new ();
1178 g_signal_connect (action, "drag-begin",
1179 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1180 g_signal_connect (action, "drag-end",
1181 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1182 g_signal_connect (action, "drag-motion",
1183 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1185 g_signal_connect (preview, "enter-event",
1186 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1187 g_signal_connect (preview, "leave-event",
1188 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1190 clutter_actor_add_action (preview, action);
1191 clutter_actor_set_reactive (preview, TRUE);
1192 clutter_actor_set_reactive (priv->preview_shown_button, TRUE);
1196 empathy_call_window_start_camera_spinning (EmpathyCallWindow *self)
1198 clutter_actor_show (self->priv->preview_spinner_actor);
1199 gtk_spinner_start (GTK_SPINNER (self->priv->preview_spinner_widget));
1203 empathy_call_window_stop_camera_spinning (EmpathyCallWindow *self)
1205 clutter_actor_hide (self->priv->preview_spinner_actor);
1206 gtk_spinner_stop (GTK_SPINNER (self->priv->preview_spinner_widget));
1210 empathy_call_window_play_camera (EmpathyCallWindow *self,
1213 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1214 GstElement *preview;
1217 if (priv->video_preview == NULL)
1219 create_video_preview (self);
1220 add_video_preview_to_pipeline (self);
1225 state = GST_STATE_PLAYING;
1229 empathy_call_window_start_camera_spinning (self);
1230 state = GST_STATE_NULL;
1233 preview = priv->video_preview_sink;
1235 gst_element_set_state (preview, state);
1236 gst_element_set_state (priv->video_tee, state);
1237 gst_element_set_state (priv->video_input, state);
1241 display_video_preview (EmpathyCallWindow *self,
1244 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1246 if (priv->video_preview == NULL)
1248 create_video_preview (self);
1249 add_video_preview_to_pipeline (self);
1254 /* Display the video preview */
1255 DEBUG ("Show video preview");
1257 empathy_call_window_play_camera (self, TRUE);
1258 clutter_actor_show (priv->video_preview);
1259 clutter_actor_raise_top (priv->floating_toolbar);
1263 /* Hide the video preview */
1264 DEBUG ("Hide video preview");
1266 if (priv->video_preview != NULL)
1268 clutter_actor_hide (priv->video_preview);
1269 empathy_call_window_play_camera (self, FALSE);
1275 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1277 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1279 empathy_call_window_status_message (window, _("Connecting…"));
1280 priv->call_state = CONNECTING;
1282 /* Show the toolbar */
1283 clutter_state_set_state (priv->transitions, "fade-in");
1286 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1287 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1291 disable_camera (EmpathyCallWindow *self)
1293 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1295 if (priv->camera_state == CAMERA_STATE_OFF)
1298 DEBUG ("Disable camera");
1300 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1302 priv->camera_state = CAMERA_STATE_OFF;
1306 enable_camera (EmpathyCallWindow *self)
1308 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1310 if (priv->camera_state == CAMERA_STATE_ON)
1313 if (priv->video_input == NULL)
1315 DEBUG ("Can't enable camera, no input");
1319 DEBUG ("Enable camera");
1321 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1323 priv->camera_state = CAMERA_STATE_ON;
1327 empathy_call_window_camera_toggled_cb (GtkToggleButton *toggle,
1328 EmpathyCallWindow *self)
1330 if (gtk_toggle_button_get_active (toggle))
1331 enable_camera (self);
1333 disable_camera (self);
1337 create_pipeline (EmpathyCallWindow *self)
1339 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1342 g_assert (priv->pipeline == NULL);
1344 priv->pipeline = gst_pipeline_new (NULL);
1345 priv->pipeline_playing = FALSE;
1347 priv->video_tee = gst_element_factory_make ("tee", NULL);
1348 gst_object_ref_sink (priv->video_tee);
1350 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1352 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1353 priv->bus_message_source_id = gst_bus_add_watch (bus,
1354 empathy_call_window_bus_message, self);
1356 g_object_unref (bus);
1360 empathy_call_window_settings_cb (GtkAction *action,
1361 EmpathyCallWindow *self)
1363 gchar *args = g_strdup_printf ("-p %s",
1364 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1366 empathy_launch_program (BIN_DIR, "empathy", args);
1372 empathy_call_window_contents_cb (GtkAction *action,
1373 EmpathyCallWindow *self)
1375 empathy_url_show (GTK_WIDGET (self), "help:empathy/audio-video");
1379 show_png (GPid pid, gint status, gpointer user_data)
1381 gtk_show_uri (NULL, (gchar *) user_data, GDK_CURRENT_TIME, NULL);
1382 g_spawn_close_pid (pid);
1387 empathy_call_window_debug_gst_cb (GtkAction *action,
1388 EmpathyCallWindow *self)
1390 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1391 GDateTime *date_time;
1393 const gchar *dot_dir;
1394 const gchar *prgname;
1400 if (priv->pipeline == NULL)
1401 DEBUG ("No pipeline");
1403 date_time = g_date_time_new_now_utc ();
1404 prgname = g_get_prgname ();
1405 filename = g_strdup_printf ("%s-%" G_GINT64_FORMAT, prgname,
1406 g_date_time_to_unix (date_time));
1408 GST_DEBUG_BIN_TO_DOT_FILE (GST_BIN (priv->pipeline),
1409 GST_DEBUG_GRAPH_SHOW_ALL, filename);
1411 dot_dir = g_getenv ("GST_DEBUG_DUMP_DOT_DIR");
1412 dot_cmd = g_strdup_printf ("dot -Tpng -o %s.png %s.dot",
1415 g_shell_parse_argv (dot_cmd, &argc, &argv, NULL);
1417 if (g_spawn_async (dot_dir,
1420 G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
1426 gchar *uri = g_strdup_printf ("file://%s/%s.png", dot_dir, filename);
1427 g_child_watch_add (dot_pid, show_png, uri);
1433 g_date_time_unref (date_time);
1437 empathy_call_window_debug_tp_cb (GtkAction *action,
1438 EmpathyCallWindow *self)
1440 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1444 empathy_call_window_about_cb (GtkAction *action,
1445 EmpathyCallWindow *self)
1447 empathy_about_dialog_new (GTK_WINDOW (self));
1451 empathy_call_window_toolbar_timeout (gpointer data)
1453 EmpathyCallWindow *self = data;
1455 /* We don't want to hide the toolbar if we're not in a call, as
1456 * to show the call status all the time. Also don't hide if we're muted
1457 * to prevent the awkward, talking when muted situation */
1458 if (self->priv->call_state != CONNECTING &&
1459 self->priv->call_state != DISCONNECTED &&
1461 clutter_state_set_state (self->priv->transitions, "fade-out");
1467 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1469 EmpathyCallWindow *self)
1471 clutter_state_set_state (self->priv->transitions, "fade-in");
1473 if (self->priv->inactivity_src > 0)
1474 g_source_remove (self->priv->inactivity_src);
1476 self->priv->inactivity_src = g_timeout_add_seconds (3,
1477 empathy_call_window_toolbar_timeout, self);
1483 empathy_call_window_configure_event_cb (GtkWidget *widget,
1485 EmpathyCallWindow *self)
1487 GdkWindow *gdk_window;
1488 GdkWindowState window_state;
1490 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1491 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1493 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1494 &self->priv->dialpad_width, NULL);
1496 gdk_window = gtk_widget_get_window (widget);
1497 window_state = gdk_window_get_state (gdk_window);
1498 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1504 empathy_call_window_destroyed_cb (GtkWidget *object,
1505 EmpathyCallWindow *self)
1507 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1509 /* Save the geometry as if the dialpad was hidden. */
1510 empathy_geometry_save_values (GTK_WINDOW (self),
1511 self->priv->x, self->priv->y,
1512 self->priv->w - self->priv->dialpad_width, self->priv->h,
1513 self->priv->maximized);
1518 empathy_call_window_incoming_call_response_cb (GtkDialog *dialog,
1520 EmpathyCallWindow *self)
1522 switch (response_id)
1524 case GTK_RESPONSE_ACCEPT:
1525 tp_channel_dispatch_operation_handle_with_async (
1526 self->priv->pending_cdo, EMPATHY_CALL_BUS_NAME, NULL, NULL);
1528 tp_clear_object (&self->priv->pending_cdo);
1529 tp_clear_object (&self->priv->pending_channel);
1530 tp_clear_object (&self->priv->pending_context);
1533 case GTK_RESPONSE_CANCEL:
1534 tp_channel_dispatch_operation_close_channels_async (
1535 self->priv->pending_cdo, NULL, NULL);
1537 empathy_call_window_status_message (self, _("Disconnected"));
1538 self->priv->call_state = DISCONNECTED;
1541 g_warn_if_reached ();
1546 empathy_call_window_set_state_ringing (EmpathyCallWindow *self)
1550 g_assert (self->priv->call_state != CONNECTED);
1552 video = tp_call_channel_has_initial_video (self->priv->pending_channel, NULL);
1554 empathy_call_window_status_message (self, _("Incoming call"));
1555 self->priv->call_state = RINGING;
1557 self->priv->incoming_call_dialog = gtk_message_dialog_new (
1558 GTK_WINDOW (self), GTK_DIALOG_MODAL,
1559 GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
1560 video ? _("Incoming video call from %s") : _("Incoming call from %s"),
1561 empathy_contact_get_alias (self->priv->contact));
1563 gtk_dialog_add_buttons (GTK_DIALOG (self->priv->incoming_call_dialog),
1564 _("Reject"), GTK_RESPONSE_CANCEL,
1565 _("Answer"), GTK_RESPONSE_ACCEPT,
1568 g_signal_connect (self->priv->incoming_call_dialog, "response",
1569 G_CALLBACK (empathy_call_window_incoming_call_response_cb), self);
1570 gtk_widget_show (self->priv->incoming_call_dialog);
1574 empathy_call_window_cdo_invalidated_cb (TpProxy *channel,
1578 EmpathyCallWindow *self)
1580 tp_clear_object (&self->priv->pending_cdo);
1581 tp_clear_object (&self->priv->pending_channel);
1582 tp_clear_object (&self->priv->pending_context);
1584 /* We don't know if the incoming call has been accepted or not, so we
1585 * assume it hasn't and if it has, we'll set the proper status when
1586 * we get the new handler. */
1587 empathy_call_window_status_message (self, _("Disconnected"));
1588 self->priv->call_state = DISCONNECTED;
1590 gtk_widget_destroy (self->priv->incoming_call_dialog);
1591 self->priv->incoming_call_dialog = NULL;
1595 empathy_call_window_start_ringing (EmpathyCallWindow *self,
1596 TpCallChannel *channel,
1597 TpChannelDispatchOperation *dispatch_operation,
1598 TpAddDispatchOperationContext *context)
1600 g_assert (self->priv->pending_channel == NULL);
1601 g_assert (self->priv->pending_context == NULL);
1602 g_assert (self->priv->pending_cdo == NULL);
1604 /* Start ringing and delay until the user answers or hangs. */
1605 self->priv->pending_channel = g_object_ref (channel);
1606 self->priv->pending_context = g_object_ref (context);
1607 self->priv->pending_cdo = g_object_ref (dispatch_operation);
1609 g_signal_connect (self->priv->pending_cdo, "invalidated",
1610 G_CALLBACK (empathy_call_window_cdo_invalidated_cb), self);
1612 empathy_call_window_set_state_ringing (self);
1613 tp_add_dispatch_operation_context_accept (context);
1617 mic_button_clicked (GtkWidget *button,
1618 EmpathyCallWindow *self)
1620 /* Toggle the muted state. We rely on audio_input_mute_notify_cb to update
1622 empathy_audio_src_set_mute (EMPATHY_GST_AUDIO_SRC (self->priv->audio_input),
1623 !self->priv->muted);
1627 empathy_call_window_init (EmpathyCallWindow *self)
1629 EmpathyCallWindowPriv *priv;
1631 GtkWidget *top_vbox;
1633 ClutterConstraint *constraint;
1634 ClutterActor *remote_avatar;
1635 ClutterColor black = { 0, 0, 0, 0 };
1636 ClutterMargin overlay_margin = { OVERLAY_MARGIN, OVERLAY_MARGIN,
1637 OVERLAY_MARGIN, OVERLAY_MARGIN };
1639 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1640 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1642 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1643 priv->timer = g_timer_new ();
1645 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1646 gui = empathy_builder_get_file (filename,
1647 "call_window_vbox", &top_vbox,
1648 "errors_vbox", &priv->errors_vbox,
1649 "pane", &priv->pane,
1650 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1651 "remote_user_status_toolbar", &priv->remote_user_status_toolbar,
1652 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1653 "status_label", &priv->status_label,
1654 "audiocall", &priv->audio_call_button,
1655 "videocall", &priv->video_call_button,
1656 "microphone", &priv->mic_button,
1657 "microphone_icon", &priv->microphone_icon,
1658 "volume", &priv->volume_button,
1659 "camera", &priv->camera_button,
1660 "hangup", &priv->hangup_button,
1661 "dialpad", &priv->dialpad_button,
1662 "toolbar", &priv->toolbar,
1663 "bottom_toolbar", &priv->bottom_toolbar,
1664 "ui_manager", &priv->ui_manager,
1665 "menufullscreen", &priv->menu_fullscreen,
1666 "menupreviewswap", &priv->menu_swap_camera,
1667 "details_vbox", &priv->details_vbox,
1668 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1669 "acodec_encoding_label", &priv->acodec_encoding_label,
1670 "acodec_decoding_label", &priv->acodec_decoding_label,
1671 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1672 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1673 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1674 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1675 "video_local_candidate_label", &priv->video_local_candidate_label,
1676 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1677 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1678 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1679 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1683 empathy_builder_connect (gui, self,
1684 "hangup", "clicked", empathy_call_window_hangup_cb,
1685 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1686 "videocall", "clicked", empathy_call_window_video_call_cb,
1687 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1688 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1689 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1690 "menusettings", "activate", empathy_call_window_settings_cb,
1691 "menucontents", "activate", empathy_call_window_contents_cb,
1692 "menudebuggst", "activate", empathy_call_window_debug_gst_cb,
1693 "menudebugtp", "activate", empathy_call_window_debug_tp_cb,
1694 "menuabout", "activate", empathy_call_window_about_cb,
1695 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1696 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1697 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1698 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1701 empathy_set_css_provider (GTK_WIDGET (self));
1702 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1704 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1706 g_object_bind_property (priv->camera_monitor, "available",
1707 priv->camera_button, "sensitive",
1708 G_BINDING_SYNC_CREATE);
1710 g_signal_connect (priv->camera_monitor, "added",
1711 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1712 g_signal_connect (priv->camera_monitor, "removed",
1713 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1715 g_signal_connect (priv->mic_button, "clicked",
1716 G_CALLBACK (mic_button_clicked), self);
1718 g_mutex_init (&priv->lock);
1720 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1722 priv->content_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,
1723 CONTENT_HBOX_SPACING);
1724 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1727 /* main contents remote avatar/video box */
1728 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_FILL,
1729 CLUTTER_BIN_ALIGNMENT_FILL);
1731 priv->video_box = clutter_box_new (priv->video_layout);
1733 priv->video_container = gtk_clutter_embed_new ();
1735 gtk_widget_set_size_request (priv->video_container,
1736 REMOTE_VIDEO_DEFAULT_WIDTH, REMOTE_VIDEO_DEFAULT_HEIGHT);
1738 /* Set the background black */
1739 clutter_stage_set_color (
1740 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1741 GTK_CLUTTER_EMBED (priv->video_container))),
1744 clutter_container_add (
1745 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1746 GTK_CLUTTER_EMBED (priv->video_container))),
1750 constraint = clutter_bind_constraint_new (
1751 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1752 CLUTTER_BIND_SIZE, 0);
1753 clutter_actor_add_constraint (priv->video_box, constraint);
1755 priv->remote_user_avatar_widget = gtk_image_new ();
1756 remote_avatar = gtk_clutter_actor_new_with_contents (
1757 priv->remote_user_avatar_widget);
1758 make_background_transparent (GTK_CLUTTER_ACTOR (remote_avatar));
1760 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1763 /* create the overlay bin */
1764 priv->overlay_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1765 CLUTTER_BIN_ALIGNMENT_CENTER);
1766 priv->overlay_bin = clutter_actor_new ();
1767 clutter_actor_set_layout_manager (priv->overlay_bin, priv->overlay_layout);
1769 clutter_actor_set_margin (priv->overlay_bin, &overlay_margin);
1771 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1773 CLUTTER_BIN_ALIGNMENT_FILL, CLUTTER_BIN_ALIGNMENT_FILL);
1775 empathy_call_window_create_preview_rectangles (self);
1777 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1778 priv->video_container, TRUE, TRUE,
1779 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1781 create_pipeline (self);
1782 create_video_output_widget (self);
1783 create_audio_input (self);
1784 create_video_input (self);
1786 priv->floating_toolbar = gtk_clutter_actor_new ();
1787 clutter_actor_set_reactive (priv->floating_toolbar, TRUE);
1788 make_background_transparent (GTK_CLUTTER_ACTOR (priv->floating_toolbar));
1790 gtk_style_context_add_class (
1791 gtk_widget_get_style_context (GTK_WIDGET (priv->bottom_toolbar)),
1792 GTK_STYLE_CLASS_OSD);
1793 gtk_widget_reparent (priv->bottom_toolbar,
1794 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1796 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->overlay_layout),
1797 priv->floating_toolbar,
1798 CLUTTER_BIN_ALIGNMENT_CENTER, CLUTTER_BIN_ALIGNMENT_END);
1800 clutter_actor_raise_top (priv->floating_toolbar);
1802 /* Transitions for the floating toolbar */
1803 priv->transitions = clutter_state_new ();
1805 /* all transitions last for 2s */
1806 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1808 /* transition from any state to "fade-out" state */
1809 clutter_state_set (priv->transitions, NULL, "fade-out",
1810 priv->floating_toolbar,
1811 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1814 /* transition from any state to "fade-in" state */
1815 clutter_state_set (priv->transitions, NULL, "fade-in",
1816 priv->floating_toolbar,
1817 "opacity", CLUTTER_EASE_OUT_QUAD, 255,
1820 /* put the actor into the "fade-in" state with no animation */
1821 clutter_state_warp_to_state (priv->transitions, "fade-in");
1823 /* The call will be started as soon the pipeline is playing */
1824 priv->start_call_when_playing = TRUE;
1826 priv->dtmf_panel = empathy_dialpad_widget_new ();
1827 g_signal_connect (priv->dtmf_panel, "start-tone",
1828 G_CALLBACK (dtmf_start_tone_cb), self);
1830 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1833 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1836 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1838 gtk_widget_show_all (top_vbox);
1840 gtk_widget_hide (priv->dtmf_panel);
1841 gtk_widget_hide (priv->details_vbox);
1843 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1845 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1846 priv->video_container);
1848 /* We hide the bottom toolbar after 3s of inactivity and show it
1849 * again on mouse movement */
1850 priv->inactivity_src = g_timeout_add_seconds (3,
1851 empathy_call_window_toolbar_timeout, self);
1853 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1854 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1856 g_signal_connect (G_OBJECT (self), "realize",
1857 G_CALLBACK (empathy_call_window_realized_cb), self);
1859 g_signal_connect (G_OBJECT (self), "delete-event",
1860 G_CALLBACK (empathy_call_window_delete_cb), self);
1862 g_signal_connect (G_OBJECT (self), "window-state-event",
1863 G_CALLBACK (empathy_call_window_state_event_cb), self);
1865 g_signal_connect (G_OBJECT (self), "key-press-event",
1866 G_CALLBACK (empathy_call_window_key_press_cb), self);
1868 g_signal_connect (self, "motion-notify-event",
1869 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1871 g_object_ref (priv->ui_manager);
1872 g_object_unref (gui);
1874 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1875 priv->mic_menu = empathy_mic_menu_new (self);
1876 priv->camera_menu = empathy_camera_menu_new (self);
1878 empathy_call_window_show_hangup_button (self, TRUE);
1880 gtk_window_set_default_size (GTK_WINDOW (self), 580, 480);
1882 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1883 /* These signals are used to track the window position and save it
1884 * when the window is destroyed. We need to do this as we don't want
1885 * the window geometry to be saved with the dialpad taken into account. */
1886 g_signal_connect (self, "destroy",
1887 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1888 g_signal_connect (self, "configure-event",
1889 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1890 g_signal_connect (self, "window-state-event",
1891 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1893 /* Don't display labels in both toolbars */
1894 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1897 /* Instead of specifying a width and a height, we specify only one size. That's
1898 because we want a square avatar icon. */
1900 init_contact_avatar_with_size (EmpathyContact *contact,
1901 GtkWidget *image_widget,
1904 GdkPixbuf *pixbuf_avatar = NULL;
1906 if (contact != NULL)
1908 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1912 if (pixbuf_avatar == NULL)
1914 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1915 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1918 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1920 if (pixbuf_avatar != NULL)
1921 g_object_unref (pixbuf_avatar);
1925 set_window_title (EmpathyCallWindow *self)
1927 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1930 if (priv->contact != NULL)
1932 /* translators: Call is a noun and %s is the contact name. This string
1933 * is used in the window title */
1934 tmp = g_strdup_printf (_("Call with %s"),
1935 empathy_contact_get_alias (priv->contact));
1936 gtk_window_set_title (GTK_WINDOW (self), tmp);
1941 g_warning ("Unknown remote contact!");
1946 set_remote_user_name (EmpathyCallWindow *self,
1947 EmpathyContact *contact)
1949 const gchar *alias = empathy_contact_get_alias (contact);
1950 const gchar *status = empathy_contact_get_status (contact);
1952 gtk_label_set_text (GTK_LABEL (self->priv->remote_user_name_toolbar), alias);
1954 if (status != NULL) {
1957 markup = g_markup_printf_escaped ("<small>%s</small>", status);
1958 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_status_toolbar),
1962 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_status_toolbar),
1968 contact_name_changed_cb (EmpathyContact *contact,
1970 EmpathyCallWindow *self)
1972 set_window_title (self);
1973 set_remote_user_name (self, contact);
1977 contact_presence_changed_cb (EmpathyContact *contact,
1979 EmpathyCallWindow *self)
1981 set_remote_user_name (self, contact);
1985 contact_avatar_changed_cb (EmpathyContact *contact,
1987 EmpathyCallWindow *self)
1990 GtkAllocation allocation;
1991 GtkWidget *avatar_widget;
1993 avatar_widget = self->priv->remote_user_avatar_widget;
1995 gtk_widget_get_allocation (avatar_widget, &allocation);
1996 size = allocation.height;
2000 /* the widget is not allocated yet, set a default size */
2001 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
2002 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
2005 init_contact_avatar_with_size (contact, avatar_widget, size);
2007 avatar_widget = self->priv->remote_user_avatar_toolbar;
2009 gtk_widget_get_allocation (avatar_widget, &allocation);
2010 size = allocation.height;
2014 /* the widget is not allocated yet, set a default size */
2015 size = SMALL_TOOLBAR_SIZE;
2018 init_contact_avatar_with_size (contact, avatar_widget, size);
2022 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
2023 EmpathyCallHandler *handler)
2025 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2027 tp_g_signal_connect_object (priv->contact, "notify::name",
2028 G_CALLBACK (contact_name_changed_cb), self, 0);
2029 tp_g_signal_connect_object (priv->contact, "notify::avatar",
2030 G_CALLBACK (contact_avatar_changed_cb), self, 0);
2031 tp_g_signal_connect_object (priv->contact, "notify::presence",
2032 G_CALLBACK (contact_presence_changed_cb), self, 0);
2034 set_window_title (self);
2035 set_remote_user_name (self, priv->contact);
2037 init_contact_avatar_with_size (priv->contact,
2038 priv->remote_user_avatar_widget,
2039 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
2040 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
2042 init_contact_avatar_with_size (priv->contact,
2043 priv->remote_user_avatar_toolbar,
2044 SMALL_TOOLBAR_SIZE);
2046 /* The remote avatar is shown by default and will be hidden when we receive
2047 video from the remote side. */
2048 clutter_actor_hide (priv->video_output);
2049 gtk_widget_show (priv->remote_user_avatar_widget);
2053 update_send_codec (EmpathyCallWindow *self,
2056 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2063 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
2064 widget = priv->acodec_encoding_label;
2068 codec = empathy_call_handler_get_send_video_codec (priv->handler);
2069 widget = priv->vcodec_encoding_label;
2075 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
2076 gtk_label_set_text (GTK_LABEL (widget), tmp);
2081 send_audio_codec_notify_cb (GObject *object,
2085 EmpathyCallWindow *self = user_data;
2087 update_send_codec (self, TRUE);
2091 send_video_codec_notify_cb (GObject *object,
2095 EmpathyCallWindow *self = user_data;
2097 update_send_codec (self, FALSE);
2101 update_recv_codec (EmpathyCallWindow *self,
2104 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2107 GString *str = NULL;
2111 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
2112 widget = priv->acodec_decoding_label;
2116 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
2117 widget = priv->vcodec_decoding_label;
2123 for (l = codecs; l != NULL; l = g_list_next (l))
2125 FsCodec *codec = l->data;
2128 str = g_string_new (NULL);
2130 g_string_append (str, ", ");
2132 g_string_append_printf (str, "%s/%u", codec->encoding_name,
2136 gtk_label_set_text (GTK_LABEL (widget), str->str);
2137 g_string_free (str, TRUE);
2141 recv_audio_codecs_notify_cb (GObject *object,
2145 EmpathyCallWindow *self = user_data;
2147 update_recv_codec (self, TRUE);
2151 recv_video_codecs_notify_cb (GObject *object,
2155 EmpathyCallWindow *self = user_data;
2157 update_recv_codec (self, FALSE);
2160 static const gchar *
2161 candidate_type_to_str (FsCandidate *candidate)
2163 switch (candidate->type)
2165 case FS_CANDIDATE_TYPE_HOST:
2167 case FS_CANDIDATE_TYPE_SRFLX:
2168 return "server reflexive";
2169 case FS_CANDIDATE_TYPE_PRFLX:
2170 return "peer reflexive";
2171 case FS_CANDIDATE_TYPE_RELAY:
2173 case FS_CANDIDATE_TYPE_MULTICAST:
2180 static const gchar *
2181 candidate_type_to_desc (FsCandidate *candidate)
2183 switch (candidate->type)
2185 case FS_CANDIDATE_TYPE_HOST:
2186 return _("The IP address as seen by the machine");
2187 case FS_CANDIDATE_TYPE_SRFLX:
2188 return _("The IP address as seen by a server on the Internet");
2189 case FS_CANDIDATE_TYPE_PRFLX:
2190 return _("The IP address of the peer as seen by the other side");
2191 case FS_CANDIDATE_TYPE_RELAY:
2192 return _("The IP address of a relay server");
2193 case FS_CANDIDATE_TYPE_MULTICAST:
2194 return _("The IP address of the multicast group");
2201 update_candidat_widget (EmpathyCallWindow *self,
2204 FsCandidate *candidate)
2208 g_assert (candidate != NULL);
2209 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
2210 candidate->port, candidate_type_to_str (candidate));
2212 gtk_label_set_text (GTK_LABEL (label), str);
2213 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
2219 candidates_changed_cb (GObject *object,
2221 EmpathyCallWindow *self)
2223 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2224 FsCandidate *candidate = NULL;
2226 if (type == FS_MEDIA_TYPE_VIDEO)
2228 /* Update remote candidate */
2229 candidate = empathy_call_handler_get_video_remote_candidate (
2232 update_candidat_widget (self, priv->video_remote_candidate_label,
2233 priv->video_remote_candidate_info_img, candidate);
2235 /* Update local candidate */
2236 candidate = empathy_call_handler_get_video_local_candidate (
2239 update_candidat_widget (self, priv->video_local_candidate_label,
2240 priv->video_local_candidate_info_img, candidate);
2244 /* Update remote candidate */
2245 candidate = empathy_call_handler_get_audio_remote_candidate (
2248 update_candidat_widget (self, priv->audio_remote_candidate_label,
2249 priv->audio_remote_candidate_info_img, candidate);
2251 /* Update local candidate */
2252 candidate = empathy_call_handler_get_audio_local_candidate (
2255 update_candidat_widget (self, priv->audio_local_candidate_label,
2256 priv->audio_local_candidate_info_img, candidate);
2261 empathy_call_window_constructed (GObject *object)
2263 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2264 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2265 TpCallChannel *call;
2268 g_assert (priv->handler != NULL);
2270 g_object_get (priv->handler, "call-channel", &call, NULL);
2271 state = tp_call_channel_get_state (call, NULL, NULL, NULL);
2272 priv->outgoing = (state == TP_CALL_STATE_PENDING_INITIATOR);
2273 tp_clear_object (&call);
2275 priv->contact = empathy_call_handler_get_contact (priv->handler);
2276 g_assert (priv->contact != NULL);
2277 g_object_ref (priv->contact);
2279 if (!empathy_contact_can_voip_video (priv->contact))
2281 gtk_widget_set_sensitive (priv->video_call_button, FALSE);
2282 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2285 empathy_call_window_setup_avatars (self, priv->handler);
2286 empathy_call_window_set_state_connecting (self);
2288 if (!empathy_call_handler_has_initial_video (priv->handler))
2290 gtk_toggle_button_set_active (
2291 GTK_TOGGLE_BUTTON (priv->camera_button), FALSE);
2293 /* If call has InitialVideo, the preview will be started once the call has
2294 * been started (start_call()). */
2296 update_send_codec (self, TRUE);
2297 update_send_codec (self, FALSE);
2298 update_recv_codec (self, TRUE);
2299 update_recv_codec (self, FALSE);
2301 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2302 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2303 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2304 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2305 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2306 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2307 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2308 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2310 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2311 G_CALLBACK (candidates_changed_cb), self, 0);
2314 static void empathy_call_window_dispose (GObject *object);
2315 static void empathy_call_window_finalize (GObject *object);
2318 empathy_call_window_set_property (GObject *object,
2319 guint property_id, const GValue *value, GParamSpec *pspec)
2321 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2323 switch (property_id)
2325 case PROP_CALL_HANDLER:
2326 priv->handler = g_value_dup_object (value);
2329 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2334 empathy_call_window_get_property (GObject *object,
2335 guint property_id, GValue *value, GParamSpec *pspec)
2337 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2339 switch (property_id)
2341 case PROP_CALL_HANDLER:
2342 g_value_set_object (value, priv->handler);
2345 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2350 empathy_call_window_class_init (
2351 EmpathyCallWindowClass *empathy_call_window_class)
2353 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2354 GParamSpec *param_spec;
2356 g_type_class_add_private (empathy_call_window_class,
2357 sizeof (EmpathyCallWindowPriv));
2359 object_class->constructed = empathy_call_window_constructed;
2360 object_class->set_property = empathy_call_window_set_property;
2361 object_class->get_property = empathy_call_window_get_property;
2363 object_class->dispose = empathy_call_window_dispose;
2364 object_class->finalize = empathy_call_window_finalize;
2366 param_spec = g_param_spec_object ("handler",
2367 "handler", "The call handler",
2368 EMPATHY_TYPE_CALL_HANDLER,
2369 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2370 g_object_class_install_property (object_class,
2371 PROP_CALL_HANDLER, param_spec);
2373 signals[SIG_INHIBIT] = g_signal_new ("inhibit",
2374 G_OBJECT_CLASS_TYPE (empathy_call_window_class),
2376 0, NULL, NULL, NULL,
2382 empathy_call_window_dispose (GObject *object)
2384 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2385 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2387 if (priv->dispose_has_run)
2390 priv->dispose_has_run = TRUE;
2392 if (priv->handler != NULL)
2394 empathy_call_handler_stop_call (priv->handler);
2395 tp_clear_object (&priv->handler);
2398 if (priv->bus_message_source_id != 0)
2400 g_source_remove (priv->bus_message_source_id);
2401 priv->bus_message_source_id = 0;
2404 if (priv->got_video_src > 0)
2406 g_source_remove (priv->got_video_src);
2407 priv->got_video_src = 0;
2410 if (priv->inactivity_src > 0)
2412 g_source_remove (priv->inactivity_src);
2413 priv->inactivity_src = 0;
2416 tp_clear_object (&priv->pipeline);
2417 tp_clear_object (&priv->video_input);
2418 tp_clear_object (&priv->audio_input);
2419 tp_clear_object (&priv->video_tee);
2420 tp_clear_object (&priv->ui_manager);
2421 tp_clear_object (&priv->fullscreen);
2422 tp_clear_object (&priv->camera_monitor);
2423 tp_clear_object (&priv->settings);
2424 tp_clear_object (&priv->sound_mgr);
2425 tp_clear_object (&priv->mic_menu);
2426 tp_clear_object (&priv->camera_menu);
2427 tp_clear_object (&priv->transitions);
2429 g_list_free_full (priv->notifiers, g_object_unref);
2431 if (priv->timer_id != 0)
2432 g_source_remove (priv->timer_id);
2435 tp_clear_object (&priv->contact);
2437 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2441 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2443 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2445 if (priv->video_output_motion_handler_id != 0)
2447 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2448 priv->video_output_motion_handler_id);
2449 priv->video_output_motion_handler_id = 0;
2454 empathy_call_window_finalize (GObject *object)
2456 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2457 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2459 disconnect_video_output_motion_handler (self);
2461 /* free any data held directly by the object here */
2462 g_mutex_clear (&priv->lock);
2464 g_timer_destroy (priv->timer);
2466 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2471 empathy_call_window_new (EmpathyCallHandler *handler)
2473 return EMPATHY_CALL_WINDOW (
2474 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2478 empathy_call_window_present (EmpathyCallWindow *self,
2479 EmpathyCallHandler *handler)
2481 g_return_if_fail (EMPATHY_IS_CALL_HANDLER (handler));
2483 empathy_window_present (GTK_WINDOW (self));
2485 if (self->priv->call_state == DISCONNECTED)
2487 /* start a new call if one is not already in progress */
2488 tp_clear_object (&self->priv->handler);
2489 self->priv->handler = g_object_ref (handler);
2490 empathy_call_window_connect_handler (self);
2492 empathy_call_window_restart_call (self);
2497 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2498 GstElement *conference, gpointer user_data)
2500 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2501 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2502 FsElementAddedNotifier *notifier;
2505 DEBUG ("Conference added");
2507 /* Add notifier to set the various element properties as needed */
2508 notifier = fs_element_added_notifier_new ();
2509 keyfile = fs_utils_get_default_element_properties (conference);
2511 if (keyfile != NULL)
2512 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2514 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2516 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2518 gst_bin_add (GST_BIN (priv->pipeline), conference);
2519 gst_element_set_state (conference, GST_STATE_PLAYING);
2523 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2524 GstElement *conference, gpointer user_data)
2526 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2527 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2529 g_list_free_full (priv->notifiers, g_object_unref);
2530 priv->notifiers = NULL;
2532 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2533 gst_element_set_state (conference, GST_STATE_NULL);
2537 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2539 GstStateChangeReturn state_change_return;
2540 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2542 if (priv->pipeline == NULL)
2545 if (priv->bus_message_source_id != 0)
2547 g_source_remove (priv->bus_message_source_id);
2548 priv->bus_message_source_id = 0;
2551 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2553 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2554 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2556 if (priv->pipeline != NULL)
2557 g_object_unref (priv->pipeline);
2558 priv->pipeline = NULL;
2560 if (priv->audio_output != NULL)
2561 g_object_unref (priv->audio_output);
2562 priv->audio_output = NULL;
2563 priv->audio_output_added = FALSE;
2565 if (priv->video_tee != NULL)
2566 g_object_unref (priv->video_tee);
2567 priv->video_tee = NULL;
2569 if (priv->video_preview != NULL)
2570 clutter_actor_destroy (priv->video_preview);
2571 priv->video_preview = NULL;
2573 /* If we destroy the preview while it's being dragged, we won't
2574 * get the ::drag-end signal, so manually destroy the clone */
2575 if (priv->drag_preview != NULL)
2577 clutter_actor_destroy (priv->drag_preview);
2578 empathy_call_window_show_preview_rectangles (self, FALSE);
2579 priv->drag_preview = NULL;
2582 priv->funnel = NULL;
2584 create_pipeline (self);
2585 /* Call will be started when user will hit the 'redial' button */
2586 priv->start_call_when_playing = FALSE;
2587 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2593 g_message ("Error: could not destroy pipeline. Closing call window");
2594 gtk_widget_destroy (GTK_WIDGET (self));
2601 reset_details_pane (EmpathyCallWindow *self)
2603 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2605 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2606 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2607 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2608 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2612 empathy_call_window_disconnected (EmpathyCallWindow *self,
2615 gboolean could_disconnect = FALSE;
2616 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2617 gboolean could_reset_pipeline;
2619 /* Leave full screen mode if needed */
2620 gtk_window_unfullscreen (GTK_WINDOW (self));
2622 g_signal_emit (self, signals[SIG_INHIBIT], 0, FALSE);
2624 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2625 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2627 /* Create the video input and then turn on the camera
2628 * menu, so that the active camera gets marked as such.
2630 if (priv->video_input == NULL)
2631 create_video_input (self);
2632 empathy_camera_menu_set_sensitive (priv->camera_menu, TRUE);
2634 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2636 if (priv->call_state == CONNECTING)
2637 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2639 if (priv->call_state != REDIALING)
2640 priv->call_state = DISCONNECTED;
2642 /* Show the toolbar */
2643 clutter_state_set_state (priv->transitions, "fade-in");
2645 if (could_reset_pipeline)
2647 g_mutex_lock (&priv->lock);
2649 g_timer_stop (priv->timer);
2651 if (priv->timer_id != 0)
2652 g_source_remove (priv->timer_id);
2655 g_mutex_unlock (&priv->lock);
2658 /* We are about to destroy the window, no need to update it or create
2659 * a video preview */
2662 empathy_call_window_status_message (self, _("Disconnected"));
2664 empathy_call_window_show_hangup_button (self, FALSE);
2666 /* Unsensitive the camera and mic button */
2667 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2668 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2670 /* Be sure that the mic button is enabled */
2671 empathy_audio_src_set_mute (
2672 EMPATHY_GST_AUDIO_SRC (self->priv->audio_input), FALSE);
2674 if (priv->camera_state == CAMERA_STATE_ON)
2676 /* Restart the preview with the new pipeline. */
2677 display_video_preview (self, TRUE);
2680 /* destroy the video output; it will be recreated when we'll redial */
2681 disconnect_video_output_motion_handler (self);
2682 if (priv->video_output != NULL)
2683 clutter_actor_destroy (priv->video_output);
2684 priv->video_output = NULL;
2685 if (priv->got_video_src > 0)
2687 g_source_remove (priv->got_video_src);
2688 priv->got_video_src = 0;
2691 gtk_widget_show (priv->remote_user_avatar_widget);
2693 reset_details_pane (self);
2695 priv->sending_video = FALSE;
2696 priv->call_started = FALSE;
2698 could_disconnect = TRUE;
2700 /* TODO: display the self avatar of the preview (depends if the "Always
2701 * Show Video Preview" is enabled or not) */
2704 return could_disconnect;
2709 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2712 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2713 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2715 if (empathy_call_window_disconnected (self, TRUE) &&
2716 priv->call_state == REDIALING)
2717 empathy_call_window_restart_call (self);
2721 empathy_call_window_content_is_raw (TfContent *content)
2723 FsConference *conference;
2726 g_object_get (content, "fs-conference", &conference, NULL);
2727 g_assert (conference != NULL);
2729 /* FIXME: Ugly hack, update when moving a packetization property into
2731 israw = g_str_has_prefix (GST_OBJECT_NAME (conference), "fsrawconf");
2732 gst_object_unref (conference);
2738 empathy_call_window_content_removed_cb (EmpathyCallHandler *handler,
2740 EmpathyCallWindow *self)
2742 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2743 FsMediaType media_type;
2745 DEBUG ("removing content");
2747 g_object_get (content, "media-type", &media_type, NULL);
2750 * This assumes that there is only one video stream per channel...
2753 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2755 if (priv->funnel != NULL)
2759 output = priv->video_output_sink;
2761 gst_element_set_state (output, GST_STATE_NULL);
2762 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2764 gst_bin_remove (GST_BIN (priv->pipeline), output);
2765 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2766 priv->funnel = NULL;
2769 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2771 if (priv->audio_output != NULL)
2773 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2775 if (priv->audio_output_added)
2776 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2777 priv->audio_output = NULL;
2778 priv->audio_output_added = FALSE;
2783 g_assert_not_reached ();
2790 empathy_call_window_framerate_changed_cb (EmpathyCallHandler *handler,
2792 EmpathyCallWindow *self)
2794 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2796 DEBUG ("Framerate changed to %u", framerate);
2798 if (priv->video_input != NULL)
2799 empathy_video_src_set_framerate (priv->video_input, framerate);
2803 empathy_call_window_resolution_changed_cb (EmpathyCallHandler *handler,
2806 EmpathyCallWindow *self)
2808 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2810 DEBUG ("Resolution changed to %ux%u", width, height);
2812 if (priv->video_input != NULL)
2814 empathy_video_src_set_resolution (priv->video_input, width, height);
2818 /* Called with global lock held */
2820 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2822 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2826 if (priv->funnel == NULL)
2828 output = priv->video_output_sink;
2830 priv->funnel = gst_element_factory_make ("funnel", NULL);
2832 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2837 g_warning ("Could not create video funnel");
2841 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2843 gst_object_unref (priv->funnel);
2844 priv->funnel = NULL;
2845 g_warning ("Could not add funnel to pipeline");
2849 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2851 g_warning ("Could not add the video output widget to the pipeline");
2855 if (!gst_element_link (priv->funnel, output))
2857 g_warning ("Could not link output sink to funnel");
2858 goto error_output_added;
2861 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2863 g_warning ("Could not start video sink");
2864 goto error_output_added;
2867 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2869 g_warning ("Could not start funnel");
2870 goto error_output_added;
2874 pad = gst_element_get_request_pad (priv->funnel, "sink_%u");
2876 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2880 g_warning ("Could not get request pad from funnel");
2887 gst_element_set_locked_state (priv->funnel, TRUE);
2888 gst_element_set_locked_state (output, TRUE);
2890 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2891 gst_element_set_state (output, GST_STATE_NULL);
2893 gst_bin_remove (GST_BIN (priv->pipeline), output);
2894 gst_element_set_locked_state (output, FALSE);
2898 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2899 priv->funnel = NULL;
2904 /* Called with global lock held */
2906 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self,
2909 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2911 GstPadTemplate *template;
2913 if (!priv->audio_output_added)
2915 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2917 g_warning ("Could not add audio sink to pipeline");
2918 g_object_unref (priv->audio_output);
2919 goto error_add_output;
2922 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2924 g_warning ("Could not start audio sink");
2929 template = gst_element_class_get_pad_template (
2930 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2932 pad = gst_element_request_pad (priv->audio_output,
2933 template, NULL, NULL);
2937 g_warning ("Could not get sink pad from sink");
2944 gst_element_set_locked_state (priv->audio_output, TRUE);
2945 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2946 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2947 priv->audio_output = NULL;
2955 empathy_call_window_update_timer (gpointer user_data)
2957 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2958 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2959 const gchar *status;
2963 time_ = g_timer_elapsed (priv->timer, NULL);
2965 if (priv->call_state == HELD)
2966 status = _("On hold");
2967 else if (priv->call_state == DISCONNECTED)
2968 status = _("Disconnected");
2969 else if (priv->muted)
2972 status = _("Duration");
2974 /* Translators: 'status - minutes:seconds' the caller has been connected */
2975 str = g_strdup_printf (_("%s — %d:%02dm"),
2977 (int) time_ / 60, (int) time_ % 60);
2978 empathy_call_window_status_message (self, str);
2986 EMP_RESPONSE_BALANCE
2990 on_error_infobar_response_cb (GtkInfoBar *info_bar,
2994 switch (response_id)
2996 case GTK_RESPONSE_CLOSE:
2997 gtk_widget_destroy (GTK_WIDGET (info_bar));
2999 case EMP_RESPONSE_BALANCE:
3000 empathy_url_show (GTK_WIDGET (info_bar),
3001 g_object_get_data (G_OBJECT (info_bar), "uri"));
3007 display_error (EmpathyCallWindow *self,
3011 const gchar *details,
3012 const gchar *button_text,
3014 gint button_response)
3016 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3017 GtkWidget *info_bar;
3018 GtkWidget *content_area;
3025 /* Create info bar */
3026 info_bar = gtk_info_bar_new ();
3028 if (button_text != NULL)
3030 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
3031 button_text, button_response);
3032 g_object_set_data_full (G_OBJECT (info_bar),
3033 "uri", g_strdup (uri), g_free);
3036 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
3037 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
3039 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
3041 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
3043 /* hbox containing the image and the messages vbox */
3044 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
3045 gtk_container_add (GTK_CONTAINER (content_area), hbox);
3048 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
3049 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
3051 /* vbox containing the main message and the details expander */
3052 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
3053 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
3056 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
3058 label = gtk_label_new (NULL);
3059 gtk_label_set_markup (GTK_LABEL (label), txt);
3060 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
3061 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
3064 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
3067 if (details != NULL)
3069 GtkWidget *expander;
3071 expander = gtk_expander_new (_("Technical Details"));
3073 txt = g_strdup_printf ("<i>%s</i>", details);
3075 label = gtk_label_new (NULL);
3076 gtk_label_set_markup (GTK_LABEL (label), txt);
3077 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
3078 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
3081 gtk_container_add (GTK_CONTAINER (expander), label);
3082 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
3085 g_signal_connect (info_bar, "response",
3086 G_CALLBACK (on_error_infobar_response_cb), NULL);
3088 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
3089 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
3090 gtk_widget_show_all (info_bar);
3095 media_stream_error_to_txt (EmpathyCallWindow *self,
3096 TpCallChannel *call,
3098 TpMediaStreamError error)
3100 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3101 const gchar *cm = NULL;
3107 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
3109 return g_strdup_printf (
3110 _("%s's software does not understand any of the audio formats "
3111 "supported by your computer"),
3112 empathy_contact_get_alias (priv->contact));
3114 return g_strdup_printf (
3115 _("%s's software does not understand any of the video formats "
3116 "supported by your computer"),
3117 empathy_contact_get_alias (priv->contact));
3119 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
3120 return g_strdup_printf (
3121 _("Can't establish a connection to %s. "
3122 "One of you might be on a network that does not allow "
3123 "direct connections."),
3124 empathy_contact_get_alias (priv->contact));
3126 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
3127 return g_strdup (_("There was a failure on the network"));
3129 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
3131 return g_strdup (_("The audio formats necessary for this call "
3132 "are not installed on your computer"));
3134 return g_strdup (_("The video formats necessary for this call "
3135 "are not installed on your computer"));
3137 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
3138 tp_connection_parse_object_path (
3139 tp_channel_get_connection (TP_CHANNEL (call)),
3142 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
3143 "product=Telepathy&component=%s", cm);
3145 result = g_strdup_printf (
3146 _("Something unexpected happened in a Telepathy component. "
3147 "Please <a href=\"%s\">report this bug</a> and attach "
3148 "logs gathered from the 'Debug' window in the Help menu."), url);
3154 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
3155 return g_strdup (_("There was a failure in the call engine"));
3157 case TP_MEDIA_STREAM_ERROR_EOS:
3158 return g_strdup (_("The end of the stream was reached"));
3160 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
3167 empathy_call_window_stream_error (EmpathyCallWindow *self,
3168 TpCallChannel *call,
3177 desc = media_stream_error_to_txt (self, call, audio, code);
3180 /* No description, use the error message. That's not great as it's not
3181 * localized but it's better than nothing. */
3182 display_error (self, call, icon, title, msg, NULL);
3186 display_error (self, call, icon, title, desc, msg);
3192 empathy_call_window_audio_stream_error (TpCallChannel *call,
3195 EmpathyCallWindow *self)
3197 empathy_call_window_stream_error (self, call, TRUE, code, msg,
3198 "gnome-stock-mic", _("Can't establish audio stream"));
3202 empathy_call_window_video_stream_error (TpCallChannel *call,
3205 EmpathyCallWindow *self)
3207 empathy_call_window_stream_error (self, call, FALSE, code, msg,
3208 "camera-web", _("Can't establish video stream"));
3213 show_balance_error (EmpathyCallWindow *self)
3217 gchar *balance, *tmp;
3218 const gchar *uri, *currency;
3222 g_object_get (self->priv->handler,
3223 "call-channel", &call,
3226 conn = tp_channel_get_connection (call);
3227 g_object_unref (call);
3229 uri = tp_connection_get_balance_uri (conn);
3231 if (!tp_connection_get_balance (conn, &amount, &scale, ¤cy))
3233 /* unknown balance */
3234 balance = g_strdup ("(--)");
3238 char *money = empathy_format_currency (amount, scale, currency);
3240 balance = g_strdup_printf ("%s %s",
3245 tmp = g_strdup_printf (_("Your current balance is %s."), balance),
3247 display_error (self,
3249 _("Sorry, you don’t have enough credit for that call."),
3253 EMP_RESPONSE_BALANCE);
3260 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
3263 EmpathyCallWindow *self)
3265 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3266 TpCallChannel *call;
3267 gboolean can_send_video;
3269 if (state == TP_CALL_STATE_ENDED)
3271 DEBUG ("Call ended: %s", (reason != NULL && reason[0] != '\0') ? reason : "unspecified reason");
3272 empathy_call_window_disconnected (self, TRUE);
3273 if (!tp_strdiff (reason, TP_ERROR_STR_INSUFFICIENT_BALANCE))
3274 show_balance_error (self);
3278 if (state != TP_CALL_STATE_ACCEPTED)
3281 if (priv->call_state == CONNECTED)
3284 g_timer_start (priv->timer);
3285 priv->call_state = CONNECTED;
3287 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3289 can_send_video = priv->video_input != NULL &&
3290 empathy_contact_can_voip_video (priv->contact) &&
3291 empathy_camera_monitor_get_available (priv->camera_monitor);
3293 g_object_get (priv->handler, "call-channel", &call, NULL);
3295 if (tp_call_channel_has_dtmf (call))
3296 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
3298 if (priv->video_input == NULL)
3299 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
3301 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
3303 empathy_call_window_show_hangup_button (self, TRUE);
3305 gtk_widget_set_sensitive (priv->mic_button, TRUE);
3307 clutter_actor_hide (priv->video_output);
3308 gtk_widget_show (priv->remote_user_avatar_widget);
3310 g_object_unref (call);
3312 g_mutex_lock (&priv->lock);
3314 priv->timer_id = g_timeout_add_seconds (1,
3315 empathy_call_window_update_timer, self);
3317 g_mutex_unlock (&priv->lock);
3319 empathy_call_window_update_timer (self);
3321 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
3325 empathy_call_window_show_video_output_cb (gpointer user_data)
3327 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3329 if (self->priv->video_output != NULL)
3331 gtk_widget_hide (self->priv->remote_user_avatar_widget);
3332 clutter_actor_show (self->priv->video_output);
3333 clutter_actor_raise_top (self->priv->overlay_bin);
3340 empathy_call_window_check_video_cb (gpointer data)
3342 EmpathyCallWindow *self = data;
3344 if (self->priv->got_video)
3346 self->priv->got_video = FALSE;
3350 /* No video in the last N seconds, display the remote avatar */
3351 empathy_call_window_show_video_output (self, FALSE);
3356 /* Called from the streaming thread */
3358 static GstPadProbeReturn
3359 empathy_call_window_video_probe_cb (GstPad *pad,
3360 GstPadProbeInfo *info,
3363 EmpathyCallWindow *self = user_data;
3365 if (G_UNLIKELY (!self->priv->got_video))
3367 /* show the remote video */
3368 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3369 empathy_call_window_show_video_output_cb,
3370 g_object_ref (self), g_object_unref);
3372 self->priv->got_video = TRUE;
3375 return GST_PAD_PROBE_OK;
3379 empathy_call_window_video_probe_cb (GstPad *pad,
3380 GstMiniObject *mini_obj,
3381 EmpathyCallWindow *self)
3384 if (GST_IS_EVENT (mini_obj))
3387 if (G_UNLIKELY (!self->priv->got_video))
3389 /* show the remote video */
3390 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3391 empathy_call_window_show_video_output_cb,
3392 g_object_ref (self), g_object_unref);
3394 self->priv->got_video = TRUE;
3401 /* Called from the streaming thread */
3403 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
3404 TfContent *content, GstPad *src, gpointer user_data)
3406 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3407 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3408 gboolean retval = FALSE;
3413 g_mutex_lock (&priv->lock);
3415 g_object_get (content, "media-type", &media_type, NULL);
3419 case TP_MEDIA_STREAM_TYPE_AUDIO:
3420 pad = empathy_call_window_get_audio_sink_pad (self, content);
3422 case TP_MEDIA_STREAM_TYPE_VIDEO:
3423 g_idle_add (empathy_call_window_show_video_output_cb, self);
3424 pad = empathy_call_window_get_video_sink_pad (self);
3427 gst_pad_add_probe (src,
3428 GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_BUFFER_LIST,
3429 empathy_call_window_video_probe_cb, self, NULL);
3431 gst_pad_add_data_probe (src,
3432 G_CALLBACK (empathy_call_window_video_probe_cb), self);
3434 if (priv->got_video_src > 0)
3435 g_source_remove (priv->got_video_src);
3436 priv->got_video_src = g_timeout_add_seconds (1,
3437 empathy_call_window_check_video_cb, self);
3440 g_assert_not_reached ();
3446 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
3447 g_warning ("Could not link %s sink pad",
3448 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
3452 gst_object_unref (pad);
3456 /* If no sink could be linked, try to add fakesink to prevent the whole call
3461 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
3463 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
3465 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
3466 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
3467 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
3469 gst_element_set_locked_state (fakesink, TRUE);
3470 gst_element_set_state (fakesink, GST_STATE_NULL);
3471 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
3475 DEBUG ("Could not link real sink, linked fakesink instead");
3477 gst_object_unref (sinkpad);
3481 gst_object_unref (fakesink);
3486 g_mutex_unlock (&priv->lock);
3492 empathy_call_window_prepare_audio_output (EmpathyCallWindow *self,
3495 EmpathyCallWindowPriv *priv = self->priv;
3497 g_assert (priv->audio_output_added == FALSE);
3498 g_assert (priv->audio_output == FALSE);
3500 priv->audio_output = empathy_audio_sink_new ();
3501 g_object_ref_sink (priv->audio_output);
3503 /* volume button to output volume linking */
3504 g_object_bind_property (priv->audio_output, "volume",
3505 priv->volume_button, "value",
3506 G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
3508 g_object_bind_property_full (content, "requested-output-volume",
3509 priv->audio_output, "volume",
3511 audio_control_volume_to_element,
3512 element_volume_to_audio_control,
3515 /* Link volumes together, sync the current audio input volume property
3516 * back to farstream first */
3517 g_object_bind_property_full (priv->audio_output, "volume",
3518 content, "reported-output-volume",
3519 G_BINDING_SYNC_CREATE,
3520 element_volume_to_audio_control,
3521 audio_control_volume_to_element,
3524 /* For raw audio conferences assume that the producer of the raw data
3525 * has already processed it, so turn off any echo cancellation and any
3526 * other audio improvements that come with it */
3527 empathy_audio_sink_set_echo_cancel (
3528 EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3529 !empathy_call_window_content_is_raw (content));
3534 empathy_call_window_content_added_cb (EmpathyCallHandler *handler,
3535 TfContent *content, gpointer user_data)
3537 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3538 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3540 FsMediaType media_type;
3541 gboolean retval = FALSE;
3543 g_object_get (content, "media-type", &media_type, "sink-pad", &sink, NULL);
3544 g_assert (sink != NULL);
3548 case FS_MEDIA_TYPE_AUDIO:
3550 /* For raw audio conferences assume that the receiver of the raw data
3551 * wants it unprocessed, so turn off any echo cancellation and any
3552 * other audio improvements that come with it */
3553 empathy_audio_src_set_echo_cancel (
3554 EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3555 !empathy_call_window_content_is_raw (content));
3557 /* Link volumes together, sync the current audio input volume property
3558 * back to farstream first */
3559 g_object_bind_property_full (content, "requested-input-volume",
3560 priv->audio_input, "volume",
3562 audio_control_volume_to_element,
3563 element_volume_to_audio_control,
3566 g_object_bind_property_full (priv->audio_input, "volume",
3567 content, "reported-input-volume",
3568 G_BINDING_SYNC_CREATE,
3569 element_volume_to_audio_control,
3570 audio_control_volume_to_element,
3573 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
3575 g_warning ("Could not add audio source to pipeline");
3579 pad = gst_element_get_static_pad (priv->audio_input, "src");
3582 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3583 g_warning ("Could not get source pad from audio source");
3587 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3589 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3590 gst_object_unref (pad);
3591 g_warning ("Could not link audio source to farsight");
3594 gst_object_unref (pad);
3596 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3598 g_warning ("Could not start audio source");
3599 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3600 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3604 /* Prepare our audio output, not added yet though */
3605 empathy_call_window_prepare_audio_output (self, content);
3609 case FS_MEDIA_TYPE_VIDEO:
3610 if (priv->video_tee != NULL)
3613 pad = gst_element_get_request_pad (priv->video_tee, "src_%u");
3615 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3617 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3619 g_warning ("Could not link video source input pipeline");
3622 gst_object_unref (pad);
3628 g_assert_not_reached ();
3631 gst_object_unref (sink);
3636 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3638 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3639 GstElement *preview;
3641 disable_camera (self);
3643 DEBUG ("remove video input");
3644 preview = priv->video_preview_sink;
3646 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3647 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3648 gst_element_set_state (preview, GST_STATE_NULL);
3650 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3653 g_object_unref (priv->video_input);
3654 priv->video_input = NULL;
3655 g_object_unref (priv->video_tee);
3656 priv->video_tee = NULL;
3657 clutter_actor_destroy (priv->video_preview);
3658 priv->video_preview = NULL;
3660 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3661 empathy_camera_menu_set_sensitive (priv->camera_menu, FALSE);
3665 start_call (EmpathyCallWindow *self)
3667 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3669 g_signal_emit (self, signals[SIG_INHIBIT], 0, TRUE);
3671 priv->call_started = TRUE;
3672 empathy_call_handler_start_call (priv->handler,
3673 gtk_get_current_event_time ());
3675 if (empathy_call_handler_has_initial_video (priv->handler))
3677 TpCallChannel *call;
3680 g_object_get (priv->handler, "call-channel", &call, NULL);
3681 /* If the call channel isn't set yet we're requesting it, if we're
3682 * requesting it with initial video it should be PENDING_SEND when we get
3685 s = TP_SENDING_STATE_PENDING_SEND;
3687 s = empathy_call_channel_get_video_state (call);
3689 if (s == TP_SENDING_STATE_PENDING_SEND ||
3690 s == TP_SENDING_STATE_SENDING)
3692 /* Enable 'send video' buttons and display the preview */
3693 gtk_toggle_button_set_active (
3694 GTK_TOGGLE_BUTTON (priv->camera_button), TRUE);
3698 gtk_toggle_button_set_active (
3699 GTK_TOGGLE_BUTTON (priv->camera_button), FALSE);
3701 if (priv->video_preview == NULL)
3703 create_video_preview (self);
3704 add_video_preview_to_pipeline (self);
3709 g_object_unref (call);
3714 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3717 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3718 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3719 GstState newstate, pending;
3721 empathy_call_handler_bus_message (priv->handler, bus, message);
3723 switch (GST_MESSAGE_TYPE (message))
3725 case GST_MESSAGE_STATE_CHANGED:
3726 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3728 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3730 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3731 !priv->call_started)
3733 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3734 if (newstate == GST_STATE_PAUSED)
3736 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3737 priv->pipeline_playing = TRUE;
3739 if (priv->start_call_when_playing)
3743 if (priv->video_preview_sink != NULL &&
3744 GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_preview_sink))
3746 gst_message_parse_state_changed (message, NULL, &newstate,
3749 if (newstate == GST_STATE_PLAYING &&
3750 pending == GST_STATE_VOID_PENDING)
3751 empathy_call_window_stop_camera_spinning (self);
3754 case GST_MESSAGE_ERROR:
3756 GError *error = NULL;
3757 GstElement *gst_error;
3761 gst_message_parse_error (message, &error, &debug);
3762 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3764 g_message ("Element error: %s -- %s\n", error->message, debug);
3766 name = gst_element_get_name (gst_error);
3767 if (g_str_has_prefix (name, VIDEO_INPUT_ERROR_PREFIX))
3769 /* Remove the video input and continue */
3770 if (priv->video_input != NULL)
3771 empathy_call_window_remove_video_input (self);
3772 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3776 empathy_call_window_disconnected (self, TRUE);
3779 g_error_free (error);
3782 case GST_MESSAGE_UNKNOWN:
3783 case GST_MESSAGE_EOS:
3784 case GST_MESSAGE_WARNING:
3785 case GST_MESSAGE_INFO:
3786 case GST_MESSAGE_TAG:
3787 case GST_MESSAGE_BUFFERING:
3788 case GST_MESSAGE_STATE_DIRTY:
3789 case GST_MESSAGE_STEP_DONE:
3790 case GST_MESSAGE_CLOCK_PROVIDE:
3791 case GST_MESSAGE_CLOCK_LOST:
3792 case GST_MESSAGE_NEW_CLOCK:
3793 case GST_MESSAGE_STRUCTURE_CHANGE:
3794 case GST_MESSAGE_STREAM_STATUS:
3795 case GST_MESSAGE_APPLICATION:
3796 case GST_MESSAGE_ELEMENT:
3797 case GST_MESSAGE_SEGMENT_START:
3798 case GST_MESSAGE_SEGMENT_DONE:
3799 case GST_MESSAGE_DURATION:
3800 case GST_MESSAGE_ANY:
3809 empathy_call_window_members_changed_cb (TpCallChannel *call,
3810 GHashTable *updates,
3812 TpCallStateReason *reason,
3813 EmpathyCallWindow *self)
3815 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3816 GHashTableIter iter;
3817 gpointer key, value;
3818 gboolean held = FALSE;
3820 g_hash_table_iter_init (&iter, updates);
3821 while (g_hash_table_iter_next (&iter, &key, &value))
3823 if (GPOINTER_TO_INT (value) & TP_CALL_MEMBER_FLAG_HELD)
3825 /* This assumes this is a 1-1 call, otherwise one participant
3826 * putting the call on hold wouldn't mean the call is on hold
3834 priv->call_state = HELD;
3835 else if (priv->call_state == HELD)
3836 priv->call_state = CONNECTED;
3840 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3842 EmpathyCallWindow *self)
3844 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3845 TpCallChannel *call;
3847 g_object_get (priv->handler, "call-channel", &call, NULL);
3852 tp_g_signal_connect_object (call, "audio-stream-error",
3853 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3854 tp_g_signal_connect_object (call, "video-stream-error",
3855 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3858 tp_g_signal_connect_object (call, "members-changed",
3859 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3861 g_object_unref (call);
3865 empathy_call_window_connect_handler (EmpathyCallWindow *self)
3867 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3868 TpCallChannel *call;
3870 g_signal_connect (priv->handler, "state-changed",
3871 G_CALLBACK (empathy_call_window_state_changed_cb), self);
3872 g_signal_connect (priv->handler, "conference-added",
3873 G_CALLBACK (empathy_call_window_conference_added_cb), self);
3874 g_signal_connect (priv->handler, "conference-removed",
3875 G_CALLBACK (empathy_call_window_conference_removed_cb), self);
3876 g_signal_connect (priv->handler, "closed",
3877 G_CALLBACK (empathy_call_window_channel_closed_cb), self);
3878 g_signal_connect (priv->handler, "src-pad-added",
3879 G_CALLBACK (empathy_call_window_src_added_cb), self);
3880 g_signal_connect (priv->handler, "content-added",
3881 G_CALLBACK (empathy_call_window_content_added_cb), self);
3882 g_signal_connect (priv->handler, "content-removed",
3883 G_CALLBACK (empathy_call_window_content_removed_cb), self);
3885 /* We connect to ::call-channel unconditionally since we'll
3886 * get new channels if we hangup and redial or if we reuse the
3888 g_signal_connect (priv->handler, "notify::call-channel",
3889 G_CALLBACK (call_handler_notify_call_cb), self);
3891 g_signal_connect (priv->handler, "framerate-changed",
3892 G_CALLBACK (empathy_call_window_framerate_changed_cb), self);
3893 g_signal_connect (priv->handler, "resolution-changed",
3894 G_CALLBACK (empathy_call_window_resolution_changed_cb), self);
3896 g_object_get (priv->handler, "call-channel", &call, NULL);
3899 /* We won't get notify::call-channel for this channel, so
3900 * directly call the callback. */
3901 call_handler_notify_call_cb (priv->handler, NULL, self);
3902 g_object_unref (call);
3907 empathy_call_window_realized_cb (GtkWidget *widget,
3908 EmpathyCallWindow *self)
3912 /* Make the hangup button twice as wide */
3913 width = gtk_widget_get_allocated_width (self->priv->hangup_button);
3914 gtk_widget_set_size_request (self->priv->hangup_button, width * 2, -1);
3916 empathy_call_window_connect_handler (self);
3918 gst_element_set_state (self->priv->pipeline, GST_STATE_PAUSED);
3922 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3923 EmpathyCallWindow *window)
3925 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3927 if (priv->pipeline != NULL)
3929 if (priv->bus_message_source_id != 0)
3931 g_source_remove (priv->bus_message_source_id);
3932 priv->bus_message_source_id = 0;
3935 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3938 if (priv->call_state == CONNECTING)
3939 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3945 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3948 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3950 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3955 gtk_widget_hide (priv->dtmf_panel);
3956 gtk_widget_hide (menu);
3957 gtk_widget_hide (priv->toolbar);
3961 if (priv->dialpad_was_visible_before_fs)
3962 gtk_widget_show (priv->dtmf_panel);
3964 gtk_widget_show (menu);
3965 gtk_widget_show (priv->toolbar);
3967 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3968 priv->original_height_before_fs);
3973 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3975 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3977 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3978 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3980 if (priv->video_output != NULL)
3983 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3984 priv->video_output, TRUE, TRUE,
3985 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3992 empathy_call_window_state_event_cb (GtkWidget *widget,
3993 GdkEventWindowState *event, EmpathyCallWindow *window)
3995 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3997 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3998 gboolean set_fullscreen = event->new_window_state &
3999 GDK_WINDOW_STATE_FULLSCREEN;
4003 gboolean dialpad_was_visible;
4004 GtkAllocation allocation;
4005 gint original_width, original_height;
4007 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
4008 original_width = allocation.width;
4009 original_height = allocation.height;
4011 g_object_get (priv->dtmf_panel,
4012 "visible", &dialpad_was_visible,
4015 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
4016 priv->original_width_before_fs = original_width;
4017 priv->original_height_before_fs = original_height;
4019 if (priv->video_output_motion_handler_id == 0 &&
4020 priv->video_output != NULL)
4022 priv->video_output_motion_handler_id = g_signal_connect (
4023 G_OBJECT (priv->video_container), "motion-notify-event",
4024 G_CALLBACK (empathy_call_window_video_output_motion_notify),
4030 disconnect_video_output_motion_handler (window);
4033 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
4035 show_controls (window, set_fullscreen);
4036 show_borders (window, set_fullscreen);
4037 gtk_action_set_stock_id (priv->menu_fullscreen,
4038 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
4039 priv->is_fullscreen = set_fullscreen;
4046 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
4049 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4050 int w, h, dialpad_width;
4051 GtkAllocation allocation;
4053 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
4054 w = allocation.width;
4055 h = allocation.height;
4057 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
4061 gtk_widget_show (priv->dtmf_panel);
4067 gtk_widget_hide (priv->dtmf_panel);
4071 gtk_window_resize (GTK_WINDOW (window), w, h);
4075 empathy_call_window_set_send_video (EmpathyCallWindow *window,
4078 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4079 TpCallChannel *call;
4081 priv->sending_video = (state == CAMERA_STATE_ON);
4083 if (state == CAMERA_STATE_ON)
4085 /* When we start sending video, we want to show the video preview by
4087 display_video_preview (window, TRUE);
4091 display_video_preview (window, FALSE);
4094 if (priv->call_state != CONNECTED)
4097 g_object_get (priv->handler, "call-channel", &call, NULL);
4098 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
4099 empathy_call_channel_send_video (call, priv->sending_video);
4100 g_object_unref (call);
4104 empathy_call_window_hangup_cb (gpointer object,
4105 EmpathyCallWindow *self)
4107 /* stopping the call will put it the ENDED state and
4108 * from state_changed_cb we'll reconfigure the window
4110 empathy_call_handler_stop_call (self->priv->handler);
4114 empathy_call_window_restart_call (EmpathyCallWindow *window)
4116 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4118 /* Remove error info bars */
4119 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
4120 (GtkCallback) gtk_widget_destroy, NULL);
4122 create_video_output_widget (window);
4123 priv->outgoing = TRUE;
4124 empathy_call_window_set_state_connecting (window);
4126 if (priv->pipeline_playing)
4127 start_call (window);
4129 /* call will be started when the pipeline is ready */
4130 priv->start_call_when_playing = TRUE;
4132 empathy_call_window_setup_avatars (window, priv->handler);
4134 empathy_call_window_show_hangup_button (window, TRUE);
4138 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
4139 EmpathyCallWindow *window)
4143 active = gtk_toggle_tool_button_get_active (button);
4145 empathy_call_window_show_dialpad (window, active);
4149 empathy_call_window_fullscreen_cb (gpointer object,
4150 EmpathyCallWindow *window)
4152 empathy_call_window_fullscreen_toggle (window);
4156 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
4158 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4160 if (priv->is_fullscreen)
4161 gtk_window_unfullscreen (GTK_WINDOW (window));
4163 gtk_window_fullscreen (GTK_WINDOW (window));
4167 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
4168 GdkEventButton *event, EmpathyCallWindow *window)
4170 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
4172 empathy_call_window_video_menu_popup (window, event->button);
4180 empathy_call_window_key_press_cb (GtkWidget *video_output,
4181 GdkEventKey *event, EmpathyCallWindow *window)
4183 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4186 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
4188 /* Since we are in fullscreen mode, toggling will bring us back to
4190 empathy_call_window_fullscreen_toggle (window);
4194 key = gdk_keyval_to_unicode (event->keyval);
4215 gtk_toggle_tool_button_set_active (
4216 GTK_TOGGLE_TOOL_BUTTON (priv->dialpad_button), TRUE);
4218 empathy_dialpad_widget_press_key (
4219 EMPATHY_DIALPAD_WIDGET (priv->dtmf_panel), key);
4225 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
4226 GdkEventMotion *event, EmpathyCallWindow *window)
4228 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4230 if (priv->is_fullscreen)
4232 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
4234 /* Show the bottom toolbar */
4235 empathy_call_window_motion_notify_cb (NULL, NULL, window);
4242 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
4246 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4248 menu = gtk_ui_manager_get_widget (priv->ui_manager,
4250 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
4251 button, gtk_get_current_event_time ());
4252 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
4256 empathy_call_window_status_message (EmpathyCallWindow *self,
4259 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
4263 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
4265 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4267 return priv->ui_manager;
4270 EmpathyGstAudioSrc *
4271 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
4273 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4275 return (EmpathyGstAudioSrc *) priv->audio_input;
4278 EmpathyGstVideoSrc *
4279 empathy_call_window_get_video_src (EmpathyCallWindow *self)
4281 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);
4285 empathy_call_window_change_webcam (EmpathyCallWindow *self,
4286 const gchar *device)
4288 EmpathyGstVideoSrc *video;
4291 /* Restart the camera only if it's already running */
4292 running = (self->priv->video_preview != NULL);
4293 video = empathy_call_window_get_video_src (self);
4296 empathy_call_window_play_camera (self, FALSE);
4298 empathy_video_src_change_device (video, device);
4301 empathy_call_window_play_camera (self, TRUE);