diff options
Diffstat (limited to 'src/command')
-rw-r--r-- | src/command/cmd_ac.c | 43 | ||||
-rw-r--r-- | src/command/cmd_defs.c | 14 | ||||
-rw-r--r-- | src/command/cmd_funcs.c | 87 |
3 files changed, 72 insertions, 72 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index deda8abe..48d712e4 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -125,7 +125,7 @@ static char* _logging_autocomplete(ProfWin* window, const char* const input, gbo 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* _correct_autocomplete(ProfWin* window, const char* const input, gboolean previous); +static gchar* _correct_autocomplete(ProfWin* window, const char* const input, gboolean previous); static char* _software_autocomplete(ProfWin* window, const char* const input, gboolean previous); static char* _url_autocomplete(ProfWin* window, const char* const input, gboolean previous); static char* _executable_autocomplete(ProfWin* window, const char* const input, gboolean previous); @@ -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; @@ -1115,6 +1116,11 @@ 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"); + + 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"); @@ -1701,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); @@ -1888,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); @@ -4291,17 +4299,15 @@ _avatar_autocomplete(ProfWin* window, const char* const input, gboolean previous 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); + char* result = autocomplete_param_with_ac(input, "/correction", correction_ac, TRUE, previous); return result; } -static char* +static gchar* _correct_autocomplete(ProfWin* window, const char* const input, gboolean previous) { - char* result = g_strdup_printf("/correct %s", win_get_last_sent_message(window)); + gchar* result = g_strdup_printf("/correct %s", win_get_last_sent_message(window)); return result; } @@ -4381,6 +4387,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; diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 3b9fccfd..e8a97398 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2438,7 +2438,7 @@ static const struct cmd_t command_defs[] = { { "set <path>", "Set avatar to the image at <path>." }, { "disable", "Disable avatar publishing; your avatar will not display to others." }, { "get <barejid>", "Download the avatar. barejid is the JID to download avatar from." }, - { "open <barejid>", "Download avatar and open it with command." }) + { "open <barejid>", "Download avatar and open it with command. See /executable." }) CMD_EXAMPLES( "/avatar set ~/images/avatar.png", "/avatar disable", @@ -2535,23 +2535,27 @@ static const struct cmd_t command_defs[] = { CMD_TAGS( CMD_TAG_DISCOVERY) CMD_SYN( - "/executable avatar <cmd>", + "/executable avatar set <cmdtemplate>", + "/executable avatar default", "/executable urlopen set <cmdtemplate>", "/executable urlopen default", "/executable urlsave set <cmdtemplate>", "/executable urlsave default", "/executable editor set <cmdtemplate>", + "/executable editor default", "/executable vcard_photo set <cmdtemplate>", "/executable vcard_photo default") 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." }, { "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( @@ -2578,10 +2582,10 @@ static const struct cmd_t command_defs[] = { "/url open <url>", "/url save <url> [<path>]") CMD_DESC( - "Deal with URLs") + "Open or save URLs. This works with OMEMO encrypted files as well.") CMD_ARGS( { "open", "Open URL with predefined executable." }, - { "save", "Save URL to optional path, default path is current directory" }) + { "save", "Save URL to optional path, default path is current directory." }) CMD_EXAMPLES( "/url open https://profanity-im.github.io", "/url save https://profanity-im.github.io/guide/latest/userguide.html /home/user/Download/") diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 70546a0b..e5ff8116 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -6578,7 +6578,8 @@ cmd_reconnect(ProfWin* window, const char* const command, gchar** args) int intval = 0; char* err_msg = NULL; if (g_strcmp0(value, "now") == 0) { - session_reconnect_now(); + cons_show("Reconnecting now."); + cl_ev_reconnect(); } else if (strtoi_range(value, &intval, 0, INT_MAX, &err_msg)) { prefs_set_reconnect(intval); if (intval == 0) { @@ -9343,9 +9344,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); } @@ -9645,15 +9643,7 @@ cmd_url_save(ProfWin* window, const char* const command, gchar** args) } 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) { @@ -9663,14 +9653,17 @@ 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); + if (def == NULL) { + def = g_strdup("built-in method"); + } + cons_show("`%s` command set to invoke %s (default)", command, def); g_free(def); } else { cons_bad_cmd_usage(command); @@ -9680,63 +9673,35 @@ cmd_executable_urlopen(ProfWin* window, const char* const command, gchar** args) } gboolean -cmd_executable_urlsave(ProfWin* window, const char* const command, gchar** args) +cmd_executable_avatar(ProfWin* window, const char* const command, gchar** args) { + return _cmd_executable_template(PREF_AVATAR_CMD, args[0], 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); - } +gboolean +cmd_executable_urlopen(ProfWin* window, const char* const command, gchar** args) +{ + return _cmd_executable_template(PREF_URL_OPEN_CMD, args[0], args); +} - return TRUE; +gboolean +cmd_executable_urlsave(ProfWin* window, const char* const command, gchar** args) +{ + 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 { - 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) { |