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



commit 48acb131e59374ecabc2775af0b14bbdfa217f72
Author: Matthew Barnes <mbarnes redhat com>
Date:   Tue Nov 23 20:23:52 2010 -0500

    Add an ESource extension for the caldav backend.

 calendar/backends/caldav/Makefile.am               |    4 +-
 .../backends/caldav/e-cal-backend-caldav-factory.c |  218 +++++++++++------
 calendar/backends/caldav/e-cal-backend-caldav.c    |  245 ++++++++++----------
 calendar/backends/caldav/e-source-caldav.c         |  201 ++++++++++++++++
 calendar/backends/caldav/e-source-caldav.h         |   71 ++++++
 5 files changed, 543 insertions(+), 196 deletions(-)
---
diff --git a/calendar/backends/caldav/Makefile.am b/calendar/backends/caldav/Makefile.am
index 1ae1232..a081028 100644
--- a/calendar/backends/caldav/Makefile.am
+++ b/calendar/backends/caldav/Makefile.am
@@ -13,7 +13,9 @@ libecalbackendcaldav_la_SOURCES = \
 	e-cal-backend-caldav-factory.c \
 	e-cal-backend-caldav-factory.h \
 	e-cal-backend-caldav.c \
-	e-cal-backend-caldav.h
+	e-cal-backend-caldav.h \
+	e-source-caldav.c \
+	e-source-caldav.h
 
 libecalbackendcaldav_la_LIBADD = \
 	$(top_builddir)/calendar/libedata-cal/libedata-cal-1.2.la \
diff --git a/calendar/backends/caldav/e-cal-backend-caldav-factory.c b/calendar/backends/caldav/e-cal-backend-caldav-factory.c
index 8b21601..a17cacc 100644
--- a/calendar/backends/caldav/e-cal-backend-caldav-factory.c
+++ b/calendar/backends/caldav/e-cal-backend-caldav-factory.c
@@ -30,19 +30,36 @@
 
 #include "e-cal-backend-caldav-factory.h"
 #include "e-cal-backend-caldav.h"
+#include "e-source-caldav.h"
 
-typedef struct {
-	ECalBackendFactory parent_object;
-} ECalBackendCalDAVFactory;
+typedef ECalBackendFactory ECalBackendCaldavEventsFactory;
+typedef ECalBackendFactoryClass ECalBackendCaldavEventsFactoryClass;
 
-typedef struct {
-	ECalBackendFactoryClass parent_class;
-} ECalBackendCalDAVFactoryClass;
+typedef ECalBackendFactory ECalBackendCaldavJournalFactory;
+typedef ECalBackendFactoryClass ECalBackendCaldavJournalFactoryClass;
 
-static void
-ecb_caldav_factory_instance_init (ECalBackendCalDAVFactory *factory)
-{
-}
+typedef ECalBackendFactory ECalBackendCaldavTodosFactory;
+typedef ECalBackendFactoryClass ECalBackendCaldavTodosFactoryClass;
+
+/* Forward Declarations */
+GType e_cal_backend_caldav_events_factory_get_type (void);
+GType e_cal_backend_caldav_journal_factory_get_type (void);
+GType e_cal_backend_caldav_todos_factory_get_type (void);
+
+G_DEFINE_DYNAMIC_TYPE (
+	ECalBackendCaldavEventsFactory,
+	e_cal_backend_caldav_events_factory,
+	E_TYPE_CAL_BACKEND_FACTORY)
+
+G_DEFINE_DYNAMIC_TYPE (
+	ECalBackendCaldavJournalFactory,
+	e_cal_backend_caldav_journal_factory,
+	E_TYPE_CAL_BACKEND_FACTORY)
+
+G_DEFINE_DYNAMIC_TYPE (
+	ECalBackendCaldavTodosFactory,
+	e_cal_backend_caldav_todos_factory,
+	E_TYPE_CAL_BACKEND_FACTORY)
 
 static const gchar *
 _get_protocol (ECalBackendFactory *factory)
@@ -50,84 +67,131 @@ _get_protocol (ECalBackendFactory *factory)
 	return "caldav";
 }
 
