[evolution-data-server/account-mgmt: 16/28] Add an ESource extension for the webdav backend.



commit c7a35b3f1c4f3a0bafeb5790d799c7ece477e863
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sat Nov 20 14:10:29 2010 -0500

    Add an ESource extension for the webdav backend.

 .../webdav/e-book-backend-webdav-factory.c         |   11 +-
 .../backends/webdav/e-book-backend-webdav.c        |  104 +---
 addressbook/backends/webdav/e-source-webdav.c      |  540 ++++++++++++++++++++
 addressbook/backends/webdav/e-source-webdav.h      |   89 ++++
 4 files changed, 663 insertions(+), 81 deletions(-)
---
diff --git a/addressbook/backends/webdav/e-book-backend-webdav-factory.c b/addressbook/backends/webdav/e-book-backend-webdav-factory.c
index 794a59d..9666a6c 100644
--- a/addressbook/backends/webdav/e-book-backend-webdav-factory.c
+++ b/addressbook/backends/webdav/e-book-backend-webdav-factory.c
@@ -28,16 +28,19 @@ E_BOOK_BACKEND_FACTORY_SIMPLE (webdav, Webdav, e_book_backend_webdav_new)
 
 static GType webdav_type;
 
-void eds_module_initialize (GTypeModule *module)
+void
+eds_module_initialize (GTypeModule *type_module)
 {
-	webdav_type = _webdav_factory_get_type (module);
+	webdav_type = _webdav_factory_get_type (type_module);
 }
 
-void eds_module_shutdown (void)
+void
+eds_module_shutdown (void)
 {
 }
 
