[evolution-data-server] I#297 - CalDAV: Support calendar-order property ][



commit 6513996448a20edd8cb39960ef8cbaf2a5550380
Author: Milan Crha <mcrha redhat com>
Date:   Fri Feb 12 09:01:48 2021 +0100

    I#297 - CalDAV: Support calendar-order property ][
    
    Let the 'order' be '(guint) -1' in cases when the value
    is not set on the server, thus it's distinguishable between
    the index 0 and a unset/unknown value.
    
    Related to https://gitlab.gnome.org/GNOME/evolution-data-server/-/issues/297

 src/libebackend/e-webdav-collection-backend.c |  6 ++++--
 src/libedataserver/e-data-server-util.c       |  3 +++
 src/libedataserver/e-source-webdav.c          |  7 ++++---
 src/libedataserver/e-webdav-discover.c        |  4 ++--
 src/libedataserver/e-webdav-session.c         | 15 +++++++++------
 src/libedataserver/e-webdav-session.h         |  2 +-
 6 files changed, 23 insertions(+), 14 deletions(-)
---
diff --git a/src/libebackend/e-webdav-collection-backend.c b/src/libebackend/e-webdav-collection-backend.c
index 1a88b1520..f666e60a1 100644
--- a/src/libebackend/e-webdav-collection-backend.c
+++ b/src/libebackend/e-webdav-collection-backend.c
@@ -207,7 +207,8 @@ webdav_collection_add_found_source (ECollectionBackend *collection,
                e_source_webdav_set_display_name (webdav_extension, display_name);
 
                if (source_type == E_WEBDAV_DISCOVER_SUPPORTS_CONTACTS) {
-                       if (is_new || e_source_webdav_get_order (webdav_extension) == 
e_source_address_book_get_order (E_SOURCE_ADDRESS_BOOK (backend)))
+                       if (order != (guint) -1 && (is_new ||
+                           e_source_webdav_get_order (webdav_extension) == e_source_address_book_get_order 
(E_SOURCE_ADDRESS_BOOK (backend))))
                                e_source_address_book_set_order (E_SOURCE_ADDRESS_BOOK (backend), order);
 
                        e_source_webdav_set_order (webdav_extension, order);
@@ -228,7 +229,8 @@ webdav_collection_add_found_source (ECollectionBackend *collection,
                                g_free (safe_color);
                        }
 
-                       if (is_new || e_source_webdav_get_order (webdav_extension) == 
e_source_selectable_get_order (E_SOURCE_SELECTABLE (backend)))
+                       if (order != (guint) -1 && (is_new ||
+                           e_source_webdav_get_order (webdav_extension) == e_source_selectable_get_order 
(E_SOURCE_SELECTABLE (backend))))
                                e_source_selectable_set_order (E_SOURCE_SELECTABLE (backend), order);
 
                        e_source_webdav_set_order (webdav_extension, order);
diff --git a/src/libedataserver/e-data-server-util.c b/src/libedataserver/e-data-server-util.c
index 5c8116af5..401fb3388 100644
--- a/src/libedataserver/e-data-server-util.c
+++ b/src/libedataserver/e-data-server-util.c
@@ -3336,6 +3336,9 @@ e_util_source_compare_get_order (ESource *source,
                        else
                                *out_order = e_source_selectable_get_order (E_SOURCE_SELECTABLE (extension));
 
+                       if (*out_order == (guint) -1)
+                               return FALSE;
+
                        return TRUE;
                }
        }
diff --git a/src/libedataserver/e-source-webdav.c b/src/libedataserver/e-source-webdav.c
index 91f9ac564..8a210bb81 100644
--- a/src/libedataserver/e-source-webdav.c
+++ b/src/libedataserver/e-source-webdav.c
@@ -644,7 +644,7 @@ e_source_webdav_class_init (ESourceWebdavClass *class)
                        "order",
                        "Order",
                        "A sorting order of the resource",
-                       0, G_MAXUINT, 0,
+                       0, G_MAXUINT, (guint) -1,
                        G_PARAM_READWRITE |
                        G_PARAM_CONSTRUCT |
                        G_PARAM_EXPLICIT_NOTIFY |
@@ -1620,14 +1620,15 @@ e_source_webdav_set_ssl_trust_response (ESourceWebdav *extension,
  * e_source_webdav_get_order:
  * @extension: an #ESourceWebdav
  *
- * Returns: the sorting order of the resource, if known. Zero is the default.
+ * Returns: the sorting order of the resource, if known. The default
+ *    is (guint) -1, which means unknown/unset.
  *
  * Since: 3.40
  **/
 guint
 e_source_webdav_get_order (ESourceWebdav *extension)
 {
-       g_return_val_if_fail (E_IS_SOURCE_WEBDAV (extension), 0);
+       g_return_val_if_fail (E_IS_SOURCE_WEBDAV (extension), (guint) -1);
 
        return extension->priv->order;
 }
diff --git a/src/libedataserver/e-webdav-discover.c b/src/libedataserver/e-webdav-discover.c
index bad613a2b..ed8f3ca44 100644
--- a/src/libedataserver/e-webdav-discover.c
+++ b/src/libedataserver/e-webdav-discover.c
@@ -293,7 +293,7 @@ e_webdav_discover_traverse_propfind_response_cb (EWebDAVSession *webdav,
                        e_webdav_resource_new (E_WEBDAV_RESOURCE_KIND_WEBDAV_NOTES,
                                E_WEBDAV_RESOURCE_SUPPORTS_WEBDAV_NOTES, href, NULL,
                                _("Notes"),
-                               NULL, 0, 0, 0, NULL, NULL, 0));
+                               NULL, 0, 0, 0, NULL, NULL, (guint) -1));
 
                e_webdav_discover_split_resources (wdd, resources);
 