-#define declare_functions(_type,_name)						\
-										\
-static ECalBackend*								\
-_new_backend_ ## _type (ECalBackendFactory *factory, ESource *source)		\
-{										\
-	   return g_object_new (E_TYPE_CAL_BACKEND_CALDAV,			\
-				"source", source,				\
-				"kind", ICAL_ ## _type ## _COMPONENT,		\
-				NULL);						\
-}										\
-										\
-static icalcomponent_kind							\
-_get_kind_ ## _type (ECalBackendFactory *factory)				\
-{										\
-	return ICAL_ ## _type ## _COMPONENT;					\
-}										\
-										\
-static void									\
-_backend_factory_class_init_ ## _type (ECalBackendCalDAVFactoryClass *klass)	\
-{										\
-	ECalBackendFactoryClass *bc =  E_CAL_BACKEND_FACTORY_CLASS (klass);	\
-										\
-	g_return_if_fail (bc != NULL);						\
-										\
-	bc->get_protocol = _get_protocol;					\
-	bc->get_kind     = _get_kind_ ## _type;					\
-	bc->new_backend  = _new_backend_ ## _type;				\
-}										\
-										\
-static GType									\
-backend_factory_get_type_ ## _type (GTypeModule *module)			\
-{										\
-	static GType type = 0;							\
-										\
-	GTypeInfo info = {							\
-		sizeof (ECalBackendCalDAVFactoryClass),				\
-		NULL, /* base_class_init */					\
-		NULL, /* base_class_finalize */					\
-		(GClassInitFunc)  _backend_factory_class_init_ ## _type,	\
-		NULL, /* class_finalize */					\
-		NULL, /* class_data */						\
-		sizeof (ECalBackend),						\
-		0,    /* n_preallocs */						\
-		(GInstanceInitFunc) ecb_caldav_factory_instance_init		\
-	   };									\
-										\
-	if (!type) {								\
-		type = g_type_module_register_type (module,			\
-			E_TYPE_CAL_BACKEND_FACTORY,				\
-			_name,							\
-			&info, 0);						\
-	}									\
-										\
-	return type;								\
-}										\
-
-declare_functions (VEVENT,   "ECalBackendCalDAVEventsFactory")
-declare_functions (VTODO,    "ECalBackendCalDAVTodosFactory")
-declare_functions (VJOURNAL, "ECalBackendCalDAVMemosFactory")
-
-static GType caldav_types[3];
+static icalcomponent_kind
+_events_get_kind (ECalBackendFactory *factory)
+{
+	return ICAL_VEVENT_COMPONENT;
+}
+
+static ECalBackend *
+_events_new_backend (ECalBackendFactory *factory,
+                     ESource *source)
+{
+	return g_object_new (
+		E_TYPE_CAL_BACKEND_CALDAV,
+		"kind", ICAL_VEVENT_COMPONENT,
+		"source", source, NULL);
+}
+
+static icalcomponent_kind
+_journal_get_kind (ECalBackendFactory *factory)
+{
+	return ICAL_VJOURNAL_COMPONENT;
+}
+
+static ECalBackend *
+_journal_new_backend (ECalBackendFactory *factory,
+                      ESource *source)
+{
+	return g_object_new (
+		E_TYPE_CAL_BACKEND_CALDAV,
+		"kind", ICAL_VJOURNAL_COMPONENT,
+		"source", source, NULL);
+}
+
+static icalcomponent_kind
+_todos_get_kind (ECalBackendFactory *factory)
+{
+	return ICAL_VTODO_COMPONENT;
+}
+
+static ECalBackend *
+_todos_new_backend (ECalBackendFactory *factory,
+                    ESource *source)
+{
+	return g_object_new (
+		E_TYPE_CAL_BACKEND_CALDAV,
+		"kind", ICAL_VTODO_COMPONENT,
+		"source", source, NULL);
+}
+
+static void
+e_cal_backend_caldav_events_factory_class_init (ECalBackendFactoryClass *class)
+{
+	class->get_protocol = _get_protocol;
+	class->get_kind     = _events_get_kind;
+	class->new_backend  = _events_new_backend;
+}
+
+static void
+e_cal_backend_caldav_events_factory_class_finalize (ECalBackendFactoryClass *class)
+{
+}
+
+static void
+e_cal_backend_caldav_events_factory_init (ECalBackendFactory *factory)
+{
+}
+
+static void
+e_cal_backend_caldav_journal_factory_class_init (ECalBackendFactoryClass *class)
+{
+	class->get_protocol = _get_protocol;
+	class->get_kind     = _journal_get_kind;
+	class->new_backend  = _journal_new_backend;
+}
+
+static void
+e_cal_backend_caldav_journal_factory_class_finalize (ECalBackendFactoryClass *class)
+{
+}
+
+static void
+e_cal_backend_caldav_journal_factory_init (ECalBackendFactory *factory)
+{
+}
+
+static void
+e_cal_backend_caldav_todos_factory_class_init (ECalBackendFactoryClass *class)
+{
+	class->get_protocol = _get_protocol;
+	class->get_kind     = _todos_get_kind;
+	class->new_backend  = _todos_new_backend;
+}
+
+static void
+e_cal_backend_caldav_todos_factory_class_finalize (ECalBackendFactoryClass *class)
+{
+}
+
+static void
+e_cal_backend_caldav_todos_factory_init (ECalBackendFactory *factory)
+{
+}
 
 void
