* 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-tp-file.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,
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));
- }
- else if (!tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER))
- {
- return TP_CHANNEL (empathy_tp_file_new (
- TP_SIMPLE_CLIENT_FACTORY (factory), conn, path, properties, error));
- }
return chainup->create_channel (factory, conn, path, properties, error);
}
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;
feature = TP_ACCOUNT_FEATURE_ADDRESSING;
g_array_append_val (features, feature);
+ feature = TP_ACCOUNT_FEATURE_STORAGE;
+ g_array_append_val (features, feature);
+
return features;
}
feature = TP_CONNECTION_FEATURE_BALANCE;
g_array_append_val (features, feature);
+ feature = TP_CONNECTION_FEATURE_CONTACT_BLOCKING;
+ g_array_append_val (features, feature);
+
+ /* Most empathy-* may allow user to add a contact to his contact list. We
+ * need this property to check if the connection allows it. It's cheap to
+ * prepare anyway as it will just call GetAll() on the ContactList iface. */
+ feature = TP_CONNECTION_FEATURE_CONTACT_LIST_PROPERTIES;
+ g_array_append_val (features, feature);
+
+ return features;
+}
+
+static GArray *
+empathy_client_factory_dup_contact_features (TpSimpleClientFactory *factory,
+ TpConnection *connection)
+{
+ GArray *features;
+ TpContactFeature extra_features[] = {
+ TP_CONTACT_FEATURE_ALIAS,
+ TP_CONTACT_FEATURE_PRESENCE,
+ TP_CONTACT_FEATURE_AVATAR_TOKEN,
+ TP_CONTACT_FEATURE_AVATAR_DATA,
+ TP_CONTACT_FEATURE_CAPABILITIES,
+ /* Needed by empathy_individual_add_menu_item_new to check if a contact
+ * 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);
+
+ g_array_append_vals (features, extra_features, G_N_ELEMENTS (extra_features));
+
return features;
}
simple_class->dup_connection_features =
empathy_client_factory_dup_connection_features;
+
+ simple_class->dup_contact_features =
+ empathy_client_factory_dup_contact_features;
}
static 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);
+}