Index: calendar/ChangeLog
===================================================================
--- calendar/ChangeLog	(revision 9729)
+++ calendar/ChangeLog	(working copy)
@@ -1,3 +1,15 @@
+2008-11-05  Milan Crha  <mcrha@redhat.com>
+
+	** Fix for bug #359745
+
+	* backends/caldav/e-cal-backend-caldav-factory.c:
+	(ecb_caldav_factory_instance_init), (declare_functions),
+	(eds_module_initialize), (eds_module_list_types):
+	* backends/caldav/e-cal-backend-caldav.c: (caldav_server_list_objects),
+	(synchronize_object), (initialize_backend), (caldav_receive_objects),
+	(caldav_get_default_object):
+	Support VTODO and VJOURNAL components on the CalDAV.
+
 2008-11-03  Sankar P  <psankar@novell.com>
 
 License Changes
Index: calendar/backends/caldav/e-cal-backend-caldav.c
===================================================================
--- calendar/backends/caldav/e-cal-backend-caldav.c	(revision 9729)
+++ calendar/backends/caldav/e-cal-backend-caldav.c	(working copy)
@@ -1002,7 +1002,18 @@ caldav_server_list_objects (ECalBackendC
 	xmlSetProp (node, (xmlChar *) "name", (xmlChar *) "VCALENDAR");
 
 	sn = xmlNewTextChild (node, nscd, (xmlChar *) "comp-filter", NULL);
-	xmlSetProp (sn, (xmlChar *) "name", (xmlChar *) "VEVENT");
+	switch (e_cal_backend_get_kind (E_CAL_BACKEND (cbdav))) {
+		default:
+		case ICAL_VEVENT_COMPONENT:
+			xmlSetProp (sn, (xmlChar *) "name", (xmlChar *) "VEVENT");
+			break;
+		case ICAL_VJOURNAL_COMPONENT:
+			xmlSetProp (sn, (xmlChar *) "name", (xmlChar *) "VJOURNAL");
+			break;
+		case ICAL_VTODO_COMPONENT:
+			xmlSetProp (sn, (xmlChar *) "name", (xmlChar *) "VTODO");
+			break;
+	}
 	/* ^^^ add timerange for performance?  */
 
 
@@ -1240,31 +1251,34 @@ synchronize_object (ECalBackendCalDAV *c
 	bkend = E_CAL_BACKEND (cbdav);
 
 	if (kind == ICAL_VCALENDAR_COMPONENT) {
-
 		kind = e_cal_backend_get_kind (bkend);
 		subcomp = icalcomponent_get_first_component (icomp, kind);
 
-		comp = e_cal_component_new ();
-		res = e_cal_component_set_icalcomponent (comp,
+		if (!subcomp) {
+			res = FALSE;
+		} else {
+			comp = e_cal_component_new ();
+			res = e_cal_component_set_icalcomponent (comp,
 						   icalcomponent_new_clone (subcomp));
-		if (res == TRUE) {
-			icaltimezone *zone = icaltimezone_new ();
+			if (res == TRUE) {
+				icaltimezone *zone = icaltimezone_new ();
 
-			e_cal_component_set_href (comp, object->href);
-			e_cal_component_set_etag (comp, object->etag);
+				e_cal_component_set_href (comp, object->href);
+				e_cal_component_set_etag (comp, object->etag);
 
-			for (subcomp = icalcomponent_get_first_component (icomp, ICAL_VTIMEZONE_COMPONENT);
-			    subcomp;
-			    subcomp = icalcomponent_get_next_component (icomp, ICAL_VTIMEZONE_COMPONENT)) {
-				/* copy timezones of the component to our cache to have it available later */
-				if (icaltimezone_set_component (zone, subcomp))
-					e_cal_backend_cache_put_timezone (priv->cache, zone);
-			}
+				for (subcomp = icalcomponent_get_first_component (icomp, ICAL_VTIMEZONE_COMPONENT);
+				    subcomp;
+				    subcomp = icalcomponent_get_next_component (icomp, ICAL_VTIMEZONE_COMPONENT)) {
+					/* copy timezones of the component to our cache to have it available later */
+					if (icaltimezone_set_component (zone, subcomp))
+						e_cal_backend_cache_put_timezone (priv->cache, zone);
+				}
 
-			icaltimezone_free (zone, TRUE);
-		} else {
-			g_object_unref (comp);
-			comp = NULL;
+				icaltimezone_free (zone, TRUE);
+			} else {
+				g_object_unref (comp);
+				comp = NULL;
+			}
 		}
 	} else {
 		res = FALSE;
@@ -1603,7 +1617,22 @@ initialize_backend (ECalBackendCalDAV *c
 	}
 
 	if (priv->cache == NULL) {
-		priv->cache = e_cal_backend_cache_new (priv->uri, E_CAL_SOURCE_TYPE_EVENT);
+		ECalSourceType source_type;
+
+		switch (e_cal_backend_get_kind (E_CAL_BACKEND (cbdav))) {
+			default:
+			case ICAL_VEVENT_COMPONENT:
+				source_type = E_CAL_SOURCE_TYPE_EVENT;
+				break;
+			case ICAL_VTODO_COMPONENT:
+				source_type = E_CAL_SOURCE_TYPE_TODO;
+				break;
+			case ICAL_VJOURNAL_COMPONENT:
+				source_type = E_CAL_SOURCE_TYPE_JOURNAL;
+				break;
+		}
+
+		priv->cache = e_cal_backend_cache_new (priv->uri, source_type);
 
 		if (priv->cache == NULL) {
 			result = GNOME_Evolution_Calendar_OtherError;
@@ -2099,7 +2128,6 @@ extract_objects (icalcomponent       *ic
 						   ekind);
 
 	while (scomp) {
-
 		/* Remove components from toplevel here */
 		*objects = g_list_prepend (*objects, scomp);
 		icalcomponent_remove_component (icomp, scomp);
@@ -2307,8 +2335,7 @@ caldav_receive_objects (ECalBackendSync 
 		return GNOME_Evolution_Calendar_InvalidObject;
 	}
 
-	/* FIXME: use the e_cal_backend_xxx_kind call here */
-	kind = ICAL_VEVENT_COMPONENT;
+	kind = e_cal_backend_get_kind (E_CAL_BACKEND (backend));
 	status = extract_objects (icomp, kind, &objects);
 
 	if (status != GNOME_Evolution_Calendar_Success) {
@@ -2393,7 +2420,22 @@ caldav_get_default_object (ECalBackendSy
 	ECalComponent *comp;
 
  	comp = e_cal_component_new ();
-	e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_EVENT);
+
+ 	switch (e_cal_backend_get_kind (E_CAL_BACKEND (backend))) {
+ 	case ICAL_VEVENT_COMPONENT:
+ 		e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_EVENT);
+ 		break;
+ 	case ICAL_VTODO_COMPONENT:
+ 		e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_TODO);
+ 		break;
+ 	case ICAL_VJOURNAL_COMPONENT:
+ 		e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_JOURNAL);
+ 		break;
+ 	default:
+ 		g_object_unref (comp);
+		return GNOME_Evolution_Calendar_ObjectNotFound;
+ 	}
+
  	*object = e_cal_component_get_as_string (comp);
  	g_object_unref (comp);
 
Index: calendar/backends/caldav/e-cal-backend-caldav-factory.c
===================================================================
--- calendar/backends/caldav/e-cal-backend-caldav-factory.c	(revision 9729)
+++ calendar/backends/caldav/e-cal-backend-caldav-factory.c	(working copy)
@@ -32,79 +32,92 @@
 #include "e-cal-backend-caldav.h"
 
 typedef struct {
-	   ECalBackendFactory parent_object;
+	ECalBackendFactory parent_object;
 } ECalBackendCalDAVFactory;
 
 typedef struct {
-	   ECalBackendFactoryClass parent_class;
+	ECalBackendFactoryClass parent_class;
 } ECalBackendCalDAVFactoryClass;
 
 static void
-e_cal_backend_caldav_factory_instance_init (ECalBackendCalDAVFactory *factory)
+ecb_caldav_factory_instance_init (ECalBackendCalDAVFactory *factory)
 {
 }
 
 static const char *
 _get_protocol (ECalBackendFactory *factory)
 {
-	   return "caldav";
-}
-
-static ECalBackend*
-_events_new_backend (ECalBackendFactory *factory, ESource *source)
-{
-	   return g_object_new (E_TYPE_CAL_BACKEND_CALDAV,
-					    "source", source,
-					    "kind", ICAL_VEVENT_COMPONENT,
-					    NULL);
-}
-
-static icalcomponent_kind
-_events_get_kind (ECalBackendFactory *factory)
-{
-	   return ICAL_VEVENT_COMPONENT;
-}
-
-static void
-events_backend_factory_class_init (ECalBackendCalDAVFactoryClass *klass)
-{
-	   E_CAL_BACKEND_FACTORY_CLASS (klass)->get_protocol = _get_protocol;
-	   E_CAL_BACKEND_FACTORY_CLASS (klass)->get_kind     = _events_get_kind;
-	   E_CAL_BACKEND_FACTORY_CLASS (klass)->new_backend  = _events_new_backend;
-}
-
-static GType
-events_backend_factory_get_type (GTypeModule *module)
-{
-	   GType type;
-
-	   GTypeInfo info = {
-			 sizeof (ECalBackendCalDAVFactoryClass),
-			 NULL, /* base_class_init */
-			 NULL, /* base_class_finalize */
-			 (GClassInitFunc)  events_backend_factory_class_init,
-			 NULL, /* class_finalize */
-			 NULL, /* class_data */
-			 sizeof (ECalBackend),
-			 0,    /* n_preallocs */
-			 (GInstanceInitFunc) e_cal_backend_caldav_factory_instance_init
-	   };
-
-	   type = g_type_module_register_type (module,
-								    E_TYPE_CAL_BACKEND_FACTORY,
-								    "ECalBackendCalDAVEventsFactory",
-								    &info, 0);
-
-	   return type;
+	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[1];
+static GType caldav_types[3];
 
 void
 eds_module_initialize (GTypeModule *module)
 {
-	   caldav_types[0] = events_backend_factory_get_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);
 }
 
 void
@@ -115,6 +128,6 @@ eds_module_shutdown   (void)
 void
 eds_module_list_types (const GType **types, int *num_types)
 {
-	   *types = caldav_types;
-	   *num_types = 1;
+	*types = caldav_types;
+	*num_types = 3;
 }
