[evolution-data-server] Bug #720940 - Always asked to synchronize folders when going offline



commit 6ce34e7d5c7b81bfc7168c2fdc5492960d03a169
Author: Milan Crha <mcrha redhat com>
Date:   Wed Feb 5 17:58:59 2014 +0100

    Bug #720940 - Always asked to synchronize folders when going offline

 camel/camel-offline-store.c |   76 +++++++++++++++++++++++++++++++++++++++++++
 camel/camel-offline-store.h |    2 +
 2 files changed, 78 insertions(+), 0 deletions(-)
---
diff --git a/camel/camel-offline-store.c b/camel/camel-offline-store.c
index 3a75e0d..fbaafcb 100644
--- a/camel/camel-offline-store.c
+++ b/camel/camel-offline-store.c
@@ -340,3 +340,79 @@ camel_offline_store_prepare_for_offline_sync (CamelOfflineStore *store,
 
        return TRUE;
 }
+
+/**
+ * camel_offline_store_requires_downsync:
+ * @store: a #CamelOfflineStore
+ *
+ * Check whether the @store requires synchronization for offline usage.
+ * This is not blocking, it only checks settings on the store and its
+ * currently opened folders.
+ *
+ * Returns %TRUE if the @store requires synchronization for offline usage
+ *
+ * Since: 3.12
+ **/
+gboolean
+camel_offline_store_requires_downsync (CamelOfflineStore *store)
+{
+       CamelService *service;
+       CamelSettings *settings;
+       gboolean host_reachable = TRUE;
+       gboolean store_is_online;
+       gboolean sync_store;
+
+       g_return_val_if_fail (CAMEL_IS_OFFLINE_STORE (store), FALSE);
+
+       service = CAMEL_SERVICE (store);
+
+       if (CAMEL_IS_NETWORK_SERVICE (store)) {
+               host_reachable =
+                       camel_network_service_get_host_reachable (
+                       CAMEL_NETWORK_SERVICE (store));
+       }
+
+       store_is_online = camel_offline_store_get_online (store);
+
+       if (!store_is_online)
+               return FALSE;
+
+       settings = camel_service_ref_settings (service);
+
+       sync_store = camel_offline_settings_get_stay_synchronized (
+               CAMEL_OFFLINE_SETTINGS (settings));
+
+       g_object_unref (settings);
+
+       if (host_reachable) {
+               CamelSession *session;
+
+               session = camel_service_ref_session (service);
+               host_reachable = camel_session_get_online (session);
+               g_clear_object (&session);
+       }
+
+       if (host_reachable && !sync_store) {
+               GPtrArray *folders;
+               guint ii;
+
+               folders = camel_object_bag_list (
+                       CAMEL_STORE (store)->folders);
+
+               for (ii = 0; ii < folders->len && !sync_store; ii++) {
+                       CamelFolder *folder = folders->pdata[ii];
+
+                       if (!CAMEL_IS_OFFLINE_FOLDER (folder))
+                               continue;
+
+                       sync_store = sync_store ||
+                               camel_offline_folder_get_offline_sync (
+                               CAMEL_OFFLINE_FOLDER (folder));
+               }
+
+               g_ptr_array_foreach (folders, (GFunc) g_object_unref, NULL);
+               g_ptr_array_free (folders, TRUE);
+       }
+
+       return sync_store && host_reachable;
+}
diff --git a/camel/camel-offline-store.h b/camel/camel-offline-store.h
index 3026f78..2c215cc 100644
--- a/camel/camel-offline-store.h
+++ b/camel/camel-offline-store.h
@@ -72,6 +72,8 @@ gboolean      camel_offline_store_prepare_for_offline_sync
                                                (CamelOfflineStore *store,
                                                 GCancellable *cancellable,
                                                 GError **error);
+gboolean       camel_offline_store_requires_downsync
+                                               (CamelOfflineStore *store);
 
 G_END_DECLS
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]