Re: [evolution-patches] [calendar] patch for #57142



On Fri, 2004-07-16 at 01:59 -0400, JP Rosevear wrote:
> On Thu, 2004-07-15 at 19:52 +0200, Rodrigo Moya wrote:
> > On Thu, 2004-07-15 at 14:35 +0200, Rodrigo Moya wrote:
> > > Updated patch for this, which makes ECalComponent use the same mechanism
> > > we use in the event editor to keep track of alarms that need a
> > > description. Whenever we change the component's summary, all the alarms'
> > > descriptions are updated if needed.
> > 
> > updated patch after some talk with JP on IRC, now including an evolution
> > part.
> 
> Looks good except I think the case where the summary changes and we have
> a custom alarm description is not covered - set_alarm_description_cb
> should make sure the previous summary and the current alarm description
> are the same (I believe the event editor code does this) before updating
> the description.
> 
right. updated patch attached.

cheers
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution-data-server/calendar/ChangeLog,v
retrieving revision 1.296
diff -u -p -r1.296 ChangeLog
--- ChangeLog	14 Jul 2004 09:32:15 -0000	1.296
+++ ChangeLog	16 Jul 2004 08:07:01 -0000
@@ -1,10 +1,22 @@
+2004-07-15  Rodrigo Moya <rodrigo novell com>
+
+	Fixes #57142
+
+	* libecal/e-cal-component.c (ensure_alarm_properties_cb): add the
+	X-EVOLUTION-NEEDS-DESCRIPTION property to the alarms we create
+	with no description, and remove the property from the alarms with
+	a description already.
+
+	(e_cal_component_set_summary, set_alarm_description_cb): set the
+	description on the alarms when the summary changes and remove the
+	above property when we set a valid description.
+
 2004-07-14  Chenthill Palanisamy <pchenthill novell com>
 
        Fixes #60344
        * backends/groupwise/e-cal-backend-groupwise.c:
        (e_cal_backend_groupwise_internal_get_timezone):
        Send the timezone present in tzid instead of sending UTC timezone.
-
 
 2004-07-12  Harish Krishnaswamy  <kharish novell com>
 
Index: libecal/e-cal-component.c
===================================================================
RCS file: /cvs/gnome/evolution-data-server/calendar/libecal/e-cal-component.c,v
retrieving revision 1.8
diff -u -p -r1.8 e-cal-component.c
--- libecal/e-cal-component.c	7 May 2004 16:04:17 -0000	1.8
+++ libecal/e-cal-component.c	16 Jul 2004 08:07:03 -0000
@@ -1211,12 +1211,36 @@ ensure_alarm_properties_cb (gpointer key
 	case ICAL_ACTION_DISPLAY:
 		/* Ensure we have a DESCRIPTION property */
 		prop = icalcomponent_get_first_property (alarm, ICAL_DESCRIPTION_PROPERTY);
-		if (prop)
-			break;
+		if (prop) {
+			if (priv->summary.prop) {
+				icalproperty *xprop;
+
+				xprop = icalcomponent_get_first_property (alarm, ICAL_X_PROPERTY);
+				while (xprop) {
+					str = icalproperty_get_x_name (xprop);
+					if (!strcmp (str, "X-EVOLUTION-NEEDS-DESCRIPTION")) {
+						icalproperty_set_description (prop, priv->summary.prop);
+
+						icalcomponent_remove_property (alarm, xprop);
+						icalproperty_free (xprop);
+						break;
+					}
+
+					xprop = icalcomponent_get_next_property (alarm, ICAL_X_PROPERTY);
+				}
 
-		if (!priv->summary.prop)
+				break;
+			}
+		}
+
+		if (!priv->summary.prop) {
 			str = _("Untitled appointment");
-		else
+
+			/* add the X-EVOLUTION-NEEDS-DESCRIPTION property */
+			prop = icalproperty_new_x ("1");
+			icalproperty_set_x_name (prop, "X-EVOLUTION-NEEDS-DESCRIPTION");
+			icalcomponent_add_property (alarm, prop);
+		} else
 			str = icalproperty_get_summary (priv->summary.prop);
 
 		prop = icalproperty_new_description (str);
@@ -3802,6 +3826,55 @@ e_cal_component_get_summary (ECalCompone
 		summary->altrep = NULL;
 }
 
+typedef struct {
+	char *old_summary;
+	char *new_summary;
+} SetAlarmDescriptionData;
+
+static void
+set_alarm_description_cb (gpointer key, gpointer value, gpointer user_data)
+{
+	icalcomponent *alarm;
+	icalproperty *icalprop, *desc_prop;
+	SetAlarmDescriptionData *sadd;
+	gboolean changed = FALSE;
+	char *old_summary = NULL;
+
+	alarm = value;
+	sadd = user_data;
+
+	/* set the new description on the alarm */
+	desc_prop = icalcomponent_get_first_property (alarm, ICAL_DESCRIPTION_PROPERTY);
+	if (desc_prop)
+		old_summary = icalproperty_get_description (desc_prop);
+	else
+		desc_prop = icalproperty_new_description (sadd->new_summary);
+
+	/* remove the X-EVOLUTION-NEEDS_DESCRIPTION property */
+	icalprop = icalcomponent_get_first_property (alarm, ICAL_X_PROPERTY);
+	while (icalprop) {
+		const char *x_name;
+
+		x_name = icalproperty_get_x_name (icalprop);
+		if (!strcmp (x_name, "X-EVOLUTION-NEEDS-DESCRIPTION")) {
+			icalcomponent_remove_property (alarm, icalprop);
+			icalproperty_free (icalprop);
+
+			icalproperty_set_description (desc_prop, sadd->new_summary);
+			changed = TRUE;
+			break;
+		}
+
+		icalprop = icalcomponent_get_next_property (alarm, ICAL_X_PROPERTY);
+	}
+
+	if (!changed) {
+		if (!strcmp (old_summary ? old_summary : "", sadd->old_summary ? sadd->old_summary : "")) {
+			icalproperty_set_description (desc_prop, sadd->new_summary);
+		}
+	}
+}
+
 /**
  * e_cal_component_set_summary:
  * @comp: A calendar component object.
@@ -3813,6 +3886,7 @@ void
 e_cal_component_set_summary (ECalComponent *comp, ECalComponentText *summary)
 {
 	ECalComponentPrivate *priv;
+	SetAlarmDescriptionData sadd;
 
 	g_return_if_fail (comp != NULL);
 	g_return_if_fail (E_IS_CAL_COMPONENT (comp));
@@ -3834,9 +3908,11 @@ e_cal_component_set_summary (ECalCompone
 
 	g_return_if_fail (summary->value != NULL);
 
-	if (priv->summary.prop)
+	if (priv->summary.prop) {
+		sadd.old_summary = icalproperty_get_summary (priv->summary.prop);
 		icalproperty_set_summary (priv->summary.prop, (char *) summary->value);
-	else {
+	} else {
+		sadd.old_summary = NULL;
 		priv->summary.prop = icalproperty_new_summary ((char *) summary->value);
 		icalcomponent_add_property (priv->icalcomp, priv->summary.prop);
 	}
@@ -3857,6 +3933,10 @@ e_cal_component_set_summary (ECalCompone
  		icalproperty_remove_parameter (priv->summary.prop, ICAL_ALTREP_PARAMETER);
  		priv->summary.altrep_param = NULL; 
 	}
+
+	/* look for alarms that need a description */
+	sadd.new_summary = summary->value;
+	g_hash_table_foreach (priv->alarm_uid_hash, set_alarm_description_cb, &sadd);
 }
 
 /**


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