diff options
author | James Booth <boothj5@gmail.com> | 2014-09-11 23:44:39 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2014-09-11 23:44:39 +0100 |
commit | 42a14d018274d2ab306e95765a735ee25aafa6ee (patch) | |
tree | aeef8fffc039ba544f8d3a457985bc9bca3dbff3 /src | |
parent | a133384ef7653d13ec092f4959726eb07f78e9f9 (diff) | |
download | profani-tty-42a14d018274d2ab306e95765a735ee25aafa6ee.tar.gz |
Added tags to form fields
Diffstat (limited to 'src')
-rw-r--r-- | src/ui/core.c | 6 | ||||
-rw-r--r-- | src/xmpp/form.c | 15 | ||||
-rw-r--r-- | src/xmpp/xmpp.h | 2 |
3 files changed, 19 insertions, 4 deletions
diff --git a/src/ui/core.c b/src/ui/core.c index 07840760..499cdf86 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -2021,13 +2021,11 @@ _ui_handle_room_configuration(const char * const room, DataForm *form) FormField *field = curr_field->data; if (g_strcmp0(field->type, "hidden") != 0) { + win_save_vprint(window, '-', NULL, NO_EOL, 0, "", "%s (", field->label); + win_save_print(window, '-', NULL, NO_DATE | NO_EOL, COLOUR_AWAY, "", g_hash_table_lookup(form->var_to_tag, field->var)); if (field->required) { - win_save_vprint(window, '-', NULL, NO_EOL, 0, "", "%s (", field->label); - win_save_print(window, '-', NULL, NO_DATE | NO_EOL, COLOUR_AWAY, "", field->var); win_save_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", ") Required: "); } else { - win_save_vprint(window, '-', NULL, NO_EOL, 0, "", "%s (", field->label); - win_save_print(window, '-', NULL, NO_DATE | NO_EOL, COLOUR_AWAY, "", field->var); win_save_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", "): "); } diff --git a/src/xmpp/form.c b/src/xmpp/form.c index b870aaa4..3ee31a6b 100644 --- a/src/xmpp/form.c +++ b/src/xmpp/form.c @@ -78,6 +78,8 @@ _form_new(void) form->title = NULL; form->instructions = NULL; form->fields = NULL; + form->var_to_tag = NULL; + form->tag_to_var = NULL; return form; } @@ -186,6 +188,10 @@ form_create(xmpp_stanza_t * const form_stanza) form->type = _get_attr(form_stanza, "type"); form->title = _get_property(form_stanza, "title"); form->instructions = _get_property(form_stanza, "instructions"); + form->var_to_tag = g_hash_table_new_full(g_str_hash, g_str_equal, free, free); + form->tag_to_var = g_hash_table_new_full(g_str_hash, g_str_equal, free, free); + + int tag_num = 1; // get fields xmpp_stanza_t *form_child = xmpp_stanza_get_children(form_stanza); @@ -198,7 +204,14 @@ 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->var = _get_attr(field_stanza, "var"); + GString *tag = g_string_new(""); + g_string_printf(tag, "field%d", tag_num++); + g_hash_table_insert(form->var_to_tag, strdup(field->var), strdup(tag->str)); + g_hash_table_insert(form->tag_to_var, strdup(tag->str), strdup(field->var)); + g_string_free(tag, TRUE); + field->description = _get_property(field_stanza, "desc"); field->required = _is_required(field_stanza); @@ -348,6 +361,8 @@ _form_destroy(DataForm *form) free(form->title); free(form->instructions); g_slist_free_full(form->fields, (GDestroyNotify)_free_field); + g_hash_table_destroy(form->var_to_tag); + g_hash_table_destroy(form->tag_to_var); free(form); } } diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index 7ffce4c4..0186fba5 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -121,6 +121,8 @@ typedef struct data_form_t { char *title; char *instructions; GSList *fields; + GHashTable *var_to_tag; + GHashTable *tag_to_var; } DataForm; void jabber_init_module(void); |