aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-08-18 17:31:10 +0800
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-08-18 18:15:06 +0800
commit9ddd25f8589ae0cd5ec8e09c4c012e4ccac6a416 (patch)
tree4e4cfd5b8f801acff74edfdd5072f45d7038e00b /libempathy
parent7fbf3e0c200b0a3c5086fdce0cc19afe48c429bb (diff)
downloadgsoc2013-empathy-9ddd25f8589ae0cd5ec8e09c4c012e4ccac6a416.tar
gsoc2013-empathy-9ddd25f8589ae0cd5ec8e09c4c012e4ccac6a416.tar.gz
gsoc2013-empathy-9ddd25f8589ae0cd5ec8e09c4c012e4ccac6a416.tar.bz2
gsoc2013-empathy-9ddd25f8589ae0cd5ec8e09c4c012e4ccac6a416.tar.lz
gsoc2013-empathy-9ddd25f8589ae0cd5ec8e09c4c012e4ccac6a416.tar.xz
gsoc2013-empathy-9ddd25f8589ae0cd5ec8e09c4c012e4ccac6a416.tar.zst
gsoc2013-empathy-9ddd25f8589ae0cd5ec8e09c4c012e4ccac6a416.zip
Port to new tp-glib client factory
- 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
Diffstat (limited to 'libempathy')
-rw-r--r--libempathy/Makefile.am4
-rw-r--r--libempathy/empathy-channel-factory.c163
-rw-r--r--libempathy/empathy-channel-factory.h58
-rw-r--r--libempathy/empathy-chatroom-manager.c39
-rw-r--r--libempathy/empathy-client-factory.c181
-rw-r--r--libempathy/empathy-client-factory.h56
-rw-r--r--libempathy/empathy-contact.c2
-rw-r--r--libempathy/empathy-ft-factory.c15
-rw-r--r--libempathy/empathy-message.c12
-rw-r--r--libempathy/empathy-tp-chat.c5
-rw-r--r--libempathy/empathy-tp-chat.h4
-rw-r--r--libempathy/empathy-utils.c40
-rw-r--r--libempathy/empathy-utils.h2
13 files changed, 281 insertions, 300 deletions
diff --git a/libempathy/Makefile.am b/libempathy/Makefile.am
index f701f7480..34a706113 100644
--- a/libempathy/Makefile.am
+++ b/libempathy/Makefile.am
@@ -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
index d8b1cd941..000000000
--- a/libempathy/empathy-channel-factory.c
+++ /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
index 7cfcf31f8..000000000
--- a/libempathy/empathy-channel-factory.h
+++ /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__ */
diff --git a/libempathy/empathy-chatroom-manager.c b/libempathy/empathy-chatroom-manager.c
index 2be475b3a..5e1c0bb45 100644
--- a/libempathy/empathy-chatroom-manager.c
+++ b/libempathy/empathy-chatroom-manager.c
@@ -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
index 000000000..5055a2628
--- /dev/null
+++ b/libempathy/empathy-client-factory.c
@@ -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
index 000000000..c4d88e286
--- /dev/null
+++ b/libempathy/empathy-client-factory.h
@@ -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__ */
diff --git a/libempathy/empathy-contact.c b/libempathy/empathy-contact.c
index cdca6dc75..d5764894b 100644
--- a/libempathy/empathy-contact.c
+++ b/libempathy/empathy-contact.c
@@ -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;
diff --git a/libempathy/empathy-ft-factory.c b/libempathy/empathy-ft-factory.c
index 5fb238a2b..597bbaf51 100644
--- a/libempathy/empathy-ft-factory.c
+++ b/libempathy/empathy-ft-factory.c
@@ -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
diff --git a/libempathy/empathy-message.c b/libempathy/empathy-message.c
index 06b3308c5..995f49ab7 100644
--- a/libempathy/empathy-message.c
+++ b/libempathy/empathy-message.c
@@ -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);
diff --git a/libempathy/empathy-tp-chat.c b/libempathy/empathy-tp-chat.c
index a690f60e3..fde1e70ba 100644
--- a/libempathy/empathy-tp-chat.c
+++ b/libempathy/empathy-tp-chat.c
@@ -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,
diff --git a/libempathy/empathy-tp-chat.h b/libempathy/empathy-tp-chat.h
index a69c4924f..810cb5184 100644
--- a/libempathy/empathy-tp-chat.h
+++ b/libempathy/empathy-tp-chat.h
@@ -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);
diff --git a/libempathy/empathy-utils.c b/libempathy/empathy-utils.c
index 5f9178a55..04a6c7836 100644
--- a/libempathy/empathy-utils.c
+++ b/libempathy/empathy-utils.c
@@ -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)
{
diff --git a/libempathy/empathy-utils.h b/libempathy/empathy-utils.h
index 97490b939..90933eded 100644
--- a/libempathy/empathy-utils.h
+++ b/libempathy/empathy-utils.h
@@ -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,