Reintroduce heading and separator in appointments

This re-introduces the heading (showing the POM and the current date) as
well as the separating line between events and appointments.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
Lukas Fleischer 2014-05-18 10:19:30 +02:00
parent 2a15531bb9
commit 2a62351d25
4 changed files with 52 additions and 32 deletions

View File

@ -307,7 +307,7 @@ app_arg(int add_line, struct date *day, long date, const char *fmt_apt,
if (date == 0)
date = get_sec_date(*day);
day_store_items(date, regex);
day_store_items(date, regex, 0);
int n = day_item_count();

View File

@ -554,12 +554,13 @@ struct nbar {
};
/* Available types of items. */
enum item_type {
RECUR_EVNT = 1,
enum day_item_type {
DAY_HEADING = 1,
RECUR_EVNT,
EVNT,
DAY_SEPARATOR,
RECUR_APPT,
APPT,
MAX_TYPES = APPT
APPT
};
/* Return codes for the getstring() function. */
@ -700,7 +701,7 @@ long day_item_get_duration(struct day_item *);
int day_item_get_state(struct day_item *);
void day_item_add_exc(struct day_item *, long);
void day_item_fork(struct day_item *, struct day_item *);
void day_store_items(long, regex_t *);
void day_store_items(long, regex_t *, int);
void day_process_storage(struct date *, unsigned);
void day_display_item_date(struct day_item *, WINDOW *, int, long, int, int);
void day_display_item(struct day_item *, WINDOW *, int, int, int, int);

View File

@ -70,17 +70,12 @@ static int day_cmp_start(struct day_item **pa, struct day_item **pb)
struct day_item *a = *pa;
struct day_item *b = *pb;
if (a->type <= EVNT) {
if (b->type <= EVNT)
return 0;
else
return -1;
} else if (b->type <= EVNT) {
return 1;
} else {
return a->start < b->start ? -1 : (a->start ==
b->start ? 0 : 1);
if ((a->type == APPT || a->type == RECUR_APPT) &&
(b->type == APPT || b->type == RECUR_APPT)) {
return a->start - b->start;
}
return a->type - b->type;
}
/* Add an item to the current day list. */
@ -338,15 +333,24 @@ static int day_store_recur_apoints(long date, regex_t * regex)
* The number of events and appointments in the current day are also updated.
*/
void
day_store_items(long date, regex_t * regex)
day_store_items(long date, regex_t * regex, int include_captions)
{
unsigned apts, events;
union aptev_ptr p = { NULL };
day_free_vector();
day_init_vector();
day_store_recur_events(date, regex);
day_store_events(date, regex);
day_store_recur_apoints(date, regex);
day_store_apoints(date, regex);
if (include_captions)
day_add_item(DAY_HEADING, 0, p);
events = day_store_recur_events(date, regex);
events += day_store_events(date, regex);
apts = day_store_recur_apoints(date, regex);
apts += day_store_apoints(date, regex);
if (include_captions && events > 0 && apts > 0)
day_add_item(DAY_SEPARATOR, 0, p);
VECTOR_SORT(&day_items, day_cmp_start);
}
@ -373,7 +377,7 @@ void day_process_storage(struct date *slctd_date, unsigned day_changed)
delwin(apad.ptrwin);
/* Store the events and appointments (recursive and normal items). */
day_store_items(date, NULL);
day_store_items(date, NULL, 1);
}
/*

View File

@ -834,28 +834,43 @@ void ui_day_draw(int n, WINDOW *win, int y, int hilt, void *cb_data)
struct day_item *item = day_get_item(n);
int width = lb_apt.sw.w;
if (item->type < RECUR_APPT) {
if (item->type == EVNT || item->type == RECUR_EVNT) {
day_display_item(item, win, !hilt, width, y, 1);
} else {
day_display_item_date(item, win, !hilt, date, y + 1, 1);
day_display_item(item, win, !hilt, width, y + 2, 1);
} else if (item->type == APPT || item->type == RECUR_APPT) {
day_display_item_date(item, win, !hilt, date, y, 1);
day_display_item(item, win, !hilt, width, y + 1, 1);
} else if (item->type == DAY_HEADING) {
unsigned x = width - (strlen(_(monthnames[slctd_date.mm - 1])) + 17);
custom_apply_attr(win, ATTR_HIGHEST);
mvwprintw(win, y, x, "%s %s %02d, %04d",
ui_calendar_get_pom(date),
_(monthnames[slctd_date.mm - 1]), slctd_date.dd,
slctd_date.yyyy);
custom_remove_attr(win, ATTR_HIGHEST);
} else if (item->type == DAY_SEPARATOR) {
wmove(win, y, 0);
whline(win, 0, width);
}
}
enum listbox_row_type ui_day_row_type(int i, void *cb_data)
enum listbox_row_type ui_day_row_type(int n, void *cb_data)
{
return LISTBOX_ROW_TEXT;
struct day_item *item = day_get_item(n);
if (item->type == DAY_HEADING || item->type == DAY_SEPARATOR)
return LISTBOX_ROW_CAPTION;
else
return LISTBOX_ROW_TEXT;
}
int ui_day_height(int n, void *cb_data)
{
struct day_item *item = day_get_item(n);
if (item->type < RECUR_APPT)
return 1;
else
if (item->type == APPT || item->type == RECUR_APPT)
return 3;
else
return 1;
}
/* Updates the Appointment panel */