evolution-data-server r9955 - in trunk/calendar: . backends/caldav backends/file backends/google libedata-cal



Author: mcrha
Date: Mon Jan 19 14:26:32 2009
New Revision: 9955
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=9955&view=rev

Log:
2009-01-19  Milan Crha  <mcrha redhat com>

	** Fix for bug #272932

	* libedata-cal/e-cal-backend-util.c:
	(e_cal_backend_mail_account_get_default),
	(e_cal_backend_mail_account_is_valid): Do not leak GConfClient.
	* libedata-cal/e-cal-backend-util.h: (e_cal_backend_user_declined):
	* libedata-cal/e-cal-backend-util.c: (e_cal_backend_user_declined),
	(is_attendee_declined): New helper function to check whether user
	declined the meeting or not. It looks into all configured and enabled
	mail accounts and checks with attendees in the icalcomponent.
	* backends/file/e-cal-backend-file.c:
	(e_cal_backend_file_receive_objects):
	* backends/caldav/e-cal-backend-caldav.c: (process_object):
	* backends/google/e-cal-backend-google.c: (receive_object):
	Recognize declined objects and do not add them to the calendar.



Modified:
   trunk/calendar/ChangeLog
   trunk/calendar/backends/caldav/e-cal-backend-caldav.c
   trunk/calendar/backends/file/e-cal-backend-file.c
   trunk/calendar/backends/google/e-cal-backend-google.c
   trunk/calendar/libedata-cal/e-cal-backend-util.c
   trunk/calendar/libedata-cal/e-cal-backend-util.h

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	Mon Jan 19 14:26:32 2009
@@ -2344,6 +2344,7 @@
 	char                     *rid;
 	char                     *ostr;
 	char                     *oostr;
+	gboolean                  is_declined;
 
 	priv = E_CAL_BACKEND_CALDAV_GET_PRIVATE (cbdav);
 	backend = E_CAL_BACKEND (cbdav);
@@ -2374,6 +2375,7 @@
 		case ICAL_METHOD_REQUEST:
 		case ICAL_METHOD_REPLY:
 
+		is_declined = e_cal_backend_user_declined (e_cal_component_get_icalcomponent (ecomp));
 		if (online) {
 			CalDAVObject object = { NULL, };
 
@@ -2387,21 +2389,31 @@
 				object.href  = href;
 				object.etag  = etag;
 
-			} else {
+			} else if (!is_declined) {
 				object.href = e_cal_component_gen_href (ecomp);
 			}
 
-			object.cdata = pack_cobj (cbdav, ecomp);
-			status = caldav_server_put_object (cbdav, &object);
-			e_cal_component_set_href (ecomp, object.href);
-			e_cal_component_set_etag (ecomp, object.etag);
-			caldav_object_free (&object, FALSE);
+			if (!is_declined || ccomp) {
+				if (!is_declined) {
+					object.cdata = pack_cobj (cbdav, ecomp);
+					status = caldav_server_put_object (cbdav, &object);
+				} else {
+					object.cdata = NULL;
+					status = caldav_server_delete_object (cbdav, &object);
+				}
+				e_cal_component_set_href (ecomp, object.href);
+				e_cal_component_set_etag (ecomp, object.etag);
+				caldav_object_free (&object, FALSE);
+			}
 		} else {
-			ECalComponentSyncState sstate;
+			ECalComponentSyncState sstate = E_CAL_COMPONENT_IN_SYNCH;
 
 			if (ccomp) {
-				sstate = E_CAL_COMPONENT_LOCALLY_MODIFIED;
-			} else {
+				if (!is_declined)
+					sstate = E_CAL_COMPONENT_LOCALLY_MODIFIED;
+				else
+					sstate = E_CAL_COMPONENT_LOCALLY_DELETED;
+			} else if (!is_declined) {
 				sstate = E_CAL_COMPONENT_LOCALLY_CREATED;
 			}
 
@@ -2413,18 +2425,21 @@
 			break;
 		}
 
-		e_cal_backend_cache_put_component (priv->cache, ecomp);
+		if (!is_declined)
+			e_cal_backend_cache_put_component (priv->cache, ecomp);
+		else
+			e_cal_backend_cache_remove_component (priv->cache, uid, rid);
 
 		if (ccomp) {
-
-			e_cal_backend_notify_object_modified (backend,
-							      ostr,
-							      oostr);
-
-		} else {
-
-			e_cal_backend_notify_object_created (backend,
-							     ostr);
+			if (!is_declined)
+				e_cal_backend_notify_object_modified (backend, ostr, oostr);
+			else {
+				id = e_cal_component_get_id (ccomp);
+				e_cal_backend_notify_object_removed (E_CAL_BACKEND (backend), id, oostr, NULL);
+				e_cal_component_free_id (id);
+			}
+		} else if (!is_declined) {
+			e_cal_backend_notify_object_created (backend, ostr);
 		}
 
 		break;
