summaryrefslogtreecommitdiff
path: root/telepathy-glib/contacts-mixin.c
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.co.uk>2012-05-08 11:45:26 +0200
committerXavier Claessens <xavier.claessens@collabora.co.uk>2012-05-09 14:59:35 +0200
commita9c13065262e3b679d537b8240971a88909ddacf (patch)
tree9d5e11e70b1b44d5fe884d2d65d04fefc852cc1c /telepathy-glib/contacts-mixin.c
parent38151925c854b2051ddf6118d882457c806c897f (diff)
downloadtelepathy-glib-a9c13065262e3b679d537b8240971a88909ddacf.tar.gz
contacts-mixin: Implement GetContactByID
Diffstat (limited to 'telepathy-glib/contacts-mixin.c')
-rw-r--r--telepathy-glib/contacts-mixin.c57
1 files changed, 52 insertions, 5 deletions
diff --git a/telepathy-glib/contacts-mixin.c b/telepathy-glib/contacts-mixin.c
index 47dc85dad..9a2792d51 100644
--- a/telepathy-glib/contacts-mixin.c
+++ b/telepathy-glib/contacts-mixin.c
@@ -82,6 +82,11 @@ static TpDBusPropertiesMixinPropImpl known_contacts_props[] = {
{ NULL }
};
+static const gchar *always_included_interfaces[] = {
+ TP_IFACE_CONNECTION,
+ NULL
+};
+
static void
tp_presence_mixin_get_contacts_dbus_property (GObject *object,
GQuark interface,
@@ -371,10 +376,6 @@ tp_contacts_mixin_get_contact_attributes_impl (
TpBaseConnection *conn = TP_BASE_CONNECTION (iface);
GHashTable *result;
gchar *sender = NULL;
- const gchar *assumed_interfaces[] = {
- TP_IFACE_CONNECTION,
- NULL
- };
TP_BASE_CONNECTION_ERROR_IF_NOT_CONNECTED (conn, context);
@@ -382,7 +383,7 @@ tp_contacts_mixin_get_contact_attributes_impl (
sender = dbus_g_method_get_sender (context);
result = tp_contacts_mixin_get_contact_attributes (G_OBJECT (conn),
- handles, interfaces, assumed_interfaces, sender);
+ handles, interfaces, always_included_interfaces, sender);
tp_svc_connection_interface_contacts_return_from_get_contact_attributes (
context, result);
@@ -391,6 +392,51 @@ tp_contacts_mixin_get_contact_attributes_impl (
g_hash_table_unref (result);
}
+static void
+tp_contacts_mixin_get_contact_by_id_impl (
+ TpSvcConnectionInterfaceContacts *iface,
+ const gchar *id,
+ const gchar **interfaces,
+ DBusGMethodInvocation *context)
+{
+ TpBaseConnection *conn = TP_BASE_CONNECTION (iface);
+ TpHandleRepoIface *contact_repo = tp_base_connection_get_handles (conn,
+ TP_HANDLE_TYPE_CONTACT);
+ TpHandle handle;
+ GArray *handles;
+ GHashTable *attributes;
+ GHashTable *result;
+ gchar *sender = NULL;
+ GError *error = NULL;
+
+ TP_BASE_CONNECTION_ERROR_IF_NOT_CONNECTED (conn, context);
+
+ handle = tp_handle_ensure (contact_repo, id, NULL, &error);
+ if (handle == 0)
+ {
+ dbus_g_method_return_error (context, error);
+ g_clear_error (&error);
+ return;
+ }
+
+ sender = dbus_g_method_get_sender (context);
+ handles = g_array_new (FALSE, FALSE, sizeof (TpHandle));
+ g_array_append_val (handles, handle);
+
+ attributes = tp_contacts_mixin_get_contact_attributes (G_OBJECT (conn),
+ handles, interfaces, always_included_interfaces, sender);
+
+ result = g_hash_table_lookup (attributes, GUINT_TO_POINTER (handle));
+ g_assert (result != NULL);
+
+ tp_svc_connection_interface_contacts_return_from_get_contact_by_id (context,
+ handle, result);
+
+ g_free (sender);
+ g_array_unref (handles);
+ g_hash_table_unref (attributes);
+}
+
/**
* tp_contacts_mixin_iface_init: (skip)
* @g_iface: A pointer to the #TpSvcConnectionInterfaceContacts in an object
@@ -413,6 +459,7 @@ tp_contacts_mixin_iface_init (gpointer g_iface, gpointer iface_data)
#define IMPLEMENT(x) tp_svc_connection_interface_contacts_implement_##x ( \
klass, tp_contacts_mixin_##x##_impl)
IMPLEMENT(get_contact_attributes);
+ IMPLEMENT(get_contact_by_id);
#undef IMPLEMENT
}