about summary refs log tree commit diff stats
path: root/src/xmpp/form.c
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-09-17 23:21:14 +0100
committerJames Booth <boothj5@gmail.com>2014-09-17 23:35:51 +0100
commit45ba6f1feded1c1ece03c85401b959adc8bbd93a (patch)
tree9699dea24314ca80aa3003a5e015683385f04a89 /src/xmpp/form.c
parentfa7b6f30000d536f45125f677a0fc820ad758e11 (diff)
downloadprofani-tty-45ba6f1feded1c1ece03c85401b959adc8bbd93a.tar.gz
Added autocompletion for form text-multi values
Diffstat (limited to 'src/xmpp/form.c')
-rw-r--r--src/xmpp/form.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/xmpp/form.c b/src/xmpp/form.c
index 21382e06..13b652f4 100644
--- a/src/xmpp/form.c
+++ b/src/xmpp/form.c
@@ -225,6 +225,7 @@ form_create(xmpp_stanza_t * const form_stanza)
 
             // handle repeated field children
             xmpp_stanza_t *field_child = xmpp_stanza_get_children(field_stanza);
+            int value_index = 1;
             while (field_child != NULL) {
                 child_name = xmpp_stanza_get_name(field_child);
 
@@ -234,6 +235,13 @@ form_create(xmpp_stanza_t * const form_stanza)
                     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("");
+                            g_string_printf(ac_val, "val%d", value_index++);
+                            autocomplete_add(field->value_ac, ac_val->str);
+                            g_string_free(ac_val, TRUE);
+                        }
                     }
 
                 // handle options
@@ -461,6 +469,13 @@ _form_add_value(DataForm *form, const char * const tag, char *value)
             FormField *field = curr->data;
             if (g_strcmp0(field->var, var) == 0) {
                 field->values = g_slist_append(field->values, strdup(value));
+                if (field->type_t == FIELD_TEXT_MULTI) {
+                    int total = g_slist_length(field->values);
+                    GString *value_index = g_string_new("");
+                    g_string_printf(value_index, "val%d", total);
+                    autocomplete_add(field->value_ac, value_index->str);
+                    g_string_free(value_index, TRUE);
+                }
                 form->modified = TRUE;
                 return;
             }
@@ -539,6 +554,10 @@ _form_remove_text_multi_value(DataForm *form, const char * const tag, int index)
                     free(item->data);
                     item->data = NULL;
                     field->values = g_slist_delete_link(field->values, item);
+                    GString *value_index = g_string_new("");
+                    g_string_printf(value_index, "val%d", index+1);
+                    autocomplete_remove(field->value_ac, value_index->str);
+                    g_string_free(value_index, TRUE);
                     form->modified = TRUE;
                     return TRUE;
                 } else {