-/*
+ /*
* $Id$
*/
/**
* \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;
+ struct tm starting_tm;
+ struct tm ending_tm;
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. We have to
+ * convert it from a struct tm in order to make it UTC.
+ */
+ memset(&starting_tm, 0, sizeof(struct tm));
+ starting_tm.tm_year = year - 1900;
+ starting_tm.tm_mon = month - 1;
+ starting_tm.tm_mday = day;
+ starting_tm.tm_hour = 0;
+ starting_tm.tm_min = 0;
+ today_start_t = icaltime_from_timet_with_zone(mktime(&starting_tm), 0, icaltimezone_get_utc_timezone());
+ today_start_t.is_utc = 1;
+
+ memset(&ending_tm, 0, sizeof(struct tm));
+ ending_tm.tm_year = year - 1900;
+ ending_tm.tm_mon = month - 1;
+ ending_tm.tm_mday = day;
+ ending_tm.tm_hour = 23;
+ ending_tm.tm_min = 59;
+ today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
+ today_end_t.is_utc = 1;
+
+ /* 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 {
+ 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
+ else
{
- show_event = (thetime == Cal->start_day) || (dst_day == Cal->start_day);
+ 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>");
* \param month the month
* \param day the day
* \param hour the hour we want to start displaying
- * \param inner a flag to display between daystart and dayend
- * (Specify inner to 1 to show inner events)
- * (Specify inner to 0 to show "all day events and events after dayend)
* \param dstart daystart
+ * \param dend dayend
*/
void calendar_day_view_display_events(time_t thetime, int year, int month,
int day, int hour,
- int inner, int dstart) {
+ int dstart, int dend) {
int i;
- icalproperty *p;
+ icalproperty *p = NULL;
+ icalproperty *q = NULL;
time_t event_start;
time_t event_end;
- icalproperty *l;
- icalproperty *n;
+ time_t event_tt;
+ time_t event_tte;
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;
+ struct tm starting_tm;
+ struct tm ending_tm;
- 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(&starting_tm, 0, sizeof(struct tm));
+ starting_tm.tm_year = year - 1900;
+ starting_tm.tm_mon = month - 1;
+ starting_tm.tm_mday = day;
+ starting_tm.tm_hour = hour;
+ starting_tm.tm_min = 0;
+ today_start_t = icaltime_from_timet_with_zone(mktime(&starting_tm), 0, icaltimezone_get_utc_timezone());
+ today_start_t.is_utc = 1;
+
+ memset(&ending_tm, 0, sizeof(struct tm));
+ ending_tm.tm_year = year - 1900;
+ ending_tm.tm_mon = month - 1;
+ ending_tm.tm_mday = day;
+ ending_tm.tm_hour = hour;
+ ending_tm.tm_min = 59;
+ today_end_t = icaltime_from_timet_with_zone(mktime(&ending_tm), 0, icaltimezone_get_utc_timezone());
+/* today_end_t.is_utc = 1;*/
+
+ /* 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 && inner)
- {
- show_event = (thetime == Cal->start_day) &&
- (event_start <= Cal->start_hour) &&
- ((Cal->end_hour != -1)?
- (Cal->end_hour < event_end) : 1);
+ all_day_event = 0;
+ q = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
+ if (q != NULL) {
+ t = icalproperty_get_dtstart(q);
+ event_tt = icaltime_as_timet(t);
+ }
+ 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) && (hour == -1));
}
else
{
- show_event = !inner && (Cal->start_day == thetime);
+ show_event = ical_ctdl_is_overlap(t, end_t, today_start_t, today_end_t);
+ localtime_r(&event_tt, &event_te);
}
+ /* 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) {
+ 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);
+ Cal->cal_msgnum, year, month, day, hour);
escputs((char *) icalproperty_get_comment(p));
wprintf("</a></dd>\n");
}
- else {
+ else
+ {
+ event_tte = icaltime_as_timet(end_t);
+ localtime_r(&event_tte, &event_tm);
+ if (hour == event_te.tm_hour) {
wprintf("<dd class=\"event\" "
"style=\"position: absolute; "
"top:%dpx; left:100px; "
"height:%dpx; \" >",
- (1 + (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)
+ ((dstart * 11) + (event_te.tm_hour - dstart) * (event_te.tm_hour < dstart? 11 : 31)),
+ ((event_tm.tm_hour - event_te.tm_hour) * 30)
);
- }/*
- else {
- wprintf("<dd>");
- }* /
- );
- }
- else {
- wprintf("<dd>");
- }
- wprintf("<a href=\"display_edit_event?"
- "msgnum=%ld&calview=day&year=%d"
- "&month=%d&day=%d&hour=%d\""
- " btt_tooltext=\"",
- WC->disp_cal[i].cal_msgnum,
- year, month, day, hour
- );
- wprintf("<i>%s</i> ", _("Summary:"));
- escputs((char *)icalproperty_get_comment(p));
- wprintf("<br />");
-
- l = icalcomponent_get_first_property(
- WC->disp_cal[i].cal,
- ICAL_LOCATION_PROPERTY);
- if (l) {
- wprintf("<i>%s</i> ", _("Location:"));
- escputs((char *)icalproperty_get_comment(l));
- wprintf("<br />");
- }
- n = icalcomponent_get_first_property(
- WC->disp_cal[i].cal,
- ICAL_DESCRIPTION_PROPERTY);
- if (n) {
- wprintf("<i>%s</i> ", _("Notes:"));
- escputs((char *)icalproperty_get_comment(n));
- wprintf("<br />");
- }
- wprintf("\">");
- escputs((char *)
- icalproperty_get_comment(p));
- wprintf("</a></dd>\n");
-
- }
+ wprintf("<a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d&case=%d\">",
+ Cal->cal_msgnum, year, month, day, t.hour, hour);
+ escputs((char *) icalproperty_get_comment(p));
+ wprintf("</a></dd>\n");
}
+
}
-
- }
-
- /* TODO: whats that? thierry, when do we need to show this?
- wprintf("<a href=\"display_edit_event?msgnum=%ld&calview=day&year=%d&month=%d&day=%d&hour=%d\">",
- WC->disp_cal[i].cal_msgnum,
- year, month, day, hour
- );
- escputs((char *)
- icalproperty_get_comment(p));
- wprintf("</a></dd>\n");
- */
}
}
}
-
-
/**
* \brief view one day
* \param year the year
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;
wprintf("<table class=\"calendar\" id=\"inner_day\"><tr> \n");
/** Innermost cell (contains hours etc.) */
- wprintf("<td class=\"middle_of_the_day\" >");
- wprintf("<dl "
- "style=\" "
- " padding:0 ; "
- " margin: 0; "
- " position: absolute ; "
- " top: 0; "
- " left: 0; "
- " width: 500px; "
- " clip: rect(0px 500px %dpx 0px);"
- " clip: rect(0px, 500px, %dpx, 0px);"
- "\">",
- (dayend - daystart) * 30,
- (dayend - daystart) * 30
- );
+ wprintf("<td class=\"events_of_the_day\" >");
+ wprintf("<dl class=\"events\" >");
/** Now the middle of the day... */
- for (hour = 0; hour <= dayend; ++hour) { /* could do HEIGHT=xx */
- if (hour >= daystart) {
- wprintf("<dt><a href=\"display_edit_event?msgnum=0"
- "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
- year, month, day, hour
- );
+ for (hour = 0; hour < 24; ++hour) { /* could do HEIGHT=xx */
+ wprintf("<dt class=\"hour%s\"><a href=\"display_edit_event?msgnum=0"
+ "&year=%d&month=%d&day=%d&hour=%d&minute=0\">",
+ (hour < daystart ? "before" : (hour > dayend ? "after" : "")),
+ year, month, day, hour
+ );
- if (time_format == WC_TIMEFORMAT_24) {
- wprintf("%2d:00</a> ", hour);
- }
- else {
- wprintf("%d:00%s</a> ",
- (hour <= 12 ? hour : hour-12),
- (hour < 12 ? "am" : "pm")
- );
- }
+ if (time_format == WC_TIMEFORMAT_24) {
+ wprintf("%2d:00</a> ", hour);
+ }
+ else {
+ wprintf("%d:00%s</a> ",
+ (hour <= 12 ? hour : hour-12),
+ (hour < 12 ? "am" : "pm")
+ );
+ }
wprintf("</dt>");
- }
+
/* put the data here, stupid */
- calendar_day_view_display_events(today_t, year, month, day, hour, 1 , daystart);
+ calendar_day_view_display_events(today_t, year, month, day, hour, daystart, dayend);
}
/** Display all-day events) */
wprintf("<dt>All day events</dt>");
- calendar_day_view_display_events(today_t, year, month, day, -1, 0 , daystart);
-
- /** Display events before daystart */
- wprintf("<dt>Before day start</dt>");
- for (hour = 0; hour <= (daystart-1); ++hour) {
- calendar_day_view_display_events(today_t, year, month, day, hour, 0, daystart );
- }
-
- /** Display events after dayend... */
- wprintf("<dt>After</dt>");
- for (hour = (dayend+1); hour <= 23; ++hour) {
- calendar_day_view_display_events(today_t, year, month, day, hour, 0, daystart );
- }
+ calendar_day_view_display_events(today_t, year, month, day, -1, daystart, dayend);
wprintf("</dl>");
" setTimeout(\"btt_enableTooltips('inner_day')\", 1); "
"</script>\n"
);
+}
-}
/**
* \brief Display today's events.
*/