diff options
author | Frederic Culot <calcurse@culot.org> | 2008-11-25 20:48:58 +0000 |
---|---|---|
committer | Frederic Culot <calcurse@culot.org> | 2008-11-25 20:48:58 +0000 |
commit | 910901a4f0abe565e5c1d12a480784e90a4bcd6c (patch) | |
tree | ba68a9d83d7cd48434a8af23bf98ad24f5c66811 | |
parent | eb88eaecb3055fc5ab3cd3e05f0bc77e68f3942a (diff) | |
download | calcurse-910901a4f0abe565e5c1d12a480784e90a4bcd6c.tar.gz calcurse-910901a4f0abe565e5c1d12a480784e90a4bcd6c.zip |
User-defined keys are now saved to file.
-rwxr-xr-x | ChangeLog | 6 | ||||
-rwxr-xr-x | src/custom.c | 7 | ||||
-rwxr-xr-x | src/io.c | 76 | ||||
-rwxr-xr-x | src/keys.c | 15 | ||||
-rwxr-xr-x | src/keys.h | 3 |
5 files changed, 80 insertions, 27 deletions
@@ -1,3 +1,9 @@ +2008-11-25 Frederic Culot <frederic@culot.org> + + * src/io.c (io_save_cal): updated to save user-defined keys + + * src/keys.c (keys_save_bindings): new function + 2008-11-23 Frederic Culot <frederic@culot.org> * src/keys.c (keys_popup_info, keys_action_count_keys): new diff --git a/src/custom.c b/src/custom.c index d532ebb..a1defe5 100755 --- a/src/custom.c +++ b/src/custom.c @@ -1,4 +1,4 @@ -/* $calcurse: custom.c,v 1.26 2008/11/23 20:38:56 culot Exp $ */ +/* $calcurse: custom.c,v 1.27 2008/11/25 20:48:58 culot Exp $ */ /* * Calcurse - text-based organizer @@ -964,14 +964,13 @@ custom_keys_config_bar (void) binding_t info = {_("Key info"), KEY_GENERIC_HELP}; binding_t add = {_("Add key"), KEY_ADD_ITEM}; binding_t del = {_("Del key"), KEY_DEL_ITEM}; - binding_t edit = {_("Edit key"), KEY_EDIT_ITEM}; binding_t up = {_("Up"), KEY_MOVE_UP}; binding_t down = {_("Down"), KEY_MOVE_DOWN}; binding_t left = {_("Prev Key"), KEY_MOVE_LEFT}; binding_t right = {_("Next Key"), KEY_MOVE_RIGHT}; binding_t *binding[] = { - &quit, &info, &add, &del, &edit, &up, &down, &left, &right + &quit, &info, &add, &del, &up, &down, &left, &right }; int binding_size = sizeof (binding) / sizeof (binding[0]); @@ -1085,8 +1084,6 @@ custom_keys_config (void) if (selelm > 0) selelm--; break; - case KEY_EDIT_ITEM: - break; case KEY_GENERIC_QUIT: wins_scrollwin_delete (&kwin); return; @@ -1,4 +1,4 @@ -/* $calcurse: io.c,v 1.42 2008/11/16 17:42:53 culot Exp $ */ +/* $calcurse: io.c,v 1.43 2008/11/25 20:48:58 culot Exp $ */ /* * Calcurse - text-based organizer @@ -47,13 +47,25 @@ #define ICALDATEFMT "%Y%m%d" #define ICALDATETIMEFMT "%Y%m%dT%H%M%S" -typedef enum -{ +typedef enum { PROGRESS_BAR_SAVE, PROGRESS_BAR_LOAD, PROGRESS_BAR_EXPORT } progress_bar_t; +enum { + PROGRESS_BAR_CONF, + PROGRESS_BAR_TODO, + PROGRESS_BAR_APTS, + PROGRESS_BAR_KEYS +}; + +enum { + PROGRESS_BAR_EXPORT_EVENTS, + PROGRESS_BAR_EXPORT_APOINTS, + PROGRESS_BAR_EXPORT_TODO +}; + typedef enum { ICAL_VEVENT, ICAL_VTODO, @@ -123,50 +135,59 @@ static void progress_bar (progress_bar_t type, int progress) { #define SLEEPTIME 125000 -#define STEPS 3 -#define LABELENGTH 15 - - int i, step; +#define NBFILES 4 +#define NBEXPORTED 3 +#define LABELENGTH 15 + int i, step, steps; char *mesg_sav = _("Saving..."); char *mesg_load = _("Loading..."); char *mesg_export = _("Exporting..."); + char *error_msg = _("Internal error while displaying progress bar"); char *barchar = "|"; - char file[STEPS][LABELENGTH] = { + char *file[NBFILES] = { "[ conf ]", "[ todo ]", - "[ apts ]" + "[ apts ]", + "[ keys ]" }; - char data[STEPS][LABELENGTH] = { + char *data[NBEXPORTED] = { "[ events ]", "[appointments]", "[ todo ]" }; - int ipos = LABELENGTH + 2; - int epos[STEPS]; + int ipos = LABELENGTH + 2; + int epos[NBFILES]; /* progress bar length init. */ ipos = LABELENGTH + 2; - step = floor (col / (STEPS + 1)); - for (i = 0; i < STEPS - 1; i++) + steps = (type == PROGRESS_BAR_EXPORT) ? NBEXPORTED : NBFILES; + step = floor (col / (steps + 1)); + for (i = 0; i < steps - 1; i++) epos[i] = (i + 2) * step; - epos[STEPS - 1] = col - 2; + epos[steps - 1] = col - 2; switch (type) { case PROGRESS_BAR_SAVE: + EXIT_IF (progress < 0 || progress > PROGRESS_BAR_KEYS, + error_msg); status_mesg (mesg_sav, file[progress]); break; case PROGRESS_BAR_LOAD: + EXIT_IF (progress < 0 || progress > PROGRESS_BAR_KEYS, + error_msg); status_mesg (mesg_load, file[progress]); break; case PROGRESS_BAR_EXPORT: + EXIT_IF (progress < 0 || progress > PROGRESS_BAR_TODO, + error_msg); status_mesg (mesg_export, data[progress]); break; } /* Draw the progress bar. */ mvwprintw (win[STA].p, 1, ipos, barchar); - mvwprintw (win[STA].p, 1, epos[STEPS - 1], barchar); + mvwprintw (win[STA].p, 1, epos[steps - 1], barchar); custom_apply_attr (win[STA].p, ATTR_HIGHEST); for (i = ipos + 1; i < epos[progress]; i++) mvwaddch (win[STA].p, 1, i, ' ' | A_REVERSE); @@ -174,6 +195,10 @@ progress_bar (progress_bar_t type, int progress) wmove (win[STA].p, 0, 0); wrefresh (win[STA].p); usleep (SLEEPTIME); +#undef SLEEPTIME +#undef NBFILES +#undef NBEXPORTED +#undef LABELENGTH } /* Ask user for a file name to export data to. */ @@ -753,9 +778,8 @@ io_save_cal (io_mode_t mode, conf_t *conf) show_bar = true; /* Save the user configuration. */ - if (show_bar) - progress_bar (PROGRESS_BAR_SAVE, 0); + progress_bar (PROGRESS_BAR_SAVE, PROGRESS_BAR_CONF); data_file = fopen (path_conf, "w"); if (data_file == NULL) ERROR_MSG (access_pb); @@ -860,7 +884,7 @@ io_save_cal (io_mode_t mode, conf_t *conf) /* Save the todo data file. */ if (show_bar) - progress_bar (PROGRESS_BAR_SAVE, 1); + progress_bar (PROGRESS_BAR_SAVE, PROGRESS_BAR_TODO); data_file = fopen (path_todo, "w"); if (data_file == NULL) ERROR_MSG (access_pb); @@ -882,7 +906,7 @@ io_save_cal (io_mode_t mode, conf_t *conf) * Recursive items are written first. */ if (show_bar) - progress_bar (PROGRESS_BAR_SAVE, 2); + progress_bar (PROGRESS_BAR_SAVE, PROGRESS_BAR_APTS); data_file = fopen (path_apts, "w"); if (data_file == NULL) ERROR_MSG (access_pb); @@ -902,6 +926,18 @@ io_save_cal (io_mode_t mode, conf_t *conf) fclose (data_file); } + /* Save user-defined keys */ + if (show_bar) + progress_bar (PROGRESS_BAR_SAVE, PROGRESS_BAR_KEYS); + data_file = fopen (path_keys, "w"); + if (data_file == NULL) + ERROR_MSG (access_pb); + else + { + keys_save_bindings (data_file); + fclose (data_file); + } + /* Print a message telling data were saved */ if (mode == IO_MODE_INTERACTIVE && !conf->skip_system_dialogs) { @@ -1,4 +1,4 @@ -/* $calcurse: keys.c,v 1.4 2008/11/23 20:38:56 culot Exp $ */ +/* $calcurse: keys.c,v 1.5 2008/11/25 20:48:58 culot Exp $ */ /* * Calcurse - text-based organizer @@ -512,3 +512,16 @@ keys_popup_info (keys_e key) #undef WINROW #undef WINCOL } + +void +keys_save_bindings (FILE *fd) +{ + int i; + + EXIT_IF (fd == NULL, _("FATAL ERROR in keys_save_bindings: " + "null file pointer.")); + dump_intro (fd); + for (i = 0; i < NBKEYS; i++) + fprintf (fd, "%s %s\n", keydef[i].label, keys_action_allkeys (i)); + fclose (fd); +} @@ -1,4 +1,4 @@ -/* $calcurse: keys.h,v 1.4 2008/11/23 20:38:56 culot Exp $ */ +/* $calcurse: keys.h,v 1.5 2008/11/25 20:48:58 culot Exp $ */ /* * Calcurse - text-based organizer @@ -102,5 +102,6 @@ char *keys_action_nkey (keys_e, int); char *keys_action_allkeys (keys_e); void keys_display_bindings_bar (WINDOW *, binding_t **, int, int); void keys_popup_info (keys_e); +void keys_save_bindings (FILE *); #endif /* CALCURSE_KEYS_H */ |