summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2013-01-08 20:19:48 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2013-01-08 20:19:48 +0000
commit810529d1fe4f84b16088a41c7fd63b7c266475d0 (patch)
tree56941cd549efd012cb7e466c39b3cafbef45ecd2
parent0f1435f548071f873d7626643f250b04b53931c9 (diff)
WiP, roster/groups.py failswip-names
Convert Gabble to use the TpNamesMixin This changes AliasesRequest into a request for several aliases into a request for a single nickname, but keep its naming for now... similarly, keep the indentation of some bits which used to be loops, but are now singular.
-rw-r--r--configure.ac4
-rw-r--r--src/conn-aliasing.c499
-rw-r--r--src/conn-aliasing.h2
-rw-r--r--src/connection.c11
-rw-r--r--src/connection.h5
5 files changed, 217 insertions, 304 deletions
diff --git a/configure.ac b/configure.ac
index f8edb6d5b..5e1d7ba67 100644
--- a/configure.ac
+++ b/configure.ac
@@ -298,8 +298,8 @@ AC_SUBST(DBUS_LIBS)
AC_DEFINE(TP_SEAL_ENABLE, [], [Prevent to use sealed variables])
AC_DEFINE(TP_DISABLE_SINGLE_INCLUDE, [], [Disable single header include])
AC_DEFINE(TP_VERSION_MIN_REQUIRED, TP_VERSION_0_18, [Ignore post 0.18 deprecations])
-AC_DEFINE(TP_VERSION_MAX_ALLOWED, TP_VERSION_0_20, [Prevent post 0.20 APIs])
-PKG_CHECK_MODULES(TP_GLIB, [telepathy-glib >= 0.19.9])
+AC_DEFINE([TP_VERSION_MAX_ALLOWED], [TP_VERSION_0_22], [Prevent post 0.22 APIs])
+PKG_CHECK_MODULES([TP_GLIB], [telepathy-glib >= 0.20.999.1])
AC_SUBST(TP_GLIB_CFLAGS)
AC_SUBST(TP_GLIB_LIBS)
diff --git a/src/conn-aliasing.c b/src/conn-aliasing.c
index 26637039e..420e7dec0 100644
--- a/src/conn-aliasing.c
+++ b/src/conn-aliasing.c
@@ -1,6 +1,6 @@
/*
* conn-aliasing.c - Gabble connection aliasing interface
- * Copyright (C) 2005-2010 Collabora Ltd.
+ * Copyright (C) 2005-2013 Collabora Ltd.
* Copyright (C) 2005-2010 Nokia Corporation
*
* This library is free software; you can redistribute it and/or
@@ -49,30 +49,12 @@ static void maybe_request_vcard (GabbleConnection *self, TpHandle handle,
/* distinct from any strdup()d pointer - used for negative caching */
static const gchar *NO_ALIAS = "";
-/**
- * gabble_connection_get_alias_flags
- *
- * Implements D-Bus method GetAliasFlags
- * on interface org.freedesktop.Telepathy.Connection.Interface.Aliasing
- *
- * @error: Used to return a pointer to a GError detailing any error
- * that occurred, D-Bus will throw the error only if this
- * function returns FALSE.
- *
- * Returns: TRUE if successful, FALSE if an error was thrown.
- */
-static void
-gabble_connection_get_alias_flags (TpSvcConnectionInterfaceAliasing *iface,
- DBusGMethodInvocation *context)
+static TpContactMetadataStorageType
+get_alias_storage (TpBaseConnection *base)
{
- TpBaseConnection *base = TP_BASE_CONNECTION (iface);
-
g_assert (GABBLE_IS_CONNECTION (base));
- TP_BASE_CONNECTION_ERROR_IF_NOT_CONNECTED (base, context);
-
- tp_svc_connection_interface_aliasing_return_from_get_alias_flags (
- context, TP_CONNECTION_ALIAS_FLAG_USER_SET);
+ return TP_CONTACT_METADATA_STORAGE_TYPE_ANYONE;
}
@@ -81,38 +63,31 @@ typedef struct _AliasesRequest AliasesRequest;
struct _AliasesRequest
{
GabbleConnection *conn;
- DBusGMethodInvocation *request_call;
- guint pending_vcard_requests;
- guint pending_pep_requests;
- GArray *contacts;
- GabbleVCardManagerRequest **vcard_requests;
- GabbleRequestPipelineItem **pep_requests;
- gchar **aliases;
+ TpHandle handle;
+ GabbleVCardManagerRequest *vcard_request;
+ GabbleRequestPipelineItem *pep_request;
+ gchar *alias;
+ GAsyncReadyCallback callback;
+ gpointer user_data;
};
-typedef struct
-{
- AliasesRequest *aliases_request;
- guint index;
-} AliasRequest;
-
static AliasesRequest *
aliases_request_new (GabbleConnection *conn,
- DBusGMethodInvocation *request_call,
- const GArray *contacts)
+ TpHandle handle,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
AliasesRequest *request;
request = g_slice_new0 (AliasesRequest);
request->conn = conn;
- request->request_call = request_call;
- request->contacts = g_array_new (FALSE, FALSE, sizeof (TpHandle));
- g_array_insert_vals (request->contacts, 0, contacts->data, contacts->len);
- request->vcard_requests =
- g_new0 (GabbleVCardManagerRequest *, contacts->len);
- request->pep_requests =
- g_new0 (GabbleRequestPipelineItem *, contacts->len);
- request->aliases = g_new0 (gchar *, contacts->len + 1);
+ request->handle = handle;
+ request->vcard_request = NULL;
+ request->pep_request = NULL;
+ request->alias = NULL;
+
+ request->callback = callback;
+ request->user_data = user_data;
return request;
}
@@ -121,35 +96,40 @@ aliases_request_new (GabbleConnection *conn,
static void
aliases_request_free (AliasesRequest *request)
{
- guint i;
-
- for (i = 0; i < request->contacts->len; i++)
{
/* FIXME: what if vcard_manager is NULL? */
- if (request->vcard_requests[i] != NULL)
+ if (request->vcard_request != NULL)
gabble_vcard_manager_cancel_request (request->conn->vcard_manager,
- request->vcard_requests[i]);
+ request->vcard_request);
}
- g_array_unref (request->contacts);
- g_free (request->vcard_requests);
- g_free (request->pep_requests);
- g_strfreev (request->aliases);
+ /* FIXME: do we need to cancel the PEP request? */
+
g_slice_free (AliasesRequest, request);
}
+static void request_nickname_async (TpBaseConnection *base,
+ TpHandle handle,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
static gboolean
aliases_request_try_return (AliasesRequest *request)
{
- if (request->pending_vcard_requests == 0 &&
- request->pending_pep_requests == 0)
+ if (request->vcard_request == NULL && request->pep_request == NULL)
{
- /* Cast to (const gchar **) necessary because no-one understands 'const'
- * in C.
- */
- tp_svc_connection_interface_aliasing_return_from_request_aliases (
- request->request_call, (const gchar **)request->aliases);
+ GSimpleAsyncResult *simple = g_simple_async_result_new (
+ G_OBJECT (request->conn), request->callback, request->user_data,
+ request_nickname_async);
+
+ /* steal */
+ g_simple_async_result_set_op_res_gpointer (simple, request->alias, NULL);
+ request->alias = NULL;
+
+ /* FIXME: does this actually need to be idle? */
+ g_simple_async_result_complete_in_idle (simple);
+
+ g_object_unref (simple);
return TRUE;
}
@@ -167,31 +147,17 @@ aliases_request_vcard_cb (GabbleVCardManager *manager,
{
AliasesRequest *aliases_request = (AliasesRequest *) user_data;
GabbleConnectionAliasSource source;
- guint i;
- gboolean found = FALSE;
gchar *alias = NULL;
- g_assert (aliases_request->pending_vcard_requests > 0);
+ g_assert (aliases_request->vcard_request == request);
- /* The index of the vCard request in the vCard request array is the
- * index of the contact/alias in their respective arrays. */
-
- for (i = 0; i < aliases_request->contacts->len; i++)
- if (aliases_request->vcard_requests[i] == request)
- {
- found = TRUE;
- break;
- }
-
- g_assert (found);
source = _gabble_connection_get_cached_alias (aliases_request->conn,
- g_array_index (aliases_request->contacts, TpHandle, i), &alias);
+ aliases_request->handle, &alias);
g_assert (source != GABBLE_CONNECTION_ALIAS_NONE);
g_assert (NULL != alias);
- aliases_request->pending_vcard_requests--;
- aliases_request->vcard_requests[i] = NULL;
- aliases_request->aliases[i] = alias;
+ aliases_request->vcard_request = NULL;
+ aliases_request->alias = alias;
if (aliases_request_try_return (aliases_request))
aliases_request_free (aliases_request);
@@ -267,16 +233,12 @@ aliases_request_pep_cb (GabbleConnection *self,
GError *error)
{
TpBaseConnection *base = (TpBaseConnection *) self;
- AliasRequest *alias_request = (AliasRequest *) user_data;
- AliasesRequest *aliases_request = alias_request->aliases_request;
- guint index = alias_request->index;
- TpHandle handle = g_array_index (aliases_request->contacts, TpHandle, index);
+ AliasesRequest *aliases_request = user_data;
+ TpHandle handle = aliases_request->handle;
GabbleConnectionAliasSource source = GABBLE_CONNECTION_ALIAS_NONE;
gchar *alias = NULL;
- aliases_request->pending_pep_requests--;
- aliases_request->pep_requests[index] = NULL;
- g_slice_free (AliasRequest, alias_request);
+ aliases_request->pep_request = NULL;
aliases_request_cache_pep (self, msg, handle, error);
@@ -290,7 +252,7 @@ aliases_request_pep_cb (GabbleConnection *self,
(self->vcard_manager != NULL &&
gabble_vcard_manager_has_cached_alias (self->vcard_manager, handle)))
{
- aliases_request->aliases[index] = alias;
+ aliases_request->alias = alias;
}
else if (tp_base_connection_get_status (base) !=
TP_CONNECTION_STATUS_CONNECTED)
@@ -306,8 +268,7 @@ aliases_request_pep_cb (GabbleConnection *self,
aliases_request, G_OBJECT (self));
g_free (alias);
- aliases_request->vcard_requests[index] = vcard_request;
- aliases_request->pending_vcard_requests++;
+ aliases_request->vcard_request = vcard_request;
}
if (aliases_request_try_return (aliases_request))
@@ -317,8 +278,6 @@ aliases_request_pep_cb (GabbleConnection *self,
typedef struct {
GabbleRequestPipelineCb callback;
gpointer user_data;
- TpHandleRepoIface *contact_handles;
- TpHandle handle;
} pep_request_ctx;
static void
@@ -359,8 +318,6 @@ gabble_do_pep_request (GabbleConnection *self,
ctx = g_slice_new0 (pep_request_ctx);
ctx->callback = callback;
ctx->user_data = user_data;
- ctx->contact_handles = contact_handles;
- ctx->handle = handle;
to = tp_handle_inspect (contact_handles, handle);
msg = wocky_stanza_build (WOCKY_STANZA_TYPE_IQ, WOCKY_STANZA_SUB_TYPE_GET,
@@ -389,34 +346,24 @@ gabble_do_pep_request (GabbleConnection *self,
* or throw an error.
*/
static void
-gabble_connection_request_aliases (TpSvcConnectionInterfaceAliasing *iface,
- const GArray *contacts,
- DBusGMethodInvocation *context)
+request_nickname_async (TpBaseConnection *base,
+ TpHandle handle,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
- GabbleConnection *self = GABBLE_CONNECTION (iface);
- TpBaseConnection *base = (TpBaseConnection *) self;
+ GabbleConnection *self = GABBLE_CONNECTION (base);
TpHandleRepoIface *contact_handles = tp_base_connection_get_handles (base,
TP_HANDLE_TYPE_CONTACT);
- guint i;
AliasesRequest *request;
- GError *error = NULL;
g_assert (GABBLE_IS_CONNECTION (self));
+ g_assert (tp_base_connection_get_status (base) ==
+ TP_CONNECTION_STATUS_CONNECTED);
- TP_BASE_CONNECTION_ERROR_IF_NOT_CONNECTED (base, context);
-
- if (!tp_handles_are_valid (contact_handles, contacts, FALSE, &error))
- {
- dbus_g_method_return_error (context, error);
- g_error_free (error);
- return;
- }
-
- request = aliases_request_new (self, context, contacts);
+ request = aliases_request_new (self, handle, callback, user_data);
- for (i = 0; i < contacts->len; i++)
+ /* keep the old indentation for now */
{
- TpHandle handle = g_array_index (contacts, TpHandle, i);
GabbleConnectionAliasSource source;
GabbleVCardManagerRequest *vcard_request;
gchar *alias;
@@ -431,7 +378,7 @@ gabble_connection_request_aliases (TpSvcConnectionInterfaceAliasing *iface,
/* Either the alias we got was from a vCard or better, or we already
* tried getting an alias from a vcard and failed, so there's no
* point trying again. */
- request->aliases[i] = alias;
+ request->alias = alias;
}
else if (self->features & GABBLE_CONNECTION_FEATURES_PEP)
{
@@ -439,16 +386,10 @@ gabble_connection_request_aliases (TpSvcConnectionInterfaceAliasing *iface,
* events when someone first sends us presence. However, the
* current ejabberd PEP implementation doesn't seem to give
* us notifications of the initial state. */
- AliasRequest *data = g_slice_new (AliasRequest);
-
g_free (alias);
- data->aliases_request = request;
- data->index = i;
-
- request->pending_pep_requests++;
- request->pep_requests[i] = gabble_do_pep_request (self,
- handle, contact_handles, aliases_request_pep_cb, data);
+ request->pep_request = gabble_do_pep_request (self,
+ handle, contact_handles, aliases_request_pep_cb, request);
}
else
@@ -460,8 +401,7 @@ gabble_connection_request_aliases (TpSvcConnectionInterfaceAliasing *iface,
vcard_request = gabble_vcard_manager_request (self->vcard_manager,
handle, 0, aliases_request_vcard_cb, request, G_OBJECT (self));
- request->vcard_requests[i] = vcard_request;
- request->pending_vcard_requests++;
+ request->vcard_request = vcard_request;
}
}
@@ -489,36 +429,22 @@ nick_publish_msg_reply_cb (GabbleConnection *conn,
#endif
}
-static gboolean
-set_one_alias (
- GabbleConnection *conn,
+static void
+set_local_alias_async (TpBaseConnection *base,
TpHandle handle,
- gchar *alias,
- GError **error)
+ const gchar *alias,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
- TpBaseConnection *base = (TpBaseConnection *) conn;
- TpHandleRepoIface *contact_handles = tp_base_connection_get_handles (base,
- TP_HANDLE_TYPE_CONTACT);
+ GabbleConnection *conn = GABBLE_CONNECTION (base);
+ GError *error = NULL;
gboolean ret = TRUE;
- g_assert (tp_base_connection_get_status (base) ==
- TP_CONNECTION_STATUS_CONNECTED);
-
- if (tp_str_empty (alias))
- alias = NULL;
-
- if (!tp_handle_is_valid (contact_handles, handle, error))
- {
- ret = FALSE;
- }
- else if (tp_base_connection_get_self_handle (base) == handle)
+ if (handle == tp_base_connection_get_self_handle (base))
{
- /* only alter the roster if we're already there, e.g. because someone
- * added us with another client
- */
if (gabble_roster_handle_has_entry (conn->roster, handle)
&& !gabble_roster_handle_set_name (conn->roster, handle,
- alias, error))
+ alias, &error))
{
ret = FALSE;
}
@@ -528,14 +454,22 @@ set_one_alias (
gchar *remote_alias = NULL;
GabbleConnectionAliasSource source = GABBLE_CONNECTION_ALIAS_FROM_ROSTER;
- if (alias == NULL)
+ if (tp_str_empty (alias))
{
+ /* We've been told to set the alias to "" which is pretty useless.
+ * Set it to their nickname instead.
+ * FIXME: after doing this, we're unable to tell whether their
+ * roster name came from us or them. We should remove their
+ * roster name here, and rely on a separate local nickname cache
+ * to suppress vCard queries. */
source = _gabble_connection_get_cached_remote_alias (conn, handle,
&remote_alias);
alias = remote_alias;
}
- ret = gabble_roster_handle_set_name (conn->roster, handle, alias, error);
+ ret = gabble_roster_handle_set_name (conn->roster, handle, alias,
+ &error);
+
g_free (remote_alias);
/* If we don't have a cached remote alias for this contact, try to ask
@@ -545,13 +479,54 @@ set_one_alias (
maybe_request_vcard (conn, handle, source);
}
- if (tp_base_connection_get_self_handle (base) == handle)
+ if (callback != NULL)
+ {
+ if (ret)
+ tp_simple_async_report_success_in_idle (G_OBJECT (base),
+ callback, user_data, set_local_alias_async);
+ else
+ g_simple_async_report_take_gerror_in_idle (G_OBJECT (base),
+ callback, user_data, error);
+ }
+}
+
+static void
+set_nickname_async (TpBaseConnection *base,
+ const gchar *alias,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GabbleConnection *conn = GABBLE_CONNECTION (base);
+ TpHandle self_handle = tp_base_connection_get_self_handle (base);
+ GError *error = NULL;
+
+ if (tp_str_empty (alias))
+ alias = NULL;
+
+ g_assert (tp_base_connection_get_status (base) ==
+ TP_CONNECTION_STATUS_CONNECTED);
+
+ /* leave the old indentation for now */
{
GabbleVCardManagerEditInfo *edit;
GQueue edits = G_QUEUE_INIT;
- /* User has called SetAliases on themselves - patch their vCard.
- * FIXME: because SetAliases is currently synchronous, we ignore errors
+ /* only alter the roster if we're already there, e.g. because someone
+ * added us with another client
+ */
+ if (gabble_roster_handle_has_entry (conn->roster, self_handle)
+ && !gabble_roster_handle_set_name (conn->roster, self_handle,
+ alias, &error))
+ {
+ if (callback != NULL)
+ g_simple_async_report_take_gerror_in_idle (G_OBJECT (base),
+ callback, user_data, error);
+
+ return;
+ }
+
+ /* User has called Set(Nickname) on themselves - patch their vCard.
+ * FIXME: because SetAliases used to be synchronous, we ignore errors
* here, and just let the request happen in the background.
*/
@@ -587,52 +562,11 @@ set_one_alias (
NULL, G_OBJECT (conn), edits.head);
}
- return ret;
+ /* For now, just say "yes". */
+ tp_simple_async_report_success_in_idle (G_OBJECT (base),
+ callback, user_data, set_nickname_async);
}
-/**
- * gabble_connection_set_aliases
- *
- * Implements D-Bus method SetAliases
- * on interface org.freedesktop.Telepathy.Connection.Interface.Aliasing
- */
-static void
-gabble_connection_set_aliases (TpSvcConnectionInterfaceAliasing *iface,
- GHashTable *aliases,
- DBusGMethodInvocation *context)
-{
- GabbleConnection *self = GABBLE_CONNECTION (iface);
- TpBaseConnection *base = (TpBaseConnection *) self;
- GHashTableIter iter;
- gpointer key, value;
- gboolean retval = TRUE;
- GError *first_error = NULL;
-
- g_assert (GABBLE_IS_CONNECTION (self));
-
- TP_BASE_CONNECTION_ERROR_IF_NOT_CONNECTED (base, context);
-
- g_hash_table_iter_init (&iter, aliases);
- while (g_hash_table_iter_next (&iter, &key, &value))
- {
- if (!set_one_alias (self, GPOINTER_TO_UINT (key), value,
- (first_error == NULL ? &first_error : NULL)))
- retval = FALSE;
- }
-
- if (retval)
- {
- tp_svc_connection_interface_aliasing_return_from_set_aliases (
- context);
- }
- else
- {
- dbus_g_method_return_error (context, first_error);
- g_error_free (first_error);
- }
-}
-
-
GQuark
gabble_conn_aliasing_pep_alias_quark (void)
{
@@ -796,7 +730,7 @@ gabble_conn_aliasing_nicknames_updated (GObject *object,
{
GabbleConnection *conn = GABBLE_CONNECTION (user_data);
GabbleConnectionAliasSource signal_source;
- GPtrArray *aliases;
+ GHashTable *aliases;
guint i;
g_return_if_fail (handles->len > 0);
@@ -824,14 +758,13 @@ gabble_conn_aliasing_nicknames_updated (GObject *object,
return;
}
- aliases = g_ptr_array_sized_new (handles->len);
+ aliases = g_hash_table_new_full (NULL, NULL, NULL, g_free);
for (i = 0; i < handles->len; i++)
{
TpHandle handle = g_array_index (handles, TpHandle, i);
GabbleConnectionAliasSource current_source;
gchar *alias = NULL;
- GValue entry = { 0, };
current_source = _gabble_connection_get_cached_alias (conn, handle,
&alias);
@@ -849,33 +782,26 @@ gabble_conn_aliasing_nicknames_updated (GObject *object,
continue;
}
- g_value_init (&entry, TP_STRUCT_TYPE_ALIAS_PAIR);
- g_value_take_boxed (&entry,
- dbus_g_type_specialized_construct (TP_STRUCT_TYPE_ALIAS_PAIR));
-
- dbus_g_type_struct_set (&entry,
- 0, handle,
- 1, alias,
- G_MAXUINT);
-
- g_ptr_array_add (aliases, g_value_get_boxed (&entry));
+ /* takes ownership */
+ g_hash_table_insert (aliases, GUINT_TO_POINTER (handle), alias);
/* Check whether the roster has an entry for the handle and if so, set
- * the roster alias so the vCard isn't fetched on every connect. */
+ * the roster alias so the vCard isn't fetched on every connect.
+ * FIXME: after doing this, we're unable to tell whether their
+ * roster name came from us or them. We should remove their
+ * roster name here, and rely on a separate local nickname cache
+ * to suppress vCard queries. */
if (signal_source < GABBLE_CONNECTION_ALIAS_FROM_ROSTER &&
gabble_roster_handle_has_entry (conn->roster, handle))
gabble_roster_handle_set_name (conn->roster, handle, alias, NULL);
-
- g_free (alias);
}
- if (aliases->len > 0)
- tp_svc_connection_interface_aliasing_emit_aliases_changed (conn, aliases);
-
- for (i = 0; i < aliases->len; i++)
- g_boxed_free (TP_STRUCT_TYPE_ALIAS_PAIR, g_ptr_array_index (aliases, i));
+ if (signal_source == GABBLE_CONNECTION_ALIAS_FROM_ROSTER)
+ tp_names_mixin_local_aliases_changed (TP_BASE_CONNECTION (conn), aliases);
+ else
+ tp_names_mixin_nicknames_changed (TP_BASE_CONNECTION (conn), aliases);
- g_ptr_array_unref (aliases);
+ g_hash_table_unref (aliases);
}
static void
@@ -1090,97 +1016,75 @@ maybe_request_vcard (GabbleConnection *self, TpHandle handle,
}
}
-static void
-conn_aliasing_fill_contact_attributes (GObject *obj,
- const GArray *contacts, GHashTable *attributes_hash)
+static gchar *
+dup_nickname (TpBaseConnection *base,
+ TpHandle contact)
{
- guint i;
- GabbleConnection *self = GABBLE_CONNECTION(obj);
-
- for (i = 0; i < contacts->len; i++)
- {
- TpHandle handle = g_array_index (contacts, TpHandle, i);
- GabbleConnectionAliasSource source;
- gchar *alias;
- GValue *val = tp_g_value_slice_new (G_TYPE_STRING);
-
- source = _gabble_connection_get_cached_alias (self, handle, &alias);
- g_assert (alias != NULL);
+ GabbleConnection *self = GABBLE_CONNECTION (base);
+ GabbleConnectionAliasSource source;
+ gchar *alias;
- g_value_take_string (val, alias);
+ g_assert (GABBLE_IS_CONNECTION (self));
- tp_contacts_mixin_set_contact_attribute (attributes_hash,
- handle, TP_IFACE_CONNECTION_INTERFACE_ALIASING"/alias",
- val);
+ source = _gabble_connection_get_cached_alias (self, contact, &alias);
+ g_assert (alias != NULL);
- maybe_request_vcard (self, handle, source);
+ switch (source)
+ {
+ case GABBLE_CONNECTION_ALIAS_NONE:
+ case GABBLE_CONNECTION_ALIAS_FROM_JID:
+ case GABBLE_CONNECTION_ALIAS_FROM_ROSTER:
+ g_free (alias);
+ return NULL;
+
+ case GABBLE_CONNECTION_ALIAS_FROM_VCARD:
+ case GABBLE_CONNECTION_ALIAS_FROM_MUC_RESOURCE:
+ case GABBLE_CONNECTION_ALIAS_FROM_CONNMGR:
+ case GABBLE_CONNECTION_ALIAS_FROM_PRESENCE:
+ return alias;
}
+
+ g_return_val_if_reached (NULL);
}
-/**
- * gabble_connection_get_aliases
- *
- * Implements D-Bus method GetAliases
- * on interface org.freedesktop.Telepathy.Connection.Interface.Aliasing
- *
- * @context: The D-Bus invocation context to use to return values
- * or throw an error.
- */
-static void
-gabble_connection_get_aliases (TpSvcConnectionInterfaceAliasing *iface,
- const GArray *contacts,
- DBusGMethodInvocation *context)
+static gchar *
+dup_local_alias (TpBaseConnection *base,
+ TpHandle contact)
{
- GabbleConnection *self = GABBLE_CONNECTION (iface);
- TpBaseConnection *base = (TpBaseConnection *) self;
- TpHandleRepoIface *contact_handles = tp_base_connection_get_handles (base,
- TP_HANDLE_TYPE_CONTACT);
- GHashTable *result;
- GError *error = NULL;
- guint i;
+ GabbleConnection *self = GABBLE_CONNECTION (base);
+ GabbleConnectionAliasSource source;
+ gchar *alias;
g_assert (GABBLE_IS_CONNECTION (self));
- TP_BASE_CONNECTION_ERROR_IF_NOT_CONNECTED (base, context);
+ source = _gabble_connection_get_cached_alias (self, contact, &alias);
+ g_assert (alias != NULL);
- if (!tp_handles_are_valid (contact_handles, contacts, FALSE, &error))
+ switch (source)
{
- dbus_g_method_return_error (context, error);
- g_error_free (error);
- return;
+ case GABBLE_CONNECTION_ALIAS_NONE:
+ case GABBLE_CONNECTION_ALIAS_FROM_JID:
+ case GABBLE_CONNECTION_ALIAS_FROM_VCARD:
+ case GABBLE_CONNECTION_ALIAS_FROM_MUC_RESOURCE:
+ case GABBLE_CONNECTION_ALIAS_FROM_CONNMGR:
+ case GABBLE_CONNECTION_ALIAS_FROM_PRESENCE:
+ g_free (alias);
+ return NULL;
+
+ case GABBLE_CONNECTION_ALIAS_FROM_ROSTER:
+ return alias;
}
- result = g_hash_table_new_full (g_direct_hash, g_direct_equal,
- NULL, g_free);
-
- for (i = 0; i < contacts->len; i++)
- {
- TpHandle handle = g_array_index (contacts, TpHandle, i);
- GabbleConnectionAliasSource source;
- gchar *alias;
-
- source = _gabble_connection_get_cached_alias (self, handle, &alias);
- g_assert (alias != NULL);
-
- g_hash_table_insert (result, GUINT_TO_POINTER (handle), alias);
-
- maybe_request_vcard (self, handle, source);
- }
-
- tp_svc_connection_interface_aliasing_return_from_get_aliases (context,
- result);
-
- g_hash_table_unref (result);
+ g_return_val_if_reached (NULL);
}
-
-
void
conn_aliasing_init (GabbleConnection *conn)
{
- tp_contacts_mixin_add_contact_attributes_iface (G_OBJECT (conn),
- TP_IFACE_CONNECTION_INTERFACE_ALIASING,
- conn_aliasing_fill_contact_attributes);
+ GObject *obj = G_OBJECT (conn);
+
+ tp_names_mixin_init (obj);
+ tp_names_mixin_register_with_contacts_mixin (obj);
conn->pep_nick = wocky_pep_service_new (NS_NICK, TRUE);
@@ -1189,16 +1093,13 @@ conn_aliasing_init (GabbleConnection *conn)
}
void
-conn_aliasing_iface_init (gpointer g_iface, gpointer iface_data)
+names_iface_init (TpNamesInterface *iface)
{
- TpSvcConnectionInterfaceAliasingClass *klass = g_iface;
-
-#define IMPLEMENT(x) tp_svc_connection_interface_aliasing_implement_##x (\
- klass, gabble_connection_##x)
- IMPLEMENT(get_alias_flags);
- IMPLEMENT(request_aliases);
- IMPLEMENT(get_aliases);
- IMPLEMENT(set_aliases);
-#undef IMPLEMENT
-}
+ iface->dup_nickname = dup_nickname;
+ iface->request_nickname_async = request_nickname_async;
+ iface->set_nickname_async = set_nickname_async;
+ iface->get_alias_storage = get_alias_storage;
+ iface->dup_local_alias = dup_local_alias;
+ iface->set_local_alias_async = set_local_alias_async;
+}
diff --git a/src/conn-aliasing.h b/src/conn-aliasing.h
index 353e3238e..b73d7c539 100644
--- a/src/conn-aliasing.h
+++ b/src/conn-aliasing.h
@@ -28,7 +28,7 @@
G_BEGIN_DECLS
void conn_aliasing_init (GabbleConnection *conn);
-void conn_aliasing_iface_init (gpointer g_iface, gpointer iface_data);
+void names_iface_init (TpNamesInterface *iface);
void gabble_conn_aliasing_nickname_updated (GObject *object,
TpHandle handle, gpointer user_data);
diff --git a/src/connection.c b/src/connection.c
index db64bd278..9d9f8e6db 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1,6 +1,6 @@
/*
* gabble-connection.c - Source for GabbleConnection
- * Copyright (C) 2005-2010 Collabora Ltd.
+ * Copyright (C) 2005-2013 Collabora Ltd.
* Copyright (C) 2005-2010 Nokia Corporation
*
* This library is free software; you can redistribute it and/or
@@ -103,7 +103,7 @@ G_DEFINE_TYPE_WITH_CODE(GabbleConnection,
gabble_connection,
TP_TYPE_BASE_CONNECTION,
G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION_INTERFACE_ALIASING,
- conn_aliasing_iface_init);
+ tp_names_mixin_aliasing_iface_init);
G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION_INTERFACE_AVATARS,
conn_avatars_iface_init);
G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION_INTERFACE_CONTACT_INFO,
@@ -120,6 +120,8 @@ G_DEFINE_TYPE_WITH_CODE(GabbleConnection,
tp_base_contact_list_mixin_groups_iface_init);
G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION_INTERFACE_CONTACT_BLOCKING,
tp_base_contact_list_mixin_blocking_iface_init);
+ G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION_INTERFACE_NAMES,
+ tp_names_mixin_iface_init);
G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CONNECTION_INTERFACE_SIMPLE_PRESENCE,
tp_presence_mixin_simple_presence_iface_init);
G_IMPLEMENT_INTERFACE (GABBLE_TYPE_SVC_CONNECTION_INTERFACE_GABBLE_DECLOAK,
@@ -143,6 +145,8 @@ G_DEFINE_TYPE_WITH_CODE(GabbleConnection,
conn_power_saving_iface_init);
G_IMPLEMENT_INTERFACE (GABBLE_TYPE_SVC_CONNECTION_INTERFACE_ADDRESSING,
conn_addressing_iface_init);
+ G_IMPLEMENT_INTERFACE (TP_TYPE_NAMES_INTERFACE,
+ names_iface_init);
G_IMPLEMENT_INTERFACE (GABBLE_TYPE_PLUGIN_CONNECTION,
gabble_plugin_connection_iface_init);
)
@@ -898,6 +902,7 @@ static const gchar *implemented_interfaces[] = {
TP_IFACE_CONNECTION_INTERFACE_POWER_SAVING,
TP_IFACE_CONNECTION_INTERFACE_ALIASING,
TP_IFACE_CONNECTION_INTERFACE_CAPABILITIES,
+ TP_IFACE_CONNECTION_INTERFACE_NAMES,
TP_IFACE_CONNECTION_INTERFACE_SIMPLE_PRESENCE,
TP_IFACE_CONNECTION_INTERFACE_PRESENCE,
TP_IFACE_CONNECTION_INTERFACE_AVATARS,
@@ -1261,6 +1266,8 @@ gabble_connection_class_init (GabbleConnectionClass *gabble_connection_class)
conn_contact_info_class_init (gabble_connection_class);
tp_base_contact_list_mixin_class_init (parent_class);
+
+ tp_names_mixin_init_dbus_properties (object_class);
}
static void
diff --git a/src/connection.h b/src/connection.h
index c3e9138b0..f3456b219 100644
--- a/src/connection.h
+++ b/src/connection.h
@@ -252,12 +252,17 @@ struct _GabbleConnection {
};
typedef enum {
+ /* Worse than nicknames */
GABBLE_CONNECTION_ALIAS_NONE = 0,
GABBLE_CONNECTION_ALIAS_FROM_JID,
+
+ /* Nicknames */
GABBLE_CONNECTION_ALIAS_FROM_VCARD,
GABBLE_CONNECTION_ALIAS_FROM_MUC_RESOURCE,
GABBLE_CONNECTION_ALIAS_FROM_CONNMGR,
GABBLE_CONNECTION_ALIAS_FROM_PRESENCE,
+
+ /* Local-alias */
GABBLE_CONNECTION_ALIAS_FROM_ROSTER
} GabbleConnectionAliasSource;