Re: [evolution-patches] Exchange, calendar fixes deletion, decline problem



Hi,

Attached the patch with the comments addressed.

Please review it.

Thanks,
Arunprakash.

On Sat, 2005-08-13 at 17:13 +0530, Sarfraaz Ahmed wrote:
> A few changes needed.
> 
> > Index: calendar/e-cal-backend-exchange-calendar.c
> > ===================================================================
> 
> 
> >  
> > +static gchar *
> > +get_cal_owner_email (ECalBackendSync *backend)
> 
> This should move to e-cal-backend-exchange.c with a proper function name
> like e_cal_backend_exchange_get_ ....
> 
> > +{
> > +       ECalBackendExchange *cbex = E_CAL_BACKEND_EXCHANGE (backend);
> 
> 
> > +/* stolen from e-itip-control.c with some modifications */
> > +static icalproperty *
> > +find_attendee (icalcomponent *ical_comp, const char *address)
> 
> how about calling this find_attendee_prop ?
> 
> > +{
> > +       icalproperty *prop;
> 
> > +
> > +static gboolean
> > +check_owner_partstatus_for_declined (ECalBackendSync *backend,
> > +                                    icalcomponent *icalcomp)
> > +{
> > +       icalproperty *icalprop;
> > +       icalparameter *param;
> > +       gchar *email;
> > +       
> > +       g_return_val_if_fail (E_IS_CAL_BACKEND (backend), FALSE);
> > +       g_return_val_if_fail (icalcomp != NULL, FALSE);
> 
> These checks are redundant.
> 
> > +       
> > +       email = get_cal_owner_email (backend);
> 
> >  static ECalBackendSyncStatus
> >  create_object (ECalBackendSync *backend, EDataCal *cal,
> >                char **calobj, char **uid)
> > @@ -1195,6 +1264,9 @@ remove_object (ECalBackendSync *backend,
> >         struct icaltimetype time_rid;
> >         ECalBackendSyncStatus ebs_status;
> >         
> > +       /* Will handle only deleting singe instance and all instances
> > of
> > +          recurring appointments and meetings and non-recurring. */
> 
> Instead list down the items we are handling in a bulleted order and
> mention the list of items we do not handle.
> 
> > +       
> >         cbexc = E_CAL_BACKEND_EXCHANGE_CALENDAR (backend);
> >  
> 
> 
> > calobj, mod, &obj, NULL);
> > -                       if (ebs_status !=
> > GNOME_Evolution_Calendar_Success)
> > -                               goto error;
> > -                       
> > -                       g_free (obj);
> > -                       return ebs_status;
> > +               g_free (obj);
> 
> unref the comp here ...
> 
> > +               return ebs_status;
> > +       }
> > +
> 
> 
> > +               }
> >         }
> > +       *object = NULL;
> 
> unref the comp here too.
> 
> >  
> 
> 
> > @@ -1634,7 +1712,7 @@ send_objects (ECalBackendSync *backend, 
> >                 tzcomp = icalcomponent_get_next_component (top_level,
> > 
> > ICAL_VTIMEZONE_COMPONENT);
> >         }
> > -                                                                                                
> 
> There seems to be some blank line here.
> 
> > +
> 
> 
> Please send a new patch with these changes.
> 
> Thanks
> -- Sarfraaz
> 
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-exchange/ChangeLog,v
retrieving revision 1.369
diff -u -p -r1.369 ChangeLog
--- ChangeLog	9 Aug 2005 08:15:40 -0000	1.369
+++ ChangeLog	16 Aug 2005 09:36:10 -0000
@@ -1,3 +1,18 @@
+2005-08-16  Arunprakash  <arunp novell com>
+
+	* calendar/e-cal-backend-exchange-calendar.c (find_attendee_prop)
+	(check_owner_partstatus_for_declined) : Newly added to check
+	the partstatus of the calendar item owner.
+	(remove_object) : Rearranged the code to enable the deletion of
+	non-recurring items also.
+	(receive_objects) : Included checks to remove the calendar item
+	if the request is declined later. Also not to create the item if
+	the request is declined.
+	* calendar/e-cal-backend-exchange.c 
+	(e_cal_backend_exchange_get_owner_email) : Added newly to get the
+	email address of the calendar's owner.
+	Fixes #310478, #310445.
+	
 2005-08-08  Sarfraaz Ahmed <asarfraaz novell com>
 
 	* configure.in : Bumped the version to 2.3.7
Index: calendar/e-cal-backend-exchange-calendar.c
===================================================================
RCS file: /cvs/gnome/evolution-exchange/calendar/e-cal-backend-exchange-calendar.c,v
retrieving revision 1.44
diff -u -p -r1.44 e-cal-backend-exchange-calendar.c
--- calendar/e-cal-backend-exchange-calendar.c	14 Jun 2005 13:12:43 -0000	1.44
+++ calendar/e-cal-backend-exchange-calendar.c	16 Aug 2005 09:36:10 -0000
@@ -55,6 +55,10 @@ static ECalBackendExchange *parent_class
 
 static ECalBackendSyncStatus modify_object_with_href (ECalBackendSync *backend, EDataCal *cal, const char *calobj, CalObjModType mod, char **old_object, const char *href);
 
