]> git.0d.be Git - empathy.git/blobdiff - src/empathy-call-window.c
Fix typo
[empathy.git] / src / empathy-call-window.c
index 8edf6817c1a7c934dc38d7b873f617f8a88ea10e..1ea9570796806e129b18a61404762ea1bd398520 100644 (file)
@@ -1,7 +1,7 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 /*
- * Copyright (C) 2007 Elliot Fairweather
- * Copyright (C) 2007-2008 Collabora Ltd.
+ * empathy-call-window.c - Source for EmpathyCallWindow
+ * Copyright (C) 2008 Collabora Ltd.
+ * @author Sjoerd Simons <sjoerd.simons@collabora.co.uk>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- *
- * Authors: Elliot Fairweather <elliot.fairweather@collabora.co.uk>
- *          Xavier Claessens <xclaesse@gmail.com>
  */
 
-#include <string.h>
 
-#include <glade/glade.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <gst/gst.h>
+#include <gtk/gtk.h>
 #include <glib/gi18n.h>
 
-#include <telepathy-glib/enums.h>
+#include <telepathy-farsight/channel.h>
 
-#include <libempathy/empathy-contact.h>
-#include <libempathy/empathy-tp-call.h>
-#include <libempathy/empathy-tp-group.h>
 #include <libempathy/empathy-utils.h>
+#include <libempathy-gtk/empathy-video-widget.h>
+#include <libempathy-gtk/empathy-audio-src.h>
+#include <libempathy-gtk/empathy-audio-sink.h>
+#include <libempathy-gtk/empathy-video-src.h>
 #include <libempathy-gtk/empathy-ui-utils.h>
 
 #include "empathy-call-window.h"
 
-#define DEBUG_FLAG EMPATHY_DEBUG_OTHER
-#include <libempathy/empathy-debug.h>
+#include "empathy-sidebar.h"
+
+G_DEFINE_TYPE(EmpathyCallWindow, empathy_call_window, GTK_TYPE_WINDOW)
 
-typedef struct
+/* signal enum */
+#if 0
+enum
 {
-  EmpathyTpCall *call;
-  GTimeVal start_time;
-  guint timeout_event_id;
-  gboolean is_drawing;
-  guint status; 
-
-  GtkWidget *window;
-  GtkWidget *main_hbox;
-  GtkWidget *controls_vbox;
-  GtkWidget *volume_hbox;
-  GtkWidget *status_label;
-  GtkWidget *input_volume_button;
-  GtkWidget *output_volume_button;
-  GtkWidget *preview_video_socket;
-  GtkWidget *output_video_socket;
-  GtkWidget *video_button;
-  GtkWidget *hang_up_button;
-  GtkWidget *confirmation_dialog;
-  GtkWidget *keypad_expander;
-} EmpathyCallWindow;
-
-static GSList *windows = NULL;
+    LAST_SIGNAL
+};
 
-static gboolean
-call_window_update_timer (gpointer data)
+static guint signals[LAST_SIGNAL] = {0};
+#endif
+
+enum {
+  PROP_CALL_HANDLER = 1,
+};
+
+/* private structure */
+typedef struct _EmpathyCallWindowPriv EmpathyCallWindowPriv;
+
+struct _EmpathyCallWindowPriv
 {
-  EmpathyCallWindow *window = data;
-  GTimeVal current;
-  gchar *str;
-  glong now, then;
-  glong time, seconds, minutes, hours;
+  gboolean dispose_has_run;
+  EmpathyCallHandler *handler;
+
+  GtkWidget *video_output;
+  GtkWidget *video_preview;
+  GtkWidget *sidebar;
+  GtkWidget *sidebar_button;
+  GtkWidget *statusbar;
 
-  g_get_current_time (&current);
+  GstElement *video_input;
+  GstElement *audio_input;
+  GstElement *audio_output;
+  GstElement *pipeline;
+  GstElement *video_tee;
 
-  now = current.tv_sec;
-  then = (window->start_time).tv_sec;
+  GladeXML *glade;
+  guint context_id;
+};
 
-  time = now - then;
+#define GET_PRIV(o) \
+  (G_TYPE_INSTANCE_GET_PRIVATE ((o), EMPATHY_TYPE_CALL_WINDOW, \
+    EmpathyCallWindowPriv))
 
-  seconds = time % 60;
-  time /= 60;
-  minutes = time % 60;
-  time /= 60;
-  hours = time % 60;
+static void empathy_call_window_realized_cb (GtkWidget *widget,
+  EmpathyCallWindow *window);
 
-  if (hours > 0)
-      str = g_strdup_printf ("Connected  -  %02ld : %02ld : %02ld", hours,
-          minutes, seconds);
-  else
-      str = g_strdup_printf ("Connected  -  %02ld : %02ld", minutes, seconds);
+static gboolean empathy_call_window_delete_cb (GtkWidget *widget,
+  GdkEvent*event, EmpathyCallWindow *window);
 
-  gtk_label_set_text (GTK_LABEL (window->status_label), str);
+static void empathy_call_window_sidebar_toggled_cb (GtkToggleButton *toggle,
+  EmpathyCallWindow *window);
 
-  g_free (str);
+static void empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
+  EmpathyCallWindow *window);
 
-  return TRUE;
-}
+static void empathy_call_window_sidebar_hidden_cb (EmpathySidebar *sidebar,
+  EmpathyCallWindow *window);
+
+static void empathy_call_window_hangup (EmpathyCallWindow *window);
+
+static void empathy_call_window_status_message (EmpathyCallWindow *window,
+  gchar *message);
+
+static void
+empathy_call_window_session_created_cb (TfChannel *tfchannel,
+  FsConference  *conference, FsParticipant *participant,
+  gpointer user_data);
 
 static void
