]> git.0d.be Git - empathy.git/blobdiff - src/empathy-call-window.c
Merge branch 'gnome-3-6'
[empathy.git] / src / empathy-call-window.c
index 6286cab573e8daff61f70897ca3c7cfcb59b8ea8..996c0f717d0e2db14fb0a36d292f6586322349a1 100644 (file)
@@ -34,9 +34,8 @@
 #include <clutter-gtk/clutter-gtk.h>
 #include <clutter-gst/clutter-gst.h>
 
-#include <telepathy-glib/util.h>
 #include <telepathy-farstream/telepathy-farstream.h>
-#include <telepathy-glib/util.h>
+#include <telepathy-glib/telepathy-glib.h>
 
 #include <farstream/fs-element-added-notifier.h>
 #include <farstream/fs-utils.h>
@@ -105,6 +104,13 @@ enum {
   PROP_CALL_HANDLER = 1,
 };
 
+enum {
+  SIG_INHIBIT,
+  LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL];
+
 typedef enum {
   RINGING,       /* Incoming call */
   CONNECTING,    /* Outgoing call */
@@ -136,7 +142,7 @@ struct _EmpathyCallWindowPriv
 
   EmpathyCameraMonitor *camera_monitor;
 
-  guint call_state;
+  CallState call_state;
   gboolean outgoing;
 
   GtkUIManager *ui_manager;
@@ -164,6 +170,7 @@ struct _EmpathyCallWindowPriv
   GtkWidget *audio_call_button;
   GtkWidget *video_call_button;
   GtkWidget *mic_button;
+  GtkWidget *microphone_icon;
   GtkWidget *volume_button;
   GtkWidget *camera_button;
   GtkWidget *dialpad_button;
@@ -473,6 +480,17 @@ audio_input_mute_notify_cb (GObject *obj, GParamSpec *spec,
   if (muted && self->priv->transitions)
     clutter_state_set_state (self->priv->transitions, "fade-in");
 
+  if (muted)
+    {
+      gtk_image_set_from_icon_name (GTK_IMAGE (self->priv->microphone_icon),
+          EMPATHY_IMAGE_MIC_MUTED, GTK_ICON_SIZE_MENU);
+    }
+  else
+    {
+      gtk_image_set_from_icon_name (GTK_IMAGE (self->priv->microphone_icon),
+          EMPATHY_IMAGE_MIC, GTK_ICON_SIZE_MENU);
+    }
+
   empathy_call_window_update_timer (self);
 }
 
@@ -487,12 +505,6 @@ create_audio_input (EmpathyCallWindow *self)
 
   g_signal_connect (priv->audio_input, "notify::mute",
     G_CALLBACK (audio_input_mute_notify_cb), self);
-
-  g_object_bind_property (priv->mic_button, "active",
-    priv->audio_input, "mute",
-    G_BINDING_BIDIRECTIONAL |
-      G_BINDING_INVERT_BOOLEAN | G_BINDING_SYNC_CREATE);
-
 }
 
 static void
@@ -1307,10 +1319,10 @@ enable_camera (EmpathyCallWindow *self)
 }
 
 static void