+static icalproperty *find_attendee_prop (icalcomponent *ical_comp, const char *address);
+static gboolean check_owner_partstatus_for_declined (ECalBackendSync *backend,
+						     icalcomponent *icalcomp);
+
 gboolean check_for_send_options (icalcomponent *icalcomp, E2kProperties *props);
 
 static void
@@ -548,6 +552,61 @@ check_for_send_options (icalcomponent *i
 	return exists;
 }
 
+/* stolen from e-itip-control.c with some modifications */
+static icalproperty *
+find_attendee_prop (icalcomponent *ical_comp, const char *address)
+{
+	icalproperty *prop;
+
+	if (address == NULL)
+		return NULL;
+
+	for (prop = icalcomponent_get_first_property (ical_comp, ICAL_ATTENDEE_PROPERTY);
+	     prop != NULL;
+	     prop = icalcomponent_get_next_property (ical_comp, ICAL_ATTENDEE_PROPERTY)) {
+		icalvalue *value;
+		const char *attendee;
+		char *text;
+
+		value = icalproperty_get_value (prop);
+		if (!value)
+			continue;
+
+		attendee = icalvalue_get_string (value);
+
+		if (!g_strncasecmp (attendee, "mailto:";, 7))
+			attendee += 7;
+		text = g_strstrip (g_strdup (attendee));
+		if (!g_strcasecmp (address, text)) {
+			g_free (text);
+			return prop;
+		}
+		g_free (text);
+	}
+	
+	return NULL;
+}
+
+static gboolean
+check_owner_partstatus_for_declined (ECalBackendSync *backend,
+				     icalcomponent *icalcomp)
+{
+	icalproperty *icalprop;
+	icalparameter *param;
+	gchar *email;
+	
+	email = e_cal_backend_exchange_get_owner_email (backend);
+	icalprop = find_attendee_prop (icalcomp, email);
+	g_free (email);
+	
+	param = icalproperty_get_first_parameter (icalprop, ICAL_PARTSTAT_PARAMETER);
+	
+	if (icalparameter_get_partstat (param) == ICAL_PARTSTAT_DECLINED) {
+		return TRUE;
+	}
+	return FALSE;
+}
+
 static ECalBackendSyncStatus
 create_object (ECalBackendSync *backend, EDataCal *cal,
 	       char **calobj, char **uid)
