mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Added tags to form fields
This commit is contained in:
parent
a133384ef7
commit
42a14d0182
@ -2021,13 +2021,11 @@ _ui_handle_room_configuration(const char * const room, DataForm *form)
|
|||||||
FormField *field = curr_field->data;
|
FormField *field = curr_field->data;
|
||||||
|
|
||||||
if (g_strcmp0(field->type, "hidden") != 0) {
|
if (g_strcmp0(field->type, "hidden") != 0) {
|
||||||
if (field->required) {
|
|
||||||
win_save_vprint(window, '-', NULL, NO_EOL, 0, "", "%s (", field->label);
|
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, COLOUR_AWAY, "", g_hash_table_lookup(form->var_to_tag, field->var));
|
||||||
|
if (field->required) {
|
||||||
win_save_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", ") Required: ");
|
win_save_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", ") Required: ");
|
||||||
} else {
|
} 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, "", "): ");
|
win_save_print(window, '-', NULL, NO_DATE | NO_EOL, 0, "", "): ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,6 +78,8 @@ _form_new(void)
|
|||||||
form->title = NULL;
|
form->title = NULL;
|
||||||
form->instructions = NULL;
|
form->instructions = NULL;
|
||||||
form->fields = NULL;
|
form->fields = NULL;
|
||||||
|
form->var_to_tag = NULL;
|
||||||
|
form->tag_to_var = NULL;
|
||||||
|
|
||||||
return form;
|
return form;
|
||||||
}
|
}
|
||||||
@ -186,6 +188,10 @@ form_create(xmpp_stanza_t * const form_stanza)
|
|||||||
form->type = _get_attr(form_stanza, "type");
|
form->type = _get_attr(form_stanza, "type");
|
||||||
form->title = _get_property(form_stanza, "title");
|
form->title = _get_property(form_stanza, "title");
|
||||||
form->instructions = _get_property(form_stanza, "instructions");
|
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
|
// get fields
|
||||||
xmpp_stanza_t *form_child = xmpp_stanza_get_children(form_stanza);
|
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->label = _get_attr(field_stanza, "label");
|
||||||
field->type = _get_attr(field_stanza, "type");
|
field->type = _get_attr(field_stanza, "type");
|
||||||
field->type_t = _get_field_type(field->type);
|
field->type_t = _get_field_type(field->type);
|
||||||
|
|
||||||
field->var = _get_attr(field_stanza, "var");
|
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->description = _get_property(field_stanza, "desc");
|
||||||
field->required = _is_required(field_stanza);
|
field->required = _is_required(field_stanza);
|
||||||
|
|
||||||
@ -348,6 +361,8 @@ _form_destroy(DataForm *form)
|
|||||||
free(form->title);
|
free(form->title);
|
||||||
free(form->instructions);
|
free(form->instructions);
|
||||||
g_slist_free_full(form->fields, (GDestroyNotify)_free_field);
|
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);
|
free(form);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,6 +121,8 @@ typedef struct data_form_t {
|
|||||||
char *title;
|
char *title;
|
||||||
char *instructions;
|
char *instructions;
|
||||||
GSList *fields;
|
GSList *fields;
|
||||||
|
GHashTable *var_to_tag;
|
||||||
|
GHashTable *tag_to_var;
|
||||||
} DataForm;
|
} DataForm;
|
||||||
|
|
||||||
void jabber_init_module(void);
|
void jabber_init_module(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user