1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Added tags to form fields

This commit is contained in:
James Booth 2014-09-11 23:44:39 +01:00
parent a133384ef7
commit 42a14d0182
3 changed files with 19 additions and 4 deletions

View File

@ -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, "", "): ");
}

View File

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

View File

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