@@ -1195,6 +1254,10 @@ remove_object (ECalBackendSync *backend,
 	struct icaltimetype time_rid;
 	ECalBackendSyncStatus ebs_status;
 	
+	/* Will handle only CALOBJ_MOD_THIS and CALOBJ_MOD_ALL for mod.
+	   CALOBJ_MOD_THISANDPRIOR and CALOBJ_MOD_THISANDFUTURE are not
+	   handled. */
+	
 	cbexc = E_CAL_BACKEND_EXCHANGE_CALENDAR (backend);
 
 	g_return_val_if_fail (E_IS_CAL_BACKEND_EXCHANGE_CALENDAR (cbexc), GNOME_Evolution_Calendar_InvalidObject);
@@ -1214,38 +1277,30 @@ remove_object (ECalBackendSync *backend,
 	if (old_object)
 		*old_object = e_cal_component_get_as_string (comp);
 	
-	switch (mod) {
-		
-		case CALOBJ_MOD_ALL:
-			ctx = exchange_account_get_context (E_CAL_BACKEND_EXCHANGE (cbexc)->account);	
-			
-			status = e2k_context_delete (ctx, NULL, ecomp->href);			
-			if (E2K_HTTP_STATUS_IS_SUCCESSFUL (status)) {		
-				
-				if (e_cal_backend_exchange_remove_object (E_CAL_BACKEND_EXCHANGE (cbexc), uid)) {
-						g_object_unref (comp);
-						return GNOME_Evolution_Calendar_Success;
-				}
-			}
-			*object = NULL;
-			break;
-		case CALOBJ_MOD_THIS:
-			/*remove_instance and modify */
-			if (rid && *rid) {
-				time_rid = icaltime_from_string (rid);
-				e_cal_util_remove_instances (ecomp->icomp, time_rid, mod);
-			}
-			calobj  = (char *) icalcomponent_as_ical_string (ecomp->icomp);
-			ebs_status = modify_object (backend, cal, calobj, mod, &obj, NULL);
-			if (ebs_status != GNOME_Evolution_Calendar_Success)
-				goto error;
-			
-			g_free (obj);
-			return ebs_status;
+	if (mod == CALOBJ_MOD_THIS && rid && *rid) {
+		/*remove a single instance of a recurring event and modify */
+		time_rid = icaltime_from_string (rid);
+		e_cal_util_remove_instances (ecomp->icomp, time_rid, mod);
+		calobj  = (char *) icalcomponent_as_ical_string (ecomp->icomp);
+		ebs_status = modify_object (backend, cal, calobj, mod, &obj, NULL);
+		g_object_unref (comp);
+		if (ebs_status != GNOME_Evolution_Calendar_Success)
+			goto error;
 		
-		default:
-			break;
+		g_free (obj);
+		return ebs_status;
 	}
+	g_object_unref (comp);
+
+	ctx = exchange_account_get_context (E_CAL_BACKEND_EXCHANGE (cbexc)->account);	
+	
+	status = e2k_context_delete (ctx, NULL, ecomp->href);
+	if (E2K_HTTP_STATUS_IS_SUCCESSFUL (status)) {
+		if (e_cal_backend_exchange_remove_object (E_CAL_BACKEND_EXCHANGE (cbexc), uid)) {
+			return GNOME_Evolution_Calendar_Success;
+		}
+	}
+	*object = NULL;
 
 error:
 	return GNOME_Evolution_Calendar_OtherError;
@@ -1300,26 +1355,38 @@ receive_objects (ECalBackendSync *backen
 		case ICAL_METHOD_REQUEST:
 		case ICAL_METHOD_REPLY:
 			if (get_exchange_comp (E_CAL_BACKEND_EXCHANGE (cbexc), uid)) {
-				char *old_object;
+				char *old_object = NULL;
 				
 				calobj = (char *) icalcomponent_as_ical_string (subcomp);
-				status = modify_object (backend, cal, calobj, CALOBJ_MOD_THIS, &old_object, NULL);
-				if (status != GNOME_Evolution_Calendar_Success)
-					goto error;
-
-				e_cal_backend_notify_object_modified (E_CAL_BACKEND (backend), old_object, calobj);
+				if (check_owner_partstatus_for_declined (backend, subcomp)) {
+					status = remove_object (backend, cal, uid, NULL, 
+								CALOBJ_MOD_ALL, &old_object,
+								NULL);
+					if (status != GNOME_Evolution_Calendar_Success)
+						goto error;
+					e_cal_backend_notify_object_removed (E_CAL_BACKEND (backend), uid,
+									     old_object, NULL);
+				} else {
+					status = modify_object_with_href (backend, cal, calobj,
+									  CALOBJ_MOD_THIS,
+									  &old_object, NULL);
+					if (status != GNOME_Evolution_Calendar_Success)
+						goto error;
+					e_cal_backend_notify_object_modified (E_CAL_BACKEND (backend),
+									      old_object, calobj);
+				}
 
 				g_free (old_object);
-			} else {
+			} else if (!check_owner_partstatus_for_declined (backend, subcomp)) {
 				char *returned_uid;
-
 				calobj = (char *) icalcomponent_as_ical_string (subcomp);
 				status = create_object (backend, cal, &calobj, &returned_uid);
 				if (status != GNOME_Evolution_Calendar_Success)
 					goto error;
 
 				e_cal_backend_notify_object_created (E_CAL_BACKEND (backend), calobj);
-			}
+			} else
+				status = GNOME_Evolution_Calendar_Success;
 			break;
 		case ICAL_METHOD_ADD:
 			/* FIXME This should be doable once all the recurid stuff is done ??*/
Index: calendar/e-cal-backend-exchange.c
===================================================================
RCS file: /cvs/gnome/evolution-exchange/calendar/e-cal-backend-exchange.c,v
retrieving revision 1.37
diff -u -p -r1.37 e-cal-backend-exchange.c
--- calendar/e-cal-backend-exchange.c	28 Jul 2005 06:00:01 -0000	1.37
+++ calendar/e-cal-backend-exchange.c	16 Aug 2005 09:36:11 -0000
@@ -1216,6 +1216,15 @@ e_cal_backend_exchange_get_from_string (
 	return g_strdup_printf ("\"%s\" <%s>", name, addr);
 }
 
+gchar *
+e_cal_backend_exchange_get_owner_email (ECalBackendSync *backend)
+{
+	ECalBackendExchange *cbex = E_CAL_BACKEND_EXCHANGE (backend);
+	ExchangeHierarchy *hier;
+
+	hier = e_folder_exchange_get_hierarchy (cbex->folder);
+	return g_strdup (hier->owner_email);
+}
 
 struct ChangeData {
 	EXmlHash *ehash;
Index: calendar/e-cal-backend-exchange.h
===================================================================
RCS file: /cvs/gnome/evolution-exchange/calendar/e-cal-backend-exchange.h,v
retrieving revision 1.11
diff -u -p -r1.11 e-cal-backend-exchange.h
--- calendar/e-cal-backend-exchange.h	14 Jun 2005 13:12:43 -0000	1.11
+++ calendar/e-cal-backend-exchange.h	16 Aug 2005 09:36:12 -0000
@@ -94,6 +94,7 @@ char * e_cal_backend_exchange_get_from_s
 gboolean e_cal_backend_exchange_is_online (ECalBackendExchange *cbex);
 GSList * get_attachment (ECalBackendExchange *cbex, const char *uid, const char *body, int len);
 char * build_msg ( ECalBackendExchange *cbex, ECalComponent *comp, const char *subject, char **boundary);
+gchar *e_cal_backend_exchange_get_owner_email (ECalBackendSync *backend);
 
 G_END_DECLS
 


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