-call_window_stop_timeout (EmpathyCallWindow *window)
+empathy_call_window_setup_menubar (EmpathyCallWindow *self)
 {
-  DEBUG ("Timer stopped");
+  EmpathyCallWindowPriv *priv = GET_PRIV (self);
+  GtkWidget *hangup;
 
-  if (window->timeout_event_id)
-    {
-      g_source_remove (window->timeout_event_id);
-      window->timeout_event_id = 0;
-    }
+  hangup = glade_xml_get_widget (priv->glade, "menuhangup");
+  g_signal_connect_swapped (G_OBJECT (hangup), "activate",
+    G_CALLBACK (empathy_call_window_hangup), self);
 }
 
 static void
-call_window_set_output_video_is_drawing (EmpathyCallWindow *window,
-                                         gboolean is_drawing)
+empathy_call_window_setup_toolbar (EmpathyCallWindow *self)
 {
-  DEBUG ("Setting output video is drawing - %d", is_drawing);
+  EmpathyCallWindowPriv *priv = GET_PRIV (self);
+  GtkWidget *hangup;
+  GtkWidget *mic;
+  GtkWidget *volume;
+  GtkWidget *volume_button;
+  GtkWidget *camera;
 
-  if (is_drawing && !window->is_drawing)
-    {
-      gtk_window_set_resizable (GTK_WINDOW (window->window), TRUE);
-      gtk_box_pack_end (GTK_BOX (window->main_hbox),
-          window->output_video_socket, TRUE, TRUE, 0);
-      empathy_tp_call_add_output_video (window->call,
-          gtk_socket_get_id (GTK_SOCKET (window->output_video_socket)));
-    }
-  if (!is_drawing && window->is_drawing)
-    {
-      gtk_window_set_resizable (GTK_WINDOW (window->window), FALSE);
-      empathy_tp_call_add_output_video (window->call, 0);
-      gtk_container_remove (GTK_CONTAINER (window->main_hbox),
-          window->output_video_socket);
-    }
+  hangup = glade_xml_get_widget (priv->glade, "hangup");
+
+  g_signal_connect_swapped (G_OBJECT (hangup), "clicked",
+    G_CALLBACK (empathy_call_window_hangup), self);
 
-  window->is_drawing = is_drawing;
+  mic = glade_xml_get_widget (priv->glade, "microphone");
+  gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (mic), TRUE);
+
+  volume = glade_xml_get_widget (priv->glade, "volume");
+  volume_button = gtk_volume_button_new ();
+  gtk_container_add (GTK_CONTAINER (volume), volume_button);
+  gtk_scale_button_set_value (GTK_SCALE_BUTTON (volume_button), 0.5);
+
+  camera = glade_xml_get_widget (priv->glade, "camera");
+  gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (camera), FALSE);
+
+  g_signal_connect (G_OBJECT (camera), "toggled",
+    G_CALLBACK (empathy_call_window_camera_toggled_cb), self);
 }
 
-static void
-call_window_finalize (EmpathyCallWindow *window)
+static GtkWidget *
+empathy_call_window_create_dtmf (EmpathyCallWindow *self)
 {
-  gtk_label_set_text (GTK_LABEL (window->status_label), _("Closed"));
-  gtk_widget_set_sensitive (window->hang_up_button, FALSE);
-  gtk_widget_set_sensitive (window->video_button, FALSE);
-  gtk_widget_set_sensitive (window->output_volume_button, FALSE);
-  gtk_widget_set_sensitive (window->input_volume_button, FALSE);
-  gtk_widget_set_sensitive (window->keypad_expander, FALSE);
-
-  if (window->call)
-    { 
-      call_window_stop_timeout (window);
-      call_window_set_output_video_is_drawing (window, FALSE);
-      empathy_tp_call_remove_preview_video (window->call,
-          gtk_socket_get_id (GTK_SOCKET (window->preview_video_socket)));
-      g_object_unref (window->call);
-      window->call = NULL;
+  GtkWidget *table;
+  int i;
+  const gchar *strings[] = { "1", "2", "3",
+                             "4", "5", "6",
+                             "7", "8", "9",
+                             "#", "0", "*",
+                             NULL };
+
+  table = gtk_table_new (4, 3, TRUE);
+
+  for (i = 0; strings[i] != NULL; i++)
+    {
+      GtkWidget *button = gtk_button_new_with_label (strings[i]);
+      gtk_table_attach (GTK_TABLE (table), button, i % 3, i % 3 + 1,
+        i/3, i/3 + 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 1, 1);
     }
 
-  if (window->confirmation_dialog)
-      gtk_widget_destroy (window->confirmation_dialog);
+  return table;
 }
 
-static void
-call_window_socket_realized_cb (GtkWidget *widget,
-                                EmpathyCallWindow *window)
+static GtkWidget *
+empathy_call_window_create_video_input (EmpathyCallWindow *self)
 {
-  if (widget == window->preview_video_socket)
+  GtkWidget *hbox;
+  int i;
+  gchar *controls[] = { _("Contrast"), _("Brightness"), _("Gamma"), NULL };
+
+  hbox = gtk_hbox_new (TRUE, 3);
+
+  for (i = 0; controls[i] != NULL; i++)
     {
-      DEBUG ("Preview socket realized");
-      empathy_tp_call_add_preview_video (window->call,
-          gtk_socket_get_id (GTK_SOCKET (window->preview_video_socket)));
+      GtkWidget *vbox = gtk_vbox_new (FALSE, 2);
+      GtkWidget *scale = gtk_vscale_new_with_range (0, 100, 10);
+      GtkWidget *label = gtk_label_new (controls[i]);
+
+      gtk_container_add (GTK_CONTAINER (hbox), vbox);
+
+      gtk_range_set_inverted (GTK_RANGE (scale), TRUE);
+      gtk_box_pack_start (GTK_BOX (vbox), scale, TRUE, TRUE, 0);
+      gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
     }
-  else
-      DEBUG ("Output socket realized");
+
+  return hbox;
 }
 
-static void
-call_window_video_button_toggled_cb (GtkWidget *button,
-                                     EmpathyCallWindow *window)
+static GtkWidget *
+empathy_call_window_create_audio_input (EmpathyCallWindow *self)
 {
-  gboolean is_sending;
-  guint status;
+  GtkWidget *hbox, *vbox, *scale, *progress, *label;
 
-  is_sending = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
+  hbox = gtk_hbox_new (TRUE, 3);
 
-  DEBUG ("Send video toggled - %d", is_sending);
+  vbox = gtk_vbox_new (FALSE, 3);
+  gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 3);
 
-  g_object_get (window->call, "status", &status, NULL);
-  if (status == EMPATHY_TP_CALL_STATUS_ACCEPTED)
-      empathy_tp_call_request_video_stream_direction (window->call, is_sending);
+  scale = gtk_vscale_new_with_range (0, 100, 10);
+  gtk_range_set_inverted (GTK_RANGE (scale), TRUE);
+  label = gtk_label_new (_("Volume"));
+
+  gtk_box_pack_start (GTK_BOX (vbox), scale, TRUE, TRUE, 3);
+  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 3);
+
+
+  progress = gtk_progress_bar_new ();
+  gtk_progress_bar_set_orientation (GTK_PROGRESS_BAR (progress),
+    GTK_PROGRESS_BOTTOM_TO_TOP);
+  gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress), 0.5);
+
+  gtk_box_pack_start (GTK_BOX (hbox), progress, FALSE, FALSE, 3);
+
+  return hbox;
 }
 
 static void
