]> code.citadel.org Git - citadel.git/blobdiff - webcit/calendar.c
Split up the conflict checker again, this time into six different
[citadel.git] / webcit / calendar.c
index 7b6374eed97bf88d5b4a44a76633221868042f51..fb3f19e89427a6a11b0f1617f3a64417e7976668 100644 (file)
@@ -421,6 +421,7 @@ void display_individual_cal(icalcomponent *cal, long msgnum, char *from, int unr
        struct wcsession *WCC = WC;
        disp_cal *Cal;
        size_t len;
+       time_t final_recurrence = 0;
 
        /* recur variables */
        icalproperty *rrule = NULL;
@@ -435,8 +436,6 @@ 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));
@@ -486,8 +485,7 @@ void display_individual_cal(icalcomponent *cal, long msgnum, char *from, int unr
        /*
         * 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
-        * stops or some outer bound is reached.  The display code *should* automatically do the right
-        * thing (but we'll have to see).
+        * stops or some outer bound is reached.  The display code will automatically do the Right Thing.
         */
 
        rrule = icalcomponent_get_first_property(Cal->cal, ICAL_RRULE_PROPERTY);
@@ -496,43 +494,53 @@ void display_individual_cal(icalcomponent *cal, long msgnum, char *from, int unr
        ritr = icalrecur_iterator_new(recur, dtstart);
        if (!ritr) return;
 
+       lprintf(9, "Recurrence found: %s\n", icalrecurrencetype_as_string(&recur));
+
        while (next = icalrecur_iterator_next(ritr), !icaltime_is_null_time(next) ) {
                ++num_recur;
 
-               /* 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));
+               if (num_recur > 1) {            /* Skip the first one.  We already did it at the root. */
+
+                       /* 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;
        
-               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_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);
+                               final_recurrence = Cal->event_start;
+                       }
+       
+                       ps = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
+                       if (ps != NULL) {
+                               icalcomponent_remove_property(Cal->cal, ps);
 
-               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 */
+                               /* Make a new dtend */
+                               ps = icalproperty_new_dtend(icaltime_add(next, dur));
+       
+                               /* and stick it somewhere */
+                               icalcomponent_add_property(Cal->cal, ps);
+                       }
+       
+                       Put(WCC->disp_cal_items, 
+                               (char*) &Cal->event_start,
+                               sizeof(Cal->event_start), 
+                               Cal, 
+                               delete_cal);
                }
-
-               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));
+       lprintf(9, "Performed %d recurrences; final one is %s", num_recur, ctime(&final_recurrence));
 
 #endif /* TECH_PREVIEW */