]> git.0d.be Git - empathy.git/commitdiff
Port to new tp-glib client factory
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Thu, 18 Aug 2011 09:31:10 +0000 (11:31 +0200)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Thu, 18 Aug 2011 10:15:06 +0000 (12:15 +0200)
- EmpathyChannelFactory has been changed to EmpathyClientFactory and inherit
from TpAutomaticClientFactory.
- We now always use the _with_am variant of TpSimple* constructors
- We define our own factory as default.
- Replace empathy_get_account_for_connection() by tp_connection_get_account()
- The factory is passed to EmpathyTpChat and TpyCallChannel
- Use tp_simple_client_factory_ensure_account() instead of
tp_account_manager_ensure_account().
- Rely on the factory to prepare connection features.

This should ensure that all the TpProxy and TpContact objects created in
Empathy are shared and use EmpathyClientFactory.

https://bugzilla.gnome.org/show_bug.cgi?id=655799

23 files changed:
libempathy-gtk/empathy-contact-list-view.c
libempathy-gtk/empathy-log-window.c
libempathy/Makefile.am
libempathy/empathy-channel-factory.c [deleted file]
libempathy/empathy-channel-factory.h [deleted file]
libempathy/empathy-chatroom-manager.c
libempathy/empathy-client-factory.c [new file with mode: 0644]
libempathy/empathy-client-factory.h [new file with mode: 0644]
libempathy/empathy-contact.c
libempathy/empathy-ft-factory.c
libempathy/empathy-message.c
libempathy/empathy-tp-chat.c
libempathy/empathy-tp-chat.h
libempathy/empathy-utils.c
libempathy/empathy-utils.h
src/empathy-call-factory.c
src/empathy-call-handler.c
src/empathy-call-observer.c
src/empathy-chat-manager.c
src/empathy-chat-window.c
src/empathy-event-manager.c
src/empathy-streamed-media-factory.c
tests/empathy-chatroom-manager-test.c

index 4b2febd307a775cea701d05586402bf940f4b982..277842ff576f58f832927683276059007edbe543 100644 (file)
@@ -34,6 +34,7 @@
 #include <telepathy-glib/account-manager.h>
 #include <telepathy-glib/util.h>
 
+#include <libempathy/empathy-client-factory.h>
 #include <libempathy/empathy-tp-contact-factory.h>
 #include <libempathy/empathy-contact-list.h>
 #include <libempathy/empathy-contact-groups.h>
