1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Merge branch 'master' into plugins

Conflicts:
	src/command/command.c
This commit is contained in:
James Booth 2014-07-15 23:03:46 +01:00
commit 52bc7fbb01
12 changed files with 132 additions and 84 deletions

View File

@ -1281,7 +1281,7 @@ cmd_autocomplete(char *input, int *size)
inp_cpy[i] = input[i];
}
inp_cpy[i] = '\0';
found = autocomplete_complete(commands_ac, inp_cpy);
found = autocomplete_complete(commands_ac, inp_cpy, TRUE);
if (found != NULL) {
char *auto_msg = strdup(found);
ui_replace_input(input, auto_msg, size);
@ -1312,10 +1312,8 @@ cmd_reset_autocomplete()
autocomplete_reset(sub_ac);
if (ui_current_win_type() == WIN_MUC) {
Autocomplete nick_ac = muc_get_roster_ac(ui_current_recipient());
if (nick_ac != NULL) {
autocomplete_reset(nick_ac);
}
char *recipient = ui_current_recipient();
muc_reset_autocomplete(recipient);
}
autocomplete_reset(who_ac);
@ -1562,7 +1560,7 @@ _cmd_complete_parameters(char *input, int *size)
for (i = 0; i < ARRAY_SIZE(nick_choices); i++) {
result = autocomplete_param_with_ac(input, size, nick_choices[i],
nick_ac);
nick_ac, TRUE);
if (result != NULL) {
ui_replace_input(input, result, size);
g_free(result);
@ -1618,7 +1616,7 @@ _cmd_complete_parameters(char *input, int *size)
Autocomplete completers[] = { help_ac, prefs_ac, disco_ac, close_ac, wins_ac };
for (i = 0; i < ARRAY_SIZE(cmds); i++) {
result = autocomplete_param_with_ac(input, size, cmds[i], completers[i]);
result = autocomplete_param_with_ac(input, size, cmds[i], completers[i], TRUE);
if (result != NULL) {
ui_replace_input(input, result, size);
g_free(result);
@ -1694,7 +1692,7 @@ _roster_autocomplete(char *input, int *size)
if (result != NULL) {
return result;
}
result = autocomplete_param_with_ac(input, size, "/roster", roster_ac);
result = autocomplete_param_with_ac(input, size, "/roster", roster_ac, TRUE);
if (result != NULL) {
return result;
}
@ -1727,7 +1725,7 @@ _group_autocomplete(char *input, int *size)
if (result != NULL) {
return result;
}
result = autocomplete_param_with_ac(input, size, "/group", group_ac);
result = autocomplete_param_with_ac(input, size, "/group", group_ac, TRUE);
if (result != NULL) {
return result;
}
@ -1786,7 +1784,7 @@ _bookmark_autocomplete(char *input, int *size)
if (autojoin) {
found = autocomplete_param_with_func(input, size, beginning->str, prefs_autocomplete_boolean_choice);
} else {
found = autocomplete_param_with_ac(input, size, beginning->str, bookmark_property_ac);
found = autocomplete_param_with_ac(input, size, beginning->str, bookmark_property_ac, TRUE);
}
g_string_free(beginning, TRUE);
if (found != NULL) {
@ -1807,7 +1805,7 @@ _bookmark_autocomplete(char *input, int *size)
return found;
}
found = autocomplete_param_with_ac(input, size, "/bookmark", bookmark_ac);
found = autocomplete_param_with_ac(input, size, "/bookmark", bookmark_ac, TRUE);
return found;
}
@ -1842,17 +1840,17 @@ _notify_autocomplete(char *input, int *size)
return result;
}
result = autocomplete_param_with_ac(input, size, "/notify room", notify_room_ac);
result = autocomplete_param_with_ac(input, size, "/notify room", notify_room_ac, TRUE);
if (result != NULL) {
return result;
}
result = autocomplete_param_with_ac(input, size, "/notify message", notify_message_ac);
result = autocomplete_param_with_ac(input, size, "/notify message", notify_message_ac, TRUE);
if (result != NULL) {
return result;
}
result = autocomplete_param_with_ac(input, size, "/notify typing", notify_typing_ac);
result = autocomplete_param_with_ac(input, size, "/notify typing", notify_typing_ac, TRUE);
if (result != NULL) {
return result;
}
@ -1866,7 +1864,7 @@ _notify_autocomplete(char *input, int *size)
}
}
result = autocomplete_param_with_ac(input, size, "/notify", notify_ac);
result = autocomplete_param_with_ac(input, size, "/notify", notify_ac, TRUE);
if (result != NULL) {
return result;
}
@ -1879,7 +1877,7 @@ _autoaway_autocomplete(char *input, int *size)
{
char *result = NULL;
result = autocomplete_param_with_ac(input, size, "/autoaway mode", autoaway_mode_ac);
result = autocomplete_param_with_ac(input, size, "/autoaway mode", autoaway_mode_ac, TRUE);
if (result != NULL) {
return result;
}
@ -1888,7 +1886,7 @@ _autoaway_autocomplete(char *input, int *size)
if (result != NULL) {
return result;
}
result = autocomplete_param_with_ac(input, size, "/autoaway", autoaway_ac);
result = autocomplete_param_with_ac(input, size, "/autoaway", autoaway_ac, TRUE);
if (result != NULL) {
return result;
}
@ -1911,7 +1909,7 @@ _log_autocomplete(char *input, int *size)
if (result != NULL) {
return result;
}
result = autocomplete_param_with_ac(input, size, "/log", log_ac);
result = autocomplete_param_with_ac(input, size, "/log", log_ac, TRUE);
if (result != NULL) {
return result;
}
@ -1929,7 +1927,7 @@ _autoconnect_autocomplete(char *input, int *size)
return result;
}
result = autocomplete_param_with_ac(input, size, "/autoconnect", autoconnect_ac);
result = autocomplete_param_with_ac(input, size, "/autoconnect", autoconnect_ac, TRUE);
if (result != NULL) {
return result;
}
@ -1949,7 +1947,7 @@ _sub_autocomplete(char *input, int *size)
if (result != NULL) {
return result;
}
result = autocomplete_param_with_ac(input, size, "/sub", sub_ac);
result = autocomplete_param_with_ac(input, size, "/sub", sub_ac, TRUE);
if (result != NULL) {
return result;
}
@ -1967,7 +1965,7 @@ _otr_autocomplete(char *input, int *size)
return found;
}
found = autocomplete_param_with_ac(input, size, "/otr log", otr_log_ac);
found = autocomplete_param_with_ac(input, size, "/otr log", otr_log_ac, TRUE);
if (found != NULL) {
return found;
}
@ -1988,7 +1986,7 @@ _otr_autocomplete(char *input, int *size)
}
}
found = autocomplete_param_with_ac(input, size, "/otr policy", otr_policy_ac);
found = autocomplete_param_with_ac(input, size, "/otr policy", otr_policy_ac, TRUE);
if (found != NULL) {
return found;
}
@ -1999,7 +1997,7 @@ _otr_autocomplete(char *input, int *size)
return found;
}
found = autocomplete_param_with_ac(input, size, "/otr", otr_ac);
found = autocomplete_param_with_ac(input, size, "/otr", otr_ac, TRUE);
if (found != NULL) {
return found;
}
@ -2023,7 +2021,7 @@ _who_autocomplete(char *input, int *size)
}
}
result = autocomplete_param_with_ac(input, size, "/who", who_ac);
result = autocomplete_param_with_ac(input, size, "/who", who_ac, TRUE);
if (result != NULL) {
return result;
}
@ -2046,12 +2044,12 @@ _theme_autocomplete(char *input, int *size)
g_slist_free(themes);
autocomplete_add(theme_load_ac, "default");
}
result = autocomplete_param_with_ac(input, size, "/theme set", theme_load_ac);
result = autocomplete_param_with_ac(input, size, "/theme set", theme_load_ac, TRUE);
if (result != NULL) {
return result;
}
}
result = autocomplete_param_with_ac(input, size, "/theme", theme_ac);
result = autocomplete_param_with_ac(input, size, "/theme", theme_ac, TRUE);
if (result != NULL) {
return result;
}
@ -2064,22 +2062,22 @@ _statuses_autocomplete(char *input, int *size)
{
char *result = NULL;
result = autocomplete_param_with_ac(input, size, "/statuses console", statuses_setting_ac);
result = autocomplete_param_with_ac(input, size, "/statuses console", statuses_setting_ac, TRUE);
if (result != NULL) {
return result;
}
result = autocomplete_param_with_ac(input, size, "/statuses chat", statuses_setting_ac);
result = autocomplete_param_with_ac(input, size, "/statuses chat", statuses_setting_ac, TRUE);
if (result != NULL) {
return result;
}
result = autocomplete_param_with_ac(input, size, "/statuses muc", statuses_setting_ac);
result = autocomplete_param_with_ac(input, size, "/statuses muc", statuses_setting_ac, TRUE);
if (result != NULL) {
return result;
}
result = autocomplete_param_with_ac(input, size, "/statuses", statuses_ac);
result = autocomplete_param_with_ac(input, size, "/statuses", statuses_ac, TRUE);
if (result != NULL) {
return result;
}
@ -2092,12 +2090,12 @@ _alias_autocomplete(char *input, int *size)
{
char *result = NULL;
result = autocomplete_param_with_ac(input, size, "/alias remove", aliases_ac);
result = autocomplete_param_with_ac(input, size, "/alias remove", aliases_ac, TRUE);
if (result != NULL) {
return result;
}
result = autocomplete_param_with_ac(input, size, "/alias", alias_ac);
result = autocomplete_param_with_ac(input, size, "/alias", alias_ac, TRUE);
if (result != NULL) {
return result;
}
@ -2123,7 +2121,7 @@ _connect_autocomplete(char *input, int *size)
g_string_append(beginning, " ");
g_string_append(beginning, args[2]);
}
found = autocomplete_param_with_ac(input, size, beginning->str, connect_property_ac);
found = autocomplete_param_with_ac(input, size, beginning->str, connect_property_ac, TRUE);
g_string_free(beginning, TRUE);
if (found != NULL) {
return found;
@ -2162,7 +2160,7 @@ _join_autocomplete(char *input, int *size)
g_string_append(beginning, " ");
g_string_append(beginning, args[2]);
}
found = autocomplete_param_with_ac(input, size, beginning->str, join_property_ac);
found = autocomplete_param_with_ac(input, size, beginning->str, join_property_ac, TRUE);
g_string_free(beginning, TRUE);
if (found != NULL) {
return found;
@ -2187,13 +2185,13 @@ _account_autocomplete(char *input, int *size)
if ((g_strv_length(args) > 3) && (g_strcmp0(args[2], "otr")) == 0) {
g_string_append(beginning, " ");
g_string_append(beginning, args[2]);
found = autocomplete_param_with_ac(input, size, beginning->str, otr_policy_ac);
found = autocomplete_param_with_ac(input, size, beginning->str, otr_policy_ac, TRUE);
g_string_free(beginning, TRUE);
if (found != NULL) {
return found;
}
} else {
found = autocomplete_param_with_ac(input, size, beginning->str, account_set_ac);
found = autocomplete_param_with_ac(input, size, beginning->str, account_set_ac, TRUE);
g_string_free(beginning, TRUE);
if (found != NULL) {
return found;
@ -2204,7 +2202,7 @@ _account_autocomplete(char *input, int *size)
if ((strncmp(input, "/account clear", 14) == 0) && (result == TRUE)) {
GString *beginning = g_string_new("/account clear ");
g_string_append(beginning, args[1]);
found = autocomplete_param_with_ac(input, size, beginning->str, account_clear_ac);
found = autocomplete_param_with_ac(input, size, beginning->str, account_clear_ac, TRUE);
g_string_free(beginning, TRUE);
if (found != NULL) {
return found;
@ -2225,6 +2223,6 @@ _account_autocomplete(char *input, int *size)
}
}
found = autocomplete_param_with_ac(input, size, "/account", account_ac);
found = autocomplete_param_with_ac(input, size, "/account", account_ac, TRUE);
return found;
}

View File

@ -101,13 +101,13 @@ _accounts_close(void)
static char *
_accounts_find_enabled(char *prefix)
{
return autocomplete_complete(enabled_ac, prefix);
return autocomplete_complete(enabled_ac, prefix, TRUE);
}
static char *
_accounts_find_all(char *prefix)
{
return autocomplete_complete(all_ac, prefix);
return autocomplete_complete(all_ac, prefix, TRUE);
}
static void

View File

@ -125,7 +125,7 @@ prefs_close(void)
char *
prefs_autocomplete_boolean_choice(char *prefix)
{
return autocomplete_complete(boolean_choice_ac, prefix);
return autocomplete_complete(boolean_choice_ac, prefix, TRUE);
}
void

View File

@ -36,6 +36,7 @@ typedef struct _muc_room_t {
char *nick; // e.g. Some User
char *password;
char *subject;
char *autocomplete_prefix;
GList *pending_broadcasts;
gboolean autojoin;
gboolean pending_nick_change;
@ -117,7 +118,7 @@ muc_reset_invites_ac(void)
char *
muc_find_invite(char *search_str)
{
return autocomplete_complete(invite_ac, search_str);
return autocomplete_complete(invite_ac, search_str, TRUE);
}
void
@ -141,6 +142,7 @@ muc_join_room(const char * const room, const char * const nick,
ChatRoom *new_room = malloc(sizeof(ChatRoom));
new_room->room = strdup(room);
new_room->nick = strdup(nick);
new_room->autocomplete_prefix = NULL;
if (password != NULL) {
new_room->password = strdup(password);
} else {
@ -571,25 +573,69 @@ muc_complete_roster_nick_change(const char * const room,
void
muc_autocomplete(char *input, int *size)
{
char *recipient = ui_current_recipient();
Autocomplete nick_ac = muc_get_roster_ac(recipient);
if (nick_ac != NULL) {
input[*size] = '\0';
gchar *last_space = g_strrstr(input, " ");
char *result = NULL;
if (last_space == NULL) {
result = autocomplete_complete(nick_ac, input);
} else {
int len = (last_space - input);
char *start_str = strndup(input, len);
result = autocomplete_param_with_ac(input, size, start_str, nick_ac);
free(start_str);
}
if (result != NULL) {
ui_replace_input(input, result, size);
g_free(result);
if (rooms == NULL) {
return;
}
char *recipient = ui_current_recipient();
ChatRoom *chat_room = g_hash_table_lookup(rooms, recipient);
if (chat_room == NULL) {
return;
}
if (chat_room->nick_ac == NULL) {
return;
}
input[*size] = '\0';
char *search_str = NULL;
gchar *last_space = g_strrstr(input, " ");
if (last_space == NULL) {
search_str = input;
if (chat_room->autocomplete_prefix == NULL) {
chat_room->autocomplete_prefix = strdup("");
}
} else {
search_str = last_space+1;
if (chat_room->autocomplete_prefix == NULL) {
chat_room->autocomplete_prefix = g_strndup(input, search_str - input);
}
}
char *result = autocomplete_complete(chat_room->nick_ac, search_str, FALSE);
if (result != NULL) {
GString *replace_with = g_string_new(chat_room->autocomplete_prefix);
g_string_append(replace_with, result);
ui_replace_input(input, replace_with->str, size);
g_string_free(replace_with, TRUE);
g_free(result);
}
return;
}
void
muc_reset_autocomplete(const char * const room)
{
if (rooms == NULL) {
return;
}
ChatRoom *chat_room = g_hash_table_lookup(rooms, room);
if (chat_room == NULL) {
return;
}
if (chat_room->nick_ac != NULL) {
autocomplete_reset(chat_room->nick_ac);
}
if (chat_room->autocomplete_prefix != NULL) {
free(chat_room->autocomplete_prefix);
chat_room->autocomplete_prefix = NULL;
}
}
@ -601,6 +647,9 @@ _free_room(ChatRoom *room)
free(room->nick);
free(room->subject);
free(room->password);
if (room->autocomplete_prefix != NULL) {
free(room->autocomplete_prefix);
}
if (room->roster != NULL) {
g_hash_table_destroy(room->roster);
}

View File

@ -77,5 +77,6 @@ void muc_add_pending_broadcast(const char * const room, const char * const messa
GList * muc_get_pending_broadcasts(const char * const room);
void muc_autocomplete(char *input, int *size);
void muc_reset_autocomplete(const char * const room);
#endif

View File

@ -53,7 +53,7 @@ autocompleters_complete(char *input, int *size)
GList *keys = g_hash_table_get_keys(autocompleters);
GList *curr = keys;
while (curr != NULL) {
result = autocomplete_param_with_ac(input, size, curr->data, g_hash_table_lookup(autocompleters, curr->data));
result = autocomplete_param_with_ac(input, size, curr->data, g_hash_table_lookup(autocompleters, curr->data), TRUE);
if (result != NULL) {
return result;
}

View File

@ -291,13 +291,13 @@ roster_has_pending_subscriptions(void)
char *
roster_find_contact(char *search_str)
{
return autocomplete_complete(name_ac, search_str);
return autocomplete_complete(name_ac, search_str, TRUE);
}
char *
roster_find_resource(char *search_str)
{
return autocomplete_complete(fulljid_ac, search_str);
return autocomplete_complete(fulljid_ac, search_str, TRUE);
}
GSList *
@ -333,13 +333,13 @@ roster_get_groups(void)
char *
roster_find_group(char *search_str)
{
return autocomplete_complete(groups_ac, search_str);
return autocomplete_complete(groups_ac, search_str, TRUE);
}
char *
roster_find_jid(char *search_str)
{
return autocomplete_complete(barejid_ac, search_str);
return autocomplete_complete(barejid_ac, search_str, TRUE);
}
static

View File

@ -34,7 +34,7 @@ struct autocomplete_t {
gchar *search_str;
};
static gchar * _search_from(Autocomplete ac, GSList *curr);
static gchar * _search_from(Autocomplete ac, GSList *curr, gboolean quote);
Autocomplete
autocomplete_new(void)
@ -148,7 +148,7 @@ autocomplete_contains(Autocomplete ac, const char *value)
}
gchar *
autocomplete_complete(Autocomplete ac, gchar *search_str)
autocomplete_complete(Autocomplete ac, gchar *search_str, gboolean quote)
{
gchar *found = NULL;
@ -166,18 +166,18 @@ autocomplete_complete(Autocomplete ac, gchar *search_str)
FREE_SET_NULL(ac->search_str);
}
ac->search_str = strdup(search_str);
found = _search_from(ac, ac->items);
found = _search_from(ac, ac->items, quote);
return found;
// subsequent search attempt
} else {
// search from here+1 tp end
found = _search_from(ac, g_slist_next(ac->last_found));
// search from here+1 to end
found = _search_from(ac, g_slist_next(ac->last_found), quote);
if (found != NULL)
return found;
// search from beginning
found = _search_from(ac, ac->items);
found = _search_from(ac, ac->items, quote);
if (found != NULL)
return found;
@ -220,7 +220,7 @@ autocomplete_param_with_func(char *input, int *size, char *command,
char *
autocomplete_param_with_ac(char *input, int *size, char *command,
Autocomplete ac)
Autocomplete ac, gboolean quote)
{
GString *auto_msg = NULL;
char *result = NULL;
@ -235,7 +235,7 @@ autocomplete_param_with_ac(char *input, int *size, char *command,
}
inp_cpy[(*size) - len] = '\0';
char *found = autocomplete_complete(ac, inp_cpy);
char *found = autocomplete_complete(ac, inp_cpy, quote);
if (found != NULL) {
auto_msg = g_string_new(command_cpy);
g_string_append(auto_msg, found);
@ -292,7 +292,7 @@ autocomplete_param_no_with_func(char *input, int *size, char *command,
}
static gchar *
_search_from(Autocomplete ac, GSList *curr)
_search_from(Autocomplete ac, GSList *curr, gboolean quote)
{
while(curr) {
@ -303,7 +303,7 @@ _search_from(Autocomplete ac, GSList *curr)
ac->last_found = curr;
// if contains space, quote before returning
if (g_strrstr(curr->data, " ")) {
if (quote && g_strrstr(curr->data, " ")) {
GString *quoted = g_string_new("\"");
g_string_append(quoted, curr->data);
g_string_append(quoted, "\"");

View File

@ -41,7 +41,7 @@ void autocomplete_add(Autocomplete ac, const char *item);
void autocomplete_remove(Autocomplete ac, const char * const item);
// find the next item prefixed with search string
gchar * autocomplete_complete(Autocomplete ac, gchar *search_str);
gchar * autocomplete_complete(Autocomplete ac, gchar *search_str, gboolean quote);
GSList * autocomplete_get_list(Autocomplete ac);
gint autocomplete_length(Autocomplete ac);
@ -50,7 +50,7 @@ char * autocomplete_param_with_func(char *input, int *size, char *command,
autocomplete_func func);
char * autocomplete_param_with_ac(char *input, int *size, char *command,
Autocomplete ac);
Autocomplete ac, gboolean quote);
char * autocomplete_param_no_with_func(char *input, int *size, char *command,
int arg_number, autocomplete_func func);

View File

@ -217,7 +217,7 @@ _bookmark_get_list(void)
static char *
_bookmark_find(char *search_str)
{
return autocomplete_complete(bookmark_ac, search_str);
return autocomplete_complete(bookmark_ac, search_str, TRUE);
}
static void

View File

@ -149,7 +149,7 @@ presence_clear_sub_requests(void)
static char *
_presence_sub_request_find(char * search_str)
{
return autocomplete_complete(sub_requests_ac, search_str);
return autocomplete_complete(sub_requests_ac, search_str, TRUE);
}
static gboolean

View File

@ -24,7 +24,7 @@ void reset_after_create(void **state)
void find_after_create(void **state)
{
Autocomplete ac = autocomplete_new();
autocomplete_complete(ac, "hello");
autocomplete_complete(ac, "hello", TRUE);
autocomplete_clear(ac);
}
@ -42,7 +42,7 @@ void add_one_and_complete(void **state)
{
Autocomplete ac = autocomplete_new();
autocomplete_add(ac, "Hello");
char *result = autocomplete_complete(ac, "Hel");
char *result = autocomplete_complete(ac, "Hel", TRUE);
assert_string_equal("Hello", result);
@ -54,7 +54,7 @@ void add_two_and_complete_returns_first(void **state)
Autocomplete ac = autocomplete_new();
autocomplete_add(ac, "Hello");
autocomplete_add(ac, "Help");
char *result = autocomplete_complete(ac, "Hel");
char *result = autocomplete_complete(ac, "Hel", TRUE);
assert_string_equal("Hello", result);
@ -66,8 +66,8 @@ void add_two_and_complete_returns_second(void **state)
Autocomplete ac = autocomplete_new();
autocomplete_add(ac, "Hello");
autocomplete_add(ac, "Help");
char *result1 = autocomplete_complete(ac, "Hel");
char *result2 = autocomplete_complete(ac, result1);
char *result1 = autocomplete_complete(ac, "Hel", TRUE);
char *result2 = autocomplete_complete(ac, result1, TRUE);
assert_string_equal("Help", result2);