[evolution-data-server/tintou/edataserver-webdavdiscoveredsource] M!48 - e-webdav-discover: Define EWebDAVDiscoveredSource as boxed type




commit efc13906ce2e7717da551c635fb5562ba16c2f1f
Author: Corentin Noël <corentin noel collabora com>
Date:   Thu Nov 5 11:46:21 2020 +0100

    M!48 - e-webdav-discover: Define EWebDAVDiscoveredSource as boxed type
    
    This allows to use the e_webdav_discover_sources_* functions from the introspection
    
    Closes https://gitlab.gnome.org/GNOME/evolution-data-server/-/merge_requests/48

 src/libedataserver/e-dataserver-autocleanups.h |  1 +
 src/libedataserver/e-webdav-discover.c         | 67 ++++++++++++++++++++------
 src/libedataserver/e-webdav-discover.h         |  7 +++
 3 files changed, 60 insertions(+), 15 deletions(-)
---
diff --git a/src/libedataserver/e-dataserver-autocleanups.h b/src/libedataserver/e-dataserver-autocleanups.h
index 556058b66..bc3c81ad4 100644
--- a/src/libedataserver/e-dataserver-autocleanups.h
+++ b/src/libedataserver/e-dataserver-autocleanups.h
@@ -87,6 +87,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(ESourceTaskList, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(ESourceUoa, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(ESourceWeather, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(ESourceWebdav, g_object_unref)
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(EWebDAVDiscoveredSource, e_webdav_discovered_source_free)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(EWebDAVSession, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(EWebDAVResource, e_webdav_resource_free)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(EWebDAVPropertyChange, e_webdav_property_change_free)
diff --git a/src/libedataserver/e-webdav-discover.c b/src/libedataserver/e-webdav-discover.c
index 9f822e079..0aefa5aae 100644
--- a/src/libedataserver/e-webdav-discover.c
+++ b/src/libedataserver/e-webdav-discover.c
@@ -41,6 +41,8 @@ typedef struct _WebDAVDiscoverData {
 
 #define CUSTOM_SUPPORTS_FLAGS (E_WEBDAV_DISCOVER_SUPPORTS_CALENDAR_AUTO_SCHEDULE | 
E_WEBDAV_DISCOVER_SUPPORTS_SUBSCRIBED_ICALENDAR)
 
+G_DEFINE_BOXED_TYPE (EWebDAVDiscoveredSource, e_webdav_discovered_source, e_webdav_discovered_source_copy, 
e_webdav_discovered_source_free)
+
 static gboolean
 e_webdav_discovery_already_discovered (const gchar *href,
                                       const GSList *discovered_sources)
@@ -416,20 +418,6 @@ e_webdav_discover_context_free (gpointer ptr)
        g_slice_free (EWebDAVDiscoverContext, context);
 }
 
-static void
-e_webdav_discover_source_free (gpointer ptr)
-{
-       EWebDAVDiscoveredSource *discovered_source = ptr;
-
-       if (discovered_source) {
-               g_free (discovered_source->href);
-               g_free (discovered_source->display_name);
-               g_free (discovered_source->description);
-               g_free (discovered_source->color);
-               g_slice_free (EWebDAVDiscoveredSource, discovered_source);
-       }
-}
-
 /**
  * e_webdav_discover_free_discovered_sources:
  * @discovered_sources: (element-type EWebDAVDiscoveredSource): A #GSList of discovered sources
@@ -442,7 +430,7 @@ e_webdav_discover_source_free (gpointer ptr)
 void
 e_webdav_discover_free_discovered_sources (GSList *discovered_sources)
 {
-       g_slist_free_full (discovered_sources, e_webdav_discover_source_free);
+       g_slist_free_full (discovered_sources, (GDestroyNotify) e_webdav_discovered_source_free);
 }
 
 static void
@@ -1044,3 +1032,52 @@ e_webdav_discover_sources_full_sync (ESource *source,
 
        return success;
 }
+
+/**
+ * e_webdav_discovered_source_copy:
+ * @discovered_source: an #EWebDAVDiscoveredSource to copy
+ *
+ * Copies the given EWebDAVDiscoveredSource.
+ *
+ * Returns: (transfer full): a copy of @discovered_source
+ *
+ * Since: 3.40
+ **/
+EWebDAVDiscoveredSource *
+e_webdav_discovered_source_copy (EWebDAVDiscoveredSource *discovered_source)
+{
+       EWebDAVDiscoveredSource *copy;
+
+       g_return_val_if_fail (discovered_source != NULL, NULL);
+
+       copy = g_slice_new0 (EWebDAVDiscoveredSource);
+       copy->href = g_strdup (discovered_source->href);
+       copy->supports = discovered_source->supports;
+       copy->display_name = g_strdup (discovered_source->display_name);
+       copy->description = g_strdup (discovered_source->description);
+       copy->color = g_strdup (discovered_source->color);
+
+       return copy;
+}
+
+
+/**
+ * e_webdav_discovered_source_free:
+ * @discovered_source: an #EWebDAVDiscoveredSource to free
+ *
+ * Frees the @discovered_source. Function does nothing, when it's %NULL.
+ *
+ * Since: 3.40
+ **/
+void
+e_webdav_discovered_source_free (EWebDAVDiscoveredSource *discovered_source)
+{
+       if (!discovered_source)
+               return;
+
+       g_clear_pointer (&discovered_source->href, g_free);
+       g_clear_pointer (&discovered_source->display_name, g_free);
+       g_clear_pointer (&discovered_source->description, g_free);
+       g_clear_pointer (&discovered_source->color, g_free);
+       g_slice_free (EWebDAVDiscoveredSource, discovered_source);
+}
diff --git a/src/libedataserver/e-webdav-discover.h b/src/libedataserver/e-webdav-discover.h
index a7d4cb22b..8b6966826 100644
--- a/src/libedataserver/e-webdav-discover.h
+++ b/src/libedataserver/e-webdav-discover.h
@@ -27,6 +27,8 @@
 #include <libedataserver/e-source.h>
 #include <libedataserver/e-webdav-session.h>
 
+#define E_TYPE_WEBDAV_DISCOVERED_SOURCE (e_webdav_discovered_source_get_type ())
+
 G_BEGIN_DECLS
 
 typedef enum {
@@ -78,6 +80,11 @@ gboolean     e_webdav_discover_sources_sync          (ESource *source,
                                                         GCancellable *cancellable,
                                                         GError **error);
 
+GType          e_webdav_discovered_source_get_type     (void) G_GNUC_CONST;
+EWebDAVDiscoveredSource *
+               e_webdav_discovered_source_copy         (EWebDAVDiscoveredSource *discovered_source);
+void           e_webdav_discovered_source_free         (EWebDAVDiscoveredSource *discovered_source);
+
 /**
  * EWebDAVDiscoverRefSourceFunc:
  * @user_data: user data, as passed to e_webdav_discover_sources_full() or


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