-call_window_hang_up_button_clicked_cb (GtkWidget *widget,
-                                       EmpathyCallWindow *window)
+empathy_call_window_init (EmpathyCallWindow *self)
 {
-  DEBUG ("Call clicked, end call");
-  call_window_finalize (window);
+  EmpathyCallWindowPriv *priv = GET_PRIV (self);
+  GtkWidget *vbox, *top_vbox;
+  GtkWidget *hbox, *h;
+  GtkWidget *arrow;
+  GtkWidget *page;
+  GstBus *bus;
+  gchar *filename;
+  GtkWidget *pane;
+
+  filename = empathy_file_lookup ("empathy-call-window.glade", "src");
+
+  priv->glade = empathy_glade_get_file (filename, "call_window", NULL,
+    "call_window_vbox", &top_vbox,
+    "pane", &pane,
+    "statusbar", &priv->statusbar,
+    NULL);
+
+  gtk_widget_reparent (top_vbox, GTK_WIDGET (self));
+
+  empathy_call_window_setup_menubar (self);
+  empathy_call_window_setup_toolbar (self);
+
+  priv->pipeline = gst_pipeline_new (NULL);
+
+  hbox = gtk_hbox_new (FALSE, 3);
+  gtk_paned_pack1 (GTK_PANED(pane), hbox, TRUE, FALSE);
+
+  bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
+
+  priv->video_output = empathy_video_widget_new (bus);
+  gtk_box_pack_start (GTK_BOX (hbox), priv->video_output, TRUE, TRUE, 3);
+
+  priv->video_tee = gst_element_factory_make ("tee", NULL);
+  gst_object_ref (priv->video_tee);
+  gst_object_sink (priv->video_tee);
+
+  vbox = gtk_vbox_new (FALSE, 3);
+  gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 3);
+
+  priv->video_preview = empathy_video_widget_new_with_size (bus, 160, 120);
+  gtk_box_pack_start (GTK_BOX (vbox), priv->video_preview, FALSE, FALSE, 3);
+
+  priv->video_input = empathy_video_src_new ();
+  gst_object_ref (priv->video_input);
+  gst_object_sink (priv->video_input);
+
+  priv->audio_input = empathy_audio_src_new ();
+  gst_object_ref (priv->audio_input);
+  gst_object_sink (priv->audio_input);
+
+  priv->audio_output = empathy_audio_sink_new ();
+  gst_object_ref (priv->audio_output);
+  gst_object_sink (priv->audio_output);
+
+  g_object_unref (bus);
+
+  priv->sidebar_button = gtk_toggle_button_new_with_mnemonic (_("_Sidebar"));
+  arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
+  g_signal_connect (G_OBJECT (priv->sidebar_button), "toggled",
+    G_CALLBACK (empathy_call_window_sidebar_toggled_cb), self);
+
+  gtk_button_set_image (GTK_BUTTON (priv->sidebar_button), arrow);
+
+  h = gtk_hbox_new (FALSE, 3);
+  gtk_box_pack_end (GTK_BOX (vbox), h, FALSE, FALSE, 3);
+  gtk_box_pack_end (GTK_BOX (h), priv->sidebar_button, FALSE, FALSE, 3);
+
+  priv->sidebar = empathy_sidebar_new ();
+  g_signal_connect (G_OBJECT (priv->sidebar),
+    "hide", G_CALLBACK (empathy_call_window_sidebar_hidden_cb),
+    self);
+  gtk_paned_pack2 (GTK_PANED(pane), priv->sidebar, FALSE, FALSE);
+
+  page = empathy_call_window_create_dtmf (self);
+  empathy_sidebar_add_page (EMPATHY_SIDEBAR (priv->sidebar), _("Dialpad"),
+    page);
+
+  page = empathy_call_window_create_audio_input (self);
+  empathy_sidebar_add_page (EMPATHY_SIDEBAR (priv->sidebar), _("Audio input"),
+    page);
+
+  page = empathy_call_window_create_video_input (self);
+  empathy_sidebar_add_page (EMPATHY_SIDEBAR (priv->sidebar), _("Video input"),
+    page);
+
+  gtk_widget_show_all (top_vbox);
+
+  gtk_widget_hide (priv->sidebar);
+
+  g_signal_connect (G_OBJECT (self), "realize",
+    G_CALLBACK (empathy_call_window_realized_cb), self);
+
+  g_signal_connect (G_OBJECT (self), "delete-event",
+    G_CALLBACK (empathy_call_window_delete_cb), self);
+
+  empathy_call_window_status_message (self, _("Connecting..."));
 }
 
