From ddf6ada3d110ea2f20ffd69070bcc199c9426733 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Mon, 9 Dec 2019 16:12:54 +0100 Subject: [PATCH] Add initial support for XEP-0392 The last 3 commits added basic support. Thanks @aaptel! This commit adds basic settings interface to use it. See `/color on|off`. We still have to enable settings for color blindness. And maybe another setting to decide whether to color the occupantslist/roster with the same algo. Regards https://github.com/profanity-im/profanity/issues/1191 --- src/command/cmd_ac.c | 2 +- src/command/cmd_defs.c | 15 +++++++++++++++ src/command/cmd_funcs.c | 7 +++++++ src/command/cmd_funcs.h | 2 ++ src/ui/console.c | 9 +++++++++ src/ui/ui.h | 1 + 6 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index a5568d65..625afd99 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -1479,7 +1479,7 @@ _cmd_ac_complete_params(ProfWin *window, const char *const input, gboolean previ // autocomplete boolean settings gchar *boolean_choices[] = { "/beep", "/intype", "/states", "/outtype", "/flash", "/splash", - "/history", "/vercheck", "/privileges", "/wrap", "/carbons", "/lastactivity" }; + "/history", "/vercheck", "/privileges", "/wrap", "/carbons", "/lastactivity", "/color" }; for (i = 0; i < ARRAY_SIZE(boolean_choices); i++) { result = autocomplete_param_with_func(input, boolean_choices[i], prefs_autocomplete_boolean_choice, previous); diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 70832552..0ea47bca 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2294,6 +2294,21 @@ static struct cmd_t command_defs[] = CMD_NOARGS CMD_NOEXAMPLES }, + + { "/color", + parse_args, 1, 1, &cons_color_setting, + CMD_NOSUBFUNCS + CMD_MAINFUNC(cmd_color) + CMD_TAGS( + CMD_TAG_UI) + CMD_SYN( + "/color on|off") + CMD_DESC( + "Settings for consistent color generation for nicks (XEP-0392).") + CMD_ARGS( + { "on|off", "Enable or disable nick colorization for MUC nicks." }) + CMD_NOEXAMPLES + }, }; static GHashTable *search_index; diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index ccf5c62e..2b7894ad 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -8626,3 +8626,10 @@ cmd_paste(ProfWin *window, const char *const command, gchar **args) return TRUE; } + +gboolean +cmd_color(ProfWin *window, const char *const command, gchar **args) +{ + _cmd_set_boolean_preference(args[0], command, "Consistent color generation for nicks", PREF_COLOR_NICK); + return TRUE; +} diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h index aab6aca2..cd37192e 100644 --- a/src/command/cmd_funcs.h +++ b/src/command/cmd_funcs.h @@ -223,4 +223,6 @@ gboolean cmd_save(ProfWin *window, const char *const command, gchar **args); gboolean cmd_reload(ProfWin *window, const char *const command, gchar **args); gboolean cmd_paste(ProfWin *window, const char *const command, gchar **args); + +gboolean cmd_color(ProfWin *window, const char *const command, gchar **args); #endif diff --git a/src/ui/console.c b/src/ui/console.c index 9d20b5f2..3906da5c 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1968,6 +1968,15 @@ cons_autoping_setting(void) } } +void +cons_color_setting(void) +{ + if (prefs_get_boolean(PREF_COLOR_NICK)) + cons_show("Consistent color generation for nicks (/color) : ON"); + else + cons_show("Consistent color generation for nicks (/color) : OFF"); +} + void cons_show_connection_prefs(void) { diff --git a/src/ui/ui.h b/src/ui/ui.h index 21bb1e32..1d811e55 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -317,6 +317,7 @@ void cons_room_cache_setting(void); void cons_inpblock_setting(void); void cons_statusbar_setting(void); void cons_winpos_setting(void); +void cons_color_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);