mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Added form type check on set
This commit is contained in:
parent
c4b4cb557f
commit
b111419693
6
ROOM_CONF_TODO
Normal file
6
ROOM_CONF_TODO
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
Handle setting different field types
|
||||||
|
Autocompelte values for field types on set
|
||||||
|
Don't allow form windows to be closed without submitting/cancelling
|
||||||
|
Help command for form fields
|
||||||
|
Command to show current form
|
||||||
|
Handle error on form submit
|
@ -1915,8 +1915,16 @@ cmd_room(gchar **args, struct cmd_help_t help)
|
|||||||
if (!form_tag_exists(current->form, tag)) {
|
if (!form_tag_exists(current->form, tag)) {
|
||||||
ui_current_print_line("Form does not contain a field with tag %s", tag);
|
ui_current_print_line("Form does not contain a field with tag %s", tag);
|
||||||
} else {
|
} else {
|
||||||
form_set_value_by_tag(current->form, tag, value);
|
form_field_type_t field_type = form_get_field_type_by_tag(current->form, tag);
|
||||||
ui_current_print_line("%s set to %s", tag, value);
|
switch (field_type) {
|
||||||
|
case FIELD_TEXT_SINGLE:
|
||||||
|
form_set_value_by_tag(current->form, tag, value);
|
||||||
|
ui_current_print_line("%s set to %s", tag, value);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ui_current_print_line("Value %s not valid for field: %s", tag, value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2041,6 +2041,8 @@ TODO add command to get help for a field
|
|||||||
|
|
||||||
curr_field = g_slist_next(curr_field);
|
curr_field = g_slist_next(curr_field);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
win_save_println(window, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -277,6 +277,8 @@ form_create_submission(DataForm *form)
|
|||||||
GSList *curr_value = NULL;
|
GSList *curr_value = NULL;
|
||||||
|
|
||||||
switch (field->type_t) {
|
switch (field->type_t) {
|
||||||
|
case FIELD_HIDDEN:
|
||||||
|
case FIELD_FIXED:
|
||||||
case FIELD_TEXT_SINGLE:
|
case FIELD_TEXT_SINGLE:
|
||||||
case FIELD_TEXT_PRIVATE:
|
case FIELD_TEXT_PRIVATE:
|
||||||
case FIELD_BOOLEAN:
|
case FIELD_BOOLEAN:
|
||||||
@ -319,8 +321,6 @@ form_create_submission(DataForm *form)
|
|||||||
curr_value = g_slist_next(curr_value);
|
curr_value = g_slist_next(curr_value);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case FIELD_HIDDEN:
|
|
||||||
case FIELD_FIXED:
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -402,6 +402,23 @@ _form_tag_exists(DataForm *form, const char * const tag)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static form_field_type_t
|
||||||
|
_form_get_field_type_by_tag(DataForm *form, const char * const tag)
|
||||||
|
{
|
||||||
|
char *var = g_hash_table_lookup(form->tag_to_var, tag);
|
||||||
|
if (var != NULL) {
|
||||||
|
GSList *curr = form->fields;
|
||||||
|
while (curr != NULL) {
|
||||||
|
FormField *field = curr->data;
|
||||||
|
if (g_strcmp0(field->var, var) == 0) {
|
||||||
|
return field->type_t;
|
||||||
|
}
|
||||||
|
curr = g_slist_next(curr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return FIELD_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_form_set_value_by_tag(DataForm *form, const char * const tag, char *value)
|
_form_set_value_by_tag(DataForm *form, const char * const tag, char *value)
|
||||||
{
|
{
|
||||||
@ -429,6 +446,7 @@ form_init_module(void)
|
|||||||
{
|
{
|
||||||
form_destroy = _form_destroy;
|
form_destroy = _form_destroy;
|
||||||
form_get_form_type_field = _form_get_form_type_field;
|
form_get_form_type_field = _form_get_form_type_field;
|
||||||
|
form_get_field_type_by_tag = _form_get_field_type_by_tag;
|
||||||
form_set_value_by_tag = _form_set_value_by_tag;
|
form_set_value_by_tag = _form_set_value_by_tag;
|
||||||
form_tag_exists = _form_tag_exists;
|
form_tag_exists = _form_tag_exists;
|
||||||
}
|
}
|
||||||
|
@ -210,5 +210,6 @@ void (*form_destroy)(DataForm *form);
|
|||||||
char * (*form_get_form_type_field)(DataForm *form);
|
char * (*form_get_form_type_field)(DataForm *form);
|
||||||
void (*form_set_value_by_tag)(DataForm *form, const char * const tag, char *value);
|
void (*form_set_value_by_tag)(DataForm *form, const char * const tag, char *value);
|
||||||
gboolean (*form_tag_exists)(DataForm *form, const char * const tag);
|
gboolean (*form_tag_exists)(DataForm *form, const char * const tag);
|
||||||
|
form_field_type_t (*form_get_field_type_by_tag)(DataForm *form, const char * const tag);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user