+static void empathy_call_window_dispose (GObject *object);
+static void empathy_call_window_finalize (GObject *object);
+
 static void
-call_window_output_volume_changed_cb (GtkScaleButton *button,
-                                      gdouble value,
-                                      EmpathyCallWindow *window)
+empathy_call_window_set_property (GObject *object,
+  guint property_id, const GValue *value, GParamSpec *pspec)
 {
-  if (!window->call)
-      return;
+  EmpathyCallWindowPriv *priv = GET_PRIV (object);
 
-  if (value <= 0)
-      empathy_tp_call_mute_output (window->call, TRUE);
-  else
+  switch (property_id)
     {
-      empathy_tp_call_mute_output (window->call, FALSE);
-      empathy_tp_call_set_output_volume (window->call, value * 100);
+      case PROP_CALL_HANDLER:
+        priv->handler = g_value_dup_object (value);
+        break;
+      default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     }
 }
 
 static void
-call_window_input_volume_changed_cb (GtkScaleButton    *button,
-                                     gdouble            value,
-                                     EmpathyCallWindow *window)
+empathy_call_window_get_property (GObject *object,
+  guint property_id, GValue *value, GParamSpec *pspec)
 {
-  if (!window->call)
-      return;
+  EmpathyCallWindowPriv *priv = GET_PRIV (object);
 
-  if (value <= 0)
-      empathy_tp_call_mute_input (window->call, TRUE);
-  else
+  switch (property_id)
     {
-      empathy_tp_call_mute_input (window->call, FALSE);
-      /* FIXME: Not implemented?
-      empathy_tp_call_set_input_volume (window->call, value * 100);*/
+      case PROP_CALL_HANDLER:
+        g_value_set_object (value, priv->handler);
+        break;
+      default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     }
 }
 
-static gboolean
-call_window_delete_event_cb (GtkWidget *widget,
-                             GdkEvent *event,
-                             EmpathyCallWindow *window)
+static void
+empathy_call_window_class_init (
+  EmpathyCallWindowClass *empathy_call_window_class)
 {
-  GtkWidget *dialog;
-  gint result;
-  guint status = EMPATHY_TP_CALL_STATUS_CLOSED;
+  GObjectClass *object_class = G_OBJECT_CLASS (empathy_call_window_class);
+  GParamSpec *param_spec;
 
-  DEBUG ("Delete event occurred");
+  g_type_class_add_private (empathy_call_window_class,
+    sizeof (EmpathyCallWindowPriv));
 
-  if (window->call)
-      g_object_get (window->call, "status", &status, NULL);
+  object_class->set_property = empathy_call_window_set_property;
+  object_class->get_property = empathy_call_window_get_property;
 
-  if (status == EMPATHY_TP_CALL_STATUS_ACCEPTED)
-    {
-      dialog = gtk_message_dialog_new (GTK_WINDOW (window->window),
-          GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
-          GTK_MESSAGE_WARNING, GTK_BUTTONS_CANCEL, _("End this call?"));
-      gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
-          _("Closing this window will end the call in progress."));
-      gtk_dialog_add_button (GTK_DIALOG (dialog), _("_End Call"), GTK_RESPONSE_OK);
-      gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
-
-      result = gtk_dialog_run (GTK_DIALOG (dialog));
-      gtk_widget_destroy (dialog);
-
-      if (result != GTK_RESPONSE_OK)
-          return TRUE;
-    }
+  object_class->dispose = empathy_call_window_dispose;
+  object_class->finalize = empathy_call_window_finalize;
 
-  return FALSE;
+  param_spec = g_param_spec_object ("handler",
+    "handler", "The call handler",
+    EMPATHY_TYPE_CALL_HANDLER,
+    G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+  g_object_class_install_property (object_class,
+    PROP_CALL_HANDLER, param_spec);
+
+}
+
+void
+empathy_call_window_dispose (GObject *object)
+{
+  EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
+  EmpathyCallWindowPriv *priv = GET_PRIV (self);
+
+  if (priv->dispose_has_run)
+    return;
+
+  priv->dispose_has_run = TRUE;
+
+  if (priv->handler != NULL)
+    g_object_unref (priv->handler);
+
+  priv->handler = NULL;
+
+  if (priv->pipeline != NULL)
+    g_object_unref (priv->pipeline);
+  priv->pipeline = NULL;
+
+  if (priv->video_input != NULL)
+    g_object_unref (priv->video_input);
+  priv->video_input = NULL;
+
+  if (priv->audio_input != NULL)
+    g_object_unref (priv->audio_input);
+  priv->audio_input = NULL;
+
+  if (priv->audio_output != NULL)
+    g_object_unref (priv->audio_output);
+  priv->audio_output = NULL;
+
+  if (priv->video_tee != NULL)
+    g_object_unref (priv->video_tee);
+  priv->video_tee = NULL;
+
+  /* release any references held by the object here */
+  if (G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose)
+    G_OBJECT_CLASS (empathy_call_window_parent_class)->dispose (object);
+}
+
+void
+empathy_call_window_finalize (GObject *object)
+{
+  //EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (object);
+  //EmpathyCallWindowPriv *priv = GET_PRIV (self);
+
+  /* free any data held directly by the object here */
+
+  G_OBJECT_CLASS (empathy_call_window_parent_class)->finalize (object);
+}
+
+
+EmpathyCallWindow *
+empathy_call_window_new (EmpathyCallHandler *handler)
+{
+  return EMPATHY_CALL_WINDOW (
+    g_object_new (EMPATHY_TYPE_CALL_WINDOW, "handler", handler, NULL));
 }
 
 static void
