From 65d38a3105b091cc32aa6227e90a68026b138bb4 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Wed, 18 Sep 2013 09:16:41 +0200 Subject: [PATCH 4/4] protocol: implement get_avatar_details() --- src/protocol.c | 37 +++++++++++++++++++++++++++++++++++++ tests/twisted/cm/protocols.py | 21 +++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/src/protocol.c b/src/protocol.c index 9089e0d..dc2fa64 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -31,6 +31,7 @@ #include #include "connection.h" +#include "connection-avatars.h" #include "debug.h" G_DEFINE_TYPE (HazeProtocol, haze_protocol, TP_TYPE_BASE_PROTOCOL) @@ -995,6 +996,41 @@ haze_protocol_dup_authentication_types (TpBaseProtocol *base) } static void +haze_protocol_get_avatar_details (TpBaseProtocol *base, + GStrv *supported_mime_types, + guint *min_height, + guint *min_width, + guint *rec_height, + guint *rec_width, + guint *max_height, + guint *max_width, + guint *max_bytes) +{ + HazeProtocol *self = HAZE_PROTOCOL (base); + PurpleBuddyIconSpec *icon_spec; + + icon_spec = &(self->priv->prpl_info->icon_spec); + + if (icon_spec->format == NULL) + { + /* We don't support avatar for this protocol */ + *supported_mime_types = NULL; + *min_height = 0; + *min_width = 0; + *rec_height = 0; + *rec_width = 0; + *max_height = 0; + *max_width = 0; + *max_bytes = 0; + return; + } + + haze_connection_get_icon_spec_requirements (icon_spec, supported_mime_types, + min_height, min_width, rec_height, rec_width, max_height, max_width, + max_bytes); +} + +static void haze_protocol_class_init (HazeProtocolClass *cls) { GObjectClass *object_class = (GObjectClass *) cls; @@ -1009,6 +1045,7 @@ haze_protocol_class_init (HazeProtocolClass *cls) base_class->get_connection_details = haze_protocol_get_connection_details; base_class->dup_authentication_types = haze_protocol_dup_authentication_types; + base_class->get_avatar_details = haze_protocol_get_avatar_details; g_type_class_add_private (cls, sizeof (HazeProtocolPrivate)); object_class->get_property = haze_protocol_get_property; diff --git a/tests/twisted/cm/protocols.py b/tests/twisted/cm/protocols.py index d0c67ce..1e8d3a7 100644 --- a/tests/twisted/cm/protocols.py +++ b/tests/twisted/cm/protocols.py @@ -27,6 +27,7 @@ def test(q, bus, conn, stream): protocol_iface = dbus.Interface(protocol, cs.PROTOCOL) protocol_props = dbus.Interface(protocol, cs.PROPERTIES_IFACE) flat_props = protocol_props.GetAll(cs.PROTOCOL) + protocol_avatar_props = protocol_props.GetAll(cs.PROTOCOL_IFACE_AVATARS) # Protocol is supposed to implement Interface.Avatars iff the # connection implements Avatars as well. @@ -105,6 +106,16 @@ def test(q, bus, conn, stream): assertDoesNotContain(cs.CONN_IFACE_AVATARS, flat_props['ConnectionInterfaces']) assertDoesNotContain(cs.CONN_IFACE_CONTACT_BLOCKING, flat_props['ConnectionInterfaces']) assertDoesNotContain(cs.CONN_IFACE_MAIL_NOTIFICATION + '.DRAFT', flat_props['ConnectionInterfaces']) + + # Avatar not supported + assertEquals(0, protocol_avatar_props['MaximumAvatarBytes']) + assertEquals(0, protocol_avatar_props['MaximumAvatarHeight']) + assertEquals(0, protocol_avatar_props['MaximumAvatarWidth']) + assertEquals(0, protocol_avatar_props['MinimumAvatarHeight']) + assertEquals(0, protocol_avatar_props['MinimumAvatarWidth']) + assertEquals(0, protocol_avatar_props['RecommendedAvatarHeight']) + assertEquals(0, protocol_avatar_props['RecommendedAvatarWidth']) + assertEquals([], protocol_avatar_props['SupportedAvatarMIMETypes']) elif name == 'myspace': assertEquals('x-myspace', flat_props['VCardField']) assertEquals('im-myspace', flat_props['Icon']) @@ -154,6 +165,16 @@ def test(q, bus, conn, stream): assertContains(cs.CONN_IFACE_AVATARS, flat_props['ConnectionInterfaces']) assertContains(cs.CONN_IFACE_CONTACT_BLOCKING, flat_props['ConnectionInterfaces']) assertContains(cs.CONN_IFACE_MAIL_NOTIFICATION + '.DRAFT', flat_props['ConnectionInterfaces']) + + # libpurple currently says there's no max size + assertEquals(0, protocol_avatar_props['MaximumAvatarBytes']) + assertEquals(96, protocol_avatar_props['MaximumAvatarHeight']) + assertEquals(96, protocol_avatar_props['MaximumAvatarWidth']) + assertEquals(32, protocol_avatar_props['MinimumAvatarHeight']) + assertEquals(32, protocol_avatar_props['MinimumAvatarWidth']) + assertEquals(0, protocol_avatar_props['RecommendedAvatarHeight']) + assertEquals(0, protocol_avatar_props['RecommendedAvatarWidth']) + assertEquals(['image/png'], protocol_avatar_props['SupportedAvatarMIMETypes']) elif name == 'qq': assertEquals('x-qq', flat_props['VCardField']) assertEquals('im-qq', flat_props['Icon']) -- 1.8.3.1