* \param cal Our calendar to process
* \param msgnum number of the mesage in our db
*/
-void display_individual_cal(icalcomponent *cal, long msgnum)
+void display_individual_cal(icalcomponent *cal, long msgnum)
{
- icalproperty *ps = NULL;
- struct icaltimetype t;
- struct wcsession *WCC;
- struct disp_cal *Cal;
- struct tm event;
- struct tm event_hr;
- time_t event_ts;
-
- WCC = WC;
+ struct wcsession *WCC = WC; /* stack this for faster access (WC is a function) */
WCC->num_cal += 1;
-
- WCC->disp_cal = realloc(WCC->disp_cal,
- (sizeof(struct disp_cal) * WCC->num_cal) );
-
- Cal = &WCC->disp_cal[WCC->num_cal - 1];
- Cal->cal = icalcomponent_new_clone(cal);
-
- Cal->cal_msgnum = msgnum;
-
- //! Precalculate some Values we can use for easy comparison later.
- ps = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
- if (ps != NULL) {
- t = icalproperty_get_dtstart(ps);
- event_ts = icaltime_as_timet(t);
-
- if (t.is_date) { //! calculate whether we are a day event.
- Cal->start_hour = -1;
- Cal->end_hour = -1;
- Cal->end_day = -1;
- localtime_r(&event_ts, &event);
- event.tm_sec = 0;
- event.tm_min = 0;
- event.tm_hour = 0;
- Cal->start_day = mktime (&event);
- }
- else { //! Precalc start day and start day + hour
- localtime_r(&event_ts, &event);
- event.tm_sec = 0;
- event.tm_min = 0;
- memcpy (&event_hr, &event, sizeof(struct tm));
- Cal->start_hour = mktime (&event_hr);
- event.tm_hour = 0;
- Cal->start_day = mktime (&event);
-
- ps = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
- if (ps != NULL) { //! Precalc the end day and end day + hour
- t = icalproperty_get_dtstart(ps);
- event_ts = icaltime_as_timet(t);
- localtime_r(&event_ts, &event);
- event.tm_sec = 0;
- event.tm_min = 0;
- memcpy (&event_hr, &event, sizeof(struct tm));
- Cal->end_hour = mktime (&event);
- event.tm_hour = 0;
- Cal->end_day = mktime (&event);
- }
- else
- {
- Cal->end_hour = -1;
- Cal->end_day = -1;
- }
- }
-
-
- }
- Cal->multi_day_event = Cal->start_day != Cal->end_day;
+ WCC->disp_cal = realloc(WC->disp_cal, (sizeof(struct disp_cal) * WCC->num_cal) );
+ WCC->disp_cal[WCC->num_cal - 1].cal = icalcomponent_new_clone(cal);
+ ical_dezonify(WCC->disp_cal[WCC->num_cal - 1].cal);
+ WCC->disp_cal[WCC->num_cal - 1].cal_msgnum = msgnum;
}
* \brief Display one day of a whole month view of a calendar
* \param thetime the month we want to see
*/
-void calendar_month_view_display_events(time_t thetime) {
+void calendar_month_view_display_events(int year, int month, int day)
+{
int i;
- struct tm today_tm;
icalproperty *p = NULL;
icalproperty *q = NULL;
struct icaltimetype t;
- int month, day, year;
+ struct icaltimetype end_t;
+ struct icaltimetype today_start_t;
+ struct icaltimetype today_end_t;
int all_day_event = 0;
- int multi_day_event = 0;
- int fill_day_event = 0;
int show_event = 0;
- time_t tt;
- time_t dst_day;
char buf[256];
- struct wcsession *WCC;
+ struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
struct disp_cal *Cal;
-
- WCC = WC;
+ time_t tt;
if (WCC->num_cal == 0) {
wprintf("<br /><br /><br />\n");
return;
}
- localtime_r(&thetime, &today_tm);
- month = today_tm.tm_mon + 1;
- day = today_tm.tm_mday;
- year = today_tm.tm_year + 1900;
- dst_day = thetime - 3600;
+ /* Create an imaginary event which spans the 24 hours of today. Any events which
+ * overlap with this one take place at least partially in this day.
+ */
+ memset(&today_start_t, 0, sizeof today_start_t);
+ today_start_t.year = year;
+ today_start_t.month = month;
+ today_start_t.day = day;
+ today_start_t.hour = 0;
+ today_start_t.minute = 0;
+ memset(&today_end_t, 0, sizeof today_end_t);
+ today_end_t.year = year;
+ today_end_t.month = month;
+ today_end_t.day = day;
+ today_end_t.hour = 23;
+ today_end_t.minute = 59;
+
+ /* Now loop through our list of events to see which ones occur today.
+ */
for (i=0; i<(WCC->num_cal); ++i) {
- fill_day_event = 0;
- multi_day_event = 0;
-
Cal = &WCC->disp_cal[i];
- all_day_event = Cal->start_hour == -1;
-// lprintf(1,"Date: %d %d %d %d\n", thetime, Cal->start_day, day, thetime - Cal->start_day);
- if (!all_day_event) {
-
- // are we in the range of the event?
- show_event = (Cal->start_day <= thetime) &&
- (Cal->end_day >= thetime);
- if (!show_event)
- // are we in the range of the event?
- show_event = (Cal->start_day <= dst_day) &&
- (Cal->end_day >= dst_day);
-
- // are we not start or end day?
- fill_day_event = (Cal->start_day < thetime) &&
- (Cal->end_day > thetime);
+ all_day_event = 0;
+ q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
+ if (q != NULL) {
+ t = icalproperty_get_dtstart(q);
}
- else
+ else {
+ memset(&t, 0, sizeof t);
+ }
+ q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
+ if (q != NULL) {
+ end_t = icalproperty_get_dtend(q);
+ }
+ else {
+ memset(&end_t, 0, sizeof end_t);
+ }
+ if (t.is_date) all_day_event = 1;
+
+ if (all_day_event)
{
- show_event = (thetime == Cal->start_day) || (dst_day == Cal->start_day);
+ show_event = ((t.year == year) && (t.month == month) && (t.day == day));
}
+ else
+ {
+ show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
+ }
+
+ /* If we determined that this event occurs today, then display it.
+ */
if (show_event) {
- p = icalcomponent_get_first_property(
- Cal->cal,
- ICAL_SUMMARY_PROPERTY);
+ p = icalcomponent_get_first_property(Cal->cal, ICAL_SUMMARY_PROPERTY);
if (p != NULL) {
if (all_day_event) {
*/
if (icalcomponent_isa(Cal->cal) == ICAL_VEVENT_COMPONENT) {
- q = icalcomponent_get_first_property(Cal->cal,
- ICAL_DTSTART_PROPERTY);
+ q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
if (q != NULL) {
t = icalproperty_get_dtstart(q);
/* Embed the 'show end date/time' loop inside here so it
* only executes if this is NOT an all day event.
*/
- q = icalcomponent_get_first_property(Cal->cal,
- ICAL_DTEND_PROPERTY);
+ q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
if (q != NULL) {
t = icalproperty_get_dtend(q);
tt = icaltime_as_timet(t);
fmt_date(buf, tt, 1);
- wprintf("<i>%s</i> %s<br>",
- _("Ending date/time:"), buf);
+ wprintf("<i>%s</i> %s<br>", _("Ending date/time:"), buf);
}
}
}
- q = icalcomponent_get_first_property(
- Cal->cal,
- ICAL_DESCRIPTION_PROPERTY);
+ q = icalcomponent_get_first_property(Cal->cal, ICAL_DESCRIPTION_PROPERTY);
if (q) {
wprintf("<i>%s</i> ", _("Notes:"));
escputs((char *)icalproperty_get_comment(q));
tm.tm_mday);
/** put the data here, stupid */
- calendar_month_view_display_events(thetime);
+ calendar_month_view_display_events(
+ tm.tm_year + 1900,
+ tm.tm_mon + 1,
+ tm.tm_mday
+ );
wprintf("</td>");
int day, int hour,
int dstart, int dend) {
int i;
- icalproperty *p;
+ icalproperty *p = NULL;
+ icalproperty *q = NULL;
time_t event_start;
time_t event_end;
struct tm event_te;
struct tm event_tm;
int show_event = 0;
int all_day_event = 0;
- struct wcsession *WCC;
+ struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
struct disp_cal *Cal;
+ struct icaltimetype t;
+ struct icaltimetype end_t;
+ struct icaltimetype today_start_t;
+ struct icaltimetype today_end_t;
- WCC = WC;
if (WCC->num_cal == 0) {
// \todo FIXME wprintf("<br /><br /><br />\n");
event_start = thetime + 60 * 60 * hour;
event_end = thetime + 60 * 60 * (hour + 1);
+
+ /* Create an imaginary event which spans the 24 hours of today. Any events which
+ * overlap with this one take place at least partially in this day.
+ */
+ memset(&today_start_t, 0, sizeof today_start_t);
+ today_start_t.year = year;
+ today_start_t.month = month;
+ today_start_t.day = day;
+ today_start_t.hour = 0;
+ today_start_t.minute = 0;
+ memset(&today_end_t, 0, sizeof today_end_t);
+ today_end_t.year = year;
+ today_end_t.month = month;
+ today_end_t.day = day;
+ today_end_t.hour = 23;
+ today_end_t.minute = 59;
+
+
+ /* Now loop through our list of events to see which ones occur today.
+ */
for (i=0; i<(WCC->num_cal); ++i) {
Cal = &WCC->disp_cal[i];
- all_day_event = Cal->start_hour == -1;
- show_event = 0;
- if (! all_day_event )
- {
- show_event = (Cal->start_day == thetime) &&
- (Cal->start_hour >= event_start) &&
- (Cal->start_hour < (event_start + 1));
+ all_day_event = 0;
+ q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
+ if (q != NULL) {
+ t = icalproperty_get_dtstart(q);
+ }
+ else {
+ memset(&t, 0, sizeof t);
+ }
+ q = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
+ if (q != NULL) {
+ end_t = icalproperty_get_dtend(q);
+ }
+ else {
+ memset(&end_t, 0, sizeof end_t);
+ }
+ if (t.is_date) all_day_event = 1;
+ if (all_day_event)
+ {
+ show_event = ((t.year == year) && (t.month == month) && (t.day == day));
}
else
{
- show_event = (Cal->start_day == thetime);
+ show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
}
+ /* If we determined that this event occurs today, then display it.
+ */
p = icalcomponent_get_first_property(Cal->cal,ICAL_SUMMARY_PROPERTY);
if ((show_event) && (p != NULL)) {
- if (all_day_event && (hour == -1)) {
- wprintf("<dd><a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d\">",
- Cal->cal_msgnum, year, month, day, hour);
- escputs((char *) icalproperty_get_comment(p));
- wprintf("</a></dd>\n");
- }
- if (!all_day_event) {
- wprintf("<dd class=\"event\" "
- "style=\"position: absolute; "
- "top:%dpx; left:100px; "
- "height:%dpx; \" >",
- (100 + (event_tm.tm_min / 2) + (event_te.tm_hour - hour) + (hour * 30) - (dstart * 30)),
- (((event_te.tm_min - event_tm.tm_min) / 2) +(event_te.tm_hour - hour) * 30)
- );
- wprintf("<a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d\">",
- Cal->cal_msgnum, year, month, day, hour);
- escputs((char *) icalproperty_get_comment(p));
- wprintf("</a></dd>\n");
+ if (all_day_event)
+ {
+ wprintf("<dd><a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d\">",
+ Cal->cal_msgnum, year, month, day, hour);
+ escputs((char *) icalproperty_get_comment(p));
+ wprintf("</a></dd>\n");
+ }
+ else
+ {
+ wprintf("<dd class=\"event\" "
+ "style=\"position: absolute; "
+ "top:%dpx; left:100px; "
+ "height:%dpx; \" >",
+ (100 + (event_tm.tm_min / 2) + (event_te.tm_hour - hour) + (hour * 30) - (dstart * 30)),
+ (((event_te.tm_min - event_tm.tm_min) / 2) +(event_te.tm_hour - hour) * 30)
+ );
+ wprintf("<a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d\">",
+ Cal->cal_msgnum, year, month, day, hour);
+ escputs((char *) icalproperty_get_comment(p));
+ wprintf("</a></dd>\n");
}
}
}
char d_str[128];
int time_format;
time_t today_t;
-
+
time_format = get_time_format_cached ();
get_preference("daystart", daystart_str, sizeof daystart_str);
if (!IsEmptyStr(daystart_str)) daystart = atoi(daystart_str);
/** Today's date */
memset(&d_tm, 0, sizeof d_tm);
- if (WC->num_cal > 0)
- localtime_r(&WC->disp_cal[0].start_day, &d_tm);
-
d_tm.tm_year = year - 1900;
d_tm.tm_mon = month - 1;
d_tm.tm_mday = day;
" setTimeout(\"btt_enableTooltips('inner_day')\", 1); "
"</script>\n"
);
+}
-}
/**
* \brief Display today's events.
*/