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-tp-file.h"
28 #include "empathy-utils.h"
30 #include <telepathy-yell/telepathy-yell.h>
32 G_DEFINE_TYPE (EmpathyClientFactory, empathy_client_factory,
33 TP_TYPE_AUTOMATIC_CLIENT_FACTORY)
35 #define chainup ((TpSimpleClientFactoryClass *) \
36 empathy_client_factory_parent_class)
38 /* FIXME: move to yell */
39 static TpyCallChannel *
40 call_channel_new_with_factory (TpSimpleClientFactory *factory,
42 const gchar *object_path,
43 const GHashTable *immutable_properties,
46 TpProxy *conn_proxy = (TpProxy *) conn;
48 g_return_val_if_fail (TP_IS_CONNECTION (conn), NULL);
49 g_return_val_if_fail (object_path != NULL, NULL);
50 g_return_val_if_fail (immutable_properties != NULL, NULL);
52 if (!tp_dbus_check_valid_object_path (object_path, error))
55 return g_object_new (TPY_TYPE_CALL_CHANNEL,
58 "dbus-daemon", conn_proxy->dbus_daemon,
59 "bus-name", conn_proxy->bus_name,
60 "object-path", object_path,
61 "handle-type", (guint) TP_UNKNOWN_HANDLE_TYPE,
62 "channel-properties", immutable_properties,
67 empathy_client_factory_create_channel (TpSimpleClientFactory *factory,
70 const GHashTable *properties,
73 const gchar *chan_type;
75 chan_type = tp_asv_get_string (properties, TP_PROP_CHANNEL_CHANNEL_TYPE);
77 if (!tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_TEXT))
81 account = tp_connection_get_account (conn);
83 return TP_CHANNEL (empathy_tp_chat_new (
84 TP_SIMPLE_CLIENT_FACTORY (factory), account, conn, path,
87 else if (!tp_strdiff (chan_type, TPY_IFACE_CHANNEL_TYPE_CALL))
89 return TP_CHANNEL (call_channel_new_with_factory (
90 TP_SIMPLE_CLIENT_FACTORY (factory), conn, path, properties, error));
92 else if (!tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER))
94 return TP_CHANNEL (empathy_tp_file_new (
95 TP_SIMPLE_CLIENT_FACTORY (factory), conn, path, properties, error));
98 return chainup->create_channel (factory, conn, path, properties, error);
102 empathy_client_factory_dup_channel_features (TpSimpleClientFactory *factory,
108 features = chainup->dup_channel_features (factory, channel);
110 if (EMPATHY_IS_TP_CHAT (channel))
112 feature = TP_CHANNEL_FEATURE_CHAT_STATES;
113 g_array_append_val (features, feature);
115 feature = EMPATHY_TP_CHAT_FEATURE_READY;
116 g_array_append_val (features, feature);
123 empathy_client_factory_dup_account_features (TpSimpleClientFactory *factory,
129 features = chainup->dup_account_features (factory, account);
131 feature = TP_ACCOUNT_FEATURE_CONNECTION;
132 g_array_append_val (features, feature);
134 feature = TP_ACCOUNT_FEATURE_ADDRESSING;
135 g_array_append_val (features, feature);
141 empathy_client_factory_dup_connection_features (TpSimpleClientFactory *factory,
142 TpConnection *connection)
147 features = chainup->dup_connection_features (factory, connection);
149 feature = TP_CONNECTION_FEATURE_CAPABILITIES;
150 g_array_append_val (features, feature);
152 feature = TP_CONNECTION_FEATURE_AVATAR_REQUIREMENTS;
153 g_array_append_val (features, feature);
155 feature = TP_CONNECTION_FEATURE_CONTACT_INFO;
156 g_array_append_val (features, feature);
158 feature = TP_CONNECTION_FEATURE_BALANCE;
159 g_array_append_val (features, feature);
161 feature = TP_CONNECTION_FEATURE_CONTACT_BLOCKING;
162 g_array_append_val (features, feature);
164 /* Most empathy-* may allow user to add a contact to his contact list. We
165 * need this property to check if the connection allows it. It's cheap to
166 * prepare anyway as it will just call GetAll() on the ContactList iface. */
167 feature = TP_CONNECTION_FEATURE_CONTACT_LIST_PROPERTIES;
168 g_array_append_val (features, feature);
174 empathy_client_factory_class_init (EmpathyClientFactoryClass *cls)
176 TpSimpleClientFactoryClass *simple_class = (TpSimpleClientFactoryClass *) cls;
178 simple_class->create_channel = empathy_client_factory_create_channel;
179 simple_class->dup_channel_features =
180 empathy_client_factory_dup_channel_features;
182 simple_class->dup_account_features =
183 empathy_client_factory_dup_account_features;
185 simple_class->dup_connection_features =
186 empathy_client_factory_dup_connection_features;
190 empathy_client_factory_init (EmpathyClientFactory *self)
194 static EmpathyClientFactory *
195 empathy_client_factory_new (TpDBusDaemon *dbus)
197 return g_object_new (EMPATHY_TYPE_CLIENT_FACTORY,
202 EmpathyClientFactory *
203 empathy_client_factory_dup (void)
205 static EmpathyClientFactory *singleton = NULL;
207 GError *error = NULL;
209 if (singleton != NULL)
210 return g_object_ref (singleton);
212 dbus = tp_dbus_daemon_dup (&error);
215 g_warning ("Failed to get TpDBusDaemon: %s", error->message);
216 g_error_free (error);
220 singleton = empathy_client_factory_new (dbus);
221 g_object_unref (dbus);
223 g_object_add_weak_pointer (G_OBJECT (singleton), (gpointer) &singleton);