-void eds_module_list_types (const GType **types, gint *num_types)
+void
+eds_module_list_types (const GType **types, gint *num_types)
 {
 	*types     = &webdav_type;
 	*num_types = 1;
diff --git a/addressbook/backends/webdav/e-book-backend-webdav.c b/addressbook/backends/webdav/e-book-backend-webdav.c
index 4c18e8d..e1beff8 100644
--- a/addressbook/backends/webdav/e-book-backend-webdav.c
+++ b/addressbook/backends/webdav/e-book-backend-webdav.c
@@ -36,6 +36,8 @@
 #include <libedataserver/e-url.h>
 #include <libedataserver/e-flag.h>
 #include <libedataserver/e-proxy.h>
+#include <libedataserver/e-source-offline.h>
+#include <libedataserver/e-source-webdav.h>
 #include <libebook/e-contact.h>
 #include <libebook/e-address-western.h>
 
@@ -189,15 +191,21 @@ download_contact (EBookBackendWebdav *webdav, const gchar *uri)
 static guint
 upload_contact (EBookBackendWebdav *webdav, EContact *contact, gchar **reason)
 {
-	ESource     *source = e_book_backend_get_source (E_BOOK_BACKEND (webdav));
+	ESource     *source;
+	ESourceWebdav *webdav_extension;
 	SoupMessage *message;
 	gchar       *uri;
 	gchar       *etag;
 	const gchar  *new_etag, *redir_uri;
 	gchar        *request;
 	guint        status;
-	const gchar  *property;
 	gboolean     avoid_ifmatch;
+	const gchar *extension_name;
+
+	source = e_book_backend_get_source (E_BOOK_BACKEND (webdav));
+
+	extension_name = E_SOURCE_EXTENSION_WEBDAV_BACKEND;
+	webdav_extension = e_source_get_extension (source, extension_name);
 
 	uri = e_contact_get (contact, E_CONTACT_UID);
 	if (uri == NULL) {
@@ -209,12 +217,7 @@ upload_contact (EBookBackendWebdav *webdav, EContact *contact, gchar **reason)
 	soup_message_headers_append (message->request_headers, "User-Agent", USERAGENT);
 	soup_message_headers_append (message->request_headers, "Connection", "close");
 
-	property = e_source_get_property(source, "avoid_ifmatch");
-	if (property != NULL && strcmp(property, "1") == 0) {
-		avoid_ifmatch = TRUE;
-	} else {
-		avoid_ifmatch = FALSE;
-	}
+	avoid_ifmatch = e_source_webdav_get_avoid_ifmatch (webdav_extension);
 
 	/* some servers (like apache < 2.2.8) don't handle If-Match, correctly so
 	 * we can leave it out */
@@ -1204,89 +1207,41 @@ proxy_settings_changed (EProxy *proxy, gpointer user_data)
 
 static void
 e_book_backend_webdav_load_source (EBookBackend *backend,
-                                  ESource *source, gboolean only_if_exists, GError **perror)
+                                   ESource *source,
+                                   gboolean only_if_exists,
+                                   GError **perror)
 {
 	EBookBackendWebdav        *webdav = E_BOOK_BACKEND_WEBDAV (backend);
 	EBookBackendWebdavPrivate *priv   = webdav->priv;
-	gchar                     *uri;
+	ESourceOffline            *offline_extension;
+	ESourceWebdav             *webdav_extension;
+	const gchar               *extension_name;
 	const gchar               *cache_dir;
-	const gchar               *offline;
-	const gchar               *use_ssl;
 	gchar                     *filename;
 	SoupSession               *session;
 	SoupURI                   *suri;
-	gint			   port;
 
 	/* will try fetch ctag for the first time, if it fails then sets this to FALSE */
 	priv->supports_getctag = TRUE;
 
 	cache_dir = e_book_backend_get_cache_dir (backend);
 
-	uri = e_source_get_uri (source);
-	if (uri == NULL) {
-		g_propagate_error (perror, EDB_ERROR_EX (OTHER_ERROR, "No uri given for addressbook"));
-		return;
-	}
+	extension_name = E_SOURCE_EXTENSION_OFFLINE;
+	offline_extension = e_source_get_extension (source, extension_name);
 
-	suri = soup_uri_new (uri);
-	g_free (uri);
+	extension_name = E_SOURCE_EXTENSION_WEBDAV_BACKEND;
+	webdav_extension = e_source_get_extension (source, extension_name);
 
-	if (!suri) {
-		g_propagate_error (perror, EDB_ERROR_EX (OTHER_ERROR, "Invalid uri given for addressbook"));
-		return;
-	}
-
-	offline = e_source_get_property(source, "offline_sync");
-	if (offline && g_str_equal(offline, "1"))
-		priv->marked_for_offline = TRUE;
+	priv->marked_for_offline =
+		e_source_offline_get_stay_synchronized (offline_extension);
 
 	if (priv->mode == E_DATA_BOOK_MODE_LOCAL
 			&& !priv->marked_for_offline ) {
-		soup_uri_free (suri);
 		g_propagate_error (perror, EDB_ERROR (OFFLINE_UNAVAILABLE));
 		return;
 	}
 
-	if (!suri->scheme || !g_str_equal (suri->scheme, "webdav")) {
-		/* the book is not for us */
-		soup_uri_free (suri);
-		g_propagate_error (perror, EDB_ERROR_EX (OTHER_ERROR, "Not a webdav uri"));
-		return;
-	}
-
-	port = soup_uri_get_port (suri);
-	use_ssl = e_source_get_property (source, "use_ssl");
-	if (use_ssl != NULL && strcmp (use_ssl, "1") == 0) {
-		soup_uri_set_scheme (suri, "https");
-	} else {
-		soup_uri_set_scheme (suri, "http");
-	}
-
-	if (port > 0 && port != soup_uri_get_port (suri))
-		soup_uri_set_port (suri, port);
-
-	/* append slash if missing */
-	if (!suri->path || !*suri->path || suri->path[strlen (suri->path) - 1] != '/') {
-		gchar *new_path = g_strconcat (suri->path ? suri->path : "", "/", NULL);
-		soup_uri_set_path (suri, new_path);
-		g_free (new_path);
-	}
-
-	if (suri->host && strchr (suri->host, '@')) {
-		gchar *at = strchr (suri->host, '@');
-		gchar *new_user;
-
-		*at = '\0';
-
-		new_user = g_strconcat (suri->user ? suri->user : "", "@", suri->host, NULL);
-
-		*at = '@';
-
-		soup_uri_set_host (suri, at + 1);
-		soup_uri_set_user (suri, new_user);
-
-		g_free (new_user);
-	}
+	suri = e_source_webdav_get_soup_uri (webdav_extension);
 
 	priv->uri = soup_uri_to_string (suri, FALSE);
 	if (!priv->uri) {
@@ -1320,13 +1275,6 @@ e_book_backend_webdav_load_source (EBookBackend *backend,
 }
 
 static void
-e_book_backend_webdav_remove (EBookBackend *backend,	EDataBook *book,
-		guint32 opid)
-{
-	e_data_book_respond_remove (book, opid, EDB_ERROR (SUCCESS));
-}
-
-static void
 e_book_backend_webdav_set_mode (EBookBackend *backend,
                                EDataBookMode mode)
 {
@@ -1415,12 +1363,14 @@ e_book_backend_webdav_class_init (EBookBackendWebdavClass *klass)
 	backend_class->get_required_fields        = e_book_backend_webdav_get_required_fields;
 	backend_class->cancel_operation           = e_book_backend_webdav_cancel_operation;
 	backend_class->get_supported_auth_methods = e_book_backend_webdav_get_supported_auth_methods;
-	backend_class->remove                     = e_book_backend_webdav_remove;
 	backend_class->set_mode                   = e_book_backend_webdav_set_mode;
 
 	object_class->dispose                     = e_book_backend_webdav_dispose;
 
 	g_type_class_add_private (object_class, sizeof (EBookBackendWebdavPrivate));
+
+	/* Register our ESource extension. */
+	E_TYPE_SOURCE_WEBDAV;
 }
 
 static void
diff --git a/addressbook/backends/webdav/e-source-webdav.c b/addressbook/backends/webdav/e-source-webdav.c
new file mode 100644
index 0000000..9c2d56c
--- /dev/null
+++ b/addressbook/backends/webdav/e-source-webdav.c
@@ -0,0 +1,540 @@
+/*
+ * 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, "host",
+		this_extension, "host",
+		G_BINDING_BIDIRECTIONAL |
+		G_BINDING_SYNC_CREATE);
+
+	g_object_bind_property (
+		other_extension, "port",
+		this_extension, "port",
+		G_BINDING_BIDIRECTIONAL |
+		G_BINDING_SYNC_CREATE);
+
+	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_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_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/addressbook/backends/webdav/e-source-webdav.h b/addressbook/backends/webdav/e-source-webdav.h
new file mode 100644
index 0000000..1f6bb5f
--- /dev/null
+++ b/addressbook/backends/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 */



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