-eds_module_initialize (GTypeModule *module)
+eds_module_initialize (GTypeModule *type_module)
 {
-	caldav_types[0] = backend_factory_get_type_VEVENT   (module);
-	caldav_types[1] = backend_factory_get_type_VTODO    (module);
-	caldav_types[2] = backend_factory_get_type_VJOURNAL (module);
+	e_source_caldav_type_register (type_module);
+	e_cal_backend_caldav_events_factory_register_type (type_module);
+	e_cal_backend_caldav_journal_factory_register_type (type_module);
+	e_cal_backend_caldav_todos_factory_register_type (type_module);
 }
 
 void
-eds_module_shutdown   (void)
+eds_module_shutdown (void)
 {
 }
 
 void
 eds_module_list_types (const GType **types, gint *num_types)
 {
+	static GType caldav_types[3];
+
+	caldav_types[0] = e_cal_backend_caldav_events_factory_get_type ();
+	caldav_types[1] = e_cal_backend_caldav_journal_factory_get_type ();
+	caldav_types[2] = e_cal_backend_caldav_todos_factory_get_type ();
+
 	*types = caldav_types;
-	*num_types = 3;
+	*num_types = G_N_ELEMENTS (caldav_types);
 }
diff --git a/calendar/backends/caldav/e-cal-backend-caldav.c b/calendar/backends/caldav/e-cal-backend-caldav.c
index 5de656b..0a80d9a 100644
--- a/calendar/backends/caldav/e-cal-backend-caldav.c
+++ b/calendar/backends/caldav/e-cal-backend-caldav.c
@@ -31,6 +31,9 @@
 #include <libedataserver/e-data-server-util.h>
 #include <libedataserver/e-xml-hash-utils.h>
 #include <libedataserver/e-proxy.h>
+#include <libedataserver/e-source-authentication.h>
+#include <libedataserver/e-source-offline.h>
+#include <libedataserver/e-source-refresh.h>
 #include <libecal/e-cal-recur.h>
 #include <libecal/e-cal-util.h>
 #include <libecal/e-cal-time-util.h>
@@ -49,6 +52,7 @@
 #include <libsoup/soup.h>
 
 #include "e-cal-backend-caldav.h"
+#include "e-source-caldav.h"
 
 #define d(x)
 
