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



commit 30469c125b5c69d1da7d78ecc00f24aa3a089f49
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 |  216 +++++++++++++-------
 calendar/backends/caldav/e-cal-backend-caldav.c    |  211 +++++++++++--------
 calendar/backends/caldav/e-source-caldav.c         |  201 ++++++++++++++++++
 calendar/backends/caldav/e-source-caldav.h         |   71 +++++++
 5 files changed, 536 insertions(+), 167 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 5e775f4..de65faf 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,74 +67,115 @@ _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
@@ -129,6 +187,12 @@ 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 694a410..b5ac655 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)
 
@@ -918,14 +922,25 @@ soup_authenticate (SoupSession *session,
                    gpointer data)
 {
 	ECalBackendCalDAVPrivate *priv;
-	ECalBackendCalDAV        *cbdav;
+	ECalBackendCalDAV *cbdav;
+	ESourceAuthentication *auth_extension;
+	ESource *source;
+	const gchar *extension_name;
+	const gchar *user;
 
 	cbdav = E_CAL_BACKEND_CALDAV (data);
 	priv = cbdav->priv;
 
+	source = e_cal_backend_get_source (E_CAL_BACKEND (data));
+	extension_name = E_SOURCE_EXTENSION_AUTHENTICATION;
+	auth_extension = e_source_get_extension (source, extension_name);
+	user = e_source_authentication_get_user (auth_extension);
+
 	/* do not send same password twice, but keep it for later use */
-	if (!retrying && priv->credentials && e_credentials_has_key (priv->credentials, E_CREDENTIALS_KEY_USERNAME)) {
-		soup_auth_authenticate (auth, e_credentials_peek (priv->credentials, E_CREDENTIALS_KEY_USERNAME), e_credentials_peek (priv->credentials, E_CREDENTIALS_KEY_PASSWORD));
+	if (!retrying && priv->credentials) {
+		soup_auth_authenticate (
+			auth, user, e_credentials_peek (
+			priv->credentials, E_CREDENTIALS_KEY_PASSWORD));
 		e_credentials_clear_peek (priv->credentials);
 	}
 }
@@ -2256,29 +2271,34 @@ maybe_append_email_domain (const gchar *username,
 static gchar *
 get_usermail (ECalBackend *backend)
 {
-	ECalBackendCalDAV        *cbdav;
-	ECalBackendCalDAVPrivate *priv;
+	ECalBackendCalDAV *cbdav;
 	ESource *source;
+	ESourceAuthentication *auth_extension;
+	ESourceCaldav *caldav_extension;
+	const gchar *extension_name;
+	const gchar *usermail;
+	const gchar *user;
 	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;
+	caldav_extension = e_source_get_extension (source, extension_name);
+
+	usermail = e_source_caldav_get_email (caldav_extension);
+	if (usermail != NULL && *usermail != '\0')
+		return g_strdup (usermail);
 
 	cbdav = E_CAL_BACKEND_CALDAV (backend);
-	priv  = cbdav->priv;
 
-	if (priv && priv->is_google && priv->credentials) {
-		res = maybe_append_email_domain (e_credentials_peek (priv->credentials, E_CREDENTIALS_KEY_USERNAME), "@gmail.com");
-	}
+	extension_name = E_SOURCE_EXTENSION_AUTHENTICATION;
+	auth_extension = e_source_get_extension (source, extension_name);
+	user = e_source_authentication_get_user (auth_extension);
+
+	if (cbdav->priv && cbdav->priv->is_google)
+		res = maybe_append_email_domain (user, "@gmail.com");
 
 	return res;
 }
@@ -2300,9 +2320,11 @@ caldav_get_backend_property (ECalBackendSync *backend,
 	g_return_val_if_fail (prop_value != NULL, FALSE);
 
 	if (g_str_equal (prop_name, CLIENT_BACKEND_PROPERTY_CAPABILITIES)) {
+		ESourceCaldav *extension;
 		ESource *source;
 		GString *caps;
 		gchar *usermail;
+		const gchar *extension_name;
 
 		caps = g_string_new (CAL_STATIC_CAPABILITY_NO_THISANDFUTURE ","
 				     CAL_STATIC_CAPABILITY_NO_THISANDPRIOR ","
@@ -2314,12 +2336,13 @@ caldav_get_backend_property (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);
 		}
 
 		*prop_value = g_string_free (caps, FALSE);
@@ -2361,13 +2384,17 @@ 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  = cbdav->priv;
 
@@ -2375,76 +2402,66 @@ initialize_backend (ECalBackendCalDAV *cbdav,
 	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->auth_required = 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;
+			}
 		}
 	}
 
@@ -2476,8 +2493,13 @@ initialize_backend (ECalBackendCalDAV *cbdav,
 		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;
@@ -2622,7 +2644,7 @@ caldav_authenticate_user (ECalBackendSync *backend,
 	e_credentials_free (priv->credentials);
 	priv->credentials = NULL;
 
-	if (!credentials || !e_credentials_has_key (credentials, E_CREDENTIALS_KEY_USERNAME)) {
+	if (!credentials) {
 		g_mutex_unlock (priv->busy_lock);
 		g_propagate_error (error, EDC_ERROR (AuthenticationRequired));
 		return;
@@ -4457,11 +4479,16 @@ caldav_get_free_busy (ECalBackendSync *backend,
 	icalcomponent *icalcomp;
 	ECalComponent *comp;
 	ECalComponentDateTime dt;
+	ECalComponentOrganizer organizer = {NULL};
+	ESourceAuthentication *auth_extension;
+	ESource *source;
 	struct icaltimetype dtvalue;
 	icaltimezone *utc;
 	gchar *str, *usermail;
 	const GSList *u;
 	GSList *attendees = NULL, *to_free = NULL;
+	const gchar *extension_name;
+	const gchar *user;
 	GError *err = NULL;
 
 	cbdav = E_CAL_BACKEND_CALDAV (backend);
@@ -4512,16 +4539,17 @@ caldav_get_free_busy (ECalBackendSync *backend,
 		usermail = NULL;
 	}
 
-	if ((priv->credentials && e_credentials_has_key (priv->credentials, E_CREDENTIALS_KEY_USERNAME)) || usermail) {
-		ECalComponentOrganizer organizer = {NULL};
-
-		organizer.value = usermail ? usermail : e_credentials_peek (priv->credentials, E_CREDENTIALS_KEY_USERNAME);
-		organizer.value = g_strconcat ("mailto:";, organizer.value, NULL);
-
-		e_cal_component_set_organizer (comp, &organizer);
+	source = e_cal_backend_get_source (E_CAL_BACKEND (backend));
+	extension_name = E_SOURCE_EXTENSION_AUTHENTICATION;
+	auth_extension = e_source_get_extension (source, extension_name);
+	user = e_source_authentication_get_user (auth_extension);
 
-		g_free ((gchar *) organizer.value);
-	}
+	if (usermail != NULL)
+		organizer.value = g_strconcat ("mailto:";, usermail, NULL);
+	else
+		organizer.value = g_strconcat ("mailto:";, user, NULL);
+	e_cal_component_set_organizer (comp, &organizer);
+	g_free ((gchar *) organizer.value);
 
 	g_free (usermail);
 
@@ -4881,4 +4909,7 @@ e_cal_backend_caldav_class_init (ECalBackendCalDAVClass *class)
 	backend_class->set_online		= caldav_set_online;
 
 	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]