[evolution-data-server] I#286 - Skip collection account refresh when parts disabled



commit bb2b322d7d801f7511a25c0683b361412a3a7dd5
Author: Milan Crha <mcrha redhat com>
Date:   Thu Jan 7 18:34:11 2021 +0100

    I#286 - Skip collection account refresh when parts disabled
    
    It doesn't make sense to ask the server for existing sources, the less
    the user for credentials to login to the server, when all the related
    parts are disabled.
    
    Closes https://gitlab.gnome.org/GNOME/evolution-data-server/-/issues/286

 src/libebackend/e-backend-enums.h             | 20 ++++++++++++
 src/libebackend/e-collection-backend.c        | 47 +++++++++++++++++++++++++++
 src/libebackend/e-collection-backend.h        |  4 +++
 src/libebackend/e-webdav-collection-backend.c |  6 +---
 4 files changed, 72 insertions(+), 5 deletions(-)
---
diff --git a/src/libebackend/e-backend-enums.h b/src/libebackend/e-backend-enums.h
index 6fefc40a1..bd9bc6dd5 100644
--- a/src/libebackend/e-backend-enums.h
+++ b/src/libebackend/e-backend-enums.h
@@ -103,4 +103,24 @@ typedef enum {
        E_OFFLINE_STATE_LOCALLY_DELETED
 } EOfflineState;
 
+/**
+ * ECollectionBackendParts:
+ * @E_COLLECTION_BACKEND_PART_NONE: None part.
+ * @E_COLLECTION_BACKEND_PART_CALENDAR: Check the calendar part.
+ * @E_COLLECTION_BACKEND_PART_CONTACTS: Check the contacts part.
+ * @E_COLLECTION_BACKEND_PART_MAIL: Check the mail part.
+ * @E_COLLECTION_BACKEND_PART_ANY: Shortcut to have all parts checked.
+ *
+ * Flags to check whether at least one of the asked for parts is enabled.
+ *
+ * Since: 3.40
+ **/
+typedef enum { /*< flags >*/
+       E_COLLECTION_BACKEND_PART_NONE = 0,
+       E_COLLECTION_BACKEND_PART_CALENDAR = 1 << 0,
+       E_COLLECTION_BACKEND_PART_CONTACTS = 1 << 1,
+       E_COLLECTION_BACKEND_PART_MAIL = 1 << 2,
+       E_COLLECTION_BACKEND_PART_ANY = ~0
+} ECollectionBackendParts;
+
 #endif /* E_BACKEND_ENUMS_H */
diff --git a/src/libebackend/e-collection-backend.c b/src/libebackend/e-collection-backend.c
index 4805a6933..da49fd510 100644
--- a/src/libebackend/e-collection-backend.c
+++ b/src/libebackend/e-collection-backend.c
@@ -2080,3 +2080,50 @@ e_collection_backend_thaw_populate (ECollectionBackend *backend)
 
        g_atomic_int_add (&backend->priv->populate_freeze_count, -1);
 }
+
+/**
+ * e_collection_backend_get_part_enabled:
+ * @backend: an #ECollectionBackend
+ * @parts: a bit-or of #ECollectionBackendParts with parts to be checked
+ *
+ * Checks whether the @backend has enabled at least of the @parts.
+ *
+ * Returns: %TRUE, when at least one of the @parts is enabled and
+ *    the backend's #ESource is enabled as well.
+ *
+ * Since: 3.40
+ **/
+gboolean
+e_collection_backend_get_part_enabled (ECollectionBackend *backend,
+                                      ECollectionBackendParts parts)
+{
+       ESourceCollection *collection_extension = NULL;
+       ESource *source;
+
+       g_return_val_if_fail (E_IS_COLLECTION_BACKEND (backend), FALSE);
+
+       source = e_backend_get_source (E_BACKEND (backend));
+
+       if (!e_source_get_enabled (source))
+               return FALSE;
+
+       if (e_source_has_extension (source, E_SOURCE_EXTENSION_COLLECTION))
+               collection_extension = e_source_get_extension (source, E_SOURCE_EXTENSION_COLLECTION);
+
+       if (!collection_extension)
+               return TRUE;
+
+       if ((parts & E_COLLECTION_BACKEND_PART_CALENDAR) != 0 &&
+           e_source_collection_get_calendar_enabled (collection_extension))
+               return TRUE;
+
+       if ((parts & E_COLLECTION_BACKEND_PART_CONTACTS) != 0 &&
+           e_source_collection_get_contacts_enabled (collection_extension))
+               return TRUE;
+
+       if ((parts & E_COLLECTION_BACKEND_PART_MAIL) != 0 &&
+           e_source_collection_get_mail_enabled (collection_extension))
+               return TRUE;
+
+       return FALSE;
+}
diff --git a/src/libebackend/e-collection-backend.h b/src/libebackend/e-collection-backend.h
index f96a7099f..7f4cf4574 100644
--- a/src/libebackend/e-collection-backend.h
+++ b/src/libebackend/e-collection-backend.h
@@ -23,6 +23,7 @@
 #define E_COLLECTION_BACKEND_H
 
 #include <libebackend/e-backend.h>
+#include <libebackend/e-backend-enums.h>
 
 /* Standard GObject macros */
 #define E_TYPE_COLLECTION_BACKEND \
@@ -177,6 +178,9 @@ gboolean    e_collection_backend_freeze_populate
                                                (ECollectionBackend *backend);
 void           e_collection_backend_thaw_populate
                                                (ECollectionBackend *backend);
+gboolean       e_collection_backend_get_part_enabled
+                                               (ECollectionBackend *backend,
+                                                ECollectionBackendParts parts);
 
 G_END_DECLS
 
diff --git a/src/libebackend/e-webdav-collection-backend.c b/src/libebackend/e-webdav-collection-backend.c
index 7f9880f2f..7f3165244 100644
--- a/src/libebackend/e-webdav-collection-backend.c
+++ b/src/libebackend/e-webdav-collection-backend.c
@@ -299,7 +299,6 @@ webdav_collection_backend_populate (ECollectionBackend *collection)
 {
        EWebDAVCollectionBackend *webdav_backend = E_WEBDAV_COLLECTION_BACKEND (collection);
        ESourceRegistryServer *server;
-       ESourceCollection *collection_extension;
        ESource *source;
        GList *list, *liter;
 
@@ -335,11 +334,8 @@ webdav_collection_backend_populate (ECollectionBackend *collection)
        g_list_free_full (list, g_object_unref);
 
        source = e_backend_get_source (E_BACKEND (collection));
-       collection_extension = e_source_get_extension (source, E_SOURCE_EXTENSION_COLLECTION);
 
-       if (e_source_get_enabled (source) && (
-           e_source_collection_get_calendar_enabled (collection_extension) ||
-           e_source_collection_get_contacts_enabled (collection_extension))) {
+       if (e_collection_backend_get_part_enabled (collection, E_COLLECTION_BACKEND_PART_CALENDAR | 
E_COLLECTION_BACKEND_PART_CONTACTS)) {
                gboolean needs_credentials = TRUE;
 
                if (e_source_has_extension (source, E_SOURCE_EXTENSION_AUTHENTICATION)) {


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