aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-09-17 23:34:48 +0100
committerJames Booth <boothj5@gmail.com>2014-09-17 23:36:10 +0100
commita905ce18a3419ccdec86334d624eeef38691b2b6 (patch)
tree040e131004e69785d488c51f61740229541e7351 /src
parent45ba6f1feded1c1ece03c85401b959adc8bbd93a (diff)
downloadprofani-tty-a905ce18a3419ccdec86334d624eeef38691b2b6.tar.gz
Added autocompletion for jid-multi form fields
Diffstat (limited to 'src')
-rw-r--r--src/command/command.c8
-rw-r--r--src/tools/autocomplete.c18
-rw-r--r--src/xmpp/form.c12
3 files changed, 29 insertions, 9 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 536ce854..b579fdcf 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -2169,6 +2169,14 @@ _form_autocomplete(char *input, int *size)
}
// handle jid-multi (remove)
+ if ((g_strcmp0(args[0], "remove") == 0) && field_type == FIELD_JID_MULTI) {
+ 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;
+ }
+ }
}
found = autocomplete_param_with_ac(input, size, "/form set", form->tag_ac, TRUE);
diff --git a/src/tools/autocomplete.c b/src/tools/autocomplete.c
index 842ec22a..0fe8f166 100644
--- a/src/tools/autocomplete.c
+++ b/src/tools/autocomplete.c
@@ -99,16 +99,18 @@ autocomplete_length(Autocomplete ac)
void
autocomplete_add(Autocomplete ac, const char *item)
{
- char *item_cpy;
- GSList *curr = g_slist_find_custom(ac->items, item, (GCompareFunc)strcmp);
+ if (ac != NULL) {
+ char *item_cpy;
+ GSList *curr = g_slist_find_custom(ac->items, item, (GCompareFunc)strcmp);
- // if item already exists
- if (curr != NULL) {
- return;
- }
+ // if item already exists
+ if (curr != NULL) {
+ return;
+ }
- item_cpy = strdup(item);
- ac->items = g_slist_insert_sorted(ac->items, item_cpy, (GCompareFunc)strcmp);
+ item_cpy = strdup(item);
+ ac->items = g_slist_insert_sorted(ac->items, item_cpy, (GCompareFunc)strcmp);
+ }
return;
}
diff --git a/src/xmpp/form.c b/src/xmpp/form.c
index 13b652f4..25a704d9 100644
--- a/src/xmpp/form.c
+++ b/src/xmpp/form.c
@@ -234,7 +234,6 @@ form_create(xmpp_stanza_t * const form_stanza)
char *value = xmpp_stanza_get_text(field_child);
if (value != NULL) {
field->values = g_slist_append(field->values, strdup(value));
- xmpp_free(ctx, value);
if (field->type_t == FIELD_TEXT_MULTI) {
GString *ac_val = g_string_new("");
@@ -242,6 +241,11 @@ form_create(xmpp_stanza_t * const form_stanza)
autocomplete_add(field->value_ac, ac_val->str);
g_string_free(ac_val, TRUE);
}
+ if (field->type_t == FIELD_JID_MULTI) {
+ autocomplete_add(field->value_ac, value);
+ }
+
+ xmpp_free(ctx, value);
}
// handle options
@@ -502,6 +506,9 @@ _form_add_unique_value(DataForm *form, const char * const tag, char *value)
}
field->values = g_slist_append(field->values, strdup(value));
+ if (field->type_t == FIELD_JID_MULTI) {
+ autocomplete_add(field->value_ac, value);
+ }
form->modified = TRUE;
return TRUE;
}
@@ -526,6 +533,9 @@ _form_remove_value(DataForm *form, const char * const tag, char *value)
free(found->data);
found->data = NULL;
field->values = g_slist_delete_link(field->values, found);
+ if (field->type_t == FIELD_JID_MULTI) {
+ autocomplete_remove(field->value_ac, value);
+ }
form->modified = TRUE;
return TRUE;
} else {