diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/command/command.c | 16 | ||||
-rw-r--r-- | src/xmpp/form.c | 37 | ||||
-rw-r--r-- | src/xmpp/xmpp.h | 3 |
3 files changed, 56 insertions, 0 deletions
diff --git a/src/command/command.c b/src/command/command.c index 0e6a6156..4c245c87 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1406,6 +1406,14 @@ cmd_reset_autocomplete() autocomplete_reset(join_property_ac); autocomplete_reset(room_ac); autocomplete_reset(form_ac); + + if (ui_current_win_type() == WIN_MUC_CONFIG) { + ProfWin *window = wins_get_current(); + if (window && window->form) { + form_reset_autocompleters(window->form); + } + } + bookmark_autocomplete_reset(); } @@ -2130,6 +2138,14 @@ _form_autocomplete(char *input, int *size) } // handle list-single (set) + if ((g_strcmp0(args[0], "set") == 0) && field_type == FIELD_LIST_SINGLE) { + Autocomplete ac = form_get_value_ac(form, tag); + found = autocomplete_param_with_ac(input, size, beginning->str, ac, TRUE); + g_string_free(beginning, TRUE); + if (found != NULL) { + return found; + } + } // handle list-multi (add, remove) diff --git a/src/xmpp/form.c b/src/xmpp/form.c index a7b9fe0a..3b37f204 100644 --- a/src/xmpp/form.c +++ b/src/xmpp/form.c @@ -207,6 +207,7 @@ form_create(xmpp_stanza_t * const form_stanza) field->label = _get_attr(field_stanza, "label"); field->type = _get_attr(field_stanza, "type"); field->type_t = _get_field_type(field->type); + field->value_ac = autocomplete_new(); field->var = _get_attr(field_stanza, "var"); @@ -241,6 +242,10 @@ form_create(xmpp_stanza_t * const form_stanza) option->label = _get_attr(field_child, "label"); option->value = _get_property(field_child, "value"); + if (field->type_t == FIELD_LIST_SINGLE) { + autocomplete_add(field->value_ac, option->value); + } + field->options = g_slist_append(field->options, option); } @@ -355,6 +360,7 @@ _free_field(FormField *field) free(field->description); g_slist_free_full(field->values, free); g_slist_free_full(field->options, (GDestroyNotify)_free_option); + autocomplete_free(field->value_ac); free(field); } } @@ -610,6 +616,35 @@ _form_get_field_by_tag(DataForm *form, const char * const tag) return NULL; } +static Autocomplete +_form_get_value_ac(DataForm *form, const char * const tag) +{ + char *var = g_hash_table_lookup(form->tag_to_var, tag); + if (var != NULL) { + GSList *curr = form->fields; + while (curr != NULL) { + FormField *field = curr->data; + if (g_strcmp0(field->var, var) == 0) { + return field->value_ac; + } + curr = g_slist_next(curr); + } + } + return NULL; +} + +static void +_form_reset_autocompleters(DataForm *form) +{ + autocomplete_reset(form->tag_ac); + GSList *curr_field = form->fields; + while (curr_field) { + FormField *field = curr_field->data; + autocomplete_reset(field->value_ac); + curr_field = g_slist_next(curr_field); + } +} + void form_init_module(void) { @@ -624,5 +659,7 @@ form_init_module(void) form_field_contains_option = _form_field_contains_option; form_tag_exists = _form_tag_exists; form_get_value_count = _form_get_value_count; + form_get_value_ac = _form_get_value_ac; form_get_field_by_tag = _form_get_field_by_tag; + form_reset_autocompleters = _form_reset_autocompleters; } diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index 85704640..3b0b8156 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -115,6 +115,7 @@ typedef struct form_field_t { gboolean required; GSList *values; GSList *options; + Autocomplete value_ac; } FormField; typedef struct data_form_t { @@ -219,5 +220,7 @@ form_field_type_t (*form_get_field_type)(DataForm *form, const char * const tag) gboolean (*form_field_contains_option)(DataForm *form, const char * const tag, char *value); int (*form_get_value_count)(DataForm *form, const char * const tag); FormField* (*form_get_field_by_tag)(DataForm *form, const char * const tag); +Autocomplete (*form_get_value_ac)(DataForm *form, const char * const tag); +void (*form_reset_autocompleters)(DataForm *form); #endif |