From 039bf5d04de6d388379d5cca300f00b1022d068e Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Mon, 10 Feb 2020 13:35:46 +0100 Subject: [PATCH] xep-0308: add `correction` autocompletion --- src/command/cmd_ac.c | 23 +++++++++++++++++++++++ src/command/cmd_defs.c | 18 ++++++++++++++++++ src/ui/console.c | 6 ++++++ src/ui/ui.h | 1 + 4 files changed, 48 insertions(+) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 5b61da6a..0b411bcb 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -113,6 +113,7 @@ static char* _status_autocomplete(ProfWin *window, const char *const input, gboo static char* _logging_autocomplete(ProfWin *window, const char *const input, gboolean previous); static char* _color_autocomplete(ProfWin *window, const char *const input, gboolean previous); static char* _avatar_autocomplete(ProfWin *window, const char *const input, gboolean previous); +static char* _correction_autocomplete(ProfWin *window, const char *const input, gboolean previous); static char* _script_autocomplete_func(const char *const prefix, gboolean previous, void *context); @@ -234,6 +235,7 @@ static Autocomplete status_ac; static Autocomplete status_state_ac; static Autocomplete logging_ac; static Autocomplete color_ac; +static Autocomplete correction_ac; void cmd_ac_init(void) @@ -928,6 +930,11 @@ cmd_ac_init(void) autocomplete_add(color_ac, "off"); autocomplete_add(color_ac, "redgreen"); autocomplete_add(color_ac, "blue"); + + correction_ac = autocomplete_new(); + autocomplete_add(correction_ac, "on"); + autocomplete_add(correction_ac, "off"); + autocomplete_add(correction_ac, "char"); } void @@ -1233,6 +1240,7 @@ cmd_ac_reset(ProfWin *window) autocomplete_reset(status_state_ac); autocomplete_reset(logging_ac); autocomplete_reset(color_ac); + autocomplete_reset(correction_ac); autocomplete_reset(script_ac); if (script_show_ac) { @@ -1380,6 +1388,7 @@ cmd_ac_uninit(void) autocomplete_free(status_state_ac); autocomplete_free(logging_ac); autocomplete_free(color_ac); + autocomplete_free(correction_ac); } static void @@ -1630,6 +1639,7 @@ _cmd_ac_complete_params(ProfWin *window, const char *const input, gboolean previ g_hash_table_insert(ac_funcs, "/logging", _logging_autocomplete); g_hash_table_insert(ac_funcs, "/color", _color_autocomplete); g_hash_table_insert(ac_funcs, "/avatar", _avatar_autocomplete); + g_hash_table_insert(ac_funcs, "/correction", _correction_autocomplete); int len = strlen(input); char parsed[len+1]; @@ -3713,3 +3723,16 @@ _avatar_autocomplete(ProfWin *window, const char *const input, gboolean previous return NULL; } + +static char* +_correction_autocomplete(ProfWin *window, const char *const input, gboolean previous) +{ + char *result = NULL; + + result = autocomplete_param_with_ac(input, "/correction", correction_ac, TRUE, previous); + if (result) { + return result; + } + + return NULL; +} diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index b583a06b..30e11990 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2361,6 +2361,24 @@ static struct cmd_t command_defs[] = { "on|off", ""}) CMD_NOEXAMPLES }, + + { "/correction", + parse_args, 1, 1, &cons_correction_setting, + CMD_NOSUBFUNCS + CMD_MAINFUNC(cmd_os) + CMD_TAGS( + CMD_TAG_CHAT, + CMD_TAG_GROUPCHAT) + CMD_SYN( + "/correction |", + "/correction char ") + CMD_DESC( + "Settings regarding Last Message Correction (XEP-0308).") + CMD_ARGS( + { "on|off", "Enable/Disable support for last message correction."}, + { "char", "Set character that will prefix corrected messages. Default: +"}) + CMD_NOEXAMPLES + }, }; static GHashTable *search_index; diff --git a/src/ui/console.c b/src/ui/console.c index 1a716a7a..57a04290 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -2021,6 +2021,12 @@ cons_os_setting(void) } } +void +cons_correction_setting(void) +{ + cons_show("TODO"); +} + void cons_show_connection_prefs(void) { diff --git a/src/ui/ui.h b/src/ui/ui.h index 4783131e..e8d42410 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -319,6 +319,7 @@ void cons_statusbar_setting(void); void cons_winpos_setting(void); void cons_color_setting(void); void cons_os_setting(void); +void cons_correction_setting(void); void cons_show_contact_online(PContact contact, Resource *resource, GDateTime *last_activity); void cons_show_contact_offline(PContact contact, char *resource, char *status); void cons_theme_properties(void);