@@ -382,7 +383,7 @@ contact_list_view_contact_drag_received (GtkWidget         *view,
                                         GtkSelectionData  *selection)
 {
        EmpathyContactListViewPriv *priv;
-       TpAccountManager           *account_manager;
+       EmpathyClientFactory       *factory;
        TpConnection               *connection = NULL;
        TpAccount                  *account = NULL;
        DndGetContactData          *data;
@@ -423,12 +424,14 @@ contact_list_view_contact_drag_received (GtkWidget         *view,
                return FALSE;
        }
 
-       account_manager = tp_account_manager_dup ();
+       factory = empathy_client_factory_dup ();
        strv = g_strsplit (sel_data, ":", 2);
        if (g_strv_length (strv) == 2) {
                account_id = strv[0];
                contact_id = strv[1];
-               account = tp_account_manager_ensure_account (account_manager, account_id);
+               account = tp_simple_client_factory_ensure_account (
+                               TP_SIMPLE_CLIENT_FACTORY (factory),
+                               account_id, NULL, NULL);
        }
        if (account) {
                connection = tp_account_get_connection (account);
@@ -438,7 +441,7 @@ contact_list_view_contact_drag_received (GtkWidget         *view,
                DEBUG ("Failed to get connection for account '%s'", account_id);
                g_free (new_group);
                g_free (old_group);
-               g_object_unref (account_manager);
+               g_object_unref (factory);
                return FALSE;
        }
 
@@ -454,7 +457,7 @@ contact_list_view_contact_drag_received (GtkWidget         *view,
                                                data, (GDestroyNotify) contact_list_view_dnd_get_contact_free,
                                                G_OBJECT (view));
        g_strfreev (strv);
-       g_object_unref (account_manager);
+       g_object_unref (factory);
 
        return TRUE;
 }
index 5620f4b7c78975fd2b2dd5e67d29315bc26bb8a2..d0f57a6de5aefe0408af3405d0980431d87e56df 100644 (file)
@@ -1041,21 +1041,14 @@ observe_channels (TpSimpleObserver *observer,
 static void
 log_window_create_observer (EmpathyLogWindow *self)
 {
-  TpDBusDaemon *dbus;
-  GError *error = NULL;
+  TpAccountManager *am;
 
-  dbus = tp_dbus_daemon_dup (&error);
+  am = tp_account_manager_dup ();
 
-  if (dbus == NULL)
-    {
-      DEBUG ("Could not connect to the bus: %s", error->message);
-      g_error_free (error);
-      return;
-    }
-
-  self->priv->observer = tp_simple_observer_new (dbus, TRUE, "LogWindow",
+  self->priv->observer = tp_simple_observer_new_with_am (am, TRUE, "LogWindow",
       TRUE, observe_channels,
       g_object_ref (self), g_object_unref);
+
   self->priv->channels = g_hash_table_new_full (g_direct_hash, g_direct_equal,
       g_object_unref, g_object_unref);
 
@@ -1077,7 +1070,7 @@ log_window_create_observer (EmpathyLogWindow *self)
 
   tp_base_client_register (self->priv->observer, NULL);
 
-  g_object_unref (dbus);
+  g_object_unref (am);
 }
 
 static TplEntity *
index f701f7480f01e6b9e47ed13e8224050b841e0bdb..34a7061133ef73b28447adddcb5b5429b8267b42 100644 (file)
@@ -33,9 +33,9 @@ libempathy_headers =                          \
        empathy-account-settings.h              \
        empathy-auth-factory.h                  \
        empathy-camera-monitor.h                \
-       empathy-channel-factory.h               \
        empathy-chatroom-manager.h              \
        empathy-chatroom.h                      \
+       empathy-client-factory.h \
        empathy-connection-managers.h           \
        empathy-connectivity.h                  \
        empathy-contact-groups.h                \
@@ -76,9 +76,9 @@ libempathy_handwritten_source =                               \
        empathy-account-settings.c                      \
        empathy-auth-factory.c                          \
        empathy-camera-monitor.c                        \
-       empathy-channel-factory.c                       \
        empathy-chatroom-manager.c                      \
        empathy-chatroom.c                              \
+       empathy-client-factory.c \
        empathy-connection-managers.c                   \
        empathy-connectivity.c                          \
        empathy-contact-groups.c                        \
diff --git a/libempathy/empathy-channel-factory.c b/libempathy/empathy-channel-factory.c
deleted file mode 100644 (file)
index d8b1cd9..0000000
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * Copyright (C) 2010 Collabora Ltd.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
- * Boston, MA  02110-1301  USA
- *
- * Authors: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
- */
-
-#include <config.h>
-
-#include "empathy-channel-factory.h"
-
-#include "empathy-tp-chat.h"
-#include "empathy-utils.h"
-
-#include <telepathy-glib/telepathy-glib.h>
-
-#include <telepathy-yell/telepathy-yell.h>
-
-static void factory_iface_init (gpointer, gpointer);
-
-G_DEFINE_TYPE_WITH_CODE (EmpathyChannelFactory, empathy_channel_factory,
-    G_TYPE_OBJECT,
-    G_IMPLEMENT_INTERFACE (TP_TYPE_CLIENT_CHANNEL_FACTORY, factory_iface_init))
-
-struct _EmpathyChannelFactoryPrivate
-{
-  TpClientChannelFactory *automatic_factory;
-};
-
-static void
-empathy_channel_factory_dispose (GObject *object)
-{
-  EmpathyChannelFactory *self = EMPATHY_CHANNEL_FACTORY (object);
-  void (*dispose) (GObject *) =
-    G_OBJECT_CLASS (empathy_channel_factory_parent_class)->dispose;
-
-  tp_clear_object (&self->priv->automatic_factory);
-
-  if (dispose != NULL)
-    dispose (object);
-}
-
-static void
-empathy_channel_factory_class_init (EmpathyChannelFactoryClass *cls)
-{
-  GObjectClass *object_class = G_OBJECT_CLASS (cls);
-
-  g_type_class_add_private (cls, sizeof (EmpathyChannelFactoryPrivate));
-
-  object_class->dispose = empathy_channel_factory_dispose;
-}
-
-static void
-empathy_channel_factory_init (EmpathyChannelFactory *self)
-{
-  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
-      EMPATHY_TYPE_CHANNEL_FACTORY, EmpathyChannelFactoryPrivate);
-
-  self->priv->automatic_factory = TP_CLIENT_CHANNEL_FACTORY (
-      tp_automatic_proxy_factory_dup ());
-}
-
-EmpathyChannelFactory *
-empathy_channel_factory_new (void)
-{
-    return g_object_new (EMPATHY_TYPE_CHANNEL_FACTORY,
-        NULL);
-}
-
-EmpathyChannelFactory *
-empathy_channel_factory_dup (void)
-{
-  static EmpathyChannelFactory *singleton = NULL;
-
-  if (singleton != NULL)
-    return g_object_ref (singleton);
-
-  singleton = empathy_channel_factory_new ();
-
-  g_object_add_weak_pointer (G_OBJECT (singleton), (gpointer) &singleton);
-
-  return singleton;
-}
-
-static TpChannel *
-empathy_channel_factory_create_channel (
-    TpClientChannelFactory *factory,
-    TpConnection *conn,
-    const gchar *path,
-    GHashTable *properties,
-    GError **error)
-{
-  EmpathyChannelFactory *self = (EmpathyChannelFactory *) factory;
-  const gchar *chan_type;
-
-  chan_type = tp_asv_get_string (properties, TP_PROP_CHANNEL_CHANNEL_TYPE);
-
-  if (!tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_TEXT))
-    {
-      TpAccount *account;
-
-      account = empathy_get_account_for_connection (conn);
-
-      return TP_CHANNEL (empathy_tp_chat_new (account, conn, path, properties));
-    }
-  else if (!tp_strdiff (chan_type, TPY_IFACE_CHANNEL_TYPE_CALL))
-    {
-      return TP_CHANNEL (tpy_call_channel_new (conn, path, properties,
-            error));
-    }
-
-  return tp_client_channel_factory_create_channel (
-      self->priv->automatic_factory, conn, path, properties, error);
-}
-
-static GArray *
-empathy_channel_factory_dup_channel_features (
-    TpClientChannelFactory *factory,
-    TpChannel *channel)
-{
-  EmpathyChannelFactory *self = (EmpathyChannelFactory *) factory;
-  GArray *features;
-  GQuark feature;
-
-  features =  tp_client_channel_factory_dup_channel_features (
-      self->priv->automatic_factory, channel);
-
-  if (EMPATHY_IS_TP_CHAT (channel))
-    {
-      feature = TP_CHANNEL_FEATURE_CHAT_STATES;
-      g_array_append_val (features, feature);
-
-      feature = EMPATHY_TP_CHAT_FEATURE_READY;
-      g_array_append_val (features, feature);
-    }
-
-  return features;
-}
-
-static void
-factory_iface_init (gpointer g_iface,
-    gpointer unused G_GNUC_UNUSED)
-{
-  TpClientChannelFactoryInterface *iface = g_iface;
-
-  iface->obj_create_channel = empathy_channel_factory_create_channel;
-  iface->obj_dup_channel_features =
-    empathy_channel_factory_dup_channel_features;
-}
diff --git a/libempathy/empathy-channel-factory.h b/libempathy/empathy-channel-factory.h
deleted file mode 100644 (file)
index 7cfcf31..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2010 Collabora Ltd.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
- * Boston, MA  02110-1301  USA
- *
- * Authors: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
- */
-
-#ifndef __EMPATHY_CHANNEL_FACTORY_H__
-#define __EMPATHY_CHANNEL_FACTORY_H__
-
-#include <glib-object.h>
-
-G_BEGIN_DECLS
-
-#define EMPATHY_TYPE_CHANNEL_FACTORY         (empathy_channel_factory_get_type ())
-#define EMPATHY_CHANNEL_FACTORY(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), EMPATHY_TYPE_CHANNEL_FACTORY, EmpathyChannelFactory))
-#define EMPATHY_CHANNEL_FACTORY_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), EMPATHY_TYPE_CHANNEL_FACTORY, EmpathyChannelFactoryClass))
-#define EMPATHY_IS_CHANNEL_FACTORY(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), EMPATHY_TYPE_CHANNEL_FACTORY))
-#define EMPATHY_IS_CHANNEL_FACTORY_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), EMPATHY_TYPE_CHANNEL_FACTORY))
-#define EMPATHY_CHANNEL_FACTORY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_CHANNEL_FACTORY, EmpathyChannelFactoryClass))
-
-typedef struct _EmpathyChannelFactory EmpathyChannelFactory;
-typedef struct _EmpathyChannelFactoryClass EmpathyChannelFactoryClass;
-typedef struct _EmpathyChannelFactoryPrivate EmpathyChannelFactoryPrivate;
-
-struct _EmpathyChannelFactory
-{
-  GObject parent;
-  EmpathyChannelFactoryPrivate *priv;
-};
-
-struct _EmpathyChannelFactoryClass
-{
-  GObjectClass parent_class;
-};
-
-GType empathy_channel_factory_get_type (void) G_GNUC_CONST;
-
-EmpathyChannelFactory * empathy_channel_factory_new (void);
-
-EmpathyChannelFactory * empathy_channel_factory_dup (void);
-
-G_END_DECLS
-#endif /* __EMPATHY_CHANNEL_FACTORY_H__ */
index 2be475b3a2e26a1057b748c36cd1d7fee5a090b2..5e1c0bb45921d954a6194525b8e389fde7cf7d9f 100644 (file)
@@ -35,9 +35,9 @@
 #include <telepathy-glib/simple-observer.h>
 #include <telepathy-glib/util.h>
 
+#include "empathy-client-factory.h"
 #include "empathy-tp-chat.h"
 #include "empathy-chatroom-manager.h"
-#include "empathy-channel-factory.h"
 #include "empathy-utils.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
@@ -220,6 +220,8 @@ chatroom_manager_parse_chatroom (EmpathyChatroomManager *manager,
   gchar *account_id;
   gboolean auto_connect;
   gboolean always_urgent;
+  EmpathyClientFactory *factory;
+  GError *error = NULL;
 
   priv = GET_PRIV (manager);
 
@@ -270,10 +272,17 @@ chatroom_manager_parse_chatroom (EmpathyChatroomManager *manager,
       xmlFree (str);
     }
 
-  account = tp_account_manager_ensure_account (priv->account_manager,
-    account_id);
+  factory = empathy_client_factory_dup ();
+
+  account = tp_simple_client_factory_ensure_account (
+          TP_SIMPLE_CLIENT_FACTORY (factory), account_id, NULL, &error);
+  g_object_unref (factory);
+
   if (account == NULL)
     {
+      DEBUG ("Failed to create account: %s", error->message);
+      g_error_free (error);
+
       g_free (name);
       g_free (room);
       g_free (account_id);
@@ -545,8 +554,6 @@ empathy_chatroom_manager_constructor (GType type,
   EmpathyChatroomManager *self;
   EmpathyChatroomManagerPriv *priv;
   GError *error = NULL;
-  TpDBusDaemon *dbus;
-  EmpathyChannelFactory *factory;
 
   if (chatroom_manager_singleton != NULL)
     return g_object_ref (chatroom_manager_singleton);
@@ -581,21 +588,10 @@ empathy_chatroom_manager_constructor (GType type,
       g_free (dir);
     }
 
-  dbus = tp_dbus_daemon_dup (&error);
-  if (dbus == NULL)
-    {
-      g_warning ("Failed to get TpDBusDaemon: %s", error->message);
-
-      g_error_free (error);
-      return obj;
-    }
-
   /* Setup a room observer */
-  priv->observer = tp_simple_observer_new (dbus, TRUE,
+  priv->observer = tp_simple_observer_new_with_am (priv->account_manager, TRUE,
       "Empathy.ChatroomManager", TRUE, observe_channels_cb, self, NULL);
 
-  g_object_unref (dbus);
-
   tp_base_client_take_observer_filter (priv->observer, tp_asv_new (
       TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
         TP_IFACE_CHANNEL_TYPE_TEXT,
@@ -603,14 +599,6 @@ empathy_chatroom_manager_constructor (GType type,
         TP_HANDLE_TYPE_ROOM,
       NULL));
 
-  tp_base_client_add_connection_features_varargs (priv->observer,
-      TP_CONNECTION_FEATURE_CAPABILITIES, NULL);
-
-  factory = empathy_channel_factory_dup ();
-
-  tp_base_client_set_channel_factory (priv->observer,
-      TP_CLIENT_CHANNEL_FACTORY (factory));
-
   if (!tp_base_client_register (priv->observer, &error))
     {
       g_critical ("Failed to register Observer: %s", error->message);
@@ -618,7 +606,6 @@ empathy_chatroom_manager_constructor (GType type,
       g_error_free (error);
     }
 
-  g_object_unref (factory);
   return obj;
 }
 
diff --git a/libempathy/empathy-client-factory.c b/libempathy/empathy-client-factory.c
new file mode 100644 (file)
index 0000000..5055a26
--- /dev/null
@@ -0,0 +1,181 @@
+/*
+ * Copyright (C) 2010 Collabora Ltd.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA  02110-1301  USA
+ *
+ * Authors: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
+ */
+
+#include <config.h>
+
+#include "empathy-client-factory.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,
+    const gchar *path,
+    const GHashTable *properties,
+    GError **error)
+{
+  const gchar *chan_type;
+
+  chan_type = tp_asv_get_string (properties, TP_PROP_CHANNEL_CHANNEL_TYPE);
+
+  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,
+            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);
+}
+
+static GArray *
+empathy_client_factory_dup_channel_features (TpSimpleClientFactory *factory,
+    TpChannel *channel)
+{
+  GArray *features;
+  GQuark feature;
+
+  features = chainup->dup_channel_features (factory, channel);
+
+  if (EMPATHY_IS_TP_CHAT (channel))
+    {
+      feature = TP_CHANNEL_FEATURE_CHAT_STATES;
+      g_array_append_val (features, feature);
+
+      feature = EMPATHY_TP_CHAT_FEATURE_READY;
+      g_array_append_val (features, feature);
+    }
+
+  return features;
+}
+
+static GArray *
+empathy_client_factory_dup_connection_features (TpSimpleClientFactory *factory,
+    TpConnection *connection)
+{
+  GArray *features;
+  GQuark feature;
+
+  features = chainup->dup_connection_features (factory, connection);
+
+  feature = TP_CONNECTION_FEATURE_CAPABILITIES;
+  g_array_append_val (features, feature);
+
+  return features;
+}
+
+static void
+empathy_client_factory_class_init (EmpathyClientFactoryClass *cls)
+{
+  TpSimpleClientFactoryClass *simple_class = (TpSimpleClientFactoryClass *) cls;
+
+  simple_class->create_channel = empathy_client_factory_create_channel;
+  simple_class->dup_channel_features =
+    empathy_client_factory_dup_channel_features;
+
+  simple_class->dup_connection_features =
+    empathy_client_factory_dup_connection_features;
+}
+
+static void
+empathy_client_factory_init (EmpathyClientFactory *self)
+{
+}
+
+static EmpathyClientFactory *
+empathy_client_factory_new (TpDBusDaemon *dbus)
+{
+    return g_object_new (EMPATHY_TYPE_CLIENT_FACTORY,
+        "dbus-daemon", dbus,
+        NULL);
+}
+
+EmpathyClientFactory *
+empathy_client_factory_dup (void)
+{
+  static EmpathyClientFactory *singleton = NULL;
+  TpDBusDaemon *dbus;
+  GError *error = NULL;
+
+  if (singleton != NULL)
+    return g_object_ref (singleton);
+
+  dbus = tp_dbus_daemon_dup (&error);
+  if (dbus == NULL)
+    {
+      g_warning ("Failed to get TpDBusDaemon: %s", error->message);
+      g_error_free (error);
+      return NULL;
+    }
+
+  singleton = empathy_client_factory_new (dbus);
+  g_object_unref (dbus);
+
+  g_object_add_weak_pointer (G_OBJECT (singleton), (gpointer) &singleton);
+
+  return singleton;
+}
diff --git a/libempathy/empathy-client-factory.h b/libempathy/empathy-client-factory.h
new file mode 100644 (file)
index 0000000..c4d88e2
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2010 Collabora Ltd.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA  02110-1301  USA
+ *
+ * Authors: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
+ */
+
+#ifndef __EMPATHY_CLIENT_FACTORY_H__
+#define __EMPATHY_CLIENT_FACTORY_H__
+
+#include <telepathy-glib/telepathy-glib.h>
+
+G_BEGIN_DECLS
+
+#define EMPATHY_TYPE_CLIENT_FACTORY         (empathy_client_factory_get_type ())
+#define EMPATHY_CLIENT_FACTORY(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), EMPATHY_TYPE_CLIENT_FACTORY, EmpathyClientFactory))
+#define EMPATHY_CLIENT_FACTORY_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), EMPATHY_TYPE_CLIENT_FACTORY, EmpathyClientFactoryClass))
+#define EMPATHY_IS_CLIENT_FACTORY(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), EMPATHY_TYPE_CLIENT_FACTORY))
+#define EMPATHY_IS_CLIENT_FACTORY_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), EMPATHY_TYPE_CLIENT_FACTORY))
+#define EMPATHY_CLIENT_FACTORY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_CLIENT_FACTORY, EmpathyClientFactoryClass))
+
+typedef struct _EmpathyClientFactory EmpathyClientFactory;
+typedef struct _EmpathyClientFactoryClass EmpathyClientFactoryClass;
+typedef struct _EmpathyClientFactoryPrivate EmpathyClientFactoryPrivate;
+
+struct _EmpathyClientFactory
+{
+  TpAutomaticClientFactory parent;
+  EmpathyClientFactoryPrivate *priv;
+};
+
+struct _EmpathyClientFactoryClass
+{
+  TpAutomaticClientFactoryClass parent_class;
+};
+
+GType empathy_client_factory_get_type (void) G_GNUC_CONST;
+
+EmpathyClientFactory * empathy_client_factory_dup (void);
+
+G_END_DECLS
+#endif /* __EMPATHY_CLIENT_FACTORY_H__ */
index cdca6dc751b6dae35334af3553cdb203e1541b74..d5764894b35601c253330e9ee06deed56ad97eb4 100644 (file)
@@ -940,7 +940,7 @@ empathy_contact_get_account (EmpathyContact *contact)
       /* FIXME: This assume the account manager already exists */
       connection = tp_contact_get_connection (priv->tp_contact);
       priv->account =
-        g_object_ref (empathy_get_account_for_connection (connection));
+        g_object_ref (tp_connection_get_account (connection));
     }
 
   return priv->account;
index 5fb238a2b9e5efcab49e52954e485de0a8575f9b..597bbaf5110378777efb29959849d3197d1db568 100644 (file)
@@ -206,20 +206,13 @@ empathy_ft_factory_init (EmpathyFTFactory *self)
 {
   EmpathyFTFactoryPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
     EMPATHY_TYPE_FT_FACTORY, EmpathyFTFactoryPriv);
-  TpDBusDaemon *dbus;
-  GError *error = NULL;
+  TpAccountManager *am;
 
   self->priv = priv;
 
-  dbus = tp_dbus_daemon_dup (&error);
-  if (dbus == NULL)
-    {
-      g_warning ("Failed to get TpDBusDaemon: %s", error->message);
-      g_error_free (error);
-      return;
-    }
+  am = tp_account_manager_dup ();
 
-  priv->handler = tp_simple_handler_new (dbus, FALSE, FALSE,
+  priv->handler = tp_simple_handler_new_with_am (am, FALSE, FALSE,
       EMPATHY_FT_BUS_NAME_SUFFIX, FALSE, handle_channels_cb, self, NULL);
 
   tp_base_client_take_handler_filter (priv->handler, tp_asv_new (
@@ -231,7 +224,7 @@ empathy_ft_factory_init (EmpathyFTFactory *self)
         TP_PROP_CHANNEL_REQUESTED, G_TYPE_BOOLEAN, FALSE,
         NULL));
 
-  g_object_unref (dbus);
+  g_object_unref (am);
 }
 
 static void
index 06b3308c506b072bafff103062e2061566c65d92..995f49ab7e299dda1e24e9e3f67f3dd2a0b6de6f 100644 (file)
@@ -39,6 +39,7 @@
 # include <telepathy-logger/call-event.h>
 #endif
 
+#include "empathy-client-factory.h"
 #include "empathy-message.h"
 #include "empathy-utils.h"
 #include "empathy-enum-types.h"
@@ -352,7 +353,7 @@ EmpathyMessage *
 empathy_message_from_tpl_log_event (TplEvent *logevent)
 {
        EmpathyMessage *retval = NULL;
-       TpAccountManager *acc_man = NULL;
+       EmpathyClientFactory *factory;
        TpAccount *account = NULL;
        TplEntity *receiver = NULL;
        TplEntity *sender = NULL;
@@ -364,7 +365,7 @@ empathy_message_from_tpl_log_event (TplEvent *logevent)
 
        g_return_val_if_fail (TPL_IS_EVENT (logevent), NULL);
 
-       acc_man = tp_account_manager_dup ();
+       factory = empathy_client_factory_dup ();
        /* FIXME Currently Empathy shows in the log viewer only valid accounts, so it
         * won't be selected any non-existing (ie removed) account.
         * When #610455 will be fixed, calling tp_account_manager_ensure_account ()
@@ -376,9 +377,10 @@ empathy_message_from_tpl_log_event (TplEvent *logevent)
         * If the way EmpathyContact stores the avatar is changes, it might not be
         * needed anymore any TpAccount passing and the following call will be
         * useless */
-       account = tp_account_manager_ensure_account (acc_man,
-                       tpl_event_get_account_path (logevent));
-       g_object_unref (acc_man);
+       account = tp_simple_client_factory_ensure_account (
+                       TP_SIMPLE_CLIENT_FACTORY (factory),
+                       tpl_event_get_account_path (logevent), NULL, NULL);
+       g_object_unref (factory);
 
        if (TPL_IS_TEXT_EVENT (logevent)) {
                TplTextEvent *textevent = TPL_TEXT_EVENT (logevent);
index a690f60e3463f8a0a5e1a0f17c0cc30c468fbea0..fde1e70ba7ccf60a62aa4699e8ccc1e082f270ec 100644 (file)
@@ -1399,7 +1399,9 @@ tp_chat_iface_init (EmpathyContactListIface *iface)
 }
 
 EmpathyTpChat *
-empathy_tp_chat_new (TpAccount *account,
+empathy_tp_chat_new (
+                    TpSimpleClientFactory *factory,
+                    TpAccount *account,
                     TpConnection *conn,
                     const gchar *object_path,
                     const GHashTable *immutable_properties)
@@ -1411,6 +1413,7 @@ empathy_tp_chat_new (TpAccount *account,
        g_return_val_if_fail (immutable_properties != NULL, NULL);
 
        return g_object_new (EMPATHY_TYPE_TP_CHAT,
+                            "factory", factory,
                             "account", account,
                             "connection", conn,
                             "dbus-daemon", conn_proxy->dbus_daemon,
index a69c4924f2b81aa026bc25ef18ec148f2e16d0a2..810cb5184e9b233f8e3355457fea715b6fcb9f31 100644 (file)
@@ -71,7 +71,9 @@ GQuark empathy_tp_chat_get_feature_ready (void) G_GNUC_CONST;
 
 GType          empathy_tp_chat_get_type             (void) G_GNUC_CONST;
 
-EmpathyTpChat *empathy_tp_chat_new                  (TpAccount *account,
+EmpathyTpChat *empathy_tp_chat_new                  (
+                                                    TpSimpleClientFactory *factory,
+                                                    TpAccount *account,
                                                     TpConnection *connection,
                                                     const gchar *object_path,
                                                     const GHashTable *immutable_properties);
index 5f9178a55b70d8554f27eea75c3530a88009a3f7..04a6c783668dd5e4772a44dbd4a9b073eb9bf3fa 100644 (file)
@@ -46,6 +46,7 @@
 #include <telepathy-glib/dbus.h>
 #include <telepathy-glib/util.h>
 
+#include "empathy-client-factory.h"
 #include "empathy-utils.h"
 #include "empathy-contact-manager.h"
 #include "empathy-individual-manager.h"
@@ -83,6 +84,8 @@ void
 empathy_init (void)
 {
   static gboolean initialized = FALSE;
+  TpAccountManager *am;
+  EmpathyClientFactory *factory;
 
   if (initialized)
     return;
@@ -103,6 +106,13 @@ empathy_init (void)
   emp_cli_init ();
 
   initialized = TRUE;
+
+  factory = empathy_client_factory_dup ();
+  am = tp_account_manager_new_with_factory (TP_SIMPLE_CLIENT_FACTORY (factory));
+  tp_account_manager_set_default (am);
+
+  g_object_unref (factory);
+  g_object_unref (am);
 }
 
 gboolean
@@ -559,36 +569,6 @@ empathy_service_name_to_display_name (const gchar *service_name)
   return service_name;
 }
 
-/* Note: this function depends on the account manager having its core feature
- * prepared. */
-TpAccount *
-empathy_get_account_for_connection (TpConnection *connection)
-{
-  TpAccountManager *manager;
-  TpAccount *account = NULL;
-  GList *accounts, *l;
-
-  manager = tp_account_manager_dup ();
-
-  accounts = tp_account_manager_get_valid_accounts (manager);
-
-  for (l = accounts; l != NULL; l = l->next)
-    {
-      TpAccount *a = l->data;
-
-      if (tp_account_get_connection (a) == connection)
-        {
-          account = a;
-          break;
-        }
-    }
-
-  g_list_free (accounts);
-  g_object_unref (manager);
-
-  return account;
-}
-
 gboolean
 empathy_account_manager_get_accounts_connected (gboolean *connecting)
 {
index 97490b939071b24bb88745d2141827306554e252..90933ededc491c3f71b9f5b181eaf320500b7a70 100644 (file)
@@ -80,8 +80,6 @@ const gchar *empathy_service_name_to_display_name (const gchar *proto_name);
 #define EMPATHY_ARRAY_TYPE_OBJECT (empathy_type_dbus_ao ())
 GType empathy_type_dbus_ao (void);
 
-TpAccount * empathy_get_account_for_connection (TpConnection *connection);
-
 gboolean empathy_account_manager_get_accounts_connected (gboolean *connecting);
 
 void empathy_connect_new_account (TpAccount *account,
index 46ef01aa5f3eaa6f07c2b2fefa6e483484cf751e..9f3fe16ec88aead02b59f1d406975f927d16d3bb 100644 (file)
@@ -29,7 +29,6 @@
 
 #include <telepathy-yell/telepathy-yell.h>
 
-#include <libempathy/empathy-channel-factory.h>
 #include <libempathy/empathy-request-util.h>
 #include <libempathy/empathy-tp-contact-factory.h>
 #include <libempathy/empathy-utils.h>
@@ -76,28 +75,15 @@ empathy_call_factory_init (EmpathyCallFactory *obj)
 {
   EmpathyCallFactoryPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (obj,
     EMPATHY_TYPE_CALL_FACTORY, EmpathyCallFactoryPriv);
-  TpDBusDaemon *dbus;
-  EmpathyChannelFactory *factory;
-  GError *error = NULL;
+  TpAccountManager *am;
 
   obj->priv = priv;
 
-  dbus = tp_dbus_daemon_dup (&error);
-  if (dbus == NULL)
-    {
-      g_warning ("Failed to get TpDBusDaemon: %s", error->message);
-      g_error_free (error);
-      return;
-    }
+  am = tp_account_manager_dup ();
 
-  priv->handler = tp_simple_handler_new (dbus, FALSE, FALSE,
+  priv->handler = tp_simple_handler_new_with_am (am, FALSE, FALSE,
       EMPATHY_CALL_BUS_NAME_SUFFIX, FALSE, handle_channels_cb, obj, NULL);
 
-  factory = empathy_channel_factory_new ();
-  tp_base_client_set_channel_factory (priv->handler,
-      TP_CLIENT_CHANNEL_FACTORY (factory));
-  g_object_unref (factory);
-
   tp_base_client_take_handler_filter (priv->handler, tp_asv_new (
         TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
           TPY_IFACE_CHANNEL_TYPE_CALL,
@@ -127,7 +113,7 @@ empathy_call_factory_init (EmpathyCallFactory *obj)
     "org.freedesktop.Telepathy.Channel.Interface.MediaSignalling/video/h264",
     NULL);
 
-  g_object_unref (dbus);
+  g_object_unref (am);
 }
 
 static GObject *
index c141b9ffa29e6479c5c5626788824ad93b2fd012..cf93a1de302c17e22fba9ddb14763250443998d8 100644 (file)
@@ -30,7 +30,6 @@
 
 #include <telepathy-farstream/telepathy-farstream.h>
 
-#include <libempathy/empathy-channel-factory.h>
 #include <libempathy/empathy-utils.h>
 #include <libempathy/empathy-tp-contact-factory.h>
 
@@ -944,7 +943,6 @@ empathy_call_handler_start_call (EmpathyCallHandler *handler,
     gint64 timestamp)
 {
   EmpathyCallHandlerPriv *priv = GET_PRIV (handler);
-  EmpathyChannelFactory *channel_factory;
   TpAccountChannelRequest *req;
   TpAccount *account;
   GHashTable *request;
@@ -966,11 +964,6 @@ empathy_call_handler_start_call (EmpathyCallHandler *handler,
 
   req = tp_account_channel_request_new (account, request, timestamp);
 
-  channel_factory = empathy_channel_factory_dup ();
-  tp_account_channel_request_set_channel_factory (req,
-      TP_CLIENT_CHANNEL_FACTORY (channel_factory));
-  g_object_unref (channel_factory);
-
   tp_account_channel_request_create_and_handle_channel_async (req, NULL,
       empathy_call_handler_request_cb, handler);
 
index 8ce57a3e1a7d642a245f4703de8bceddc1db759a..0fecbdca614f2b011f083ae12991ff02efb86e1e 100644 (file)
@@ -28,7 +28,6 @@
 
 #include <libnotify/notification.h>
 
-#include <libempathy/empathy-channel-factory.h>
 #include <libempathy/empathy-utils.h>
 
 #include <libempathy-gtk/empathy-images.h>
@@ -349,31 +348,19 @@ 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 Call and StreamedMedia channels */
   tp_base_client_take_observer_filter (self->priv->observer,
       tp_asv_new (
@@ -398,7 +385,7 @@ empathy_call_observer_init (EmpathyCallObserver *self)
       g_error_free (error);
     }
 
-  g_object_unref (dbus);
+  g_object_unref (am);
 }
 
 EmpathyCallObserver *
index e6ffaa0e926deb2c42c460fb8b065a6b4567b476..0e1745edbff5a0c2ea8a67691cc396d452d02142 100644 (file)
@@ -20,7 +20,6 @@
 #include <telepathy-glib/telepathy-glib.h>
 #include <telepathy-glib/proxy-subclass.h>
 
-#include <libempathy/empathy-channel-factory.h>
 #include <libempathy/empathy-chatroom-manager.h>
 #include <libempathy/empathy-request-util.h>
 #include <libempathy/empathy-utils.h>
@@ -235,35 +234,22 @@ static void
 empathy_chat_manager_init (EmpathyChatManager *self)
 {
   EmpathyChatManagerPriv *priv = GET_PRIV (self);
-  TpDBusDaemon *dbus;
+  TpAccountManager *am;
   GError *error = NULL;
-  EmpathyChannelFactory *factory;
 
   priv->closed_queue = g_queue_new ();
   priv->messages = g_hash_table_new_full (g_str_hash, g_str_equal,
       g_free, (GDestroyNotify) g_hash_table_unref);
 
-  dbus = tp_dbus_daemon_dup (&error);
-  if (dbus == NULL)
-    {
-      g_critical ("Failed to get D-Bus daemon: %s", error->message);
-      g_error_free (error);
-      return;
-    }
+  am = tp_account_manager_dup ();
 
   priv->chatroom_mgr = empathy_chatroom_manager_dup_singleton (NULL);
 
   /* Text channels handler */
-  priv->handler = tp_simple_handler_new (dbus, FALSE, FALSE,
+  priv->handler = tp_simple_handler_new_with_am (am, FALSE, FALSE,
       EMPATHY_CHAT_BUS_NAME_SUFFIX, FALSE, handle_channels, self, NULL);
 
-  /* EmpathyTpChat relies on these features being prepared */
-  tp_base_client_add_connection_features_varargs (priv->handler,
-    TP_CONNECTION_FEATURE_CAPABILITIES, 0);
-  tp_base_client_add_channel_features_varargs (priv->handler,
-      TP_CHANNEL_FEATURE_CHAT_STATES, 0);
-
-  g_object_unref (dbus);
+  g_object_unref (am);
 
   tp_base_client_take_handler_filter (priv->handler, tp_asv_new (
         TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_TEXT,
@@ -280,18 +266,11 @@ empathy_chat_manager_init (EmpathyChatManager *self)
         TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_NONE,
         NULL));
 
-  factory = empathy_channel_factory_dup ();
-
-  tp_base_client_set_channel_factory (priv->handler,
-      TP_CLIENT_CHANNEL_FACTORY (factory));
-
   if (!tp_base_client_register (priv->handler, &error))
     {
       g_critical ("Failed to register text handler: %s", error->message);
       g_error_free (error);
     }
-
-  g_object_unref (factory);
 }
 
 static void
index c0a08d4ddc9feb6b85518e5baf3d4c66ed51cfa4..171b6358d205fe2f7264569c9457f88fe7f4218d 100644 (file)
@@ -38,6 +38,7 @@
 
 #include <telepathy-glib/telepathy-glib.h>
 
+#include <libempathy/empathy-client-factory.h>
 #include <libempathy/empathy-contact.h>
 #include <libempathy/empathy-message.h>
 #include <libempathy/empathy-chatroom-manager.h>
@@ -1827,7 +1828,7 @@ chat_window_drag_data_received (GtkWidget        *widget,
                EmpathyChat           *chat = NULL;
                EmpathyChatWindow     *old_window;
                TpAccount             *account = NULL;
-               TpAccountManager      *account_manager;
+               EmpathyClientFactory  *factory;
                const gchar           *id;
                gchar                **strv;
                const gchar           *account_id;
@@ -1835,9 +1836,7 @@ chat_window_drag_data_received (GtkWidget        *widget,
 
                id = (const gchar*) gtk_selection_data_get_data (selection);
 
-               /* FIXME: Perhaps should be sure that the account manager is
-                * prepared before calling _ensure_account on it. */
-               account_manager = tp_account_manager_dup ();
+               factory = empathy_client_factory_dup ();
 
                DEBUG ("DND contact from roster with id:'%s'", id);
 
@@ -1846,7 +1845,11 @@ chat_window_drag_data_received (GtkWidget        *widget,
                        account_id = strv[0];
                        contact_id = strv[1];
                        account =
-                               tp_account_manager_ensure_account (account_manager, account_id);
+                               tp_simple_client_factory_ensure_account (
+                               TP_SIMPLE_CLIENT_FACTORY (factory), account_id,
+                                NULL, NULL);
+
+                       g_object_unref (factory);
                        if (account != NULL)
                                chat = empathy_chat_window_find_chat (account, contact_id, FALSE);
                }
@@ -1864,7 +1867,6 @@ chat_window_drag_data_received (GtkWidget        *widget,
                        g_strfreev (strv);
                        return;
                }
-               g_object_unref (account_manager);
                g_strfreev (strv);
 
                old_window = chat_window_find_chat (chat);
index 27f8a0bdb7bc115ce3eb55a111cb27f3346d2988..a6ce22b18068cfb9202e562de5e5e96fa0032675 100644 (file)
@@ -31,7 +31,6 @@
 
 #include <telepathy-yell/telepathy-yell.h>
 
-#include <libempathy/empathy-channel-factory.h>
 #include <libempathy/empathy-presence-manager.h>
 #include <libempathy/empathy-tp-contact-factory.h>
 #include <libempathy/empathy-contact-manager.h>
@@ -1371,9 +1370,8 @@ empathy_event_manager_init (EmpathyEventManager *manager)
 {
   EmpathyEventManagerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (manager,
     EMPATHY_TYPE_EVENT_MANAGER, EmpathyEventManagerPriv);
-  TpDBusDaemon *dbus;
   GError *error = NULL;
-  EmpathyChannelFactory *factory;
+  TpAccountManager *am;
 
   manager->priv = priv;
 
@@ -1389,20 +1387,10 @@ empathy_event_manager_init (EmpathyEventManager *manager)
   g_signal_connect (priv->contact_manager, "members-changed",
     G_CALLBACK (event_manager_members_changed_cb), manager);
 
-  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 ();
 
-  priv->approver = tp_simple_approver_new (dbus, "Empathy.EventManager", FALSE,
-      approve_channels, manager, NULL);
-
-  /* EmpathyTpChat relies on this feature being prepared */
-  tp_base_client_add_connection_features_varargs (priv->approver,
-    TP_CONNECTION_FEATURE_CAPABILITIES, 0);
+  priv->approver = tp_simple_approver_new_with_am (am, "Empathy.EventManager",
+      FALSE, approve_channels, manager, NULL);
 
   /* Private text channels */
   tp_base_client_take_approver_filter (priv->approver,
@@ -1449,7 +1437,7 @@ empathy_event_manager_init (EmpathyEventManager *manager)
    * EmpathyTpChat and its users to not depend on the connection being
    * prepared with capabilities. I chose the former, obviously. :-) */
 
-  priv->auth_approver = tp_simple_approver_new (dbus,
+  priv->auth_approver = tp_simple_approver_new_with_am (am,
       "Empathy.AuthEventManager", FALSE, approve_channels, manager,
       NULL);
 
@@ -1463,11 +1451,6 @@ empathy_event_manager_init (EmpathyEventManager *manager)
           TP_IFACE_CHANNEL_INTERFACE_SASL_AUTHENTICATION,
         NULL));
 
-  factory = empathy_channel_factory_dup ();
-
-  tp_base_client_set_channel_factory (priv->approver,
-      TP_CLIENT_CHANNEL_FACTORY (factory));
-
   if (!tp_base_client_register (priv->approver, &error))
     {
       DEBUG ("Failed to register Approver: %s", error->message);
@@ -1480,8 +1463,7 @@ empathy_event_manager_init (EmpathyEventManager *manager)
       g_error_free (error);
     }
 
-  g_object_unref (factory);
-  g_object_unref (dbus);
+  g_object_unref (am);
 }
 
 EmpathyEventManager *
index e044a1b52b650dcad4673d00f632839ffa769d5b..9ef5da5e16008fcdf78b45200f38815cca097432 100644 (file)
@@ -72,20 +72,13 @@ empathy_streamed_media_factory_init (EmpathyStreamedMediaFactory *obj)
 {
   EmpathyStreamedMediaFactoryPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (obj,
     EMPATHY_TYPE_STREAMED_MEDIA_FACTORY, EmpathyStreamedMediaFactoryPriv);
-  TpDBusDaemon *dbus;
-  GError *error = NULL;
+  TpAccountManager *am;
 
   obj->priv = priv;
 
-  dbus = tp_dbus_daemon_dup (&error);
-  if (dbus == NULL)
-    {
-      g_warning ("Failed to get TpDBusDaemon: %s", error->message);
-      g_error_free (error);
-      return;
-    }
+  am = tp_account_manager_dup ();
 
-  priv->handler = tp_simple_handler_new (dbus, FALSE, FALSE,
+  priv->handler = tp_simple_handler_new_with_am (am, FALSE, FALSE,
       EMPATHY_AV_BUS_NAME_SUFFIX, FALSE, handle_channels_cb, obj, NULL);
 
   tp_base_client_take_handler_filter (priv->handler, tp_asv_new (
@@ -114,7 +107,7 @@ empathy_streamed_media_factory_init (EmpathyStreamedMediaFactory *obj)
     "org.freedesktop.Telepathy.Channel.Interface.MediaSignalling/video/h264",
     NULL);
 
-  g_object_unref (dbus);
+  g_object_unref (am);
 }
 
 static GObject *
index b79e898d048803bc40951c9ba2eb4b32705bb296..966027f385a890df07bbf6bd4156df88a215a80b 100644 (file)
@@ -109,7 +109,7 @@ START_TEST (test_empathy_chatroom_manager_dup_singleton)
         { "name1", "room1", TRUE, TRUE },
         { "name2", "room2", FALSE, TRUE }};
 
-  account_manager = empathy_account_manager_dup_singleton ();
+  account_manager = tp_account_manager_dup ();
   account = get_test_account ();
 
   copy_xml_file (CHATROOM_SAMPLE, CHATROOM_FILE);
@@ -143,7 +143,7 @@ START_TEST (test_empathy_chatroom_manager_add)
         { "name4", "room4", FALSE, FALSE }};
   EmpathyChatroom *chatroom;
 
-  account_manager = empathy_account_manager_dup_singleton ();
+  account_manager = tp_account_manager_dup ();
 
   account = get_test_account ();
 
@@ -203,7 +203,7 @@ START_TEST (test_empathy_chatroom_manager_remove)
   EmpathyChatroom *chatroom;
   EmpathyAccountManager *account_mgr;
 
-  account_mgr = empathy_account_manager_dup_singleton ();
+  account_mgr = tp_account_manager_dup ();
   account = get_test_account ();
 
   copy_xml_file (CHATROOM_SAMPLE, CHATROOM_FILE);
@@ -260,7 +260,7 @@ START_TEST (test_empathy_chatroom_manager_change_favorite)
         { "name2", "room2", FALSE, FALSE }};
   EmpathyChatroom *chatroom;
 
-  account_manager = empathy_account_manager_dup_singleton ();
+  account_manager = tp_account_manager_dup ();
   account = get_test_account ();
 
   copy_xml_file (CHATROOM_SAMPLE, CHATROOM_FILE);
@@ -324,7 +324,7 @@ START_TEST (test_empathy_chatroom_manager_change_chatroom)
         { "name2", "room2", FALSE, TRUE }};
   EmpathyChatroom *chatroom;
 
-  account_manager = empathy_account_manager_dup_singleton ();
+  account_manager = tp_account_manager_dup ();
   account = get_test_account ();
 
   copy_xml_file (CHATROOM_SAMPLE, "foo.xml");