-call_window_destroy_cb (GtkWidget *widget,
-                        EmpathyCallWindow *window)
+empathy_call_window_conference_added_cb (EmpathyCallHandler *handler,
+  GstElement *conference, gpointer user_data)
 {
-  call_window_finalize (window);
+  EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
+  EmpathyCallWindowPriv *priv = GET_PRIV (self);
 
-  g_object_unref (window->output_video_socket);
-  g_object_unref (window->preview_video_socket);
+  gst_bin_add (GST_BIN (priv->pipeline), conference);
 
-  windows = g_slist_remove (windows, window);
-  g_slice_free (EmpathyCallWindow, window);
+  gst_element_set_state (conference, GST_STATE_PLAYING);
 }
 
 static void
-call_window_confirmation_dialog_response_cb (GtkDialog *dialog,
-                                             gint response,
-                                             EmpathyCallWindow *window)
+empathy_call_window_channel_closed_cb (TfChannel *channel, gpointer user_data)
 {
-  if (response == GTK_RESPONSE_OK && window->call)
-      empathy_tp_call_accept_incoming_call (window->call);
-  else
-      call_window_finalize (window);
+  EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
 
-  gtk_widget_destroy (window->confirmation_dialog);
-  window->confirmation_dialog = NULL;
+  empathy_call_window_status_message (self, _("Disconnected"));
 }
 
 static void
-call_window_show_confirmation_dialog (EmpathyCallWindow *window)
+empathy_call_window_session_created_cb (TfChannel *tfchannel,
+  FsConference  *conference, FsParticipant *participant,
+  gpointer user_data)
 {
-  EmpathyContact *contact;
-  GtkWidget *button;
-  GtkWidget *image;
-
-  if (window->confirmation_dialog)
-      return;
-
-  g_object_get (window->call, "contact", &contact, NULL);
-
-  window->confirmation_dialog = gtk_message_dialog_new (GTK_WINDOW (window->window),
-      GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
-      GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, _("Incoming call"));
-  gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (window->confirmation_dialog),
-      _("%s is calling you, do you want to answer?"),
-      empathy_contact_get_name (contact));
-  gtk_dialog_set_default_response (GTK_DIALOG (window->confirmation_dialog),
-      GTK_RESPONSE_OK);
-
-  button = gtk_dialog_add_button (GTK_DIALOG (window->confirmation_dialog),
-      _("_Reject"), GTK_RESPONSE_CANCEL);
-  image = gtk_image_new_from_icon_name (GTK_STOCK_CANCEL, GTK_ICON_SIZE_BUTTON);
-  gtk_button_set_image (GTK_BUTTON (button), image);
-
-  button = gtk_dialog_add_button (GTK_DIALOG (window->confirmation_dialog),
-      _("_Answer"), GTK_RESPONSE_OK);
-  image = gtk_image_new_from_icon_name (GTK_STOCK_APPLY, GTK_ICON_SIZE_BUTTON);
-  gtk_button_set_image (GTK_BUTTON (button), image);
-
-  g_signal_connect (window->confirmation_dialog, "response",
-      G_CALLBACK (call_window_confirmation_dialog_response_cb),
-      window);
-
-  gtk_widget_show (window->confirmation_dialog);
-  g_object_unref (contact);
+  g_signal_connect (G_OBJECT (tfchannel), "closed",
+    G_CALLBACK (empathy_call_window_channel_closed_cb), user_data);
 }
 
 static void
