From 3e14f31738c6a9ede5f026b6de43bcd21197a06d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Sat, 7 Mar 2009 17:24:58 +0000 Subject: [PATCH] * add Michael Meskes patch: make time in task due dates optional * make time format a define: FULL/BRIEF/RAWDATE --- webcit/calendar.c | 33 +++++++++++++++++---- webcit/calendar_tools.c | 4 +-- webcit/calendar_view.c | 31 +++++++++++--------- webcit/fmt_date.c | 64 ++++++++++++++++++++++++----------------- webcit/msg_renderers.c | 4 +-- webcit/static/wclib.js | 26 +++++++++++++++++ webcit/webcit.h | 6 +++- 7 files changed, 118 insertions(+), 50 deletions(-) diff --git a/webcit/calendar.c b/webcit/calendar.c index 43d7a710d..720876021 100644 --- a/webcit/calendar.c +++ b/webcit/calendar.c @@ -125,7 +125,7 @@ void cal_process_object(StrBuf *Target, } else { tt = icaltime_as_timet(t); - webcit_fmt_date(buf, tt, 0); + webcit_fmt_date(buf, tt, DATEFMT_FULL); StrBufAppendPrintf(Target, "
"); StrBufAppendPrintf(Target, _("Starting date/time:")); StrBufAppendPrintf(Target, "
%s
", buf); @@ -136,7 +136,7 @@ void cal_process_object(StrBuf *Target, if (p != NULL) { t = icalproperty_get_dtend(p); tt = icaltime_as_timet(t); - webcit_fmt_date(buf, tt, 0); + webcit_fmt_date(buf, tt, DATEFMT_FULL); StrBufAppendPrintf(Target, "
"); StrBufAppendPrintf(Target, _("Ending date/time:")); StrBufAppendPrintf(Target, "
%s
", buf); @@ -683,6 +683,13 @@ 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", 0); + + wprintf(""); + wprintf(_("Time associated")); wprintf("\n"); wprintf(""); @@ -704,7 +711,13 @@ 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", 0); - + + wprintf(""); + wprintf(_("Time associated")); wprintf("\n"); todoStatus = icalcomponent_get_status(vtodo); wprintf("\n"); @@ -837,7 +850,12 @@ void save_individual_task(icalcomponent *supplied_vtodo, long msgnum, char* from icalproperty_free(prop); } if (IsEmptyStr(bstr("nodtstart"))) { - icaltime_from_webform(&t, "dtstart"); + if (yesbstr("dtstart_time")) { + icaltime_from_webform(&t, "dtstart"); + } + else { + icaltime_from_webform_dateonly(&t, "dtstart"); + } icalcomponent_add_property(vtodo, icalproperty_new_dtstart(t) ); @@ -880,7 +898,12 @@ void save_individual_task(icalcomponent *supplied_vtodo, long msgnum, char* from icalproperty_free(prop); } if (IsEmptyStr(bstr("nodue"))) { - icaltime_from_webform(&t, "due"); + if (yesbstr("due_time")) { + icaltime_from_webform(&t, "due"); + } + else { + icaltime_from_webform_dateonly(&t, "due"); + } icalcomponent_add_property(vtodo, icalproperty_new_due(t) ); diff --git a/webcit/calendar_tools.c b/webcit/calendar_tools.c index b595d74a5..6cad617ff 100644 --- a/webcit/calendar_tools.c +++ b/webcit/calendar_tools.c @@ -81,7 +81,7 @@ void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix, int d } wprintf(_("Hour: ")); - wprintf("\n", prefix, prefix); for (i=0; i<=23; ++i) { if (time_format == WC_TIMEFORMAT_24) { @@ -101,7 +101,7 @@ void display_icaltimetype_as_webform(struct icaltimetype *t, char *prefix, int d wprintf("\n"); wprintf(_("Minute: ")); - wprintf("\n", prefix, prefix); for (i=0; i<=59; ++i) { if ( (i % 5 == 0) || (tm.tm_min == i) ) { wprintf("\n", diff --git a/webcit/calendar_view.c b/webcit/calendar_view.c index 4d0d0c831..8ff0a4dbc 100644 --- a/webcit/calendar_view.c +++ b/webcit/calendar_view.c @@ -290,7 +290,7 @@ void calendar_month_view_display_events(int year, int month, int day) } else { tt = icaltime_as_timet(t); - webcit_fmt_date(buf, tt, 1); + webcit_fmt_date(buf, tt, DATEFMT_BRIEF); wprintf("%s %s
", _("Starting date/time:"), buf); @@ -302,7 +302,7 @@ void calendar_month_view_display_events(int year, int month, int day) if (q != NULL) { t = icalproperty_get_dtend(q); tt = icaltime_as_timet(t); - webcit_fmt_date(buf, tt, 1); + webcit_fmt_date(buf, tt, DATEFMT_BRIEF); wprintf("%s %s
", _("Ending date/time:"), buf); } @@ -913,9 +913,9 @@ void calendar_day_view_display_events(time_t thetime, escputs((char *)icalproperty_get_comment(q)); wprintf("
"); } - webcit_fmt_date(buf, event_tt, 1); + webcit_fmt_date(buf, event_tt, DATEFMT_BRIEF); wprintf("%s %s
", _("Starting date/time:"), buf); - webcit_fmt_date(buf, event_tte, 1); + webcit_fmt_date(buf, event_tte, DATEFMT_BRIEF); wprintf("%s %s
", _("Ending date/time:"), buf); q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY); if (q) { @@ -992,9 +992,9 @@ void calendar_day_view_display_events(time_t thetime, escputs((char *)icalproperty_get_comment(q)); wprintf("
"); } - webcit_fmt_date(buf, event_tt, 1); + webcit_fmt_date(buf, event_tt, DATEFMT_BRIEF); wprintf("%s %s
", _("Starting date/time:"), buf); - webcit_fmt_date(buf, event_tte, 1); + webcit_fmt_date(buf, event_tte, DATEFMT_BRIEF); wprintf("%s %s
", _("Ending date/time:"), buf); q = icalcomponent_get_first_property(Cal->cal,ICAL_DESCRIPTION_PROPERTY); if (q) { @@ -1435,7 +1435,7 @@ void render_calendar_view(struct calview *c) /* * Helper function for do_tasks_view(). Returns the due date/time of a vtodo. */ -time_t get_task_due_date(icalcomponent *vtodo) { +time_t get_task_due_date(icalcomponent *vtodo, int *is_date) { icalproperty *p; if (vtodo == NULL) { @@ -1451,13 +1451,17 @@ time_t get_task_due_date(icalcomponent *vtodo) { return get_task_due_date( icalcomponent_get_first_component( vtodo, ICAL_VTODO_COMPONENT - ) + ), is_date ); } p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY); if (p != NULL) { - return(icaltime_as_timet(icalproperty_get_due(p))); + struct icaltimetype t = icalproperty_get_due(p); + + if (is_date) + *is_date = t.is_date; + return(icaltime_as_timet(t)); } else { return(0L); @@ -1475,8 +1479,8 @@ int task_due_cmp(const void *vtask1, const void *vtask2) { time_t t1; time_t t2; - t1 = get_task_due_date(Task1->cal); - t2 = get_task_due_date(Task2->cal); + t1 = get_task_due_date(Task1->cal, NULL); + t2 = get_task_due_date(Task2->cal, NULL); if (t1 < t2) return(-1); if (t1 > t2) return(1); return(0); @@ -1545,6 +1549,7 @@ void do_tasks_view(void) { Pos = GetNewHashPos(WCC->disp_cal_items, 0); while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) { icalproperty_status todoStatus; + int is_date; Cal = (disp_cal*)vCal; wprintf(""); @@ -1567,10 +1572,10 @@ void do_tasks_view(void) { wprintf("\n"); wprintf("\n"); - due = get_task_due_date(Cal->cal); + due = get_task_due_date(Cal->cal, &is_date); wprintf(" 0) { - webcit_fmt_date(buf, due, 0); + webcit_fmt_date(buf, due, is_date ? DATEFMT_RAWDATE : DATEFMT_FULL); wprintf(">%s",buf); } else { diff --git a/webcit/fmt_date.c b/webcit/fmt_date.c index 2b6ec2036..04cb391f5 100644 --- a/webcit/fmt_date.c +++ b/webcit/fmt_date.c @@ -47,7 +47,7 @@ size_t wc_strftime(char *s, size_t max, const char *format, const struct tm *tm) /* * Format a date/time stamp for output */ -void webcit_fmt_date(char *buf, time_t thetime, int brief) +void webcit_fmt_date(char *buf, time_t thetime, int Format) { struct tm tm; struct tm today_tm; @@ -60,34 +60,44 @@ void webcit_fmt_date(char *buf, time_t thetime, int brief) localtime_r(&thetime, &tm); - if (brief) { + /* + * DATEFMT_FULL: full display + * DATEFMT_BRIEF: if date == today, show only the time + * otherwise, for messages up to 6 months old, + * show the month and day, and the time + * older than 6 months, show only the date + * DATEFMT_RAWDATE: show full date, regardless of age + */ - /* If date == today, show only the time */ - if ((tm.tm_year == today_tm.tm_year) - &&(tm.tm_mon == today_tm.tm_mon) - &&(tm.tm_mday == today_tm.tm_mday)) { - if (time_format == WC_TIMEFORMAT_24) - wc_strftime(buf, 32, "%k:%M", &tm); - else - wc_strftime(buf, 32, "%l:%M%p", &tm); - } - /* Otherwise, for messages up to 6 months old, show the month and day, and the time */ - else if (today_timet - thetime < 15552000) { - if (time_format == WC_TIMEFORMAT_24) - wc_strftime(buf, 32, "%b %d %k:%M", &tm); + switch (Format) { + case DATEFMT_BRIEF: + if ((tm.tm_year == today_tm.tm_year) + &&(tm.tm_mon == today_tm.tm_mon) + &&(tm.tm_mday == today_tm.tm_mday)) { + if (time_format == WC_TIMEFORMAT_24) + wc_strftime(buf, 32, "%k:%M", &tm); + else + wc_strftime(buf, 32, "%l:%M%p", &tm); + } + else if (today_timet - thetime < 15552000) { + if (time_format == WC_TIMEFORMAT_24) + wc_strftime(buf, 32, "%b %d %k:%M", &tm); + else + wc_strftime(buf, 32, "%b %d %l:%M%p", &tm); + } + else { + wc_strftime(buf, 32, "%b %d %Y", &tm); + } + break; + case DATEFMT_FULL: + if (time_format == WC_TIMEFORMAT_24) + wc_strftime(buf, 32, "%a %b %d %Y %T %Z", &tm); else - wc_strftime(buf, 32, "%b %d %l:%M%p", &tm); - } - /* older than 6 months, show only the date */ - else { - wc_strftime(buf, 32, "%b %d %Y", &tm); - } - } - else { - if (time_format == WC_TIMEFORMAT_24) - wc_strftime(buf, 32, "%a %b %d %Y %T %Z", &tm); - else - wc_strftime(buf, 32, "%a %b %d %Y %r %Z", &tm); + wc_strftime(buf, 32, "%a %b %d %Y %r %Z", &tm); + break; + case DATEFMT_RAWDATE: + wc_strftime(buf, 32, "%a %b %d %Y", &tm); + break; } } diff --git a/webcit/msg_renderers.c b/webcit/msg_renderers.c index ed20d2eb2..e944548b0 100644 --- a/webcit/msg_renderers.c +++ b/webcit/msg_renderers.c @@ -441,7 +441,7 @@ void tmplput_MAIL_SUMM_DATE_BRIEF(StrBuf *Target, WCTemplputParams *TP) { char datebuf[64]; message_summary *Msg = (message_summary*) CTX; - webcit_fmt_date(datebuf, Msg->date, 1); + webcit_fmt_date(datebuf, Msg->date, DATEFMT_BRIEF); StrBufAppendBufPlain(Target, datebuf, -1, 0); } @@ -449,7 +449,7 @@ void tmplput_MAIL_SUMM_DATE_FULL(StrBuf *Target, WCTemplputParams *TP) { char datebuf[64]; message_summary *Msg = (message_summary*) CTX; - webcit_fmt_date(datebuf, Msg->date, 0); + webcit_fmt_date(datebuf, Msg->date, DATEFMT_FULL); StrBufAppendBufPlain(Target, datebuf, -1, 0); } void tmplput_MAIL_SUMM_DATE_NO(StrBuf *Target, WCTemplputParams *TP) diff --git a/webcit/static/wclib.js b/webcit/static/wclib.js index be0728432..622e92005 100644 --- a/webcit/static/wclib.js +++ b/webcit/static/wclib.js @@ -647,12 +647,24 @@ function HandleRSVP(question_divname, title_divname, msgnum, cal_partnum, sc) { // TODO: Collapse into one function function toggleTaskDtStart(event) { var checkBox = $('nodtstart'); + var checkBoxTime = $('dtstart_time'); dtStart = document.getElementById("dtstart"); + dtStartHour = document.getElementById("dtstart_hour"); + dtStartMinute = document.getElementById("dtstart_minute"); if (checkBox.checked) { dtStart.disabled = true; + dtStartHour.disabled = true; + dtStartMinute.disabled = true; dtStart.style.textDecoration = "line-through"; } else { dtStart.disabled = false; + if (checkBoxTime.checked) { + dtStartHour.disabled = false; + dtStartMinute.disabled = false; + } else { + dtStartHour.disabled = true; + dtStartMinute.disabled = true; + } dtStart.style.textDecoration = ""; if (dtStart.value.length == 0) dtStart.dpck._initCurrentDate(); @@ -660,12 +672,24 @@ function toggleTaskDtStart(event) { } function toggleTaskDue(event) { var checkBox = $('nodue'); + var checkBoxTime = $('due_time'); dueField = document.getElementById("due"); + dueFieldHour = document.getElementById("due_hour"); + dueFieldMinute = document.getElementById("due_minute"); if (checkBox.checked) { dueField.disabled = true; + dueFieldHour.disabled = true; + dueFieldMinute.disabled = true; dueField.style.textDecoration = "line-through"; } else { dueField.disabled = false; + if (checkBoxTime.checked) { + dueFieldHour.disabled = false; + dueFieldMinute.disabled = false; + } else { + dueFieldHour.disabled = true; + dueFieldMinute.disabled = true; + } dueField.style.textDecoration = ""; if (dueField.value.length == 0) dueField.dpck._initCurrentDate(); @@ -677,7 +701,9 @@ function ToggleTaskDateOrNoDateActivate(event) { toggleTaskDtStart(null); toggleTaskDue(null); $('nodtstart').observe('click', toggleTaskDtStart); + $('dtstart_time').observe('click', toggleTaskDtStart); $('nodue').observe('click', toggleTaskDue); + $('due_time').observe('click', toggleTaskDue); } } function TaskViewGatherCategoriesFromTable() { diff --git a/webcit/webcit.h b/webcit/webcit.h index 74083d41c..e2c7aef9e 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -721,7 +721,11 @@ long guess_calhourformat(void); int get_time_format_cached (void); int xtoi(const char *in, size_t len); const char *get_selected_language(void); -void webcit_fmt_date(char *buf, time_t thetime, int brief); + +#define DATEFMT_FULL 0 +#define DATEFMT_BRIEF 1 +#define DATEFMT_RAWDATE 2 +void webcit_fmt_date(char *buf, time_t thetime, int Format); int fetch_http(char *url, char *target_buf, int maxbytes); void free_attachments(wcsession *sess); void summary(void); -- 2.30.2