diff options
author | Will Song <incertia9474@gmail.com> | 2015-01-27 19:55:16 -0600 |
---|---|---|
committer | Will Song <incertia9474@gmail.com> | 2015-01-27 19:55:16 -0600 |
commit | 7f436d614b11d72893d856f1c3d817ab34b0b9eb (patch) | |
tree | 0f0692382e6976602e51643c569c6fd467040642 | |
parent | 6529220351dd9b11c610df1c3372dd138d2af2b4 (diff) | |
download | profani-tty-7f436d614b11d72893d856f1c3d817ab34b0b9eb.tar.gz |
use custom format string for time preference
-rw-r--r-- | src/command/command.c | 22 | ||||
-rw-r--r-- | src/command/commands.c | 23 | ||||
-rw-r--r-- | src/config/preferences.c | 2 | ||||
-rw-r--r-- | src/ui/console.c | 6 | ||||
-rw-r--r-- | src/ui/window.c | 9 |
5 files changed, 15 insertions, 47 deletions
diff --git a/src/command/command.c b/src/command/command.c index 8e16276b..1441ef46 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -620,10 +620,10 @@ static struct cmd_t command_defs[] = { "/time", cmd_time, parse_args, 1, 1, &cons_time_setting, - { "/time minutes|seconds", "Time display.", - { "/time minutes|seconds", + { "/time <format>", "Time display.", + { "/time <format>", "---------------------", - "Configure time precision for the main window.", + "Configure the time format for the main window.", NULL } } }, { "/inpblock", @@ -1121,7 +1121,6 @@ static Autocomplete form_ac; static Autocomplete form_field_multi_ac; static Autocomplete occupants_ac; static Autocomplete occupants_default_ac; -static Autocomplete time_ac; static Autocomplete resource_ac; static Autocomplete inpblock_ac; @@ -1461,15 +1460,6 @@ cmd_init(void) autocomplete_add(occupants_default_ac, "show"); autocomplete_add(occupants_default_ac, "hide"); - time_ac = autocomplete_new(); - autocomplete_add(time_ac, "minutes"); - autocomplete_add(time_ac, "seconds"); - autocomplete_add(time_ac, "off"); - - time_ac = autocomplete_new(); - autocomplete_add(time_ac, "minutes"); - autocomplete_add(time_ac, "seconds"); - resource_ac = autocomplete_new(); autocomplete_add(resource_ac, "set"); autocomplete_add(resource_ac, "off"); @@ -1532,7 +1522,6 @@ cmd_uninit(void) autocomplete_free(form_field_multi_ac); autocomplete_free(occupants_ac); autocomplete_free(occupants_default_ac); - autocomplete_free(time_ac); autocomplete_free(resource_ac); autocomplete_free(inpblock_ac); } @@ -1697,7 +1686,6 @@ cmd_reset_autocomplete() autocomplete_reset(form_field_multi_ac); autocomplete_reset(occupants_ac); autocomplete_reset(occupants_default_ac); - autocomplete_reset(time_ac); autocomplete_reset(resource_ac); autocomplete_reset(inpblock_ac); @@ -2010,8 +1998,8 @@ _cmd_complete_parameters(const char * const input) } } - gchar *cmds[] = { "/help", "/prefs", "/disco", "/close", "/wins", "/subject", "/room", "/time" }; - Autocomplete completers[] = { help_ac, prefs_ac, disco_ac, close_ac, wins_ac, subject_ac, room_ac, time_ac }; + gchar *cmds[] = { "/help", "/prefs", "/disco", "/close", "/wins", "/subject", "/room", }; + Autocomplete completers[] = { help_ac, prefs_ac, disco_ac, close_ac, wins_ac, subject_ac, room_ac, }; for (i = 0; i < ARRAY_SIZE(cmds); i++) { result = autocomplete_param_with_ac(input, cmds[i], completers[i], TRUE); diff --git a/src/command/commands.c b/src/command/commands.c index 60ef3780..02910f99 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -3257,25 +3257,10 @@ cmd_wrap(gchar **args, struct cmd_help_t help) gboolean cmd_time(gchar **args, struct cmd_help_t help) { - if (g_strcmp0(args[0], "minutes") == 0) { - prefs_set_string(PREF_TIME, "minutes"); - cons_show("Time precision set to minutes."); - wins_resize_all(); - return TRUE; - } else if (g_strcmp0(args[0], "seconds") == 0) { - prefs_set_string(PREF_TIME, "seconds"); - cons_show("Time precision set to seconds."); - wins_resize_all(); - return TRUE; - } else if (g_strcmp0(args[0], "off") == 0) { - prefs_set_string(PREF_TIME, "off"); - cons_show("Time display disabled."); - wins_resize_all(); - return TRUE; - } else { - cons_show("Usage: %s", help.usage); - return TRUE; - } + prefs_set_string(PREF_TIME, args[0]); + cons_show("Time format set to '%s'", args[0]); + wins_resize_all(); + return TRUE; } gboolean diff --git a/src/config/preferences.c b/src/config/preferences.c index 67f12b18..652d4ed9 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -727,7 +727,7 @@ _get_default_string(preference_t pref) case PREF_ROSTER_BY: return "none"; case PREF_TIME: - return "seconds"; + return "%H:%M:%S"; default: return NULL; } diff --git a/src/ui/console.c b/src/ui/console.c index dd50d6d3..689f218c 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -919,12 +919,10 @@ void cons_time_setting(void) { char *pref_time = prefs_get_string(PREF_TIME); - if (g_strcmp0(pref_time, "minutes") == 0) - cons_show("Time (/time) : minutes"); - else if (g_strcmp0(pref_time, "off") == 0) + if (g_strcmp0(pref_time, "off") == 0) cons_show("Time (/time) : OFF"); else - cons_show("Time (/time) : seconds"); + cons_show("Time (/time) : %s", pref_time); prefs_free_string(pref_time); } diff --git a/src/ui/window.c b/src/ui/window.c index dfec5aab..7757fe39 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -36,6 +36,7 @@ #include <stdlib.h> #include <string.h> +#include <time.h> #include <assert.h> #include <glib.h> @@ -882,14 +883,10 @@ _win_print(ProfWin *window, const char show_char, GDateTime *time, if ((flags & NO_DATE) == 0) { gchar *date_fmt = NULL; char *time_pref = prefs_get_string(PREF_TIME); - if (g_strcmp0(time_pref, "minutes") == 0) { - date_fmt = g_date_time_format(time, "%H:%M"); - } else if (g_strcmp0(time_pref, "seconds") == 0) { - date_fmt = g_date_time_format(time, "%H:%M:%S"); - } + date_fmt = g_date_time_format(time, time_pref); free(time_pref); - if (date_fmt) { + if (date_fmt && strlen(date_fmt)) { if ((flags & NO_COLOUR_DATE) == 0) { wattron(window->layout->win, theme_attrs(THEME_TIME)); } |