@@ -2472,11 +2487,11 @@
 							      rid);
 
 			id = e_cal_component_get_id (ccomp);
-
 			e_cal_backend_notify_object_removed (E_CAL_BACKEND (backend),
 							     id,
 							     oostr,
 							     ostr);
+			e_cal_component_free_id (id);
 			break;
 
 		default:

Modified: trunk/calendar/backends/file/e-cal-backend-file.c
==============================================================================
--- trunk/calendar/backends/file/e-cal-backend-file.c	(original)
+++ trunk/calendar/backends/file/e-cal-backend-file.c	Mon Jan 19 14:26:32 2009
@@ -2559,6 +2559,7 @@
 		const char *uid;
 		char *object, *old_object, *rid, *new_object;
 		ECalBackendFileObject *obj_data;
+		gboolean is_declined;
 
 		subcomp = l->data;
 
@@ -2583,8 +2584,10 @@
 		case ICAL_METHOD_PUBLISH:
 		case ICAL_METHOD_REQUEST:
 		case ICAL_METHOD_REPLY:
+			is_declined = e_cal_backend_user_declined (subcomp);
+
 			/* handle attachments */
-			if (e_cal_component_has_attachments (comp))
+			if (!is_declined && e_cal_component_has_attachments (comp))
 				fetch_attachments (backend, comp);
 			obj_data = g_hash_table_lookup (priv->comp_uid_hash, uid);
 			if (obj_data) {
@@ -2593,13 +2596,27 @@
 					remove_instance (cbfile, obj_data, rid);
 				else
 					remove_component (cbfile, uid, obj_data);
-				add_component (cbfile, comp, FALSE);
+
+				if (!is_declined)
+					add_component (cbfile, comp, FALSE);
 
 				object = e_cal_component_get_as_string (comp);
-				e_cal_backend_notify_object_modified (E_CAL_BACKEND (backend), old_object, object);
+				if (!is_declined)
+					e_cal_backend_notify_object_modified (E_CAL_BACKEND (backend), old_object, object);
+				else {
+					ECalComponentId *id = e_cal_component_get_id (comp);
+
+					if (rid)
+						e_cal_backend_notify_object_removed (E_CAL_BACKEND (backend), id, old_object, object);
+					else
+						e_cal_backend_notify_object_removed (E_CAL_BACKEND (backend), id, old_object, NULL);
+
+					e_cal_component_free_id (id);
+				}
+
 				g_free (object);
 				g_free (old_object);
-			} else {
+			} else if (!is_declined) {
 				add_component (cbfile, comp, FALSE);
 
 				object = e_cal_component_get_as_string (comp);

Modified: trunk/calendar/backends/google/e-cal-backend-google.c
==============================================================================
--- trunk/calendar/backends/google/e-cal-backend-google.c	(original)
+++ trunk/calendar/backends/google/e-cal-backend-google.c	Mon Jan 19 14:26:32 2009
@@ -544,8 +544,7 @@
 	GSList *comps = NULL, *l = NULL;
 	icalproperty_method method;
 	icalproperty *icalprop;
-	gboolean instances = TRUE, found = FALSE;
-	icalparameter_partstat pstatus = 0;
+	gboolean instances = TRUE, found = FALSE, is_declined;
 
 	priv = cbgo->priv;
 	icalprop = icalcomponent_get_first_property (icalcomp, ICAL_X_PROPERTY);	
@@ -561,15 +560,17 @@
 		}
 		icalprop = icalcomponent_get_next_property (icalcomp, ICAL_X_PROPERTY);
 	}
-	
+
+	is_declined = e_cal_backend_user_declined (icalcomp);
+
 	comp = e_cal_component_new ();
 	e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (icalcomp));
 	method = icalcomponent_get_method (icalcomp);	
 
 	/* Attachments */
-	if (e_cal_component_has_attachments (comp)) 
+	if (!is_declined && e_cal_component_has_attachments (comp))
 		fetch_attachments (cbgo, comp);
-	 
+
 	/* Sent to Server */
 	item = e_go_item_from_cal_component (cbgo, comp);	
 	entry =	e_go_item_get_entry (item);
