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
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user