]> git.0d.be Git - empathy.git/blobdiff - libempathy/empathy-client-factory.c
EmpathySmileyManager: use the proper Unicode characters
[empathy.git] / libempathy / empathy-client-factory.c
index 294eaf5ff43cc41b7144c014e927c01dc1213fbd..b57ea06524b00b1e2061a5dd68803464fcd1dfbd 100644 (file)
  * Authors: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
  */
 
-#include <config.h>
-
+#include "config.h"
 #include "empathy-client-factory.h"
 
+#include <tp-account-widgets/tpaw-utils.h>
+#include <telepathy-glib/telepathy-glib-dbus.h>
+
 #include "empathy-tp-chat.h"
 #include "empathy-utils.h"
 
-#include <telepathy-yell/telepathy-yell.h>
-
 G_DEFINE_TYPE (EmpathyClientFactory, empathy_client_factory,
     TP_TYPE_AUTOMATIC_CLIENT_FACTORY)
 
 #define chainup ((TpSimpleClientFactoryClass *) \
     empathy_client_factory_parent_class)
 
-/* FIXME: move to yell */
-static TpyCallChannel *
-call_channel_new_with_factory (TpSimpleClientFactory *factory,
-    TpConnection *conn,
-    const gchar *object_path,
-    const GHashTable *immutable_properties,
-    GError **error)
-{
-  TpProxy *conn_proxy = (TpProxy *) conn;
-
-  g_return_val_if_fail (TP_IS_CONNECTION (conn), NULL);
-  g_return_val_if_fail (object_path != NULL, NULL);
-  g_return_val_if_fail (immutable_properties != NULL, NULL);
-
-  if (!tp_dbus_check_valid_object_path (object_path, error))
-    return NULL;
-
-  return g_object_new (TPY_TYPE_CALL_CHANNEL,
-      "factory", factory,
-      "connection", conn,
-      "dbus-daemon", conn_proxy->dbus_daemon,
-      "bus-name", conn_proxy->bus_name,
-      "object-path", object_path,
-      "handle-type", (guint) TP_UNKNOWN_HANDLE_TYPE,
-      "channel-properties", immutable_properties,
-      NULL);
-}
-
 static TpChannel *
 empathy_client_factory_create_channel (TpSimpleClientFactory *factory,
     TpConnection *conn,
@@ -75,19 +47,10 @@ empathy_client_factory_create_channel (TpSimpleClientFactory *factory,
 
   if (!tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_TEXT))
     {
-      TpAccount *account;
-
-      account = tp_connection_get_account (conn);
-
       return TP_CHANNEL (empathy_tp_chat_new (
-            TP_SIMPLE_CLIENT_FACTORY (factory), account, conn, path,
+            TP_SIMPLE_CLIENT_FACTORY (factory), conn, path,
             properties));
     }
-  else if (!tp_strdiff (chan_type, TPY_IFACE_CHANNEL_TYPE_CALL))
-    {
-      return TP_CHANNEL (call_channel_new_with_factory (
-            TP_SIMPLE_CLIENT_FACTORY (factory), conn, path, properties, error));
-    }
 
   return chainup->create_channel (factory, conn, path, properties, error);
 }
@@ -101,9 +64,12 @@ empathy_client_factory_dup_channel_features (TpSimpleClientFactory *factory,
 
   features = chainup->dup_channel_features (factory, channel);
 
+  feature = TP_CHANNEL_FEATURE_CONTACTS;
+  g_array_append_val (features, feature);
+
   if (EMPATHY_IS_TP_CHAT (channel))
     {
-      feature = TP_CHANNEL_FEATURE_CHAT_STATES;
+      feature = TP_TEXT_CHANNEL_FEATURE_CHAT_STATES;
       g_array_append_val (features, feature);
 
       feature = EMPATHY_TP_CHAT_FEATURE_READY;
@@ -128,6 +94,9 @@ empathy_client_factory_dup_account_features (TpSimpleClientFactory *factory,
   feature = TP_ACCOUNT_FEATURE_ADDRESSING;
   g_array_append_val (features, feature);
 
+  feature = TP_ACCOUNT_FEATURE_STORAGE;
+  g_array_append_val (features, feature);
+
   return features;
 }
 
@@ -179,6 +148,8 @@ empathy_client_factory_dup_contact_features (TpSimpleClientFactory *factory,
        * is already in the contact list. This feature is pretty cheap to
        * prepare as it doesn't prepare the full roster. */
       TP_CONTACT_FEATURE_SUBSCRIPTION_STATES,
+      TP_CONTACT_FEATURE_CONTACT_GROUPS,
+      TP_CONTACT_FEATURE_CLIENT_TYPES,
   };
 
   features = chainup->dup_contact_features (factory, connection);
@@ -245,3 +216,67 @@ empathy_client_factory_dup (void)
 
   return singleton;
 }
+
+static void
+dup_contact_cb (GObject *source,
+    GAsyncResult *result,
+    gpointer user_data)
+{
+  GSimpleAsyncResult *my_result = user_data;
+  GError *error = NULL;
+  TpContact *contact;
+
+  contact = tp_connection_dup_contact_by_id_finish (TP_CONNECTION (source),
+      result, &error);
+
+  if (contact == NULL)
+    {
+      g_simple_async_result_take_error (my_result, error);
+    }
+  else
+    {
+      g_simple_async_result_set_op_res_gpointer (my_result,
+          empathy_contact_dup_from_tp_contact (contact), g_object_unref);
+
+      g_object_unref (contact);
+    }
+
+  g_simple_async_result_complete (my_result);
+  g_object_unref (my_result);
+}
+
+void
+empathy_client_factory_dup_contact_by_id_async (
+    EmpathyClientFactory *self,
+    TpConnection *connection,
+    const gchar *id,
+    GAsyncReadyCallback callback,
+    gpointer user_data)
+{
+  GSimpleAsyncResult *result;
+  GArray *features;
+
+  g_return_if_fail (EMPATHY_IS_CLIENT_FACTORY (self));
+  g_return_if_fail (id != NULL);
+
+  result = g_simple_async_result_new ((GObject *) self, callback, user_data,
+      empathy_client_factory_dup_contact_by_id_async);
+
+  features = empathy_client_factory_dup_contact_features (
+      TP_SIMPLE_CLIENT_FACTORY (self), connection);
+
+  tp_connection_dup_contact_by_id_async (connection, id, features->len,
+      (TpContactFeature * ) features->data, dup_contact_cb, result);
+
+  g_array_unref (features);
+}
+
+EmpathyContact *
+empathy_client_factory_dup_contact_by_id_finish (
+    EmpathyClientFactory *self,
+    GAsyncResult *result,
+    GError **error)
+{
+  tpaw_implement_finish_return_copy_pointer (self,
+      empathy_client_factory_dup_contact_by_id_async, g_object_ref);
+}