Simplify display_item*()

Pass the generic item container instead of individual fields to
display_item() and display_item_date(). This reduces some code
duplication and cleans up day_write_pad() a bit.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
Lukas Fleischer 2012-06-25 12:29:41 +02:00
parent 80e24954c2
commit 920875d7cb

View File

@ -333,8 +333,7 @@ struct day_items_nb *day_process_storage(struct date *slctd_date,
* Print an item date in the appointment panel. * Print an item date in the appointment panel.
*/ */
static void static void
display_item_date(int incolor, long start, long dur, int state, int type, display_item_date(struct day_item *day, int incolor, long date, int y, int x)
long date, int y, int x)
{ {
WINDOW *win; WINDOW *win;
char a_st[100], a_end[100]; char a_st[100], a_end[100];
@ -342,22 +341,25 @@ display_item_date(int incolor, long start, long dur, int state, int type,
/* FIXME: Redesign apoint_sec2str() and remove the need for a temporary /* FIXME: Redesign apoint_sec2str() and remove the need for a temporary
* appointment item here. */ * appointment item here. */
struct apoint apt_tmp; struct apoint apt_tmp;
apt_tmp.start = start; apt_tmp.start = day->start;
apt_tmp.dur = dur; apt_tmp.dur = day_item_get_duration(day);
win = apad.ptrwin; win = apad.ptrwin;
apoint_sec2str(&apt_tmp, date, a_st, a_end); apoint_sec2str(&apt_tmp, date, a_st, a_end);
if (incolor == 0) if (incolor == 0)
custom_apply_attr(win, ATTR_HIGHEST); custom_apply_attr(win, ATTR_HIGHEST);
if (type == RECUR_EVNT || type == RECUR_APPT)
if (state & APOINT_NOTIFY) if (day->type == RECUR_EVNT || day->type == RECUR_APPT) {
if (day_item_get_state(day) & APOINT_NOTIFY)
mvwprintw(win, y, x, " *!%s -> %s", a_st, a_end); mvwprintw(win, y, x, " *!%s -> %s", a_st, a_end);
else else
mvwprintw(win, y, x, " * %s -> %s", a_st, a_end); mvwprintw(win, y, x, " * %s -> %s", a_st, a_end);
else if (state & APOINT_NOTIFY) } else if (day_item_get_state(day) & APOINT_NOTIFY) {
mvwprintw(win, y, x, " -!%s -> %s", a_st, a_end); mvwprintw(win, y, x, " -!%s -> %s", a_st, a_end);
else } else {
mvwprintw(win, y, x, " - %s -> %s", a_st, a_end); mvwprintw(win, y, x, " - %s -> %s", a_st, a_end);
}
if (incolor == 0) if (incolor == 0)
custom_remove_attr(win, ATTR_HIGHEST); custom_remove_attr(win, ATTR_HIGHEST);
} }
@ -366,8 +368,7 @@ display_item_date(int incolor, long start, long dur, int state, int type,
* Print an item description in the corresponding panel window. * Print an item description in the corresponding panel window.
*/ */
static void static void
display_item(int incolor, char *msg, int recur, int note, int width, int y, display_item(struct day_item *day, int incolor, int width, int y, int x)
int x)
{ {
WINDOW *win; WINDOW *win;
int ch_recur, ch_note; int ch_recur, ch_note;
@ -377,18 +378,20 @@ display_item(int incolor, char *msg, int recur, int note, int width, int y,
if (width <= 0) if (width <= 0)
return; return;
char *mesg = day_item_get_mesg(day);
win = apad.ptrwin; win = apad.ptrwin;
ch_recur = (recur) ? '*' : ' '; ch_recur = (day->type == RECUR_EVNT || day->type == RECUR_APPT) ? '*' : ' ';
ch_note = (note) ? '>' : ' '; ch_note = day_item_get_note(day) ? '>' : ' ';
if (incolor == 0) if (incolor == 0)
custom_apply_attr(win, ATTR_HIGHEST); custom_apply_attr(win, ATTR_HIGHEST);
if (utf8_strwidth(msg) < width) if (utf8_strwidth(mesg) < width)
mvwprintw(win, y, x, " %c%c%s", ch_recur, ch_note, msg); mvwprintw(win, y, x, " %c%c%s", ch_recur, ch_note, mesg);
else { else {
for (i = 0; msg[i] && width > 0; i++) { for (i = 0; mesg[i] && width > 0; i++) {
if (!UTF8_ISCONT(msg[i])) if (!UTF8_ISCONT(mesg[i]))
width -= utf8_width(&msg[i]); width -= utf8_width(&mesg[i]);
buf[i] = msg[i]; buf[i] = mesg[i];
} }
if (i) if (i)
buf[i - 1] = 0; buf[i - 1] = 0;
@ -411,7 +414,7 @@ void day_write_pad(long date, int width, int length, int incolor)
{ {
llist_item_t *i; llist_item_t *i;
struct apoint a; struct apoint a;
int line, item_number, recur; int line, item_number;
const int x_pos = 0; const int x_pos = 0;
unsigned draw_line = 0; unsigned draw_line = 0;
@ -419,23 +422,15 @@ void day_write_pad(long date, int width, int length, int incolor)
LLIST_FOREACH(&day_items, i) { LLIST_FOREACH(&day_items, i) {
struct day_item *day = LLIST_TS_GET_DATA(i); struct day_item *day = LLIST_TS_GET_DATA(i);
char *mesg = day_item_get_mesg(day);
char *note = day_item_get_note(day);
if (day->type == RECUR_EVNT || day->type == RECUR_APPT)
recur = 1;
else
recur = 0;
/* First print the events for current day. */ /* First print the events for current day. */
if (day->type < RECUR_APPT) { if (day->type < RECUR_APPT) {
item_number++; item_number++;
if (item_number - incolor == 0) { if (item_number - incolor == 0) {
day_saved_item.type = day->type; day_saved_item.type = day->type;
day_saved_item.mesg = mesg; day_saved_item.mesg = day_item_get_mesg(day);
} }
display_item(item_number - incolor, mesg, recur, (note != NULL) ? 1 : 0, display_item(day, item_number - incolor, width - 7, line, x_pos);
width - 7, line, x_pos);
line++; line++;
draw_line = 1; draw_line = 1;
} else { } else {
@ -449,14 +444,11 @@ void day_write_pad(long date, int width, int length, int incolor)
item_number++; item_number++;
if (item_number - incolor == 0) { if (item_number - incolor == 0) {
day_saved_item.type = day->type; day_saved_item.type = day->type;
day_saved_item.mesg = mesg; day_saved_item.mesg = day_item_get_mesg(day);
apoint_sec2str(&a, date, day_saved_item.start, day_saved_item.end); apoint_sec2str(&a, date, day_saved_item.start, day_saved_item.end);
} }
display_item_date(item_number - incolor, day->start, display_item_date(day, item_number - incolor, date, line + 1, x_pos);
day_item_get_duration(day), day_item_get_state(day), display_item(day, item_number - incolor, width - 7, line + 2, x_pos);
day->type, date, line + 1, x_pos);
display_item(item_number - incolor, mesg, 0, (note != NULL) ? 1 : 0,
width - 7, line + 2, x_pos);
line += 3; line += 3;
} }
} }