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);