From 2aa39fc362fd9ab681e86d87eeb7109973416a21 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 11 May 2014 15:59:11 +0100 Subject: [PATCH] Add contact to /otr policy autocomplete --- src/command/command.c | 48 ++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 9015fd2a..65c56ab3 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1803,32 +1803,48 @@ _autoconnect_autocomplete(char *input, int *size) static char * _otr_autocomplete(char *input, int *size) { - char *result = NULL; + char *found = NULL; - result = autocomplete_param_with_func(input, size, "/otr start", roster_find_contact); - if (result != NULL) { - return result; + found = autocomplete_param_with_func(input, size, "/otr start", roster_find_contact); + if (found != NULL) { + return found; } - result = autocomplete_param_with_ac(input, size, "/otr log", otr_log_ac); - if (result != NULL) { - return result; + found = autocomplete_param_with_ac(input, size, "/otr log", otr_log_ac); + if (found != NULL) { + return found; } - result = autocomplete_param_with_ac(input, size, "/otr policy", otr_policy_ac); - if (result != NULL) { - return result; + // /otr policy always user@server.com + gboolean result; + gchar **args = parse_args(input, 3, 3, &result); + if (result && (strcmp(args[0], "policy") == 0)) { + GString *beginning = g_string_new("/otr "); + g_string_append(beginning, args[0]); + g_string_append(beginning, " "); + g_string_append(beginning, args[1]); + + found = autocomplete_param_with_func(input, size, beginning->str, roster_find_contact); + g_string_free(beginning, TRUE); + if (found != NULL) { + return found; + } } - result = autocomplete_param_with_func(input, size, "/otr warn", + found = autocomplete_param_with_ac(input, size, "/otr policy", otr_policy_ac); + if (found != NULL) { + return found; + } + + found = autocomplete_param_with_func(input, size, "/otr warn", prefs_autocomplete_boolean_choice); - if (result != NULL) { - return result; + if (found != NULL) { + return found; } - result = autocomplete_param_with_ac(input, size, "/otr", otr_ac); - if (result != NULL) { - return result; + found = autocomplete_param_with_ac(input, size, "/otr", otr_ac); + if (found != NULL) { + return found; } return NULL;