Have proper autocompletion for /software in chat window
In console autocomplete from roster. In muc autocomplete from occupants lits. In 1:1 regular chat autocomplete from active resources of currently selected user (new). Also give a hint (/help resource) how to set the resource should a user choose that way. Fix https://github.com/profanity-im/profanity/issues/1337
This commit is contained in:
@@ -121,6 +121,7 @@ static char* _color_autocomplete(ProfWin *window, const char *const input, gbool
|
|||||||
static char* _avatar_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* _correction_autocomplete(ProfWin *window, const char *const input, gboolean previous);
|
||||||
static char* _correct_autocomplete(ProfWin *window, const char *const input, gboolean previous);
|
static char* _correct_autocomplete(ProfWin *window, const char *const input, gboolean previous);
|
||||||
|
static char* _software_autocomplete(ProfWin *window, const char *const input, gboolean previous);
|
||||||
|
|
||||||
static char* _script_autocomplete_func(const char *const prefix, gboolean previous, void *context);
|
static char* _script_autocomplete_func(const char *const prefix, gboolean previous, void *context);
|
||||||
|
|
||||||
@@ -1613,7 +1614,7 @@ _cmd_ac_complete_params(ProfWin *window, const char *const input, gboolean previ
|
|||||||
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
||||||
Autocomplete nick_ac = muc_roster_ac(mucwin->roomjid);
|
Autocomplete nick_ac = muc_roster_ac(mucwin->roomjid);
|
||||||
if (nick_ac) {
|
if (nick_ac) {
|
||||||
gchar *nick_choices[] = { "/msg", "/info", "/caps", "/software" } ;
|
gchar *nick_choices[] = { "/msg", "/info", "/caps" } ;
|
||||||
|
|
||||||
// Remove quote character before and after names when doing autocomplete
|
// Remove quote character before and after names when doing autocomplete
|
||||||
char *unquoted = strip_arg_quotes(input);
|
char *unquoted = strip_arg_quotes(input);
|
||||||
@@ -1641,7 +1642,7 @@ _cmd_ac_complete_params(ProfWin *window, const char *const input, gboolean previ
|
|||||||
}
|
}
|
||||||
free(unquoted);
|
free(unquoted);
|
||||||
|
|
||||||
gchar *resource_choices[] = { "/caps", "/software", "/ping" };
|
gchar *resource_choices[] = { "/caps", "/ping" };
|
||||||
for (i = 0; i < ARRAY_SIZE(resource_choices); i++) {
|
for (i = 0; i < ARRAY_SIZE(resource_choices); i++) {
|
||||||
result = autocomplete_param_with_func(input, resource_choices[i], roster_fulljid_autocomplete, previous, NULL);
|
result = autocomplete_param_with_func(input, resource_choices[i], roster_fulljid_autocomplete, previous, NULL);
|
||||||
if (result) {
|
if (result) {
|
||||||
@@ -1726,6 +1727,7 @@ _cmd_ac_complete_params(ProfWin *window, const char *const input, gboolean previ
|
|||||||
g_hash_table_insert(ac_funcs, "/avatar", _avatar_autocomplete);
|
g_hash_table_insert(ac_funcs, "/avatar", _avatar_autocomplete);
|
||||||
g_hash_table_insert(ac_funcs, "/correction", _correction_autocomplete);
|
g_hash_table_insert(ac_funcs, "/correction", _correction_autocomplete);
|
||||||
g_hash_table_insert(ac_funcs, "/correct", _correct_autocomplete);
|
g_hash_table_insert(ac_funcs, "/correct", _correct_autocomplete);
|
||||||
|
g_hash_table_insert(ac_funcs, "/software", _software_autocomplete);
|
||||||
|
|
||||||
int len = strlen(input);
|
int len = strlen(input);
|
||||||
char parsed[len+1];
|
char parsed[len+1];
|
||||||
@@ -3887,3 +3889,38 @@ _correct_autocomplete(ProfWin *window, const char *const input, gboolean previou
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char*
|
||||||
|
_software_autocomplete(ProfWin *window, const char *const input, gboolean previous)
|
||||||
|
{
|
||||||
|
char *result = NULL;
|
||||||
|
|
||||||
|
if (window->type == WIN_CHAT){
|
||||||
|
ProfChatWin *chatwin = (ProfChatWin*)window;
|
||||||
|
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
||||||
|
|
||||||
|
GString *search_str = g_string_new("/software ");
|
||||||
|
g_string_append(search_str, chatwin->barejid);
|
||||||
|
result = autocomplete_param_with_func(search_str->str, "/software", roster_fulljid_autocomplete, previous, NULL);
|
||||||
|
g_string_free(search_str, TRUE);
|
||||||
|
} else if (window->type == WIN_MUC) {
|
||||||
|
ProfMucWin *mucwin = (ProfMucWin*)window;
|
||||||
|
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
||||||
|
|
||||||
|
Autocomplete nick_ac = muc_roster_ac(mucwin->roomjid);
|
||||||
|
|
||||||
|
if (nick_ac) {
|
||||||
|
result = autocomplete_param_with_ac(input, "/software", nick_ac, TRUE, previous);
|
||||||
|
if (result) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result = autocomplete_param_with_func(input, "/software", roster_fulljid_autocomplete, previous, NULL);
|
||||||
|
if (result) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|||||||
@@ -3427,6 +3427,22 @@ cmd_caps(ProfWin *window, const char *const command, gchar **args)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_send_software_version_iq_to_fulljid(char *request)
|
||||||
|
{
|
||||||
|
Jid *myJid = jid_create(connection_get_fulljid());
|
||||||
|
Jid *jid = jid_create(request);
|
||||||
|
|
||||||
|
if (jid == NULL || jid->fulljid == NULL) {
|
||||||
|
cons_show("You must provide a full jid to the /software command.");
|
||||||
|
} else if (g_strcmp0(jid->barejid, myJid->barejid) == 0) {
|
||||||
|
cons_show("Cannot request software version for yourself.");
|
||||||
|
} else {
|
||||||
|
iq_send_software_version(jid->fulljid);
|
||||||
|
}
|
||||||
|
jid_destroy(myJid);
|
||||||
|
jid_destroy(jid);
|
||||||
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
cmd_software(ProfWin *window, const char *const command, gchar **args)
|
cmd_software(ProfWin *window, const char *const command, gchar **args)
|
||||||
@@ -3458,7 +3474,8 @@ cmd_software(ProfWin *window, const char *const command, gchar **args)
|
|||||||
break;
|
break;
|
||||||
case WIN_CHAT:
|
case WIN_CHAT:
|
||||||
if (args[0]) {
|
if (args[0]) {
|
||||||
cons_show("No parameter needed to /software when in chat.");
|
_send_software_version_iq_to_fulljid(args[0]);
|
||||||
|
break;
|
||||||
} else {
|
} else {
|
||||||
ProfChatWin *chatwin = (ProfChatWin*)window;
|
ProfChatWin *chatwin = (ProfChatWin*)window;
|
||||||
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
||||||
@@ -3477,24 +3494,13 @@ cmd_software(ProfWin *window, const char *const command, gchar **args)
|
|||||||
iq_send_software_version(fulljid->str);
|
iq_send_software_version(fulljid->str);
|
||||||
g_string_free(fulljid, TRUE);
|
g_string_free(fulljid, TRUE);
|
||||||
} else {
|
} else {
|
||||||
win_println(window, THEME_DEFAULT, "-", "Unknown resource for /software command.");
|
win_println(window, THEME_DEFAULT, "-", "Unknown resource for /software command. See /help resource.");
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case WIN_CONSOLE:
|
case WIN_CONSOLE:
|
||||||
if (args[0]) {
|
if (args[0]) {
|
||||||
Jid *myJid = jid_create(connection_get_fulljid());
|
_send_software_version_iq_to_fulljid(args[0]);
|
||||||
Jid *jid = jid_create(args[0]);
|
|
||||||
|
|
||||||
if (jid == NULL || jid->fulljid == NULL) {
|
|
||||||
cons_show("You must provide a full jid to the /software command.");
|
|
||||||
} else if (g_strcmp0(jid->barejid, myJid->barejid) == 0) {
|
|
||||||
cons_show("Cannot request software version for yourself.");
|
|
||||||
} else {
|
|
||||||
iq_send_software_version(jid->fulljid);
|
|
||||||
}
|
|
||||||
jid_destroy(myJid);
|
|
||||||
jid_destroy(jid);
|
|
||||||
} else {
|
} else {
|
||||||
cons_show("You must provide a jid to the /software command.");
|
cons_show("You must provide a jid to the /software command.");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user