[evolution-data-server] Bug 795869 - Synchronize color of WebDAV resources
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Bug 795869 - Synchronize color of WebDAV resources
- Date: Mon, 11 Jun 2018 07:42:38 +0000 (UTC)
commit b8df8674995af17070a37de9b2dda21b772c0d03
Author: Milan Crha <mcrha redhat com>
Date: Mon Jun 11 09:36:11 2018 +0200
Bug 795869 - Synchronize color of WebDAV resources
src/libebackend/e-webdav-collection-backend.c | 15 +++-
src/libedataserver/e-source-webdav.c | 111 ++++++++++++++++++++++++++
src/libedataserver/e-source-webdav.h | 4 +
3 files changed, 127 insertions(+), 3 deletions(-)
---
diff --git a/src/libebackend/e-webdav-collection-backend.c b/src/libebackend/e-webdav-collection-backend.c
index 024779b76..3fe35f612 100644
--- a/src/libebackend/e-webdav-collection-backend.c
+++ b/src/libebackend/e-webdav-collection-backend.c
@@ -181,24 +181,33 @@ webdav_collection_add_found_source (ECollectionBackend *collection,
/* these properties are synchronized always */
if (source) {
+ ESourceWebdav *webdav_extension;
gint rr, gg, bb;
backend = e_source_get_extension (source, backend_name);
e_source_backend_set_backend_name (backend, provider);
- e_source_set_display_name (source, display_name);
+ webdav_extension = e_source_get_extension (source, E_SOURCE_EXTENSION_WEBDAV_BACKEND);
+
+ if (is_new || g_strcmp0 (e_source_webdav_get_display_name (webdav_extension),
e_source_get_display_name (source)) == 0)
+ e_source_set_display_name (source, display_name);
+
+ e_source_webdav_set_display_name (webdav_extension, display_name);
e_source_set_enabled (source, TRUE);
/* Also check whether the color format is as expected; it cannot
be used gdk_rgba_parse here, because it required gdk/gtk. */
- if (is_new && source_type != E_WEBDAV_DISCOVER_SUPPORTS_CONTACTS && color &&
+ if (source_type != E_WEBDAV_DISCOVER_SUPPORTS_CONTACTS && color &&
sscanf (color, "#%02x%02x%02x", &rr, &gg, &bb) == 3) {
gchar *safe_color;
/* In case an #RRGGBBAA is returned */
safe_color = g_strdup_printf ("#%02x%02x%02x", rr, gg, bb);
- e_source_selectable_set_color (E_SOURCE_SELECTABLE (backend), safe_color);
+ if (is_new || g_strcmp0 (e_source_webdav_get_color (webdav_extension),
e_source_selectable_get_color (E_SOURCE_SELECTABLE (backend))) == 0)
+ e_source_selectable_set_color (E_SOURCE_SELECTABLE (backend), safe_color);
+
+ e_source_webdav_set_color (webdav_extension, safe_color);
g_free (safe_color);
}
diff --git a/src/libedataserver/e-source-webdav.c b/src/libedataserver/e-source-webdav.c
index 343982a88..67804f524 100644
--- a/src/libedataserver/e-source-webdav.c
+++ b/src/libedataserver/e-source-webdav.c
@@ -64,6 +64,7 @@
struct _ESourceWebdavPrivate {
gchar *display_name;
+ gchar *color;
gchar *email_address;
gchar *resource_path;
gchar *resource_query;
@@ -77,6 +78,7 @@ enum {
PROP_0,
PROP_AVOID_IFMATCH,
PROP_CALENDAR_AUTO_SCHEDULE,
+ PROP_COLOR,
PROP_DISPLAY_NAME,
PROP_EMAIL_ADDRESS,
PROP_RESOURCE_PATH,
@@ -283,6 +285,12 @@ source_webdav_set_property (GObject *object,
g_value_get_boolean (value));
return;
+ case PROP_COLOR:
+ e_source_webdav_set_color (
+ E_SOURCE_WEBDAV (object),
+ g_value_get_string (value));
+ return;
+
case PROP_DISPLAY_NAME:
e_source_webdav_set_display_name (
E_SOURCE_WEBDAV (object),
@@ -344,6 +352,13 @@ source_webdav_get_property (GObject *object,
E_SOURCE_WEBDAV (object)));
return;
+ case PROP_COLOR:
+ g_value_take_string (
+ value,
+ e_source_webdav_dup_color (
+ E_SOURCE_WEBDAV (object)));
+ return;
+
case PROP_DISPLAY_NAME:
g_value_take_string (
value,
@@ -397,6 +412,7 @@ source_webdav_finalize (GObject *object)
priv = E_SOURCE_WEBDAV_GET_PRIVATE (object);
+ g_free (priv->color);
g_free (priv->display_name);
g_free (priv->email_address);
g_free (priv->resource_path);
@@ -512,6 +528,18 @@ e_source_webdav_class_init (ESourceWebdavClass *class)
G_PARAM_CONSTRUCT |
E_SOURCE_PARAM_SETTING));
+ g_object_class_install_property (
+ object_class,
+ PROP_COLOR,
+ g_param_spec_string (
+ "color",
+ "Color",
+ "Color of the WebDAV resource",
+ "",
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ E_SOURCE_PARAM_SETTING));
+
g_object_class_install_property (
object_class,
PROP_DISPLAY_NAME,
@@ -783,6 +811,89 @@ e_source_webdav_set_display_name (ESourceWebdav *extension,
g_object_notify (G_OBJECT (extension), "display-name");
}
+/**
+ * e_source_webdav_get_color:
+ * @extension: an #ESourceWebdav
+ *
+ * Returns the last known color of a WebDAV resource as provided by the server.
+ *
+ * Returns: the color of the WebDAV resource, if any set on the server
+ *
+ * Since: 3.30
+ **/
+const gchar *
+e_source_webdav_get_color (ESourceWebdav *extension)
+{
+ g_return_val_if_fail (E_IS_SOURCE_WEBDAV (extension), NULL);
+
+ return extension->priv->color;
+}
+
+/**
+ * e_source_webdav_dup_color:
+ * @extension: an #ESourceWebdav
+ *
+ * Thread-safe variation of e_source_webdav_get_color().
+ * Use this function when accessing @extension from multiple threads.
+ *
+ * The returned string should be freed with g_free() when no longer needed.
+ *
+ * Returns: a newly-allocated copy of #ESourceWebdav:color
+ *
+ * Since: 3.30
+ **/
+gchar *
+e_source_webdav_dup_color (ESourceWebdav *extension)
+{
+ const gchar *protected;
+ gchar *duplicate;
+
+ g_return_val_if_fail (E_IS_SOURCE_WEBDAV (extension), NULL);
+
+ e_source_extension_property_lock (E_SOURCE_EXTENSION (extension));
+
+ protected = e_source_webdav_get_color (extension);
+ duplicate = g_strdup (protected);
+
+ e_source_extension_property_unlock (E_SOURCE_EXTENSION (extension));
+
+ return duplicate;
+}
+
+/**
+ * e_source_webdav_set_color:
+ * @extension: an #ESourceWebdav
+ * @color: (optional): the color of the WebDAV resource, or %NULL
+ *
+ * Updates the last known color of a WebDAV resource, as provided by the server.
+ *
+ * The internal copy of @color is automatically stripped of leading
+ * and trailing whitespace. If the resulting string is empty, %NULL is set
+ * instead.
+ *
+ * Since: 3.30
+ **/
+void
+e_source_webdav_set_color (ESourceWebdav *extension,
+ const gchar *color)
+{
+ g_return_if_fail (E_IS_SOURCE_WEBDAV (extension));
+
+ e_source_extension_property_lock (E_SOURCE_EXTENSION (extension));
+
+ if (g_strcmp0 (extension->priv->color, color) == 0) {
+ e_source_extension_property_unlock (E_SOURCE_EXTENSION (extension));
+ return;
+ }
+
+ g_free (extension->priv->color);
+ extension->priv->color = e_util_strdup_strip (color);
+
+ e_source_extension_property_unlock (E_SOURCE_EXTENSION (extension));
+
+ g_object_notify (G_OBJECT (extension), "color");
+}
+
/**
* e_source_webdav_get_email_address:
* @extension: an #ESourceWebdav
diff --git a/src/libedataserver/e-source-webdav.h b/src/libedataserver/e-source-webdav.h
index 86eacb375..1a9173361 100644
--- a/src/libedataserver/e-source-webdav.h
+++ b/src/libedataserver/e-source-webdav.h
@@ -102,6 +102,10 @@ gchar * e_source_webdav_dup_display_name
void e_source_webdav_set_display_name
(ESourceWebdav *extension,
const gchar *display_name);
+const gchar * e_source_webdav_get_color (ESourceWebdav *extension);
+gchar * e_source_webdav_dup_color (ESourceWebdav *extension);
+void e_source_webdav_set_color (ESourceWebdav *extension,
+ const gchar *color);
const gchar * e_source_webdav_get_email_address
(ESourceWebdav *extension);
gchar * e_source_webdav_dup_email_address
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]