diff options
author | Alban Crequy <alban.crequy@collabora.co.uk> | 2011-12-13 12:16:07 +0000 |
---|---|---|
committer | Alban Crequy <alban.crequy@collabora.co.uk> | 2012-03-27 19:47:36 +0100 |
commit | 45d81af51417a79bd2fd7c98b0980ba7e725dd5c (patch) | |
tree | 100b5b53c1ea9e9985dce3679f3a949f8f60b058 | |
parent | deb67c35893b1770533eb48c4e7ec0840afc8926 (diff) |
ContactList: downloading the roster at connection depends on a connection parameter
https://bugs.freedesktop.org/show_bug.cgi?id=43828
-rw-r--r-- | src/connection.c | 37 | ||||
-rw-r--r-- | src/protocol.c | 8 | ||||
-rw-r--r-- | src/roster.c | 58 |
3 files changed, 96 insertions, 7 deletions
diff --git a/src/connection.c b/src/connection.c index a7c187bbe..c1e5946c5 100644 --- a/src/connection.c +++ b/src/connection.c @@ -183,6 +183,7 @@ enum PROP_FALLBACK_SERVERS, PROP_EXTRA_CERTIFICATE_IDENTITIES, PROP_POWER_SAVING, + PROP_DOWNLOAD_AT_CONNECTION, LAST_PROPERTY }; @@ -679,6 +680,23 @@ gabble_connection_get_property (GObject *object, g_value_set_boolean (value, priv->power_saving); break; + case PROP_DOWNLOAD_AT_CONNECTION: + { + gboolean download_at_connection = TRUE; + if (self->roster != NULL) + { + g_object_get (self->roster, + "download-at-connection", &download_at_connection, + NULL); + } + else + { + g_warn_if_reached (); + } + g_value_set_boolean (value, download_at_connection); + break; + } + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -820,6 +838,16 @@ gabble_connection_set_property (GObject *object, priv->power_saving = g_value_get_boolean (value); break; + case PROP_DOWNLOAD_AT_CONNECTION: + /* Connection parameters are set by TpBaseProtocolClass->new_connection + * after the channel managers are created. So at this step self->roster + * is not NULL and we pass the property. + */ + if (self->roster != NULL) + g_object_set (self->roster, "download-at-connection", + g_value_get_boolean (value), NULL); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -1177,6 +1205,15 @@ gabble_connection_class_init (GabbleConnectionClass *gabble_connection_class) FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + g_object_class_install_property ( + object_class, PROP_DOWNLOAD_AT_CONNECTION, + g_param_spec_boolean ( + "download-roster-at-connection", + "Download the contact list at connection?", + "Download the contact list at connection?", + TRUE, + G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + g_object_class_install_property (object_class, PROP_FALLBACK_SERVERS, g_param_spec_boxed ( "fallback-servers", "Fallback servers", diff --git a/src/protocol.c b/src/protocol.c index b1e1952f3..144521993 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -158,6 +158,12 @@ static TpCMParamSpec jabber_params[] = { TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT, GUINT_TO_POINTER (30), 0 /* unused */, NULL, NULL }, + { TP_PROP_CONNECTION_INTERFACE_CONTACT_LIST_DOWNLOAD_AT_CONNECTION, + DBUS_TYPE_BOOLEAN_AS_STRING, G_TYPE_BOOLEAN, + TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT | TP_CONN_MGR_PARAM_FLAG_DBUS_PROPERTY, + GUINT_TO_POINTER (TRUE), + 0 /* unused */, NULL, NULL }, + { GABBLE_PROP_CONNECTION_INTERFACE_GABBLE_DECLOAK_DECLOAK_AUTOMATICALLY, DBUS_TYPE_BOOLEAN_AS_STRING, G_TYPE_BOOLEAN, TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT | @@ -245,6 +251,8 @@ struct ParamMapping { SAME ("alias"), SAME ("fallback-socks5-proxies"), SAME ("keepalive-interval"), + MAP (TP_PROP_CONNECTION_INTERFACE_CONTACT_LIST_DOWNLOAD_AT_CONNECTION, + "download-roster-at-connection"), MAP (GABBLE_PROP_CONNECTION_INTERFACE_GABBLE_DECLOAK_DECLOAK_AUTOMATICALLY, "decloak-automatically"), SAME ("fallback-servers"), diff --git a/src/roster.c b/src/roster.c index 02b2e91ce..7bd6758f4 100644 --- a/src/roster.c +++ b/src/roster.c @@ -1795,19 +1795,28 @@ connection_status_changed_cb (GabbleConnection *conn, case TP_CONNECTION_STATUS_CONNECTED: { WockyStanza *stanza; + TpBaseContactList *base = TP_BASE_CONTACT_LIST (self); self->priv->cancel_on_disconnect = g_cancellable_new (); - DEBUG ("requesting roster"); + if (tp_base_contact_list_get_download_at_connection (base)) + { + DEBUG ("requesting roster"); - stanza = _gabble_roster_message_new (self, WOCKY_STANZA_SUB_TYPE_GET, - NULL); + stanza = _gabble_roster_message_new (self, WOCKY_STANZA_SUB_TYPE_GET, + NULL); - conn_util_send_iq_async (conn, stanza, - self->priv->cancel_on_disconnect, - roster_received_cb, tp_weak_ref_new (self, NULL, NULL)); + conn_util_send_iq_async (conn, stanza, + self->priv->cancel_on_disconnect, + roster_received_cb, tp_weak_ref_new (self, NULL, NULL)); - g_object_unref (stanza); + g_object_unref (stanza); + } + else + { + DEBUG ("don't request the roster because the property" + " ContactList.DownloadAtConnection is FALSE"); + } } break; @@ -2957,6 +2966,40 @@ gabble_roster_unpublish_async (TpBaseContactList *base, tp_handle_set_destroy (removed); } +static void +gabble_roster_download_async (TpBaseContactList *base, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GabbleRoster *self = GABBLE_ROSTER (base); + GError *error = NULL; + + if (!tp_base_contact_list_get_download_at_connection (base)) + { + WockyStanza *stanza; + + DEBUG ("Downloading roster requested"); + + stanza = _gabble_roster_message_new (self, WOCKY_STANZA_SUB_TYPE_GET, + NULL); + + conn_util_send_iq_async (self->priv->conn, stanza, + self->priv->cancel_on_disconnect, + roster_received_cb, tp_weak_ref_new (self, NULL, NULL)); + + g_object_unref (stanza); + } + else + { + DEBUG ("Downloading roster requested but it is already requested at " + "connection. Just do nothing and return."); + } + + gabble_simple_async_succeed_or_fail_in_idle (self, callback, user_data, + gabble_roster_download_async, error); + g_clear_error (&error); +} + static TpHandleSet * gabble_roster_dup_blocked_contacts (TpBaseContactList *base) { @@ -3541,6 +3584,7 @@ gabble_roster_class_init (GabbleRosterClass *cls) base_class->dup_states = gabble_roster_dup_states; base_class->dup_contacts = gabble_roster_dup_contacts; + base_class->download_async = gabble_roster_download_async; signals[NICKNAMES_UPDATE] = g_signal_new ( "nicknames-update", |