From c2d70a071fb107a98f9b057eab4e5021f0eb7187 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Mon, 10 Feb 2020 13:48:31 +0100 Subject: [PATCH] xep-0308: set correction char in config --- src/command/cmd_defs.c | 2 +- src/command/cmd_funcs.c | 27 +++++++++++++++++++++++++++ src/command/cmd_funcs.h | 1 + src/config/preferences.c | 26 ++++++++++++++++++++++++++ src/config/preferences.h | 3 +++ 5 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 30e11990..1563bf73 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2365,7 +2365,7 @@ static struct cmd_t command_defs[] = { "/correction", parse_args, 1, 1, &cons_correction_setting, CMD_NOSUBFUNCS - CMD_MAINFUNC(cmd_os) + CMD_MAINFUNC(cmd_correction) CMD_TAGS( CMD_TAG_CHAT, CMD_TAG_GROUPCHAT) diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 930004b3..1870429d 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -8651,3 +8651,30 @@ cmd_os(ProfWin *window, const char *const command, gchar **args) return TRUE; } + +gboolean +cmd_correction(ProfWin *window, const char *const command, gchar **args) +{ + // enable/disable + if (g_strcmp0(args[0], "on") == 0) { + prefs_set_boolean(PREF_BOOKMARK_INVITE, TRUE); + return TRUE; + } else if (g_strcmp0(args[0], "off") == 0) { + prefs_set_boolean(PREF_BOOKMARK_INVITE, FALSE); + return TRUE; + } + + // char + if (g_strcmp(args[0], "char") == 0) { + if (args[1] == NULL) { + cons_bad_cmd_usage(command); + } else if (strlen(args[1]) != 1) { + cons_bad_cmd_usage(command); + } else { + prefs_set_correction_char(args[1][0]); + cons_show("LMC char set to %c.", args[1][0]); + } + } + + return TRUE; +} diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h index a743951f..a2ccd000 100644 --- a/src/command/cmd_funcs.h +++ b/src/command/cmd_funcs.h @@ -227,4 +227,5 @@ gboolean cmd_paste(ProfWin *window, const char *const command, gchar **args); gboolean cmd_color(ProfWin *window, const char *const command, gchar **args); gboolean cmd_avatar(ProfWin *window, const char *const command, gchar **args); gboolean cmd_os(ProfWin *window, const char *const command, gchar **args); +gboolean cmd_correction(ProfWin *window, const char *const command, gchar **args); #endif diff --git a/src/config/preferences.c b/src/config/preferences.c index 6cc2bb56..d817f907 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -1201,6 +1201,32 @@ prefs_set_roster_presence_indent(gint value) g_key_file_set_integer(prefs, PREF_GROUP_UI, "roster.presence.indent", value); } +char +prefs_get_correction_char(void) +{ + char result = '+'; + + char *resultstr = g_key_file_get_string(prefs, PREF_GROUP_UI, "correction.char", NULL); + if (!resultstr) { + result = '+'; + } else { + result = resultstr[0]; + } + free(resultstr); + + return result; +} + +void +prefs_set_correction_char(char ch) +{ + char str[2]; + str[0] = ch; + str[1] = '\0'; + + g_key_file_set_string(prefs, PREF_GROUP_UI, "correction.char", str); +} + gboolean prefs_add_room_notify_trigger(const char * const text) { diff --git a/src/config/preferences.h b/src/config/preferences.h index e11eec46..2a30f655 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -268,6 +268,9 @@ void prefs_set_roster_presence_indent(gint value); gint prefs_get_occupants_indent(void); void prefs_set_occupants_indent(gint value); +char prefs_get_correction_char(void); +void prefs_set_correction_char(char ch); + void prefs_add_login(const char *jid); void prefs_set_tray_timer(gint value);