diff --git a/src/command/command.c b/src/command/command.c index 2203b398..f1432d90 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -947,8 +947,8 @@ static struct cmd_t command_defs[] = CMD_TAGS( CMD_TAG_UI) CMD_SYN( - "/time main set ", - "/time main off", + "/time console|chat|muc|mucconfig|private|xml set ", + "/time console|chat|muc|mucconfig|private|xml off", "/time statusbar set ", "/time statusbar off", "/time lastactivity set ") @@ -959,8 +959,18 @@ static struct cmd_t command_defs[] = "Setting the format to an unsupported string, will display the string. " "If the format contains spaces, it must be surrounded with double quotes.") CMD_ARGS( - { "main set ", "Change time format in main window." }, - { "main off", "Do not show time in main window." }, + { "console set ", "Set time format for console window." }, + { "console off", "Do not show time in console window." }, + { "chat set ", "Set time format for chat windows." }, + { "chat off", "Do not show time in chat windows." }, + { "muc set ", "Set time format for chat room windows." }, + { "muc off", "Do not show time in chat room windows." }, + { "mucconfig set ", "Set time format for chat room config windows." }, + { "mucconfig off", "Do not show time in chat room config windows." }, + { "private set ", "Set time format for private chat windows." }, + { "private off", "Do not show time in private chat windows." }, + { "xml set ", "Set time format for XML console window." }, + { "xml off", "Do not show time in XML console window." }, { "statusbar set ", "Change time format in statusbar." }, { "statusbar off", "Do not show time in status bar." }, { "lastactivity set ", "Change time format for last activity." }) @@ -2099,7 +2109,12 @@ cmd_init(void) autocomplete_add(occupants_show_ac, "jid"); time_ac = autocomplete_new(); - autocomplete_add(time_ac, "main"); + autocomplete_add(time_ac, "console"); + autocomplete_add(time_ac, "chat"); + autocomplete_add(time_ac, "muc"); + autocomplete_add(time_ac, "mucconfig"); + autocomplete_add(time_ac, "private"); + autocomplete_add(time_ac, "xml"); autocomplete_add(time_ac, "statusbar"); autocomplete_add(time_ac, "lastactivity"); @@ -3376,7 +3391,32 @@ _time_autocomplete(ProfWin *window, const char * const input) return found; } - found = autocomplete_param_with_ac(input, "/time main", time_format_ac, TRUE); + found = autocomplete_param_with_ac(input, "/time console", time_format_ac, TRUE); + if (found) { + return found; + } + + found = autocomplete_param_with_ac(input, "/time chat", time_format_ac, TRUE); + if (found) { + return found; + } + + found = autocomplete_param_with_ac(input, "/time muc", time_format_ac, TRUE); + if (found) { + return found; + } + + found = autocomplete_param_with_ac(input, "/time mucconfig", time_format_ac, TRUE); + if (found) { + return found; + } + + found = autocomplete_param_with_ac(input, "/time private", time_format_ac, TRUE); + if (found) { + return found; + } + + found = autocomplete_param_with_ac(input, "/time xml", time_format_ac, TRUE); if (found) { return found; } diff --git a/src/command/commands.c b/src/command/commands.c index 2e4332b2..eb4aa03f 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -3571,7 +3571,7 @@ cmd_time(ProfWin *window, const char * const command, gchar **args) { if (g_strcmp0(args[0], "lastactivity") == 0) { if (args[1] == NULL) { - cons_show("Current last activity time format is '%s'.", prefs_get_string(PREF_TIME_LASTACTIVITY)); + cons_show("Last activity time format: '%s'.", prefs_get_string(PREF_TIME_LASTACTIVITY)); return TRUE; } else if (g_strcmp0(args[1], "set") == 0 && args[2] != NULL) { prefs_set_string(PREF_TIME_LASTACTIVITY, args[2]); @@ -3588,7 +3588,7 @@ cmd_time(ProfWin *window, const char * const command, gchar **args) } } else if (g_strcmp0(args[0], "statusbar") == 0) { if (args[1] == NULL) { - cons_show("Current status bar time format is '%s'.", prefs_get_string(PREF_TIME_STATUSBAR)); + cons_show("Status bar time format: '%s'.", prefs_get_string(PREF_TIME_STATUSBAR)); return TRUE; } else if (g_strcmp0(args[1], "set") == 0 && args[2] != NULL) { prefs_set_string(PREF_TIME_STATUSBAR, args[2]); @@ -3596,7 +3596,7 @@ cmd_time(ProfWin *window, const char * const command, gchar **args) ui_redraw(); return TRUE; } else if (g_strcmp0(args[1], "off") == 0) { - prefs_set_string(PREF_TIME_STATUSBAR, ""); + prefs_set_string(PREF_TIME_STATUSBAR, "off"); cons_show("Status bar time display disabled."); ui_redraw(); return TRUE; @@ -3604,18 +3604,108 @@ cmd_time(ProfWin *window, const char * const command, gchar **args) cons_bad_cmd_usage(command); return TRUE; } - } else if (g_strcmp0(args[0], "main") == 0) { + } else if (g_strcmp0(args[0], "console") == 0) { if (args[1] == NULL) { - cons_show("Current time format is '%s'.", prefs_get_string(PREF_TIME)); + cons_show("Console time format: '%s'.", prefs_get_string(PREF_TIME_CONSOLE)); return TRUE; } else if (g_strcmp0(args[1], "set") == 0 && args[2] != NULL) { - prefs_set_string(PREF_TIME, args[2]); - cons_show("Time format set to '%s'.", args[2]); + prefs_set_string(PREF_TIME_CONSOLE, args[2]); + cons_show("Console time format set to '%s'.", args[2]); wins_resize_all(); return TRUE; } else if (g_strcmp0(args[1], "off") == 0) { - prefs_set_string(PREF_TIME, ""); - cons_show("Time display disabled."); + prefs_set_string(PREF_TIME_CONSOLE, "off"); + cons_show("Console time display disabled."); + wins_resize_all(); + return TRUE; + } else { + cons_bad_cmd_usage(command); + return TRUE; + } + } else if (g_strcmp0(args[0], "chat") == 0) { + if (args[1] == NULL) { + cons_show("Chat time format: '%s'.", prefs_get_string(PREF_TIME_CHAT)); + return TRUE; + } else if (g_strcmp0(args[1], "set") == 0 && args[2] != NULL) { + prefs_set_string(PREF_TIME_CHAT, args[2]); + cons_show("Chat time format set to '%s'.", args[2]); + wins_resize_all(); + return TRUE; + } else if (g_strcmp0(args[1], "off") == 0) { + prefs_set_string(PREF_TIME_CHAT, "off"); + cons_show("Chat time display disabled."); + wins_resize_all(); + return TRUE; + } else { + cons_bad_cmd_usage(command); + return TRUE; + } + } else if (g_strcmp0(args[0], "muc") == 0) { + if (args[1] == NULL) { + cons_show("MUC time format: '%s'.", prefs_get_string(PREF_TIME_MUC)); + return TRUE; + } else if (g_strcmp0(args[1], "set") == 0 && args[2] != NULL) { + prefs_set_string(PREF_TIME_MUC, args[2]); + cons_show("MUC time format set to '%s'.", args[2]); + wins_resize_all(); + return TRUE; + } else if (g_strcmp0(args[1], "off") == 0) { + prefs_set_string(PREF_TIME_MUC, "off"); + cons_show("MUC time display disabled."); + wins_resize_all(); + return TRUE; + } else { + cons_bad_cmd_usage(command); + return TRUE; + } + } else if (g_strcmp0(args[0], "mucconfig") == 0) { + if (args[1] == NULL) { + cons_show("MUC config time format: '%s'.", prefs_get_string(PREF_TIME_MUCCONFIG)); + return TRUE; + } else if (g_strcmp0(args[1], "set") == 0 && args[2] != NULL) { + prefs_set_string(PREF_TIME_MUCCONFIG, args[2]); + cons_show("MUC config time format set to '%s'.", args[2]); + wins_resize_all(); + return TRUE; + } else if (g_strcmp0(args[1], "off") == 0) { + prefs_set_string(PREF_TIME_MUCCONFIG, "off"); + cons_show("MUC config time display disabled."); + wins_resize_all(); + return TRUE; + } else { + cons_bad_cmd_usage(command); + return TRUE; + } + } else if (g_strcmp0(args[0], "private") == 0) { + if (args[1] == NULL) { + cons_show("Private chat time format: '%s'.", prefs_get_string(PREF_TIME_PRIVATE)); + return TRUE; + } else if (g_strcmp0(args[1], "set") == 0 && args[2] != NULL) { + prefs_set_string(PREF_TIME_PRIVATE, args[2]); + cons_show("Private chat time format set to '%s'.", args[2]); + wins_resize_all(); + return TRUE; + } else if (g_strcmp0(args[1], "off") == 0) { + prefs_set_string(PREF_TIME_PRIVATE, "off"); + cons_show("Private chat time display disabled."); + wins_resize_all(); + return TRUE; + } else { + cons_bad_cmd_usage(command); + return TRUE; + } + } else if (g_strcmp0(args[0], "xml") == 0) { + if (args[1] == NULL) { + cons_show("XML Console time format: '%s'.", prefs_get_string(PREF_TIME_XMLCONSOLE)); + return TRUE; + } else if (g_strcmp0(args[1], "set") == 0 && args[2] != NULL) { + prefs_set_string(PREF_TIME_XMLCONSOLE, args[2]); + cons_show("XML Console time format set to '%s'.", args[2]); + wins_resize_all(); + return TRUE; + } else if (g_strcmp0(args[1], "off") == 0) { + prefs_set_string(PREF_TIME_XMLCONSOLE, "off"); + cons_show("XML Console time display disabled."); wins_resize_all(); return TRUE; } else { diff --git a/src/config/preferences.c b/src/config/preferences.c index c53c09bc..b7ea178f 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -108,37 +108,22 @@ prefs_load(void) prefs_free_string(message); } - // move pre 0.4.7 otr.warn to enc.warn - err = NULL; - gboolean otr_warn = g_key_file_get_boolean(prefs, PREF_GROUP_UI, "otr.warn", &err); - if (err == NULL) { - g_key_file_set_boolean(prefs, PREF_GROUP_UI, _get_key(PREF_ENC_WARN), otr_warn); - g_key_file_remove_key(prefs, PREF_GROUP_UI, "otr.warn", NULL); - } else { - g_error_free(err); - } - - // migrate pre 0.4.7 time settings format + // migrate pre 0.4.8 time settings if (g_key_file_has_key(prefs, PREF_GROUP_UI, "time", NULL)) { char *time = g_key_file_get_string(prefs, PREF_GROUP_UI, "time", NULL); - if (g_strcmp0(time, "minutes") == 0) { - g_key_file_set_string(prefs, PREF_GROUP_UI, "time", "%H:%M"); - } else if (g_strcmp0(time, "seconds") == 0) { - g_key_file_set_string(prefs, PREF_GROUP_UI, "time", "%H:%M:%S"); - } else if (g_strcmp0(time, "off") == 0) { - g_key_file_set_string(prefs, PREF_GROUP_UI, "time", ""); - } - prefs_free_string(time); - } - if (g_key_file_has_key(prefs, PREF_GROUP_UI, "time.statusbar", NULL)) { - char *time = g_key_file_get_string(prefs, PREF_GROUP_UI, "time.statusbar", NULL); - if (g_strcmp0(time, "minutes") == 0) { - g_key_file_set_string(prefs, PREF_GROUP_UI, "time.statusbar", "%H:%M"); - } else if (g_strcmp0(time, "seconds") == 0) { - g_key_file_set_string(prefs, PREF_GROUP_UI, "time.statusbar", "%H:%M:%S"); - } else if (g_strcmp0(time, "off") == 0) { - g_key_file_set_string(prefs, PREF_GROUP_UI, "time.statusbar", ""); + char *val = NULL; + if (time) { + val = time; + } else { + val = "off"; } + g_key_file_set_string(prefs, PREF_GROUP_UI, "time.console", val); + g_key_file_set_string(prefs, PREF_GROUP_UI, "time.chat", val); + g_key_file_set_string(prefs, PREF_GROUP_UI, "time.muc", val); + g_key_file_set_string(prefs, PREF_GROUP_UI, "time.mucconfig", val); + g_key_file_set_string(prefs, PREF_GROUP_UI, "time.private", val); + g_key_file_set_string(prefs, PREF_GROUP_UI, "time.xmlconsole", val); + g_key_file_remove_key(prefs, PREF_GROUP_UI, "time", NULL); prefs_free_string(time); } @@ -600,7 +585,12 @@ _get_group(preference_t pref) case PREF_PRESENCE: case PREF_WRAP: case PREF_WINS_AUTO_TIDY: - case PREF_TIME: + case PREF_TIME_CONSOLE: + case PREF_TIME_CHAT: + case PREF_TIME_MUC: + case PREF_TIME_MUCCONFIG: + case PREF_TIME_PRIVATE: + case PREF_TIME_XMLCONSOLE: case PREF_TIME_STATUSBAR: case PREF_TIME_LASTACTIVITY: case PREF_ROSTER: @@ -753,8 +743,18 @@ _get_key(preference_t pref) return "wrap"; case PREF_WINS_AUTO_TIDY: return "wins.autotidy"; - case PREF_TIME: - return "time"; + case PREF_TIME_CONSOLE: + return "time.console"; + case PREF_TIME_CHAT: + return "time.chat"; + case PREF_TIME_MUC: + return "time.muc"; + case PREF_TIME_MUCCONFIG: + return "time.mucconfig"; + case PREF_TIME_PRIVATE: + return "time.private"; + case PREF_TIME_XMLCONSOLE: + return "time.xmlconsole"; case PREF_TIME_STATUSBAR: return "time.statusbar"; case PREF_TIME_LASTACTIVITY: @@ -844,7 +844,13 @@ _get_default_string(preference_t pref) return "all"; case PREF_ROSTER_BY: return "presence"; - case PREF_TIME: + case PREF_TIME_CONSOLE: + return "%H:%M:%S"; + case PREF_TIME_CHAT: + return "%H:%M:%S"; + case PREF_TIME_MUC: + return "%H:%M:%S"; + case PREF_TIME_XMLCONSOLE: return "%H:%M:%S"; case PREF_TIME_STATUSBAR: return "%H:%M"; diff --git a/src/config/preferences.h b/src/config/preferences.h index 875db253..770e379e 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -70,7 +70,12 @@ typedef enum { PREF_PRESENCE, PREF_WRAP, PREF_WINS_AUTO_TIDY, - PREF_TIME, + PREF_TIME_CONSOLE, + PREF_TIME_CHAT, + PREF_TIME_MUC, + PREF_TIME_MUCCONFIG, + PREF_TIME_PRIVATE, + PREF_TIME_XMLCONSOLE, PREF_TIME_STATUSBAR, PREF_TIME_LASTACTIVITY, PREF_STATUSES, diff --git a/src/config/theme.c b/src/config/theme.c index 588a3a42..e840fab5 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -432,7 +432,12 @@ _load_preferences(void) _set_boolean_preference("splash", PREF_SPLASH); _set_boolean_preference("wrap", PREF_WRAP); _set_boolean_preference("wins.autotidy", PREF_WINS_AUTO_TIDY); - _set_string_preference("time", PREF_TIME); + _set_string_preference("time.console", PREF_TIME_CONSOLE); + _set_string_preference("time.chat", PREF_TIME_CHAT); + _set_string_preference("time.muc", PREF_TIME_MUC); + _set_string_preference("time.mucconfig", PREF_TIME_MUCCONFIG); + _set_string_preference("time.private", PREF_TIME_PRIVATE); + _set_string_preference("time.xmlconsole", PREF_TIME_XMLCONSOLE); _set_string_preference("time.statusbar", PREF_TIME_STATUSBAR); _set_string_preference("time.lastactivity", PREF_TIME_LASTACTIVITY); diff --git a/src/ui/console.c b/src/ui/console.c index 1bbaac38..5445a503 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -997,12 +997,47 @@ cons_autoconnect_setting(void) void cons_time_setting(void) { - char *pref_time = prefs_get_string(PREF_TIME); - if (g_strcmp0(pref_time, "off") == 0) - cons_show("Time main (/time) : OFF"); + char *pref_time_console = prefs_get_string(PREF_TIME_CONSOLE); + if (g_strcmp0(pref_time_console, "off") == 0) + cons_show("Time console (/time) : OFF"); else - cons_show("Time main (/time) : %s", pref_time); - prefs_free_string(pref_time); + cons_show("Time console (/time) : %s", pref_time_console); + prefs_free_string(pref_time_console); + + char *pref_time_chat = prefs_get_string(PREF_TIME_CHAT); + if (g_strcmp0(pref_time_chat, "off") == 0) + cons_show("Time chat (/time) : OFF"); + else + cons_show("Time chat (/time) : %s", pref_time_chat); + prefs_free_string(pref_time_chat); + + char *pref_time_muc = prefs_get_string(PREF_TIME_MUC); + if (g_strcmp0(pref_time_muc, "off") == 0) + cons_show("Time MUC (/time) : OFF"); + else + cons_show("Time MUC (/time) : %s", pref_time_muc); + prefs_free_string(pref_time_muc); + + char *pref_time_mucconf = prefs_get_string(PREF_TIME_MUCCONFIG); + if (g_strcmp0(pref_time_mucconf, "off") == 0) + cons_show("Time MUC config (/time) : OFF"); + else + cons_show("Time MUC config (/time) : %s", pref_time_mucconf); + prefs_free_string(pref_time_mucconf); + + char *pref_time_private = prefs_get_string(PREF_TIME_PRIVATE); + if (g_strcmp0(pref_time_private, "off") == 0) + cons_show("Time private (/time) : OFF"); + else + cons_show("Time private (/time) : %s", pref_time_private); + prefs_free_string(pref_time_private); + + char *pref_time_xml = prefs_get_string(PREF_TIME_XMLCONSOLE); + if (g_strcmp0(pref_time_xml, "off") == 0) + cons_show("Time XML Console (/time) : OFF"); + else + cons_show("Time XML Console (/time) : %s", pref_time_xml); + prefs_free_string(pref_time_xml); char *pref_time_statusbar = prefs_get_string(PREF_TIME_STATUSBAR); if (g_strcmp0(pref_time_statusbar, "off") == 0) diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index 5541f648..47aa1b1a 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -129,11 +129,17 @@ status_bar_resize(void) if (message) { char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR); - gchar *date_fmt = g_date_time_format(last_time, time_pref); + + gchar *date_fmt = NULL; + if (g_strcmp0(time_pref, "off") == 0) { + date_fmt = g_strdup(""); + } else { + date_fmt = g_date_time_format(last_time, time_pref); + } assert(date_fmt != NULL); size_t len = strlen(date_fmt); g_free(date_fmt); - if (g_strcmp0(time_pref, "") != 0) { + if (g_strcmp0(time_pref, "off") != 0) { /* 01234567890123456 * [HH:MM] message */ mvwprintw(status_bar, 0, 5 + len, message); @@ -308,11 +314,17 @@ status_bar_print_message(const char * const msg) message = strdup(msg); char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR); - gchar *date_fmt = g_date_time_format(last_time, time_pref); + gchar *date_fmt = NULL; + if (g_strcmp0(time_pref, "off") == 0) { + date_fmt = g_strdup(""); + } else { + date_fmt = g_date_time_format(last_time, time_pref); + } + assert(date_fmt != NULL); size_t len = strlen(date_fmt); g_free(date_fmt); - if (g_strcmp0(time_pref, "") != 0) { + if (g_strcmp0(time_pref, "off") != 0) { mvwprintw(status_bar, 0, 5 + len, message); } else { mvwprintw(status_bar, 0, 1, message); @@ -444,7 +456,7 @@ _status_bar_draw(void) int bracket_attrs = theme_attrs(THEME_STATUS_BRACKET); char *time_pref = prefs_get_string(PREF_TIME_STATUSBAR); - if (g_strcmp0(time_pref, "") != 0) { + if (g_strcmp0(time_pref, "off") != 0) { gchar *date_fmt = g_date_time_format(last_time, time_pref); assert(date_fmt != NULL); size_t len = strlen(date_fmt); diff --git a/src/ui/window.c b/src/ui/window.c index 5a2196f2..8579b02f 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -982,9 +982,34 @@ _win_print(ProfWin *window, const char show_char, int pad_indent, GDateTime *tim int colour = theme_attrs(THEME_ME); size_t indent = 0; + char *time_pref = NULL; + switch (window->type) { + case WIN_CHAT: + time_pref = prefs_get_string(PREF_TIME_CHAT); + break; + case WIN_MUC: + time_pref = prefs_get_string(PREF_TIME_MUC); + break; + case WIN_MUC_CONFIG: + time_pref = prefs_get_string(PREF_TIME_MUCCONFIG); + break; + case WIN_PRIVATE: + time_pref = prefs_get_string(PREF_TIME_PRIVATE); + break; + case WIN_XML: + time_pref = prefs_get_string(PREF_TIME_XMLCONSOLE); + break; + default: + time_pref = prefs_get_string(PREF_TIME_CONSOLE); + break; + } + gchar *date_fmt = NULL; - char *time_pref = prefs_get_string(PREF_TIME); - date_fmt = g_date_time_format(time, time_pref); + if (g_strcmp0(time_pref, "off") == 0) { + date_fmt = g_strdup(""); + } else { + date_fmt = g_date_time_format(time, time_pref); + } prefs_free_string(time_pref); assert(date_fmt != NULL); diff --git a/tests/functionaltests/proftest.c b/tests/functionaltests/proftest.c index 1837505a..c12481d6 100644 --- a/tests/functionaltests/proftest.c +++ b/tests/functionaltests/proftest.c @@ -185,9 +185,19 @@ init_prof_test(void **state) assert_true(prof_output_exact("Word wrap disabled")); prof_input("/roster hide"); assert_true(prof_output_exact("Roster disabled")); - prof_input("/time main off"); - prof_input("/time main off"); - assert_true(prof_output_exact("Time display disabled")); + prof_input("/time console off"); + prof_input("/time console off"); + assert_true(prof_output_exact("Console time display disabled.")); + prof_input("/time chat off"); + assert_true(prof_output_exact("Chat time display disabled.")); + prof_input("/time muc off"); + assert_true(prof_output_exact("MUC time display disabled.")); + prof_input("/time mucconfig off"); + assert_true(prof_output_exact("MUC config time display disabled.")); + prof_input("/time private off"); + assert_true(prof_output_exact("Private chat time display disabled.")); + prof_input("/time xml off"); + assert_true(prof_output_exact("XML Console time display disabled.")); } void