-call_window_update (EmpathyCallWindow *window)
+empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
+  GstPad *src, guint media_type, gpointer user_data)
 {
-  EmpathyContact *contact;
-  guint stream_state;
-  EmpathyTpCallStream *audio_stream;
-  EmpathyTpCallStream *video_stream;
-  gboolean is_incoming;
-  gchar *title;
-
-  g_object_get (window->call,
-      "status", &window->status,
-      "audio-stream", &audio_stream,
-      "video-stream", &video_stream,
-      "contact", &contact,
-      "is-incoming", &is_incoming,
-      NULL);
-
-  if (video_stream->state > audio_stream->state)
-      stream_state = video_stream->state;
-  else
-      stream_state = audio_stream->state;
+  EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
+  EmpathyCallWindowPriv *priv = GET_PRIV (self);
 
-  DEBUG ("Status changed - status: %d, stream state: %d, "
-      "is-incoming: %d video-stream direction: %d",
-      window->status, stream_state, is_incoming, video_stream->direction);
+  GstPad *pad;
+  GstElement *element;
+  gchar *str;
 
-  if (empathy_tp_call_has_dtmf (window->call))
-    {
-      gtk_widget_show (window->keypad_expander);
-    }
-  else
+  str = g_strdup_printf (_("Connected -- %d:%02dm"), 0, 0);
+  empathy_call_window_status_message (self, str);
+  g_free (str);
+
+  switch (media_type)
     {
-      gtk_widget_hide (window->keypad_expander);
+      case TP_MEDIA_STREAM_TYPE_AUDIO:
+        element = priv->audio_output;
+        g_object_ref (element);
+        break;
+      case TP_MEDIA_STREAM_TYPE_VIDEO:
+        element =
+          empathy_video_widget_get_element (
+            EMPATHY_VIDEO_WIDGET (priv->video_output));
+        break;
+      default:
+        g_assert_not_reached ();
     }
 
-  /* Depending on the status we have to set:
-   * - window's title
-   * - status's label
-   * - sensibility of all buttons
-   * */
-  if (window->status == EMPATHY_TP_CALL_STATUS_READYING)
+  gst_bin_add (GST_BIN (priv->pipeline), element);
+
+  pad = gst_element_get_static_pad (element, "sink");
+  gst_element_set_state (element, GST_STATE_PLAYING);
+
+  gst_pad_link (src, pad);
+}
+
+static void
+empathy_call_window_sink_added_cb (EmpathyCallHandler *handler,
+  GstPad *sink, guint media_type, gpointer user_data)
+{
+  EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
+  EmpathyCallWindowPriv *priv = GET_PRIV (self);
+  GstPad *pad;
+
+  switch (media_type)
     {
-      gtk_window_set_title (GTK_WINDOW (window->window), _("Empathy Call"));
-      /* To translators: Readying is the first state of the call, it is
-       * preparing the connection and it does not yet ring. */
-      gtk_label_set_text (GTK_LABEL (window->status_label), _("Readying"));
-      gtk_widget_set_sensitive (window->video_button, FALSE);
-      gtk_widget_set_sensitive (window->output_volume_button, FALSE);
-      gtk_widget_set_sensitive (window->input_volume_button, FALSE);
-      gtk_widget_set_sensitive (window->hang_up_button, FALSE);
-      gtk_widget_set_sensitive (window->keypad_expander, FALSE);
+      case TP_MEDIA_STREAM_TYPE_AUDIO:
+        gst_bin_add (GST_BIN (priv->pipeline), priv->audio_input);
+        gst_element_set_state (priv->audio_input, GST_STATE_PLAYING);
+
+        pad = gst_element_get_static_pad (priv->audio_input, "src");
+        gst_pad_link (pad, sink);
+        break;
+      case TP_MEDIA_STREAM_TYPE_VIDEO:
+        pad =  gst_element_get_request_pad (priv->video_tee, "src%d");
+        gst_pad_link (pad, sink);
+        break;
+      default:
+        g_assert_not_reached ();
     }
-  else if (window->status == EMPATHY_TP_CALL_STATUS_PENDING)
+
+}
+
+static void
+empathy_call_window_realized_cb (GtkWidget *widget, EmpathyCallWindow *window)
+{
+  EmpathyCallWindowPriv *priv = GET_PRIV (window);
+  GstElement *preview;
+  GstBus *bus;
+
+  g_signal_connect (priv->handler, "conference-added",
+    G_CALLBACK (empathy_call_window_conference_added_cb), window);
+  g_signal_connect (priv->handler, "session-created",
+    G_CALLBACK (empathy_call_window_session_created_cb), window);
+  g_signal_connect (priv->handler, "src-pad-added",
+    G_CALLBACK (empathy_call_window_src_added_cb), window);
+  g_signal_connect (priv->handler, "sink-pad-added",
+    G_CALLBACK (empathy_call_window_sink_added_cb), window);
+
+  bus = gst_pipeline_get_bus (GST_PIPELINE (priv->pipeline));
+  empathy_call_handler_set_bus (priv->handler, bus);
+  empathy_call_handler_start_call (priv->handler);
+
+  preview = empathy_video_widget_get_element (
+    EMPATHY_VIDEO_WIDGET (priv->video_preview));
+
+  gst_bin_add_many (GST_BIN (priv->pipeline), priv->video_input,
+    priv->video_tee, preview, NULL);
+  gst_element_link_many (priv->video_input, priv->video_tee,
+    preview, NULL);
+
+  gst_element_set_state (priv->pipeline, GST_STATE_PLAYING);
+
+  g_object_unref (bus);
+}
+
+static gboolean
+empathy_call_window_delete_cb (GtkWidget *widget, GdkEvent*event,
+  EmpathyCallWindow *window)
+{
+  EmpathyCallWindowPriv *priv = GET_PRIV (window);
+
+  gst_element_set_state (priv->pipeline, GST_STATE_NULL);
+
+  return FALSE;
+}
+
+static void
+empathy_call_window_sidebar_toggled_cb (GtkToggleButton *toggle,
+  EmpathyCallWindow *window)
+{
+  EmpathyCallWindowPriv *priv = GET_PRIV (window);
+  GtkWidget *arrow;
+
+  if (gtk_toggle_button_get_active (toggle))
     {
-      title = g_strdup_printf (_("%s - Empathy Call"),
-          empathy_contact_get_name (contact));
-
-      gtk_window_set_title (GTK_WINDOW (window->window), title);
-      gtk_label_set_text (GTK_LABEL (window->status_label), _("Ringing"));
-      gtk_widget_set_sensitive (window->hang_up_button, TRUE);
-      if (is_incoming)
-          call_window_show_confirmation_dialog (window);
+      arrow = gtk_arrow_new (GTK_ARROW_LEFT, GTK_SHADOW_NONE);
+      gtk_widget_show (priv->sidebar);
     }
-  else if (window->status == EMPATHY_TP_CALL_STATUS_ACCEPTED)
+  else
     {
-      gboolean receiving_video;
-      gboolean sending_video;
-
-      if (stream_state == TP_MEDIA_STREAM_STATE_DISCONNECTED)
-          gtk_label_set_text (GTK_LABEL (window->status_label), _("Disconnected"));
-      if (stream_state == TP_MEDIA_STREAM_STATE_CONNECTING)
-          gtk_label_set_text (GTK_LABEL (window->status_label), _("Connecting"));
-      else if (stream_state == TP_MEDIA_STREAM_STATE_CONNECTED &&
-               window->timeout_event_id == 0)
-        {
-          /* The call started, launch the timer */
-          g_get_current_time (&(window->start_time));
-          window->timeout_event_id = g_timeout_add_seconds (1,
-              call_window_update_timer, window);
-          call_window_update_timer (window);
-        }
-
-      receiving_video = video_stream->direction & TP_MEDIA_STREAM_DIRECTION_RECEIVE;
-      sending_video = video_stream->direction & TP_MEDIA_STREAM_DIRECTION_SEND;
-      call_window_set_output_video_is_drawing (window, receiving_video);
-      g_signal_handlers_block_by_func (window->video_button,
-          call_window_video_button_toggled_cb, window);
-      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (window->video_button),
-          sending_video);
-      g_signal_handlers_unblock_by_func (window->video_button,
-          call_window_video_button_toggled_cb, window);
-
-      gtk_widget_set_sensitive (window->video_button, TRUE);
-      gtk_widget_set_sensitive (window->output_volume_button, TRUE);
-      gtk_widget_set_sensitive (window->input_volume_button, TRUE);
-      gtk_widget_set_sensitive (window->hang_up_button, TRUE);
-      gtk_widget_set_sensitive (window->keypad_expander, TRUE);
+      arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
+      gtk_widget_hide (priv->sidebar);
     }
