]> git.0d.be Git - empathy.git/blobdiff - src/empathy-call-observer.c
Updated Kannada translation
[empathy.git] / src / empathy-call-observer.c
index c6ba53c9525f7ebee918b96647b5b6c2851d4118..82887b00978b206ae926e6edf5784771094067e2 100644 (file)
  * Authors: Emilio Pozuelo Monfort <emilio.pozuelo@collabora.co.uk>
  */
 
-#include <config.h>
+#include "config.h"
+#include "empathy-call-observer.h"
 
 #include <glib/gi18n-lib.h>
+#include <tp-account-widgets/tpaw-images.h>
+#include <telepathy-glib/telepathy-glib-dbus.h>
 
-#include <telepathy-glib/telepathy-glib.h>
-
-#include <libnotify/notification.h>
-
-#include <libempathy/empathy-channel-factory.h>
-#include <libempathy/empathy-utils.h>
-
-#include <libempathy-gtk/empathy-images.h>
-#include <libempathy-gtk/empathy-notify-manager.h>
-
-#include <extensions/extensions.h>
-
-#include "empathy-call-observer.h"
+#include "empathy-notify-manager.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_VOIP
-#include <libempathy/empathy-debug.h>
+#include "empathy-debug.h"
 
 struct _EmpathyCallObserverPriv {
   EmpathyNotifyManager *notify_mgr;
@@ -103,29 +94,16 @@ auto_reject_ctx_free (AutoRejectCtx *ctx)
 }
 
 static void
-get_contact_cb (TpConnection *connection,
-    guint n_contacts,
-    TpContact * const *contacts,
-    guint n_failed,
-    const TpHandle *failed,
-    const GError *error,
-    gpointer user_data,
-    GObject *weak_object)
+display_reject_notification (EmpathyCallObserver *self,
+    TpChannel *channel)
 {
-  EmpathyCallObserver *self = (EmpathyCallObserver *) weak_object;
-  NotifyNotification *notification;
   TpContact *contact;
+  NotifyNotification *notification;
   gchar *summary, *body;
   EmpathyContact *emp_contact;
   GdkPixbuf *pixbuf;
 
-  if (n_contacts != 1)
-    {
-      DEBUG ("Failed to get TpContact; ignoring notification bubble");
-      return;
-    }
-
-  contact = contacts[0];
+  contact = tp_channel_get_target_contact (channel);
 
   summary = g_strdup_printf (_("Missed call from %s"),
       tp_contact_get_alias (contact));
@@ -133,11 +111,12 @@ get_contact_cb (TpConnection *connection,
       _("%s just tried to call you, but you were in another call."),
       tp_contact_get_alias (contact));
 
-  notification = notify_notification_new (summary, body, NULL);
+  notification = empathy_notify_manager_create_notification (summary, body,
+      NULL);
 
   emp_contact = empathy_contact_dup_from_tp_contact (contact);
   pixbuf = empathy_notify_manager_get_pixbuf_for_notification (
-      self->priv->notify_mgr, emp_contact, EMPATHY_IMAGE_AVATAR_DEFAULT);
+      self->priv->notify_mgr, emp_contact, TPAW_IMAGE_AVATAR_DEFAULT);
 
   if (pixbuf != NULL)
     {
@@ -153,21 +132,6 @@ get_contact_cb (TpConnection *connection,
   g_object_unref (emp_contact);
 }
 
-static void
-display_reject_notification (EmpathyCallObserver *self,
-    TpChannel *channel)
-{
-  TpHandle handle;
-  TpContactFeature features[] = { TP_CONTACT_FEATURE_ALIAS,
-      TP_CONTACT_FEATURE_AVATAR_DATA };
-
-  handle = tp_channel_get_handle (channel, NULL);
-
-  tp_connection_get_contacts_by_handle (tp_channel_borrow_connection (channel),
-      1, &handle, G_N_ELEMENTS (features), features, get_contact_cb,
-      g_object_ref (channel), g_object_unref, G_OBJECT (self));
-}
-
 static TpChannel *
 find_main_channel (GList *channels)
 {
@@ -183,7 +147,7 @@ find_main_channel (GList *channels)
 
       channel_type = tp_channel_get_channel_type_id (channel);
 
-      if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_STREAMED_MEDIA)
+      if (channel_type == TP_IFACE_QUARK_CHANNEL_TYPE_CALL)
         return channel;
     }
 
@@ -193,8 +157,21 @@ find_main_channel (GList *channels)
 static gboolean
 has_ongoing_calls (EmpathyCallObserver *self)
 {
-  if (self->priv->channels != NULL)
-    return TRUE;
+  GList *l;
+
+  for (l = self->priv->channels; l != NULL; l = l->next)
+    {
+      TpChannel *channel = TP_CHANNEL (l->data);
+      GQuark type = tp_channel_get_channel_type_id (channel);
+
+      /* Check that Call channels are not ended */
+      if (type == TP_IFACE_QUARK_CHANNEL_TYPE_CALL &&
+          tp_call_channel_get_state (TP_CALL_CHANNEL (channel),
+              NULL, NULL, NULL) == TP_CALL_STATE_ENDED)
+        continue;
+
+      return TRUE;
+    }
 
   return FALSE;
 }
@@ -239,10 +216,10 @@ observe_channels (TpSimpleObserver *observer,
   channel = find_main_channel (channels);
   if (channel == NULL)
     {
-      GError err = { TP_ERRORS, TP_ERROR_INVALID_ARGUMENT,
+      GError err = { TP_ERROR, TP_ERROR_INVALID_ARGUMENT,
           "Unknown channel type" };
 
-      DEBUG ("Didn't find any Call or StreamedMedia channel; ignoring");
+      DEBUG ("Didn't find any Call channel; ignoring");
 
       tp_observe_channels_context_fail (context, &err);
       return;
@@ -333,36 +310,24 @@ empathy_call_observer_init (EmpathyCallObserver *self)
 {
   EmpathyCallObserverPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
     EMPATHY_TYPE_CALL_OBSERVER, EmpathyCallObserverPriv);
-  TpDBusDaemon *dbus;
-  EmpathyChannelFactory *factory;
+  TpAccountManager *am;
   GError *error = NULL;
 
   self->priv = priv;
 
   self->priv->notify_mgr = empathy_notify_manager_dup_singleton ();
 
-  dbus = tp_dbus_daemon_dup (&error);
-  if (dbus == NULL)
-    {
-      DEBUG ("Failed to get TpDBusDaemon: %s", error->message);
-      g_error_free (error);
-      return;
-    }
+  am = tp_account_manager_dup ();
 
-  self->priv->observer = tp_simple_observer_new (dbus, TRUE,
+  self->priv->observer = tp_simple_observer_new_with_am (am, TRUE,
       "Empathy.CallObserver", FALSE,
       observe_channels, self, NULL);
 
-  factory = empathy_channel_factory_dup ();
-  tp_base_client_set_channel_factory (self->priv->observer,
-      TP_CLIENT_CHANNEL_FACTORY (factory));
-  g_object_unref (factory);
-
-  /* Observe StreamedMedia channels */
+  /* Observe Call channels */
   tp_base_client_take_observer_filter (self->priv->observer,
       tp_asv_new (
         TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
-          TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA,
+          TP_IFACE_CHANNEL_TYPE_CALL,
         TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT,
           TP_HANDLE_TYPE_CONTACT,
         NULL));
@@ -375,7 +340,7 @@ empathy_call_observer_init (EmpathyCallObserver *self)
       g_error_free (error);
     }
 
-  g_object_unref (dbus);
+  g_object_unref (am);
 }
 
 EmpathyCallObserver *