2 * Copyright (C) 2010 Collabora Ltd.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301 USA
19 * Authors: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
24 #include "empathy-client-factory.h"
26 #include "empathy-tp-chat.h"
27 #include "empathy-utils.h"
29 #include <telepathy-yell/telepathy-yell.h>
31 G_DEFINE_TYPE (EmpathyClientFactory, empathy_client_factory,
32 TP_TYPE_AUTOMATIC_CLIENT_FACTORY)
34 #define chainup ((TpSimpleClientFactoryClass *) \
35 empathy_client_factory_parent_class)
37 /* FIXME: move to yell */
38 static TpyCallChannel *
39 call_channel_new_with_factory (TpSimpleClientFactory *factory,
41 const gchar *object_path,
42 const GHashTable *immutable_properties,
45 TpProxy *conn_proxy = (TpProxy *) conn;
47 g_return_val_if_fail (TP_IS_CONNECTION (conn), NULL);
48 g_return_val_if_fail (object_path != NULL, NULL);
49 g_return_val_if_fail (immutable_properties != NULL, NULL);
51 if (!tp_dbus_check_valid_object_path (object_path, error))
54 return g_object_new (TPY_TYPE_CALL_CHANNEL,
57 "dbus-daemon", conn_proxy->dbus_daemon,
58 "bus-name", conn_proxy->bus_name,
59 "object-path", object_path,
60 "handle-type", (guint) TP_UNKNOWN_HANDLE_TYPE,
61 "channel-properties", immutable_properties,
66 empathy_client_factory_create_channel (TpSimpleClientFactory *factory,
69 const GHashTable *properties,
72 const gchar *chan_type;
74 chan_type = tp_asv_get_string (properties, TP_PROP_CHANNEL_CHANNEL_TYPE);
76 if (!tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_TEXT))
80 account = tp_connection_get_account (conn);
82 return TP_CHANNEL (empathy_tp_chat_new (
83 TP_SIMPLE_CLIENT_FACTORY (factory), account, conn, path,
86 else if (!tp_strdiff (chan_type, TPY_IFACE_CHANNEL_TYPE_CALL))
88 return TP_CHANNEL (call_channel_new_with_factory (
89 TP_SIMPLE_CLIENT_FACTORY (factory), conn, path, properties, error));
92 return chainup->create_channel (factory, conn, path, properties, error);
96 empathy_client_factory_dup_channel_features (TpSimpleClientFactory *factory,
102 features = chainup->dup_channel_features (factory, channel);
104 if (EMPATHY_IS_TP_CHAT (channel))
106 feature = TP_CHANNEL_FEATURE_CHAT_STATES;
107 g_array_append_val (features, feature);
109 feature = EMPATHY_TP_CHAT_FEATURE_READY;
110 g_array_append_val (features, feature);
117 empathy_client_factory_dup_account_features (TpSimpleClientFactory *factory,
123 features = chainup->dup_account_features (factory, account);
125 feature = TP_ACCOUNT_FEATURE_CONNECTION;
126 g_array_append_val (features, feature);
128 feature = TP_ACCOUNT_FEATURE_ADDRESSING;
129 g_array_append_val (features, feature);
135 empathy_client_factory_dup_connection_features (TpSimpleClientFactory *factory,
136 TpConnection *connection)
141 features = chainup->dup_connection_features (factory, connection);
143 feature = TP_CONNECTION_FEATURE_CAPABILITIES;
144 g_array_append_val (features, feature);
146 feature = TP_CONNECTION_FEATURE_AVATAR_REQUIREMENTS;
147 g_array_append_val (features, feature);
149 feature = TP_CONNECTION_FEATURE_CONTACT_INFO;
150 g_array_append_val (features, feature);
152 feature = TP_CONNECTION_FEATURE_BALANCE;
153 g_array_append_val (features, feature);
155 feature = TP_CONNECTION_FEATURE_CONTACT_BLOCKING;
156 g_array_append_val (features, feature);
158 /* Most empathy-* may allow user to add a contact to his contact list. We
159 * need this property to check if the connection allows it. It's cheap to
160 * prepare anyway as it will just call GetAll() on the ContactList iface. */
161 feature = TP_CONNECTION_FEATURE_CONTACT_LIST_PROPERTIES;
162 g_array_append_val (features, feature);
168 empathy_client_factory_dup_contact_features (TpSimpleClientFactory *factory,
169 TpConnection *connection)
172 TpContactFeature feature;
174 features = chainup->dup_contact_features (factory, connection);
176 /* Needed by empathy_individual_add_menu_item_new to check if a contact is
177 * already in the contact list. This feature is pretty cheap to prepare as
178 * it doesn't prepare the full roster. */
179 feature = TP_CONTACT_FEATURE_SUBSCRIPTION_STATES;
180 g_array_append_val (features, feature);
186 empathy_client_factory_class_init (EmpathyClientFactoryClass *cls)
188 TpSimpleClientFactoryClass *simple_class = (TpSimpleClientFactoryClass *) cls;
190 simple_class->create_channel = empathy_client_factory_create_channel;
191 simple_class->dup_channel_features =
192 empathy_client_factory_dup_channel_features;
194 simple_class->dup_account_features =
195 empathy_client_factory_dup_account_features;
197 simple_class->dup_connection_features =
198 empathy_client_factory_dup_connection_features;
200 simple_class->dup_contact_features =
201 empathy_client_factory_dup_contact_features;
205 empathy_client_factory_init (EmpathyClientFactory *self)
209 static EmpathyClientFactory *
210 empathy_client_factory_new (TpDBusDaemon *dbus)
212 return g_object_new (EMPATHY_TYPE_CLIENT_FACTORY,
217 EmpathyClientFactory *
218 empathy_client_factory_dup (void)
220 static EmpathyClientFactory *singleton = NULL;
222 GError *error = NULL;
224 if (singleton != NULL)
225 return g_object_ref (singleton);
227 dbus = tp_dbus_daemon_dup (&error);
230 g_warning ("Failed to get TpDBusDaemon: %s", error->message);
231 g_error_free (error);
235 singleton = empathy_client_factory_new (dbus);
236 g_object_unref (dbus);
238 g_object_add_weak_pointer (G_OBJECT (singleton), (gpointer) &singleton);