From daf3d193e226648a2b3f0021731ec006956727e5 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Tue, 9 May 2023 19:31:35 +0200 Subject: [PATCH 1/6] Remove parsing of /avatar cmd This is done in `/executable avatar set` since d7848e38b. The command help also didn't mention this anymore. Seems like it was forgotten to remove the actual parsing of this. --- src/command/cmd_funcs.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 6e9ca259..b0e287f2 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -9309,9 +9309,6 @@ cmd_avatar(ProfWin* window, const char* const command, gchar** args) avatar_get_by_nick(args[1], false); } else if (g_strcmp0(args[0], "open") == 0) { avatar_get_by_nick(args[1], true); - } else if (g_strcmp0(args[0], "cmd") == 0) { - prefs_set_string(PREF_AVATAR_CMD, args[1]); - cons_show("Avatar cmd set to: %s", args[1]); } else { cons_bad_cmd_usage(command); } From 8075b32ebc6311d7985e94c780fafecc4e8def9f Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Tue, 9 May 2023 19:58:21 +0200 Subject: [PATCH 2/6] Align avatar behaviour with urlopen `/executable avatar` now also uses cmdtemplate and parse %p. It seems to me that the `/avatar` command was actually completely broken on master. --- src/command/cmd_defs.c | 8 +++++--- src/command/cmd_funcs.c | 33 ++++++++++++++++++--------------- src/config/preferences.c | 2 +- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index c6e886a5..ceb84d05 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2437,7 +2437,7 @@ static const struct cmd_t command_defs[] = { { "set ", "Set avatar to the image at ." }, { "disable", "Disable avatar publishing; your avatar will not display to others." }, { "get ", "Download the avatar. barejid is the JID to download avatar from." }, - { "open ", "Download avatar and open it with command." }) + { "open ", "Download avatar and open it with command. See /executable." }) CMD_EXAMPLES( "/avatar set ~/images/avatar.png", "/avatar disable", @@ -2534,7 +2534,8 @@ static const struct cmd_t command_defs[] = { CMD_TAGS( CMD_TAG_DISCOVERY) CMD_SYN( - "/executable avatar ", + "/executable avatar set ", + "/executable avatar default", "/executable urlopen set ", "/executable urlopen default", "/executable urlsave set ", @@ -2545,7 +2546,8 @@ static const struct cmd_t command_defs[] = { CMD_DESC( "Configure executable that should be called upon a certain command.") CMD_ARGS( - { "avatar", "Set executable that is run by /avatar open. Use your favorite image viewer." }, + { "avatar set", "Set executable that is run by /avatar open. Use your favorite image viewer." }, + { "avatar default", "Restore to default settings." }, { "urlopen set", "Set executable that is run by /url open. Takes a command template that replaces %u and %p with the URL and path respectively." }, { "urlopen default", "Restore to default settings." }, { "urlsave set", "Set executable that is run by /url save. Takes a command template that replaces %u and %p with the URL and path respectively." }, diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index b0e287f2..e18498c6 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -9617,15 +9617,7 @@ out: } gboolean -cmd_executable_avatar(ProfWin* window, const char* const command, gchar** args) -{ - prefs_set_string(PREF_AVATAR_CMD, args[1]); - cons_show("`avatar` command set to invoke '%s'", args[1]); - return TRUE; -} - -gboolean -cmd_executable_urlopen(ProfWin* window, const char* const command, gchar** args) +_cmd_executable_template(const preference_t setting, const char* command, gchar** args) { guint num_args = g_strv_length(args); if (num_args < 2) { @@ -9635,14 +9627,14 @@ cmd_executable_urlopen(ProfWin* window, const char* const command, gchar** args) if (g_strcmp0(args[1], "set") == 0 && num_args >= 3) { gchar* str = g_strjoinv(" ", &args[2]); - prefs_set_string(PREF_URL_OPEN_CMD, str); - cons_show("`url open` command set to invoke '%s'", str); + prefs_set_string(setting, str); + cons_show("`%s` command set to invoke '%s'", command, str); g_free(str); } else if (g_strcmp0(args[1], "default") == 0) { - prefs_set_string(PREF_URL_OPEN_CMD, NULL); - gchar* def = prefs_get_string(PREF_URL_OPEN_CMD); - cons_show("`url open` command set to invoke %s (default)", def); + prefs_set_string(setting, NULL); + gchar* def = prefs_get_string(setting); + cons_show("`%s` command set to invoke %s (default)", command, def); g_free(def); } else { cons_bad_cmd_usage(command); @@ -9651,10 +9643,21 @@ cmd_executable_urlopen(ProfWin* window, const char* const command, gchar** args) return TRUE; } +gboolean +cmd_executable_avatar(ProfWin* window, const char* const command, gchar** args) +{ + return _cmd_executable_template(PREF_AVATAR_CMD, args[0], args); +} + +gboolean +cmd_executable_urlopen(ProfWin* window, const char* const command, gchar** args) +{ + return _cmd_executable_template(PREF_URL_OPEN_CMD, args[0], args); +} + gboolean cmd_executable_urlsave(ProfWin* window, const char* const command, gchar** args) { - guint num_args = g_strv_length(args); if (num_args < 2) { cons_bad_cmd_usage(command); diff --git a/src/config/preferences.c b/src/config/preferences.c index 2d975e39..f1b4154e 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -2314,7 +2314,7 @@ _get_default_string(preference_t pref) case PREF_COLOR_NICK: return "false"; case PREF_AVATAR_CMD: - return "xdg-open"; + return "xdg-open %p"; case PREF_URL_OPEN_CMD: return "xdg-open %u"; case PREF_VCARD_PHOTO_CMD: From a7159c5954c71efcf750c76f8861f19821d5e9b8 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Tue, 9 May 2023 20:00:05 +0200 Subject: [PATCH 3/6] Add vcard_photo to /executable autocompletion Was forgotten in f934c5b59. --- src/command/cmd_ac.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index deda8abe..17d08888 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -1115,6 +1115,7 @@ cmd_ac_init(void) autocomplete_add(executable_ac, "urlopen"); autocomplete_add(executable_ac, "urlsave"); autocomplete_add(executable_ac, "editor"); + autocomplete_add(executable_ac, "vcard_photo"); intype_ac = autocomplete_new(); autocomplete_add(intype_ac, "console"); From 46c90bc68138ca0268ef2562e4f8c9917daf257f Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Tue, 9 May 2023 20:04:31 +0200 Subject: [PATCH 4/6] Make it possible to reset editor to default All the other commands (avatar, vcard_photo, urlsave, urlopen) have the ability to reset to default already. --- src/command/cmd_defs.c | 2 ++ src/command/cmd_funcs.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index ceb84d05..9828ab1a 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2541,6 +2541,7 @@ static const struct cmd_t command_defs[] = { "/executable urlsave set ", "/executable urlsave default", "/executable editor set ", + "/executable editor default", "/executable vcard_photo set ", "/executable vcard_photo default") CMD_DESC( @@ -2553,6 +2554,7 @@ static const struct cmd_t command_defs[] = { { "urlsave set", "Set executable that is run by /url save. Takes a command template that replaces %u and %p with the URL and path respectively." }, { "urlsave default", "Use the built-in download method for saving." }, { "editor set", "Set editor to be used with /editor. Needs a terminal editor or a script to run a graphical editor." }, + { "editor default", "Restore to default settings." }, { "vcard_photo set", "Set executable that is run by /vcard photo open. Takes a command template that replaces %p with the path" }, { "vcard_photo default", "Restore to default settings." }) CMD_EXAMPLES( diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index e18498c6..3c982213 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -9688,6 +9688,9 @@ cmd_executable_editor(ProfWin* window, const char* const command, gchar** args) if (g_strcmp0(args[1], "set") == 0 && num_args >= 3) { prefs_set_string(PREF_COMPOSE_EDITOR, args[2]); cons_show("`editor` command set to invoke '%s'", args[2]); + } else if (g_strcmp0(args[1], "default") == 0) { + prefs_set_string(PREF_COMPOSE_EDITOR, NULL); + cons_show("`editor` will use built-in download method (default)"); } else { cons_bad_cmd_usage(command); } From 79efe56d64fb639f96f3ed3e421b9bb7ee37957e Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Tue, 9 May 2023 20:10:55 +0200 Subject: [PATCH 5/6] Add autocompletion for /executable parameters We autocompleted `/executable` to `avatar`, `vcard_photo`, `editor` etc. But didn't autocomplete the next parameter. Namely `set` and `default`. --- src/command/cmd_ac.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 17d08888..d93633c3 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -277,6 +277,7 @@ static Autocomplete correction_ac; static Autocomplete avatar_ac; static Autocomplete url_ac; static Autocomplete executable_ac; +static Autocomplete executable_param_ac; static Autocomplete intype_ac; static Autocomplete mood_ac; static Autocomplete mood_type_ac; @@ -1117,6 +1118,10 @@ cmd_ac_init(void) autocomplete_add(executable_ac, "editor"); autocomplete_add(executable_ac, "vcard_photo"); + executable_param_ac = autocomplete_new(); + autocomplete_add(executable_param_ac, "set"); + autocomplete_add(executable_param_ac, "default"); + intype_ac = autocomplete_new(); autocomplete_add(intype_ac, "console"); autocomplete_add(intype_ac, "titlebar"); @@ -1702,6 +1707,7 @@ cmd_ac_reset(ProfWin* window) autocomplete_reset(avatar_ac); autocomplete_reset(url_ac); autocomplete_reset(executable_ac); + autocomplete_reset(executable_param_ac); autocomplete_reset(intype_ac); autocomplete_reset(mood_ac); autocomplete_reset(mood_type_ac); @@ -1889,6 +1895,7 @@ cmd_ac_uninit(void) autocomplete_free(avatar_ac); autocomplete_free(url_ac); autocomplete_free(executable_ac); + autocomplete_free(executable_param_ac); autocomplete_free(intype_ac); autocomplete_free(adhoc_cmd_ac); autocomplete_free(lastactivity_ac); @@ -4382,6 +4389,31 @@ _executable_autocomplete(ProfWin* window, const char* const input, gboolean prev { char* result = NULL; + result = autocomplete_param_with_ac(input, "/executable avatar", executable_param_ac, TRUE, previous); + if (result) { + return result; + } + + result = autocomplete_param_with_ac(input, "/executable urlopen", executable_param_ac, TRUE, previous); + if (result) { + return result; + } + + result = autocomplete_param_with_ac(input, "/executable urlsave", executable_param_ac, TRUE, previous); + if (result) { + return result; + } + + result = autocomplete_param_with_ac(input, "/executable vcard_photo", executable_param_ac, TRUE, previous); + if (result) { + return result; + } + + result = autocomplete_param_with_ac(input, "/executable editor", executable_param_ac, TRUE, previous); + if (result) { + return result; + } + result = autocomplete_param_with_ac(input, "/executable", executable_ac, TRUE, previous); return result; From 60c197487daee968d504a5f73fac391b6a6c6971 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Wed, 10 May 2023 09:41:59 +0200 Subject: [PATCH 6/6] Add helper function for individual cmd_executable_*() functions Each of the cmd_executable_editor(), cmd_executable_urlopen() etc calls this helper function since they were all doing the same just for different configurations. --- src/command/cmd_funcs.c | 53 ++++++----------------------------------- 1 file changed, 7 insertions(+), 46 deletions(-) diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 3c982213..ccba8827 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -9634,6 +9634,9 @@ _cmd_executable_template(const preference_t setting, const char* command, gchar* } else if (g_strcmp0(args[1], "default") == 0) { prefs_set_string(setting, NULL); gchar* def = prefs_get_string(setting); + if (def == NULL) { + def = g_strdup("built-in method"); + } cons_show("`%s` command set to invoke %s (default)", command, def); g_free(def); } else { @@ -9658,63 +9661,21 @@ cmd_executable_urlopen(ProfWin* window, const char* const command, gchar** args) gboolean cmd_executable_urlsave(ProfWin* window, const char* const command, gchar** args) { - guint num_args = g_strv_length(args); - if (num_args < 2) { - cons_bad_cmd_usage(command); - return TRUE; - } - - if (g_strcmp0(args[1], "set") == 0 && num_args >= 3) { - gchar* str = g_strjoinv(" ", &args[2]); - prefs_set_string(PREF_URL_SAVE_CMD, str); - cons_show("`url save` command set to invoke '%s'", str); - g_free(str); - - } else if (g_strcmp0(args[1], "default") == 0) { - prefs_set_string(PREF_URL_SAVE_CMD, NULL); - cons_show("`url save` will use built-in download method (default)"); - } else { - cons_bad_cmd_usage(command); - } - - return TRUE; + return _cmd_executable_template(PREF_URL_SAVE_CMD, args[0], args); } gboolean cmd_executable_editor(ProfWin* window, const char* const command, gchar** args) { - guint num_args = g_strv_length(args); - - if (g_strcmp0(args[1], "set") == 0 && num_args >= 3) { - prefs_set_string(PREF_COMPOSE_EDITOR, args[2]); - cons_show("`editor` command set to invoke '%s'", args[2]); - } else if (g_strcmp0(args[1], "default") == 0) { - prefs_set_string(PREF_COMPOSE_EDITOR, NULL); - cons_show("`editor` will use built-in download method (default)"); - } else { - cons_bad_cmd_usage(command); - } - - return TRUE; + return _cmd_executable_template(PREF_COMPOSE_EDITOR, args[0], args); } gboolean cmd_executable_vcard_photo(ProfWin* window, const char* const command, gchar** args) { - if (g_strcmp0(args[1], "set") == 0 && args[2] != NULL) { - prefs_set_string(PREF_VCARD_PHOTO_CMD, args[2]); - cons_show("`vcard photo open` command set to invoke '%s'", args[2]); - } else if (g_strcmp0(args[1], "default") == 0) { - prefs_set_string(PREF_VCARD_PHOTO_CMD, NULL); - char* cmd = prefs_get_string(PREF_VCARD_PHOTO_CMD); - cons_show("`vcard photo open` command set to invoke '%s' (default)", cmd); - g_free(cmd); - } else { - cons_bad_cmd_usage(command); - } - - return TRUE; + return _cmd_executable_template(PREF_VCARD_PHOTO_CMD, args[0], args); } + gboolean cmd_mam(ProfWin* window, const char* const command, gchar** args) {