2 * empathy-call-window.c - Source for EmpathyCallWindow
3 * Copyright (C) 2008-2011 Collabora Ltd.
4 * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #include <gdk/gdkkeysyms.h>
31 #include <glib/gi18n.h>
33 #include <clutter/clutter.h>
34 #include <clutter-gtk/clutter-gtk.h>
35 #include <clutter-gst/clutter-gst.h>
37 #include <telepathy-glib/util.h>
38 #include <telepathy-farstream/telepathy-farstream.h>
39 #include <telepathy-glib/util.h>
41 #include <farstream/fs-element-added-notifier.h>
42 #include <farstream/fs-utils.h>
44 #include <libempathy/empathy-camera-monitor.h>
45 #include <libempathy/empathy-gsettings.h>
46 #include <libempathy/empathy-tp-contact-factory.h>
47 #include <libempathy/empathy-request-util.h>
48 #include <libempathy/empathy-utils.h>
50 #include <libempathy-gtk/empathy-avatar-image.h>
51 #include <libempathy-gtk/empathy-dialpad-widget.h>
52 #include <libempathy-gtk/empathy-ui-utils.h>
53 #include <libempathy-gtk/empathy-sound-manager.h>
54 #include <libempathy-gtk/empathy-geometry.h>
55 #include <libempathy-gtk/empathy-images.h>
56 #include <libempathy-gtk/empathy-call-utils.h>
58 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
59 #include <libempathy/empathy-debug.h>
61 #include "empathy-call-window.h"
62 #include "empathy-call-window-fullscreen.h"
63 #include "empathy-call-factory.h"
64 #include "empathy-video-widget.h"
65 #include "empathy-about-dialog.h"
66 #include "empathy-audio-src.h"
67 #include "empathy-audio-sink.h"
68 #include "empathy-video-src.h"
69 #include "empathy-mic-menu.h"
70 #include "empathy-preferences.h"
71 #include "empathy-rounded-actor.h"
72 #include "empathy-rounded-rectangle.h"
73 #include "empathy-rounded-texture.h"
74 #include "empathy-camera-menu.h"
76 #define CONTENT_HBOX_BORDER_WIDTH 6
77 #define CONTENT_HBOX_SPACING 3
78 #define CONTENT_HBOX_CHILDREN_PACKING_PADDING 3
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 #define FLOATING_TOOLBAR_OPACITY 192
86 #define FLOATING_TOOLBAR_WIDTH 280
87 #define FLOATING_TOOLBAR_HEIGHT 36
88 #define FLOATING_TOOLBAR_SPACING 20
90 /* The avatar's default width and height are set to the same value because we
91 want a square icon. */
92 #define REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
93 #define REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT \
94 EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT
96 #define SMALL_TOOLBAR_SIZE 36
98 /* If an video input error occurs, the error message will start with "v4l" */
99 #define VIDEO_INPUT_ERROR_PREFIX "v4l"
101 /* The time interval in milliseconds between 2 outgoing rings */
102 #define MS_BETWEEN_RING 500
104 /* The roundedness of preview box and placeholders */
105 #define PREVIEW_ROUND_FACTOR 16
107 G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
110 PROP_CALL_HANDLER = 1,
114 RINGING, /* Incoming call */
115 CONNECTING, /* Outgoing call */
116 CONNECTED, /* Connected */
117 HELD, /* Connected, but on hold */
118 DISCONNECTED, /* Disconnected */
119 REDIALING /* Redialing (special case of CONNECTING) */
123 CAMERA_STATE_OFF = 0,
129 PREVIEW_POS_TOP_LEFT,
130 PREVIEW_POS_TOP_RIGHT,
131 PREVIEW_POS_BOTTOM_LEFT,
132 PREVIEW_POS_BOTTOM_RIGHT,
135 struct _EmpathyCallWindowPriv
137 gboolean dispose_has_run;
138 EmpathyCallHandler *handler;
140 EmpathyContact *contact;
142 EmpathyCameraMonitor *camera_monitor;
147 GtkUIManager *ui_manager;
148 GtkWidget *errors_vbox;
149 /* widget displays the video received from the remote user. This widget is
150 * alive only during call. */
151 ClutterActor *video_output;
152 ClutterActor *video_preview;
153 ClutterActor *drag_preview;
154 ClutterActor *preview_shown_button;
155 ClutterActor *preview_hidden_button;
156 ClutterActor *preview_rectangle1;
157 ClutterActor *preview_rectangle2;
158 ClutterActor *preview_rectangle3;
159 ClutterActor *preview_rectangle4;
160 ClutterActor *preview_rectangle_box1;
161 ClutterActor *preview_rectangle_box2;
162 ClutterActor *preview_rectangle_box3;
163 ClutterActor *preview_rectangle_box4;
164 ClutterActor *preview_spinner_actor;
165 GtkWidget *preview_spinner_widget;
166 GtkWidget *video_container;
167 GtkWidget *remote_user_avatar_widget;
168 GtkWidget *remote_user_avatar_toolbar;
169 GtkWidget *remote_user_name_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 *volume_button;
176 GtkWidget *camera_button;
177 GtkWidget *dialpad_button;
179 GtkWidget *bottom_toolbar;
180 ClutterActor *floating_toolbar;
182 GtkAction *menu_fullscreen;
183 GtkAction *menu_swap_camera;
185 ClutterState *transitions;
187 /* The box that contains self and remote avatar and video
188 input/output. When we redial, we destroy and re-create the box */
189 ClutterActor *video_box;
190 ClutterLayoutManager *video_layout;
192 /* Coordinates of the preview drag event's start. */
193 PreviewPosition preview_pos;
195 /* We keep a reference on the hbox which contains the main content so we can
196 easilly repack everything when toggling fullscreen */
197 GtkWidget *content_hbox;
199 /* These are used to accept or reject an incoming call when the status
201 GtkWidget *incoming_call_dialog;
202 TpCallChannel *pending_channel;
203 TpChannelDispatchOperation *pending_cdo;
204 TpAddDispatchOperationContext *pending_context;
206 gulong video_output_motion_handler_id;
207 guint bus_message_source_id;
209 GtkWidget *dtmf_panel;
212 GtkWidget *details_vbox;
213 GtkWidget *vcodec_encoding_label;
214 GtkWidget *acodec_encoding_label;
215 GtkWidget *vcodec_decoding_label;
216 GtkWidget *acodec_decoding_label;
218 GtkWidget *audio_remote_candidate_label;
219 GtkWidget *audio_local_candidate_label;
220 GtkWidget *video_remote_candidate_label;
221 GtkWidget *video_local_candidate_label;
222 GtkWidget *video_remote_candidate_info_img;
223 GtkWidget *video_local_candidate_info_img;
224 GtkWidget *audio_remote_candidate_info_img;
225 GtkWidget *audio_local_candidate_info_img;
227 GstElement *video_input;
228 GstElement *video_preview_sink;
229 GstElement *video_output_sink;
230 GstElement *audio_input;
231 GstElement *audio_output;
232 gboolean audio_output_added;
233 GstElement *pipeline;
234 GstElement *video_tee;
244 gboolean call_started;
245 gboolean sending_video;
246 CameraState camera_state;
248 EmpathyCallWindowFullscreen *fullscreen;
249 gboolean is_fullscreen;
254 guint inactivity_src;
256 /* Those fields represent the state of the window before it actually was in
258 gboolean dialpad_was_visible_before_fs;
259 gint original_width_before_fs;
260 gint original_height_before_fs;
262 gint x, y, w, h, dialpad_width;
265 /* TRUE if the call should be started when the pipeline is playing */
266 gboolean start_call_when_playing;
267 /* TRUE if we requested to set the pipeline in the playing state */
268 gboolean pipeline_playing;
270 EmpathySoundManager *sound_mgr;
273 EmpathyMicMenu *mic_menu;
274 EmpathyCameraMenu *camera_menu;
277 #define GET_PRIV(o) (EMPATHY_CALL_WINDOW (o)->priv)
279 static void empathy_call_window_realized_cb (GtkWidget *widget,
280 EmpathyCallWindow *window);
282 static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
283 GdkEvent *event, EmpathyCallWindow *window);
285 static gboolean empathy_call_window_state_event_cb (GtkWidget *widget,
286 GdkEventWindowState *event, EmpathyCallWindow *window);
288 static void empathy_call_window_set_send_video (EmpathyCallWindow *window,
291 static void empathy_call_window_hangup_cb (gpointer object,
292 EmpathyCallWindow *window);
294 static void empathy_call_window_fullscreen_cb (gpointer object,
295 EmpathyCallWindow *window);
297 static void empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window);
299 static gboolean empathy_call_window_video_button_press_cb (
300 GtkWidget *video_output, GdkEventButton *event, EmpathyCallWindow *window);
302 static gboolean empathy_call_window_key_press_cb (GtkWidget *video_output,
303 GdkEventKey *event, EmpathyCallWindow *window);
305 static gboolean empathy_call_window_video_output_motion_notify (
306 GtkWidget *widget, GdkEventMotion *event, EmpathyCallWindow *window);
308 static void empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
311 static void empathy_call_window_connect_handler (EmpathyCallWindow *self);
313 static void empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
314 EmpathyCallWindow *window);
316 static void empathy_call_window_restart_call (EmpathyCallWindow *window);
318 static void empathy_call_window_status_message (EmpathyCallWindow *window,
321 static gboolean empathy_call_window_bus_message (GstBus *bus,
322 GstMessage *message, gpointer user_data);
325 empathy_call_window_show_hangup_button (EmpathyCallWindow *self,
328 gtk_widget_set_visible (self->priv->hangup_button, show);
329 gtk_widget_set_visible (self->priv->audio_call_button, !show);
330 gtk_widget_set_visible (self->priv->video_call_button, !show);
334 empathy_call_window_audio_call_cb (GtkToggleToolButton *button,
335 EmpathyCallWindow *self)
337 g_object_set (self->priv->handler, "initial-video", FALSE, NULL);
338 empathy_call_window_restart_call (self);
342 empathy_call_window_video_call_cb (GtkToggleToolButton *button,
343 EmpathyCallWindow *self)
345 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
346 g_object_set (self->priv->handler, "initial-video", TRUE, NULL);
347 empathy_call_window_restart_call (self);
351 dtmf_start_tone_cb (EmpathyDialpadWidget *dialpad,
353 EmpathyCallWindow *self)
358 g_object_get (self->priv->handler, "call-channel", &call, NULL);
360 tones[0] = tp_dtmf_event_to_char (event);
362 tp_call_channel_send_tones_async (call, tones, NULL, NULL, NULL);
364 g_object_unref (call);
368 empathy_call_window_raise_actors (EmpathyCallWindow *self)
370 clutter_actor_raise_top (self->priv->floating_toolbar);
372 clutter_actor_raise_top (self->priv->preview_rectangle_box1);
373 clutter_actor_raise_top (self->priv->preview_rectangle_box2);
374 clutter_actor_raise_top (self->priv->preview_rectangle_box3);
375 clutter_actor_raise_top (self->priv->preview_rectangle_box4);
379 empathy_call_window_show_video_output (EmpathyCallWindow *self,
382 if (self->priv->video_output != NULL)
383 g_object_set (self->priv->video_output, "visible", show, NULL);
385 gtk_widget_set_visible (self->priv->remote_user_avatar_widget, !show);
387 empathy_call_window_raise_actors (self);
391 create_video_output_widget (EmpathyCallWindow *self)
393 EmpathyCallWindowPriv *priv = GET_PRIV (self);
395 g_assert (priv->video_output == NULL);
396 g_assert (priv->pipeline != NULL);
398 priv->video_output = clutter_texture_new ();
400 clutter_texture_set_keep_aspect_ratio (CLUTTER_TEXTURE (priv->video_output),
403 priv->video_output_sink = gst_element_factory_make ("cluttersink", NULL);
404 if (priv->video_output_sink == NULL)
405 g_error ("Missing cluttersink");
407 g_object_set (priv->video_output_sink, "texture", priv->video_output, NULL);
409 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
412 gtk_widget_add_events (priv->video_container,
413 GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK);
414 g_signal_connect (G_OBJECT (priv->video_container), "button-press-event",
415 G_CALLBACK (empathy_call_window_video_button_press_cb), self);
419 create_video_input (EmpathyCallWindow *self)
421 EmpathyCallWindowPriv *priv = GET_PRIV (self);
423 g_assert (priv->video_input == NULL);
424 priv->video_input = empathy_video_src_new ();
425 gst_object_ref (priv->video_input);
426 gst_object_sink (priv->video_input);
430 audio_control_volume_to_element (GBinding *binding,
431 const GValue *source_value,
432 GValue *target_value,
435 /* AudioControl volume is 0-255, with -1 for unknown */
438 hv = g_value_get_int (source_value);
443 g_value_set_double (target_value, hv/255.0);
449 element_volume_to_audio_control (GBinding *binding,
450 const GValue *source_value,
451 GValue *target_value,
456 ev = g_value_get_double (source_value);
457 ev = CLAMP (ev, 0.0, 1.0);
459 g_value_set_int (target_value, ev * 255);
464 create_audio_input (EmpathyCallWindow *self)
466 EmpathyCallWindowPriv *priv = GET_PRIV (self);
468 g_assert (priv->audio_input == NULL);
469 priv->audio_input = empathy_audio_src_new ();
470 gst_object_ref (priv->audio_input);
471 gst_object_sink (priv->audio_input);
473 g_object_bind_property (priv->mic_button, "active",
474 priv->audio_input, "mute",
475 G_BINDING_BIDIRECTIONAL |
476 G_BINDING_INVERT_BOOLEAN | G_BINDING_SYNC_CREATE);
480 add_video_preview_to_pipeline (EmpathyCallWindow *self)
482 EmpathyCallWindowPriv *priv = GET_PRIV (self);
485 g_assert (priv->video_preview != NULL);
486 g_assert (priv->pipeline != NULL);
487 g_assert (priv->video_input != NULL);
488 g_assert (priv->video_tee != NULL);
490 preview = priv->video_preview_sink;
492 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->video_input))
494 g_warning ("Could not add video input to pipeline");
498 if (!gst_bin_add (GST_BIN (priv->pipeline), preview))
500 g_warning ("Could not add video preview to pipeline");
504 if (!gst_element_link (priv->video_input, priv->video_tee))
506 g_warning ("Could not link video input to video tee");
510 if (!gst_element_link (priv->video_tee, preview))
512 g_warning ("Could not link video tee to video preview");
518 empathy_call_window_disable_camera_cb (GtkAction *action,
519 EmpathyCallWindow *self)
521 clutter_actor_destroy (self->priv->preview_hidden_button);
523 gtk_toggle_tool_button_set_active (
524 GTK_TOGGLE_TOOL_BUTTON (self->priv->camera_button), FALSE);
528 empathy_call_window_minimise_camera_cb (GtkAction *action,
529 EmpathyCallWindow *self)
531 clutter_actor_hide (self->priv->video_preview);
532 clutter_actor_show (self->priv->preview_hidden_button);
536 empathy_call_window_maximise_camera_cb (GtkAction *action,
537 EmpathyCallWindow *self)
539 clutter_actor_show (self->priv->video_preview);
540 clutter_actor_hide (self->priv->preview_hidden_button);
544 empathy_call_window_swap_camera_cb (GtkAction *action,
545 EmpathyCallWindow *self)
547 const GList *cameras, *l;
550 DEBUG ("Swapping the camera");
552 cameras = empathy_camera_monitor_get_cameras (self->priv->camera_monitor);
553 current_cam = empathy_video_src_dup_device (
554 EMPATHY_GST_VIDEO_SRC (self->priv->video_input));
556 for (l = cameras; l != NULL; l = l->next)
558 EmpathyCamera *camera = l->data;
560 if (!tp_strdiff (camera->device, current_cam))
565 next = l->next->data;
567 next = cameras->data;
569 /* EmpathyCameraMenu will update itself and do the actual change
571 g_settings_set_string (self->priv->settings,
572 EMPATHY_PREFS_CALL_CAMERA_DEVICE,
579 g_free (current_cam);
583 empathy_call_window_camera_added_cb (EmpathyCameraMonitor *monitor,
584 EmpathyCamera *camera,
585 EmpathyCallWindow *self)
587 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
589 gtk_action_set_visible (self->priv->menu_swap_camera,
590 g_list_length ((GList *) cameras) >= 2);
594 empathy_call_window_camera_removed_cb (EmpathyCameraMonitor *monitor,
595 EmpathyCamera *camera,
596 EmpathyCallWindow *self)
598 const GList *cameras = empathy_camera_monitor_get_cameras (monitor);
600 gtk_action_set_visible (self->priv->menu_swap_camera,
601 g_list_length ((GList *) cameras) >= 2);
605 empathy_call_window_preview_button_clicked_cb (GtkButton *button,
606 EmpathyCallWindow *self)
610 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
612 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
613 0, gtk_get_current_event_time ());
614 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
618 empathy_call_window_preview_hidden_button_clicked_cb (GtkButton *button,
619 EmpathyCallWindow *self)
623 menu = gtk_ui_manager_get_widget (self->priv->ui_manager,
624 "/preview-hidden-menu");
625 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
626 0, gtk_get_current_event_time ());
627 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
630 static ClutterActor *
631 empathy_call_window_create_preview_rectangle (EmpathyCallWindow *self,
633 ClutterBinAlignment x,
634 ClutterBinAlignment y)
636 ClutterLayoutManager *layout1, *layout2;
637 EmpathyRoundedRectangle *rectangle;
638 ClutterActor *box1, *box2;
640 layout1 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
641 CLUTTER_BIN_ALIGNMENT_START);
643 box1 = clutter_box_new (layout1);
647 rectangle = empathy_rounded_rectangle_new (
648 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
649 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN,
650 PREVIEW_ROUND_FACTOR);
652 clutter_actor_set_size (box1,
653 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
654 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
655 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
657 layout2 = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
658 CLUTTER_BIN_ALIGNMENT_CENTER);
660 /* We have a box with the margins and the video in the middle inside
661 * a bigger box with an extra bottom margin so we're not on top of
662 * the floating toolbar. */
663 box2 = clutter_box_new (layout2);
665 clutter_actor_set_size (box2,
666 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
667 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
669 clutter_container_add_actor (CLUTTER_CONTAINER (box1), box2);
670 clutter_container_add_actor (CLUTTER_CONTAINER (box2), CLUTTER_ACTOR (rectangle));
672 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (self->priv->video_layout),
675 clutter_actor_hide (CLUTTER_ACTOR (rectangle));
677 return CLUTTER_ACTOR (rectangle);
681 empathy_call_window_create_preview_rectangles (EmpathyCallWindow *self)
683 self->priv->preview_rectangle1 =
684 empathy_call_window_create_preview_rectangle (self,
685 &self->priv->preview_rectangle_box1,
686 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_START);
687 self->priv->preview_rectangle2 =
688 empathy_call_window_create_preview_rectangle (self,
689 &self->priv->preview_rectangle_box2,
690 CLUTTER_BIN_ALIGNMENT_START, CLUTTER_BIN_ALIGNMENT_END);
691 self->priv->preview_rectangle3 =
692 empathy_call_window_create_preview_rectangle (self,
693 &self->priv->preview_rectangle_box3,
694 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_START);
695 self->priv->preview_rectangle4 =
696 empathy_call_window_create_preview_rectangle (self,
697 &self->priv->preview_rectangle_box4,
698 CLUTTER_BIN_ALIGNMENT_END, CLUTTER_BIN_ALIGNMENT_END);
702 empathy_call_window_show_preview_rectangles (EmpathyCallWindow *self,
705 g_object_set (self->priv->preview_rectangle1, "visible", show, NULL);
706 g_object_set (self->priv->preview_rectangle2, "visible", show, NULL);
707 g_object_set (self->priv->preview_rectangle3, "visible", show, NULL);
708 g_object_set (self->priv->preview_rectangle4, "visible", show, NULL);
712 empathy_call_window_get_preview_coordinates (EmpathyCallWindow *self,
717 guint ret_x = 0, ret_y = 0;
720 if (!clutter_actor_has_allocation (self->priv->video_box))
723 clutter_actor_get_geometry (self->priv->video_box, &box);
727 case PREVIEW_POS_TOP_LEFT:
728 ret_x = ret_y = SELF_VIDEO_SECTION_MARGIN;
730 case PREVIEW_POS_TOP_RIGHT:
731 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
732 - SELF_VIDEO_SECTION_WIDTH;
733 ret_y = SELF_VIDEO_SECTION_MARGIN;
735 case PREVIEW_POS_BOTTOM_LEFT:
736 ret_x = SELF_VIDEO_SECTION_MARGIN;
737 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
738 - SELF_VIDEO_SECTION_HEIGHT
739 - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING;
741 case PREVIEW_POS_BOTTOM_RIGHT:
742 ret_x = box.width - SELF_VIDEO_SECTION_MARGIN
743 - SELF_VIDEO_SECTION_WIDTH;
744 ret_y = box.height - SELF_VIDEO_SECTION_MARGIN
745 - SELF_VIDEO_SECTION_HEIGHT - FLOATING_TOOLBAR_HEIGHT
746 - FLOATING_TOOLBAR_SPACING;
749 g_warn_if_reached ();
760 static PreviewPosition
761 empathy_call_window_get_preview_position (EmpathyCallWindow *self,
766 PreviewPosition pos = PREVIEW_POS_NONE;
768 if (!clutter_actor_has_allocation (self->priv->video_box))
771 clutter_actor_get_geometry (self->priv->video_box, &box);
773 if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
774 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
775 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
776 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
778 pos = PREVIEW_POS_TOP_LEFT;
780 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
781 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
782 0 + SELF_VIDEO_SECTION_MARGIN <= event_y &&
783 event_y <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_HEIGHT))
785 pos = PREVIEW_POS_TOP_RIGHT;
787 else if (0 + SELF_VIDEO_SECTION_MARGIN <= event_x &&
788 event_x <= (0 + SELF_VIDEO_SECTION_MARGIN + (gint) SELF_VIDEO_SECTION_WIDTH) &&
789 box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
790 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
792 pos = PREVIEW_POS_BOTTOM_LEFT;
794 else if (box.width - SELF_VIDEO_SECTION_MARGIN >= event_x &&
795 event_x >= (box.width - SELF_VIDEO_SECTION_MARGIN - (gint) SELF_VIDEO_SECTION_WIDTH) &&
796 box.height - 2 * SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING >= event_y &&
797 event_y >= (box.height - SELF_VIDEO_SECTION_MARGIN - FLOATING_TOOLBAR_HEIGHT - FLOATING_TOOLBAR_SPACING - (gint) SELF_VIDEO_SECTION_HEIGHT))
799 pos = PREVIEW_POS_BOTTOM_RIGHT;
805 static ClutterActor *
806 empathy_call_window_get_preview_rectangle (EmpathyCallWindow *self,
809 ClutterActor *rectangle;
813 case PREVIEW_POS_TOP_LEFT:
814 rectangle = self->priv->preview_rectangle1;
816 case PREVIEW_POS_TOP_RIGHT:
817 rectangle = self->priv->preview_rectangle3;
819 case PREVIEW_POS_BOTTOM_LEFT:
820 rectangle = self->priv->preview_rectangle2;
822 case PREVIEW_POS_BOTTOM_RIGHT:
823 rectangle = self->priv->preview_rectangle4;
833 empathy_call_window_move_video_preview (EmpathyCallWindow *self,
836 ClutterBinLayout *layout = CLUTTER_BIN_LAYOUT (self->priv->video_layout);
838 DEBUG ("moving the video preview to %d", pos);
840 self->priv->preview_pos = pos;
844 case PREVIEW_POS_TOP_LEFT:
845 clutter_bin_layout_set_alignment (layout,
846 self->priv->video_preview,
847 CLUTTER_BIN_ALIGNMENT_START,
848 CLUTTER_BIN_ALIGNMENT_START);
850 case PREVIEW_POS_TOP_RIGHT:
851 clutter_bin_layout_set_alignment (layout,
852 self->priv->video_preview,
853 CLUTTER_BIN_ALIGNMENT_END,
854 CLUTTER_BIN_ALIGNMENT_START);
856 case PREVIEW_POS_BOTTOM_LEFT:
857 clutter_bin_layout_set_alignment (layout,
858 self->priv->video_preview,
859 CLUTTER_BIN_ALIGNMENT_START,
860 CLUTTER_BIN_ALIGNMENT_END);
862 case PREVIEW_POS_BOTTOM_RIGHT:
863 clutter_bin_layout_set_alignment (layout,
864 self->priv->video_preview,
865 CLUTTER_BIN_ALIGNMENT_END,
866 CLUTTER_BIN_ALIGNMENT_END);
869 g_warn_if_reached ();
872 g_settings_set_enum (self->priv->settings, "camera-position", pos);
876 _clutter_color_from_rgba (ClutterColor *color,
879 color->red = (guint8) floor (rgba->red * 255);
880 color->green = (guint8) floor (rgba->green * 255);
881 color->blue = (guint8) floor (rgba->blue * 255);
882 color->alpha = (guint8) floor (rgba->alpha * 255);
886 empathy_call_window_highlight_preview_rectangle (EmpathyCallWindow *self,
889 ClutterActor *rectangle;
890 GtkStyleContext *context;
892 ClutterColor color, highlight;
894 rectangle = empathy_call_window_get_preview_rectangle (self, pos);
895 context = gtk_widget_get_style_context (GTK_WIDGET (self));
896 gtk_style_context_get_color (context, 0, &rgba);
898 _clutter_color_from_rgba (&color, &rgba);
899 clutter_color_shade (&color, 1.4, &highlight);
901 empathy_rounded_rectangle_set_border_width (
902 EMPATHY_ROUNDED_RECTANGLE (rectangle), 2 * SELF_VIDEO_SECTION_MARGIN);
903 empathy_rounded_rectangle_set_border_color (
904 EMPATHY_ROUNDED_RECTANGLE (rectangle), &highlight);
908 empathy_call_window_darken_preview_rectangle (EmpathyCallWindow *self,
909 ClutterActor *rectangle)
911 GtkStyleContext *context;
913 ClutterColor color, darker;
915 context = gtk_widget_get_style_context (GTK_WIDGET (self));
916 gtk_style_context_get_background_color (context, 0, &rgba);
918 _clutter_color_from_rgba (&color, &rgba);
919 clutter_color_shade (&color, 0.55, &darker);
921 empathy_rounded_rectangle_set_border_width (
922 EMPATHY_ROUNDED_RECTANGLE (rectangle), 1);
923 empathy_rounded_rectangle_set_border_color (
924 EMPATHY_ROUNDED_RECTANGLE (rectangle), &darker);
928 empathy_call_window_darken_preview_rectangles (EmpathyCallWindow *self)
930 ClutterActor *rectangle;
932 rectangle = empathy_call_window_get_preview_rectangle (self,
933 self->priv->preview_pos);
935 /* We don't want to darken the rectangle where the preview
938 if (self->priv->preview_rectangle1 != rectangle)
939 empathy_call_window_darken_preview_rectangle (self,
940 self->priv->preview_rectangle1);
942 if (self->priv->preview_rectangle2 != rectangle)
943 empathy_call_window_darken_preview_rectangle (self,
944 self->priv->preview_rectangle2);
946 if (self->priv->preview_rectangle3 != rectangle)
947 empathy_call_window_darken_preview_rectangle (self,
948 self->priv->preview_rectangle3);
950 if (self->priv->preview_rectangle4 != rectangle)
951 empathy_call_window_darken_preview_rectangle (self,
952 self->priv->preview_rectangle4);
956 empathy_call_window_preview_on_drag_begin_cb (ClutterDragAction *action,
960 ClutterModifierType modifiers,
961 EmpathyCallWindow *self)
963 ClutterActor *stage = clutter_actor_get_stage (actor);
966 self->priv->drag_preview = clutter_clone_new (actor);
968 clutter_container_add_actor (CLUTTER_CONTAINER (stage),
969 self->priv->drag_preview);
971 clutter_actor_transform_stage_point (actor, event_x, event_y,
974 clutter_actor_set_position (self->priv->drag_preview,
975 event_x - rel_x, event_y - rel_y);
977 clutter_drag_action_set_drag_handle (action,
978 self->priv->drag_preview);
980 clutter_actor_set_opacity (actor, 0);
981 clutter_actor_hide (self->priv->preview_shown_button);
983 empathy_call_window_show_preview_rectangles (self, TRUE);
984 empathy_call_window_darken_preview_rectangles (self);
988 empathy_call_window_on_animation_completed_cb (ClutterAnimation *animation,
991 clutter_actor_set_opacity (actor, 255);
995 empathy_call_window_preview_on_drag_end_cb (ClutterDragAction *action,
999 ClutterModifierType modifiers,
1000 EmpathyCallWindow *self)
1002 PreviewPosition pos;
1005 /* Get the position before destroying the drag actor, otherwise the
1006 * preview_box allocation won't be valid and we won't be able to
1007 * calculate the position. */
1008 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
1010 empathy_call_window_get_preview_coordinates (self,
1011 pos != PREVIEW_POS_NONE ? pos : self->priv->preview_pos,
1014 /* Move the preview to the destination and destroy it afterwards */
1015 clutter_actor_animate (self->priv->drag_preview, CLUTTER_LINEAR, 500,
1018 "signal-swapped-after::completed",
1019 clutter_actor_destroy, self->priv->drag_preview,
1020 "signal-swapped-after::completed",
1021 clutter_actor_show, self->priv->preview_shown_button,
1022 "signal::completed",
1023 empathy_call_window_on_animation_completed_cb, actor,
1026 self->priv->drag_preview = NULL;
1028 if (pos != PREVIEW_POS_NONE)
1029 empathy_call_window_move_video_preview (self, pos);
1031 empathy_call_window_show_preview_rectangles (self, FALSE);
1035 empathy_call_window_preview_on_drag_motion_cb (ClutterDragAction *action,
1036 ClutterActor *actor,
1039 EmpathyCallWindow *self)
1041 PreviewPosition pos;
1042 gfloat event_x, event_y;
1044 clutter_drag_action_get_motion_coords (action, &event_x, &event_y);
1046 pos = empathy_call_window_get_preview_position (self, event_x, event_y);
1048 if (pos != PREVIEW_POS_NONE)
1049 empathy_call_window_highlight_preview_rectangle (self, pos);
1051 empathy_call_window_darken_preview_rectangles (self);
1055 empathy_call_window_preview_enter_event_cb (ClutterActor *actor,
1056 ClutterCrossingEvent *event,
1057 EmpathyCallWindow *self)
1059 ClutterActor *rectangle;
1061 rectangle = empathy_call_window_get_preview_rectangle (self,
1062 self->priv->preview_pos);
1064 empathy_call_window_highlight_preview_rectangle (self,
1065 self->priv->preview_pos);
1067 clutter_actor_show (rectangle);
1073 empathy_call_window_preview_leave_event_cb (ClutterActor *actor,
1074 ClutterCrossingEvent *event,
1075 EmpathyCallWindow *self)
1077 ClutterActor *rectangle;
1079 rectangle = empathy_call_window_get_preview_rectangle (self,
1080 self->priv->preview_pos);
1082 empathy_call_window_darken_preview_rectangle (self, rectangle);
1084 clutter_actor_hide (rectangle);
1090 create_video_preview (EmpathyCallWindow *self)
1092 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1093 ClutterLayoutManager *layout, *layout_center, *layout_end;
1094 ClutterActor *preview;
1097 ClutterAction *action;
1099 PreviewPosition pos;
1100 GdkRGBA transparent = { 0., 0., 0., 0. };
1103 g_assert (priv->video_preview == NULL);
1105 pos = g_settings_get_enum (priv->settings, "camera-position");
1107 preview = empathy_rounded_texture_new ();
1108 clutter_actor_set_size (preview,
1109 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1111 priv->video_preview_sink = gst_element_factory_make ("cluttersink", NULL);
1112 if (priv->video_preview_sink == NULL)
1113 g_error ("Missing cluttersink, check your clutter-gst installation");
1114 g_object_set (priv->video_preview_sink, "texture", preview, NULL);
1115 g_object_add_weak_pointer (G_OBJECT (priv->video_preview_sink), (gpointer) &priv->video_preview_sink);
1117 /* Add a little offset to the video preview */
1118 layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1119 CLUTTER_BIN_ALIGNMENT_START);
1120 priv->video_preview = clutter_box_new (layout);
1121 clutter_actor_set_size (priv->video_preview,
1122 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1123 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN +
1124 FLOATING_TOOLBAR_HEIGHT + FLOATING_TOOLBAR_SPACING);
1126 /* Spinner for when changing the camera device */
1127 priv->preview_spinner_widget = gtk_spinner_new ();
1128 priv->preview_spinner_actor = empathy_rounded_actor_new (PREVIEW_ROUND_FACTOR);
1130 g_object_set (priv->preview_spinner_widget, "expand", TRUE, NULL);
1131 gtk_widget_override_background_color (
1132 gtk_clutter_actor_get_widget (
1133 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor)),
1134 GTK_STATE_FLAG_NORMAL, &transparent);
1135 gtk_widget_show (priv->preview_spinner_widget);
1138 GTK_CONTAINER (gtk_clutter_actor_get_widget (
1139 GTK_CLUTTER_ACTOR (priv->preview_spinner_actor))),
1140 priv->preview_spinner_widget);
1141 clutter_actor_set_size (priv->preview_spinner_actor,
1142 SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
1143 clutter_actor_set_opacity (priv->preview_spinner_actor, 128);
1144 clutter_actor_hide (priv->preview_spinner_actor);
1146 /* We have a box with the margins and the video in the middle inside
1147 * a bigger box with an extra bottom margin so we're not on top of
1148 * the floating toolbar. */
1149 layout_center = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1150 CLUTTER_BIN_ALIGNMENT_CENTER);
1151 box = clutter_box_new (layout_center);
1152 clutter_actor_set_size (box,
1153 SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
1154 SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
1156 clutter_container_add_actor (CLUTTER_CONTAINER (box), preview);
1157 clutter_container_add_actor (CLUTTER_CONTAINER (box),
1158 priv->preview_spinner_actor);
1159 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1161 g_object_set (priv->video_preview_sink,
1166 /* Translators: this is an "Info" label. It should be as short
1168 button = gtk_button_new_with_label (_("i"));
1169 priv->preview_shown_button = b = gtk_clutter_actor_new_with_contents (button);
1170 clutter_actor_set_size (b, 24, 24);
1171 bin = gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (b));
1172 gtk_widget_override_background_color (bin, GTK_STATE_FLAG_NORMAL, &transparent);
1174 layout_end = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_END,
1175 CLUTTER_BIN_ALIGNMENT_END);
1176 box = clutter_box_new (layout_end);
1177 clutter_actor_set_size (box,
1178 SELF_VIDEO_SECTION_WIDTH - 4,
1179 SELF_VIDEO_SECTION_HEIGHT - 2);
1181 clutter_container_add_actor (CLUTTER_CONTAINER (box), b);
1182 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_preview), box);
1184 g_signal_connect (button, "clicked",
1185 G_CALLBACK (empathy_call_window_preview_button_clicked_cb),
1188 /* Translators: this is an "Info" label. It should be as short
1190 button = gtk_button_new_with_label (_("i"));
1191 priv->preview_hidden_button = b = gtk_clutter_actor_new_with_contents (button);
1192 clutter_actor_set_size (b, 24, 24);
1193 gtk_widget_override_background_color (bin, GTK_STATE_FLAG_NORMAL, &transparent);
1195 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1196 priv->preview_hidden_button,
1197 CLUTTER_BIN_ALIGNMENT_START,
1198 CLUTTER_BIN_ALIGNMENT_END);
1200 self->priv->preview_pos = PREVIEW_POS_BOTTOM_LEFT;
1202 clutter_actor_hide (priv->preview_hidden_button);
1204 g_signal_connect (button, "clicked",
1205 G_CALLBACK (empathy_call_window_preview_hidden_button_clicked_cb),
1208 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1209 priv->video_preview,
1210 CLUTTER_BIN_ALIGNMENT_START,
1211 CLUTTER_BIN_ALIGNMENT_END);
1213 empathy_call_window_move_video_preview (self, pos);
1215 action = clutter_drag_action_new ();
1216 g_signal_connect (action, "drag-begin",
1217 G_CALLBACK (empathy_call_window_preview_on_drag_begin_cb), self);
1218 g_signal_connect (action, "drag-end",
1219 G_CALLBACK (empathy_call_window_preview_on_drag_end_cb), self);
1220 g_signal_connect (action, "drag-motion",
1221 G_CALLBACK (empathy_call_window_preview_on_drag_motion_cb), self);
1223 g_signal_connect (preview, "enter-event",
1224 G_CALLBACK (empathy_call_window_preview_enter_event_cb), self);
1225 g_signal_connect (preview, "leave-event",
1226 G_CALLBACK (empathy_call_window_preview_leave_event_cb), self);
1228 clutter_actor_add_action (preview, action);
1229 clutter_actor_set_reactive (preview, TRUE);
1230 clutter_actor_set_reactive (priv->preview_shown_button, TRUE);
1234 empathy_call_window_start_camera_spinning (EmpathyCallWindow *self)
1236 clutter_actor_show (self->priv->preview_spinner_actor);
1237 gtk_spinner_start (GTK_SPINNER (self->priv->preview_spinner_widget));
1241 empathy_call_window_stop_camera_spinning (EmpathyCallWindow *self)
1243 clutter_actor_hide (self->priv->preview_spinner_actor);
1244 gtk_spinner_stop (GTK_SPINNER (self->priv->preview_spinner_widget));
1248 empathy_call_window_play_camera (EmpathyCallWindow *self,
1251 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1252 GstElement *preview;
1255 if (priv->video_preview == NULL)
1257 create_video_preview (self);
1258 add_video_preview_to_pipeline (self);
1263 state = GST_STATE_PLAYING;
1267 empathy_call_window_start_camera_spinning (self);
1268 state = GST_STATE_NULL;
1271 preview = priv->video_preview_sink;
1273 gst_element_set_state (preview, state);
1274 gst_element_set_state (priv->video_tee, state);
1275 gst_element_set_state (priv->video_input, state);
1279 display_video_preview (EmpathyCallWindow *self,
1282 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1284 if (priv->video_preview == NULL)
1286 create_video_preview (self);
1287 add_video_preview_to_pipeline (self);
1292 /* Display the video preview */
1293 DEBUG ("Show video preview");
1295 empathy_call_window_play_camera (self, TRUE);
1296 clutter_actor_show (priv->video_preview);
1297 clutter_actor_raise_top (priv->floating_toolbar);
1301 /* Hide the video preview */
1302 DEBUG ("Hide video preview");
1304 if (priv->video_preview != NULL)
1306 clutter_actor_hide (priv->video_preview);
1307 empathy_call_window_play_camera (self, FALSE);
1313 empathy_call_window_set_state_connecting (EmpathyCallWindow *window)
1315 EmpathyCallWindowPriv *priv = GET_PRIV (window);
1317 empathy_call_window_status_message (window, _("Connecting…"));
1318 priv->call_state = CONNECTING;
1320 /* Show the toolbar */
1321 clutter_state_set_state (priv->transitions, "fade-in");
1324 empathy_sound_manager_start_playing (priv->sound_mgr, GTK_WIDGET (window),
1325 EMPATHY_SOUND_PHONE_OUTGOING, MS_BETWEEN_RING);
1329 disable_camera (EmpathyCallWindow *self)
1331 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1333 if (priv->camera_state == CAMERA_STATE_OFF)
1336 DEBUG ("Disable camera");
1338 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
1340 priv->camera_state = CAMERA_STATE_OFF;
1344 enable_camera (EmpathyCallWindow *self)
1346 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1348 if (priv->camera_state == CAMERA_STATE_ON)
1351 if (priv->video_input == NULL)
1353 DEBUG ("Can't enable camera, no input");
1357 DEBUG ("Enable camera");
1359 empathy_call_window_set_send_video (self, CAMERA_STATE_ON);
1361 priv->camera_state = CAMERA_STATE_ON;
1365 empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
1366 EmpathyCallWindow *self)
1368 if (gtk_toggle_tool_button_get_active (toggle))
1369 enable_camera (self);
1371 disable_camera (self);
1375 create_pipeline (EmpathyCallWindow *self)
1377 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1380 g_assert (priv->pipeline == NULL);
1382 priv->pipeline = gst_pipeline_new (NULL);
1383 priv->pipeline_playing = FALSE;
1385 priv->video_tee = gst_element_factory_make ("tee", NULL);
1386 gst_object_ref (priv->video_tee);
1387 gst_object_sink (priv->video_tee);
1389 gst_bin_add (GST_BIN (priv->pipeline), priv->video_tee);
1391 bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
1392 priv->bus_message_source_id = gst_bus_add_watch (bus,
1393 empathy_call_window_bus_message, self);
1395 g_object_unref (bus);
1399 empathy_call_window_settings_cb (GtkAction *action,
1400 EmpathyCallWindow *self)
1402 gchar *args = g_strdup_printf ("-p %s",
1403 empathy_preferences_tab_to_string (EMPATHY_PREFERENCES_TAB_CALLS));
1405 empathy_launch_program (BIN_DIR, "empathy", args);
1411 empathy_call_window_contents_cb (GtkAction *action,
1412 EmpathyCallWindow *self)
1414 empathy_url_show (GTK_WIDGET (self), "help:empathy/audio-video");
1418 empathy_call_window_debug_cb (GtkAction *action,
1419 EmpathyCallWindow *self)
1421 empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
1425 empathy_call_window_about_cb (GtkAction *action,
1426 EmpathyCallWindow *self)
1428 empathy_about_dialog_new (GTK_WINDOW (self));
1432 empathy_call_window_toolbar_timeout (gpointer data)
1434 EmpathyCallWindow *self = data;
1436 /* We don't want to hide the toolbar if we're not in a call, as
1437 * to show the call status all the time. */
1438 if (self->priv->call_state != CONNECTING &&
1439 self->priv->call_state != DISCONNECTED)
1440 clutter_state_set_state (self->priv->transitions, "fade-out");
1446 empathy_call_window_motion_notify_cb (GtkWidget *widget,
1448 EmpathyCallWindow *self)
1450 clutter_state_set_state (self->priv->transitions, "fade-in");
1452 if (self->priv->inactivity_src > 0)
1453 g_source_remove (self->priv->inactivity_src);
1455 self->priv->inactivity_src = g_timeout_add_seconds (3,
1456 empathy_call_window_toolbar_timeout, self);
1462 empathy_call_window_configure_event_cb (GtkWidget *widget,
1464 EmpathyCallWindow *self)
1466 GdkWindow *gdk_window;
1467 GdkWindowState window_state;
1469 gtk_window_get_position (GTK_WINDOW (self), &self->priv->x, &self->priv->y);
1470 gtk_window_get_size (GTK_WINDOW (self), &self->priv->w, &self->priv->h);
1472 gtk_widget_get_preferred_width (self->priv->dtmf_panel,
1473 &self->priv->dialpad_width, NULL);
1475 gdk_window = gtk_widget_get_window (widget);
1476 window_state = gdk_window_get_state (gdk_window);
1477 self->priv->maximized = (window_state & GDK_WINDOW_STATE_MAXIMIZED);
1483 empathy_call_window_destroyed_cb (GtkWidget *object,
1484 EmpathyCallWindow *self)
1486 if (gtk_widget_get_visible (self->priv->dtmf_panel))
1488 /* Save the geometry as if the dialpad was hidden. */
1489 empathy_geometry_save_values (GTK_WINDOW (self),
1490 self->priv->x, self->priv->y,
1491 self->priv->w - self->priv->dialpad_width, self->priv->h,
1492 self->priv->maximized);
1497 empathy_call_window_stage_allocation_changed_cb (ClutterActor *stage,
1499 ClutterBindConstraint *constraint)
1501 ClutterActorBox allocation;
1503 clutter_actor_get_allocation_box (stage, &allocation);
1505 clutter_bind_constraint_set_offset (constraint,
1506 allocation.y2 - allocation.y1 -
1507 FLOATING_TOOLBAR_SPACING - FLOATING_TOOLBAR_HEIGHT);
1511 empathy_call_window_incoming_call_response_cb (GtkDialog *dialog,
1513 EmpathyCallWindow *self)
1515 switch (response_id)
1517 case GTK_RESPONSE_ACCEPT:
1518 tp_channel_dispatch_operation_handle_with_async (
1519 self->priv->pending_cdo, EMPATHY_CALL_BUS_NAME, NULL, NULL);
1521 tp_clear_object (&self->priv->pending_cdo);
1522 tp_clear_object (&self->priv->pending_channel);
1523 tp_clear_object (&self->priv->pending_context);
1526 case GTK_RESPONSE_CANCEL:
1527 tp_channel_dispatch_operation_close_channels_async (
1528 self->priv->pending_cdo, NULL, NULL);
1530 empathy_call_window_status_message (self, _("Disconnected"));
1531 self->priv->call_state = DISCONNECTED;
1534 g_warn_if_reached ();
1539 empathy_call_window_set_state_ringing (EmpathyCallWindow *self)
1543 g_assert (self->priv->call_state != CONNECTED);
1545 video = tp_call_channel_has_initial_video (self->priv->pending_channel, NULL);
1547 empathy_call_window_status_message (self, _("Incoming call"));
1548 self->priv->call_state = RINGING;
1550 self->priv->incoming_call_dialog = gtk_message_dialog_new (
1551 GTK_WINDOW (self), GTK_DIALOG_MODAL,
1552 GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
1553 video ? _("Incoming video call from %s") : _("Incoming call from %s"),
1554 empathy_contact_get_alias (self->priv->contact));
1556 gtk_dialog_add_buttons (GTK_DIALOG (self->priv->incoming_call_dialog),
1557 _("Reject"), GTK_RESPONSE_CANCEL,
1558 _("Answer"), GTK_RESPONSE_ACCEPT,
1561 g_signal_connect (self->priv->incoming_call_dialog, "response",
1562 G_CALLBACK (empathy_call_window_incoming_call_response_cb), self);
1563 gtk_widget_show (self->priv->incoming_call_dialog);
1567 empathy_call_window_cdo_invalidated_cb (TpProxy *channel,
1571 EmpathyCallWindow *self)
1573 tp_clear_object (&self->priv->pending_cdo);
1574 tp_clear_object (&self->priv->pending_channel);
1575 tp_clear_object (&self->priv->pending_context);
1577 /* We don't know if the incoming call has been accepted or not, so we
1578 * assume it hasn't and if it has, we'll set the proper status when
1579 * we get the new handler. */
1580 empathy_call_window_status_message (self, _("Disconnected"));
1581 self->priv->call_state = DISCONNECTED;
1583 gtk_widget_destroy (self->priv->incoming_call_dialog);
1584 self->priv->incoming_call_dialog = NULL;
1588 empathy_call_window_start_ringing (EmpathyCallWindow *self,
1589 TpCallChannel *channel,
1590 TpChannelDispatchOperation *dispatch_operation,
1591 TpAddDispatchOperationContext *context)
1593 g_assert (self->priv->pending_channel == NULL);
1594 g_assert (self->priv->pending_context == NULL);
1595 g_assert (self->priv->pending_cdo == NULL);
1597 /* Start ringing and delay until the user answers or hangs. */
1598 self->priv->pending_channel = g_object_ref (channel);
1599 self->priv->pending_context = g_object_ref (context);
1600 self->priv->pending_cdo = g_object_ref (dispatch_operation);
1602 g_signal_connect (self->priv->pending_cdo, "invalidated",
1603 G_CALLBACK (empathy_call_window_cdo_invalidated_cb), self);
1605 empathy_call_window_set_state_ringing (self);
1606 tp_add_dispatch_operation_context_accept (context);
1610 empathy_call_window_init (EmpathyCallWindow *self)
1612 EmpathyCallWindowPriv *priv;
1614 GtkWidget *top_vbox;
1616 ClutterConstraint *constraint;
1617 ClutterActor *remote_avatar;
1618 GtkStyleContext *context;
1622 priv = self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
1623 EMPATHY_TYPE_CALL_WINDOW, EmpathyCallWindowPriv);
1625 priv->settings = g_settings_new (EMPATHY_PREFS_CALL_SCHEMA);
1627 filename = empathy_file_lookup ("empathy-call-window.ui", "src");
1628 gui = empathy_builder_get_file (filename,
1629 "call_window_vbox", &top_vbox,
1630 "errors_vbox", &priv->errors_vbox,
1631 "pane", &priv->pane,
1632 "remote_user_name_toolbar", &priv->remote_user_name_toolbar,
1633 "remote_user_avatar_toolbar", &priv->remote_user_avatar_toolbar,
1634 "status_label", &priv->status_label,
1635 "audiocall", &priv->audio_call_button,
1636 "videocall", &priv->video_call_button,
1637 "microphone", &priv->mic_button,
1638 "volume", &priv->volume_button,
1639 "camera", &priv->camera_button,
1640 "hangup", &priv->hangup_button,
1641 "dialpad", &priv->dialpad_button,
1642 "toolbar", &priv->toolbar,
1643 "bottom_toolbar", &priv->bottom_toolbar,
1644 "ui_manager", &priv->ui_manager,
1645 "menufullscreen", &priv->menu_fullscreen,
1646 "menupreviewswap", &priv->menu_swap_camera,
1647 "details_vbox", &priv->details_vbox,
1648 "vcodec_encoding_label", &priv->vcodec_encoding_label,
1649 "acodec_encoding_label", &priv->acodec_encoding_label,
1650 "acodec_decoding_label", &priv->acodec_decoding_label,
1651 "vcodec_decoding_label", &priv->vcodec_decoding_label,
1652 "audio_remote_candidate_label", &priv->audio_remote_candidate_label,
1653 "audio_local_candidate_label", &priv->audio_local_candidate_label,
1654 "video_remote_candidate_label", &priv->video_remote_candidate_label,
1655 "video_local_candidate_label", &priv->video_local_candidate_label,
1656 "video_remote_candidate_info_img", &priv->video_remote_candidate_info_img,
1657 "video_local_candidate_info_img", &priv->video_local_candidate_info_img,
1658 "audio_remote_candidate_info_img", &priv->audio_remote_candidate_info_img,
1659 "audio_local_candidate_info_img", &priv->audio_local_candidate_info_img,
1663 empathy_builder_connect (gui, self,
1664 "hangup", "clicked", empathy_call_window_hangup_cb,
1665 "audiocall", "clicked", empathy_call_window_audio_call_cb,
1666 "videocall", "clicked", empathy_call_window_video_call_cb,
1667 "camera", "toggled", empathy_call_window_camera_toggled_cb,
1668 "dialpad", "toggled", empathy_call_window_dialpad_cb,
1669 "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
1670 "menusettings", "activate", empathy_call_window_settings_cb,
1671 "menucontents", "activate", empathy_call_window_contents_cb,
1672 "menudebug", "activate", empathy_call_window_debug_cb,
1673 "menuabout", "activate", empathy_call_window_about_cb,
1674 "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
1675 "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
1676 "menupreviewmaximise", "activate", empathy_call_window_maximise_camera_cb,
1677 "menupreviewswap", "activate", empathy_call_window_swap_camera_cb,
1680 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
1682 priv->camera_monitor = empathy_camera_monitor_dup_singleton ();
1684 g_object_bind_property (priv->camera_monitor, "available",
1685 priv->camera_button, "sensitive",
1686 G_BINDING_SYNC_CREATE);
1688 g_signal_connect (priv->camera_monitor, "added",
1689 G_CALLBACK (empathy_call_window_camera_added_cb), self);
1690 g_signal_connect (priv->camera_monitor, "removed",
1691 G_CALLBACK (empathy_call_window_camera_removed_cb), self);
1693 priv->lock = g_mutex_new ();
1695 gtk_container_add (GTK_CONTAINER (self), top_vbox);
1697 priv->content_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL,
1698 CONTENT_HBOX_SPACING);
1699 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
1700 CONTENT_HBOX_BORDER_WIDTH);
1701 gtk_box_pack_start (GTK_BOX (priv->pane), priv->content_hbox,
1704 /* avatar/video box */
1705 priv->video_layout = clutter_bin_layout_new (CLUTTER_BIN_ALIGNMENT_CENTER,
1706 CLUTTER_BIN_ALIGNMENT_CENTER);
1708 priv->video_box = clutter_box_new (priv->video_layout);
1710 priv->video_container = gtk_clutter_embed_new ();
1712 gtk_widget_set_size_request (priv->video_container,
1713 EMPATHY_VIDEO_WIDGET_DEFAULT_WIDTH, EMPATHY_VIDEO_WIDGET_DEFAULT_HEIGHT);
1715 /* Set the background color to that of the rest of the window */
1716 context = gtk_widget_get_style_context (priv->content_hbox);
1717 gtk_style_context_get_background_color (context,
1718 GTK_STATE_FLAG_NORMAL, &rgba);
1719 bg.red = CLAMP (rgba.red * 255.0, 0, 255);
1720 bg.green = CLAMP (rgba.green * 255.0, 0, 255);
1721 bg.blue = CLAMP (rgba.blue * 255.0, 0, 255);
1722 bg.alpha = CLAMP (rgba.alpha * 255.0, 0, 255);
1723 clutter_stage_set_color (
1724 CLUTTER_STAGE (gtk_clutter_embed_get_stage (
1725 GTK_CLUTTER_EMBED (priv->video_container))),
1728 clutter_container_add (
1729 CLUTTER_CONTAINER (gtk_clutter_embed_get_stage (
1730 GTK_CLUTTER_EMBED (priv->video_container))),
1734 constraint = clutter_bind_constraint_new (
1735 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1736 CLUTTER_BIND_SIZE, 0);
1737 clutter_actor_add_constraint (priv->video_box, constraint);
1739 priv->remote_user_avatar_widget = gtk_image_new ();
1740 remote_avatar = gtk_clutter_actor_new_with_contents (
1741 priv->remote_user_avatar_widget);
1743 clutter_container_add_actor (CLUTTER_CONTAINER (priv->video_box),
1746 empathy_call_window_create_preview_rectangles (self);
1748 gtk_box_pack_start (GTK_BOX (priv->content_hbox),
1749 priv->video_container, TRUE, TRUE,
1750 CONTENT_HBOX_CHILDREN_PACKING_PADDING);
1752 create_pipeline (self);
1753 create_video_output_widget (self);
1754 create_audio_input (self);
1755 create_video_input (self);
1757 priv->floating_toolbar = empathy_rounded_actor_new (2);
1759 gtk_widget_reparent (priv->bottom_toolbar,
1760 gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (priv->floating_toolbar)));
1762 constraint = clutter_bind_constraint_new (
1763 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1766 clutter_actor_add_constraint (priv->floating_toolbar, constraint);
1769 gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (priv->video_container)),
1770 "notify::allocation",
1771 G_CALLBACK (empathy_call_window_stage_allocation_changed_cb),
1774 clutter_actor_set_size (priv->floating_toolbar,
1775 FLOATING_TOOLBAR_WIDTH, FLOATING_TOOLBAR_HEIGHT);
1776 clutter_actor_set_opacity (priv->floating_toolbar, FLOATING_TOOLBAR_OPACITY);
1778 clutter_bin_layout_add (CLUTTER_BIN_LAYOUT (priv->video_layout),
1779 priv->floating_toolbar,
1780 CLUTTER_BIN_ALIGNMENT_CENTER,
1781 CLUTTER_BIN_ALIGNMENT_END);
1783 clutter_actor_raise_top (priv->floating_toolbar);
1785 /* Transitions for the floating toolbar */
1786 priv->transitions = clutter_state_new ();
1788 /* all transitions last for 2s */
1789 clutter_state_set_duration (priv->transitions, NULL, NULL, 2000);
1791 /* transition from any state to "fade-out" state */
1792 clutter_state_set (priv->transitions, NULL, "fade-out",
1793 priv->floating_toolbar,
1794 "opacity", CLUTTER_EASE_OUT_QUAD, 0,
1797 /* transition from any state to "fade-in" state */
1798 clutter_state_set (priv->transitions, NULL, "fade-in",
1799 priv->floating_toolbar,
1800 "opacity", CLUTTER_EASE_OUT_QUAD, FLOATING_TOOLBAR_OPACITY,
1803 /* put the actor into the "fade-in" state with no animation */
1804 clutter_state_warp_to_state (priv->transitions, "fade-in");
1806 /* The call will be started as soon the pipeline is playing */
1807 priv->start_call_when_playing = TRUE;
1809 priv->dtmf_panel = empathy_dialpad_widget_new ();
1810 g_signal_connect (priv->dtmf_panel, "start-tone",
1811 G_CALLBACK (dtmf_start_tone_cb), self);
1813 gtk_box_pack_start (GTK_BOX (priv->pane), priv->dtmf_panel,
1816 gtk_box_pack_start (GTK_BOX (priv->pane), priv->details_vbox,
1819 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
1821 gtk_widget_show_all (top_vbox);
1823 gtk_widget_hide (priv->dtmf_panel);
1824 gtk_widget_hide (priv->details_vbox);
1826 priv->fullscreen = empathy_call_window_fullscreen_new (self);
1828 empathy_call_window_fullscreen_set_video_widget (priv->fullscreen,
1829 priv->video_container);
1831 /* We hide the bottom toolbar after 3s of inactivity and show it
1832 * again on mouse movement */
1833 priv->inactivity_src = g_timeout_add_seconds (3,
1834 empathy_call_window_toolbar_timeout, self);
1836 g_signal_connect (G_OBJECT (priv->fullscreen->leave_fullscreen_button),
1837 "clicked", G_CALLBACK (empathy_call_window_fullscreen_cb), self);
1839 g_signal_connect (G_OBJECT (self), "realize",
1840 G_CALLBACK (empathy_call_window_realized_cb), self);
1842 g_signal_connect (G_OBJECT (self), "delete-event",
1843 G_CALLBACK (empathy_call_window_delete_cb), self);
1845 g_signal_connect (G_OBJECT (self), "window-state-event",
1846 G_CALLBACK (empathy_call_window_state_event_cb), self);
1848 g_signal_connect (G_OBJECT (self), "key-press-event",
1849 G_CALLBACK (empathy_call_window_key_press_cb), self);
1851 g_signal_connect (self, "motion-notify-event",
1852 G_CALLBACK (empathy_call_window_motion_notify_cb), self);
1854 priv->timer = g_timer_new ();
1856 g_object_ref (priv->ui_manager);
1857 g_object_unref (gui);
1859 priv->sound_mgr = empathy_sound_manager_dup_singleton ();
1860 priv->mic_menu = empathy_mic_menu_new (self);
1861 priv->camera_menu = empathy_camera_menu_new (self);
1863 empathy_call_window_show_hangup_button (self, TRUE);
1865 empathy_geometry_bind (GTK_WINDOW (self), "call-window");
1866 /* These signals are used to track the window position and save it
1867 * when the window is destroyed. We need to do this as we don't want
1868 * the window geometry to be saved with the dialpad taken into account. */
1869 g_signal_connect (self, "destroy",
1870 G_CALLBACK (empathy_call_window_destroyed_cb), self);
1871 g_signal_connect (self, "configure-event",
1872 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1873 g_signal_connect (self, "window-state-event",
1874 G_CALLBACK (empathy_call_window_configure_event_cb), self);
1876 /* Don't display labels in both toolbars */
1877 gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS);
1880 /* Instead of specifying a width and a height, we specify only one size. That's
1881 because we want a square avatar icon. */
1883 init_contact_avatar_with_size (EmpathyContact *contact,
1884 GtkWidget *image_widget,
1887 GdkPixbuf *pixbuf_avatar = NULL;
1889 if (contact != NULL)
1891 pixbuf_avatar = empathy_pixbuf_avatar_from_contact_scaled (contact,
1895 if (pixbuf_avatar == NULL)
1897 pixbuf_avatar = empathy_pixbuf_from_icon_name_sized (
1898 EMPATHY_IMAGE_AVATAR_DEFAULT, size);
1901 gtk_image_set_from_pixbuf (GTK_IMAGE (image_widget), pixbuf_avatar);
1903 if (pixbuf_avatar != NULL)
1904 g_object_unref (pixbuf_avatar);
1908 set_window_title (EmpathyCallWindow *self)
1910 EmpathyCallWindowPriv *priv = GET_PRIV (self);
1913 if (priv->contact != NULL)
1915 /* translators: Call is a noun and %s is the contact name. This string
1916 * is used in the window title */
1917 tmp = g_strdup_printf (_("Call with %s"),
1918 empathy_contact_get_alias (priv->contact));
1919 gtk_window_set_title (GTK_WINDOW (self), tmp);
1924 g_warning ("Unknown remote contact!");
1929 set_remote_user_name (EmpathyCallWindow *self,
1930 EmpathyContact *contact)
1932 const gchar *alias = empathy_contact_get_alias (contact);
1933 const gchar *status = empathy_contact_get_status (contact);
1936 label = g_strdup_printf ("%s\n<small>%s</small>", alias, status);
1937 gtk_label_set_markup (GTK_LABEL (self->priv->remote_user_name_toolbar),
1943 contact_name_changed_cb (EmpathyContact *contact,
1945 EmpathyCallWindow *self)
1947 set_window_title (self);
1948 set_remote_user_name (self, contact);
1952 contact_presence_changed_cb (EmpathyContact *contact,
1954 EmpathyCallWindow *self)
1956 set_remote_user_name (self, contact);
1960 contact_avatar_changed_cb (EmpathyContact *contact,
1962 EmpathyCallWindow *self)
1965 GtkAllocation allocation;
1966 GtkWidget *avatar_widget;
1968 avatar_widget = self->priv->remote_user_avatar_widget;
1970 gtk_widget_get_allocation (avatar_widget, &allocation);
1971 size = allocation.height;
1975 /* the widget is not allocated yet, set a default size */
1976 size = MIN (REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT,
1977 REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH);
1980 init_contact_avatar_with_size (contact, avatar_widget, size);
1982 avatar_widget = self->priv->remote_user_avatar_toolbar;
1984 gtk_widget_get_allocation (avatar_widget, &allocation);
1985 size = allocation.height;
1989 /* the widget is not allocated yet, set a default size */
1990 size = SMALL_TOOLBAR_SIZE;
1993 init_contact_avatar_with_size (contact, avatar_widget, size);
1997 empathy_call_window_setup_avatars (EmpathyCallWindow *self,
1998 EmpathyCallHandler *handler)
2000 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2002 tp_g_signal_connect_object (priv->contact, "notify::name",
2003 G_CALLBACK (contact_name_changed_cb), self, 0);
2004 tp_g_signal_connect_object (priv->contact, "notify::avatar",
2005 G_CALLBACK (contact_avatar_changed_cb), self, 0);
2006 tp_g_signal_connect_object (priv->contact, "notify::presence",
2007 G_CALLBACK (contact_presence_changed_cb), self, 0);
2009 set_window_title (self);
2010 set_remote_user_name (self, priv->contact);
2012 init_contact_avatar_with_size (priv->contact,
2013 priv->remote_user_avatar_widget,
2014 MIN (REMOTE_CONTACT_AVATAR_DEFAULT_WIDTH,
2015 REMOTE_CONTACT_AVATAR_DEFAULT_HEIGHT));
2017 init_contact_avatar_with_size (priv->contact,
2018 priv->remote_user_avatar_toolbar,
2019 SMALL_TOOLBAR_SIZE);
2021 /* The remote avatar is shown by default and will be hidden when we receive
2022 video from the remote side. */
2023 clutter_actor_hide (priv->video_output);
2024 gtk_widget_show (priv->remote_user_avatar_widget);
2028 update_send_codec (EmpathyCallWindow *self,
2031 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2038 codec = empathy_call_handler_get_send_audio_codec (priv->handler);
2039 widget = priv->acodec_encoding_label;
2043 codec = empathy_call_handler_get_send_video_codec (priv->handler);
2044 widget = priv->vcodec_encoding_label;
2050 tmp = g_strdup_printf ("%s/%u", codec->encoding_name, codec->clock_rate);
2051 gtk_label_set_text (GTK_LABEL (widget), tmp);
2056 send_audio_codec_notify_cb (GObject *object,
2060 EmpathyCallWindow *self = user_data;
2062 update_send_codec (self, TRUE);
2066 send_video_codec_notify_cb (GObject *object,
2070 EmpathyCallWindow *self = user_data;
2072 update_send_codec (self, FALSE);
2076 update_recv_codec (EmpathyCallWindow *self,
2079 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2082 GString *str = NULL;
2086 codecs = empathy_call_handler_get_recv_audio_codecs (priv->handler);
2087 widget = priv->acodec_decoding_label;
2091 codecs = empathy_call_handler_get_recv_video_codecs (priv->handler);
2092 widget = priv->vcodec_decoding_label;
2098 for (l = codecs; l != NULL; l = g_list_next (l))
2100 FsCodec *codec = l->data;
2103 str = g_string_new (NULL);
2105 g_string_append (str, ", ");
2107 g_string_append_printf (str, "%s/%u", codec->encoding_name,
2111 gtk_label_set_text (GTK_LABEL (widget), str->str);
2112 g_string_free (str, TRUE);
2116 recv_audio_codecs_notify_cb (GObject *object,
2120 EmpathyCallWindow *self = user_data;
2122 update_recv_codec (self, TRUE);
2126 recv_video_codecs_notify_cb (GObject *object,
2130 EmpathyCallWindow *self = user_data;
2132 update_recv_codec (self, FALSE);
2135 static const gchar *
2136 candidate_type_to_str (FsCandidate *candidate)
2138 switch (candidate->type)
2140 case FS_CANDIDATE_TYPE_HOST:
2142 case FS_CANDIDATE_TYPE_SRFLX:
2143 return "server reflexive";
2144 case FS_CANDIDATE_TYPE_PRFLX:
2145 return "peer reflexive";
2146 case FS_CANDIDATE_TYPE_RELAY:
2148 case FS_CANDIDATE_TYPE_MULTICAST:
2155 static const gchar *
2156 candidate_type_to_desc (FsCandidate *candidate)
2158 switch (candidate->type)
2160 case FS_CANDIDATE_TYPE_HOST:
2161 return _("The IP address as seen by the machine");
2162 case FS_CANDIDATE_TYPE_SRFLX:
2163 return _("The IP address as seen by a server on the Internet");
2164 case FS_CANDIDATE_TYPE_PRFLX:
2165 return _("The IP address of the peer as seen by the other side");
2166 case FS_CANDIDATE_TYPE_RELAY:
2167 return _("The IP address of a relay server");
2168 case FS_CANDIDATE_TYPE_MULTICAST:
2169 return _("The IP address of the multicast group");
2176 update_candidat_widget (EmpathyCallWindow *self,
2179 FsCandidate *candidate)
2183 g_assert (candidate != NULL);
2184 str = g_strdup_printf ("%s %u (%s)", candidate->ip,
2185 candidate->port, candidate_type_to_str (candidate));
2187 gtk_label_set_text (GTK_LABEL (label), str);
2188 gtk_widget_set_tooltip_text (img, candidate_type_to_desc (candidate));
2194 candidates_changed_cb (GObject *object,
2196 EmpathyCallWindow *self)
2198 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2199 FsCandidate *candidate = NULL;
2201 if (type == FS_MEDIA_TYPE_VIDEO)
2203 /* Update remote candidate */
2204 candidate = empathy_call_handler_get_video_remote_candidate (
2207 update_candidat_widget (self, priv->video_remote_candidate_label,
2208 priv->video_remote_candidate_info_img, candidate);
2210 /* Update local candidate */
2211 candidate = empathy_call_handler_get_video_local_candidate (
2214 update_candidat_widget (self, priv->video_local_candidate_label,
2215 priv->video_local_candidate_info_img, candidate);
2219 /* Update remote candidate */
2220 candidate = empathy_call_handler_get_audio_remote_candidate (
2223 update_candidat_widget (self, priv->audio_remote_candidate_label,
2224 priv->audio_remote_candidate_info_img, candidate);
2226 /* Update local candidate */
2227 candidate = empathy_call_handler_get_audio_local_candidate (
2230 update_candidat_widget (self, priv->audio_local_candidate_label,
2231 priv->audio_local_candidate_info_img, candidate);
2236 empathy_call_window_constructed (GObject *object)
2238 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2239 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2240 TpCallChannel *call;
2243 g_assert (priv->handler != NULL);
2245 g_object_get (priv->handler, "call-channel", &call, NULL);
2246 state = tp_call_channel_get_state (call, NULL, NULL, NULL);
2247 priv->outgoing = (state == TP_CALL_STATE_PENDING_INITIATOR);
2248 tp_clear_object (&call);
2250 priv->contact = empathy_call_handler_get_contact (priv->handler);
2251 g_assert (priv->contact != NULL);
2252 g_object_ref (priv->contact);
2254 if (!empathy_contact_can_voip_video (priv->contact))
2256 gtk_widget_set_sensitive (priv->video_call_button, FALSE);
2257 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2260 empathy_call_window_setup_avatars (self, priv->handler);
2261 empathy_call_window_set_state_connecting (self);
2263 if (!empathy_call_handler_has_initial_video (priv->handler))
2265 gtk_toggle_tool_button_set_active (
2266 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
2268 /* If call has InitialVideo, the preview will be started once the call has
2269 * been started (start_call()). */
2271 update_send_codec (self, TRUE);
2272 update_send_codec (self, FALSE);
2273 update_recv_codec (self, TRUE);
2274 update_recv_codec (self, FALSE);
2276 tp_g_signal_connect_object (priv->handler, "notify::send-audio-codec",
2277 G_CALLBACK (send_audio_codec_notify_cb), self, 0);
2278 tp_g_signal_connect_object (priv->handler, "notify::send-video-codec",
2279 G_CALLBACK (send_video_codec_notify_cb), self, 0);
2280 tp_g_signal_connect_object (priv->handler, "notify::recv-audio-codecs",
2281 G_CALLBACK (recv_audio_codecs_notify_cb), self, 0);
2282 tp_g_signal_connect_object (priv->handler, "notify::recv-video-codecs",
2283 G_CALLBACK (recv_video_codecs_notify_cb), self, 0);
2285 tp_g_signal_connect_object (priv->handler, "candidates-changed",
2286 G_CALLBACK (candidates_changed_cb), self, 0);
2289 static void empathy_call_window_dispose (GObject *object);
2290 static void empathy_call_window_finalize (GObject *object);
2293 empathy_call_window_set_property (GObject *object,
2294 guint property_id, const GValue *value, GParamSpec *pspec)
2296 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2298 switch (property_id)
2300 case PROP_CALL_HANDLER:
2301 priv->handler = g_value_dup_object (value);
2304 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2309 empathy_call_window_get_property (GObject *object,
2310 guint property_id, GValue *value, GParamSpec *pspec)
2312 EmpathyCallWindowPriv *priv = GET_PRIV (object);
2314 switch (property_id)
2316 case PROP_CALL_HANDLER:
2317 g_value_set_object (value, priv->handler);
2320 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
2325 empathy_call_window_class_init (
2326 EmpathyCallWindowClass *empathy_call_window_class)
2328 GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
2329 GParamSpec *param_spec;
2331 g_type_class_add_private (empathy_call_window_class,
2332 sizeof (EmpathyCallWindowPriv));
2334 object_class->constructed = empathy_call_window_constructed;
2335 object_class->set_property = empathy_call_window_set_property;
2336 object_class->get_property = empathy_call_window_get_property;
2338 object_class->dispose = empathy_call_window_dispose;
2339 object_class->finalize = empathy_call_window_finalize;
2341 param_spec = g_param_spec_object ("handler",
2342 "handler", "The call handler",
2343 EMPATHY_TYPE_CALL_HANDLER,
2344 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
2345 g_object_class_install_property (object_class,
2346 PROP_CALL_HANDLER, param_spec);
2350 empathy_call_window_dispose (GObject *object)
2352 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2353 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2355 if (priv->dispose_has_run)
2358 priv->dispose_has_run = TRUE;
2360 if (priv->handler != NULL)
2362 empathy_call_handler_stop_call (priv->handler);
2363 tp_clear_object (&priv->handler);
2366 if (priv->bus_message_source_id != 0)
2368 g_source_remove (priv->bus_message_source_id);
2369 priv->bus_message_source_id = 0;
2372 if (priv->got_video_src > 0)
2374 g_source_remove (priv->got_video_src);
2375 priv->got_video_src = 0;
2378 if (priv->inactivity_src > 0)
2380 g_source_remove (priv->inactivity_src);
2381 priv->inactivity_src = 0;
2384 tp_clear_object (&priv->pipeline);
2385 tp_clear_object (&priv->video_input);
2386 tp_clear_object (&priv->audio_input);
2387 tp_clear_object (&priv->video_tee);
2388 tp_clear_object (&priv->ui_manager);
2389 tp_clear_object (&priv->fullscreen);
2390 tp_clear_object (&priv->camera_monitor);
2391 tp_clear_object (&priv->settings);
2392 tp_clear_object (&priv->sound_mgr);
2393 tp_clear_object (&priv->mic_menu);
2394 tp_clear_object (&priv->camera_menu);
2395 tp_clear_object (&priv->transitions);
2397 g_list_free_full (priv->notifiers, g_object_unref);
2399 if (priv->timer_id != 0)
2400 g_source_remove (priv->timer_id);
2403 tp_clear_object (&priv->contact);
2405 G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
2409 disconnect_video_output_motion_handler (EmpathyCallWindow *self)
2411 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2413 if (priv->video_output_motion_handler_id != 0)
2415 g_signal_handler_disconnect (G_OBJECT (priv->video_container),
2416 priv->video_output_motion_handler_id);
2417 priv->video_output_motion_handler_id = 0;
2422 empathy_call_window_finalize (GObject *object)
2424 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
2425 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2427 disconnect_video_output_motion_handler (self);
2429 /* free any data held directly by the object here */
2430 g_mutex_free (priv->lock);
2432 g_timer_destroy (priv->timer);
2434 G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
2439 empathy_call_window_new (EmpathyCallHandler *handler)
2441 return EMPATHY_CALL_WINDOW (
2442 g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
2446 empathy_call_window_present (EmpathyCallWindow *self,
2447 EmpathyCallHandler *handler)
2449 g_return_if_fail (EMPATHY_IS_CALL_HANDLER (handler));
2451 empathy_window_present (GTK_WINDOW (self));
2453 if (self->priv->call_state == DISCONNECTED)
2455 /* start a new call if one is not already in progress */
2456 tp_clear_object (&self->priv->handler);
2457 self->priv->handler = g_object_ref (handler);
2458 empathy_call_window_connect_handler (self);
2460 empathy_call_window_restart_call (self);
2465 empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
2466 GstElement *conference, gpointer user_data)
2468 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2469 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2470 FsElementAddedNotifier *notifier;
2473 DEBUG ("Conference added");
2475 /* Add notifier to set the various element properties as needed */
2476 notifier = fs_element_added_notifier_new ();
2477 keyfile = fs_utils_get_default_element_properties (conference);
2479 if (keyfile != NULL)
2480 fs_element_added_notifier_set_properties_from_keyfile (notifier, keyfile);
2482 fs_element_added_notifier_add (notifier, GST_BIN (priv->pipeline));
2484 priv->notifiers = g_list_prepend (priv->notifiers, notifier);
2486 gst_bin_add (GST_BIN (priv->pipeline), conference);
2487 gst_element_set_state (conference, GST_STATE_PLAYING);
2491 empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
2492 GstElement *conference, gpointer user_data)
2494 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2495 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2497 gst_bin_remove (GST_BIN (priv->pipeline), conference);
2498 gst_element_set_state (conference, GST_STATE_NULL);
2502 empathy_call_window_reset_pipeline (EmpathyCallWindow *self)
2504 GstStateChangeReturn state_change_return;
2505 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2507 if (priv->pipeline == NULL)
2510 if (priv->bus_message_source_id != 0)
2512 g_source_remove (priv->bus_message_source_id);
2513 priv->bus_message_source_id = 0;
2516 state_change_return = gst_element_set_state (priv->pipeline, GST_STATE_NULL);
2518 if (state_change_return == GST_STATE_CHANGE_SUCCESS ||
2519 state_change_return == GST_STATE_CHANGE_NO_PREROLL)
2521 if (priv->pipeline != NULL)
2522 g_object_unref (priv->pipeline);
2523 priv->pipeline = NULL;
2525 if (priv->audio_output != NULL)
2526 g_object_unref (priv->audio_output);
2527 priv->audio_output = NULL;
2528 priv->audio_output_added = FALSE;
2530 if (priv->video_tee != NULL)
2531 g_object_unref (priv->video_tee);
2532 priv->video_tee = NULL;
2534 if (priv->video_preview != NULL)
2535 clutter_actor_destroy (priv->video_preview);
2536 priv->video_preview = NULL;
2538 /* If we destroy the preview while it's being dragged, we won't
2539 * get the ::drag-end signal, so manually destroy the clone */
2540 if (priv->drag_preview != NULL)
2542 clutter_actor_destroy (priv->drag_preview);
2543 empathy_call_window_show_preview_rectangles (self, FALSE);
2544 priv->drag_preview = NULL;
2547 priv->funnel = NULL;
2549 create_pipeline (self);
2550 /* Call will be started when user will hit the 'redial' button */
2551 priv->start_call_when_playing = FALSE;
2552 gst_element_set_state (priv->pipeline, GST_STATE_PAUSED);
2558 g_message ("Error: could not destroy pipeline. Closing call window");
2559 gtk_widget_destroy (GTK_WIDGET (self));
2566 reset_details_pane (EmpathyCallWindow *self)
2568 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2570 gtk_label_set_text (GTK_LABEL (priv->vcodec_encoding_label), _("Unknown"));
2571 gtk_label_set_text (GTK_LABEL (priv->acodec_encoding_label), _("Unknown"));
2572 gtk_label_set_text (GTK_LABEL (priv->vcodec_decoding_label), _("Unknown"));
2573 gtk_label_set_text (GTK_LABEL (priv->acodec_decoding_label), _("Unknown"));
2577 empathy_call_window_disconnected (EmpathyCallWindow *self,
2580 gboolean could_disconnect = FALSE;
2581 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2582 gboolean could_reset_pipeline;
2584 /* Leave full screen mode if needed */
2585 gtk_window_unfullscreen (GTK_WINDOW (self));
2587 gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
2588 gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
2590 could_reset_pipeline = empathy_call_window_reset_pipeline (self);
2592 if (priv->call_state == CONNECTING)
2593 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
2595 if (priv->call_state != REDIALING)
2596 priv->call_state = DISCONNECTED;
2598 /* Show the toolbar */
2599 clutter_state_set_state (priv->transitions, "fade-in");
2601 if (could_reset_pipeline)
2603 g_mutex_lock (priv->lock);
2605 g_timer_stop (priv->timer);
2607 if (priv->timer_id != 0)
2608 g_source_remove (priv->timer_id);
2611 g_mutex_unlock (priv->lock);
2614 /* We are about to destroy the window, no need to update it or create
2615 * a video preview */
2618 empathy_call_window_status_message (self, _("Disconnected"));
2620 empathy_call_window_show_hangup_button (self, FALSE);
2622 /* Unsensitive the camera and mic button */
2623 gtk_widget_set_sensitive (priv->camera_button, FALSE);
2624 gtk_widget_set_sensitive (priv->mic_button, FALSE);
2626 /* Be sure that the mic button is enabled */
2627 gtk_toggle_tool_button_set_active (
2628 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button), TRUE);
2630 if (priv->camera_state == CAMERA_STATE_ON)
2632 /* Restart the preview with the new pipeline. */
2633 display_video_preview (self, TRUE);
2636 /* destroy the video output; it will be recreated when we'll redial */
2637 disconnect_video_output_motion_handler (self);
2638 if (priv->video_output != NULL)
2639 clutter_actor_destroy (priv->video_output);
2640 priv->video_output = NULL;
2641 if (priv->got_video_src > 0)
2643 g_source_remove (priv->got_video_src);
2644 priv->got_video_src = 0;
2647 gtk_widget_show (priv->remote_user_avatar_widget);
2649 reset_details_pane (self);
2651 priv->sending_video = FALSE;
2652 priv->call_started = FALSE;
2654 could_disconnect = TRUE;
2656 /* TODO: display the self avatar of the preview (depends if the "Always
2657 * Show Video Preview" is enabled or not) */
2660 return could_disconnect;
2665 empathy_call_window_channel_closed_cb (EmpathyCallHandler *handler,
2668 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2669 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2671 if (empathy_call_window_disconnected (self, TRUE) &&
2672 priv->call_state == REDIALING)
2673 empathy_call_window_restart_call (self);
2677 empathy_call_window_content_is_raw (TfContent *content)
2679 FsConference *conference;
2682 g_object_get (content, "fs-conference", &conference, NULL);
2683 g_assert (conference != NULL);
2685 /* FIXME: Ugly hack, update when moving a packetization property into
2687 israw = g_str_has_prefix (GST_OBJECT_NAME (conference), "fsrawconf");
2688 gst_object_unref (conference);
2694 empathy_call_window_content_removed_cb (EmpathyCallHandler *handler,
2696 EmpathyCallWindow *self)
2698 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2699 FsMediaType media_type;
2701 DEBUG ("removing content");
2703 g_object_get (content, "media-type", &media_type, NULL);
2706 * This assumes that there is only one video stream per channel...
2709 if ((guint) media_type == FS_MEDIA_TYPE_VIDEO)
2711 if (priv->funnel != NULL)
2715 output = priv->video_output_sink;
2717 gst_element_set_state (output, GST_STATE_NULL);
2718 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2720 gst_bin_remove (GST_BIN (priv->pipeline), output);
2721 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2722 priv->funnel = NULL;
2725 else if (media_type == FS_MEDIA_TYPE_AUDIO)
2727 if (priv->audio_output != NULL)
2729 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2731 if (priv->audio_output_added)
2732 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2733 priv->audio_output = NULL;
2734 priv->audio_output_added = FALSE;
2739 g_assert_not_reached ();
2746 empathy_call_window_framerate_changed_cb (EmpathyCallHandler *handler,
2748 EmpathyCallWindow *self)
2750 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2752 DEBUG ("Framerate changed to %u", framerate);
2754 if (priv->video_input != NULL)
2755 empathy_video_src_set_framerate (priv->video_input, framerate);
2759 empathy_call_window_resolution_changed_cb (EmpathyCallHandler *handler,
2762 EmpathyCallWindow *self)
2764 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2766 DEBUG ("Resolution changed to %ux%u", width, height);
2768 if (priv->video_input != NULL)
2770 empathy_video_src_set_resolution (priv->video_input, width, height);
2774 /* Called with global lock held */
2776 empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
2778 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2782 if (priv->funnel == NULL)
2784 output = priv->video_output_sink;
2786 priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
2790 g_warning ("Could not create fsfunnel");
2794 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->funnel))
2796 gst_object_unref (priv->funnel);
2797 priv->funnel = NULL;
2798 g_warning ("Could not add funnel to pipeline");
2802 if (!gst_bin_add (GST_BIN (priv->pipeline), output))
2804 g_warning ("Could not add the video output widget to the pipeline");
2808 if (!gst_element_link (priv->funnel, output))
2810 g_warning ("Could not link output sink to funnel");
2811 goto error_output_added;
2814 if (gst_element_set_state (output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2816 g_warning ("Could not start video sink");
2817 goto error_output_added;
2820 if (gst_element_set_state (priv->funnel, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2822 g_warning ("Could not start funnel");
2823 goto error_output_added;
2827 pad = gst_element_get_request_pad (priv->funnel, "sink%d");
2830 g_warning ("Could not get request pad from funnel");
2837 gst_element_set_locked_state (priv->funnel, TRUE);
2838 gst_element_set_locked_state (output, TRUE);
2840 gst_element_set_state (priv->funnel, GST_STATE_NULL);
2841 gst_element_set_state (output, GST_STATE_NULL);
2843 gst_bin_remove (GST_BIN (priv->pipeline), output);
2844 gst_element_set_locked_state (output, FALSE);
2848 gst_bin_remove (GST_BIN (priv->pipeline), priv->funnel);
2849 priv->funnel = NULL;
2854 /* Called with global lock held */
2856 empathy_call_window_get_audio_sink_pad (EmpathyCallWindow *self,
2859 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2861 GstPadTemplate *template;
2863 if (!priv->audio_output_added)
2865 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_output))
2867 g_warning ("Could not add audio sink to pipeline");
2868 g_object_unref (priv->audio_output);
2869 goto error_add_output;
2872 if (gst_element_set_state (priv->audio_output, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
2874 g_warning ("Could not start audio sink");
2879 template = gst_element_class_get_pad_template (
2880 GST_ELEMENT_GET_CLASS (priv->audio_output), "sink%d");
2882 pad = gst_element_request_pad (priv->audio_output,
2883 template, NULL, NULL);
2887 g_warning ("Could not get sink pad from sink");
2894 gst_element_set_locked_state (priv->audio_output, TRUE);
2895 gst_element_set_state (priv->audio_output, GST_STATE_NULL);
2896 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_output);
2897 priv->audio_output = NULL;
2905 empathy_call_window_update_timer (gpointer user_data)
2907 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
2908 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2909 const gchar *status;
2913 time_ = g_timer_elapsed (priv->timer, NULL);
2915 if (priv->call_state == HELD)
2916 status = _("On hold");
2917 else if (!gtk_toggle_tool_button_get_active (
2918 GTK_TOGGLE_TOOL_BUTTON (priv->mic_button)))
2921 status = _("Duration");
2923 /* Translators: 'status - minutes:seconds' the caller has been connected */
2924 str = g_strdup_printf (_("%s — %d:%02dm"),
2926 (int) time_ / 60, (int) time_ % 60);
2927 empathy_call_window_status_message (self, str);
2935 EMP_RESPONSE_BALANCE
2939 on_error_infobar_response_cb (GtkInfoBar *info_bar,
2943 switch (response_id)
2945 case GTK_RESPONSE_CLOSE:
2946 gtk_widget_destroy (GTK_WIDGET (info_bar));
2948 case EMP_RESPONSE_BALANCE:
2949 empathy_url_show (GTK_WIDGET (info_bar),
2950 g_object_get_data (G_OBJECT (info_bar), "uri"));
2956 display_error (EmpathyCallWindow *self,
2960 const gchar *details,
2961 const gchar *button_text,
2963 gint button_response)
2965 EmpathyCallWindowPriv *priv = GET_PRIV (self);
2966 GtkWidget *info_bar;
2967 GtkWidget *content_area;
2974 /* Create info bar */
2975 info_bar = gtk_info_bar_new ();
2977 if (button_text != NULL)
2979 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
2980 button_text, button_response);
2981 g_object_set_data_full (G_OBJECT (info_bar),
2982 "uri", g_strdup (uri), g_free);
2985 gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
2986 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
2988 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
2990 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
2992 /* hbox containing the image and the messages vbox */
2993 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
2994 gtk_container_add (GTK_CONTAINER (content_area), hbox);
2997 image = gtk_image_new_from_icon_name (img, GTK_ICON_SIZE_DIALOG);
2998 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
3000 /* vbox containing the main message and the details expander */
3001 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
3002 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
3005 txt = g_strdup_printf ("<b>%s</b>\n%s", title, desc);
3007 label = gtk_label_new (NULL);
3008 gtk_label_set_markup (GTK_LABEL (label), txt);
3009 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
3010 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
3013 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
3016 if (details != NULL)
3018 GtkWidget *expander;
3020 expander = gtk_expander_new (_("Technical Details"));
3022 txt = g_strdup_printf ("<i>%s</i>", details);
3024 label = gtk_label_new (NULL);
3025 gtk_label_set_markup (GTK_LABEL (label), txt);
3026 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
3027 gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
3030 gtk_container_add (GTK_CONTAINER (expander), label);
3031 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
3034 g_signal_connect (info_bar, "response",
3035 G_CALLBACK (on_error_infobar_response_cb), NULL);
3037 gtk_box_pack_start (GTK_BOX (priv->errors_vbox), info_bar,
3038 FALSE, FALSE, CONTENT_HBOX_CHILDREN_PACKING_PADDING);
3039 gtk_widget_show_all (info_bar);
3044 media_stream_error_to_txt (EmpathyCallWindow *self,
3045 TpCallChannel *call,
3047 TpMediaStreamError error)
3049 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3050 const gchar *cm = NULL;
3056 case TP_MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED:
3058 return g_strdup_printf (
3059 _("%s's software does not understand any of the audio formats "
3060 "supported by your computer"),
3061 empathy_contact_get_alias (priv->contact));
3063 return g_strdup_printf (
3064 _("%s's software does not understand any of the video formats "
3065 "supported by your computer"),
3066 empathy_contact_get_alias (priv->contact));
3068 case TP_MEDIA_STREAM_ERROR_CONNECTION_FAILED:
3069 return g_strdup_printf (
3070 _("Can't establish a connection to %s. "
3071 "One of you might be on a network that does not allow "
3072 "direct connections."),
3073 empathy_contact_get_alias (priv->contact));
3075 case TP_MEDIA_STREAM_ERROR_NETWORK_ERROR:
3076 return g_strdup (_("There was a failure on the network"));
3078 case TP_MEDIA_STREAM_ERROR_NO_CODECS:
3080 return g_strdup (_("The audio formats necessary for this call "
3081 "are not installed on your computer"));
3083 return g_strdup (_("The video formats necessary for this call "
3084 "are not installed on your computer"));
3086 case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
3087 tp_connection_parse_object_path (
3088 tp_channel_borrow_connection (TP_CHANNEL (call)),
3091 url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
3092 "product=Telepathy&component=%s", cm);
3094 result = g_strdup_printf (
3095 _("Something unexpected happened in a Telepathy component. "
3096 "Please <a href=\"%s\">report this bug</a> and attach "
3097 "logs gathered from the 'Debug' window in the Help menu."), url);
3103 case TP_MEDIA_STREAM_ERROR_MEDIA_ERROR:
3104 return g_strdup (_("There was a failure in the call engine"));
3106 case TP_MEDIA_STREAM_ERROR_EOS:
3107 return g_strdup (_("The end of the stream was reached"));
3109 case TP_MEDIA_STREAM_ERROR_UNKNOWN:
3116 empathy_call_window_stream_error (EmpathyCallWindow *self,
3117 TpCallChannel *call,
3126 desc = media_stream_error_to_txt (self, call, audio, code);
3129 /* No description, use the error message. That's not great as it's not
3130 * localized but it's better than nothing. */
3131 display_error (self, call, icon, title, msg, NULL);
3135 display_error (self, call, icon, title, desc, msg);
3141 empathy_call_window_audio_stream_error (TpCallChannel *call,
3144 EmpathyCallWindow *self)
3146 empathy_call_window_stream_error (self, call, TRUE, code, msg,
3147 "gnome-stock-mic", _("Can't establish audio stream"));
3151 empathy_call_window_video_stream_error (TpCallChannel *call,
3154 EmpathyCallWindow *self)
3156 empathy_call_window_stream_error (self, call, FALSE, code, msg,
3157 "camera-web", _("Can't establish video stream"));
3162 show_balance_error (EmpathyCallWindow *self)
3166 gchar *balance, *tmp;
3167 const gchar *uri, *currency;
3171 g_object_get (self->priv->handler,
3172 "call-channel", &call,
3175 conn = tp_channel_borrow_connection (call);
3176 g_object_unref (call);
3178 uri = tp_connection_get_balance_uri (conn);
3180 if (!tp_connection_get_balance (conn, &amount, &scale, ¤cy))
3182 /* unknown balance */
3183 balance = g_strdup ("(--)");
3187 char *money = empathy_format_currency (amount, scale, currency);
3189 balance = g_strdup_printf ("%s %s",
3194 tmp = g_strdup_printf (_("Your current balance is %s."), balance),
3196 display_error (self,
3198 _("Sorry, you don’t have enough credit for that call."),
3202 EMP_RESPONSE_BALANCE);
3209 empathy_call_window_state_changed_cb (EmpathyCallHandler *handler,
3212 EmpathyCallWindow *self)
3214 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3215 TpCallChannel *call;
3216 gboolean can_send_video;
3218 if (state == TP_CALL_STATE_ENDED)
3220 DEBUG ("Call ended: %s", (reason != NULL && reason[0] != '\0') ? reason : "unspecified reason");
3221 empathy_call_window_disconnected (self, TRUE);
3222 if (!tp_strdiff (reason, TP_ERROR_STR_INSUFFICIENT_BALANCE))
3223 show_balance_error (self);
3227 if (state != TP_CALL_STATE_ACCEPTED)
3230 if (priv->call_state == CONNECTED)
3233 g_timer_start (priv->timer);
3234 priv->call_state = CONNECTED;
3236 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3238 can_send_video = priv->video_input != NULL &&
3239 empathy_contact_can_voip_video (priv->contact) &&
3240 empathy_camera_monitor_get_available (priv->camera_monitor);
3242 g_object_get (priv->handler, "call-channel", &call, NULL);
3244 if (tp_call_channel_has_dtmf (call))
3245 gtk_widget_set_sensitive (priv->dtmf_panel, TRUE);
3247 if (priv->video_input == NULL)
3248 empathy_call_window_set_send_video (self, CAMERA_STATE_OFF);
3250 gtk_widget_set_sensitive (priv->camera_button, can_send_video);
3252 empathy_call_window_show_hangup_button (self, TRUE);
3254 gtk_widget_set_sensitive (priv->mic_button, TRUE);
3256 clutter_actor_hide (priv->video_output);
3257 gtk_widget_show (priv->remote_user_avatar_widget);
3259 g_object_unref (call);
3261 g_mutex_lock (priv->lock);
3263 priv->timer_id = g_timeout_add_seconds (1,
3264 empathy_call_window_update_timer, self);
3266 g_mutex_unlock (priv->lock);
3268 empathy_call_window_update_timer (self);
3270 gtk_action_set_sensitive (priv->menu_fullscreen, TRUE);
3274 empathy_call_window_show_video_output_cb (gpointer user_data)
3276 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3278 if (self->priv->video_output != NULL)
3280 gtk_widget_hide (self->priv->remote_user_avatar_widget);
3281 clutter_actor_show (self->priv->video_output);
3282 empathy_call_window_raise_actors (self);
3289 empathy_call_window_check_video_cb (gpointer data)
3291 EmpathyCallWindow *self = data;
3293 if (self->priv->got_video)
3295 self->priv->got_video = FALSE;
3299 /* No video in the last N seconds, display the remote avatar */
3300 empathy_call_window_show_video_output (self, FALSE);
3305 /* Called from the streaming thread */
3307 empathy_call_window_video_probe_cb (GstPad *pad,
3308 GstMiniObject *mini_obj,
3309 EmpathyCallWindow *self)
3312 if (GST_IS_EVENT (mini_obj))
3315 if (G_UNLIKELY (!self->priv->got_video))
3317 /* show the remote video */
3318 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
3319 empathy_call_window_show_video_output_cb,
3320 g_object_ref (self), g_object_unref);
3322 self->priv->got_video = TRUE;
3328 /* Called from the streaming thread */
3330 empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
3331 TfContent *content, GstPad *src, gpointer user_data)
3333 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3334 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3335 gboolean retval = FALSE;
3340 g_mutex_lock (priv->lock);
3342 g_object_get (content, "media-type", &media_type, NULL);
3346 case TP_MEDIA_STREAM_TYPE_AUDIO:
3347 pad = empathy_call_window_get_audio_sink_pad (self, content);
3349 case TP_MEDIA_STREAM_TYPE_VIDEO:
3350 g_idle_add (empathy_call_window_show_video_output_cb, self);
3351 pad = empathy_call_window_get_video_sink_pad (self);
3353 gst_pad_add_data_probe (src,
3354 G_CALLBACK (empathy_call_window_video_probe_cb), self);
3355 if (priv->got_video_src > 0)
3356 g_source_remove (priv->got_video_src);
3357 priv->got_video_src = g_timeout_add_seconds (1,
3358 empathy_call_window_check_video_cb, self);
3361 g_assert_not_reached ();
3367 if (GST_PAD_LINK_FAILED (gst_pad_link (src, pad)))
3368 g_warning ("Could not link %s sink pad",
3369 media_type == TP_MEDIA_STREAM_TYPE_AUDIO ? "audio" : "video");
3373 gst_object_unref (pad);
3377 /* If no sink could be linked, try to add fakesink to prevent the whole call
3382 GstElement *fakesink = gst_element_factory_make ("fakesink", NULL);
3384 if (gst_bin_add (GST_BIN (priv->pipeline), fakesink))
3386 GstPad *sinkpad = gst_element_get_static_pad (fakesink, "sink");
3387 if (gst_element_set_state (fakesink, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE ||
3388 GST_PAD_LINK_FAILED (gst_pad_link (src, sinkpad)))
3390 gst_element_set_locked_state (fakesink, TRUE);
3391 gst_element_set_state (fakesink, GST_STATE_NULL);
3392 gst_bin_remove (GST_BIN (priv->pipeline), fakesink);
3396 DEBUG ("Could not link real sink, linked fakesink instead");
3398 gst_object_unref (sinkpad);
3402 gst_object_unref (fakesink);
3407 g_mutex_unlock (priv->lock);
3413 empathy_call_window_prepare_audio_output (EmpathyCallWindow *self,
3416 EmpathyCallWindowPriv *priv = self->priv;
3418 g_assert (priv->audio_output_added == FALSE);
3419 g_assert (priv->audio_output == FALSE);
3421 priv->audio_output = empathy_audio_sink_new ();
3422 g_object_ref_sink (priv->audio_output);
3424 /* volume button to output volume linking */
3425 g_object_bind_property (priv->audio_output, "volume",
3426 priv->volume_button, "value",
3427 G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
3429 g_object_bind_property_full (content, "requested-output-volume",
3430 priv->audio_output, "volume",
3432 audio_control_volume_to_element,
3433 element_volume_to_audio_control,
3436 /* Link volumes together, sync the current audio input volume property
3437 * back to farstream first */
3438 g_object_bind_property_full (priv->audio_output, "volume",
3439 content, "reported-output-volume",
3440 G_BINDING_SYNC_CREATE,
3441 element_volume_to_audio_control,
3442 audio_control_volume_to_element,
3445 /* For raw audio conferences assume that the producer of the raw data
3446 * has already processed it, so turn off any echo cancellation and any
3447 * other audio improvements that come with it */
3448 empathy_audio_sink_set_echo_cancel (
3449 EMPATHY_GST_AUDIO_SINK (priv->audio_output),
3450 !empathy_call_window_content_is_raw (content));
3455 empathy_call_window_content_added_cb (EmpathyCallHandler *handler,
3456 TfContent *content, gpointer user_data)
3458 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3459 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3461 FsMediaType media_type;
3462 gboolean retval = FALSE;
3464 g_object_get (content, "media-type", &media_type, "sink-pad", &sink, NULL);
3465 g_assert (sink != NULL);
3469 case FS_MEDIA_TYPE_AUDIO:
3471 /* For raw audio conferences assume that the receiver of the raw data
3472 * wants it unprocessed, so turn off any echo cancellation and any
3473 * other audio improvements that come with it */
3474 empathy_audio_src_set_echo_cancel (
3475 EMPATHY_GST_AUDIO_SRC (priv->audio_input),
3476 !empathy_call_window_content_is_raw (content));
3478 /* Link volumes together, sync the current audio input volume property
3479 * back to farstream first */
3480 g_object_bind_property_full (content, "requested-input-volume",
3481 priv->audio_input, "volume",
3483 audio_control_volume_to_element,
3484 element_volume_to_audio_control,
3487 g_object_bind_property_full (priv->audio_input, "volume",
3488 content, "reported-input-volume",
3489 G_BINDING_SYNC_CREATE,
3490 element_volume_to_audio_control,
3491 audio_control_volume_to_element,
3494 if (!gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input))
3496 g_warning ("Could not add audio source to pipeline");
3500 pad = gst_element_get_static_pad (priv->audio_input, "src");
3503 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3504 g_warning ("Could not get source pad from audio source");
3508 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3510 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3511 gst_object_unref (pad);
3512 g_warning ("Could not link audio source to farsight");
3515 gst_object_unref (pad);
3517 if (gst_element_set_state (priv->audio_input, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
3519 g_warning ("Could not start audio source");
3520 gst_element_set_state (priv->audio_input, GST_STATE_NULL);
3521 gst_bin_remove (GST_BIN (priv->pipeline), priv->audio_input);
3525 /* Prepare our audio output, not added yet though */
3526 empathy_call_window_prepare_audio_output (self, content);
3530 case FS_MEDIA_TYPE_VIDEO:
3531 if (priv->video_tee != NULL)
3533 pad = gst_element_get_request_pad (priv->video_tee, "src%d");
3534 if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
3536 g_warning ("Could not link video source input pipeline");
3539 gst_object_unref (pad);
3545 g_assert_not_reached ();
3548 gst_object_unref (sink);
3553 empathy_call_window_remove_video_input (EmpathyCallWindow *self)
3555 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3556 GstElement *preview;
3558 disable_camera (self);
3560 DEBUG ("remove video input");
3561 preview = priv->video_preview_sink;
3563 gst_element_set_state (priv->video_input, GST_STATE_NULL);
3564 gst_element_set_state (priv->video_tee, GST_STATE_NULL);
3565 gst_element_set_state (preview, GST_STATE_NULL);
3567 gst_bin_remove_many (GST_BIN (priv->pipeline), priv->video_input,
3570 g_object_unref (priv->video_input);
3571 priv->video_input = NULL;
3572 g_object_unref (priv->video_tee);
3573 priv->video_tee = NULL;
3574 clutter_actor_destroy (priv->video_preview);
3575 priv->video_preview = NULL;
3577 gtk_widget_set_sensitive (priv->camera_button, FALSE);
3581 start_call (EmpathyCallWindow *self)
3583 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3585 priv->call_started = TRUE;
3586 empathy_call_handler_start_call (priv->handler,
3587 gtk_get_current_event_time ());
3589 if (empathy_call_handler_has_initial_video (priv->handler))
3591 TpCallChannel *call;
3594 g_object_get (priv->handler, "call-channel", &call, NULL);
3595 /* If the call channel isn't set yet we're requesting it, if we're
3596 * requesting it with initial video it should be PENDING_SEND when we get
3599 s = TP_SENDING_STATE_PENDING_SEND;
3601 s = empathy_call_channel_get_video_state (call);
3603 if (s == TP_SENDING_STATE_PENDING_SEND ||
3604 s == TP_SENDING_STATE_SENDING)
3606 /* Enable 'send video' buttons and display the preview */
3607 gtk_toggle_tool_button_set_active (
3608 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), TRUE);
3612 gtk_toggle_tool_button_set_active (
3613 GTK_TOGGLE_TOOL_BUTTON (priv->camera_button), FALSE);
3615 if (priv->video_preview == NULL)
3617 create_video_preview (self);
3618 add_video_preview_to_pipeline (self);
3623 g_object_unref (call);
3628 empathy_call_window_bus_message (GstBus *bus, GstMessage *message,
3631 EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
3632 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3633 GstState newstate, pending;
3635 empathy_call_handler_bus_message (priv->handler, bus, message);
3637 switch (GST_MESSAGE_TYPE (message))
3639 case GST_MESSAGE_STATE_CHANGED:
3640 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_input))
3642 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3644 if (GST_MESSAGE_SRC (message) == GST_OBJECT (priv->pipeline) &&
3645 !priv->call_started)
3647 gst_message_parse_state_changed (message, NULL, &newstate, NULL);
3648 if (newstate == GST_STATE_PAUSED)
3650 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3651 priv->pipeline_playing = TRUE;
3653 if (priv->start_call_when_playing)
3657 if (priv->video_preview_sink != NULL &&
3658 GST_MESSAGE_SRC (message) == GST_OBJECT (priv->video_preview_sink))
3660 gst_message_parse_state_changed (message, NULL, &newstate,
3663 if (newstate == GST_STATE_PLAYING &&
3664 pending == GST_STATE_VOID_PENDING)
3665 empathy_call_window_stop_camera_spinning (self);
3668 case GST_MESSAGE_ERROR:
3670 GError *error = NULL;
3671 GstElement *gst_error;
3674 gst_message_parse_error (message, &error, &debug);
3675 gst_error = GST_ELEMENT (GST_MESSAGE_SRC (message));
3677 g_message ("Element error: %s -- %s\n", error->message, debug);
3679 if (g_str_has_prefix (gst_element_get_name (gst_error),
3680 VIDEO_INPUT_ERROR_PREFIX))
3682 /* Remove the video input and continue */
3683 if (priv->video_input != NULL)
3684 empathy_call_window_remove_video_input (self);
3685 gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
3689 empathy_call_window_disconnected (self, TRUE);
3691 g_error_free (error);
3694 case GST_MESSAGE_UNKNOWN:
3695 case GST_MESSAGE_EOS:
3696 case GST_MESSAGE_WARNING:
3697 case GST_MESSAGE_INFO:
3698 case GST_MESSAGE_TAG:
3699 case GST_MESSAGE_BUFFERING:
3700 case GST_MESSAGE_STATE_DIRTY:
3701 case GST_MESSAGE_STEP_DONE:
3702 case GST_MESSAGE_CLOCK_PROVIDE:
3703 case GST_MESSAGE_CLOCK_LOST:
3704 case GST_MESSAGE_NEW_CLOCK:
3705 case GST_MESSAGE_STRUCTURE_CHANGE:
3706 case GST_MESSAGE_STREAM_STATUS:
3707 case GST_MESSAGE_APPLICATION:
3708 case GST_MESSAGE_ELEMENT:
3709 case GST_MESSAGE_SEGMENT_START:
3710 case GST_MESSAGE_SEGMENT_DONE:
3711 case GST_MESSAGE_DURATION:
3712 case GST_MESSAGE_ANY:
3721 empathy_call_window_members_changed_cb (TpCallChannel *call,
3722 GHashTable *updates,
3724 TpCallStateReason *reason,
3725 EmpathyCallWindow *self)
3727 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3728 GHashTableIter iter;
3729 gpointer key, value;
3730 gboolean held = FALSE;
3732 g_hash_table_iter_init (&iter, updates);
3733 while (g_hash_table_iter_next (&iter, &key, &value))
3735 if (GPOINTER_TO_INT (value) & TP_CALL_MEMBER_FLAG_HELD)
3737 /* This assumes this is a 1-1 call, otherwise one participant
3738 * putting the call on hold wouldn't mean the call is on hold
3746 priv->call_state = HELD;
3747 else if (priv->call_state == HELD)
3748 priv->call_state = CONNECTED;
3752 call_handler_notify_call_cb (EmpathyCallHandler *handler,
3754 EmpathyCallWindow *self)
3756 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3757 TpCallChannel *call;
3759 g_object_get (priv->handler, "call-channel", &call, NULL);
3764 tp_g_signal_connect_object (call, "audio-stream-error",
3765 G_CALLBACK (empathy_call_window_audio_stream_error), self, 0);
3766 tp_g_signal_connect_object (call, "video-stream-error",
3767 G_CALLBACK (empathy_call_window_video_stream_error), self, 0);
3770 tp_g_signal_connect_object (call, "members-changed",
3771 G_CALLBACK (empathy_call_window_members_changed_cb), self, 0);
3773 g_object_unref (call);
3777 empathy_call_window_connect_handler (EmpathyCallWindow *self)
3779 EmpathyCallWindowPriv *priv = GET_PRIV (self);
3780 TpCallChannel *call;
3782 g_signal_connect (priv->handler, "state-changed",
3783 G_CALLBACK (empathy_call_window_state_changed_cb), self);
3784 g_signal_connect (priv->handler, "conference-added",
3785 G_CALLBACK (empathy_call_window_conference_added_cb), self);
3786 g_signal_connect (priv->handler, "conference-removed",
3787 G_CALLBACK (empathy_call_window_conference_removed_cb), self);
3788 g_signal_connect (priv->handler, "closed",
3789 G_CALLBACK (empathy_call_window_channel_closed_cb), self);
3790 g_signal_connect (priv->handler, "src-pad-added",
3791 G_CALLBACK (empathy_call_window_src_added_cb), self);
3792 g_signal_connect (priv->handler, "content-added",
3793 G_CALLBACK (empathy_call_window_content_added_cb), self);
3794 g_signal_connect (priv->handler, "content-removed",
3795 G_CALLBACK (empathy_call_window_content_removed_cb), self);
3797 /* We connect to ::call-channel unconditionally since we'll
3798 * get new channels if we hangup and redial or if we reuse the
3800 g_signal_connect (priv->handler, "notify::call-channel",
3801 G_CALLBACK (call_handler_notify_call_cb), self);
3803 g_signal_connect (priv->handler, "framerate-changed",
3804 G_CALLBACK (empathy_call_window_framerate_changed_cb), self);
3805 g_signal_connect (priv->handler, "resolution-changed",
3806 G_CALLBACK (empathy_call_window_resolution_changed_cb), self);
3808 g_object_get (priv->handler, "call-channel", &call, NULL);
3811 /* We won't get notify::call-channel for this channel, so
3812 * directly call the callback. */
3813 call_handler_notify_call_cb (priv->handler, NULL, self);
3814 g_object_unref (call);
3819 empathy_call_window_realized_cb (GtkWidget *widget,
3820 EmpathyCallWindow *self)
3824 /* Make the hangup button twice as wide */
3825 width = gtk_widget_get_allocated_width (self->priv->hangup_button);
3826 gtk_widget_set_size_request (self->priv->hangup_button, width * 2, -1);
3828 empathy_call_window_connect_handler (self);
3830 gst_element_set_state (self->priv->pipeline, GST_STATE_PAUSED);
3834 empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
3835 EmpathyCallWindow *window)
3837 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3839 if (priv->pipeline != NULL)
3841 if (priv->bus_message_source_id != 0)
3843 g_source_remove (priv->bus_message_source_id);
3844 priv->bus_message_source_id = 0;
3847 gst_element_set_state (priv->pipeline, GST_STATE_NULL);
3850 if (priv->call_state == CONNECTING)
3851 empathy_sound_manager_stop (priv->sound_mgr, EMPATHY_SOUND_PHONE_OUTGOING);
3857 show_controls (EmpathyCallWindow *window, gboolean set_fullscreen)
3860 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3862 menu = gtk_ui_manager_get_widget (priv->ui_manager,
3867 gtk_widget_hide (priv->dtmf_panel);
3868 gtk_widget_hide (menu);
3869 gtk_widget_hide (priv->toolbar);
3873 if (priv->dialpad_was_visible_before_fs)
3874 gtk_widget_show (priv->dtmf_panel);
3876 gtk_widget_show (menu);
3877 gtk_widget_show (priv->toolbar);
3879 gtk_window_resize (GTK_WINDOW (window), priv->original_width_before_fs,
3880 priv->original_height_before_fs);
3885 show_borders (EmpathyCallWindow *window, gboolean set_fullscreen)
3887 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3889 gtk_container_set_border_width (GTK_CONTAINER (priv->content_hbox),
3890 set_fullscreen ? 0 : CONTENT_HBOX_BORDER_WIDTH);
3891 gtk_box_set_spacing (GTK_BOX (priv->content_hbox),
3892 set_fullscreen ? 0 : CONTENT_HBOX_SPACING);
3894 if (priv->video_output != NULL)
3897 gtk_box_set_child_packing (GTK_BOX (priv->content_hbox),
3898 priv->video_output, TRUE, TRUE,
3899 set_fullscreen ? 0 : CONTENT_HBOX_CHILDREN_PACKING_PADDING,
3906 empathy_call_window_state_event_cb (GtkWidget *widget,
3907 GdkEventWindowState *event, EmpathyCallWindow *window)
3909 if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN)
3911 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3912 gboolean set_fullscreen = event->new_window_state &
3913 GDK_WINDOW_STATE_FULLSCREEN;
3917 gboolean dialpad_was_visible;
3918 GtkAllocation allocation;
3919 gint original_width, original_height;
3921 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3922 original_width = allocation.width;
3923 original_height = allocation.height;
3925 g_object_get (priv->dtmf_panel,
3926 "visible", &dialpad_was_visible,
3929 priv->dialpad_was_visible_before_fs = dialpad_was_visible;
3930 priv->original_width_before_fs = original_width;
3931 priv->original_height_before_fs = original_height;
3933 if (priv->video_output_motion_handler_id == 0 &&
3934 priv->video_output != NULL)
3936 priv->video_output_motion_handler_id = g_signal_connect (
3937 G_OBJECT (priv->video_container), "motion-notify-event",
3938 G_CALLBACK (empathy_call_window_video_output_motion_notify),
3944 disconnect_video_output_motion_handler (window);
3947 empathy_call_window_fullscreen_set_fullscreen (priv->fullscreen,
3949 show_controls (window, set_fullscreen);
3950 show_borders (window, set_fullscreen);
3951 gtk_action_set_stock_id (priv->menu_fullscreen,
3952 (set_fullscreen ? "gtk-leave-fullscreen" : "gtk-fullscreen"));
3953 priv->is_fullscreen = set_fullscreen;
3960 empathy_call_window_show_dialpad (EmpathyCallWindow *window,
3963 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3964 int w, h, dialpad_width;
3965 GtkAllocation allocation;
3967 gtk_widget_get_allocation (GTK_WIDGET (window), &allocation);
3968 w = allocation.width;
3969 h = allocation.height;
3971 gtk_widget_get_preferred_width (priv->dtmf_panel, &dialpad_width, NULL);
3975 gtk_widget_show (priv->dtmf_panel);
3981 gtk_widget_hide (priv->dtmf_panel);
3985 gtk_window_resize (GTK_WINDOW (window), w, h);
3989 empathy_call_window_set_send_video (EmpathyCallWindow *window,
3992 EmpathyCallWindowPriv *priv = GET_PRIV (window);
3993 TpCallChannel *call;
3995 priv->sending_video = (state == CAMERA_STATE_ON);
3997 if (state == CAMERA_STATE_ON)
3999 /* When we start sending video, we want to show the video preview by
4001 display_video_preview (window, TRUE);
4005 display_video_preview (window, FALSE);
4008 if (priv->call_state != CONNECTED)
4011 g_object_get (priv->handler, "call-channel", &call, NULL);
4012 DEBUG ("%s sending video", priv->sending_video ? "start": "stop");
4013 empathy_call_channel_send_video (call, priv->sending_video);
4014 g_object_unref (call);
4018 empathy_call_window_hangup_cb (gpointer object,
4019 EmpathyCallWindow *self)
4021 /* stopping the call will put it the ENDED state and
4022 * from state_changed_cb we'll reconfigure the window
4024 empathy_call_handler_stop_call (self->priv->handler);
4028 empathy_call_window_restart_call (EmpathyCallWindow *window)
4030 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4032 /* Remove error info bars */
4033 gtk_container_forall (GTK_CONTAINER (priv->errors_vbox),
4034 (GtkCallback) gtk_widget_destroy, NULL);
4036 create_video_output_widget (window);
4037 priv->outgoing = TRUE;
4038 empathy_call_window_set_state_connecting (window);
4040 if (priv->pipeline_playing)
4041 start_call (window);
4043 /* call will be started when the pipeline is ready */
4044 priv->start_call_when_playing = TRUE;
4046 empathy_call_window_setup_avatars (window, priv->handler);
4048 empathy_call_window_show_hangup_button (window, TRUE);
4052 empathy_call_window_dialpad_cb (GtkToggleToolButton *button,
4053 EmpathyCallWindow *window)
4057 active = gtk_toggle_tool_button_get_active (button);
4059 empathy_call_window_show_dialpad (window, active);
4063 empathy_call_window_fullscreen_cb (gpointer object,
4064 EmpathyCallWindow *window)
4066 empathy_call_window_fullscreen_toggle (window);
4070 empathy_call_window_fullscreen_toggle (EmpathyCallWindow *window)
4072 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4074 if (priv->is_fullscreen)
4075 gtk_window_unfullscreen (GTK_WINDOW (window));
4077 gtk_window_fullscreen (GTK_WINDOW (window));
4081 empathy_call_window_video_button_press_cb (GtkWidget *video_preview,
4082 GdkEventButton *event, EmpathyCallWindow *window)
4084 if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
4086 empathy_call_window_video_menu_popup (window, event->button);
4094 empathy_call_window_key_press_cb (GtkWidget *video_output,
4095 GdkEventKey *event, EmpathyCallWindow *window)
4097 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4099 if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
4101 /* Since we are in fullscreen mode, toggling will bring us back to
4103 empathy_call_window_fullscreen_toggle (window);
4111 empathy_call_window_video_output_motion_notify (GtkWidget *widget,
4112 GdkEventMotion *event, EmpathyCallWindow *window)
4114 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4116 if (priv->is_fullscreen)
4118 empathy_call_window_fullscreen_show_popup (priv->fullscreen);
4120 /* Show the bottom toolbar */
4121 empathy_call_window_motion_notify_cb (NULL, NULL, window);
4128 empathy_call_window_video_menu_popup (EmpathyCallWindow *window,
4132 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4134 menu = gtk_ui_manager_get_widget (priv->ui_manager,
4136 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
4137 button, gtk_get_current_event_time ());
4138 gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
4142 empathy_call_window_status_message (EmpathyCallWindow *self,
4145 gtk_label_set_label (GTK_LABEL (self->priv->status_label), message);
4149 empathy_call_window_get_ui_manager (EmpathyCallWindow *window)
4151 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4153 return priv->ui_manager;
4156 EmpathyGstAudioSrc *
4157 empathy_call_window_get_audio_src (EmpathyCallWindow *window)
4159 EmpathyCallWindowPriv *priv = GET_PRIV (window);
4161 return (EmpathyGstAudioSrc *) priv->audio_input;
4164 EmpathyGstVideoSrc *
4165 empathy_call_window_get_video_src (EmpathyCallWindow *self)
4167 return EMPATHY_GST_VIDEO_SRC (self->priv->video_input);
4171 empathy_call_window_change_webcam (EmpathyCallWindow *self,
4172 const gchar *device)
4174 EmpathyGstVideoSrc *video;
4177 /* Restart the camera only if it's already running */
4178 running = (self->priv->video_preview != NULL);
4179 video = empathy_call_window_get_video_src (self);
4182 empathy_call_window_play_camera (self, FALSE);
4184 empathy_video_src_change_device (video, device);
4187 empathy_call_window_play_camera (self, TRUE);