aboutsummaryrefslogtreecommitdiffstats
path: root/src/calcurse.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/calcurse.c')
-rw-r--r--src/calcurse.c201
1 files changed, 132 insertions, 69 deletions
diff --git a/src/calcurse.c b/src/calcurse.c
index 1f0696d..c89d1dd 100644
--- a/src/calcurse.c
+++ b/src/calcurse.c
@@ -1,7 +1,7 @@
/*
* Calcurse - text-based organizer
*
- * Copyright (c) 2004-2020 calcurse Development Team <misc@calcurse.org>
+ * Copyright (c) 2004-2023 calcurse Development Team <misc@calcurse.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -41,36 +41,6 @@
#define HANDLE_KEY(key, fn) case key: fn(); break;
int count, reg;
-/*
- * Store events and appointments for a range of days in the day vector -
- * beginning with the selected day - and load them into the APP listbox. If no
- * day-change occurs, reset the selected APP item and with it the selected day,
- * thereby storing and loading the same range of days.
- */
-static void do_storage(int day_changed)
-{
- /*
- * Save the selected item before rebuilding the day vector -
- * unless already set.
- */
- if (!day_check_sel_data())
- day_set_sel_data(ui_day_get_sel());
-
- if (!day_changed)
- ui_day_sel_reset();
-
- /* The day_items vector. */
- day_store_items(get_slctd_day(), 1, day_get_days());
- /* The APP listbox. */
- ui_day_load_items();
-
- if (day_changed)
- ui_day_sel_reset();
- else
- ui_day_find_sel();
-
- day_set_sel_data(&empty_day);
-}
static inline void key_generic_change_view(void)
{
@@ -79,6 +49,13 @@ static inline void key_generic_change_view(void)
wins_update(FLAG_ALL);
}
+static inline void key_generic_prev_view(void)
+{
+ wins_reset_status_page();
+ wins_slctd_prev();
+ wins_update(FLAG_ALL);
+}
+
static inline void key_generic_other_cmd(void)
{
wins_other_status_page();
@@ -90,7 +67,7 @@ static inline void key_generic_goto(void)
wins_erase_status_bar();
ui_calendar_set_current_date();
ui_calendar_change_day(conf.input_datefmt);
- do_storage(1);
+ day_do_storage(1);
wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
}
@@ -99,7 +76,7 @@ static inline void key_generic_goto_today(void)
wins_erase_status_bar();
ui_calendar_set_current_date();
ui_calendar_goto_today();
- do_storage(1);
+ day_do_storage(1);
wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
}
@@ -117,14 +94,14 @@ static inline void key_generic_config_menu(void)
wins_erase_status_bar();
wins_reset_status_page();
custom_config_main();
- do_storage(0);
+ day_do_storage(0);
wins_update(FLAG_ALL);
}
static inline void key_generic_add_appt(void)
{
ui_day_item_add();
- do_storage(0);
+ day_do_storage(0);
wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
}
@@ -140,7 +117,7 @@ static inline void key_add_item(void)
case APP:
case CAL:
ui_day_item_add();
- do_storage(0);
+ day_do_storage(0);
wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
break;
case TOD:
@@ -156,7 +133,7 @@ static inline void key_edit_item(void)
{
if (wins_slctd() == APP && !event_dummy(ui_day_get_sel())) {
ui_day_item_edit();
- do_storage(0);
+ day_do_storage(0);
wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
} else if (wins_slctd() == TOD) {
ui_todo_edit();
@@ -168,7 +145,7 @@ static inline void key_del_item(void)
{
if (wins_slctd() == APP && !event_dummy(ui_day_get_sel())) {
ui_day_item_delete(reg);
- do_storage(0);
+ day_do_storage(0);
wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
} else if (wins_slctd() == TOD) {
ui_todo_delete();
@@ -186,7 +163,7 @@ static inline void key_generic_paste(void)
{
if (wins_slctd() == APP) {
ui_day_item_paste(reg);
- do_storage(0);
+ day_do_storage(0);
wins_update(FLAG_CAL | FLAG_APP);
}
}
@@ -195,7 +172,7 @@ static inline void key_repeat_item(void)
{
if (wins_slctd() == APP && !event_dummy(ui_day_get_sel())) {
ui_day_item_repeat();
- do_storage(0);
+ day_do_storage(0);
wins_update(FLAG_CAL | FLAG_APP | FLAG_STA);
}
}
@@ -204,7 +181,7 @@ static inline void key_flag_item(void)
{
if (wins_slctd() == APP && !event_dummy(ui_day_get_sel())) {
ui_day_flag();
- do_storage(0);
+ day_do_storage(0);
wins_update(FLAG_APP);
} else if (wins_slctd() == TOD) {
ui_todo_flag();
@@ -243,7 +220,7 @@ static inline void key_edit_note(void)
{
if (wins_slctd() == APP && !event_dummy(ui_day_get_sel())) {
ui_day_edit_note();
- do_storage(0);
+ day_do_storage(0);
} else if (wins_slctd() == TOD) {
ui_todo_edit_note();
}
@@ -283,7 +260,7 @@ static inline void key_generic_save(void)
if (ret == IO_SAVE_RELOAD) {
ui_todo_load_items();
ui_todo_sel_reset();
- do_storage(0);
+ day_do_storage(0);
notify_check_next_app(1);
ui_calendar_monthly_view_cache_set_invalid();
}
@@ -318,7 +295,7 @@ static inline void key_generic_reload(void)
ret == IO_RELOAD_MERGE) {
ui_todo_load_items();
ui_todo_sel_reset();
- do_storage(0);
+ day_do_storage(0);
notify_check_next_app(1);
ui_calendar_monthly_view_cache_set_invalid();
}
@@ -348,7 +325,7 @@ static inline void key_generic_import(void)
wins_erase_status_bar();
io_import_data(IO_IMPORT_ICAL, NULL, NULL, NULL, NULL, NULL, NULL);
ui_calendar_monthly_view_cache_set_invalid();
- do_storage(0);
+ day_do_storage(0);
ui_todo_load_items();
wins_update(FLAG_ALL);
}
@@ -373,14 +350,14 @@ static inline void key_generic_export()
break;
}
- do_storage(0);
+ day_do_storage(0);
wins_update(FLAG_ALL);
}
static inline void key_generic_prev_day(void)
{
ui_calendar_move(DAY_PREV, count);
- do_storage(1);
+ day_do_storage(1);
wins_update(FLAG_CAL | FLAG_APP);
}
@@ -393,7 +370,7 @@ static inline void key_move_left(void)
static inline void key_generic_next_day(void)
{
ui_calendar_move(DAY_NEXT, count);
- do_storage(1);
+ day_do_storage(1);
wins_update(FLAG_CAL | FLAG_APP);
}
@@ -406,7 +383,7 @@ static inline void key_move_right(void)
static inline void key_generic_prev_week(void)
{
ui_calendar_move(WEEK_PREV, count);
- do_storage(1);
+ day_do_storage(1);
wins_update(FLAG_CAL | FLAG_APP);
}
@@ -417,7 +394,7 @@ static inline void key_move_up(void)
} else if (wins_slctd() == APP) {
if (!ui_day_sel_move(-1)) {
ui_calendar_move(DAY_PREV, 1);
- do_storage(1);
+ day_do_storage(1);
ui_day_sel_dayend();
}
wins_update(FLAG_APP | FLAG_CAL);
@@ -430,7 +407,7 @@ static inline void key_move_up(void)
static inline void key_generic_next_week(void)
{
ui_calendar_move(WEEK_NEXT, count);
- do_storage(1);
+ day_do_storage(1);
wins_update(FLAG_CAL | FLAG_APP);
}
@@ -441,7 +418,7 @@ static inline void key_move_down(void)
} else if (wins_slctd() == APP) {
if (!ui_day_sel_move(1)) {
ui_calendar_move(DAY_PREV, day_get_days() - 2);
- do_storage(1);
+ day_do_storage(1);
ui_day_sel_daybegin(day_get_days() - 1);
}
wins_update(FLAG_APP | FLAG_CAL);
@@ -454,28 +431,28 @@ static inline void key_move_down(void)
static inline void key_generic_prev_month(void)
{
ui_calendar_move(MONTH_PREV, count);
- do_storage(1);
+ day_do_storage(1);
wins_update(FLAG_CAL | FLAG_APP);
}
static inline void key_generic_next_month(void)
{
ui_calendar_move(MONTH_NEXT, count);
- do_storage(1);
+ day_do_storage(1);
wins_update(FLAG_CAL | FLAG_APP);
}
static inline void key_generic_prev_year(void)
{
ui_calendar_move(YEAR_PREV, count);
- do_storage(1);
+ day_do_storage(1);
wins_update(FLAG_CAL | FLAG_APP);
}
static inline void key_generic_next_year(void)
{
ui_calendar_move(YEAR_NEXT, count);
- do_storage(1);
+ day_do_storage(1);
wins_update(FLAG_CAL | FLAG_APP);
}
@@ -483,7 +460,7 @@ static inline void key_start_of_week(void)
{
if (wins_slctd() == CAL) {
ui_calendar_move(WEEK_START, count);
- do_storage(1);
+ day_do_storage(1);
wins_update(FLAG_CAL | FLAG_APP);
}
}
@@ -492,7 +469,7 @@ static inline void key_end_of_week(void)
{
if (wins_slctd() == CAL) {
ui_calendar_move(WEEK_END, count);
- do_storage(1);
+ day_do_storage(1);
wins_update(FLAG_CAL | FLAG_APP);
}
}
@@ -556,7 +533,8 @@ static inline void key_generic_cmd(void)
int valid = 0, force = 0, ret;
char *error_msg;
- status_mesg(_("Command: [ h(elp) | w(rite)(!) | q(uit)(!) | wq(!) ]"), "");
+ status_mesg(_("Command: "
+ "[ h(elp) | w(rite)(!) | q(uit)(!) | wq(!) | n(ext) | p(rev) ]"), "");
if (getstring(win[STA].p, cmd, BUFSIZ, 0, 1) != GETSTRING_VALID)
goto cleanup;
cmd_name = strtok(cmd, " ");
@@ -608,6 +586,96 @@ static inline void key_generic_cmd(void)
valid = 1;
}
+ if (!strcmp(cmd_name, "next") || !strcmp(cmd_name, "n")) {
+ struct day_item *item;
+ time_t day, next;
+ struct recur_apoint *rapt;
+ struct recur_event *rev;
+ int more = 0;
+
+ if (wins_slctd() != APP) {
+ error_msg =
+ _("Select a repeating item in the appointments panel.");
+ warnbox(error_msg);
+ goto cleanup;
+ }
+ item = ui_day_get_sel();
+ /*
+ * The selected day need not be the (item) start day
+ * for multi-day occurrences.
+ */
+ day = DAY(item->start);
+ if (item->type == RECUR_EVNT) {
+ rev = item->item.rev;
+ more = recur_next_occurrence(rev->day, -1, rev->rpt, &rev->exc,
+ day, &next);
+ } else if (item->type == RECUR_APPT) {
+ rapt = item->item.rapt;
+ more = recur_next_occurrence(rapt->start, rapt->dur, rapt->rpt,
+ &rapt->exc, day, &next);
+ } else {
+ error_msg = _("Not a repeating item.");
+ warnbox(error_msg);
+ goto cleanup;
+ }
+ if (!more) {
+ error_msg = _("Last occurrence.");
+ warnbox(error_msg);
+ goto cleanup;
+ }
+ item->order = next;
+ ui_calendar_set_slctd_day(sec2date(next));
+ day_set_sel_data(item);
+ day_do_storage(1);
+
+ valid = 1;
+ }
+ if (!strcmp(cmd_name, "prev") || !strcmp(cmd_name, "p")) {
+ struct day_item *item;
+ time_t day, prev;
+ struct recur_apoint *rapt;
+ struct recur_event *rev;
+ int more = 0;
+
+ if (wins_slctd() != APP) {
+ error_msg = _("Select a repeating item in the"
+ " appointments panel.");
+ warnbox(error_msg);
+ goto cleanup;
+ }
+ item = ui_day_get_sel();
+ /*
+ * The selected day need not be the (item) start day
+ * for multi-day occurrences.
+ */
+ day = DAY(item->start);
+ if (item->type == RECUR_EVNT) {
+ rev = item->item.rev;
+ more = recur_prev_occurrence(rev->day, -1, rev->rpt,
+ &rev->exc, day, &prev);
+ } else if (item->type == RECUR_APPT) {
+ rapt = item->item.rapt;
+ more = recur_prev_occurrence(rapt->start, rapt->dur,
+ rapt->rpt, &rapt->exc,
+ day, &prev);
+ } else {
+ error_msg = _("Not a repeating item.");
+ warnbox(error_msg);
+ goto cleanup;
+ }
+ if (!more) {
+ error_msg = _("First occurrence.");
+ warnbox(error_msg);
+ goto cleanup;
+ }
+ item->order = prev;
+ ui_calendar_set_slctd_day(sec2date(prev));
+ day_set_sel_data(item);
+ day_do_storage(1);
+
+ valid = 1;
+ }
+
if (!valid) {
asprintf(&error_msg, _("No such command: %s"), cmd);
status_mesg(error_msg, "");
@@ -628,8 +696,6 @@ cleanup:
*/
int main(int argc, char **argv)
{
- int no_data_file = 1;
-
#if ENABLE_NLS
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
@@ -644,7 +710,7 @@ int main(int argc, char **argv)
/* Non-interactive mode. */
exit_calcurse(EXIT_SUCCESS);
} else {
- no_data_file = io_check_data_files();
+ io_check_data_files();
dmon_stop();
io_set_lock();
}
@@ -714,12 +780,8 @@ int main(int argc, char **argv)
* implicitly calling wrefresh() later (causing ncurses race conditions).
*/
wins_wrefresh(win[KEY].p);
- if (show_dialogs()) {
- wins_update(FLAG_ALL);
- io_startup_screen(no_data_file);
- }
ui_calendar_monthly_view_cache_set_invalid();
- do_storage(1);
+ day_do_storage(1);
ui_todo_load_items();
ui_todo_sel_reset();
wins_update(FLAG_ALL);
@@ -739,7 +801,7 @@ int main(int argc, char **argv)
que_show();
if (conf.systemevents) {
que_save();
- do_storage(0);
+ day_do_storage(0);
}
wins_update(FLAG_ALL);
que_rem();
@@ -749,7 +811,7 @@ int main(int argc, char **argv)
resize = 0;
wins_reset();
if (conf.multiple_days) {
- do_storage(0);
+ day_do_storage(0);
wins_update(FLAG_APP);
}
}
@@ -765,6 +827,7 @@ int main(int argc, char **argv)
wtimeout(win[KEY].p, -1);
switch (key) {
HANDLE_KEY(KEY_GENERIC_CHANGE_VIEW, key_generic_change_view);
+ HANDLE_KEY(KEY_GENERIC_PREV_VIEW, key_generic_prev_view);
HANDLE_KEY(KEY_GENERIC_OTHER_CMD, key_generic_other_cmd);
HANDLE_KEY(KEY_GENERIC_GOTO, key_generic_goto);
HANDLE_KEY(KEY_GENERIC_GOTO_TODAY, key_generic_goto_today);