1
0
mirror of https://github.com/Tha14/toxic.git synced 2025-07-01 06:16:44 +02:00

Add support for custom timestamps in chat and logs.

Internal representations of the time_format setting are replaced by timestamp format strings.
time_format is only used in the setup.

Signed-off-by: Loui Chang <louipc.ist@gmail.com>
This commit is contained in:
Loui Chang
2015-02-19 18:20:38 -05:00
parent d6c57c7aa3
commit 53e4b2c971
10 changed files with 77 additions and 30 deletions

View File

@ -47,10 +47,12 @@
static struct ui_strings {
const char* self;
const char* timestamps;
const char* time_format;
const char* timestamp_format;
const char* log_timestamp_format;
const char* alerts;
const char* native_colors;
const char* autolog;
const char* time_format;
const char* history_size;
const char* show_typing_self;
const char* show_typing_other;
@ -63,10 +65,12 @@ static struct ui_strings {
} ui_strings = {
"ui",
"timestamps",
"time_format",
"timestamp_format",
"log_timestamp_format",
"alerts",
"native_colors",
"autolog",
"time_format",
"history_size",
"show_typing_self",
"show_typing_other",
@ -80,7 +84,9 @@ static struct ui_strings {
static void ui_defaults(struct user_settings* settings)
{
settings->timestamps = TIMESTAMPS_ON;
settings->time = TIME_24;
snprintf(settings->timestamp_format, sizeof(settings->timestamp_format), "%s", TIMESTAMP_DEFAULT);
snprintf(settings->log_timestamp_format, sizeof(settings->log_timestamp_format), "%s", LOG_TIMESTAMP_DEFAULT);
settings->autolog = AUTOLOG_OFF;
settings->alerts = ALERTS_ENABLED;
settings->colour_theme = DFLT_COLS;
@ -267,6 +273,23 @@ int settings_load(struct user_settings *s, const char *patharg)
/* ui */
if ((setting = config_lookup(cfg, ui_strings.self)) != NULL) {
config_setting_lookup_bool(setting, ui_strings.timestamps, &s->timestamps);
int time = 24;
if ( config_setting_lookup_int(setting, ui_strings.time_format, &time) ) {
if (time == 12) {
snprintf(s->timestamp_format, sizeof(s->timestamp_format), "%s", "%I:%M:%S %p");
snprintf(s->log_timestamp_format, sizeof(s->log_timestamp_format), "%s", "%Y/%m/%d [%I:%M:%S %p]");
}
}
if ( config_setting_lookup_string(setting, ui_strings.timestamp_format, &str) ) {
snprintf(s->timestamp_format, sizeof(s->timestamp_format), "%s", str);
}
if ( config_setting_lookup_string(setting, ui_strings.log_timestamp_format, &str) ) {
snprintf(s->log_timestamp_format, sizeof(s->log_timestamp_format), "%s", str);
}
config_setting_lookup_bool(setting, ui_strings.alerts, &s->alerts);
config_setting_lookup_bool(setting, ui_strings.autolog, &s->autolog);
config_setting_lookup_bool(setting, ui_strings.native_colors, &s->colour_theme);
@ -274,8 +297,6 @@ int settings_load(struct user_settings *s, const char *patharg)
config_setting_lookup_bool(setting, ui_strings.show_typing_self, &s->show_typing_self);
config_setting_lookup_bool(setting, ui_strings.show_typing_other, &s->show_typing_other);
config_setting_lookup_bool(setting, ui_strings.show_welcome_msg, &s->show_welcome_msg);
config_setting_lookup_int(setting, ui_strings.time_format, &s->time);
s->time = s->time == TIME_24 || s->time == TIME_12 ? s->time : TIME_24; /* Check defaults */
if ( config_setting_lookup_string(setting, ui_strings.line_join, &str) ) {
snprintf(s->line_join, sizeof(s->line_join), "%s", str);