X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Ftasks.c;h=adf758378e08cd549c26993ec61d1ba1be3770f6;hb=4b4dc864ede7c5d8d956febe4a0afb422b78e7c4;hp=c2f4b827864e85038c7922b402aa753e20823268;hpb=e2f37ceb57dfceb0e207171842669e4dd6a46e5f;p=citadel.git diff --git a/webcit/tasks.c b/webcit/tasks.c index c2f4b8278..adf758378 100644 --- a/webcit/tasks.c +++ b/webcit/tasks.c @@ -89,17 +89,15 @@ int tasks_RenderView_or_Tail(SharedMessageStatus *Stat, icalproperty *p; wcsession *WCC = WC; - wprintf("
" - "\n\n" - "\n", + wc_printf("
"); - wprintf(_("Completed?")); - wprintf(""); - wprintf(_("Name of task")); - wprintf(""); - wprintf(_("Date due")); - wprintf(""); - wprintf(_("Category")); - wprintf(" ()
\n\n\n", _("Show All")); nItems = GetCount(WC->disp_cal_items); @@ -123,47 +121,47 @@ int tasks_RenderView_or_Tail(SharedMessageStatus *Stat, int is_date; Cal = (disp_cal*)vCal; - wprintf("\n"); + wc_printf("\n"); + wc_printf("\n"); due = get_task_due_date(Cal->cal, &is_date); - wprintf(""); - wprintf(""); + wc_printf(""); - wprintf(""); + wc_printf(""); + wc_printf(""); } - wprintf("
"); + wc_printf(_("Completed?")); + wc_printf(""); + wc_printf(_("Name of task")); + wc_printf(""); + wc_printf(_("Date due")); + wc_printf(""); + wc_printf(_("Category")); + wc_printf(" ()
"); + wc_printf("
"); todoStatus = icalcomponent_get_status(Cal->cal); - wprintf("\n"); + wc_printf("disabled=\"disabled\">\n"); p = icalcomponent_get_first_property(Cal->cal, ICAL_SUMMARY_PROPERTY); - wprintf("cal_msgnum); - urlescputs(ChrPtr(WC->wc_roomname)); - wprintf("\">"); - /* wprintf("cal_msgnum); + urlescputs(ChrPtr(WC->CurRoom.name)); + wc_printf("\">"); + /* wc_printf(" "); */ if (p != NULL) { escputs((char *)icalproperty_get_comment(p)); } - wprintf("\n"); - wprintf(" 0) { webcit_fmt_date(buf, SIZ, due, is_date ? DATEFMT_RAWDATE : DATEFMT_FULL); - wprintf(">%s",buf); + wc_printf(">%s",buf); } else { - wprintf(">"); + wc_printf(">"); } - wprintf(""); + wc_printf(""); p = icalcomponent_get_first_property(Cal->cal, ICAL_CATEGORIES_PROPERTY); if (p != NULL) { escputs((char *)icalproperty_get_categories(p)); } - wprintf("
\n"); + wc_printf("\n"); /* Free the list */ DeleteHash(&WC->disp_cal_items); @@ -181,12 +179,9 @@ void display_edit_individual_task(icalcomponent *supplied_vtodo, long msgnum, ch icalcomponent *vtodo; icalproperty *p; struct icaltimetype IcalTime; - time_t now; int created_new_vtodo = 0; icalproperty_status todoStatus; - now = time(NULL); - if (supplied_vtodo != NULL) { vtodo = supplied_vtodo; @@ -220,55 +215,55 @@ void display_edit_individual_task(icalcomponent *supplied_vtodo, long msgnum, ch /* TODO: Can we take all this and move it into a template? */ output_headers(1, 1, 1, 0, 0, 0); - wprintf(""); + wc_printf(""); p = icalcomponent_get_first_property(vtodo, ICAL_SUMMARY_PROPERTY); /* Get summary early for title */ - wprintf("
\n"); - wprintf("
"); - wprintf(_("Edit task")); - wprintf("- "); + wc_printf("
\n"); + wc_printf("
"); + wc_printf(_("Edit task")); + wc_printf("- "); if (p != NULL) { escputs((char *)icalproperty_get_comment(p)); } - wprintf("
"); + wc_printf("
"); - wprintf("
\n"); - wprintf("
\n"); - wprintf("
\n "); - wprintf("\n", WC->nonce); - wprintf("\n", msgnum); - wprintf("\n", + wc_printf("
\n"); + wc_printf("\n"); + wc_printf("
\n "); + wc_printf("\n", WC->nonce); + wc_printf("\n", msgnum); + wc_printf("\n", ibstr("return_to_summary")); - wprintf("
"); - wprintf("
"); - wprintf("\n"); + wc_printf(""); + wc_printf("
"); + wc_printf("\n"); - wprintf("\n"); + wc_printf("\">\n"); - wprintf("\n"); + wc_printf(">"); + wc_printf(_("Time associated")); + wc_printf("\n"); - wprintf("\n"); + wc_printf(">"); + wc_printf(_("Time associated")); + wc_printf("\n"); todoStatus = icalcomponent_get_status(vtodo); - wprintf(""); + wc_printf(" >"); + wc_printf(""); /* start category field */ p = icalcomponent_get_first_property(vtodo, ICAL_CATEGORIES_PROPERTY); - wprintf("\n "); + wc_printf("\">"); + wc_printf("\n "); /* end category field */ - wprintf("
"); - wprintf(_("Summary:")); - wprintf("" + wc_printf("
"); + wc_printf(_("Summary:")); + wc_printf("" "
"); - wprintf(_("Start date:")); - wprintf(""); + wc_printf("
"); + wc_printf(_("Start date:")); + wc_printf(""); p = icalcomponent_get_first_property(vtodo, ICAL_DTSTART_PROPERTY); - wprintf(""); - wprintf(_("No date")); + wc_printf(">"); + wc_printf(_("No date")); - wprintf(" "); - wprintf(""); - wprintf(_("or")); - wprintf(" "); + wc_printf(" "); + wc_printf(""); + wc_printf(_("or")); + wc_printf(" "); if (p != NULL) { IcalTime = icalproperty_get_dtstart(p); } @@ -276,28 +271,28 @@ void display_edit_individual_task(icalcomponent *supplied_vtodo, long msgnum, ch IcalTime = icaltime_current_time_with_zone(get_default_icaltimezone()); display_icaltimetype_as_webform(&IcalTime, "dtstart", 0); - wprintf(""); - wprintf(_("Time associated")); - wprintf("
"); - wprintf(_("Due date:")); - wprintf(""); + wc_printf("
"); + wc_printf(_("Due date:")); + wc_printf(""); p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY); - wprintf(""); - wprintf(_("No date")); - wprintf(" "); - wprintf("\n"); - wprintf(_("or")); - wprintf(" "); + wc_printf("CHECKED=\"CHECKED\""); + } + wc_printf(">"); + wc_printf(_("No date")); + wc_printf(" "); + wc_printf("\n"); + wc_printf(_("or")); + wc_printf(" "); if (p != NULL) { IcalTime = icalproperty_get_due(p); } @@ -305,48 +300,48 @@ void display_edit_individual_task(icalcomponent *supplied_vtodo, long msgnum, ch IcalTime = icaltime_current_time_with_zone(get_default_icaltimezone()); display_icaltimetype_as_webform(&IcalTime, "due", 0); - wprintf(""); - wprintf(_("Time associated")); - wprintf("
\n"); - wprintf(_("Completed:")); - wprintf(""); - wprintf("\n"); + wc_printf(_("Completed:")); + wc_printf(""); + wc_printf(""); - wprintf("
"); - wprintf(_("Category:")); - wprintf(""); - wprintf(""); + wc_printf(_("Category:")); + wc_printf(""); + wc_printf(""); - wprintf("
"); - wprintf(_("Description:")); - wprintf(""); - wprintf("
\n"); + wc_printf("
\n"); - wprintf("" + wc_printf("" "" "  " "\n" @@ -357,10 +352,10 @@ void display_edit_individual_task(icalcomponent *supplied_vtodo, long msgnum, ch _("Delete"), _("Cancel") ); - wprintf("
"); - wprintf("\n"); - wprintf("
\n"); - wprintf(""); + wc_printf(""); + wc_printf("\n"); + wc_printf("
\n"); + wc_printf(""); wDumpContent(1); if (created_new_vtodo) { @@ -503,7 +498,7 @@ void save_individual_task(icalcomponent *supplied_vtodo, long msgnum, char* from ); } /** Give this task a UID if it doesn't have one. */ - lprintf(9, "Give this task a UID if it doesn't have one.\n"); + syslog(9, "Give this task a UID if it doesn't have one.\n"); if (icalcomponent_get_first_property(vtodo, ICAL_UID_PROPERTY) == NULL) { generate_uuid(buf); @@ -513,17 +508,17 @@ void save_individual_task(icalcomponent *supplied_vtodo, long msgnum, char* from } /* Increment the sequence ID */ - lprintf(9, "Increment the sequence ID\n"); + syslog(9, "Increment the sequence ID\n"); while (prop = icalcomponent_get_first_property(vtodo, ICAL_SEQUENCE_PROPERTY), (prop != NULL) ) { i = icalproperty_get_sequence(prop); - lprintf(9, "Sequence was %d\n", i); + syslog(9, "Sequence was %d\n", i); if (i > sequence) sequence = i; icalcomponent_remove_property(vtodo, prop); icalproperty_free(prop); } ++sequence; - lprintf(9, "New sequence is %d. Adding...\n", sequence); + syslog(9, "New sequence is %d. Adding...\n", sequence); icalcomponent_add_property(vtodo, icalproperty_new_sequence(sequence) ); @@ -535,7 +530,7 @@ void save_individual_task(icalcomponent *supplied_vtodo, long msgnum, char* from * can't encapsulate something that may already be encapsulated * somewhere else. */ - lprintf(9, "Encapsulating into a full VCALENDAR component\n"); + syslog(9, "Encapsulating into a full VCALENDAR component\n"); encaps = ical_encapsulate_subcomponent(icalcomponent_new_clone(vtodo)); /* Serialize it and save it to the message base */ @@ -575,13 +570,95 @@ void save_individual_task(icalcomponent *supplied_vtodo, long msgnum, char* from /* Go back to wherever we came from */ if (ibstr("return_to_summary") == 1) { - summary(); + do_template("summary_page"); } else { - readloop(readfwd); + readloop(readfwd, eUseDefault); + } +} + + +/* + * free memory allocated using libical + */ +void delete_task(void *vCal) +{ + disp_cal *Cal = (disp_cal*) vCal; + icalcomponent_free(Cal->cal); + free(Cal->from); + free(Cal); +} + + +/* + * Load a Task into a hash table for later display. + */ +void load_task(icalcomponent *event, long msgnum, char *from, int unread, calview *calv) +{ + icalproperty *ps = NULL; + struct icaltimetype dtstart, dtend; + wcsession *WCC = WC; + disp_cal *Cal; + size_t len; + icalcomponent *cptr = NULL; + + dtstart = icaltime_null_time(); + dtend = icaltime_null_time(); + + if (WCC->disp_cal_items == NULL) { + WCC->disp_cal_items = NewHash(0, Flathash); + } + + Cal = (disp_cal*) malloc(sizeof(disp_cal)); + memset(Cal, 0, sizeof(disp_cal)); + Cal->cal = icalcomponent_new_clone(event); + + /* Dezonify and decapsulate at the very last moment */ + ical_dezonify(Cal->cal); + if (icalcomponent_isa(Cal->cal) != ICAL_VTODO_COMPONENT) { + cptr = icalcomponent_get_first_component(Cal->cal, ICAL_VTODO_COMPONENT); + if (cptr) { + cptr = icalcomponent_new_clone(cptr); + icalcomponent_free(Cal->cal); + Cal->cal = cptr; + } } + + Cal->unread = unread; + len = strlen(from); + Cal->from = (char*)malloc(len+ 1); + memcpy(Cal->from, from, len + 1); + Cal->cal_msgnum = msgnum; + + /* Precalculate the starting date and time of this event, and store it in our top-level + * structure. Later, when we are rendering the calendar, we can just peek at these values + * without having to break apart every calendar item. + */ + ps = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY); + if (ps != NULL) { + dtstart = icalproperty_get_dtstart(ps); + Cal->event_start = icaltime_as_timet(dtstart); + } + + /* Do the same for the ending date and time. It makes the day view much easier to render. */ + ps = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY); + if (ps != NULL) { + dtend = icalproperty_get_dtend(ps); + Cal->event_end = icaltime_as_timet(dtend); + } + + /* Store it in the hash list. */ + /* syslog(LOG_DEBUG, "INITIAL: %s", ctime(&Cal->event_start)); */ + Put(WCC->disp_cal_items, + (char*) &Cal->event_start, + sizeof(Cal->event_start), + Cal, + delete_task + ); } + + /* * Display task view */ @@ -593,7 +670,7 @@ int tasks_LoadMsgFromServer(SharedMessageStatus *Stat, { /* Not (yet?) needed here? calview *c = (calview *) *ViewSpecific; */ - load_ical_object(Msg->msgnum, is_new, ICAL_VTODO_COMPONENT, display_individual_cal, NULL, 0); + load_ical_object(Msg->msgnum, is_new, ICAL_VTODO_COMPONENT, load_task, NULL, 0); return 0; } @@ -643,7 +720,9 @@ int tasks_GetParamsGetServerCall(SharedMessageStatus *Stat, void **ViewSpecific, long oper, char *cmd, - long len) + long len, + char *filter, + long flen) { strcpy(cmd, "MSGS ALL"); Stat->maxmsgs = 32767; @@ -669,8 +748,10 @@ InitModule_TASKS VIEW_TASKS, tasks_GetParamsGetServerCall, NULL, + NULL, + NULL, tasks_LoadMsgFromServer, tasks_RenderView_or_Tail, tasks_Cleanup); - WebcitAddUrlHandler(HKEY("save_task"), save_task, 0); + WebcitAddUrlHandler(HKEY("save_task"), "", 0, save_task, 0); }