-  else if (window->status == EMPATHY_TP_CALL_STATUS_CLOSED)
-      call_window_finalize (window);
 
-  if (contact)
-      g_object_unref (contact);
+  gtk_button_set_image (GTK_BUTTON (priv->sidebar_button), arrow);
 }
 
-static gboolean
-call_window_dtmf_button_release_event_cb (GtkWidget *widget,
-                                          GdkEventButton *event,
-                                          EmpathyCallWindow *window)
+static void
+empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
+  EmpathyCallWindow *window)
 {
-  empathy_tp_call_stop_tone (window->call);
-  return FALSE;
+  EmpathyCallWindowPriv *priv = GET_PRIV (window);
+  gboolean active;
+  EmpathyTpCall *call;
+
+  active = (gtk_toggle_tool_button_get_active (toggle));
+
+  g_object_get (priv->handler, "tp-call", &call, NULL);
+
+  empathy_tp_call_request_video_stream_direction (call, active);
+
+  g_object_unref (call);
 }
 
-static gboolean
-call_window_dtmf_button_press_event_cb (GtkWidget *widget,
-                                        GdkEventButton *event,
-                                        EmpathyCallWindow *window)
+static void
+empathy_call_window_sidebar_hidden_cb (EmpathySidebar *sidebar,
+  EmpathyCallWindow *window)
 {
-  TpDTMFEvent dtmf_event;
+  EmpathyCallWindowPriv *priv = GET_PRIV (window);
 
-  dtmf_event = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (widget), "code"));
-  empathy_tp_call_start_tone (window->call, dtmf_event);
-  return FALSE;
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->sidebar_button),
+    FALSE);
 }
 
 static void
-call_window_dtmf_connect (GladeXML *glade,
-                          EmpathyCallWindow *window,
-                          const gchar *name,
-                          TpDTMFEvent event)
+empathy_call_window_hangup (EmpathyCallWindow *window)
 {
-  GtkWidget *widget;
-
-  widget = glade_xml_get_widget (glade, name);
-  g_object_set_data (G_OBJECT (widget), "code", GUINT_TO_POINTER (event));
-  g_signal_connect (widget, "button-press-event",
-      G_CALLBACK (call_window_dtmf_button_press_event_cb), window);
-  g_signal_connect (widget, "button-release-event",
-      G_CALLBACK (call_window_dtmf_button_release_event_cb), window);
-  /* FIXME: Connect "key-[press/release]-event" to*/
+  EmpathyCallWindowPriv *priv = GET_PRIV (window);
+
+  gst_element_set_state (priv->pipeline, GST_STATE_NULL);
+  gtk_widget_destroy (GTK_WIDGET (window));
 }
 
-GtkWidget *
-empathy_call_window_new (TpChannel *channel)
+static void
+empathy_call_window_status_message (EmpathyCallWindow *window,
+  gchar *message)
 {
-  EmpathyCallWindow *window;
-  GladeXML *glade;
-  gchar *filename;
-  const gchar *icons[] = {"audio-input-microphone", NULL};
+  EmpathyCallWindowPriv *priv = GET_PRIV (window);
 
-  g_return_val_if_fail (TP_IS_CHANNEL (channel), NULL);
-
-  if (windows)
+  if (priv->context_id == 0)
     {
-      window = (EmpathyCallWindow*) windows->data;
-      if (!window->call)
-        {
-          window->call = empathy_tp_call_new (channel);
-          g_signal_connect_swapped (G_OBJECT (window->call), "notify",
-              G_CALLBACK (call_window_update), window);
-          call_window_update (window);
-
-          if (GTK_WIDGET_REALIZED (GTK_WIDGET (window->preview_video_socket)))
-            {
-              call_window_socket_realized_cb (window->preview_video_socket,
-                  window);
-            }
-        }
-      else
-        {
-          GtkWidget *dialog;
-          EmpathyContact *contact;
-          EmpathyTpGroup *tp_group;
-
-          tp_group = empathy_tp_group_new (channel);
-          empathy_run_until_ready (tp_group);
-          empathy_tp_group_get_invitation (tp_group, &contact);
-          empathy_contact_run_until_ready (contact, EMPATHY_CONTACT_READY_NAME,
-              NULL);
-
-          /* We don't want to have multiple calls running.
-           * FIXME: We should use the hold interface... */
-          tp_cli_channel_call_close (channel, -1, NULL, NULL, NULL, NULL);
-
-          dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_INFO,
-              GTK_BUTTONS_CLOSE,
-              _("Incoming call from %s rejected because there is already a"
-                " running call."), empathy_contact_get_name (contact));
-
-          g_object_unref (contact);
-          g_object_unref (tp_group);
-
-          g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy),
-              NULL);
-          gtk_widget_show (dialog);
-        }
-
-      gtk_window_present (GTK_WINDOW (window->window));
-      return window->window;
+      priv->context_id = gtk_statusbar_get_context_id (
+        GTK_STATUSBAR (priv->statusbar), "voip call status messages");
+    }
+  else
+    {
+      gtk_statusbar_pop (GTK_STATUSBAR (priv->statusbar), priv->context_id);
     }
 