@@ -115,7 +119,7 @@ struct _ECalBackendCalDAVPrivate {
 	/* Authentication info */
 	gchar *username;
 	gchar *password;
-	gboolean need_auth;
+	gboolean auth_required;
 
 	/* object cleanup */
 	gboolean disposed;
@@ -535,7 +539,7 @@ status_code_to_result (SoupMessage *message, ECalBackendCalDAVPrivate  *priv, GE
 		break;
 
 	case 401:
-		if (priv && priv->need_auth)
+		if (priv && priv->auth_required)
 			g_propagate_error (perror, EDC_ERROR (AuthenticationFailed));
 		else
 			g_propagate_error (perror, EDC_ERROR (AuthenticationRequired));
@@ -2170,19 +2174,21 @@ get_usermail (ECalBackend *backend)
 	ECalBackendCalDAV        *cbdav;
 	ECalBackendCalDAVPrivate *priv;
 	ESource *source;
+	ESourceCaldav *extension;
+	const gchar *extension_name;
+	const gchar *usermail;
 	gchar *res = NULL;
 
 	g_return_val_if_fail (backend != NULL, NULL);
 
 	source = e_cal_backend_get_source (backend);
-	if (source) {
-		res = e_source_get_duped_property (source, "usermail");
-		if (res && *res)
-			return res;
 
-		g_free (res);
-		res = NULL;
-	}
+	extension_name = E_SOURCE_EXTENSION_CALDAV_BACKEND;
+	extension = e_source_get_extension (source, extension_name);
+
+	usermail = e_source_caldav_get_email (extension);
+	if (usermail != NULL && *usermail != '\0')
+		return g_strdup (usermail);
 
 	cbdav = E_CAL_BACKEND_CALDAV (backend);
 	priv  = E_CAL_BACKEND_CALDAV_GET_PRIVATE (cbdav);
@@ -2251,6 +2257,8 @@ caldav_get_static_capabilities (ECalBackendSync  *backend,
 				GError          **perror)
 {
 	ESource *source;
+	ESourceCaldav *extension;
+	const gchar *extension_name;
 	GString *caps;
 	gchar *usermail;
 
@@ -2264,13 +2272,13 @@ caldav_get_static_capabilities (ECalBackendSync  *backend,
 	g_free (usermail);
 
 	source = e_cal_backend_get_source (E_CAL_BACKEND (backend));
-	if (source) {
-		const gchar *prop = e_source_get_property (source, "autoschedule");
 
-		if (prop && g_str_equal (prop, "1"))
-			g_string_append (caps, "," CAL_STATIC_CAPABILITY_CREATE_MESSAGES
-					       "," CAL_STATIC_CAPABILITY_SAVE_SCHEDULES);
-	}
+	extension_name = E_SOURCE_EXTENSION_CALDAV_BACKEND;
+	extension = e_source_get_extension (source, extension_name);
+
+	if (e_source_caldav_get_autoschedule (extension))
+		g_string_append (caps, "," CAL_STATIC_CAPABILITY_CREATE_MESSAGES
+				       "," CAL_STATIC_CAPABILITY_SAVE_SCHEDULES);
 
 	*capabilities = g_string_free (caps, FALSE);
 }
@@ -2279,13 +2287,17 @@ static gboolean
 initialize_backend (ECalBackendCalDAV *cbdav, GError **perror)
 {
 	ECalBackendCalDAVPrivate *priv;
+	ESourceAuthentication    *auth_extension;
+	ESourceCaldav            *caldav_extension;
+	ESourceOffline           *offline_extension;
+	ESourceRefresh           *refresh_extension;
 	ECalBackend              *backend;
+	SoupURI                  *soup_uri;
 	ESource                  *source;
-	const gchar		 *os_val;
-	const gchar               *uri;
 	gsize                     len;
-	const gchar              *refresh;
 	const gchar              *cache_dir;
+	const gchar              *extension_name;
+	guint                     interval_in_minutes;
 
 	priv  = E_CAL_BACKEND_CALDAV_GET_PRIVATE (cbdav);
 
@@ -2293,76 +2305,66 @@ initialize_backend (ECalBackendCalDAV *cbdav, GError **perror)
 	source = e_cal_backend_get_source (backend);
 	cache_dir = e_cal_backend_get_cache_dir (backend);
 
-	if (!g_signal_handler_find (G_OBJECT (source), G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, 0, 0, NULL, caldav_source_changed_cb, cbdav))
-		g_signal_connect (G_OBJECT (source), "changed", G_CALLBACK (caldav_source_changed_cb), cbdav);
-
-	os_val = e_source_get_property (source, "offline_sync");
+	extension_name = E_SOURCE_EXTENSION_AUTHENTICATION;
+	auth_extension = e_source_get_extension (source, extension_name);
 
-	if (!os_val || !g_str_equal (os_val, "1")) {
-		priv->do_offline = FALSE;
-	}
+	extension_name = E_SOURCE_EXTENSION_CALDAV_BACKEND;
+	caldav_extension = e_source_get_extension (source, extension_name);
 
-	os_val = e_source_get_property (source, "auth");
-	priv->need_auth = os_val != NULL;
+	extension_name = E_SOURCE_EXTENSION_OFFLINE;
+	offline_extension = e_source_get_extension (source, extension_name);
 
-	os_val = e_source_get_property(source, "ssl");
-	uri = e_cal_backend_get_uri (backend);
+	extension_name = E_SOURCE_EXTENSION_REFRESH;
+	refresh_extension = e_source_get_extension (source, extension_name);
 
-	g_free (priv->uri);
-	priv->uri = NULL;
-	if (g_str_has_prefix (uri, "caldav://")) {
-		const gchar *proto;
+	if (!g_signal_handler_find (G_OBJECT (source), G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, 0, 0, NULL, caldav_source_changed_cb, cbdav))
+		g_signal_connect (G_OBJECT (source), "changed", G_CALLBACK (caldav_source_changed_cb), cbdav);
 
-		if (os_val && os_val[0] == '1') {
-			proto = "https://";;
-		} else {
-			proto = "http://";;
-		}
+	priv->do_offline = e_source_offline_get_stay_synchronized (offline_extension);
 
-		priv->uri = g_strconcat (proto, uri + 9, NULL);
-	} else {
-		priv->uri = g_strdup (uri);
-	}
+	priv->auth_required = e_source_authentication_required (auth_extension);
 
-	if (priv->uri) {
-		SoupURI *suri = soup_uri_new (priv->uri);
+	soup_uri = e_source_webdav_get_soup_uri (
+		E_SOURCE_WEBDAV (caldav_extension));
 
-		/* properly encode uri */
-		if (suri && suri->path) {
-			gchar *tmp, *path;
+	/* properly encode uri */
+	if (soup_uri != NULL && soup_uri->path != NULL) {
+		gchar *tmp, *path;
 
-			if (suri->path && strchr (suri->path, '%')) {
-				/* If path contains anything already encoded, then decode it first,
-				   thus it'll be managed properly. For example, the '#' in a path
-				   is in URI shown as %23 and not doing this decode makes it being
-				   like %2523, which is not what is wanted here. */
-				tmp = soup_uri_decode (suri->path);
-				soup_uri_set_path (suri, tmp);
-				g_free (tmp);
-			}
+		if (strchr (soup_uri->path, '%')) {
+			/* If path contains anything already encoded, then
+			 * decode it first, thus it'll be managed properly.
+			 * For example, the '#' in a path is in URI shown as
+			 * %23 and not doing this decode makes it being like
+			 * %2523, which is not what is wanted here. */
+			tmp = soup_uri_decode (soup_uri->path);
+			soup_uri_set_path (soup_uri, tmp);
+			g_free (tmp);
+		}
 
-			tmp = soup_uri_encode (suri->path, NULL);
-			path = soup_uri_normalize (tmp, "/");
+		tmp = soup_uri_encode (soup_uri->path, NULL);
+		path = soup_uri_normalize (tmp, "/");
 
-			soup_uri_set_path (suri, path);
+		soup_uri_set_path (soup_uri, path);
 
-			g_free (tmp);
-			g_free (path);
-			g_free (priv->uri);
+		g_free (tmp);
+		g_free (path);
+	}
 
-			priv->uri = soup_uri_to_string (suri, FALSE);
-		}
+	g_free (priv->uri);
+	priv->uri = soup_uri_to_string (soup_uri, FALSE);
 
-		soup_uri_free (suri);
-	}
+	soup_uri_free (soup_uri);
 
 	/* remove trailing slashes... */
-	len = strlen (priv->uri);
-	while (len--) {
-		if (priv->uri[len] == '/') {
-			priv->uri[len] = '\0';
-		} else {
-			break;
+	if (priv->uri != NULL) {
+		len = strlen (priv->uri);
+		while (len--) {
+			if (priv->uri[len] == '/') {
+				priv->uri[len] = '\0';
+			} else {
+				break;
+			}
 		}
 	}
 
@@ -2394,8 +2396,13 @@ initialize_backend (ECalBackendCalDAV *cbdav, GError **perror)
 		return FALSE;
 	}
 
-	refresh = e_source_get_property (source, "refresh");
-	priv->refresh_time.tv_sec  = (refresh && atoi (refresh) > 0) ? (60 * atoi (refresh)) : (DEFAULT_REFRESH_TIME);
+	interval_in_minutes =
+		e_source_refresh_get_interval_minutes (refresh_extension);
+
+	if (interval_in_minutes == 0)
+		priv->refresh_time.tv_sec = DEFAULT_REFRESH_TIME;
+	else
+		priv->refresh_time.tv_sec = interval_in_minutes * 60;
 
 	if (!priv->synch_slave) {
 		GThread *slave;
@@ -2454,7 +2461,7 @@ caldav_do_open (ECalBackendSync *backend,
 		return;
 	}
 
-	if (priv->need_auth) {
+	if (priv->auth_required) {
 		if ((username == NULL || password == NULL)) {
 			g_mutex_unlock (priv->busy_lock);
 			g_propagate_error (perror, EDC_ERROR (AuthenticationRequired));
@@ -2536,48 +2543,6 @@ caldav_refresh (ECalBackendSync *backend, EDataCal *cal, GError **perror)
 }
 
 static void
-caldav_remove (ECalBackendSync *backend,
-	       EDataCal        *cal,
-	       GError         **perror)
-{
-	ECalBackendCalDAV        *cbdav;
-	ECalBackendCalDAVPrivate *priv;
-	gboolean                  online;
-
-	cbdav = E_CAL_BACKEND_CALDAV (backend);
-	priv  = E_CAL_BACKEND_CALDAV_GET_PRIVATE (cbdav);
-
-	/* first tell it to die, then wait for its lock */
-	priv->slave_cmd = SLAVE_SHOULD_DIE;
-
-	g_mutex_lock (priv->busy_lock);
-
-	if (!priv->loaded) {
-		g_mutex_unlock (priv->busy_lock);
-		return;
-	}
-
-	if (!check_state (cbdav, &online, NULL)) {
-		/* lie here a bit, but otherwise the calendar will not be removed, even it should */
-		g_print (G_STRLOC ": Failed to check state");
-	}
-
-	e_cal_backend_store_remove (priv->store);
-	priv->store = NULL;
-	priv->loaded = FALSE;
-	priv->opened = FALSE;
-
-	if (priv->synch_slave) {
-		g_cond_signal (priv->cond);
-
-		/* wait until the slave died */
-		g_cond_wait (priv->slave_gone_cond, priv->busy_lock);
-	}
-
-	g_mutex_unlock (priv->busy_lock);
-}
-
-static void
 remove_comp_from_cache_cb (gpointer value, gpointer user_data)
 {
 	ECalComponent *comp = value;
@@ -4429,6 +4394,47 @@ caldav_is_loaded (ECalBackend *backend)
 	return priv->loaded;
 }
 
+static gboolean
+caldav_remove (ECalBackend *backend,
+               GError **error)
+{
+	ECalBackendCalDAV        *cbdav;
+	ECalBackendCalDAVPrivate *priv;
+	gboolean                  online;
+
+	cbdav = E_CAL_BACKEND_CALDAV (backend);
+	priv  = E_CAL_BACKEND_CALDAV_GET_PRIVATE (cbdav);
+
+	/* first tell it to die, then wait for its lock */
+	priv->slave_cmd = SLAVE_SHOULD_DIE;
+
+	g_mutex_lock (priv->busy_lock);
+
+	if (!priv->loaded) {
+		g_mutex_unlock (priv->busy_lock);
+		return TRUE;
+	}
+
+	if (!check_state (cbdav, &online, error))
+		return FALSE;
+
+	e_cal_backend_store_remove (priv->store);
+	priv->store = NULL;
+	priv->loaded = FALSE;
+	priv->opened = FALSE;
+
+	if (priv->synch_slave) {
+		g_cond_signal (priv->cond);
+
+		/* wait until the slave died */
+		g_cond_wait (priv->slave_gone_cond, priv->busy_lock);
+	}
+
+	g_mutex_unlock (priv->busy_lock);
+
+	return TRUE;
+}
+
 static CalMode
 caldav_get_mode (ECalBackend *backend)
 {
@@ -4710,7 +4716,6 @@ e_cal_backend_caldav_class_init (ECalBackendCalDAVClass *class)
 
 	sync_class->open_sync                    = caldav_do_open;
 	sync_class->refresh_sync                 = caldav_refresh;
-	sync_class->remove_sync                  = caldav_remove;
 
 	sync_class->create_object_sync = caldav_create_object;
 	sync_class->modify_object_sync = caldav_modify_object;
@@ -4728,10 +4733,14 @@ e_cal_backend_caldav_class_init (ECalBackendCalDAVClass *class)
 	sync_class->get_changes_sync          = caldav_get_changes;
 
 	backend_class->is_loaded   = caldav_is_loaded;
+	backend_class->remove      = caldav_remove;
 	backend_class->start_query = caldav_start_query;
 	backend_class->get_mode    = caldav_get_mode;
 	backend_class->set_mode    = caldav_set_mode;
 
 	backend_class->internal_get_default_timezone = caldav_internal_get_default_timezone;
 	backend_class->internal_get_timezone         = caldav_internal_get_timezone;
+
+	/* Register our ESource extension. */
+	E_TYPE_SOURCE_CALDAV;
 }
diff --git a/calendar/backends/caldav/e-source-caldav.c b/calendar/backends/caldav/e-source-caldav.c
new file mode 100644
index 0000000..d6e1462
--- /dev/null
+++ b/calendar/backends/caldav/e-source-caldav.c
@@ -0,0 +1,201 @@
+/*
+ * e-source-caldav.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 <webcal://www.gnu.org/licenses/>
+ *
+ */
+
+#include "e-source-caldav.h"
+
+#define E_SOURCE_CALDAV_GET_PRIVATE(obj) \
+	(G_TYPE_INSTANCE_GET_PRIVATE \
+	((obj), E_TYPE_SOURCE_CALDAV, ESourceCaldavPrivate))
+
+struct _ESourceCaldavPrivate {
+	gboolean autoschedule;
+	gchar *email;
+};
+
+enum {
+	PROP_0,
+	PROP_AUTOSCHEDULE,
+	PROP_EMAIL
+};
+
+G_DEFINE_DYNAMIC_TYPE (
+	ESourceCaldav,
+	e_source_caldav,
+	E_TYPE_SOURCE_WEBDAV)
+
+static void
+source_caldav_set_property (GObject *object,
+                            guint property_id,
+                            const GValue *value,
+                            GParamSpec *pspec)
+{
+	switch (property_id) {
+		case PROP_AUTOSCHEDULE:
+			e_source_caldav_set_autoschedule (
+				E_SOURCE_CALDAV (object),
+				g_value_get_boolean (value));
+			return;
+
+		case PROP_EMAIL:
+			e_source_caldav_set_email (
+				E_SOURCE_CALDAV (object),
+				g_value_get_string (value));
+			return;
+	}
+
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+source_caldav_get_property (GObject *object,
+                            guint property_id,
+                            GValue *value,
+                            GParamSpec *pspec)
+{
+	switch (property_id) {
+		case PROP_AUTOSCHEDULE:
+			g_value_set_boolean (
+				value,
+				e_source_caldav_get_autoschedule (
+				E_SOURCE_CALDAV (object)));
+			return;
+
+		case PROP_EMAIL:
+			g_value_set_string (
+				value,
+				e_source_caldav_get_email (
+				E_SOURCE_CALDAV (object)));
+			return;
+	}
+
+	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+source_caldav_finalize (GObject *object)
+{
+	ESourceCaldavPrivate *priv;
+
+	priv = E_SOURCE_CALDAV_GET_PRIVATE (object);
+
+	g_free (priv->email);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (e_source_caldav_parent_class)->finalize (object);
+}
+
+static void
+e_source_caldav_class_init (ESourceCaldavClass *class)
+{
+	GObjectClass *object_class;
+	ESourceExtensionClass *extension_class;
+
+	g_type_class_add_private (class, sizeof (ESourceCaldavPrivate));
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->set_property = source_caldav_set_property;
+	object_class->get_property = source_caldav_get_property;
+	object_class->finalize = source_caldav_finalize;
+
+	extension_class = E_SOURCE_EXTENSION_CLASS (class);
+	extension_class->name = E_SOURCE_EXTENSION_CALDAV_BACKEND;
+
+	g_object_class_install_property (
+		object_class,
+		PROP_AUTOSCHEDULE,
+		g_param_spec_boolean (
+			"autoschedule",
+			"Auto-Schedule",
+			"Server handles meeting invitations",
+			FALSE,
+			G_PARAM_READWRITE |
+			G_PARAM_CONSTRUCT |
+			E_SOURCE_PARAM_SETTING));
+
+	g_object_class_install_property (
+		object_class,
+		PROP_EMAIL,
+		g_param_spec_string (
+			"email",
+			"Email",
+			"User's email address",
+			"",
+			G_PARAM_READWRITE |
+			G_PARAM_CONSTRUCT |
+			E_SOURCE_PARAM_SETTING));
+}
+
+static void
+e_source_caldav_class_finalize (ESourceCaldavClass *class)
+{
+}
+
+static void
+e_source_caldav_init (ESourceCaldav *extension)
+{
+	extension->priv = E_SOURCE_CALDAV_GET_PRIVATE (extension);
+}
+
+void
+e_source_caldav_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_caldav_register_type (type_module);
+}
+
+gboolean
+e_source_caldav_get_autoschedule (ESourceCaldav *extension)
+{
+	g_return_val_if_fail (E_IS_SOURCE_CALDAV (extension), FALSE);
+
+	return extension->priv->autoschedule;
+}
+
+void
+e_source_caldav_set_autoschedule (ESourceCaldav *extension,
+                                  gboolean autoschedule)
+{
+	g_return_if_fail (E_IS_SOURCE_CALDAV (extension));
+
+	extension->priv->autoschedule = autoschedule;
+
+	g_object_notify (G_OBJECT (extension), "autoschedule");
+}
+
+const gchar *
+e_source_caldav_get_email (ESourceCaldav *extension)
+{
+	g_return_val_if_fail (E_IS_SOURCE_CALDAV (extension), NULL);
+
+	return extension->priv->email;
+}
+
+void
+e_source_caldav_set_email (ESourceCaldav *extension,
+                           const gchar *email)
+{
+	g_return_if_fail (E_IS_SOURCE_CALDAV (extension));
+
+	g_free (extension->priv->email);
+	extension->priv->email = g_strdup (email);
+
+	g_object_notify (G_OBJECT (extension), "email");
+}
+
diff --git a/calendar/backends/caldav/e-source-caldav.h b/calendar/backends/caldav/e-source-caldav.h
new file mode 100644
index 0000000..7e46d52
--- /dev/null
+++ b/calendar/backends/caldav/e-source-caldav.h
@@ -0,0 +1,71 @@
+/*
+ * e-source-caldav.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 <webcal://www.gnu.org/licenses/>
+ *
+ */
+
+#ifndef E_SOURCE_CALDAV_H
+#define E_SOURCE_CALDAV_H
+
+#include <libedataserver/e-source-webdav.h>
+
+/* Standard GObject macros */
+#define E_TYPE_SOURCE_CALDAV \
+	(e_source_caldav_get_type ())
+#define E_SOURCE_CALDAV(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), E_TYPE_SOURCE_CALDAV, ESourceCaldav))
+#define E_SOURCE_CALDAV_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), E_TYPE_SOURCE_CALDAV, ESourceCaldavClass))
+#define E_IS_SOURCE_CALDAV(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), E_TYPE_SOURCE_CALDAV))
+#define E_IS_SOURCE_CALDAV_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), E_TYPE_SOURCE_CALDAV))
+#define E_SOURCE_CALDAV_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), E_TYPE_SOURCE_CALDAV, ESourceCaldavClass))
+
+#define E_SOURCE_EXTENSION_CALDAV_BACKEND "CalDAV Backend"
+
+G_BEGIN_DECLS
+
+typedef struct _ESourceCaldav ESourceCaldav;
+typedef struct _ESourceCaldavClass ESourceCaldavClass;
+typedef struct _ESourceCaldavPrivate ESourceCaldavPrivate;
+
+struct _ESourceCaldav {
+	ESourceWebdav parent;
+	ESourceCaldavPrivate *priv;
+};
+
+struct _ESourceCaldavClass {
+	ESourceWebdavClass parent_class;
+};
+
+GType		e_source_caldav_get_type	(void);
+void		e_source_caldav_type_register	(GTypeModule *type_module);
+gboolean	e_source_caldav_get_autoschedule
+						(ESourceCaldav *extension);
+void		e_source_caldav_set_autoschedule
+						(ESourceCaldav *extension,
+						 gboolean autoschedule);
+const gchar *	e_source_caldav_get_email	(ESourceCaldav *extension);
+void		e_source_caldav_set_email	(ESourceCaldav *extension,
+						 const gchar *email);
+
+#endif /* E_SOURCE_CALDAV_H */



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