diff options
author | Michael Vetter <jubalh@iodoru.org> | 2020-03-10 07:12:13 +0100 |
---|---|---|
committer | Michael Vetter <jubalh@iodoru.org> | 2020-03-10 07:12:13 +0100 |
commit | 52e7e596aa0e7ca8b8db11c7c47c584fc7a75be6 (patch) | |
tree | d7020dffd72bd991f4ee73158db8fec763587ca6 /src/command | |
parent | 7e62d458ee22e9171bf5741cda5c8ce85b20bd6a (diff) | |
download | profani-tty-52e7e596aa0e7ca8b8db11c7c47c584fc7a75be6.tar.gz |
xep-0084/avatar: add option to open avatar directly
Change: `/avatar me@somewhere.org` -> `/avatar get me@somewhere.org` New: `/avatar cmd feh` `/avatar open me@somewhere.org` Implement https://github.com/profanity-im/profanity/issues/1281
Diffstat (limited to 'src/command')
-rw-r--r-- | src/command/cmd_ac.c | 20 | ||||
-rw-r--r-- | src/command/cmd_defs.c | 15 | ||||
-rw-r--r-- | src/command/cmd_funcs.c | 14 |
3 files changed, 43 insertions, 6 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index c80c058d..12331bfb 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -242,6 +242,7 @@ static Autocomplete logging_group_ac; static Autocomplete logging_group_color_ac; static Autocomplete color_ac; static Autocomplete correction_ac; +static Autocomplete avatar_ac; void cmd_ac_init(void) @@ -965,6 +966,11 @@ cmd_ac_init(void) autocomplete_add(correction_ac, "on"); autocomplete_add(correction_ac, "off"); autocomplete_add(correction_ac, "char"); + + avatar_ac = autocomplete_new(); + autocomplete_add(avatar_ac, "get"); + autocomplete_add(avatar_ac, "cmd"); + autocomplete_add(avatar_ac, "open"); } void @@ -1276,6 +1282,7 @@ cmd_ac_reset(ProfWin *window) autocomplete_reset(logging_group_color_ac); autocomplete_reset(color_ac); autocomplete_reset(correction_ac); + autocomplete_reset(avatar_ac); autocomplete_reset(script_ac); if (script_show_ac) { @@ -1429,6 +1436,7 @@ cmd_ac_uninit(void) autocomplete_free(logging_group_color_ac); autocomplete_free(color_ac); autocomplete_free(correction_ac); + autocomplete_free(avatar_ac); } static void @@ -3773,9 +3781,19 @@ _avatar_autocomplete(ProfWin *window, const char *const input, gboolean previous { char *result = NULL; + result = autocomplete_param_with_ac(input, "/avatar", avatar_ac, TRUE, previous); + if (result) { + return result; + } + jabber_conn_status_t conn_status = connection_get_status(); if (conn_status == JABBER_CONNECTED) { - result = autocomplete_param_with_func(input, "/avatar", roster_barejid_autocomplete, previous, NULL); + result = autocomplete_param_with_func(input, "/avatar get", roster_barejid_autocomplete, previous, NULL); + if (result) { + return result; + } + + result = autocomplete_param_with_func(input, "/avatar open", roster_barejid_autocomplete, previous, NULL); if (result) { return result; } diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 9c9340de..33a38703 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2343,20 +2343,27 @@ static struct cmd_t command_defs[] = }, { "/avatar", - parse_args, 1, 1, NULL, + parse_args, 2, 2, &cons_avatar_setting, CMD_NOSUBFUNCS CMD_MAINFUNC(cmd_avatar) CMD_TAGS( CMD_TAG_CHAT) CMD_SYN( - "/avatar <barejid>") + "/avatar get <barejid>", + "/avatar open <barejid>", + "/avatar cmd <command>") CMD_DESC( "Download avatar (XEP-0084) for a certain contact. " "If nothing happens after using this command the user either doesn't have an avatar set at all " "or doesn't use XEP-0084 to publish it.") CMD_ARGS( - { "<barejid>", "JID to download avatar from."}) - CMD_NOEXAMPLES + { "get <barejid>", "Download the avatar. barejid is the JID to download avatar from."}, + { "cmd <command>", "Set a command to execute with 'avatar open'. Use your favourite image viewer here."}, + { "open <barejid>", "Download avatar and open it with command."}) + CMD_EXAMPLES( + "/avatar get someone@contacts.org", + "/avatar cmd xdg-open", + "/avatar open someone@contacts.org") }, { "/os", diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 5395a53e..1776c72e 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -8733,7 +8733,19 @@ cmd_color(ProfWin *window, const char *const command, gchar **args) gboolean cmd_avatar(ProfWin *window, const char *const command, gchar **args) { - avatar_get_by_nick(args[0]); + if (args[1] == NULL) { + cons_bad_cmd_usage(command); + return TRUE; + } + + if (g_strcmp0(args[0], "get") == 0) { + 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]); + } return TRUE; } |