From 09f8a09a48ff4f15da4977fb45414082503c4a8e Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Wed, 20 Jul 2011 10:58:14 +0100 Subject: [PATCH] Add a TpContactsMixin --- src/idle-connection.c | 10 +++++++++- src/idle-connection.h | 3 +++ tests/twisted/Makefile.am | 1 + tests/twisted/contacts.py | 29 +++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletions(-) create mode 100644 tests/twisted/contacts.py diff --git a/src/idle-connection.c b/src/idle-connection.c index d6f5796..902d376 100644 --- a/src/idle-connection.c +++ b/src/idle-connection.c @@ -79,7 +79,9 @@ static void _renaming_iface_init(gpointer, gpointer); G_DEFINE_TYPE_WITH_CODE(IdleConnection, idle_connection, TP_TYPE_BASE_CONNECTION, G_IMPLEMENT_INTERFACE(TP_TYPE_SVC_CONNECTION_INTERFACE_ALIASING, _aliasing_iface_init); G_IMPLEMENT_INTERFACE(TP_TYPE_SVC_CONNECTION_INTERFACE_CONTACT_INFO, idle_contact_info_iface_init); - G_IMPLEMENT_INTERFACE(IDLE_TYPE_SVC_CONNECTION_INTERFACE_RENAMING, _renaming_iface_init)); + G_IMPLEMENT_INTERFACE(IDLE_TYPE_SVC_CONNECTION_INTERFACE_RENAMING, _renaming_iface_init); + G_IMPLEMENT_INTERFACE(TP_TYPE_SVC_CONNECTION_INTERFACE_CONTACTS, tp_contacts_mixin_iface_init); +); typedef struct _IdleOutputPendingMsg IdleOutputPendingMsg; struct _IdleOutputPendingMsg { @@ -223,6 +225,9 @@ static void idle_connection_init(IdleConnection *obj) { priv->sconn_status = SERVER_CONNECTION_STATE_NOT_CONNECTED; priv->msg_queue = g_queue_new(); + + tp_contacts_mixin_init((GObject *) obj, G_STRUCT_OFFSET(IdleConnection, contacts)); + tp_base_connection_register_with_contacts_mixin ((TpBaseConnection *) obj); } static void @@ -402,6 +407,7 @@ static void idle_connection_finalize (GObject *object) { idle_output_pending_msg_free(msg); g_queue_free(priv->msg_queue); + tp_contacts_mixin_finalize(object); G_OBJECT_CLASS(idle_connection_parent_class)->finalize(object); } @@ -411,6 +417,7 @@ static const gchar * interfaces_always_present[] = { TP_IFACE_CONNECTION_INTERFACE_CONTACT_INFO, IDLE_IFACE_CONNECTION_INTERFACE_RENAMING, TP_IFACE_CONNECTION_INTERFACE_REQUESTS, + TP_IFACE_CONNECTION_INTERFACE_CONTACTS, NULL}; const gchar * const *idle_connection_get_implemented_interfaces (void) { @@ -475,6 +482,7 @@ static void idle_connection_class_init(IdleConnectionClass *klass) { param_spec = g_param_spec_boolean("password-prompt", "Password prompt", "Whether the connection should pop up a SASL channel if no password is given", FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT); g_object_class_install_property(object_class, PROP_PASSWORD_PROMPT, param_spec); + tp_contacts_mixin_class_init(object_class, G_STRUCT_OFFSET(IdleConnectionClass, contacts)); idle_contact_info_class_init(klass); } diff --git a/src/idle-connection.h b/src/idle-connection.h index 5d0d510..c73e202 100644 --- a/src/idle-connection.h +++ b/src/idle-connection.h @@ -24,6 +24,7 @@ #include #include #include +#include #include "idle-parser.h" @@ -36,10 +37,12 @@ typedef struct _IdleConnectionClass IdleConnectionClass; struct _IdleConnectionClass { TpBaseConnectionClass parent_class; + TpContactsMixinClass contacts; }; struct _IdleConnection { TpBaseConnection parent; + TpContactsMixin contacts; IdleParser *parser; GQueue *contact_info_requests; }; diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am index 95c50e4..6548dff 100644 --- a/tests/twisted/Makefile.am +++ b/tests/twisted/Makefile.am @@ -7,6 +7,7 @@ TWISTED_TESTS = \ connect/server-quit-ignore.py \ connect/server-quit-noclose.py \ connect/invalid-nick.py \ + contacts.py \ channels/join-muc-channel.py \ channels/join-muc-channel-bouncer.py \ channels/requests-create.py \ diff --git a/tests/twisted/contacts.py b/tests/twisted/contacts.py new file mode 100644 index 0000000..8c6d404 --- /dev/null +++ b/tests/twisted/contacts.py @@ -0,0 +1,29 @@ +""" +Test the Contacts interface. +""" + +from idletest import exec_test +from servicetest import assertContains, assertEquals +import constants as cs + +def test(q, bus, conn, stream): + conn.Connect() + q.expect('dbus-signal', signal='StatusChanged', args=[0, 1]) + + interfaces = conn.Properties.Get(cs.CONN, "Interfaces") + assertContains(cs.CONN_IFACE_CONTACTS, interfaces) + + brillana, miriam = conn.RequestHandles(cs.HT_CONTACT, + ["brillana", "miriam"]) + + # First up, check that contact-id is always present + attrs = conn.Contacts.GetContactAttributes([brillana], [], True) + assertContains(brillana, attrs) + brillana_attrs = attrs[brillana] + assertContains(cs.CONN + "/contact-id", brillana_attrs) + assertEquals("brillana", brillana_attrs[cs.CONN + "/contact-id"]) + + +if __name__ == '__main__': + exec_test(test) + -- 1.7.5.4