aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLars Henriksen <LarsHenriksen@get2net.dk>2018-12-13 20:29:22 +0100
committerLukas Fleischer <lfleischer@calcurse.org>2019-05-22 01:56:59 -0400
commit8dd694b56956a1c4ec3519743904222b465e10a5 (patch)
treea049852063d6fdece604a454e2218fae892f68d6 /src
parent06a4449afae29d4dd0e5d49249674511bb1f4489 (diff)
downloadcalcurse-8dd694b56956a1c4ec3519743904222b465e10a5.tar.gz
calcurse-8dd694b56956a1c4ec3519743904222b465e10a5.zip
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>
Diffstat (limited to 'src')
-rw-r--r--src/calcurse.c11
-rw-r--r--src/calcurse.h3
-rw-r--r--src/day.c25
-rw-r--r--src/ui-calendar.c6
-rw-r--r--src/ui-day.c8
-rw-r--r--src/utils.c6
6 files changed, 15 insertions, 44 deletions
diff --git a/src/calcurse.c b/src/calcurse.c
index a6d54fd..d470661 100644
--- a/src/calcurse.c
+++ b/src/calcurse.c
@@ -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)
diff --git a/src/calcurse.h b/src/calcurse.h
index 3c9986f..6d6f205 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -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);
diff --git a/src/day.c b/src/day.c
index 96b863a..c4d1cac 100644
--- a/src/day.c
+++ b/src/day.c
@@ -369,28 +369,6 @@ day_store_items(time_t date, int include_captions)
}
/*
- * 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.
*/
void
@@ -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:"));
diff --git a/src/ui-calendar.c b/src/ui-calendar.c
index 20bfd09..5b8ab1f 100644
--- a/src/ui-calendar.c
+++ b/src/ui-calendar.c
@@ -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;
diff --git a/src/ui-day.c b/src/ui-day.c
index 2df9cef..bb5063f 100644
--- a/src/ui-day.c
+++ b/src/ui-day.c
@@ -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();
diff --git a/src/utils.c b/src/utils.c
index a194b10..fd47de6 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -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)
{