[evolution/account-mgmt: 23/25] Add 'book-config-webdav' module.



commit 586f7f08dd237622f1ec5629edca82b22d917d0a
Author: Matthew Barnes <mbarnes redhat com>
Date:   Thu Dec 23 09:00:21 2010 -0500

    Add 'book-config-webdav' module.
    
    Registers the "WebDAV" backend in EBookSourceConfig widgets.
    
    Replaces the 'webdav-account-setup' plugin.

 configure.ac                                       |    1 +
 modules/Makefile.am                                |    1 +
 modules/book-config-webdav/Makefile.am             |   29 ++
 modules/book-config-webdav/e-source-webdav.c       |  532 ++++++++++++++++++++
 modules/book-config-webdav/e-source-webdav.h       |   89 ++++
 .../evolution-book-config-webdav.c                 |  235 +++++++++
 6 files changed, 887 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index a3ffa81..b69a45f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1819,6 +1819,7 @@ modules/addressbook/Makefile
 modules/calendar/Makefile
 modules/mail/Makefile
 modules/book-config-local/Makefile
+modules/book-config-webdav/Makefile
 modules/composer-autosave/Makefile
 modules/connman/Makefile
 modules/mailto-handler/Makefile
diff --git a/modules/Makefile.am b/modules/Makefile.am
index 9949d2d..ca97cdf 100644
--- a/modules/Makefile.am
+++ b/modules/Makefile.am
@@ -23,6 +23,7 @@ SUBDIRS = \
 	calendar \
 	mail \
 	book-config-local \
+	book-config-webdav \
 	composer-autosave \
 	mailto-handler \
 	offline-alert \
