From 96db60c2f708a46d292068aa300d2474c9ff8b65 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Tue, 10 Apr 2012 16:52:49 +0200 Subject: [PATCH] Add tp_capabilities_supports_sms() https://bugs.freedesktop.org/show_bug.cgi?id=48506 --- docs/reference/telepathy-glib-sections.txt | 1 + telepathy-glib/capabilities.c | 61 ++++++++++++++++++++++++++++ telepathy-glib/capabilities.h | 2 + tests/capabilities.c | 56 +++++++++++++++++++++++++ 4 files changed, 120 insertions(+), 0 deletions(-) diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index d5023dc..7e6e432 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -4933,6 +4933,7 @@ tp_capabilities_get_channel_classes tp_capabilities_is_specific_to_contact tp_capabilities_supports_text_chatrooms tp_capabilities_supports_text_chats +tp_capabilities_supports_sms tp_capabilities_supports_audio_call tp_capabilities_supports_audio_video_call tp_capabilities_supports_file_transfer diff --git a/telepathy-glib/capabilities.c b/telepathy-glib/capabilities.c index 66140b2..5a70477 100644 --- a/telepathy-glib/capabilities.c +++ b/telepathy-glib/capabilities.c @@ -360,6 +360,67 @@ tp_capabilities_supports_text_chatrooms (TpCapabilities *self) TP_HANDLE_TYPE_ROOM); } +/** + * tp_capabilities_supports_sms: + * @self: a #TpCapabilities object + * + * If the #TpCapabilities:contact-specific property is %FALSE, this function + * checks if SMS text channels can be requested with the connection associated + * with this #TpCapabilities. + * + * If the #TpCapabilities:contact-specific property is %TRUE, this function + * checks if the contact associated with this #TpCapabilities supports + * SMS text channels. + * + * Returns: %TRUE if a channel request containing Text as ChannelType, + * HandleTypeContact as TargetHandleType, a channel identifier and + * #TP_PROP_CHANNEL_INTERFACE_SMS_SMS_CHANNEL set to %TRUE can be + * expected to work, %FALSE otherwise. + * + * Since: 0.UNRELEASED + */ +gboolean +tp_capabilities_supports_sms (TpCapabilities *self) +{ + guint i; + + g_return_val_if_fail (TP_IS_CAPABILITIES (self), FALSE); + + for (i = 0; i < self->priv->classes->len; i++) + { + GValueArray *arr = g_ptr_array_index (self->priv->classes, i); + GHashTable *fixed; + const gchar *chan_type; + TpHandleType handle_type; + gboolean valid; + + fixed = g_value_get_boxed (g_value_array_get_nth (arr, 0)); + + handle_type = tp_asv_get_uint32 (fixed, + TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, &valid); + + if (!valid) + continue; + + if (handle_type != TP_HANDLE_TYPE_CONTACT) + continue; + + chan_type = tp_asv_get_string (fixed, TP_PROP_CHANNEL_CHANNEL_TYPE); + + if (tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_TEXT)) + continue; + + if (!tp_asv_get_boolean (fixed, TP_PROP_CHANNEL_INTERFACE_SMS_SMS_CHANNEL, + NULL)) + continue; + + return TRUE; + } + + return FALSE; + +} + static gboolean supports_call_full (TpCapabilities *self, TpHandleType expected_handle_type, diff --git a/telepathy-glib/capabilities.h b/telepathy-glib/capabilities.h index e283331..1d55c1a 100644 --- a/telepathy-glib/capabilities.h +++ b/telepathy-glib/capabilities.h @@ -54,6 +54,8 @@ gboolean tp_capabilities_is_specific_to_contact (TpCapabilities *self); gboolean tp_capabilities_supports_text_chats (TpCapabilities *self); gboolean tp_capabilities_supports_text_chatrooms (TpCapabilities *self); +gboolean tp_capabilities_supports_sms (TpCapabilities *self); + gboolean tp_capabilities_supports_audio_call (TpCapabilities *self, TpHandleType handle_type); gboolean tp_capabilities_supports_audio_video_call (TpCapabilities *self, diff --git a/tests/capabilities.c b/tests/capabilities.c index 01eac78..c6c43fc 100644 --- a/tests/capabilities.c +++ b/tests/capabilities.c @@ -177,6 +177,7 @@ test_supports (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)); + g_assert (!tp_capabilities_supports_sms (caps)); g_object_unref (caps); @@ -195,6 +196,7 @@ test_supports (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)); + g_assert (!tp_capabilities_supports_sms (caps)); g_object_unref (caps); @@ -214,6 +216,7 @@ test_supports (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)); + g_assert (!tp_capabilities_supports_sms (caps)); g_object_unref (caps); @@ -223,6 +226,7 @@ test_supports (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)); + g_assert (!tp_capabilities_supports_sms (caps)); classes = tp_capabilities_get_channel_classes (caps); g_assert_cmpuint (classes->len, ==, 0); @@ -651,6 +655,56 @@ test_supports_room_list (Test *test, g_object_unref (caps); } +static void +add_sms_class (GPtrArray *classes) +{ + GHashTable *fixed; + const gchar * const allowed[] = { + NULL }; + GValueArray *arr; + + fixed = tp_asv_new ( + TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, + TP_IFACE_CHANNEL_TYPE_TEXT, + TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, + TP_HANDLE_TYPE_CONTACT, + TP_PROP_CHANNEL_INTERFACE_SMS_SMS_CHANNEL, G_TYPE_BOOLEAN, + TRUE, + NULL); + + arr = tp_value_array_build (2, + TP_HASH_TYPE_STRING_VARIANT_MAP, fixed, + G_TYPE_STRV, allowed, + G_TYPE_INVALID); + + g_hash_table_unref (fixed); + + g_ptr_array_add (classes, arr); +} + +static void +test_supports_sms (Test *test, + gconstpointer data G_GNUC_UNUSED) +{ + TpCapabilities *caps; + GPtrArray *classes; + + classes = g_ptr_array_sized_new (1); + add_sms_class (classes); + + caps = tp_tests_object_new_static_class (TP_TYPE_CAPABILITIES, + "channel-classes", classes, + "contact-specific", FALSE, + NULL); + + g_boxed_free (TP_ARRAY_TYPE_REQUESTABLE_CHANNEL_CLASS_LIST, + classes); + + g_assert (tp_capabilities_supports_sms (caps)); + + g_object_unref (caps); +} + int main (int argc, char **argv) @@ -668,6 +722,8 @@ main (int argc, test_supports_tube, NULL); g_test_add (TEST_PREFIX "supports/room-list", Test, NULL, setup, test_supports_room_list, NULL); + g_test_add (TEST_PREFIX "supports/sms", Test, NULL, setup, + test_supports_sms, NULL); return g_test_run (); } -- 1.7.7.6