diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2012-04-25 15:57:13 +0100 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2012-04-30 19:20:03 +0100 |
commit | 521799547ad4daf15d006a9ede630bcc7ff98f86 (patch) | |
tree | c70af4413bde4803756855c7bcb7e1283b7a3ee3 /telepathy-glib/capabilities.c | |
parent | 6cdfe94bfdb340455fa1c377fb807a45cbb265d1 (diff) | |
download | telepathy-glib-521799547ad4daf15d006a9ede630bcc7ff98f86.tar.gz |
Add and test functions to check for particular file transfer properties
These functions make the simplifying assumption that all of these
properties are orthogonal, so if both (say) InitialOffset and Description
are supported, then they'll be supported in the same requestable
channel class.
This is about the best you can do without exposing the
requestable channel classes themselves as API and having applications
iterate through them, which seems lower-level than we want.
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=48780
Diffstat (limited to 'telepathy-glib/capabilities.c')
-rw-r--r-- | telepathy-glib/capabilities.c | 166 |
1 files changed, 164 insertions, 2 deletions
diff --git a/telepathy-glib/capabilities.c b/telepathy-glib/capabilities.c index 72f14a430..5f1b85d58 100644 --- a/telepathy-glib/capabilities.c +++ b/telepathy-glib/capabilities.c @@ -571,6 +571,95 @@ tp_capabilities_supports_audio_video_call (TpCapabilities *self, return supports_call_full (self, handle_type, TRUE, TRUE); } +typedef enum { + FT_CAP_FLAGS_NONE = 0, + FT_CAP_FLAG_URI = (1<<0), + FT_CAP_FLAG_OFFSET = (1<<1), + FT_CAP_FLAG_DATE = (1<<2), + FT_CAP_FLAG_DESCRIPTION = (1<<3) +} FTCapFlags; + +static gboolean +supports_file_transfer (TpCapabilities *self, + FTCapFlags flags) +{ + 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; + guint n_fixed = 2; + const gchar * const *allowed; + + tp_value_array_unpack (arr, 2, &fixed, &allowed); + + chan_type = tp_asv_get_string (fixed, TP_PROP_CHANNEL_CHANNEL_TYPE); + + if (tp_strdiff (chan_type, TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER)) + continue; + + 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; + + /* ContentType, Filename, Size are mandatory. In principle we could check + * that the CM allows them, but not allowing them would be ridiculous, + * so we don't. + */ + + if ((flags & FT_CAP_FLAG_DESCRIPTION) != 0) + { + /* Description makes no sense as a fixed property so we assume + * the CM won't be ridiculous */ + if (!tp_strv_contains (allowed, + TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_DESCRIPTION)) + continue; + } + + if ((flags & FT_CAP_FLAG_DATE) != 0) + { + /* makes no sense as a fixed property */ + if (!tp_strv_contains (allowed, + TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_DATE)) + continue; + } + + if ((flags & FT_CAP_FLAG_URI) != 0) + { + /* makes no sense as a fixed property */ + if (!tp_strv_contains (allowed, + TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_URI)) + continue; + } + + if ((flags & FT_CAP_FLAG_OFFSET) != 0) + { + /* makes no sense as a fixed property */ + if (!tp_strv_contains (allowed, + TP_PROP_CHANNEL_TYPE_FILE_TRANSFER_INITIAL_OFFSET)) + continue; + } + + if (n_fixed != tp_asv_size (fixed)) + continue; + + return TRUE; + } + + return FALSE; +} + /** * tp_capabilities_supports_file_transfer: * @self: a #TpCapabilities object @@ -587,8 +676,81 @@ tp_capabilities_supports_audio_video_call (TpCapabilities *self, gboolean tp_capabilities_supports_file_transfer (TpCapabilities *self) { - return supports_simple_channel (self, TP_IFACE_CHANNEL_TYPE_FILE_TRANSFER, - TP_HANDLE_TYPE_CONTACT); + return supports_file_transfer (self, FT_CAP_FLAGS_NONE); +} + +/** + * tp_capabilities_supports_file_transfer_uri: + * @self: a #TpCapabilities object + * + * <!-- --> + * + * Returns: %TRUE if requests as described for + * tp_capabilities_supports_file_transfer() can also specify the outgoing + * file's URI + * + * Since: 0.19.UNRELEASED + */ +gboolean +tp_capabilities_supports_file_transfer_uri (TpCapabilities *self) +{ + return supports_file_transfer (self, FT_CAP_FLAG_URI); +} + +/** + * tp_capabilities_supports_file_transfer_description: + * @self: a #TpCapabilities object + * + * <!-- --> + * + * Returns: %TRUE if requests as described for + * tp_capabilities_supports_file_transfer() can also specify the outgoing + * file's description + * + * Since: 0.19.UNRELEASED + */ +gboolean +tp_capabilities_supports_file_transfer_description (TpCapabilities *self) +{ + return supports_file_transfer (self, FT_CAP_FLAG_DESCRIPTION); +} + +/** + * tp_capabilities_supports_file_transfer_initial_offset: + * @self: a #TpCapabilities object + * + * Return whether an initial offset other than 0 can be specified on + * outgoing file transfers. This can be used to resume partial transfers, + * by omitting the part that has already been sent. + * + * Returns: %TRUE if requests as described for + * tp_capabilities_supports_file_transfer() can also specify an + * initial offset greater than 0 + * + * Since: 0.19.UNRELEASED + */ +gboolean +tp_capabilities_supports_file_transfer_initial_offset (TpCapabilities *self) +{ + return supports_file_transfer (self, FT_CAP_FLAG_OFFSET); +} + +/** + * tp_capabilities_supports_file_transfer_timestamp: + * @self: a #TpCapabilities object + * + * <!-- --> + * + * Returns: %TRUE if requests as described for + * tp_capabilities_supports_file_transfer() can also specify the outgoing + * file's timestamp + * + * Since: 0.19.UNRELEASED + */ +gboolean +tp_capabilities_supports_file_transfer_timestamp (TpCapabilities *self) +{ + return supports_file_transfer (self, FT_CAP_FLAG_DATE); } static gboolean |