-empathy_call_window_camera_toggled_cb (GtkToggleToolButton *toggle,
+empathy_call_window_camera_toggled_cb (GtkToggleButton *toggle,
   EmpathyCallWindow *self)
 {
-  if (gtk_toggle_tool_button_get_active (toggle))
+  if (gtk_toggle_button_get_active (toggle))
     enable_camera (self);
   else
     disable_camera (self);
@@ -1359,7 +1371,65 @@ empathy_call_window_contents_cb (GtkAction *action,
 }
 
 static void
-empathy_call_window_debug_cb (GtkAction *action,
+show_png (GPid pid, gint status, gpointer user_data)
+{
+  gtk_show_uri (NULL, (gchar *) user_data, GDK_CURRENT_TIME, NULL);
+  g_spawn_close_pid (pid);
+  g_free (user_data);
+}
+
+static void
+empathy_call_window_debug_gst_cb (GtkAction *action,
+    EmpathyCallWindow *self)
+{
+  EmpathyCallWindowPriv *priv = GET_PRIV (self);
+  GDateTime *date_time;
+  GPid dot_pid;
+  const gchar *dot_dir;
+  const gchar *prgname;
+  gchar *dot_cmd;
+  gchar *filename;
+  gchar **argv;
+  gint argc;
+
+  if (priv->pipeline == NULL)
+    DEBUG ("No pipeline");
+
+  date_time = g_date_time_new_now_utc ();
+  prgname = g_get_prgname ();
+  filename = g_strdup_printf ("%s-%" G_GINT64_FORMAT, prgname,
+      g_date_time_to_unix (date_time));
+
+  GST_DEBUG_BIN_TO_DOT_FILE (GST_BIN (priv->pipeline),
+      GST_DEBUG_GRAPH_SHOW_ALL, filename);
+
+  dot_dir = g_getenv ("GST_DEBUG_DUMP_DOT_DIR");
+  dot_cmd = g_strdup_printf ("dot -Tpng -o %s.png %s.dot",
+      filename,
+      filename);
+  g_shell_parse_argv (dot_cmd, &argc, &argv, NULL);
+
+  if (g_spawn_async (dot_dir,
+          argv,
+          NULL,
+          G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
+          NULL,
+          NULL,
+          &dot_pid,
+          NULL))
+    {
+      gchar *uri = g_strdup_printf ("file://%s/%s.png", dot_dir, filename);
+      g_child_watch_add (dot_pid, show_png, uri);
+    }
+
+  g_strfreev (argv);
+  g_free (dot_cmd);
+  g_free (filename);
+  g_date_time_unref (date_time);
+}
+
+static void
+empathy_call_window_debug_tp_cb (GtkAction *action,
     EmpathyCallWindow *self)
 {
   empathy_launch_program (BIN_DIR, "empathy-debugger", "-s Empathy.Call");
@@ -1538,6 +1608,16 @@ empathy_call_window_start_ringing (EmpathyCallWindow *self,
   tp_add_dispatch_operation_context_accept (context);
 }
 
+static void
+mic_button_clicked (GtkWidget *button,
+    EmpathyCallWindow *self)
+{
+  /* Toggle the muted state. We rely on audio_input_mute_notify_cb to update
+   * the icon. */
+  empathy_audio_src_set_mute (EMPATHY_GST_AUDIO_SRC (self->priv->audio_input),
+      !self->priv->muted);
+}
+
 static void
 empathy_call_window_init (EmpathyCallWindow *self)
 {
@@ -1569,6 +1649,7 @@ empathy_call_window_init (EmpathyCallWindow *self)
     "audiocall", &priv->audio_call_button,
     "videocall", &priv->video_call_button,
     "microphone", &priv->mic_button,
+    "microphone_icon", &priv->microphone_icon,
     "volume", &priv->volume_button,
     "camera", &priv->camera_button,
     "hangup", &priv->hangup_button,
@@ -1603,7 +1684,8 @@ empathy_call_window_init (EmpathyCallWindow *self)
     "menufullscreen", "activate", empathy_call_window_fullscreen_cb,
     "menusettings", "activate", empathy_call_window_settings_cb,
     "menucontents", "activate", empathy_call_window_contents_cb,
-    "menudebug", "activate", empathy_call_window_debug_cb,
+    "menudebuggst", "activate", empathy_call_window_debug_gst_cb,
+    "menudebugtp", "activate", empathy_call_window_debug_tp_cb,
     "menuabout", "activate", empathy_call_window_about_cb,
     "menupreviewdisable", "activate", empathy_call_window_disable_camera_cb,
     "menupreviewminimise", "activate", empathy_call_window_minimise_camera_cb,
@@ -1625,6 +1707,9 @@ empathy_call_window_init (EmpathyCallWindow *self)
   g_signal_connect (priv->camera_monitor, "removed",
       G_CALLBACK (empathy_call_window_camera_removed_cb), self);
 
+  g_signal_connect (priv->mic_button, "clicked",
+      G_CALLBACK (mic_button_clicked), self);
+
   g_mutex_init (&priv->lock);
 
   gtk_container_add (GTK_CONTAINER (self), top_vbox);
@@ -1787,6 +1872,8 @@ empathy_call_window_init (EmpathyCallWindow *self)
 
   empathy_call_window_show_hangup_button (self, TRUE);
 
+  gtk_window_set_default_size (GTK_WINDOW (self), 580, 480);
+
   empathy_geometry_bind (GTK_WINDOW (self), "call-window");
   /* These signals are used to track the window position and save it
    * when the window is destroyed. We need to do this as we don't want
@@ -2277,6 +2364,13 @@ empathy_call_window_class_init (
     G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
   g_object_class_install_property (object_class,
     PROP_CALL_HANDLER, param_spec);
+
+  signals[SIG_INHIBIT] = g_signal_new ("inhibit",
+      G_OBJECT_CLASS_TYPE (empathy_call_window_class),
+      G_SIGNAL_RUN_LAST,
+      0, NULL, NULL, NULL,
+      G_TYPE_NONE,
+      1, G_TYPE_BOOLEAN);
 }
 
 void
@@ -2427,6 +2521,9 @@ empathy_call_window_conference_removed_cb (EmpathyCallHandler *handler,
   EmpathyCallWindow *self = EMPATHY_CALL_WINDOW (user_data);
   EmpathyCallWindowPriv *priv = GET_PRIV (self);
 
+  g_list_free_full (priv->notifiers, g_object_unref);
+  priv->notifiers = NULL;
+
   gst_bin_remove (GST_BIN (priv->pipeline), conference);
   gst_element_set_state (conference, GST_STATE_NULL);
 }
@@ -2517,9 +2614,18 @@ empathy_call_window_disconnected (EmpathyCallWindow *self,
   /* Leave full screen mode if needed */
   gtk_window_unfullscreen (GTK_WINDOW (self));
 
+  g_signal_emit (self, signals[SIG_INHIBIT], 0, FALSE);
+
   gtk_action_set_sensitive (priv->menu_fullscreen, FALSE);
   gtk_widget_set_sensitive (priv->dtmf_panel, FALSE);
 
+  /* Create the video input and then turn on the camera
+   * menu, so that the active camera gets marked as such.
+   */
+  if (priv->video_input == NULL)
+    create_video_input (self);
+  empathy_camera_menu_set_sensitive (priv->camera_menu, TRUE);
+
   could_reset_pipeline = empathy_call_window_reset_pipeline (self);
 
   if (priv->call_state == CONNECTING)
@@ -2557,8 +2663,8 @@ empathy_call_window_disconnected (EmpathyCallWindow *self,
       gtk_widget_set_sensitive (priv->mic_button, FALSE);
 
       /* Be sure that the mic button is enabled */
-      gtk_toggle_button_set_active (
-          GTK_TOGGLE_BUTTON (priv->mic_button), TRUE);
+      empathy_audio_src_set_mute (
+          EMPATHY_GST_AUDIO_SRC (self->priv->audio_input), FALSE);
 
       if (priv->camera_state == CAMERA_STATE_ON)
         {
@@ -2715,12 +2821,15 @@ empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
   if (priv->funnel == NULL)
     {
       output = priv->video_output_sink;
-
+#ifdef HAVE_GST1
+      priv->funnel = gst_element_factory_make ("funnel", NULL);
+#else
       priv->funnel = gst_element_factory_make ("fsfunnel", NULL);
+#endif
 
       if (!priv->funnel)
         {
-          g_warning ("Could not create fsfunnel");
+          g_warning ("Could not create video funnel");
           return NULL;
         }
 
@@ -2756,8 +2865,11 @@ empathy_call_window_get_video_sink_pad (EmpathyCallWindow *self)
           goto error_output_added;
         }
     }
-
+#ifdef HAVE_GST1
+  pad = gst_element_get_request_pad (priv->funnel, "sink_%u");
+#else
   pad = gst_element_get_request_pad (priv->funnel, "sink%d");
+#endif
 
   if (!pad)
     g_warning ("Could not get request pad from funnel");
@@ -2847,8 +2959,9 @@ empathy_call_window_update_timer (gpointer user_data)
 
   if (priv->call_state == HELD)
     status = _("On hold");
-  else if (!gtk_toggle_button_get_active (
-      GTK_TOGGLE_BUTTON (priv->mic_button)))
+  else if (priv->call_state == DISCONNECTED)
+    status = _("Disconnected");
+  else if (priv->muted)
     status = _("Mute");
   else
     status = _("Duration");
@@ -3018,7 +3131,7 @@ media_stream_error_to_txt (EmpathyCallWindow *self,
 
       case TP_MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR:
         tp_connection_parse_object_path (
-            tp_channel_borrow_connection (TP_CHANNEL (call)),
+            tp_channel_get_connection (TP_CHANNEL (call)),
             NULL, &cm);
 
         url = g_strdup_printf ("http://bugs.freedesktop.org/enter_bug.cgi?"
@@ -3105,7 +3218,7 @@ show_balance_error (EmpathyCallWindow *self)
       "call-channel", &call,
       NULL);
 
-  conn = tp_channel_borrow_connection (call);
+  conn = tp_channel_get_connection (call);
   g_object_unref (call);
 
   uri = tp_connection_get_balance_uri (conn);
@@ -3236,6 +3349,27 @@ empathy_call_window_check_video_cb (gpointer data)
 }
 
 /* Called from the streaming thread */
+#ifdef HAVE_GST1
+static GstPadProbeReturn
+empathy_call_window_video_probe_cb (GstPad *pad,
+    GstPadProbeInfo *info,
+    gpointer user_data)
+{
+    EmpathyCallWindow *self = user_data;
+
+  if (G_UNLIKELY (!self->priv->got_video))
+    {
+      /* show the remote video */
+      g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
+          empathy_call_window_show_video_output_cb,
+          g_object_ref (self), g_object_unref);
+
+      self->priv->got_video = TRUE;
+    }
+
+  return GST_PAD_PROBE_OK;
+}
+#else
 static gboolean
 empathy_call_window_video_probe_cb (GstPad *pad,
     GstMiniObject *mini_obj,
@@ -3257,6 +3391,7 @@ empathy_call_window_video_probe_cb (GstPad *pad,
 
   return TRUE;
 }
+#endif
 
 /* Called from the streaming thread */
 static gboolean
@@ -3283,8 +3418,14 @@ empathy_call_window_src_added_cb (EmpathyCallHandler *handler,
         g_idle_add (empathy_call_window_show_video_output_cb, self);
         pad = empathy_call_window_get_video_sink_pad (self);
 
+#ifdef HAVE_GST1
+        gst_pad_add_probe (src,
+            GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_BUFFER_LIST,
+            empathy_call_window_video_probe_cb, self, NULL);
+#else
         gst_pad_add_data_probe (src,
             G_CALLBACK (empathy_call_window_video_probe_cb), self);
+#endif
         if (priv->got_video_src > 0)
           g_source_remove (priv->got_video_src);
         priv->got_video_src = g_timeout_add_seconds (1,
@@ -3463,7 +3604,11 @@ empathy_call_window_content_added_cb (EmpathyCallHandler *handler,
       case FS_MEDIA_TYPE_VIDEO:
         if (priv->video_tee != NULL)
           {
+#ifdef HAVE_GST1
+            pad = gst_element_get_request_pad (priv->video_tee, "src_%u");
+#else
             pad = gst_element_get_request_pad (priv->video_tee, "src%d");
+#endif
             if (GST_PAD_LINK_FAILED (gst_pad_link (pad, sink)))
               {
                 g_warning ("Could not link video source input pipeline");
@@ -3508,6 +3653,7 @@ empathy_call_window_remove_video_input (EmpathyCallWindow *self)
   priv->video_preview = NULL;
 
   gtk_widget_set_sensitive (priv->camera_button, FALSE);
+  empathy_camera_menu_set_sensitive (priv->camera_menu, FALSE);
 }
 
 static void
@@ -3515,6 +3661,8 @@ start_call (EmpathyCallWindow *self)
 {
   EmpathyCallWindowPriv *priv = GET_PRIV (self);
 
+  g_signal_emit (self, signals[SIG_INHIBIT], 0, TRUE);
+
   priv->call_started = TRUE;
   empathy_call_handler_start_call (priv->handler,
       gtk_get_current_event_time ());
@@ -4028,6 +4176,7 @@ empathy_call_window_key_press_cb (GtkWidget *video_output,
   GdkEventKey *event, EmpathyCallWindow *window)
 {
   EmpathyCallWindowPriv *priv = GET_PRIV (window);
+  gchar key;
 
   if (priv->is_fullscreen && event->keyval == GDK_KEY_Escape)
     {
@@ -4037,7 +4186,34 @@ empathy_call_window_key_press_cb (GtkWidget *video_output,
       return TRUE;
     }
 
-  return FALSE;
+  key = gdk_keyval_to_unicode (event->keyval);
+  switch (key)
+    {
+      case '0':
+      case '1':
+      case '2':
+      case '3':
+      case '4':
+      case '5':
+      case '6':
+      case '7':
+      case '8':
+      case '9':
+      case '*':
+      case '#':
+        break;
+      default:
+        return TRUE;
+        break;
+    }
+
+  gtk_toggle_tool_button_set_active (
+      GTK_TOGGLE_TOOL_BUTTON (priv->dialpad_button), TRUE);
+
+  empathy_dialpad_widget_press_key (
+      EMPATHY_DIALPAD_WIDGET (priv->dtmf_panel), key);
+
+  return TRUE;
 }
 
 static gboolean