diff --git a/modules/book-config-webdav/Makefile.am b/modules/book-config-webdav/Makefile.am
new file mode 100644
index 0000000..4f8f2b7
--- /dev/null
+++ b/modules/book-config-webdav/Makefile.am
@@ -0,0 +1,29 @@
+module_LTLIBRARIES = libevolution-module-book-config-webdav.la
+
+libevolution_module_book_config_webdav_la_CPPFLAGS =		\
+	$(AM_CPPFLAGS)						\
+	-I$(top_srcdir)						\
+	-I$(top_srcdir)/widgets					\
+	-DG_LOG_DOMAIN=\"evolution-book-config-webdav\"		\
+	$(EVOLUTION_ADDRESSBOOK_CFLAGS)				\
+	$(GNOME_PLATFORM_CFLAGS)
+
+libevolution_module_book_config_webdav_la_SOURCES =		\
+	evolution-book-config-webdav.c				\
+	e-source-webdav.c					\
+	e-source-webdav.h
+
+libevolution_module_book_config_webdav_la_LIBADD =		\
+	$(top_builddir)/e-util/libeutil.la			\
+	$(top_builddir)/widgets/misc/libemiscwidgets.la		\
+	$(top_builddir)/addressbook/printing/libecontactprint.la \
+	$(top_builddir)/addressbook/gui/merging/libeabbookmerging.la \
+	$(top_builddir)/addressbook/gui/widgets/libeabwidgets.la \
+	$(top_builddir)/addressbook/util/libeabutil.la		\
+	$(EVOLUTION_ADDRESSBOOK_LIBS)				\
+	$(GNOME_PLATFORM_LIBS)
+
+libevolution_module_book_config_webdav_la_LDFLAGS =		\
+	-module -avoid-version $(NO_UNDEFINED)
+
+-include $(top_srcdir)/git.mk
diff --git a/modules/book-config-webdav/e-source-webdav.c b/modules/book-config-webdav/e-source-webdav.c
new file mode 100644
index 0000000..8231455
--- /dev/null
+++ b/modules/book-config-webdav/e-source-webdav.c
@@ -0,0 +1,532 @@
+/*
+ * e-source-webdav.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#include "e-source-webdav.h"
+
+#include <libedataserver/e-source-authentication.h>
+#include <libedataserver/e-source-security.h>
+
+#define E_SOURCE_WEBDAV_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), E_TYPE_SOURCE_WEBDAV, ESourceWebdavPrivate))
+
+struct _ESourceWebdavPrivate {
+	gboolean avoid_ifmatch;
+	SoupURI *uri;
+};
+
+enum {
+	PROP_0,
+	PROP_AVOID_IFMATCH,
+	PROP_HOST,
+	PROP_PATH,
+	PROP_PORT,
+	PROP_SECURE,
+	PROP_URI,
+	PROP_USER
+};
+
+G_DEFINE_DYNAMIC_TYPE (
+	ESourceWebdav,
+	e_source_webdav,
+	E_TYPE_SOURCE_EXTENSION)
+
+static gboolean
+source_webdav_user_to_method (GBinding *binding,
+                              const GValue *source_value,
+                              GValue *target_value,
+                              gpointer user_data)
+{
+	const gchar *user;
+
+	user = g_value_get_string (source_value);
+	if (user == NULL || *user == '\0')
+		g_value_set_string (target_value, "none");
+	else
+		g_value_set_string (target_value, "plain/password");
+
+	return TRUE;
+}
+
+static void
+source_webdav_set_property (GObject *object,
+                            guint property_id,
+                            const GValue *value,
+                            GParamSpec *pspec)
+{
+	switch (property_id) {
+		case PROP_AVOID_IFMATCH:
+			e_source_webdav_set_avoid_ifmatch (
+				E_SOURCE_WEBDAV (object),
+				g_value_get_boolean (value));
+			return;
+
+		case PROP_HOST:
+			e_source_webdav_set_host (
+				E_SOURCE_WEBDAV (object),
+				g_value_get_string (value));
+			return;
+
+		case PROP_PATH:
+			e_source_webdav_set_path (
+				E_SOURCE_WEBDAV (object),
+				g_value_get_string (value));
+			return;
+
+		case PROP_PORT:
+			e_source_webdav_set_port (
+				E_SOURCE_WEBDAV (object),
+				g_value_get_uint (value));
+			return;
+
+		case PROP_SECURE:
+			e_source_webdav_set_secure (
+				E_SOURCE_WEBDAV (object),
+				g_value_get_boolean (value));
+			return;
+
+		case PROP_URI:
+			e_source_webdav_set_uri (
+				E_SOURCE_WEBDAV (object),
+				g_value_get_boxed (value));
+			return;
+
+		case PROP_USER:
+			e_source_webdav_set_user (
+				E_SOURCE_WEBDAV (object),
+				g_value_get_string (value));
+			return;
+	}
+
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+source_webdav_get_property (GObject *object,
+                            guint property_id,
+                            GValue *value,
+                            GParamSpec *pspec)
+{
+	switch (property_id) {
+		case PROP_AVOID_IFMATCH:
+			g_value_set_boolean (
+				value,
+				e_source_webdav_get_avoid_ifmatch (
+				E_SOURCE_WEBDAV (object)));
+			return;
+
+		case PROP_HOST:
+			g_value_set_string (
+				value,
+				e_source_webdav_get_host (
+				E_SOURCE_WEBDAV (object)));
+			return;
+
+		case PROP_PATH:
+			g_value_set_string (
+				value,
+				e_source_webdav_get_path (
+				E_SOURCE_WEBDAV (object)));
+			return;
+
+		case PROP_PORT:
+			g_value_set_uint (
+				value,
+				e_source_webdav_get_port (
+				E_SOURCE_WEBDAV (object)));
+			return;
+
+		case PROP_SECURE:
+			g_value_set_boolean (
+				value,
+				e_source_webdav_get_secure (
+				E_SOURCE_WEBDAV (object)));
+			return;
+
+		case PROP_URI:
+			g_value_take_boxed (
+				value,
+				e_source_webdav_get_uri (
+				E_SOURCE_WEBDAV (object)));
+			return;
+
+		case PROP_USER:
+			g_value_set_string (
+				value,
+				e_source_webdav_get_user (
+				E_SOURCE_WEBDAV (object)));
+			return;
+	}
+
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+source_webdav_finalize (GObject *object)
+{
+	ESourceWebdavPrivate *priv;
+
+	priv = E_SOURCE_WEBDAV_GET_PRIVATE (object);
+
+	soup_uri_free (priv->uri);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (e_source_webdav_parent_class)->finalize (object);
+}
+
+static void
+source_webdav_constructed (GObject *object)
+{
+	ESource *source;
+	ESourceExtension *this_extension;
+	ESourceExtension *other_extension;
+	const gchar *extension_name;
+
+	/* Chain up to parent's constructed() method. */
+	G_OBJECT_CLASS (e_source_webdav_parent_class)->constructed (object);
+
+	this_extension = E_SOURCE_EXTENSION (object);
+	source = e_source_extension_get_source (this_extension);
+
+	/* Bind to properties of other extensions for convenience. */
+
+	extension_name = E_SOURCE_EXTENSION_AUTHENTICATION;
+	other_extension = e_source_get_extension (source, extension_name);
+
+	g_object_bind_property (
+		other_extension, "user",
+		this_extension, "user",
+		G_BINDING_BIDIRECTIONAL |
+		G_BINDING_SYNC_CREATE);
+
+	/* XXX Avoid binding the "user" and "method" properties of
+	 *     other_extension until we require GLib 2.28, or else
+	 *     it causes a crash in GBinding.  I reported this in:
+	 *     https://bugzilla.gnome.org/show_bug.cgi?id=639873. */
+	g_object_bind_property_full (
+		this_extension, "user",
+		other_extension, "method",
+		G_BINDING_SYNC_CREATE,
+		source_webdav_user_to_method,
+		NULL,
+		NULL, (GDestroyNotify) NULL);
+
+	extension_name = E_SOURCE_EXTENSION_SECURITY;
+	other_extension = e_source_get_extension (source, extension_name);
+
+	g_object_bind_property (
+		other_extension, "secure",
+		this_extension, "secure",
+		G_BINDING_BIDIRECTIONAL |
+		G_BINDING_SYNC_CREATE);
+}
+
+static void
+e_source_webdav_class_init (ESourceWebdavClass *class)
+{
+	GObjectClass *object_class;
+	ESourceExtensionClass *extension_class;
+
+	g_type_class_add_private (class, sizeof (ESourceWebdavPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->set_property = source_webdav_set_property;
+	object_class->get_property = source_webdav_get_property;
+	object_class->finalize = source_webdav_finalize;
+	object_class->constructed = source_webdav_constructed;
+
+	extension_class = E_SOURCE_EXTENSION_CLASS (class);
+	extension_class->name = E_SOURCE_EXTENSION_WEBDAV_BACKEND;
+
+	g_object_class_install_property (
+		object_class,
+		PROP_AVOID_IFMATCH,
+		g_param_spec_boolean (
+			"avoid-ifmatch",
+			"Avoid If-Match",
+			"Avoid If-Match",
+			FALSE,
+			G_PARAM_READWRITE |
+			G_PARAM_CONSTRUCT |
+			E_SOURCE_PARAM_SETTING));
+
+	g_object_class_install_property (
+		object_class,
+		PROP_HOST,
+		g_param_spec_string (
+			"host",
+			"Host",
+			"WebDAV service host name",
+			NULL,
+			G_PARAM_READWRITE |
+			G_PARAM_CONSTRUCT |
+			E_SOURCE_PARAM_SETTING));
+
+	g_object_class_install_property (
+		object_class,
+		PROP_PATH,
+		g_param_spec_string (
+			"path",
+			"Path",
+			"WebDAV service path",
+			NULL,
+			G_PARAM_READWRITE |
+			G_PARAM_CONSTRUCT |
+			E_SOURCE_PARAM_SETTING));
+
+	g_object_class_install_property (
+		object_class,
+		PROP_PORT,
+		g_param_spec_uint (
+			"port",
+			"Port",
+			"WebDAV service port number",
+			0, G_MAXUINT16, 0,
+			G_PARAM_READWRITE |
+			G_PARAM_CONSTRUCT |
+			E_SOURCE_PARAM_SETTING));
+
+	g_object_class_install_property (
+		object_class,
+		PROP_SECURE,
+		g_param_spec_boolean (
+			"secure",
+			"Secure",
+			"Secure the network connection",
+			FALSE,
+			G_PARAM_READWRITE));
+
+	g_object_class_install_property (
+		object_class,
+		PROP_URI,
+		g_param_spec_boxed (
+			"uri",
+			"URI",
+			"WebDAV service as a SoupURI",
+			SOUP_TYPE_URI,
+			G_PARAM_READWRITE));
+
+	g_object_class_install_property (
+		object_class,
+		PROP_USER,
+		g_param_spec_string (
+			"user",
+			"User",
+			"WebDAV service user name",
+			NULL,
+			G_PARAM_READWRITE));
+}
+
+static void
+e_source_webdav_class_finalize (ESourceWebdavClass *class)
+{
+}
+
+static void
+e_source_webdav_init (ESourceWebdav *extension)
+{
+	extension->priv = E_SOURCE_WEBDAV_GET_PRIVATE (extension);
+	extension->priv->uri = soup_uri_new (NULL);
+}
+
+void
+e_source_webdav_type_register (GTypeModule *type_module)
+{
+	/* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration
+	 *     function, so we have to wrap it with a public function in
+	 *     order to register types from a separate compilation unit. */
+	e_source_webdav_register_type (type_module);
+}
+
+gboolean
+e_source_webdav_get_avoid_ifmatch (ESourceWebdav *extension)
+{
+	g_return_val_if_fail (E_IS_SOURCE_WEBDAV (extension), FALSE);
+
+	return extension->priv->avoid_ifmatch;
+}
+
+void
+e_source_webdav_set_avoid_ifmatch (ESourceWebdav *extension,
+                                   gboolean avoid_ifmatch)
+{
+	g_return_if_fail (E_IS_SOURCE_WEBDAV (extension));
+
+	extension->priv->avoid_ifmatch = avoid_ifmatch;
+
+	g_object_notify (G_OBJECT (extension), "avoid-ifmatch");
+}
+
+const gchar *
+e_source_webdav_get_host (ESourceWebdav *extension)
+{
+	g_return_val_if_fail (E_IS_SOURCE_WEBDAV (extension), NULL);
+
+	return extension->priv->uri->host;
+}
+
+void
+e_source_webdav_set_host (ESourceWebdav *extension,
+                          const gchar *host)
+{
+	GObject *object;
+
+	g_return_if_fail (E_IS_SOURCE_WEBDAV (extension));
+
+	soup_uri_set_host (extension->priv->uri, host);
+
+	object = G_OBJECT (extension);
+	g_object_freeze_notify (object);
+	g_object_notify (object, "host");
+	g_object_notify (object, "uri");
+	g_object_thaw_notify (object);
+}
+
+const gchar *
+e_source_webdav_get_path (ESourceWebdav *extension)
+{
+	g_return_val_if_fail (E_IS_SOURCE_WEBDAV (extension), NULL);
+
+	return extension->priv->uri->path;
+}
+
+void
+e_source_webdav_set_path (ESourceWebdav *extension,
+                          const gchar *path)
+{
+	GObject *object;
+
+	g_return_if_fail (E_IS_SOURCE_WEBDAV (extension));
+
+	soup_uri_set_path (extension->priv->uri, path);
+
+	object = G_OBJECT (extension);
+	g_object_freeze_notify (object);
+	g_object_notify (object, "path");
+	g_object_notify (object, "uri");
+	g_object_thaw_notify (object);
+}
+
+guint16
+e_source_webdav_get_port (ESourceWebdav *extension)
+{
+	g_return_val_if_fail (E_IS_SOURCE_WEBDAV (extension), 0);
+
+	return (guint16) extension->priv->uri->port;
+}
+
+void
+e_source_webdav_set_port (ESourceWebdav *extension,
+                          guint16 port)
+{
+	GObject *object;
+
+	g_return_if_fail (E_IS_SOURCE_WEBDAV (extension));
+
+	soup_uri_set_port (extension->priv->uri, port);
+
+	object = G_OBJECT (extension);
+	g_object_freeze_notify (object);
+	g_object_notify (object, "port");
+	g_object_notify (object, "uri");
+	g_object_thaw_notify (object);
+}
+
+gboolean
+e_source_webdav_get_secure (ESourceWebdav *extension)
+{
+	g_return_val_if_fail (E_IS_SOURCE_WEBDAV (extension), FALSE);
+
+	return (extension->priv->uri->scheme == SOUP_URI_SCHEME_HTTPS);
+}
+
+void
+e_source_webdav_set_secure (ESourceWebdav *extension,
+                            gboolean secure)
+{
+	GObject *object;
+	const gchar *scheme;
+
+	g_return_if_fail (E_IS_SOURCE_WEBDAV (extension));
+
+	scheme = secure ? SOUP_URI_SCHEME_HTTPS : SOUP_URI_SCHEME_HTTP;
+	soup_uri_set_scheme (extension->priv->uri, scheme);
+
+	object = G_OBJECT (extension);
+	g_object_freeze_notify (object);
+	g_object_notify (object, "port");
+	g_object_notify (object, "secure");
+	g_object_notify (object, "uri");
+	g_object_thaw_notify (object);
+}
+
+SoupURI *
+e_source_webdav_get_uri (ESourceWebdav *extension)
+{
+	g_return_val_if_fail (E_IS_SOURCE_WEBDAV (extension), NULL);
+
+	return soup_uri_copy (extension->priv->uri);
+}
+
+void
+e_source_webdav_set_uri (ESourceWebdav *extension,
+                         SoupURI *uri)
+{
+	GObject *object;
+
+	g_return_if_fail (extension != NULL);
+	g_return_if_fail (uri != NULL);
+
+	soup_uri_free (extension->priv->uri);
+	extension->priv->uri = soup_uri_copy (uri);
+
+	object = G_OBJECT (extension);
+	g_object_freeze_notify (object);
+	g_object_notify (object, "host");
+	g_object_notify (object, "path");
+	g_object_notify (object, "port");
+	g_object_notify (object, "secure");
+	g_object_notify (object, "uri");
+	g_object_notify (object, "user");
+	g_object_thaw_notify (object);
+}
+
+const gchar *
+e_source_webdav_get_user (ESourceWebdav *extension)
+{
+	g_return_val_if_fail (E_IS_SOURCE_WEBDAV (extension), NULL);
+
+	return extension->priv->uri->user;
+}
+
+void
+e_source_webdav_set_user (ESourceWebdav *extension,
+                          const gchar *user)
+{
+	GObject *object;
+
+	g_return_if_fail (E_IS_SOURCE_WEBDAV (extension));
+
+	soup_uri_set_user (extension->priv->uri, user);
+
+	object = G_OBJECT (extension);
+	g_object_freeze_notify (object);
+	g_object_notify (object, "user");
+	g_object_notify (object, "uri");
+	g_object_thaw_notify (object);
+}
diff --git a/modules/book-config-webdav/e-source-webdav.h b/modules/book-config-webdav/e-source-webdav.h
new file mode 100644
index 0000000..1f6bb5f
--- /dev/null
+++ b/modules/book-config-webdav/e-source-webdav.h
@@ -0,0 +1,89 @@
+/*
+ * e-source-webdav.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#ifndef E_SOURCE_WEBDAV_H
+#define E_SOURCE_WEBDAV_H
+
+#include <libsoup/soup.h>
+#include <libedataserver/e-source-extension.h>
+
+/* Standard GObject macros */
+#define E_TYPE_SOURCE_WEBDAV \
+	(e_source_webdav_get_type ())
+#define E_SOURCE_WEBDAV(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), E_TYPE_SOURCE_WEBDAV, ESourceWebdav))
+#define E_SOURCE_WEBDAV_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), E_TYPE_SOURCE_WEBDAV, ESourceWebdavClass))
+#define E_IS_SOURCE_WEBDAV(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), E_TYPE_SOURCE_WEBDAV))
+#define E_IS_SOURCE_WEBDAV_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), E_TYPE_SOURCE_WEBDAV))
+#define E_SOURCE_WEBDAV_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), E_TYPE_SOURCE_WEBDAV, ESourceWebdavClass))
+
+#define E_SOURCE_EXTENSION_WEBDAV_BACKEND "WebDAV Backend"
+
+G_BEGIN_DECLS
+
+typedef struct _ESourceWebdav ESourceWebdav;
+typedef struct _ESourceWebdavClass ESourceWebdavClass;
+typedef struct _ESourceWebdavPrivate ESourceWebdavPrivate;
+
+struct _ESourceWebdav {
+	ESourceExtension parent;
+	ESourceWebdavPrivate *priv;
+};
+
+struct _ESourceWebdavClass {
+	ESourceExtensionClass parent_class;
+};
+
+GType		e_source_webdav_get_type	(void);
+void		e_source_webdav_type_register	(GTypeModule *type_module);
+gboolean	e_source_webdav_get_avoid_ifmatch
+						(ESourceWebdav *extension);
+void		e_source_webdav_set_avoid_ifmatch
+						(ESourceWebdav *extension,
+						 gboolean avoid_ifmatch);
+const gchar *	e_source_webdav_get_host	(ESourceWebdav *extension);
+void		e_source_webdav_set_host	(ESourceWebdav *extension,
+						 const gchar *host);
+const gchar *	e_source_webdav_get_path	(ESourceWebdav *extension);
+void		e_source_webdav_set_path	(ESourceWebdav *extension,
+						 const gchar *path);
+guint16		e_source_webdav_get_port	(ESourceWebdav *extension);
+void		e_source_webdav_set_port	(ESourceWebdav *extension,
+						 guint16 port);
+gboolean	e_source_webdav_get_secure	(ESourceWebdav *extension);
+void		e_source_webdav_set_secure	(ESourceWebdav *extension,
+						 gboolean secure);
+SoupURI *	e_source_webdav_get_uri		(ESourceWebdav *extension);
+void		e_source_webdav_set_uri		(ESourceWebdav *extension,
+						 SoupURI *uri);
+const gchar *	e_source_webdav_get_user	(ESourceWebdav *extension);
+void		e_source_webdav_set_user	(ESourceWebdav *extension,
+						 const gchar *user);
+
+G_END_DECLS
+
+#endif /* E_SOURCE_WEBDAV_H */
diff --git a/modules/book-config-webdav/evolution-book-config-webdav.c b/modules/book-config-webdav/evolution-book-config-webdav.c
new file mode 100644
index 0000000..2c2aef3
--- /dev/null
+++ b/modules/book-config-webdav/evolution-book-config-webdav.c
@@ -0,0 +1,235 @@
+/*
+ * evolution-book-config-webdav.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#include <config.h>
+#include <glib/gi18n-lib.h>
+#include <libedataserver/e-source-authentication.h>
+#include <libedataserver/e-source-security.h>
+
+#include <e-util/e-extension.h>
+#include <misc/e-source-config-backend.h>
+#include <addressbook/gui/widgets/e-book-source-config.h>
+
+#include "e-source-webdav.h"
+
+typedef ESourceConfigBackend EBookConfigWebdav;
+typedef ESourceConfigBackendClass EBookConfigWebdavClass;
+
+typedef struct _Context Context;
+
+struct _Context {
+	GtkWidget *url_entry;
+	GtkWidget *user_entry;
+	GtkWidget *avoid_ifmatch;
+};
+
+/* Module Entry Points */
+void e_module_load (GTypeModule *type_module);
+void e_module_unload (GTypeModule *type_module);
+
+/* Forward Declarations */
+GType e_book_config_webdav_get_type (void);
+
+G_DEFINE_DYNAMIC_TYPE (
+	EBookConfigWebdav,
+	e_book_config_webdav,
+	E_TYPE_SOURCE_CONFIG_BACKEND)
+
+static void
+book_config_webdav_context_free (Context *context)
+{
+	g_object_unref (context->url_entry);
+	g_object_unref (context->user_entry);
+	g_object_unref (context->avoid_ifmatch);
+
+	g_slice_free (Context, context);
+}
+
+static gboolean
+book_config_webdav_uri_to_text (GBinding *binding,
+                                const GValue *source_value,
+                                GValue *target_value,
+                                gpointer user_data)
+{
+	SoupURI *uri;
+	gchar *text;
+
+	uri = g_value_get_boxed (source_value);
+	soup_uri_set_user (uri, NULL);
+
+	text = soup_uri_to_string (uri, FALSE);
+	g_value_set_string (target_value, text);
+	g_free (text);
+
+	return TRUE;
+}
+
+static gboolean
+book_config_webdav_text_to_uri (GBinding *binding,
+                                const GValue *source_value,
+                                GValue *target_value,
+                                gpointer user_data)
+{
+	ESourceWebdav *extension = user_data;
+	SoupURI *uri;
+	const gchar *text;
+	const gchar *user;
+
+	text = g_value_get_string (source_value);
+	uri = soup_uri_new (text);
+
+	if (uri == NULL)
+		return FALSE;
+
+	user = e_source_webdav_get_user (extension);
+	soup_uri_set_user (uri, user);
+
+	g_value_set_boxed (target_value, uri);
+	soup_uri_free (uri);
+
+	return TRUE;
+}
+
+static void
+book_config_webdav_insert_widgets (ESourceConfigBackend *backend,
+                                   ESource *scratch_source)
+{
+	ESourceConfig *config;
+	ESourceExtension *extension;
+	GtkWidget *widget;
+	Context *context;
+	const gchar *extension_name;
+	const gchar *uid;
+
+	context = g_slice_new (Context);
+	uid = e_source_get_uid (scratch_source);
+	config = e_source_config_backend_get_config (backend);
+
+	g_object_set_data_full (
+		G_OBJECT (backend), uid, context,
+		(GDestroyNotify) book_config_webdav_context_free);
+
+	e_book_source_config_add_offline_toggle (
+		E_BOOK_SOURCE_CONFIG (config), scratch_source);
+
+	widget = gtk_entry_new ();
+	e_source_config_insert_widget (
+		config, scratch_source, _("URL:"), widget);
+	context->url_entry = g_object_ref (widget);
+	gtk_widget_show (widget);
+
+	widget = gtk_entry_new ();
+	e_source_config_insert_widget (
+		config, scratch_source, _("User:"), widget);
+	context->user_entry = g_object_ref (widget);
+	gtk_widget_show (widget);
+
+	widget = gtk_check_button_new_with_mnemonic (
+		_("_Avoid IfMatch (needed on Apache < 2.2.8)"));
+	e_source_config_insert_widget (
+		config, scratch_source, NULL, widget);
+	context->avoid_ifmatch = g_object_ref (widget);
+	gtk_widget_show (widget);
+
+	extension_name = E_SOURCE_EXTENSION_WEBDAV_BACKEND;
+	extension = e_source_get_extension (scratch_source, extension_name);
+
+	g_object_bind_property (
+		extension, "avoid-ifmatch",
+		context->avoid_ifmatch, "active",
+		G_BINDING_BIDIRECTIONAL |
+		G_BINDING_SYNC_CREATE);
+
+	g_object_bind_property_full (
+		extension, "uri",
+		context->url_entry, "text",
+		G_BINDING_BIDIRECTIONAL |
+		G_BINDING_SYNC_CREATE,
+		book_config_webdav_uri_to_text,
+		book_config_webdav_text_to_uri,
+		extension, (GDestroyNotify) NULL);
+
+	g_object_bind_property (
+		extension, "user",
+		context->user_entry, "text",
+		G_BINDING_BIDIRECTIONAL |
+		G_BINDING_SYNC_CREATE);
+}
+
+static gboolean
+book_config_webdav_check_complete (ESourceConfigBackend *backend,
+                                   ESource *scratch_source)
+{
+	SoupURI *uri;
+	GtkEntry *entry;
+	Context *context;
+	const gchar *uri_string;
+	const gchar *uid;
+	gboolean complete;
+
+	uid = e_source_get_uid (scratch_source);
+	context = g_object_get_data (G_OBJECT (backend), uid);
+	g_return_val_if_fail (context != NULL, FALSE);
+
+	entry = GTK_ENTRY (context->url_entry);
+	uri_string = gtk_entry_get_text (entry);
+
+	uri = soup_uri_new (uri_string);
+	complete = SOUP_URI_VALID_FOR_HTTP (uri);
+
+	if (uri != NULL)
+		soup_uri_free (uri);
+
+	return complete;
+}
+
+static void
+e_book_config_webdav_class_init (ESourceConfigBackendClass *class)
+{
+	EExtensionClass *extension_class;
+
+	extension_class = E_EXTENSION_CLASS (class);
+	extension_class->extensible_type = E_TYPE_BOOK_SOURCE_CONFIG;
+
+	class->backend_name = "webdav";
+	class->insert_widgets = book_config_webdav_insert_widgets;
+	class->check_complete = book_config_webdav_check_complete;
+}
+
+static void
+e_book_config_webdav_class_finalize (ESourceConfigBackendClass *class)
+{
+}
+
+static void
+e_book_config_webdav_init (ESourceConfigBackend *backend)
+{
+	E_TYPE_SOURCE_WEBDAV;
+}
+
+G_MODULE_EXPORT void
+e_module_load (GTypeModule *type_module)
+{
+	e_source_webdav_type_register (type_module);
+	e_book_config_webdav_register_type (type_module);
+}
+
+G_MODULE_EXPORT void
+e_module_unload (GTypeModule *type_module)
+{
+}



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