]> git.0d.be Git - empathy.git/blobdiff - src/empathy-call-handler.c
Updated Swedish translation
[empathy.git] / src / empathy-call-handler.c
index 119746657f2c113deb646313bdfacfcfa5c173e1..2935c2a7ca2b1bd1382a06e302d05805b382a527 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <telepathy-glib/account-channel-request.h>
-#include <telepathy-glib/util.h>
-#include <telepathy-glib/interfaces.h>
+#include "config.h"
+#include "empathy-call-handler.h"
 
 #include <telepathy-farstream/telepathy-farstream.h>
 
-#include <libempathy/empathy-utils.h>
-#include <libempathy/empathy-tp-contact-factory.h>
-
-#include <libempathy-gtk/empathy-call-utils.h>
-
-#include "empathy-call-handler.h"
+#include "empathy-call-utils.h"
+#include "empathy-utils.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
-#include <libempathy/empathy-debug.h>
+#include "empathy-debug.h"
 
 G_DEFINE_TYPE(EmpathyCallHandler, empathy_call_handler, G_TYPE_OBJECT)
 
@@ -61,7 +52,6 @@ enum {
   PROP_CALL_CHANNEL = 1,
   PROP_GST_BUS,
   PROP_CONTACT,
-  PROP_INITIAL_AUDIO,
   PROP_INITIAL_VIDEO,
   PROP_SEND_AUDIO_CODEC,
   PROP_SEND_VIDEO_CODEC,
@@ -80,7 +70,6 @@ struct _EmpathyCallHandlerPriv {
 
   EmpathyContact *contact;
   TfChannel *tfchannel;
-  gboolean initial_audio;
   gboolean initial_video;
 
   FsCodec *send_audio_codec;
@@ -91,6 +80,7 @@ struct _EmpathyCallHandlerPriv {
   FsCandidate *video_remote_candidate;
   FsCandidate *audio_local_candidate;
   FsCandidate *video_local_candidate;
+  gboolean accept_when_initialised;
 };
 
 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyCallHandler)
@@ -133,6 +123,21 @@ empathy_call_handler_init (EmpathyCallHandler *obj)
   obj->priv = priv;
 }
 
