diff options
author | Alban Crequy <alban.crequy@collabora.co.uk> | 2012-02-25 19:31:05 +0000 |
---|---|---|
committer | Alban Crequy <alban.crequy@collabora.co.uk> | 2012-03-27 17:46:48 +0100 |
commit | 8bde24822f73aeb9ec66f719d3066673d41d1c08 (patch) | |
tree | 4ffc11a7233205fdf9cf3f6e7f0a581d53cd2c2e | |
parent | aa1d2196aa5291af961d4ceff36507773a5393c0 (diff) | |
download | telepathy-glib-8bde24822f73aeb9ec66f719d3066673d41d1c08.tar.gz |
ContactList: add method Download in TpBaseContactList
https://bugs.freedesktop.org/show_bug.cgi?id=43826
-rw-r--r-- | docs/reference/telepathy-glib-sections.txt | 3 | ||||
-rw-r--r-- | telepathy-glib/base-contact-list.c | 115 | ||||
-rw-r--r-- | telepathy-glib/base-contact-list.h | 22 |
3 files changed, 139 insertions, 1 deletions
diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt index 9f9e3c00a..af1ced253 100644 --- a/docs/reference/telepathy-glib-sections.txt +++ b/docs/reference/telepathy-glib-sections.txt @@ -6073,7 +6073,10 @@ tp_base_contact_list_dup_contacts TpBaseContactListDupStatesFunc tp_base_contact_list_dup_states TpBaseContactListUIntFunc +TpBaseContactListAsyncFunc TpBaseContactListAsyncFinishFunc +tp_base_contact_list_download_async +tp_base_contact_list_download_finish <SUBSECTION changes> TP_TYPE_MUTABLE_CONTACT_LIST TpMutableContactListInterface diff --git a/telepathy-glib/base-contact-list.c b/telepathy-glib/base-contact-list.c index 7f4b47620..fcdc069b2 100644 --- a/telepathy-glib/base-contact-list.c +++ b/telepathy-glib/base-contact-list.c @@ -140,6 +140,12 @@ * tp_base_contact_list_get_contact_list_persists(); if a subclass does not * implement this itself, the default implementation always returns %TRUE, * which is correct for most protocols + * @download_async: the implementation of + * tp_base_contact_list_download_async(); if a subclass does not implement + * this itself, the default implementation will raise + * TP_ERROR_NOT_IMPLEMENTED asynchronously. Since: 0.UNRELEASED + * @download_finish: the implementation of + * tp_base_contact_list_download_finish(). Since: 0.UNRELEASED * * The class of a #TpBaseContactList. * @@ -191,6 +197,17 @@ */ /** + * TpBaseContactListAsyncFunc: + * @self: the contact list manager + * @callback: a callback to call on success, failure or disconnection + * @user_data: user data for the callback + * + * Signature of a virtual method that needs no additional information. + * + * Since: 0.UNRELEASED + */ + +/** * TpBaseContactListActOnContactsFunc: * @self: the contact list manager * @contacts: the contacts on which to act @@ -747,6 +764,7 @@ tp_base_contact_list_constructed (GObject *object) g_return_if_fail (cls->dup_contacts != NULL); g_return_if_fail (cls->dup_states != NULL); g_return_if_fail (cls->get_contact_list_persists != NULL); + g_return_if_fail (cls->download_async != NULL); self->priv->svc_contact_list = TP_IS_SVC_CONNECTION_INTERFACE_CONTACT_LIST (self->priv->conn); @@ -860,6 +878,16 @@ tp_base_contact_list_simple_finish (TpBaseContactList *self, } static void +tp_base_contact_list_download_async_default (TpBaseContactList *self, + GAsyncReadyCallback callback, + gpointer user_data) +{ + g_simple_async_report_error_in_idle (G_OBJECT (self), callback, + user_data, TP_ERRORS, TP_ERROR_NOT_IMPLEMENTED, + "This CM does not implement Download"); +} + +static void tp_mutable_contact_list_default_init (TpMutableContactListInterface *iface) { iface->request_subscription_finish = tp_base_contact_list_simple_finish; @@ -920,6 +948,8 @@ tp_base_contact_list_class_init (TpBaseContactListClass *cls) /* defaults */ cls->get_contact_list_persists = tp_base_contact_list_true_func; + cls->download_async = tp_base_contact_list_download_async_default; + cls->download_finish = tp_base_contact_list_simple_finish; object_class->get_property = tp_base_contact_list_get_property; object_class->set_property = tp_base_contact_list_set_property; @@ -3126,6 +3156,65 @@ tp_base_contact_list_get_contact_list_persists (TpBaseContactList *self) } /** + * tp_base_contact_list_download_async: + * @self: a contact list manager + * @callback: a callback to call when the operation succeeds or fails + * @user_data: optional data to pass to @callback + * + * Download the contact list when it is not done automatically at + * connection. + * + * If the #TpBaseContactList subclass does not override + * download_async, the default implementation will raise + * TP_ERROR_NOT_IMPLEMENTED asynchronously. + * + * Since: 0.UNRELEASED + */ +void +tp_base_contact_list_download_async (TpBaseContactList *self, + GAsyncReadyCallback callback, + gpointer user_data) +{ + TpBaseContactListClass *cls = TP_BASE_CONTACT_LIST_GET_CLASS (self); + + g_return_if_fail (cls != NULL); + g_return_if_fail (cls->download_async != NULL); + + return cls->download_async (self, callback, user_data); +} + +/** + * tp_base_contact_list_download_finish: + * @self: a contact list manager + * @result: the result passed to @callback by an implementation of + * tp_base_contact_list_download_async() + * @error: used to raise an error if %FALSE is returned + * + * Interpret the result of an asynchronous call to + * tp_base_contact_list_download_async(). + * + * This is a virtual method which may be implemented using + * #TpContactListClass.download_finish. If the @result + * will be a #GSimpleAsyncResult, the default implementation may be used. + * + * Returns: %TRUE on success or %FALSE on error + * + * Since: 0.UNRELEASED + */ +gboolean +tp_base_contact_list_download_finish (TpBaseContactList *self, + GAsyncResult *result, + GError **error) +{ + TpBaseContactListClass *cls = TP_BASE_CONTACT_LIST_GET_CLASS (self); + + g_return_val_if_fail (cls != NULL, FALSE); + g_return_val_if_fail (cls->download_finish != NULL, FALSE); + + return cls->download_finish (self, result, error); +} + +/** * tp_base_contact_list_get_request_uses_message: * @self: a contact list manager * @@ -5330,6 +5419,31 @@ tp_base_contact_list_fill_list_contact_attributes (GObject *obj, } } +static void +tp_base_contact_list_mixin_download_cb (GObject *source, + GAsyncResult *result, + gpointer context) +{ + TpBaseContactList *self = TP_BASE_CONTACT_LIST (source); + GError *error = NULL; + + tp_base_contact_list_download_finish (self, result, &error); + tp_base_contact_list_mixin_return_void (context, error); + g_clear_error (&error); +} + +static void +tp_base_contact_list_mixin_download ( + TpSvcConnectionInterfaceContactList *svc, + DBusGMethodInvocation *context) +{ + TpBaseContactList *self = _tp_base_connection_find_channel_manager ( + (TpBaseConnection *) svc, TP_TYPE_BASE_CONTACT_LIST); + + tp_base_contact_list_download_async (self, + tp_base_contact_list_mixin_download_cb, context); +} + /** * tp_base_contact_list_mixin_list_iface_init: * @klass: the service-side D-Bus interface @@ -5354,6 +5468,7 @@ tp_base_contact_list_mixin_list_iface_init ( IMPLEMENT (remove_contacts); IMPLEMENT (unsubscribe); IMPLEMENT (unpublish); + IMPLEMENT (download); #undef IMPLEMENT } diff --git a/telepathy-glib/base-contact-list.h b/telepathy-glib/base-contact-list.h index 1511673a4..bc9b59912 100644 --- a/telepathy-glib/base-contact-list.h +++ b/telepathy-glib/base-contact-list.h @@ -112,6 +112,23 @@ void tp_base_contact_list_dup_states (TpBaseContactList *self, TpSubscriptionState *publish, gchar **publish_request); +typedef void (*TpBaseContactListAsyncFunc) ( + TpBaseContactList *self, + GAsyncReadyCallback callback, + gpointer user_data); + +void tp_base_contact_list_download_async (TpBaseContactList *self, + GAsyncReadyCallback callback, + gpointer user_data); + +gboolean tp_base_contact_list_download_finish (TpBaseContactList *self, + GAsyncResult *result, + GError **error); + +typedef gboolean (*TpBaseContactListAsyncFinishFunc) (TpBaseContactList *self, + GAsyncResult *result, + GError **error); + struct _TpBaseContactListClass { GObjectClass parent_class; @@ -119,8 +136,11 @@ struct _TpBaseContactListClass { TpBaseContactListDupStatesFunc dup_states; TpBaseContactListBooleanFunc get_contact_list_persists; + TpBaseContactListAsyncFunc download_async; + TpBaseContactListAsyncFinishFunc download_finish; + /*<private>*/ - GCallback _padding[7]; + GCallback _padding[5]; TpBaseContactListClassPrivate *priv; }; |