@@ -617,7 +618,7 @@
 	for (l = comps; l != NULL; l = l->next) {
 		ECalComponent *component = E_CAL_COMPONENT (l->data);
 
-		if (pstatus == ICAL_PARTSTAT_DECLINED) {
+		if (is_declined) {
 			ECalComponentId *id = e_cal_component_get_id (component);
 
 			if (e_cal_backend_cache_remove_component (priv->cache, id->uid, id->rid)) {

Modified: trunk/calendar/libedata-cal/e-cal-backend-util.c
==============================================================================
--- trunk/calendar/libedata-cal/e-cal-backend-util.c	(original)
+++ trunk/calendar/libedata-cal/e-cal-backend-util.c	Mon Jan 19 14:26:32 2009
@@ -44,9 +44,13 @@
 {
 	const EAccount *account;
 
-	/* FIXME I think this leaks the gconf client */
-	if (accounts == NULL)
-		accounts = e_account_list_new(gconf_client_get_default());
+	if (accounts == NULL) {
+		GConfClient *gconf = gconf_client_get_default ();
+
+		accounts = e_account_list_new (gconf);
+
+		g_object_unref (gconf);
+	}
 
 	account = e_account_list_get_default(accounts);
 	if (account) {
@@ -71,9 +75,13 @@
 {
 	const EAccount *account;
 
-	/* FIXME I think this leaks the gconf client */
-	if (accounts == NULL)
-		accounts = e_account_list_new(gconf_client_get_default());
+	if (accounts == NULL) {
+		GConfClient *gconf = gconf_client_get_default ();
+
+		accounts = e_account_list_new (gconf);
+
+		g_object_unref (gconf);
+	}
 
 	account = e_account_list_find(accounts, E_ACCOUNT_FIND_ID_ADDRESS, user);
 	if (account)
@@ -142,3 +150,90 @@
 
 	return NULL;
 }
+
+/**
+ * is_attendee_declined:
+ * @param icalcomp Component where to check the attendee list.
+ * @param email Attendee's email to look for.
+ * @return Whether the required attendee declined or not.
+ *         It's not necessary to have this attendee in the list.
+ **/
+static gboolean
+is_attendee_declined (icalcomponent *icalcomp, const char *email)
+{
+	icalproperty *prop;
+	icalparameter *param;
+
+	g_return_val_if_fail (icalcomp != NULL, FALSE);
+	g_return_val_if_fail (email != NULL, FALSE);
+
+	for (prop = icalcomponent_get_first_property (icalcomp, ICAL_ATTENDEE_PROPERTY);
+	     prop != NULL;
+	     prop = icalcomponent_get_next_property (icalcomp, ICAL_ATTENDEE_PROPERTY)) {
+		const char *attendee;
+		char *text = NULL;
+
+		attendee = icalproperty_get_value_as_string (prop);
+		if (!attendee)
+			continue;
+
+		if (!g_ascii_strncasecmp (attendee, "mailto:";, 7))
+			text = g_strdup (attendee + 7);
+		text = g_strstrip (text);
+
+		if (!g_ascii_strcasecmp (email, text)) {
+			g_free (text);
+			break;
+		}
+		g_free (text);
+	}
+
+	if (!prop)
+		return FALSE;
+
+	param = icalproperty_get_first_parameter (prop, ICAL_PARTSTAT_PARAMETER);
+
+	return param && icalparameter_get_partstat (param) == ICAL_PARTSTAT_DECLINED;
+}
+
+/**
+ * e_cal_backend_user_declined:
+ * @param icalcomp Component where to check.
+ * @return Whether icalcomp contains attendee with a mail same as any of configured
+ *         enabled mail account and whether this user declined.
+ **/
+gboolean
+e_cal_backend_user_declined (icalcomponent *icalcomp)
+{
+	gboolean res = FALSE;
+	EAccountList *accounts;
+	GConfClient *gconf;
+
+	g_return_val_if_fail (icalcomp != NULL, FALSE);
+
+	gconf = gconf_client_get_default ();
+	accounts = e_account_list_new (gconf);
+
+	if (accounts) {
+		EIterator *it;
+
+		for (it = e_list_get_iterator (E_LIST (accounts)); e_iterator_is_valid (it); e_iterator_next (it)) {
+			EAccount *account = (EAccount *) e_iterator_get (it);
+
+			if (account && account->enabled && e_account_get_string (account, E_ACCOUNT_ID_ADDRESS)) {
+				res = is_attendee_declined (icalcomp, e_account_get_string (account, E_ACCOUNT_ID_ADDRESS));
+
+				if (res)
+					break;
+			}
+		}
+
+		g_object_unref (it);
+		g_object_unref (accounts);
+	}
+
+	g_object_unref (gconf);
+
+	return res;
+}
+

Modified: trunk/calendar/libedata-cal/e-cal-backend-util.h
==============================================================================
--- trunk/calendar/libedata-cal/e-cal-backend-util.h	(original)
+++ trunk/calendar/libedata-cal/e-cal-backend-util.h	Mon Jan 19 14:26:32 2009
@@ -35,6 +35,8 @@
 
 const char *e_cal_backend_status_to_string (GNOME_Evolution_Calendar_CallStatus status);
 
+gboolean e_cal_backend_user_declined (icalcomponent *icalcomp);
+
 G_END_DECLS
 
 #endif



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