diff options
Diffstat (limited to 'src/calcurse.c')
-rw-r--r-- | src/calcurse.c | 304 |
1 files changed, 172 insertions, 132 deletions
diff --git a/src/calcurse.c b/src/calcurse.c index 662f185..35a1fa5 100644 --- a/src/calcurse.c +++ b/src/calcurse.c @@ -39,6 +39,22 @@ #include "calcurse.h" /* + * Store the events and appointments for the selected day and reset the + * appointment highlight pointer if a new day was selected. + */ +static struct day_items_nb +do_storage (int day_changed) +{ + struct day_items_nb inday = *day_process_storage (calendar_get_slctd_day (), + day_changed, &inday); + + if (day_changed) + apoint_hilt_set (1); + + return inday; +} + +/* * Calcurse is a text-based personal organizer which helps keeping track * of events and everyday tasks. It contains a calendar, a 'todo' list, * and puts your appointments in order. The user interface is configurable, @@ -48,22 +64,16 @@ int main (int argc, char **argv) { - struct conf conf; struct day_items_nb inday; - int background, foreground; int non_interactive; int no_data_file = 1; - int sav_hilt_app = 0; - int sav_hilt_tod = 0; int cut_item = 0; - unsigned do_storage = 0; - unsigned do_update = 1; - unsigned day_changed = 0; char *no_color_support = _("Sorry, colors are not supported by your terminal\n" "(Press [ENTER] to continue)"); char *quit_message = _("Do you really want to quit ?"); char choices[] = "[y/n] "; + int count; #if ENABLE_NLS setlocale (LC_ALL, ""); @@ -83,7 +93,7 @@ main (int argc, char **argv) * Begin by parsing and handling command line arguments. * The data path is also initialized here. */ - non_interactive = parse_args (argc, argv, &conf); + non_interactive = parse_args (argc, argv); if (non_interactive) exit_calcurse (EXIT_SUCCESS); else @@ -137,7 +147,7 @@ main (int argc, char **argv) background = COLOR_BLACK; } - vars_init (&conf); + vars_init (); wins_init (); wins_slctd_init (); notify_init_bar (); @@ -148,7 +158,7 @@ main (int argc, char **argv) * configuration (the display is then updated), and then * the todo list, appointments and events. */ - custom_load_conf (&conf, background); + custom_load_conf (); wins_erase_status_bar (); io_load_keys (conf.pager); io_load_todo (); @@ -156,73 +166,58 @@ main (int argc, char **argv) wins_reinit (); if (notify_bar ()) notify_start_main_thread (); - wins_update (); + wins_update (FLAG_ALL); io_startup_screen (conf.skip_system_dialogs, no_data_file); - inday = *day_process_storage (0, day_changed, &inday); + inday = *day_process_storage (0, 0, &inday); wins_slctd_set (CAL); - wins_update (); + wins_update (FLAG_ALL); calendar_start_date_thread (); if (conf.periodic_save > 0) - io_start_psave_thread (&conf); + io_start_psave_thread (); /* User input */ for (;;) { int key; - do_update = 1; - key = keys_getch (win[STA].p); - switch (key) + if (resize) { - case ERR: - do_update = 0; - break; + resize = 0; + wins_reset (); + } + key = keys_getch (win[STA].p, &count); + switch (key) + { case KEY_GENERIC_REDRAW: resize = 1; break; case KEY_GENERIC_CHANGE_VIEW: wins_reset_status_page (); - /* Need to save the previously highlighted event. */ - switch (wins_slctd ()) - { - case TOD: - sav_hilt_tod = todo_hilt (); - todo_hilt_set (0); - break; - case APP: - sav_hilt_app = apoint_hilt (); - apoint_hilt_set (0); - break; - default: - break; - } wins_slctd_next (); /* Select the event to highlight. */ switch (wins_slctd ()) { case TOD: - if ((sav_hilt_tod == 0) && (todo_nb () != 0)) + if ((todo_hilt () == 0) && (todo_nb () > 0)) todo_hilt_set (1); - else - todo_hilt_set (sav_hilt_tod); break; case APP: - if ((sav_hilt_app == 0) - && ((inday.nb_events + inday.nb_apoints) != 0)) + if ((apoint_hilt () == 0) && + ((inday.nb_events + inday.nb_apoints) > 0)) apoint_hilt_set (1); - else - apoint_hilt_set (sav_hilt_app); break; default: break; } + wins_update (FLAG_ALL); break; case KEY_GENERIC_OTHER_CMD: wins_other_status_page (wins_slctd ()); + wins_update (FLAG_STA); break; case KEY_GENERIC_GOTO: @@ -233,8 +228,8 @@ main (int argc, char **argv) calendar_goto_today (); else calendar_change_day (conf.input_datefmt); - do_storage = 1; - day_changed = 1; + inday = do_storage (1); + wins_update (FLAG_CAL | FLAG_APP | FLAG_STA); break; case KEY_VIEW_ITEM: @@ -242,6 +237,7 @@ main (int argc, char **argv) day_popup_item (); else if ((wins_slctd () == TOD) && (todo_hilt () != 0)) item_in_popup (NULL, NULL, todo_saved_mesg (), _("To do :")); + wins_update (FLAG_ALL); break; case KEY_GENERIC_CONFIG_MENU: @@ -269,7 +265,7 @@ main (int argc, char **argv) break; case 'G': case 'g': - custom_general_config (&conf); + custom_general_config (); break; case 'N': case 'n': @@ -283,25 +279,29 @@ main (int argc, char **argv) case 'S': custom_sidebar_config (); break; + default: + continue; } wins_reset (); - wins_update (); - do_storage = 1; + wins_update (FLAG_ALL); wins_erase_status_bar (); custom_config_bar (); + inday = do_storage (0); } - wins_update (); + wins_update (FLAG_ALL); break; case KEY_GENERIC_ADD_APPT: apoint_add (); - do_storage = 1; + inday = do_storage (1); + wins_update (FLAG_CAL | FLAG_APP | FLAG_STA); break; case KEY_GENERIC_ADD_TODO: todo_new_item (); if (todo_hilt () == 0 && todo_nb () == 1) - todo_hilt_increase (); + todo_hilt_increase (1); + wins_update (FLAG_TOD | FLAG_STA); break; case KEY_ADD_ITEM: @@ -309,12 +309,14 @@ main (int argc, char **argv) { case APP: apoint_add (); - do_storage = 1; + inday = do_storage (0); + wins_update (FLAG_CAL | FLAG_APP | FLAG_STA); break; case TOD: todo_new_item (); if (todo_hilt () == 0 && todo_nb () == 1) - todo_hilt_increase (); + todo_hilt_increase (1); + wins_update (FLAG_TOD | FLAG_STA); break; default: break; @@ -323,25 +325,38 @@ main (int argc, char **argv) case KEY_EDIT_ITEM: if (wins_slctd () == APP && apoint_hilt () != 0) - day_edit_item (&conf); + { + day_edit_item (); + inday = do_storage (0); + wins_update (FLAG_CAL | FLAG_APP | FLAG_STA); + } else if (wins_slctd () == TOD && todo_hilt () != 0) - todo_edit_item (); - do_storage = 1; + { + todo_edit_item (); + wins_update (FLAG_TOD | FLAG_STA); + } break; case KEY_DEL_ITEM: if (wins_slctd () == APP && apoint_hilt () != 0) - apoint_delete (&conf, &inday.nb_events, &inday.nb_apoints); + { + apoint_delete (&inday.nb_events, &inday.nb_apoints); + inday = do_storage (0); + wins_update (FLAG_CAL | FLAG_APP | FLAG_STA); + } else if (wins_slctd () == TOD && todo_hilt () != 0) - todo_delete (&conf); - do_storage = 1; + { + todo_delete (); + wins_update (FLAG_TOD | FLAG_STA); + } break; case KEY_GENERIC_CUT: if (wins_slctd () == APP && apoint_hilt () != 0) { cut_item = apoint_cut (&inday.nb_events, &inday.nb_apoints); - do_storage = 1; + inday = do_storage (0); + wins_update (FLAG_CAL | FLAG_APP); } break; @@ -350,22 +365,38 @@ main (int argc, char **argv) { apoint_paste (&inday.nb_events, &inday.nb_apoints, cut_item); cut_item = 0; - do_storage = 1; + inday = do_storage (0); + wins_update (FLAG_CAL | FLAG_APP); } break; case KEY_REPEAT_ITEM: if (wins_slctd () == APP && apoint_hilt () != 0) - recur_repeat_item (&conf); - do_storage = 1; + recur_repeat_item (); + inday = do_storage (0); + wins_update (FLAG_CAL | FLAG_APP | FLAG_STA); break; case KEY_FLAG_ITEM: if (wins_slctd () == APP && apoint_hilt () != 0) - apoint_switch_notify (); + { + apoint_switch_notify (); + inday = do_storage (0); + wins_update (FLAG_APP); + } + else if (wins_slctd () == TOD && todo_hilt () != 0) + { + todo_flag (); + wins_update (FLAG_TOD); + } + break; + + case KEY_PIPE_ITEM: + if (wins_slctd () == APP && apoint_hilt () != 0) + day_pipe_item (); else if (wins_slctd () == TOD && todo_hilt () != 0) - todo_flag (); - do_storage = 1; + todo_pipe_item (); + wins_update (FLAG_ALL); break; case KEY_RAISE_PRIORITY: @@ -377,15 +408,19 @@ main (int argc, char **argv) todo_set_first (todo_hilt ()); else if (todo_hilt_pos () >= win[TOD].h - 4) todo_set_first (todo_hilt () - win[TOD].h + 5); + wins_update (FLAG_TOD); } break; case KEY_EDIT_NOTE: if (wins_slctd () == APP && apoint_hilt () != 0) - day_edit_note (conf.editor); + { + day_edit_note (conf.editor); + inday = do_storage (0); + } else if (wins_slctd () == TOD && todo_hilt () != 0) todo_edit_note (conf.editor); - do_storage = 1; + wins_update (FLAG_ALL); break; case KEY_VIEW_NOTE: @@ -393,21 +428,25 @@ main (int argc, char **argv) day_view_note (conf.pager); else if (wins_slctd () == TOD && todo_hilt () != 0) todo_view_note (conf.pager); + wins_update (FLAG_ALL); break; case KEY_GENERIC_HELP: wins_status_bar (); help_screen (); + wins_update (FLAG_ALL); break; case KEY_GENERIC_SAVE: - io_save_cal (&conf, IO_SAVE_DISPLAY_BAR); + io_save_cal (IO_SAVE_DISPLAY_BAR); + wins_update (FLAG_STA); break; case KEY_GENERIC_IMPORT: wins_erase_status_bar (); - io_import_data (IO_IMPORT_ICAL, &conf, NULL); - do_storage = 1; + io_import_data (IO_IMPORT_ICAL, NULL); + inday = do_storage (0); + wins_update (FLAG_ALL); break; case KEY_GENERIC_EXPORT: @@ -419,29 +458,29 @@ main (int argc, char **argv) { case 'I': case 'i': - io_export_data (IO_EXPORT_ICAL, &conf); + io_export_data (IO_EXPORT_ICAL); break; case 'P': case 'p': - io_export_data (IO_EXPORT_PCAL, &conf); + io_export_data (IO_EXPORT_PCAL); break; } wins_reset (); - wins_update (); - do_storage = 1; + wins_update (FLAG_ALL); wins_erase_status_bar (); io_export_bar (); } - wins_update (); + inday = do_storage (0); + wins_update (FLAG_ALL); break; case KEY_GENERIC_NEXT_DAY: case KEY_MOVE_RIGHT: if (wins_slctd () == CAL || key == KEY_GENERIC_NEXT_DAY) { - do_storage = 1; - day_changed = 1; - calendar_move (RIGHT); + calendar_move (RIGHT, count); + inday = do_storage (1); + wins_update (FLAG_CAL | FLAG_APP); } break; @@ -449,9 +488,9 @@ main (int argc, char **argv) case KEY_MOVE_LEFT: if (wins_slctd () == CAL || key == KEY_GENERIC_PREV_DAY) { - do_storage = 1; - day_changed = 1; - calendar_move (LEFT); + calendar_move (LEFT, count); + inday = do_storage (1); + wins_update (FLAG_CAL | FLAG_APP); } break; @@ -459,20 +498,26 @@ main (int argc, char **argv) case KEY_MOVE_UP: if (wins_slctd () == CAL || key == KEY_GENERIC_PREV_WEEK) { - do_storage = 1; - day_changed = 1; - calendar_move (UP); + calendar_move (UP, count); + inday = do_storage (1); + wins_update (FLAG_CAL | FLAG_APP); } - else if ((wins_slctd () == APP) && (apoint_hilt () > 1)) + else if (wins_slctd () == APP) { - apoint_hilt_decrease (); + if (count >= apoint_hilt ()) + count = apoint_hilt () - 1; + apoint_hilt_decrease (count); apoint_scroll_pad_up (inday.nb_events); + wins_update (FLAG_APP); } - else if ((wins_slctd () == TOD) && (todo_hilt () > 1)) + else if (wins_slctd () == TOD) { - todo_hilt_decrease (); + if (count >= todo_hilt ()) + count = todo_hilt () - 1; + todo_hilt_decrease (count); if (todo_hilt_pos () < 0) - todo_first_decrease (); + todo_first_increase (todo_hilt_pos ()); + wins_update (FLAG_TOD); } break; @@ -480,55 +525,68 @@ main (int argc, char **argv) case KEY_MOVE_DOWN: if (wins_slctd () == CAL || key == KEY_GENERIC_NEXT_WEEK) { - do_storage = 1; - day_changed = 1; - calendar_move (DOWN); + calendar_move (DOWN, count); + inday = do_storage (1); + wins_update (FLAG_CAL | FLAG_APP); } - else if ((wins_slctd () == APP) && - (apoint_hilt () < inday.nb_events + inday.nb_apoints)) + else if (wins_slctd () == APP) { - apoint_hilt_increase (); + if (count > inday.nb_events + inday.nb_apoints - apoint_hilt ()) + count = inday.nb_events + inday.nb_apoints - apoint_hilt (); + apoint_hilt_increase (count); apoint_scroll_pad_down (inday.nb_events, win[APP].h); + wins_update (FLAG_APP); } - else if ((wins_slctd () == TOD) && (todo_hilt () < todo_nb ())) + else if (wins_slctd () == TOD) { - todo_hilt_increase (); - if (todo_hilt_pos () == win[TOD].h - 4) - todo_first_increase (); + if (count > todo_nb () - todo_hilt ()) + count = todo_nb () - todo_hilt (); + todo_hilt_increase (count); + if (todo_hilt_pos () >= win[TOD].h - 4) + todo_first_increase (todo_hilt_pos () - win[TOD].h + 5); + wins_update (FLAG_TOD); } break; case KEY_START_OF_WEEK: if (wins_slctd () == CAL) { - do_storage = 1; - day_changed = 1; - calendar_move (WEEK_START); + calendar_move (WEEK_START, count); + inday = do_storage (1); + wins_update (FLAG_CAL | FLAG_APP); } break; case KEY_END_OF_WEEK: if (wins_slctd () == CAL) { - do_storage = 1; - day_changed = 1; - calendar_move (WEEK_END); + calendar_move (WEEK_END, count); + inday = do_storage (1); + wins_update (FLAG_CAL | FLAG_APP); } break; case KEY_GENERIC_SCROLL_UP: if (wins_slctd () == CAL) - calendar_view_prev (); + { + calendar_view_prev (); + wins_update (FLAG_CAL | FLAG_APP); + } break; case KEY_GENERIC_SCROLL_DOWN: if (wins_slctd () == CAL) - calendar_view_next (); + { + calendar_view_next (); + wins_update (FLAG_CAL | FLAG_APP); + } break; case KEY_GENERIC_QUIT: if (conf.auto_save) - io_save_cal (&conf, IO_SAVE_DISPLAY_BAR); + io_save_cal (IO_SAVE_DISPLAY_BAR); + if (conf.auto_gc) + note_gc (); if (conf.confirm_quit) { @@ -539,6 +597,7 @@ main (int argc, char **argv) else { wins_erase_status_bar (); + wins_update (FLAG_STA); break; } } @@ -546,34 +605,15 @@ main (int argc, char **argv) exit_calcurse (EXIT_SUCCESS); break; + case KEY_RESIZE: + case ERR: + /* Do not reset the count parameter on resize or error. */ + continue; + default: - do_update = 0; break; } - if (do_storage) - { - inday = *day_process_storage (calendar_get_slctd_day (), - day_changed, &inday); - do_storage = !do_storage; - if (day_changed) - { - sav_hilt_app = 0; - day_changed = !day_changed; - if ((wins_slctd () == APP) && - (inday.nb_events + inday.nb_apoints != 0)) - apoint_hilt_set (1); - } - } - - if (resize) - { - resize = 0; - do_update = 0; - wins_reset (); - } - - if (do_update) - wins_update (); + count = 0; } } |