From ad16821aa7ab49a16a976edc52e045024fe713d6 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Mon, 11 Apr 2011 14:41:08 +0200 Subject: [PATCH] TpProtocol: add API to get avatars requirements (fdo #36049) --- docs/reference/telepathy-glib-sections.txt | 1 + telepathy-glib/protocol.c | 91 ++++++++++++++++++++ telepathy-glib/protocol.h | 3 + tests/dbus/protocol-objects.c | 43 +++++++++ .../telepathy/managers/test_manager_file.manager | 10 ++- 5 files changed, 147 insertions(+), 1 deletions(-) diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index 1e48f46..f0aa2b2 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -5085,6 +5085,7 @@ tp_protocol_get_english_name tp_protocol_get_icon_name tp_protocol_get_vcard_field tp_protocol_get_authentication_types +tp_protocol_get_avatar_requirements tp_cli_protocol_call_identify_account tp_cli_protocol_call_normalize_contact diff --git a/telepathy-glib/protocol.c b/telepathy-glib/protocol.c index de90100..db9bcb3 100644 --- a/telepathy-glib/protocol.c +++ b/telepathy-glib/protocol.c @@ -141,6 +141,7 @@ struct _TpProtocolPrivate gchar *icon_name; GStrv authentication_types; TpCapabilities *capabilities; + TpAvatarRequirements *avatar_req; }; enum @@ -153,6 +154,7 @@ enum PROP_CAPABILITIES, PROP_PARAM_NAMES, PROP_AUTHENTICATION_TYPES, + PROP_AVATAR_REQUIREMENTS, N_PROPS }; @@ -279,6 +281,10 @@ tp_protocol_get_property (GObject *object, g_value_set_boxed (value, tp_protocol_get_authentication_types (self)); break; + case PROP_AVATAR_REQUIREMENTS: + g_value_set_pointer (value, tp_protocol_get_avatar_requirements (self)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -357,6 +363,8 @@ tp_protocol_dispose (GObject *object) self->priv->authentication_types = NULL; } + tp_clear_pointer (&self->priv->avatar_req, tp_avatar_requirements_destroy); + if (dispose != NULL) dispose (object); } @@ -508,6 +516,28 @@ tp_protocol_constructed (GObject *object) tp_proxy_add_interfaces (proxy, interfaces); + if (tp_proxy_has_interface_by_id (self, + TP_IFACE_QUARK_PROTOCOL_INTERFACE_AVATARS)) + { + self->priv->avatar_req = tp_avatar_requirements_new ( + (GStrv) tp_asv_get_strv (self->priv->protocol_properties, + TP_PROP_PROTOCOL_INTERFACE_AVATARS_SUPPORTED_AVATAR_MIME_TYPES), + tp_asv_get_uint32 (self->priv->protocol_properties, + TP_PROP_PROTOCOL_INTERFACE_AVATARS_MINIMUM_AVATAR_WIDTH, NULL), + tp_asv_get_uint32 (self->priv->protocol_properties, + TP_PROP_PROTOCOL_INTERFACE_AVATARS_MINIMUM_AVATAR_HEIGHT, NULL), + tp_asv_get_uint32 (self->priv->protocol_properties, + TP_PROP_PROTOCOL_INTERFACE_AVATARS_RECOMMENDED_AVATAR_WIDTH, NULL), + tp_asv_get_uint32 (self->priv->protocol_properties, + TP_PROP_PROTOCOL_INTERFACE_AVATARS_RECOMMENDED_AVATAR_HEIGHT, NULL), + tp_asv_get_uint32 (self->priv->protocol_properties, + TP_PROP_PROTOCOL_INTERFACE_AVATARS_MAXIMUM_AVATAR_WIDTH, NULL), + tp_asv_get_uint32 (self->priv->protocol_properties, + TP_PROP_PROTOCOL_INTERFACE_AVATARS_MAXIMUM_AVATAR_HEIGHT, NULL), + tp_asv_get_uint32 (self->priv->protocol_properties, + TP_PROP_PROTOCOL_INTERFACE_AVATARS_MAXIMUM_AVATAR_BYTES, NULL)); + } + /* become ready immediately */ _tp_proxy_set_feature_prepared (proxy, TP_PROTOCOL_FEATURE_PARAMETERS, had_immutables); @@ -691,6 +721,21 @@ tp_protocol_class_init (TpProtocolClass *klass) "A list of authentication types", G_TYPE_STRV, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + /** + * TpProtocol:avatar-requirements: + * + * A #TpAvatarRequirements representing the avatar requirements on this + * protocol, or %NULL if %TP_PROTOCOL_FEATURE_CORE has not been prepared or + * if the protocol doesn't support avatars. + * + * Since: 0.15.UNRELEASED + */ + g_object_class_install_property (object_class, PROP_AVATAR_REQUIREMENTS, + g_param_spec_pointer ("avatar-requirements", + "Avatars requirements", + "Avatars requirements", + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); + proxy_class->list_features = tp_protocol_list_features; proxy_class->must_have_unique_name = FALSE; proxy_class->interface = TP_IFACE_QUARK_PROTOCOL; @@ -1461,6 +1506,34 @@ _tp_protocol_parse_manager_file (GKeyFile *file, G_TYPE_STRV, g_key_file_get_string_list (file, group, "AuthenticationTypes", NULL, NULL)); + /* Avatars */ + tp_asv_take_boxed (immutables, + TP_PROP_PROTOCOL_INTERFACE_AVATARS_SUPPORTED_AVATAR_MIME_TYPES, + G_TYPE_STRV, + g_key_file_get_string_list (file, group, "SupportedAvatarMIMETypes", + NULL, NULL)); + tp_asv_set_uint32 (immutables, + TP_PROP_PROTOCOL_INTERFACE_AVATARS_MINIMUM_AVATAR_HEIGHT, + g_key_file_get_uint64 (file, group, "MinimumAvatarHeight", NULL)); + tp_asv_set_uint32 (immutables, + TP_PROP_PROTOCOL_INTERFACE_AVATARS_MINIMUM_AVATAR_WIDTH, + g_key_file_get_uint64 (file, group, "MinimumAvatarWidth", NULL)); + tp_asv_set_uint32 (immutables, + TP_PROP_PROTOCOL_INTERFACE_AVATARS_RECOMMENDED_AVATAR_HEIGHT, + g_key_file_get_uint64 (file, group, "RecommendedAvatarHeight", NULL)); + tp_asv_set_uint32 (immutables, + TP_PROP_PROTOCOL_INTERFACE_AVATARS_RECOMMENDED_AVATAR_WIDTH, + g_key_file_get_uint64 (file, group, "RecommendedAvatarWidth", NULL)); + tp_asv_set_uint32 (immutables, + TP_PROP_PROTOCOL_INTERFACE_AVATARS_MAXIMUM_AVATAR_HEIGHT, + g_key_file_get_uint64 (file, group, "MaximumAvatarHeight", NULL)); + tp_asv_set_uint32 (immutables, + TP_PROP_PROTOCOL_INTERFACE_AVATARS_MAXIMUM_AVATAR_WIDTH, + g_key_file_get_uint64 (file, group, "MaximumAvatarWidth", NULL)); + tp_asv_set_uint32 (immutables, + TP_PROP_PROTOCOL_INTERFACE_AVATARS_MAXIMUM_AVATAR_BYTES, + g_key_file_get_uint64 (file, group, "MaximumAvatarBytes", NULL)); + rccs = g_ptr_array_new (); rcc_groups = g_key_file_get_string_list (file, group, @@ -1482,3 +1555,21 @@ _tp_protocol_parse_manager_file (GKeyFile *file, return immutables; } + +/** + * tp_protocol_get_avatar_requirements + * @self: a #TpProtocol + * + * Return the #TpProtocol:avatar-requirements property + * + * Returns: (transfer none): the value of #TpProtocol:avatar-requirements + * + * Since: 0.15.UNRELEASED + */ +TpAvatarRequirements * +tp_protocol_get_avatar_requirements (TpProtocol *self) +{ + g_return_val_if_fail (TP_IS_PROTOCOL (self), NULL); + + return self->priv->avatar_req; +} diff --git a/telepathy-glib/protocol.h b/telepathy-glib/protocol.h index edc2635..8b25390 100644 --- a/telepathy-glib/protocol.h +++ b/telepathy-glib/protocol.h @@ -23,6 +23,7 @@ #include #include +#include #include G_BEGIN_DECLS @@ -102,6 +103,8 @@ const gchar *tp_protocol_get_english_name (TpProtocol *self); const gchar *tp_protocol_get_icon_name (TpProtocol *self); TpCapabilities *tp_protocol_get_capabilities (TpProtocol *self); +TpAvatarRequirements * tp_protocol_get_avatar_requirements (TpProtocol *self); + G_END_DECLS #include diff --git a/tests/dbus/protocol-objects.c b/tests/dbus/protocol-objects.c index ecea32f..13a4e94 100644 --- a/tests/dbus/protocol-objects.c +++ b/tests/dbus/protocol-objects.c @@ -325,9 +325,34 @@ test_protocols_property_old (Test *test, } static void +check_avatar_requirements (TpAvatarRequirements *req) +{ + g_assert (req != NULL); + + g_assert (req->supported_mime_types != NULL); + g_assert_cmpuint (g_strv_length (req->supported_mime_types), ==, 3); + g_assert (tp_strv_contains ((const gchar * const *) req->supported_mime_types, + "image/png")); + g_assert (tp_strv_contains ((const gchar * const *) req->supported_mime_types, + "image/jpeg")); + g_assert (tp_strv_contains ((const gchar * const *) req->supported_mime_types, + "image/gif")); + + g_assert_cmpuint (req->minimum_width, ==, 32); + g_assert_cmpuint (req->minimum_height, ==, 32); + g_assert_cmpuint (req->recommended_width, ==, 64); + g_assert_cmpuint (req->recommended_height, ==, 64); + g_assert_cmpuint (req->maximum_width, ==, 96); + g_assert_cmpuint (req->maximum_height, ==, 96); + g_assert_cmpuint (req->maximum_bytes, ==, 37748736); +} + +static void test_protocol_object (Test *test, gconstpointer data G_GNUC_UNUSED) { + TpAvatarRequirements *req; + g_assert_cmpstr (tp_connection_manager_get_name (test->cm), ==, "example_echo_2"); tp_tests_proxy_run_until_prepared (test->cm, NULL); @@ -357,12 +382,20 @@ test_protocol_object (Test *test, "x-telepathy-example"); g_assert (TP_IS_CAPABILITIES (tp_protocol_get_capabilities ( test->protocol))); + + req = tp_protocol_get_avatar_requirements (test->protocol); + check_avatar_requirements (req); + + g_object_get (test->protocol, "avatar-requirements", &req, NULL); + check_avatar_requirements (req); } static void test_protocol_object_old (Test *test, gconstpointer data G_GNUC_UNUSED) { + TpAvatarRequirements *req; + g_assert_cmpstr (tp_connection_manager_get_name (test->old_cm), ==, "example_echo"); tp_tests_proxy_run_until_prepared (test->old_cm, NULL); @@ -386,6 +419,9 @@ test_protocol_object_old (Test *test, "Example"); g_assert_cmpstr (tp_protocol_get_vcard_field (test->old_protocol), ==, NULL); g_assert (tp_protocol_get_capabilities (test->old_protocol) == NULL); + + req = tp_protocol_get_avatar_requirements (test->old_protocol); + g_assert (req == NULL); } static void @@ -394,6 +430,7 @@ test_protocol_object_from_file (Test *test, { GQuark features[] = { TP_PROTOCOL_FEATURE_CORE, 0 }; TpCapabilities *caps; + TpAvatarRequirements *req; g_assert_cmpstr (tp_connection_manager_get_name (test->file_cm), ==, "test_manager_file"); @@ -425,6 +462,12 @@ test_protocol_object_from_file (Test *test, g_assert (!tp_capabilities_is_specific_to_contact (caps)); g_assert (tp_capabilities_supports_text_chats (caps)); g_assert (!tp_capabilities_supports_text_chatrooms (caps)); + + req = tp_protocol_get_avatar_requirements (test->file_protocol); + check_avatar_requirements (req); + + g_object_get (test->file_protocol, "avatar-requirements", &req, NULL); + check_avatar_requirements (req); } int diff --git a/tests/dbus/telepathy/managers/test_manager_file.manager b/tests/dbus/telepathy/managers/test_manager_file.manager index 85fe6da..b1629d1 100644 --- a/tests/dbus/telepathy/managers/test_manager_file.manager +++ b/tests/dbus/telepathy/managers/test_manager_file.manager @@ -11,12 +11,20 @@ param-server-list = as default-account = foo@default default-port = 1234 default-server-list = foo;bar; -Interfaces= +Interfaces=org.freedesktop.Telepathy.Protocol.Interface.Avatars; ConnectionInterfaces=org.freedesktop.Telepathy.Connection.Interface.Requests;org.freedesktop.Telepathy.Connection.Interface.Contacts; RequestableChannelClasses=1-1-text; VCardField=x-telepathy-tests EnglishName=Regression tests Icon=im-icq +SupportedAvatarMIMETypes=image/png;image/jpeg;image/gif; +MinimumAvatarHeight=32 +RecommendedAvatarHeight=64 +MaximumAvatarHeight=96 +MinimumAvatarWidth=32 +RecommendedAvatarWidth=64 +MaximumAvatarWidth=96 +MaximumAvatarBytes=37748736 [1-1-text] org.freedesktop.Telepathy.Channel.ChannelType s=org.freedesktop.Telepathy.Channel.Type.Text -- 1.7.4.1