+static void
+on_call_accepted_cb (GObject *source_object,
+    GAsyncResult *res,
+    gpointer user_data)
+{
+  TpCallChannel *call = TP_CALL_CHANNEL (source_object);
+  GError *error = NULL;
+
+  if (!tp_call_channel_accept_finish (call, res, &error))
+    {
+      g_warning ("could not accept Call: %s", error->message);
+      g_error_free (error);
+    }
+}
+
 static void
 on_call_invalidated_cb (TpCallChannel *call,
     guint domain,
@@ -147,6 +152,7 @@ on_call_invalidated_cb (TpCallChannel *call,
       /* Invalidated unexpectedly? Fake call ending */
       g_signal_emit (self, signals[STATE_CHANGED], 0,
           TP_CALL_STATE_ENDED, NULL);
+      priv->accept_when_initialised = FALSE;
       tp_clear_object (&priv->call);
       tp_clear_object (&priv->tfchannel);
     }
@@ -162,16 +168,29 @@ on_call_state_changed_cb (TpCallChannel *call,
 {
   EmpathyCallHandlerPriv *priv = handler->priv;
 
-  g_signal_emit (handler, signals[STATE_CHANGED], 0, state,
-      reason->dbus_reason);
-
+  /* Clean up the TfChannel before bubbling the state-change signal
+   * further up. This ensures that the conference-removed signal is
+   * emitted before state-changed so that the client gets a chance
+   * to remove the conference from the pipeline before resetting the
+   * pipeline itself.
+   */
   if (state == TP_CALL_STATE_ENDED)
     {
       tp_channel_close_async (TP_CHANNEL (call), NULL, NULL);
-
+      priv->accept_when_initialised = FALSE;
       tp_clear_object (&priv->call);
       tp_clear_object (&priv->tfchannel);
     }
+
+  g_signal_emit (handler, signals[STATE_CHANGED], 0, state,
+      reason->dbus_reason);
+
+  if (state == TP_CALL_STATE_INITIALISED &&
+      priv->accept_when_initialised)
+    {
+      tp_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
+      priv->accept_when_initialised = FALSE;
+    }
 }
 
 static void
@@ -195,9 +214,6 @@ empathy_call_handler_set_property (GObject *object,
         tp_g_signal_connect_object (priv->call, "invalidated",
           G_CALLBACK (on_call_invalidated_cb), object, 0);
         break;
-      case PROP_INITIAL_AUDIO:
-        priv->initial_audio = g_value_get_boolean (value);
-        break;
       case PROP_INITIAL_VIDEO:
         priv->initial_video = g_value_get_boolean (value);
         break;
@@ -220,9 +236,6 @@ empathy_call_handler_get_property (GObject *object,
       case PROP_CALL_CHANNEL:
         g_value_set_object (value, priv->call);
         break;
-      case PROP_INITIAL_AUDIO:
-        g_value_set_boolean (value, priv->initial_audio);
-        break;
       case PROP_INITIAL_VIDEO:
         g_value_set_boolean (value, priv->initial_video);
         break;
@@ -281,13 +294,6 @@ empathy_call_handler_class_init (EmpathyCallHandlerClass *klass)
     G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
   g_object_class_install_property (object_class, PROP_CALL_CHANNEL, param_spec);
 
-  param_spec = g_param_spec_boolean ("initial-audio",
-    "initial-audio", "Whether the call should start with audio",
-    TRUE,
-    G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
-  g_object_class_install_property (object_class, PROP_INITIAL_AUDIO,
-      param_spec);
-
   param_spec = g_param_spec_boolean ("initial-video",
     "initial-video", "Whether the call should start with video",
     FALSE,
@@ -836,21 +842,6 @@ empathy_call_handler_start_tpfs (EmpathyCallHandler *self)
       on_tf_channel_ready, self);
 }
 
-static void
-on_call_accepted_cb (GObject *source_object,
-    GAsyncResult *res,
-    gpointer user_data)
-{
-  TpCallChannel *call = TP_CALL_CHANNEL (source_object);
-  GError *error = NULL;
-
-  if (!tp_call_channel_accept_finish (call, res, &error))
-    {
-      g_warning ("could not accept Call: %s", error->message);
-      g_error_free (error);
-    }
-}
-
 static void
 empathy_call_handler_request_cb (GObject *source,
     GAsyncResult *result,
@@ -896,12 +887,28 @@ empathy_call_handler_start_call (EmpathyCallHandler *handler,
   EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
   TpAccountChannelRequest *req;
   TpAccount *account;
-  GHashTable *request;
 
   if (priv->call != NULL)
     {
       empathy_call_handler_start_tpfs (handler);
-      tp_call_channel_accept_async (priv->call, on_call_accepted_cb, NULL);
+
+      if (tp_channel_get_requested (TP_CHANNEL (priv->call)))
+        {
+          /* accept outgoing channels immediately */
+          tp_call_channel_accept_async (priv->call,
+              on_call_accepted_cb, NULL);
+        }
+      else
+        {
+          /* accepting incoming channels when they are INITIALISED */
+          if (tp_call_channel_get_state (priv->call, NULL, NULL, NULL) ==
+              TP_CALL_STATE_INITIALISED)
+            tp_call_channel_accept_async (priv->call,
+                on_call_accepted_cb, NULL);
+          else
+            priv->accept_when_initialised = TRUE;
+        }
+
       return;
     }
 
@@ -909,17 +916,14 @@ empathy_call_handler_start_call (EmpathyCallHandler *handler,
   g_assert (priv->contact != NULL);
 
   account = empathy_contact_get_account (priv->contact);
-  request = empathy_call_create_call_request (
-      empathy_contact_get_id (priv->contact),
-      priv->initial_audio, priv->initial_video);
 
-  req = tp_account_channel_request_new (account, request, timestamp);
+  req = empathy_call_create_call_request (account,
+      empathy_contact_get_id (priv->contact), priv->initial_video, timestamp);
 
   tp_account_channel_request_create_and_handle_channel_async (req, NULL,
       empathy_call_handler_request_cb, handler);
 
   g_object_unref (req);
-  g_hash_table_unref (request);
 }
 
 /**
@@ -938,10 +942,6 @@ empathy_call_handler_stop_call (EmpathyCallHandler *handler)
       tp_call_channel_hangup_async (priv->call,
           TP_CALL_STATE_CHANGE_REASON_USER_REQUESTED,
           "", "", NULL, NULL);
-      tp_channel_close_async (TP_CHANNEL (priv->call),
-        NULL, NULL);
-      tp_clear_object (&priv->call);
-      tp_clear_object (&priv->tfchannel);
     }
 }
 
@@ -1029,3 +1029,9 @@ empathy_call_handler_get_video_local_candidate (
 
   return priv->video_local_candidate;
 }
+
+EmpathyContact *
+empathy_call_handler_get_contact (EmpathyCallHandler *self)
+{
+  return self->priv->contact;
+}