more work on recurrence
authorArt Cancro <ajc@citadel.org>
Tue, 15 Jul 2008 19:05:24 +0000 (19:05 +0000)
committerArt Cancro <ajc@citadel.org>
Tue, 15 Jul 2008 19:05:24 +0000 (19:05 +0000)
webcit/calendar.c

index f638a709650c484cbb6c326d3a1a87aa10abdcac..32a3e02f535b7644ab83e7b771abd615edbc6cac 100644 (file)
@@ -417,6 +417,7 @@ void display_individual_cal(icalcomponent *cal, long msgnum, char *from, int unr
 {
        icalproperty *ps = NULL;
        struct icaltimetype dtstart, dtend;
+       struct icaldurationtype dur;
        struct wcsession *WCC = WC;
        disp_cal *Cal;
        size_t len;
@@ -433,7 +434,10 @@ void display_individual_cal(icalcomponent *cal, long msgnum, char *from, int unr
        
        if (WCC->disp_cal_items == NULL)
                WCC->disp_cal_items = NewHash(0, Flathash);
-       
+
+
+
+       /* Note: anything we do here, we also have to do below for the recurrences. */
        Cal = (disp_cal*) malloc(sizeof(disp_cal));
        memset(Cal, 0, sizeof(disp_cal));
 
@@ -475,6 +479,10 @@ void display_individual_cal(icalcomponent *cal, long msgnum, char *from, int unr
 
        if (icaltime_is_null_time(dtstart)) return;     /* Can't recur without a start time */
 
+       if (!icaltime_is_null_time(dtend)) {            /* Need duration for recurrences */
+               dur = icaltime_subtract(dtend, dtstart);
+       }
+
        /*
         * Just let libical iterate the recurrence, and keep looping back to the top of this function,
         * adding new hash entries that all point back to the same msgnum, until either the iteration
@@ -490,9 +498,41 @@ void display_individual_cal(icalcomponent *cal, long msgnum, char *from, int unr
 
        while (next = icalrecur_iterator_next(ritr), !icaltime_is_null_time(next) ) {
                ++num_recur;
-               lprintf(9, "* Doing a recurrence %d\n", num_recur);
-               /* FIXME this is unfinished */
+
+               /* Note: anything we do here, we also have to do above for the root event. */
+               Cal = (disp_cal*) malloc(sizeof(disp_cal));
+               memset(Cal, 0, sizeof(disp_cal));
+       
+               Cal->cal = icalcomponent_new_clone(cal);
+               Cal->unread = unread;
+               len = strlen(from);
+               Cal->from = (char*)malloc(len+ 1);
+               memcpy(Cal->from, from, len + 1);
+               ical_dezonify(Cal->cal);
+               Cal->cal_msgnum = msgnum;
+
+               ps = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
+               if (ps != NULL) {
+                       icalcomponent_remove_property(Cal->cal, ps);
+                       ps = icalproperty_new_dtstart(next);
+                       icalcomponent_add_property(Cal->cal, ps);
+                       Cal->event_start = icaltime_as_timet(next);
+               }
+
+               ps = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
+               if (ps != NULL) {
+                       icalcomponent_remove_property(Cal->cal, ps);
+                       /* FIXME now set the dtend property and stuff it somewhere */
+               }
+
+               Put(WCC->disp_cal_items, 
+                       (char*) &Cal->event_start,
+                       sizeof(Cal->event_start), 
+                       Cal, 
+                       delete_cal);
        }
+       time_t tt = icaltime_as_timet(next);
+       lprintf(9, "Performed %d recurrences; final one is %s", num_recur, ctime(&tt));
 
 #endif /* TECH_PREVIEW */