/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
- * Copyright (C) 2007 Collabora Ltd.
+ * Copyright (C) 2007-2008 Collabora Ltd.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
#include <string.h>
#include <telepathy-glib/util.h>
-#include <libtelepathy/tp-conn.h>
-#include <libtelepathy/tp-conn-iface-aliasing-gen.h>
-#include <libtelepathy/tp-conn-iface-presence-gen.h>
-#include <libtelepathy/tp-conn-iface-avatars-gen.h>
-#include <libtelepathy/tp-conn-iface-capabilities-gen.h>
+#include <telepathy-glib/connection.h>
+#include <telepathy-glib/gtypes.h>
#include <libmissioncontrol/mission-control.h>
+#include <extensions/extensions.h>
+
#include "empathy-tp-contact-factory.h"
#include "empathy-utils.h"
-#include "empathy-debug.h"
+#include "empathy-account-manager.h"
-#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
- EMPATHY_TYPE_TP_CONTACT_FACTORY, EmpathyTpContactFactoryPriv))
-
-#define DEBUG_DOMAIN "TpContactFactory"
+#define DEBUG_FLAG EMPATHY_DEBUG_TP | EMPATHY_DEBUG_CONTACT
+#include "empathy-debug.h"
-struct _EmpathyTpContactFactoryPriv {
- MissionControl *mc;
+#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyTpContactFactory)
+typedef struct {
+ EmpathyAccountManager *account_manager;
McAccount *account;
-
- TpConn *tp_conn;
- DBusGProxy *aliasing_iface;
- DBusGProxy *avatars_iface;
- DBusGProxy *presence_iface;
- DBusGProxy *capabilities_iface;
+ TpConnection *connection;
+ gboolean ready;
GList *contacts;
- guint self_handle;
-};
+ EmpathyContact *user;
-static void empathy_tp_contact_factory_class_init (EmpathyTpContactFactoryClass *klass);
-static void empathy_tp_contact_factory_init (EmpathyTpContactFactory *factory);
+ gchar **avatar_mime_types;
+ guint avatar_min_width;
+ guint avatar_min_height;
+ guint avatar_max_width;
+ guint avatar_max_height;
+ guint avatar_max_size;
+ gboolean can_request_ft;
+} EmpathyTpContactFactoryPriv;
G_DEFINE_TYPE (EmpathyTpContactFactory, empathy_tp_contact_factory, G_TYPE_OBJECT);
enum {
PROP_0,
PROP_ACCOUNT,
+ PROP_READY,
+
+ PROP_MIME_TYPES,
+ PROP_MIN_WIDTH,
+ PROP_MIN_HEIGHT,
+ PROP_MAX_WIDTH,
+ PROP_MAX_HEIGHT,
+ PROP_MAX_SIZE
};
static EmpathyContact *
{
EmpathyTpContactFactoryPriv *priv = GET_PRIV (data);
- empathy_debug (DEBUG_DOMAIN, "Remove finalized contact %p",
- where_the_object_was);
+ DEBUG ("Remove finalized contact %p", where_the_object_was);
priv->contacts = g_list_remove (priv->contacts, where_the_object_was);
}
EmpathyContact *contact)
{
const GValue *message;
+ const gchar *message_str = NULL;
empathy_contact_set_presence (contact,
empathy_presence_from_str (state_str));
message = g_hash_table_lookup (presences_table, "message");
- if (message != NULL) {
- empathy_contact_set_presence_message (contact,
- g_value_get_string (message));
+ if (message) {
+ message_str = g_value_get_string (message);
+ }
+
+ if (!EMP_STR_EMPTY (message_str)) {
+ empathy_contact_set_presence_message (contact, message_str);
+ } else {
+ empathy_contact_set_presence_message (contact, NULL);
}
}
(GHFunc) tp_contact_factory_presences_table_foreach,
contact);
- empathy_debug (DEBUG_DOMAIN, "Changing presence for contact %s (%d) to %s (%d)",
- empathy_contact_get_id (contact),
- handle,
- empathy_contact_get_presence_message (contact),
- empathy_contact_get_presence (contact));
+ DEBUG ("Changing presence for contact %s (%d) to '%s' (%d)",
+ empathy_contact_get_id (contact),
+ handle,
+ empathy_contact_get_presence_message (contact),
+ empathy_contact_get_presence (contact));
}
static void
-tp_contact_factory_get_presence_cb (DBusGProxy *proxy,
- GHashTable *handle_table,
- GError *error,
- gpointer user_data)
+tp_contact_factory_get_presence_cb (TpConnection *connection,
+ GHashTable *handle_table,
+ const GError *error,
+ gpointer user_data,
+ GObject *tp_factory)
{
- EmpathyTpContactFactory *tp_factory = user_data;
-
if (error) {
- empathy_debug (DEBUG_DOMAIN, "Error getting presence: %s",
- error->message);
- goto OUT;
+ DEBUG ("Error getting presence: %s", error->message);
+ if (error->domain == TP_DBUS_ERRORS &&
+ error->code == TP_DBUS_ERROR_NO_INTERFACE) {
+ guint *handles = user_data;
+
+ /* We have no presence iface, set default presence
+ * to available */
+ while (*handles != 0) {
+ EmpathyContact *contact;
+
+ contact = tp_contact_factory_find_by_handle (
+ (EmpathyTpContactFactory*) tp_factory,
+ *handles);
+ if (contact) {
+ empathy_contact_set_presence (contact,
+ MC_PRESENCE_AVAILABLE);
+ }
+
+ handles++;
+ }
+ }
+
+ return;
}
g_hash_table_foreach (handle_table,
(GHFunc) tp_contact_factory_parse_presence_foreach,
- tp_factory);
-
- g_hash_table_destroy (handle_table);
-OUT:
- g_object_unref (tp_factory);
+ EMPATHY_TP_CONTACT_FACTORY (tp_factory));
}
static void
-tp_contact_factory_presence_update_cb (DBusGProxy *proxy,
- GHashTable *handle_table,
- EmpathyTpContactFactory *tp_factory)
+tp_contact_factory_presence_update_cb (TpConnection *connection,
+ GHashTable *handle_table,
+ gpointer user_data,
+ GObject *tp_factory)
{
g_hash_table_foreach (handle_table,
(GHFunc) tp_contact_factory_parse_presence_foreach,
- tp_factory);
+ EMPATHY_TP_CONTACT_FACTORY (tp_factory));
}
static void
-tp_contact_factory_set_aliases_cb (DBusGProxy *proxy,
- GError *error,
- gpointer user_data)
+tp_contact_factory_set_aliases_cb (TpConnection *connection,
+ const GError *error,
+ gpointer user_data,
+ GObject *tp_factory)
{
- EmpathyTpContactFactory *tp_factory = user_data;
-
if (error) {
- empathy_debug (DEBUG_DOMAIN, "Error setting alias: %s",
- error->message);
+ DEBUG ("Error setting alias: %s", error->message);
}
-
- g_object_unref (tp_factory);
}
-typedef struct {
- EmpathyTpContactFactory *tp_factory;
- guint *handles;
-} RequestAliasesData;
-
static void
-tp_contact_factory_request_aliases_cb (DBusGProxy *proxy,
- gchar **contact_names,
- GError *error,
- gpointer user_data)
+tp_contact_factory_request_aliases_cb (TpConnection *connection,
+ const gchar **contact_names,
+ const GError *error,
+ gpointer user_data,
+ GObject *tp_factory)
{
- RequestAliasesData *data = user_data;
- guint i = 0;
- gchar **name;
+ guint *handles = user_data;
+ guint i = 0;
+ const gchar **name;
if (error) {
- empathy_debug (DEBUG_DOMAIN, "Error requesting aliases: %s",
- error->message);
- goto OUT;
+ DEBUG ("Error requesting aliases: %s", error->message);
+
+ /* If we failed to get alias set it to NULL, like that if
+ * someone is waiting for the name to be ready it won't wait
+ * infinitely */
+ while (*handles != 0) {
+ EmpathyContact *contact;
+
+ contact = tp_contact_factory_find_by_handle (
+ (EmpathyTpContactFactory*) tp_factory,
+ *handles);
+ if (contact) {
+ empathy_contact_set_name (contact, NULL);
+ }
+
+ handles++;
+ }
+ return;
}
for (name = contact_names; *name; name++) {
EmpathyContact *contact;
- contact = tp_contact_factory_find_by_handle (data->tp_factory,
- data->handles[i]);
+ contact = tp_contact_factory_find_by_handle (EMPATHY_TP_CONTACT_FACTORY (tp_factory),
+ handles[i]);
if (!contact) {
continue;
}
- empathy_debug (DEBUG_DOMAIN, "Renaming contact %s (%d) to %s (request cb)",
- empathy_contact_get_id (contact),
- data->handles[i], *name);
+ DEBUG ("Renaming contact %s (%d) to %s (request cb)",
+ empathy_contact_get_id (contact),
+ empathy_contact_get_handle (contact),
+ *name);
empathy_contact_set_name (contact, *name);
i++;
}
-
- g_strfreev (contact_names);
-OUT:
- g_object_unref (data->tp_factory);
- g_free (data->handles);
- g_slice_free (RequestAliasesData, data);
}
static void
-tp_contact_factory_aliases_changed_cb (DBusGProxy *proxy,
- GPtrArray *renamed_handlers,
- gpointer user_data)
+tp_contact_factory_aliases_changed_cb (TpConnection *connection,
+ const GPtrArray *renamed_handlers,
+ gpointer user_data,
+ GObject *weak_object)
{
- EmpathyTpContactFactory *tp_factory = user_data;
+ EmpathyTpContactFactory *tp_factory = EMPATHY_TP_CONTACT_FACTORY (weak_object);
guint i;
for (i = 0; renamed_handlers->len > i; i++) {
EmpathyContact *contact;
renamed_struct = g_ptr_array_index (renamed_handlers, i);
- handle = g_value_get_uint(g_value_array_get_nth (renamed_struct, 0));
- alias = g_value_get_string(g_value_array_get_nth (renamed_struct, 1));
+ handle = g_value_get_uint (g_value_array_get_nth (renamed_struct, 0));
+ alias = g_value_get_string (g_value_array_get_nth (renamed_struct, 1));
contact = tp_contact_factory_find_by_handle (tp_factory, handle);
if (!contact) {
continue;
}
- if (G_STR_EMPTY (alias)) {
- alias = NULL;
- }
-
- empathy_debug (DEBUG_DOMAIN, "Renaming contact %s (%d) to %s (changed cb)",
- empathy_contact_get_id (contact),
- handle, alias);
+ DEBUG ("Renaming contact %s (%d) to %s (changed cb)",
+ empathy_contact_get_id (contact),
+ handle, alias);
empathy_contact_set_name (contact, alias);
}
}
static void
-tp_contact_factory_set_avatar_cb (DBusGProxy *proxy,
- gchar *token,
- GError *error,
- gpointer user_data)
+tp_contact_factory_set_avatar_cb (TpConnection *connection,
+ const gchar *token,
+ const GError *error,
+ gpointer user_data,
+ GObject *tp_factory)
{
- EmpathyTpContactFactory *tp_factory = user_data;
-
if (error) {
- empathy_debug (DEBUG_DOMAIN, "Error setting avatar: %s",
- error->message);
+ DEBUG ("Error setting avatar: %s", error->message);
}
-
- g_object_unref (tp_factory);
- g_free (token);
}
static void
-tp_contact_factory_clear_avatar_cb (DBusGProxy *proxy,
- GError *error,
- gpointer user_data)
+tp_contact_factory_clear_avatar_cb (TpConnection *connection,
+ const GError *error,
+ gpointer user_data,
+ GObject *tp_factory)
{
- EmpathyTpContactFactory *tp_factory = user_data;
-
if (error) {
- empathy_debug (DEBUG_DOMAIN, "Error clearing avatar: %s",
- error->message);
+ DEBUG ("Error clearing avatar: %s", error->message);
}
-
- g_object_unref (tp_factory);
}
static void
-tp_contact_factory_avatar_retrieved_cb (DBusGProxy *proxy,
- guint handle,
- gchar *token,
- GArray *avatar_data,
- gchar *mime_type,
- gpointer user_data)
+tp_contact_factory_avatar_retrieved_cb (TpConnection *connection,
+ guint handle,
+ const gchar *token,
+ const GArray *avatar_data,
+ const gchar *mime_type,
+ gpointer user_data,
+ GObject *tp_factory)
{
- EmpathyTpContactFactory *tp_factory = user_data;
- EmpathyContact *contact;
- EmpathyAvatar *avatar;
+ EmpathyContact *contact;
- contact = tp_contact_factory_find_by_handle (tp_factory, handle);
+ contact = tp_contact_factory_find_by_handle (EMPATHY_TP_CONTACT_FACTORY (tp_factory),
+ handle);
if (!contact) {
return;
}
- empathy_debug (DEBUG_DOMAIN, "Avatar retrieved for contact %s (%d)",
- empathy_contact_get_id (contact),
- handle);
+ DEBUG ("Avatar retrieved for contact %s (%d)",
+ empathy_contact_get_id (contact),
+ handle);
- avatar = empathy_avatar_new (avatar_data->data,
- avatar_data->len,
- mime_type,
- token);
-
- empathy_contact_set_avatar (contact, avatar);
- empathy_avatar_unref (avatar);
+ empathy_contact_load_avatar_data (contact,
+ avatar_data->data,
+ avatar_data->len,
+ mime_type,
+ token);
}
static void
-tp_contact_factory_request_avatars_cb (DBusGProxy *proxy,
- GError *error,
- gpointer user_data)
+tp_contact_factory_request_avatars_cb (TpConnection *connection,
+ const GError *error,
+ gpointer user_data,
+ GObject *tp_factory)
{
- EmpathyTpContactFactory *tp_factory = user_data;
-
if (error) {
- empathy_debug (DEBUG_DOMAIN, "Error requesting avatars: %s",
- error->message);
+ DEBUG ("Error requesting avatars: %s", error->message);
}
-
- g_object_unref (tp_factory);
}
static gboolean
}
/* Check if we have an avatar */
- if (G_STR_EMPTY (token)) {
+ if (EMP_STR_EMPTY (token)) {
empathy_contact_set_avatar (contact, NULL);
return TRUE;
}
}
/* The avatar changed, search the new one in the cache */
- avatar = empathy_avatar_new_from_cache (token);
- if (avatar) {
+ if (empathy_contact_load_avatar_cache (contact, token)) {
/* Got from cache, use it */
- empathy_contact_set_avatar (contact, avatar);
- empathy_avatar_unref (avatar);
return TRUE;
}
}
static void
-tp_contact_factory_get_known_avatar_tokens_cb (DBusGProxy *proxy,
- GHashTable *tokens,
- GError *error,
- gpointer user_data)
+tp_contact_factory_get_known_avatar_tokens_cb (TpConnection *connection,
+ GHashTable *tokens,
+ const GError *error,
+ gpointer user_data,
+ GObject *tp_factory)
{
- EmpathyTpContactFactory *tp_factory = user_data;
- EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
- TokensData data;
+ TokensData data;
if (error) {
- empathy_debug (DEBUG_DOMAIN,
- "Error getting known avatars tokens: %s",
- error->message);
- goto OUT;
+ DEBUG ("Error getting known avatars tokens: %s", error->message);
+ return;
}
- data.tp_factory = tp_factory;
+ data.tp_factory = EMPATHY_TP_CONTACT_FACTORY (tp_factory);
data.handles = g_array_new (FALSE, FALSE, sizeof (guint));
g_hash_table_foreach (tokens,
tp_contact_factory_avatar_tokens_foreach,
&data);
- empathy_debug (DEBUG_DOMAIN, "Got %d tokens, need to request %d avatars",
- g_hash_table_size (tokens),
- data.handles->len);
+ DEBUG ("Got %d tokens, need to request %d avatars",
+ g_hash_table_size (tokens), data.handles->len);
/* Request needed avatars */
if (data.handles->len > 0) {
- tp_conn_iface_avatars_request_avatars_async (priv->avatars_iface,
- data.handles,
- tp_contact_factory_request_avatars_cb,
- g_object_ref (tp_factory));
+ tp_cli_connection_interface_avatars_call_request_avatars (connection,
+ -1,
+ data.handles,
+ tp_contact_factory_request_avatars_cb,
+ NULL, NULL,
+ tp_factory);
}
- g_hash_table_destroy (tokens);
g_array_free (data.handles, TRUE);
-OUT:
- g_object_unref (tp_factory);
}
static void
-tp_contact_factory_avatar_updated_cb (DBusGProxy *proxy,
- guint handle,
- gchar *new_token,
- gpointer user_data)
+tp_contact_factory_avatar_updated_cb (TpConnection *connection,
+ guint handle,
+ const gchar *new_token,
+ gpointer user_data,
+ GObject *tp_factory)
{
- EmpathyTpContactFactory *tp_factory = user_data;
- EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
- GArray *handles;
+ GArray *handles;
- if (tp_contact_factory_avatar_maybe_update (tp_factory, handle, new_token)) {
+ if (tp_contact_factory_avatar_maybe_update (EMPATHY_TP_CONTACT_FACTORY (tp_factory),
+ handle, new_token)) {
/* Avatar was cached, nothing to do */
return;
}
- empathy_debug (DEBUG_DOMAIN, "Need to request avatar for token %s",
- new_token);
+ DEBUG ("Need to request avatar for token %s", new_token);
handles = g_array_new (FALSE, FALSE, sizeof (guint));
g_array_append_val (handles, handle);
- tp_conn_iface_avatars_request_avatars_async (priv->avatars_iface,
- handles,
- tp_contact_factory_request_avatars_cb,
- g_object_ref (tp_factory));
+ tp_cli_connection_interface_avatars_call_request_avatars (connection,
+ -1,
+ handles,
+ tp_contact_factory_request_avatars_cb,
+ NULL, NULL,
+ tp_factory);
g_array_free (handles, TRUE);
}
}
capabilities = empathy_contact_get_capabilities (contact);
+ capabilities &= ~EMPATHY_CAPABILITIES_UNKNOWN;
if (strcmp (channel_type, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA) == 0) {
capabilities &= ~EMPATHY_CAPABILITIES_AUDIO;
}
}
- empathy_debug (DEBUG_DOMAIN, "Changing capabilities for contact %s (%d) to %d",
- empathy_contact_get_id (contact),
- empathy_contact_get_handle (contact),
- capabilities);
+ DEBUG ("Changing capabilities for contact %s (%d) to %d",
+ empathy_contact_get_id (contact),
+ empathy_contact_get_handle (contact),
+ capabilities);
empathy_contact_set_capabilities (contact, capabilities);
}
static void
-tp_contact_factory_get_capabilities_cb (DBusGProxy *proxy,
- GPtrArray *capabilities,
- GError *error,
- gpointer user_data)
+tp_contact_factory_get_capabilities_cb (TpConnection *connection,
+ const GPtrArray *capabilities,
+ const GError *error,
+ gpointer user_data,
+ GObject *weak_object)
{
- EmpathyTpContactFactory *tp_factory = user_data;
+ EmpathyTpContactFactory *tp_factory = EMPATHY_TP_CONTACT_FACTORY (weak_object);
guint i;
if (error) {
- empathy_debug (DEBUG_DOMAIN, "Error getting capabilities: %s",
- error->message);
- goto OUT;
+ DEBUG ("Error getting capabilities: %s", error->message);
+ /* FIXME Should set the capabilities of the contacts for which this request
+ * originated to NONE */
+ return;
}
for (i = 0; i < capabilities->len; i++) {
channel_type,
generic,
specific);
-
- g_value_array_free (values);
}
-
- g_ptr_array_free (capabilities, TRUE);
-OUT:
- g_object_unref (tp_factory);
}
static void
-tp_contact_factory_capabilities_changed_cb (DBusGProxy *proxy,
- GPtrArray *capabilities,
- gpointer user_data)
+tp_contact_factory_capabilities_changed_cb (TpConnection *connection,
+ const GPtrArray *capabilities,
+ gpointer user_data,
+ GObject *weak_object)
{
- EmpathyTpContactFactory *tp_factory = user_data;
+ EmpathyTpContactFactory *tp_factory = EMPATHY_TP_CONTACT_FACTORY (weak_object);
guint i;
for (i = 0; i < capabilities->len; i++) {
static void
tp_contact_factory_request_everything (EmpathyTpContactFactory *tp_factory,
- GArray *handles)
+ const GArray *handles)
{
EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
-
- if (priv->presence_iface) {
- tp_conn_iface_presence_get_presence_async (priv->presence_iface,
- handles,
- tp_contact_factory_get_presence_cb,
- g_object_ref (tp_factory));
- }
-
- if (priv->aliasing_iface) {
- RequestAliasesData *data;
-
- data = g_slice_new (RequestAliasesData);
- data->tp_factory = g_object_ref (tp_factory);
- data->handles = g_memdup (handles->data, handles->len * sizeof (guint));
-
- tp_conn_iface_aliasing_request_aliases_async (priv->aliasing_iface,
- handles,
- tp_contact_factory_request_aliases_cb,
- data);
- }
-
- if (priv->avatars_iface) {
- tp_conn_iface_avatars_get_known_avatar_tokens_async (priv->avatars_iface,
- handles,
- tp_contact_factory_get_known_avatar_tokens_cb,
- g_object_ref (tp_factory));
- }
-
- if (priv->capabilities_iface) {
- tp_conn_iface_capabilities_get_capabilities_async (priv->capabilities_iface,
+ guint *dup_handles;
+
+ g_return_if_fail (priv->ready);
+
+ dup_handles = g_malloc0 ((handles->len + 1) * sizeof (guint));
+ g_memmove (dup_handles, handles->data, handles->len * sizeof (guint));
+ tp_cli_connection_interface_presence_call_get_presence (priv->connection,
+ -1,
+ handles,
+ tp_contact_factory_get_presence_cb,
+ dup_handles, g_free,
+ G_OBJECT (tp_factory));
+
+ /* FIXME: Sometimes the dbus call timesout because CM takes
+ * too much time to request all aliases from the server,
+ * that's why we increase the timeout here. See fd.o bug #14795 */
+ dup_handles = g_malloc0 ((handles->len + 1) * sizeof (guint));
+ g_memmove (dup_handles, handles->data, handles->len * sizeof (guint));
+ tp_cli_connection_interface_aliasing_call_request_aliases (priv->connection,
+ 5*60*1000,
handles,
- tp_contact_factory_get_capabilities_cb,
- g_object_ref (tp_factory));
- }
+ tp_contact_factory_request_aliases_cb,
+ dup_handles, g_free,
+ G_OBJECT (tp_factory));
+
+ tp_cli_connection_interface_avatars_call_get_known_avatar_tokens (priv->connection,
+ -1,
+ handles,
+ tp_contact_factory_get_known_avatar_tokens_cb,
+ NULL, NULL,
+ G_OBJECT (tp_factory));
+
+ tp_cli_connection_interface_capabilities_call_get_capabilities (priv->connection,
+ -1,
+ handles,
+ tp_contact_factory_get_capabilities_cb,
+ NULL, NULL,
+ G_OBJECT (tp_factory));
}
-typedef struct {
- EmpathyTpContactFactory *tp_factory;
- GList *contacts;
-} RequestHandlesData;
+static void
+tp_contact_factory_list_free (gpointer data)
+{
+ GList *l = data;
+
+ g_list_foreach (l, (GFunc) g_object_unref, NULL);
+ g_list_free (l);
+}
static void
-tp_contact_factory_request_handles_cb (DBusGProxy *proxy,
- GArray *handles,
- GError *error,
- gpointer user_data)
+tp_contact_factory_request_handles_cb (TpConnection *connection,
+ const GArray *handles,
+ const GError *error,
+ gpointer user_data,
+ GObject *tp_factory)
{
- RequestHandlesData *data = user_data;
- EmpathyTpContactFactory *tp_factory = data->tp_factory;
- EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
- GList *l;
- guint i = 0;
+ GList *contacts = user_data;
+ GList *l;
+ guint i = 0;
if (error) {
- empathy_debug (DEBUG_DOMAIN, "Failed to request handles: %s",
- error->message);
- goto OUT;
+ DEBUG ("Failed to request handles: %s", error->message);
+ return;
}
- for (l = data->contacts; l; l = l->next) {
+ for (l = contacts; l; l = l->next) {
guint handle;
handle = g_array_index (handles, guint, i);
empathy_contact_set_handle (l->data, handle);
- if (handle == priv->self_handle) {
- empathy_contact_set_is_user (l->data, TRUE);
- }
i++;
}
- tp_contact_factory_request_everything (tp_factory, handles);
- g_array_free (handles, TRUE);
+ tp_contact_factory_request_everything (EMPATHY_TP_CONTACT_FACTORY (tp_factory),
+ handles);
+}
+
+static void
+tp_contact_factory_inspect_handles_cb (TpConnection *connection,
+ const gchar **ids,
+ const GError *error,
+ gpointer user_data,
+ GObject *tp_factory)
+{
+ const gchar **id;
+ GList *contacts = user_data;
+ GList *l;
+
+ if (error) {
+ DEBUG ("Failed to inspect handles: %s", error->message);
+ return;
+ }
-OUT:
- g_list_foreach (data->contacts, (GFunc) g_object_unref, NULL);
- g_list_free (data->contacts);
- g_object_unref (tp_factory);
- g_slice_free (RequestHandlesData, data);
+ id = ids;
+ for (l = contacts; l; l = l->next) {
+ empathy_contact_set_id (l->data, *id);
+ id++;
+ }
}
static void
}
static void
-tp_contact_factory_destroy_cb (TpConn *tp_conn,
- EmpathyTpContactFactory *tp_factory)
+tp_contact_factory_connection_invalidated_cb (EmpathyTpContactFactory *tp_factory)
{
EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
- empathy_debug (DEBUG_DOMAIN, "Account disconnected or CM crashed");
+ DEBUG ("Connection invalidated");
+
+ g_object_unref (priv->connection);
+ priv->connection = NULL;
+ priv->ready = FALSE;
+ g_object_notify (G_OBJECT (tp_factory), "ready");
- g_object_unref (priv->tp_conn);
- priv->tp_conn = NULL;
- priv->aliasing_iface = NULL;
- priv->avatars_iface = NULL;
- priv->presence_iface = NULL;
- priv->capabilities_iface = NULL;
g_list_foreach (priv->contacts,
tp_contact_factory_disconnect_contact_foreach,
}
static void
-tp_contact_factory_disconnect (EmpathyTpContactFactory *tp_factory)
+tp_contact_factory_ready (EmpathyTpContactFactory *tp_factory)
{
EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
+ GList *l;
+ GArray *handle_needed;
+ GArray *id_needed;
+ GList *handle_needed_contacts = NULL;
+ GList *id_needed_contacts = NULL;
- if (priv->aliasing_iface) {
- dbus_g_proxy_disconnect_signal (priv->aliasing_iface,
- "AliasesChanged",
- G_CALLBACK (tp_contact_factory_aliases_changed_cb),
- tp_factory);
- }
- if (priv->avatars_iface) {
- dbus_g_proxy_disconnect_signal (priv->avatars_iface,
- "AvatarUpdated",
- G_CALLBACK (tp_contact_factory_avatar_updated_cb),
- tp_factory);
- dbus_g_proxy_disconnect_signal (priv->avatars_iface,
- "AvatarRetrieved",
- G_CALLBACK (tp_contact_factory_avatar_retrieved_cb),
- tp_factory);
- }
- if (priv->presence_iface) {
- dbus_g_proxy_disconnect_signal (priv->presence_iface,
- "PresenceUpdate",
- G_CALLBACK (tp_contact_factory_presence_update_cb),
- tp_factory);
- }
- if (priv->capabilities_iface) {
- dbus_g_proxy_disconnect_signal (priv->capabilities_iface,
- "CapabilitiesChanged",
- G_CALLBACK (tp_contact_factory_capabilities_changed_cb),
- tp_factory);
- }
- if (priv->tp_conn) {
- g_signal_handlers_disconnect_by_func (priv->tp_conn,
- tp_contact_factory_destroy_cb,
- tp_factory);
+ DEBUG ("Connection ready");
+
+ priv->ready = TRUE;
+ g_object_notify (G_OBJECT (tp_factory), "ready");
+
+ /* Connect signals */
+ tp_cli_connection_interface_aliasing_connect_to_aliases_changed (priv->connection,
+ tp_contact_factory_aliases_changed_cb,
+ NULL, NULL,
+ G_OBJECT (tp_factory),
+ NULL);
+ tp_cli_connection_interface_avatars_connect_to_avatar_updated (priv->connection,
+ tp_contact_factory_avatar_updated_cb,
+ NULL, NULL,
+ G_OBJECT (tp_factory),
+ NULL);
+ tp_cli_connection_interface_avatars_connect_to_avatar_retrieved (priv->connection,
+ tp_contact_factory_avatar_retrieved_cb,
+ NULL, NULL,
+ G_OBJECT (tp_factory),
+ NULL);
+ tp_cli_connection_interface_presence_connect_to_presence_update (priv->connection,
+ tp_contact_factory_presence_update_cb,
+ NULL, NULL,
+ G_OBJECT (tp_factory),
+ NULL);
+ tp_cli_connection_interface_capabilities_connect_to_capabilities_changed (priv->connection,
+ tp_contact_factory_capabilities_changed_cb,
+ NULL, NULL,
+ G_OBJECT (tp_factory),
+ NULL);
+
+ /* Request needed info for all existing contacts */
+ handle_needed = g_array_new (TRUE, FALSE, sizeof (gchar*));
+ id_needed = g_array_new (FALSE, FALSE, sizeof (guint));
+ for (l = priv->contacts; l; l = l->next) {
+ EmpathyContact *contact;
+ guint handle;
+ const gchar *id;
+
+ contact = l->data;
+ handle = empathy_contact_get_handle (contact);
+ id = empathy_contact_get_id (contact);
+ if (handle == 0) {
+ g_assert (!EMP_STR_EMPTY (id));
+ g_array_append_val (handle_needed, id);
+ handle_needed_contacts = g_list_prepend (handle_needed_contacts,
+ g_object_ref (contact));
+ }
+ if (EMP_STR_EMPTY (id)) {
+ g_array_append_val (id_needed, handle);
+ id_needed_contacts = g_list_prepend (id_needed_contacts,
+ g_object_ref (contact));
+ }
}
+ handle_needed_contacts = g_list_reverse (handle_needed_contacts);
+ id_needed_contacts = g_list_reverse (id_needed_contacts);
+
+ tp_cli_connection_call_request_handles (priv->connection,
+ -1,
+ TP_HANDLE_TYPE_CONTACT,
+ (const gchar**) handle_needed->data,
+ tp_contact_factory_request_handles_cb,
+ handle_needed_contacts, tp_contact_factory_list_free,
+ G_OBJECT (tp_factory));
+
+ tp_cli_connection_call_inspect_handles (priv->connection,
+ -1,
+ TP_HANDLE_TYPE_CONTACT,
+ id_needed,
+ tp_contact_factory_inspect_handles_cb,
+ id_needed_contacts, tp_contact_factory_list_free,
+ G_OBJECT (tp_factory));
+
+ tp_contact_factory_request_everything ((EmpathyTpContactFactory*) tp_factory,
+ id_needed);
+
+ g_array_free (handle_needed, TRUE);
+ g_array_free (id_needed, TRUE);
}
static void
-tp_contact_factory_update (EmpathyTpContactFactory *tp_factory)
+get_requestable_channel_classes_cb (TpProxy *connection,
+ const GValue *value,
+ const GError *error,
+ gpointer user_data,
+ GObject *weak_object)
{
- EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
- TpConn *tp_conn = NULL;
- RequestHandlesData *data;
- const gchar **contact_ids;
+ EmpathyTpContactFactory *self = EMPATHY_TP_CONTACT_FACTORY (weak_object);
+ EmpathyTpContactFactoryPriv *priv = GET_PRIV (self);
+ GPtrArray *classes;
guint i;
- GList *l;
- GError *error = NULL;
-
- if (priv->account) {
- guint status;
-
- /* status == 0 means the status is CONNECTED */
- status = mission_control_get_connection_status (priv->mc,
- priv->account,
- NULL);
- if (status == 0) {
- tp_conn = mission_control_get_connection (priv->mc,
- priv->account,
- NULL);
- }
- }
- if (!tp_conn) {
- /* We are not connected anymore, remove the old connection */
- tp_contact_factory_disconnect (tp_factory);
- if (priv->tp_conn) {
- tp_contact_factory_destroy_cb (priv->tp_conn, tp_factory);
- }
- return;
- }
- else if (priv->tp_conn) {
- /* We were connected and we still are connected, nothing
- * changed so nothing to do. */
- g_object_unref (tp_conn);
+ if (error != NULL) {
+ DEBUG ("Error: %s", error->message);
+ tp_contact_factory_ready (self);
return;
}
- /* We got a new connection */
- priv->tp_conn = tp_conn;
- priv->aliasing_iface = tp_conn_get_interface (priv->tp_conn,
- TP_IFACE_QUARK_CONNECTION_INTERFACE_ALIASING);
- priv->avatars_iface = tp_conn_get_interface (priv->tp_conn,
- TP_IFACE_QUARK_CONNECTION_INTERFACE_AVATARS);
- priv->presence_iface = tp_conn_get_interface (priv->tp_conn,
- TP_IFACE_QUARK_CONNECTION_INTERFACE_PRESENCE);
- priv->capabilities_iface = tp_conn_get_interface (priv->tp_conn,
- TP_IFACE_QUARK_CONNECTION_INTERFACE_CAPABILITIES);
+ classes = g_value_get_boxed (value);
+ for (i = 0; i < classes->len; i++) {
+ GValue class = {0,};
+ GValue *chan_type, *handle_type;
+ GHashTable *fixed_prop;
+ GList *l;
+
+ g_value_init (&class, TP_STRUCT_TYPE_REQUESTABLE_CHANNEL_CLASS);
+ g_value_set_static_boxed (&class, g_ptr_array_index (classes, i));
+
+ dbus_g_type_struct_get (&class,
+ 0, &fixed_prop,
+ G_MAXUINT);
+
+ chan_type = g_hash_table_lookup (fixed_prop,
+ TP_IFACE_CHANNEL ".ChannelType");
+ if (chan_type == NULL ||
+ tp_strdiff (g_value_get_string (chan_type),
+ TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER)) {
+ continue;
+ }
- /* Connect signals */
- if (priv->aliasing_iface) {
- dbus_g_proxy_connect_signal (priv->aliasing_iface,
- "AliasesChanged",
- G_CALLBACK (tp_contact_factory_aliases_changed_cb),
- tp_factory, NULL);
- }
- if (priv->avatars_iface) {
- dbus_g_proxy_connect_signal (priv->avatars_iface,
- "AvatarUpdated",
- G_CALLBACK (tp_contact_factory_avatar_updated_cb),
- tp_factory, NULL);
- dbus_g_proxy_connect_signal (priv->avatars_iface,
- "AvatarRetrieved",
- G_CALLBACK (tp_contact_factory_avatar_retrieved_cb),
- tp_factory, NULL);
+ handle_type = g_hash_table_lookup (fixed_prop,
+ TP_IFACE_CHANNEL ".TargetHandleType");
+ if (handle_type == NULL ||
+ g_value_get_uint (handle_type) != TP_HANDLE_TYPE_CONTACT) {
+ continue;
+ }
+
+ /* We can request file transfer channel to contacts. */
+ priv->can_request_ft = TRUE;
+
+ /* Update the capabilities of all contacts */
+ for (l = priv->contacts; l != NULL; l = g_list_next (l)) {
+ EmpathyContact *contact = l->data;
+ EmpathyCapabilities caps;
+
+ caps = empathy_contact_get_capabilities (contact);
+ empathy_contact_set_capabilities (contact, caps |
+ EMPATHY_CAPABILITIES_FT);
+ }
+ break;
}
- if (priv->presence_iface) {
- dbus_g_proxy_connect_signal (priv->presence_iface,
- "PresenceUpdate",
- G_CALLBACK (tp_contact_factory_presence_update_cb),
- tp_factory, NULL);
+
+ tp_contact_factory_ready (self);
+}
+
+static void
+tp_contact_factory_got_avatar_requirements_cb (TpConnection *proxy,
+ const gchar **mime_types,
+ guint min_width,
+ guint min_height,
+ guint max_width,
+ guint max_height,
+ guint max_size,
+ const GError *error,
+ gpointer user_data,
+ GObject *tp_factory)
+{
+ EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
+
+ if (error) {
+ DEBUG ("Failed to get avatar requirements: %s", error->message);
+ /* We'll just leave avatar_mime_types as NULL; the
+ * avatar-setting code can use this as a signal that you can't
+ * set avatars.
+ */
+ } else {
+ priv->avatar_mime_types = g_strdupv ((gchar **) mime_types);
+ priv->avatar_min_width = min_width;
+ priv->avatar_min_height = min_height;
+ priv->avatar_max_width = max_width;
+ priv->avatar_max_height = max_height;
+ priv->avatar_max_size = max_size;
}
- if (priv->capabilities_iface) {
- dbus_g_proxy_connect_signal (priv->capabilities_iface,
- "CapabilitiesChanged",
- G_CALLBACK (tp_contact_factory_capabilities_changed_cb),
- tp_factory, NULL);
+
+ /* Can we request file transfer channels? */
+ tp_cli_dbus_properties_call_get (priv->connection, -1,
+ TP_IFACE_CONNECTION_INTERFACE_REQUESTS,
+ "RequestableChannelClasses",
+ get_requestable_channel_classes_cb, NULL, NULL,
+ G_OBJECT (tp_factory));
+}
+
+static void
+tp_contact_factory_got_self_handle_cb (TpConnection *proxy,
+ guint handle,
+ const GError *error,
+ gpointer user_data,
+ GObject *tp_factory)
+{
+ EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
+
+ if (error) {
+ DEBUG ("Failed to get self handles: %s", error->message);
+ return;
}
- g_signal_connect (priv->tp_conn, "destroy",
- G_CALLBACK (tp_contact_factory_destroy_cb),
- tp_factory);
+
+ empathy_contact_set_handle (priv->user, handle);
+
+ /* Get avatar requirements for this connection */
+ tp_cli_connection_interface_avatars_call_get_avatar_requirements (
+ priv->connection,
+ -1,
+ tp_contact_factory_got_avatar_requirements_cb,
+ NULL, NULL,
+ tp_factory);
+}
+
+static void
+tp_contact_factory_connection_ready_cb (EmpathyTpContactFactory *tp_factory)
+{
+ EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
/* Get our own handle */
- if (!tp_conn_get_self_handle (DBUS_G_PROXY (priv->tp_conn),
- &priv->self_handle,
- &error)) {
- empathy_debug (DEBUG_DOMAIN, "GetSelfHandle Error: %s",
- error ? error->message : "No error given");
- g_clear_error (&error);
+ tp_cli_connection_call_get_self_handle (priv->connection,
+ -1,
+ tp_contact_factory_got_self_handle_cb,
+ NULL, NULL,
+ G_OBJECT (tp_factory));
+}
+
+static void
+tp_contact_factory_status_updated (EmpathyTpContactFactory *tp_factory)
+{
+ EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
+ gboolean connection_ready;
+ MissionControl *mc;
+
+ if (priv->connection) {
+ /* We already have our connection object */
+ return;
}
- /* Request new handles for all contacts */
- if (priv->contacts) {
- data = g_slice_new (RequestHandlesData);
- data->tp_factory = g_object_ref (tp_factory);
- data->contacts = g_list_copy (priv->contacts);
- g_list_foreach (data->contacts, (GFunc) g_object_ref, NULL);
-
- i = g_list_length (data->contacts);
- contact_ids = g_new0 (const gchar*, i + 1);
- i = 0;
- for (l = data->contacts; l; l = l->next) {
- contact_ids[i] = empathy_contact_get_id (l->data);
- i++;
- }
+ mc = empathy_mission_control_dup_singleton ();
+ priv->connection = mission_control_get_tpconnection (mc, priv->account, NULL);
+ if (!priv->connection) {
+ return;
+ }
+
+ /* We got a new connection, wait for it to be ready */
+ g_signal_connect_swapped (priv->connection, "invalidated",
+ G_CALLBACK (tp_contact_factory_connection_invalidated_cb),
+ tp_factory);
- tp_conn_request_handles_async (DBUS_G_PROXY (priv->tp_conn),
- TP_HANDLE_TYPE_CONTACT,
- contact_ids,
- tp_contact_factory_request_handles_cb,
- data);
- g_free (contact_ids);
+ g_object_get (priv->connection, "connection-ready", &connection_ready, NULL);
+ if (connection_ready) {
+ tp_contact_factory_connection_ready_cb (tp_factory);
+ } else {
+ g_signal_connect_swapped (priv->connection, "notify::connection-ready",
+ G_CALLBACK (tp_contact_factory_connection_ready_cb),
+ tp_factory);
}
+
+ g_object_unref (mc);
}
static void
-tp_contact_factory_status_changed_cb (MissionControl *mc,
- TpConnectionStatus status,
- McPresence presence,
- TpConnectionStatusReason reason,
- const gchar *unique_name,
- EmpathyTpContactFactory *tp_factory)
+tp_contact_factory_account_connection_cb (EmpathyAccountManager *account_manager,
+ McAccount *account,
+ TpConnectionStatusReason reason,
+ TpConnectionStatus current,
+ TpConnectionStatus previous,
+ EmpathyTpContactFactory *tp_factory)
{
EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
- McAccount *account;
- account = mc_account_lookup (unique_name);
if (account && empathy_account_equal (account, priv->account)) {
- tp_contact_factory_update (tp_factory);
+ tp_contact_factory_status_updated (tp_factory);
}
- g_object_unref (account);
}
static void
tp_factory);
priv->contacts = g_list_prepend (priv->contacts, contact);
- if (!priv->presence_iface) {
- /* We have no presence iface, set default presence
- * to available */
- empathy_contact_set_presence (contact, MC_PRESENCE_AVAILABLE);
- }
-
- empathy_debug (DEBUG_DOMAIN, "Contact added: %s (%d)",
- empathy_contact_get_id (contact),
- empathy_contact_get_handle (contact));
+ DEBUG ("Contact added: %s (%d)",
+ empathy_contact_get_id (contact),
+ empathy_contact_get_handle (contact));
}
static void
-tp_contact_factory_hold_handles_cb (DBusGProxy *proxy,
- GError *error,
- gpointer userdata)
+tp_contact_factory_hold_handles_cb (TpConnection *connection,
+ const GError *error,
+ gpointer userdata,
+ GObject *tp_factory)
{
if (error) {
- empathy_debug (DEBUG_DOMAIN, "Failed to hold handles: %s",
- error->message);
+ DEBUG ("Failed to hold handles: %s", error->message);
}
}
g_return_val_if_fail (EMPATHY_IS_TP_CONTACT_FACTORY (tp_factory), NULL);
- return empathy_tp_contact_factory_get_from_handle (tp_factory,
- priv->self_handle);
+ return g_object_ref (priv->user);
+}
+
+static void
+contact_created (EmpathyTpContactFactory *self,
+ EmpathyContact *contact)
+{
+ EmpathyTpContactFactoryPriv *priv = GET_PRIV (self);
+
+ if (priv->can_request_ft)
+ {
+ /* Set the FT capability */
+ /* FIXME: We should use the futur ContactCapabilities interface */
+ EmpathyCapabilities caps;
+
+ caps = empathy_contact_get_capabilities (contact);
+ caps |= EMPATHY_CAPABILITIES_FT;
+
+ empathy_contact_set_capabilities (contact, caps);
+ }
+
+ tp_contact_factory_add_contact (self, contact);
}
EmpathyContact *
"account", priv->account,
"id", id,
NULL);
- tp_contact_factory_add_contact (tp_factory, contact);
+ contact_created (tp_factory, contact);
- /* If the account is connected, request contact's handle */
- if (priv->tp_conn) {
- RequestHandlesData *data;
- const gchar *contact_ids[] = {id, NULL};
+ if (priv->ready) {
+ const gchar *contact_ids[] = {id, NULL};
+ GList *contacts;
- data = g_slice_new (RequestHandlesData);
- data->tp_factory = g_object_ref (tp_factory);
- data->contacts = g_list_prepend (NULL, g_object_ref (contact));
- tp_conn_request_handles_async (DBUS_G_PROXY (priv->tp_conn),
- TP_HANDLE_TYPE_CONTACT,
- contact_ids,
- tp_contact_factory_request_handles_cb,
- data);
+ contacts = g_list_prepend (NULL, g_object_ref (contact));
+ tp_cli_connection_call_request_handles (priv->connection,
+ -1,
+ TP_HANDLE_TYPE_CONTACT,
+ contact_ids,
+ tp_contact_factory_request_handles_cb,
+ contacts, tp_contact_factory_list_free,
+ G_OBJECT (tp_factory));
}
return contact;
GList *
empathy_tp_contact_factory_get_from_handles (EmpathyTpContactFactory *tp_factory,
- GArray *handles)
+ const GArray *handles)
{
EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
GList *contacts = NULL;
GArray *new_handles;
- gchar **handles_names;
+ GList *new_contacts = NULL;
guint i;
- GError *error = NULL;
g_return_val_if_fail (EMPATHY_IS_TP_CONTACT_FACTORY (tp_factory), NULL);
g_return_val_if_fail (handles != NULL, NULL);
return contacts;
}
- /* Get the IDs of all new handles */
- if (!tp_conn_inspect_handles (DBUS_G_PROXY (priv->tp_conn),
- TP_HANDLE_TYPE_CONTACT,
- new_handles,
- &handles_names,
- &error)) {
- empathy_debug (DEBUG_DOMAIN,
- "Couldn't inspect contact: %s",
- error ? error->message : "No error given");
- g_clear_error (&error);
- g_array_free (new_handles, TRUE);
- return contacts;
- }
-
/* Create new contacts */
for (i = 0; i < new_handles->len; i++) {
EmpathyContact *contact;
- gchar *id;
guint handle;
- gboolean is_user;
- id = handles_names[i];
handle = g_array_index (new_handles, guint, i);
- is_user = (handle == priv->self_handle);
contact = g_object_new (EMPATHY_TYPE_CONTACT,
"account", priv->account,
"handle", handle,
- "id", id,
- "is-user", is_user,
NULL);
- tp_contact_factory_add_contact (tp_factory, contact);
+ contact_created (tp_factory, contact);
contacts = g_list_prepend (contacts, contact);
- g_free (id);
+ new_contacts = g_list_prepend (new_contacts, g_object_ref (contact));
+ }
+ new_contacts = g_list_reverse (new_contacts);
+
+ if (priv->ready) {
+ /* Get the IDs of all new handles */
+ tp_cli_connection_call_inspect_handles (priv->connection,
+ -1,
+ TP_HANDLE_TYPE_CONTACT,
+ new_handles,
+ tp_contact_factory_inspect_handles_cb,
+ new_contacts, tp_contact_factory_list_free,
+ G_OBJECT (tp_factory));
+
+ /* Hold all new handles. */
+ /* FIXME: Should be unholded when removed from the factory */
+ tp_cli_connection_call_hold_handles (priv->connection,
+ -1,
+ TP_HANDLE_TYPE_CONTACT,
+ new_handles,
+ tp_contact_factory_hold_handles_cb,
+ NULL, NULL,
+ G_OBJECT (tp_factory));
+
+ tp_contact_factory_request_everything (tp_factory, new_handles);
}
- g_free (handles_names);
-
- /* Hold all new handles. */
- tp_conn_hold_handles_async (DBUS_G_PROXY (priv->tp_conn),
- TP_HANDLE_TYPE_CONTACT,
- new_handles,
- tp_contact_factory_hold_handles_cb,
- NULL);
-
- tp_contact_factory_request_everything (tp_factory, new_handles);
g_array_free (new_handles, TRUE);
g_return_if_fail (EMPATHY_IS_TP_CONTACT_FACTORY (tp_factory));
g_return_if_fail (EMPATHY_IS_CONTACT (contact));
+ g_return_if_fail (priv->ready);
g_return_if_fail (empathy_account_equal (empathy_contact_get_account (contact),
priv->account));
- if (!priv->aliasing_iface) {
- return;
- }
-
handle = empathy_contact_get_handle (contact);
- empathy_debug (DEBUG_DOMAIN, "Setting alias for contact %s (%d) to %s",
- empathy_contact_get_id (contact),
- handle, alias);
+ DEBUG ("Setting alias for contact %s (%d) to %s",
+ empathy_contact_get_id (contact),
+ handle, alias);
new_alias = g_hash_table_new_full (g_direct_hash,
g_direct_equal,
GUINT_TO_POINTER (handle),
g_strdup (alias));
- tp_conn_iface_aliasing_set_aliases_async (priv->aliasing_iface,
- new_alias,
- tp_contact_factory_set_aliases_cb,
- g_object_ref (tp_factory));
+ tp_cli_connection_interface_aliasing_call_set_aliases (priv->connection,
+ -1,
+ new_alias,
+ tp_contact_factory_set_aliases_cb,
+ NULL, NULL,
+ G_OBJECT (tp_factory));
g_hash_table_destroy (new_alias);
}
EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
g_return_if_fail (EMPATHY_IS_TP_CONTACT_FACTORY (tp_factory));
-
- if (!priv->avatars_iface) {
- return;
- }
+ g_return_if_fail (priv->ready);
if (data && size > 0 && size < G_MAXUINT) {
GArray avatar;
avatar.data = (gchar*) data;
avatar.len = size;
- empathy_debug (DEBUG_DOMAIN, "Setting avatar on account %s",
- mc_account_get_unique_name (priv->account));
+ DEBUG ("Setting avatar on account %s",
+ mc_account_get_unique_name (priv->account));
- tp_conn_iface_avatars_set_avatar_async (priv->avatars_iface,
- &avatar,
- mime_type,
- tp_contact_factory_set_avatar_cb,
- g_object_ref (tp_factory));
+ tp_cli_connection_interface_avatars_call_set_avatar (priv->connection,
+ -1,
+ &avatar,
+ mime_type,
+ tp_contact_factory_set_avatar_cb,
+ NULL, NULL,
+ G_OBJECT (tp_factory));
} else {
- empathy_debug (DEBUG_DOMAIN, "Clearing avatar on account %s",
- mc_account_get_unique_name (priv->account));
- tp_conn_iface_avatars_clear_avatar_async (priv->avatars_iface,
- tp_contact_factory_clear_avatar_cb,
- g_object_ref (tp_factory));
+ DEBUG ("Clearing avatar on account %s",
+ mc_account_get_unique_name (priv->account));
+
+ tp_cli_connection_interface_avatars_call_clear_avatar (priv->connection,
+ -1,
+ tp_contact_factory_clear_avatar_cb,
+ NULL, NULL,
+ G_OBJECT (tp_factory));
}
}
+gboolean
+empathy_tp_contact_factory_is_ready (EmpathyTpContactFactory *tp_factory)
+{
+ EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
+
+ g_return_val_if_fail (EMPATHY_IS_TP_CONTACT_FACTORY (tp_factory), FALSE);
+
+ return priv->ready;
+}
+
static void
tp_contact_factory_get_property (GObject *object,
guint param_id,
case PROP_ACCOUNT:
g_value_set_object (value, priv->account);
break;
+ case PROP_READY:
+ g_value_set_boolean (value, priv->ready);
+ break;
+ case PROP_MIME_TYPES:
+ g_value_set_boxed (value, priv->avatar_mime_types);
+ break;
+ case PROP_MIN_WIDTH:
+ g_value_set_uint (value, priv->avatar_min_width);
+ break;
+ case PROP_MIN_HEIGHT:
+ g_value_set_uint (value, priv->avatar_min_height);
+ break;
+ case PROP_MAX_WIDTH:
+ g_value_set_uint (value, priv->avatar_max_width);
+ break;
+ case PROP_MAX_HEIGHT:
+ g_value_set_uint (value, priv->avatar_max_height);
+ break;
+ case PROP_MAX_SIZE:
+ g_value_set_uint (value, priv->avatar_max_size);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
EmpathyTpContactFactoryPriv *priv = GET_PRIV (object);
GList *l;
- empathy_debug (DEBUG_DOMAIN, "Finalized: %p (%s)",
- object,
- mc_account_get_normalized_name (priv->account));
+ DEBUG ("Finalized: %p (%s)", object,
+ mc_account_get_normalized_name (priv->account));
- tp_contact_factory_disconnect (EMPATHY_TP_CONTACT_FACTORY (object));
- dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (priv->mc),
- "AccountStatusChanged",
- G_CALLBACK (tp_contact_factory_status_changed_cb),
- object);
+ g_signal_handlers_disconnect_by_func (priv->account_manager,
+ tp_contact_factory_account_connection_cb,
+ object);
for (l = priv->contacts; l; l = l->next) {
g_object_weak_unref (G_OBJECT (l->data),
}
g_list_free (priv->contacts);
- g_object_unref (priv->mc);
+ g_object_unref (priv->account_manager);
g_object_unref (priv->account);
+ g_object_unref (priv->user);
- if (priv->tp_conn) {
- g_object_unref (priv->tp_conn);
+ if (priv->connection) {
+ g_signal_handlers_disconnect_by_func (priv->connection,
+ tp_contact_factory_connection_invalidated_cb,
+ object);
+ g_object_unref (priv->connection);
}
+ g_strfreev (priv->avatar_mime_types);
+
G_OBJECT_CLASS (empathy_tp_contact_factory_parent_class)->finalize (object);
}
GObjectConstructParam *props)
{
GObject *tp_factory;
+ EmpathyTpContactFactoryPriv *priv;
tp_factory = G_OBJECT_CLASS (empathy_tp_contact_factory_parent_class)->constructor (type, n_props, props);
+ priv = GET_PRIV (tp_factory);
- tp_contact_factory_update (EMPATHY_TP_CONTACT_FACTORY (tp_factory));
+ priv->ready = FALSE;
+ priv->user = empathy_contact_new (priv->account);
+ empathy_contact_set_is_user (priv->user, TRUE);
+ tp_contact_factory_add_contact ((EmpathyTpContactFactory*) tp_factory, priv->user);
+ tp_contact_factory_status_updated (EMPATHY_TP_CONTACT_FACTORY (tp_factory));
return tp_factory;
}
-
static void
empathy_tp_contact_factory_class_init (EmpathyTpContactFactoryClass *klass)
{
object_class->get_property = tp_contact_factory_get_property;
object_class->set_property = tp_contact_factory_set_property;
- /* Construct-only properties */
g_object_class_install_property (object_class,
PROP_ACCOUNT,
g_param_spec_object ("account",
"The account associated with the factory",
MC_TYPE_ACCOUNT,
G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY));
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class,
+ PROP_READY,
+ g_param_spec_boolean ("ready",
+ "Whether the factory is ready",
+ "TRUE once the factory is ready to be used",
+ FALSE,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class,
+ PROP_MIME_TYPES,
+ g_param_spec_boxed ("avatar-mime-types",
+ "Supported MIME types for avatars",
+ "Types of images that may be set as "
+ "avatars on this connection. Only valid "
+ "once 'ready' becomes TRUE.",
+ G_TYPE_STRV,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class,
+ PROP_MIN_WIDTH,
+ g_param_spec_uint ("avatar-min-width",
+ "Minimum width for avatars",
+ "Minimum width of avatar that may be set. "
+ "Only valid once 'ready' becomes TRUE.",
+ 0,
+ G_MAXUINT,
+ 0,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class,
+ PROP_MIN_HEIGHT,
+ g_param_spec_uint ("avatar-min-height",
+ "Minimum height for avatars",
+ "Minimum height of avatar that may be set. "
+ "Only valid once 'ready' becomes TRUE.",
+ 0,
+ G_MAXUINT,
+ 0,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class,
+ PROP_MAX_WIDTH,
+ g_param_spec_uint ("avatar-max-width",
+ "Maximum width for avatars",
+ "Maximum width of avatar that may be set "
+ "or 0 if there is no maximum. "
+ "Only valid once 'ready' becomes TRUE.",
+ 0,
+ G_MAXUINT,
+ 0,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class,
+ PROP_MAX_HEIGHT,
+ g_param_spec_uint ("avatar-max-height",
+ "Maximum height for avatars",
+ "Maximum height of avatar that may be set "
+ "or 0 if there is no maximum. "
+ "Only valid once 'ready' becomes TRUE.",
+ 0,
+ G_MAXUINT,
+ 0,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class,
+ PROP_MAX_SIZE,
+ g_param_spec_uint ("avatar-max-size",
+ "Maximum size for avatars in bytes",
+ "Maximum file size of avatar that may be "
+ "set or 0 if there is no maximum. "
+ "Only valid once 'ready' becomes TRUE.",
+ 0,
+ G_MAXUINT,
+ 0,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+
g_type_class_add_private (object_class, sizeof (EmpathyTpContactFactoryPriv));
}
static void
empathy_tp_contact_factory_init (EmpathyTpContactFactory *tp_factory)
{
- EmpathyTpContactFactoryPriv *priv = GET_PRIV (tp_factory);
+ EmpathyTpContactFactoryPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (tp_factory,
+ EMPATHY_TYPE_TP_CONTACT_FACTORY, EmpathyTpContactFactoryPriv);
+
+ tp_factory->priv = priv;
+ priv->account_manager = empathy_account_manager_dup_singleton ();
+
+ g_signal_connect (priv->account_manager, "account-connection-changed",
+ G_CALLBACK (tp_contact_factory_account_connection_cb),
+ tp_factory);
- priv->mc = empathy_mission_control_new ();
- dbus_g_proxy_connect_signal (DBUS_G_PROXY (priv->mc),
- "AccountStatusChanged",
- G_CALLBACK (tp_contact_factory_status_changed_cb),
- tp_factory, NULL);
+ priv->can_request_ft = FALSE;
}
EmpathyTpContactFactory *