[evolution-ews] Bug 691293 - Claim old resources in offline mode
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-ews] Bug 691293 - Claim old resources in offline mode
- Date: Thu, 6 Nov 2014 13:24:50 +0000 (UTC)
commit 96be82f43d6d0c256fe3bba864e71a2645fc7494
Author: Milan Crha <mcrha redhat com>
Date: Thu Nov 6 14:23:54 2014 +0100
Bug 691293 - Claim old resources in offline mode
src/addressbook/e-book-backend-ews.c | 24 +++++++--
src/calendar/e-cal-backend-ews.c | 14 +++---
src/collection/e-ews-backend.c | 89 +++++++++++++++++++--------------
3 files changed, 76 insertions(+), 51 deletions(-)
---
diff --git a/src/addressbook/e-book-backend-ews.c b/src/addressbook/e-book-backend-ews.c
index 5b35820..43beef1 100644
--- a/src/addressbook/e-book-backend-ews.c
+++ b/src/addressbook/e-book-backend-ews.c
@@ -3315,6 +3315,17 @@ e_book_backend_ews_start_view (EBookBackend *backend,
E_BACKEND (backend),
E_SOURCE_AUTHENTICATOR (backend),
cancellable, &error);
+ if (g_error_matches (error, EWS_CONNECTION_ERROR, EWS_CONNECTION_ERROR_NORESPONSE)) {
+ /* possibly server unreachable, try offline */
+ if (priv->summary)
+ e_book_sqlite_get_key_value_int (priv->summary, E_BOOK_SQL_IS_POPULATED_KEY,
&is_populated, NULL);
+ if (is_populated) {
+ g_clear_error (&error);
+ fetch_from_offline (ebews, book_view, query, cancellable, &error);
+ goto out;
+ }
+ }
+
if (error != NULL)
goto out;
}
@@ -3900,7 +3911,7 @@ e_book_backend_ews_open_sync (EBookBackend *backend,
ews_settings = book_backend_ews_get_collection_settings (ebews);
PRIV_LOCK (priv);
- need_to_authenticate = priv->cnc == NULL && e_backend_get_online (E_BACKEND (backend));
+ need_to_authenticate = priv->cnc == NULL && e_backend_is_destination_reachable (E_BACKEND (backend),
cancellable, NULL);
PRIV_UNLOCK (priv);
@@ -3929,11 +3940,6 @@ e_book_backend_ews_open_sync (EBookBackend *backend,
if (priv->listen_notifications)
ebews_listen_notifications_cb (ebews, NULL, ews_settings);
- g_signal_connect_swapped (
- priv->cnc,
- "server-notification",
- G_CALLBACK (ebews_server_notification_cb),
- ebews);
PRIV_UNLOCK (priv);
g_signal_connect_swapped (
@@ -4159,6 +4165,12 @@ book_backend_ews_try_password_sync (ESourceAuthenticator *authenticator,
backend->priv->cnc = g_object_ref (connection);
backend->priv->is_writable = !backend->priv->is_gal;
+ g_signal_connect_swapped (
+ backend->priv->cnc,
+ "server-notification",
+ G_CALLBACK (ebews_server_notification_cb),
+ backend);
+
PRIV_UNLOCK (backend->priv);
e_backend_set_online (E_BACKEND (backend), TRUE);
diff --git a/src/calendar/e-cal-backend-ews.c b/src/calendar/e-cal-backend-ews.c
index 5f502c4..761948d 100644
--- a/src/calendar/e-cal-backend-ews.c
+++ b/src/calendar/e-cal-backend-ews.c
@@ -780,7 +780,7 @@ e_cal_backend_ews_open (ECalBackend *backend,
need_to_authenticate =
(priv->cnc == NULL) &&
- (e_backend_get_online (E_BACKEND (backend)));
+ (e_backend_is_destination_reachable (E_BACKEND (backend), cancellable, NULL));
PRIV_UNLOCK (priv);
@@ -799,12 +799,6 @@ e_cal_backend_ews_open (ECalBackend *backend,
if (priv->listen_notifications)
cbews_listen_notifications_cb (cbews, NULL, ews_settings);
-
- g_signal_connect_swapped (
- priv->cnc,
- "server-notification",
- G_CALLBACK (cbews_server_notification_cb),
- cbews);
}
PRIV_UNLOCK (priv);
}
@@ -4247,6 +4241,12 @@ cal_backend_ews_try_password_sync (ESourceAuthenticator *authenticator,
g_object_unref (backend->priv->cnc);
backend->priv->cnc = g_object_ref (connection);
+ g_signal_connect_swapped (
+ backend->priv->cnc,
+ "server-notification",
+ G_CALLBACK (cbews_server_notification_cb),
+ backend);
+
PRIV_UNLOCK (backend->priv);
ews_start_sync (backend);
diff --git a/src/collection/e-ews-backend.c b/src/collection/e-ews-backend.c
index 386e41d..42791e5 100644
--- a/src/collection/e-ews-backend.c
+++ b/src/collection/e-ews-backend.c
@@ -394,6 +394,7 @@ ews_backend_add_gal_source (EEwsBackend *backend)
g_object_unref (server);
if (source != NULL) {
+ e_source_set_enabled (source, TRUE);
g_object_unref (source);
return;
}
@@ -430,6 +431,7 @@ ews_backend_add_gal_source (EEwsBackend *backend)
source = e_collection_backend_new_child (
collection_backend, oal_id);
+ e_source_set_enabled (source, TRUE);
e_source_set_display_name (source, display_name);
@@ -463,48 +465,21 @@ ews_backend_add_gal_source (EEwsBackend *backend)
g_object_unref (source);
}
+static void ews_backend_populate (ECollectionBackend *backend);
+
static void
ews_backend_source_changed_cb (ESource *source,
EEwsBackend *backend)
{
- CamelEwsSettings *settings;
- const gchar *oal_selected;
- const gchar *gal_uid;
-
if (!e_source_get_enabled (source)) {
backend->priv->need_update_folders = TRUE;
return;
}
- if (!e_backend_get_online (E_BACKEND (backend)) ||
- !backend->priv->need_update_folders)
- return;
-
- settings = ews_backend_get_settings (backend);
- gal_uid = camel_ews_settings_get_gal_uid (settings);
- oal_selected = camel_ews_settings_get_oal_selected (settings);
-
- if (g_strcmp0 (oal_selected, backend->priv->oal_selected) == 0)
+ if (!backend->priv->need_update_folders)
return;
- /* Remove the old Global Address List source if present. */
- if (gal_uid != NULL) {
- ECollectionBackend *collection_backend;
- ESourceRegistryServer *server;
-
- collection_backend = E_COLLECTION_BACKEND (backend);
- server = e_collection_backend_ref_server (collection_backend);
- source = e_source_registry_server_ref_source (server, gal_uid);
-
- if (source != NULL) {
- e_source_registry_server_remove_source (server, source);
- g_object_unref (source);
- }
-
- camel_ews_settings_set_gal_uid (settings, NULL);
- }
-
- ews_backend_add_gal_source (backend);
+ ews_backend_populate (E_COLLECTION_BACKEND (backend));
}
static void
@@ -652,6 +627,43 @@ ews_backend_constructed (GObject *object)
}
static void
+ews_backend_claim_old_resources (ECollectionBackend *backend)
+{
+ ESourceRegistryServer *registry;
+ GList *old_resources, *iter;
+
+ g_return_if_fail (E_IS_COLLECTION_BACKEND (backend));
+
+ registry = e_collection_backend_ref_server (backend);
+ old_resources = e_collection_backend_claim_all_resources (backend);
+
+ for (iter = old_resources; iter; iter = g_list_next (iter)) {
+ ESource *source = iter->data;
+
+ e_source_set_enabled (source, TRUE);
+ e_source_registry_server_add_source (registry, source);
+ }
+
+ g_list_free_full (old_resources, g_object_unref);
+ g_clear_object (®istry);
+}
+
+static void
+ews_backend_folders_synced_cb (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ EEwsBackend *ews_backend;
+
+ g_return_if_fail (E_IS_EWS_BACKEND (source));
+
+ ews_backend = E_EWS_BACKEND (source);
+
+ if (!e_ews_backend_sync_folders_finish (ews_backend, result, NULL))
+ ews_backend_claim_old_resources (E_COLLECTION_BACKEND (ews_backend));
+}
+
+static void
ews_backend_populate (ECollectionBackend *backend)
{
ESource *source;
@@ -661,20 +673,21 @@ ews_backend_populate (ECollectionBackend *backend)
ews_backend->priv->need_update_folders = TRUE;
- /* do not do anything, if account is disabled */
- if (!e_source_get_enabled (source))
- return;
-
if (!ews_backend->priv->notify_online_id)
ews_backend->priv->notify_online_id = g_signal_connect (
backend, "notify::online",
G_CALLBACK (ews_backend_populate), NULL);
- /* For now at least, we don't need to know the
- * results, so no callback function is needed. */
- e_ews_backend_sync_folders (ews_backend, NULL, NULL, NULL);
+ /* do not do anything, if account is disabled */
+ if (!e_source_get_enabled (source))
+ return;
ews_backend_add_gal_source (ews_backend);
+
+ if (e_backend_get_online (E_BACKEND (backend)))
+ e_ews_backend_sync_folders (ews_backend, NULL, ews_backend_folders_synced_cb, NULL);
+ else
+ ews_backend_claim_old_resources (backend);
}
static gchar *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]