-  window = g_slice_new0 (EmpathyCallWindow);
-  windows = g_slist_prepend (windows, window);
-  window->call = empathy_tp_call_new (channel);
-
-  filename = empathy_file_lookup ("empathy-call-window.glade", "src");
-  glade = empathy_glade_get_file (filename,
-      "window",
-      NULL,
-      "window", &window->window,
-      "main_hbox", &window->main_hbox,
-      "controls_vbox", &window->controls_vbox,
-      "volume_hbox", &window->volume_hbox,
-      "status_label", &window->status_label,
-      "video_button", &window->video_button,
-      "hang_up_button", &window->hang_up_button,
-      "keypad_expander", &window->keypad_expander,
-      NULL);
-  g_free (filename);
-
-  empathy_glade_connect (glade,
-      window,
-      "window", "destroy", call_window_destroy_cb,
-      "window", "delete_event", call_window_delete_event_cb,
-      "hang_up_button", "clicked", call_window_hang_up_button_clicked_cb,
-      "video_button", "toggled", call_window_video_button_toggled_cb,
-      NULL);
-
-  /* Setup DTMF buttons */
-  call_window_dtmf_connect (glade, window, "button_0", TP_DTMF_EVENT_DIGIT_0);
-  call_window_dtmf_connect (glade, window, "button_1", TP_DTMF_EVENT_DIGIT_1);
-  call_window_dtmf_connect (glade, window, "button_2", TP_DTMF_EVENT_DIGIT_2);
-  call_window_dtmf_connect (glade, window, "button_3", TP_DTMF_EVENT_DIGIT_3);
-  call_window_dtmf_connect (glade, window, "button_4", TP_DTMF_EVENT_DIGIT_4);
-  call_window_dtmf_connect (glade, window, "button_5", TP_DTMF_EVENT_DIGIT_5);
-  call_window_dtmf_connect (glade, window, "button_6", TP_DTMF_EVENT_DIGIT_6);
-  call_window_dtmf_connect (glade, window, "button_7", TP_DTMF_EVENT_DIGIT_7);
-  call_window_dtmf_connect (glade, window, "button_8", TP_DTMF_EVENT_DIGIT_8);
-  call_window_dtmf_connect (glade, window, "button_9", TP_DTMF_EVENT_DIGIT_9);
-  call_window_dtmf_connect (glade, window, "button_asterisk", TP_DTMF_EVENT_ASTERISK);
-  call_window_dtmf_connect (glade, window, "button_hash", TP_DTMF_EVENT_HASH);
-
-  g_object_unref (glade);
-
-  /* Output volume button */
-  window->output_volume_button = gtk_volume_button_new ();
-  gtk_scale_button_set_value (GTK_SCALE_BUTTON (window->output_volume_button), 1);
-  gtk_box_pack_start (GTK_BOX (window->volume_hbox),
-      window->output_volume_button, FALSE, FALSE, 0);
-  gtk_widget_show (window->output_volume_button);
-  g_signal_connect (window->output_volume_button, "value-changed",
-      G_CALLBACK (call_window_output_volume_changed_cb), window);
-
-  /* Input volume button */
-  window->input_volume_button = gtk_volume_button_new ();
-  gtk_scale_button_set_icons (GTK_SCALE_BUTTON (window->input_volume_button),
-      icons);
-  gtk_scale_button_set_value (GTK_SCALE_BUTTON (window->input_volume_button), 1);
-  gtk_box_pack_start (GTK_BOX (window->volume_hbox),
-      window->input_volume_button, FALSE, FALSE, 0);
-  gtk_widget_show (window->input_volume_button);
-  g_signal_connect (window->input_volume_button, "value-changed",
-      G_CALLBACK (call_window_input_volume_changed_cb), window);
-
-  /* Output video socket */
-  window->output_video_socket = g_object_ref (gtk_socket_new ());
-  gtk_widget_set_size_request (window->output_video_socket, 400, 300);
-  g_signal_connect (GTK_OBJECT (window->output_video_socket), "realize",
-      G_CALLBACK (call_window_socket_realized_cb), window);
-  gtk_widget_show (window->output_video_socket);
-
-  /* Preview video socket */
-  window->preview_video_socket = g_object_ref (gtk_socket_new ());
-  gtk_widget_set_size_request (window->preview_video_socket, 176, 144);
-  g_signal_connect (GTK_OBJECT (window->preview_video_socket), "realize",
-      G_CALLBACK (call_window_socket_realized_cb), window);
-  gtk_widget_show (window->preview_video_socket);
-
-  /* FIXME: We shouldn't do this if there is no video input */
-  gtk_box_pack_start (GTK_BOX (window->controls_vbox),
-      window->preview_video_socket, FALSE, FALSE, 0);
-  gtk_box_reorder_child (GTK_BOX (window->controls_vbox),
-      window->preview_video_socket, 0);
-
-  g_signal_connect_swapped (G_OBJECT (window->call), "notify",
-      G_CALLBACK (call_window_update),
-      window);
-
-  call_window_update (window);
-  gtk_widget_show (window->window);
-
-  return window->window;
+  gtk_statusbar_push (GTK_STATUSBAR (priv->statusbar), priv->context_id,
+    message);
 }
-