evolution-data-server r9781 - in trunk/calendar: . backends/caldav



Author: mcrha
Date: Fri Nov 28 10:33:02 2008
New Revision: 9781
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=9781&view=rev

Log:
2008-11-28  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.



Modified:
   trunk/calendar/ChangeLog
   trunk/calendar/backends/caldav/e-cal-backend-caldav-factory.c
   trunk/calendar/backends/caldav/e-cal-backend-caldav.c

Modified: trunk/calendar/backends/caldav/e-cal-backend-caldav-factory.c
==============================================================================
--- trunk/calendar/backends/caldav/e-cal-backend-caldav-factory.c	(original)
+++ trunk/calendar/backends/caldav/e-cal-backend-caldav-factory.c	Fri Nov 28 10:33:02 2008
@@ -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 @@
 void
 eds_module_list_types (const GType **types, int *num_types)
 {
-	   *types = caldav_types;
-	   *num_types = 1;
+	*types = caldav_types;
+	*num_types = 3;
 }

Modified: trunk/calendar/backends/caldav/e-cal-backend-caldav.c
==============================================================================
--- trunk/calendar/backends/caldav/e-cal-backend-caldav.c	(original)
+++ trunk/calendar/backends/caldav/e-cal-backend-caldav.c	Fri Nov 28 10:33:02 2008
@@ -1010,7 +1010,18 @@
 	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?  */
 
 
@@ -1248,31 +1259,34 @@
 	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;
@@ -1611,7 +1625,22 @@
 	}
 
 	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;
@@ -2107,7 +2136,6 @@
 						   ekind);
 
 	while (scomp) {
-
 		/* Remove components from toplevel here */
 		*objects = g_list_prepend (*objects, scomp);
 		icalcomponent_remove_component (icomp, scomp);
@@ -2315,8 +2343,7 @@
 		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) {
@@ -2401,7 +2428,22 @@
 	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);
 



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