Simplify day storage

The function day_process_storage() is a wrapper for day_store_items().
It has an unused second argument, and is only used twice to load the
selected day. It has been removed.

A new function, get_slctd_day(), is the equivalant of get_today() and
replaces the very awkwardly named ui_calendar_get_slctd_day_sec().

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
Lars Henriksen 2018-12-13 20:29:22 +01:00 committed by Lukas Fleischer
parent 06a4449afa
commit 8dd694b569
6 changed files with 15 additions and 44 deletions

View File

@ -48,18 +48,13 @@ int count, reg;
*/
static void do_storage(int day_changed)
{
/* * Save the selected item before rebuilding the day vector. */
struct day_item *day = ui_day_selitem();
union aptev_ptr item;
if (day) {
/*
* day_process_storage() rebuilds the vector of day items, so
* we need to save the reference to the actual item here.
*/
if (day)
item = day->item;
}
day_process_storage(ui_calendar_get_slctd_day(), day_changed);
day_store_items(get_slctd_day(), 1);
ui_day_load_items();
if (day_changed)

View File

@ -773,7 +773,6 @@ unsigned ui_calendar_week_begins_on_monday(void);
void ui_calendar_store_current_date(struct date *);
void ui_calendar_init_slctd_day(void);
struct date *ui_calendar_get_slctd_day(void);
time_t ui_calendar_get_slctd_day_sec(void);
void ui_calendar_monthly_view_cache_set_invalid(void);
void ui_calendar_update_panel(void);
void ui_calendar_goto_today(void);
@ -807,7 +806,6 @@ int day_item_get_state(struct day_item *);
void day_item_add_exc(struct day_item *, time_t);
void day_item_fork(struct day_item *, struct day_item *);
void day_store_items(time_t, int);
void day_process_storage(struct date *, unsigned);
void day_display_item_date(struct day_item *, WINDOW *, int, time_t, int, int);
void day_display_item(struct day_item *, WINDOW *, int, int, int, int);
void day_write_stdout(time_t, const char *, const char *, const char *,
@ -1175,6 +1173,7 @@ long min2sec(unsigned);
void draw_scrollbar(struct scrollwin *, int);
void item_in_popup(const char *, const char *, const char *, const char *);
time_t get_today(void);
time_t get_slctd_day(void);
time_t now(void);
char *nowstr(void);
void print_bool_option_incolor(WINDOW *, unsigned, int, int);

View File

@ -368,28 +368,6 @@ day_store_items(time_t date, int include_captions)
day_items_nb = events + apts;
}
/*
* Store the events and appointments for the selected day, and write
* those items in a pad. If selected day is null, then store items for current
* day. This is useful to speed up the appointment panel update.
*/
void day_process_storage(struct date *slctd_date, unsigned day_changed)
{
struct date day;
if (slctd_date)
day = *slctd_date;
else
ui_calendar_store_current_date(&day);
/* Inits */
if (apad.length != 0)
delwin(apad.ptrwin);
/* Store the events and appointments (recursive and normal items). */
day_store_items(date2sec(day, 0, 0), 1);
}
/*
* Print an item date in the appointment panel.
*/
@ -495,8 +473,7 @@ void day_popup_item(struct day_item *day)
struct apoint apt_tmp;
apt_tmp.start = day->start;
apt_tmp.dur = day_item_get_duration(day);
apoint_sec2str(&apt_tmp, ui_calendar_get_slctd_day_sec(),
a_st, a_end);
apoint_sec2str(&apt_tmp, get_slctd_day(), a_st, a_end);
item_in_popup(a_st, a_end, day_item_get_mesg(day),
_("Appointment:"));

View File

@ -193,12 +193,6 @@ struct date *ui_calendar_get_slctd_day(void)
return &slctd_day;
}
/* Returned value represents the selected day in calendar (in seconds) */
time_t ui_calendar_get_slctd_day_sec(void)
{
return date2sec(slctd_day, 0, 0);
}
static int ui_calendar_get_wday(struct date *date)
{
struct tm t;

View File

@ -672,7 +672,7 @@ void ui_day_item_add(void)
item.ev = event_new(item_mesg, 0L, start, 1);
}
io_set_modified();
day_process_storage(ui_calendar_get_slctd_day(), 0);
day_store_items(get_slctd_day(), 1);
ui_day_load_items();
ui_day_set_selitem_by_aptev_ptr(item);
}
@ -734,7 +734,7 @@ void ui_day_item_delete(unsigned reg)
break;
case 2:
if (p->type == RECUR_EVNT) {
date = ui_calendar_get_slctd_day_sec();
date = get_slctd_day();
day_item_add_exc(p, date);
} else {
date = update_time_in_date(p->start, 0, 0);
@ -888,7 +888,7 @@ void ui_day_item_repeat(void)
keys_wgetch(win[KEY].p);
}
date = ui_calendar_get_slctd_day_sec();
date = get_slctd_day();
if (p->type == EVNT) {
struct event *ev = p->item.ev;
recur_event_new(ev->mesg, ev->note, ev->day, ev->id, type,
@ -963,7 +963,7 @@ void ui_day_item_paste(unsigned reg)
return;
day_item_fork(&day_cut[reg], &day);
day_paste_item(&day, ui_calendar_get_slctd_day_sec());
day_paste_item(&day, get_slctd_day());
io_set_modified();
ui_calendar_monthly_view_cache_set_invalid();

View File

@ -672,6 +672,12 @@ time_t get_today(void)
return date2sec(day, 0, 0);
}
/* Returns the beginning of the selected day in the calendar. */
time_t get_slctd_day(void)
{
return date2sec(*ui_calendar_get_slctd_day(), 0, 0);
}
/* Returns the current time in seconds. */
time_t now(void)
{