@@ -768,7 +768,7 @@ e_webdav_discover_cmp_sources (gconstpointer ptr1,
        if (!source1 || !source2)
                return (source1 ? 1 : 0) - (source2 ? 1 : 0);
 
-       if (source1->order != source2->order)
+       if (source1->order != source2->order && source1->order != (guint) -1 && source2->order != (guint) -1)
                return source1->order < source2->order ? -1 : 1;
 
        return g_strcmp0 (source1->display_name, source2->display_name);
diff --git a/src/libedataserver/e-webdav-session.c b/src/libedataserver/e-webdav-session.c
index 0976510ff..58ba4b760 100644
--- a/src/libedataserver/e-webdav-session.c
+++ b/src/libedataserver/e-webdav-session.c
@@ -66,7 +66,7 @@ G_DEFINE_BOXED_TYPE (EWebDAVAccessControlEntry, e_webdav_access_control_entry, e
  * @last_modified: optional last modified time of the resource, or 0
  * @description: (nullable): optional description of the resource, or %NULL
  * @color: (nullable): optional color of the resource, or %NULL
- * @order: sort order of the resource, or 0
+ * @order: sort order of the resource, or (guint) -1
  *
  * Some values of the resource are not always valid, depending on the @kind,
  * but also whether server stores such values and whether it had been asked
@@ -3578,19 +3578,22 @@ e_webdav_session_extract_uint (xmlNodePtr parent,
                               const gchar *prop_ns_href,
                               const gchar *prop_name)
 {
-       gchar *value_str;
+       gchar *value_str, *end_ptr = NULL;
        guint64 value;
 
-       g_return_val_if_fail (parent != NULL, 0);
+       g_return_val_if_fail (parent != NULL, (guint) -1);
 
        value_str = e_webdav_session_extract_nonempty (parent, prop_ns_href, prop_name, NULL, NULL);
        if (!value_str)
-               return 0;
+               return (guint) -1;
 
-       value = g_ascii_strtoull (value_str, NULL, 10);
+       value = g_ascii_strtoull (value_str, &end_ptr, 10);
 
        g_free (value_str);
 
+       if (end_ptr == value_str)
+               return (guint) -1;
+
        return (guint) value;
 }
 
@@ -5013,7 +5016,7 @@ e_webdav_session_principal_property_search_cb (EWebDAVSession *webdav,
                0, /* last_modified */
                NULL, /* description */
                NULL, /* color */
-               0); /* order */
+               (guint) -1); /* order */
        resource->display_name = display_name;
 
        *out_principals = g_slist_prepend (*out_principals, resource);
diff --git a/src/libedataserver/e-webdav-session.h b/src/libedataserver/e-webdav-session.h
index fd9050daf..45752f2ff 100644
--- a/src/libedataserver/e-webdav-session.h
+++ b/src/libedataserver/e-webdav-session.h
@@ -116,7 +116,7 @@ typedef struct _EWebDAVResource {
        glong last_modified;
        gchar *description;
        gchar *color;
-       guint order;
+       guint order; /* (guint) -1, if unknown */
 } EWebDAVResource;
 
 GType          e_webdav_resource_get_type              (void) G_GNUC_CONST;


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