]> code.citadel.org Git - citadel.git/blobdiff - webcit/calendar.c
* put QP Decoder intoo its own file
[citadel.git] / webcit / calendar.c
index 8d41f02d4c4c5c69a1fe6857cbe5f6d8799504c2..9013ad3b11750dbd6c6b8849728dc3e95c234027 100644 (file)
@@ -413,7 +413,7 @@ void delete_cal(void *vCal)
  * any iCalendar objects and store them in a hash table.  Later on, the second phase will
  * use this hash table to render the calendar for display.
  */
-void display_individual_cal(icalcomponent *cal, long msgnum, char *from, int unread)
+void display_individual_cal(icalcomponent *cal, long msgnum, char *from, int unread, struct calview *calv)
 {
        icalproperty *ps = NULL;
        struct icaltimetype dtstart, dtend;
@@ -472,8 +472,6 @@ void display_individual_cal(icalcomponent *cal, long msgnum, char *from, int unr
            Cal, 
            delete_cal);
 
-#ifdef TECH_PREVIEW
-
        /* handle recurring events */
 
        if (icaltime_is_null_time(dtstart)) return;     /* Can't recur without a start time */
@@ -485,8 +483,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);
@@ -495,7 +492,8 @@ void display_individual_cal(icalcomponent *cal, long msgnum, char *from, int unr
        ritr = icalrecur_iterator_new(recur, dtstart);
        if (!ritr) return;
 
-       while (next = icalrecur_iterator_next(ritr), !icaltime_is_null_time(next) ) {
+       int stop_rr = 0;
+       while (next = icalrecur_iterator_next(ritr), ((!icaltime_is_null_time(next))&&(!stop_rr)) ) {
                ++num_recur;
 
                if (num_recur > 1) {            /* Skip the first one.  We already did it at the root. */
@@ -532,16 +530,25 @@ void display_individual_cal(icalcomponent *cal, long msgnum, char *from, int unr
                                icalcomponent_add_property(Cal->cal, ps);
                        }
        
-                       Put(WCC->disp_cal_items, 
-                               (char*) &Cal->event_start,
-                               sizeof(Cal->event_start), 
-                               Cal, 
-                               delete_cal);
+                       if ( (Cal->event_start > calv->lower_bound)
+                          && (Cal->event_start < calv->upper_bound) ) {
+                               Put(WCC->disp_cal_items, 
+                                       (char*) &Cal->event_start,
+                                       sizeof(Cal->event_start), 
+                                       Cal, 
+                                       delete_cal
+                               );
+                       }
+                       else {
+                               delete_cal(Cal);
+                       }
+
+                       /* If an upper bound is set, stop when we go out of scope */
+                       if (final_recurrence > calv->upper_bound) stop_rr = 1;
                }
        }
-       lprintf(9, "Performed %d recurrences; final one is %s", num_recur, ctime(&final_recurrence));
-
-#endif /* TECH_PREVIEW */
+       icalrecur_iterator_free(ritr);
+       /* lprintf(9, "Performed %d recurrences; final one is %s", num_recur, ctime(&final_recurrence)); */
 
 }
 
@@ -550,7 +557,8 @@ void display_individual_cal(icalcomponent *cal, long msgnum, char *from, int unr
 /*
  * Display a task by itself (for editing)
  */
-void display_edit_individual_task(icalcomponent *supplied_vtodo, long msgnum, char *from, int unread) 
+void display_edit_individual_task(icalcomponent *supplied_vtodo, long msgnum, char *from,
+                       int unread, struct calview *calv)
 {
        icalcomponent *vtodo;
        icalproperty *p;
@@ -577,8 +585,7 @@ void display_edit_individual_task(icalcomponent *supplied_vtodo, long msgnum, ch
                                icalcomponent_get_first_component(
                                        vtodo, ICAL_VTODO_COMPONENT
                                        ), 
-                               msgnum,
-                               from, unread
+                               msgnum, from, unread, calv
                                );
                        return;
                }
@@ -642,7 +649,7 @@ void display_edit_individual_task(icalcomponent *supplied_vtodo, long msgnum, ch
        }
        else
                IcalTime = icaltime_current_time_with_zone(get_default_icaltimezone());
-       display_icaltimetype_as_webform(&IcalTime, "dtstart");
+       display_icaltimetype_as_webform(&IcalTime, "dtstart", 0);
        wprintf("</TD></TR>\n");
 
        wprintf("<TR><TD>");
@@ -663,7 +670,7 @@ void display_edit_individual_task(icalcomponent *supplied_vtodo, long msgnum, ch
        }
        else
                IcalTime = icaltime_current_time_with_zone(get_default_icaltimezone());
-       display_icaltimetype_as_webform(&IcalTime, "due");
+       display_icaltimetype_as_webform(&IcalTime, "due", 0);
                
        wprintf("</TD></TR>\n");
        todoStatus = icalcomponent_get_status(vtodo);
@@ -727,7 +734,8 @@ void display_edit_individual_task(icalcomponent *supplied_vtodo, long msgnum, ch
  * \param supplied_vtodo the task to save
  * \param msgnum number of the mesage in our db
  */
-void save_individual_task(icalcomponent *supplied_vtodo, long msgnum, char* from, int unread) 
+void save_individual_task(icalcomponent *supplied_vtodo, long msgnum, char* from, int unread,
+                               struct calview *calv)
 {
        char buf[SIZ];
        int delete_existing = 0;
@@ -752,7 +760,7 @@ void save_individual_task(icalcomponent *supplied_vtodo, long msgnum, char* from
                        save_individual_task(
                                icalcomponent_get_first_component(
                                        vtodo, ICAL_VTODO_COMPONENT), 
-                               msgnum, from, unread
+                               msgnum, from, unread, calv
                                );
                        return;
                }
@@ -914,9 +922,10 @@ void save_individual_task(icalcomponent *supplied_vtodo, long msgnum, char* from
  * the relevant part, deserialize it into a libical component, filter it for
  * the requested object type, and feed it to the specified handler.
  */
-void display_using_handler(long msgnum, int unread,
+void load_ical_object(long msgnum, int unread,
                           icalcomponent_kind which_kind,
-                          void (*callback)(icalcomponent *, long, char*, int)
+                          void (*callback)(icalcomponent *, long, char*, int, struct calview *),
+                          struct calview *calv
        ) 
 {
        char buf[1024];
@@ -967,14 +976,14 @@ void display_using_handler(long msgnum, int unread,
 
                                /* Simple components of desired type */
                                if (icalcomponent_isa(cal) == which_kind) {
-                                       callback(cal, msgnum, from, unread);
+                                       callback(cal, msgnum, from, unread, calv);
                                }
 
                                /* Subcomponents of desired type */
                                for (c = icalcomponent_get_first_component(cal, which_kind);
                                     (c != 0);
                                     c = icalcomponent_get_next_component(cal, which_kind)) {
-                                       callback(c, msgnum, from, unread);
+                                       callback(c, msgnum, from, unread, calv);
                                }
                                icalcomponent_free(cal);
                        }
@@ -987,15 +996,15 @@ void display_using_handler(long msgnum, int unread,
 /*
  * Display a calendar item
  */
-void display_calendar(long msgnum, int unread) {
-       display_using_handler(msgnum, unread, ICAL_VEVENT_COMPONENT, display_individual_cal);
+void load_calendar_item(message_summary *Msg, int unread, struct calview *c) {
+       load_ical_object(Msg->msgnum, unread, ICAL_VEVENT_COMPONENT, display_individual_cal, c);
 }
 
 /*
  * Display task view
  */
-void display_task(long msgnum, int unread) {
-       display_using_handler(msgnum, unread, ICAL_VTODO_COMPONENT, display_individual_cal);
+void display_task(message_summary *Msg, int unread) {
+       load_ical_object(Msg->msgnum, unread, ICAL_VTODO_COMPONENT, display_individual_cal, NULL);
 }
 
 /*
@@ -1012,13 +1021,15 @@ void display_edit_task(void) {
        msgnum = lbstr("msgnum");
        if (msgnum > 0L) {
                /* existing task */
-               display_using_handler(msgnum, 0,
+               load_ical_object(msgnum, 0,
                                      ICAL_VTODO_COMPONENT,
-                                     display_edit_individual_task);
+                                     display_edit_individual_task,
+                                     NULL
+               );
        }
        else {
                /* new task */
-               display_edit_individual_task(NULL, 0L, "", 0);
+               display_edit_individual_task(NULL, 0L, "", 0, NULL);
        }
 }
 
@@ -1027,13 +1038,12 @@ void display_edit_task(void) {
  */
 void save_task(void) {
        long msgnum = 0L;
-
        msgnum = lbstr("msgnum");
        if (msgnum > 0L) {
-               display_using_handler(msgnum, 0, ICAL_VTODO_COMPONENT, save_individual_task);
+               load_ical_object(msgnum, 0, ICAL_VTODO_COMPONENT, save_individual_task, NULL);
        }
        else {
-               save_individual_task(NULL, 0L, "", 0);
+               save_individual_task(NULL, 0L, "", 0, NULL);
        }
 }
 
@@ -1046,11 +1056,11 @@ void display_edit_event(void) {
        msgnum = lbstr("msgnum");
        if (msgnum > 0L) {
                /* existing event */
-               display_using_handler(msgnum, 0, ICAL_VEVENT_COMPONENT, display_edit_individual_event);
+               load_ical_object(msgnum, 0, ICAL_VEVENT_COMPONENT, display_edit_individual_event, NULL);
        }
        else {
                /* new event */
-               display_edit_individual_event(NULL, 0L, "", 0);
+               display_edit_individual_event(NULL, 0L, "", 0, NULL);
        }
 }
 
@@ -1063,10 +1073,10 @@ void save_event(void) {
        msgnum = lbstr("msgnum");
 
        if (msgnum > 0L) {
-               display_using_handler(msgnum, 0, ICAL_VEVENT_COMPONENT, save_individual_event);
+               load_ical_object(msgnum, 0, ICAL_VEVENT_COMPONENT, save_individual_event, NULL);
        }
        else {
-               save_individual_event(NULL, 0L, "", 0);
+               save_individual_event(NULL, 0L, "", 0, NULL);
        }
 }
 
@@ -1077,7 +1087,7 @@ void save_event(void) {
 /*
  * Anonymous request of freebusy data for a user
  */
-void do_freebusy(char *req) {
+void do_freebusy(const char *req) {
        char who[SIZ];
        char buf[SIZ];
        int len;