1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-02-02 15:08:15 -05:00

Show form fields after updating

This commit is contained in:
James Booth 2014-09-15 23:28:12 +01:00
parent 6b575aa8fc
commit f494faac99
5 changed files with 39 additions and 10 deletions

View File

@ -1858,15 +1858,15 @@ cmd_form(gchar **args, struct cmd_help_t help)
case FIELD_TEXT_PRIVATE:
case FIELD_JID_SINGLE:
form_set_value(current->form, tag, value);
ui_current_print_line("%s set to %s", tag, value);
ui_show_form_field(current, current->form, tag);
break;
case FIELD_BOOLEAN:
if (g_strcmp0(value, "on") == 0) {
form_set_value(current->form, tag, "1");
ui_current_print_line("%s set to %s", tag, value);
ui_show_form_field(current, current->form, tag);
} else if (g_strcmp0(value, "off") == 0) {
form_set_value(current->form, tag, "0");
ui_current_print_line("%s set to %s", tag, value);
ui_show_form_field(current, current->form, tag);
} else {
ui_current_print_line("Value %s not valid for boolean field: %s", value, tag);
}
@ -1875,7 +1875,7 @@ cmd_form(gchar **args, struct cmd_help_t help)
valid = form_field_contains_option(current->form, tag, value);
if (valid == TRUE) {
form_set_value(current->form, tag, value);
ui_current_print_line("%s set to %s", tag, value);
ui_show_form_field(current, current->form, tag);
} else {
ui_current_print_line("Value %s not a valid option for field: %s", value, tag);
}
@ -1916,7 +1916,7 @@ cmd_form(gchar **args, struct cmd_help_t help)
if (valid) {
added = form_add_unique_value(current->form, tag, value);
if (added) {
ui_current_print_line("Added %s to %s", value, tag);
ui_show_form_field(current, current->form, tag);
} else {
ui_current_print_line("Value %s already selected for %s", value, tag);
}
@ -1926,12 +1926,12 @@ cmd_form(gchar **args, struct cmd_help_t help)
break;
case FIELD_TEXT_MULTI:
form_add_value(current->form, tag, value);
ui_current_print_line("Added %s to %s", value, tag);
ui_show_form_field(current, current->form, tag);
break;
case FIELD_JID_MULTI:
added = form_add_unique_value(current->form, tag, value);
if (added) {
ui_current_print_line("Added %s to %s", value, tag);
ui_show_form_field(current, current->form, tag);
} else {
ui_current_print_line("JID %s already exists in %s", value, tag);
}
@ -1972,7 +1972,7 @@ cmd_form(gchar **args, struct cmd_help_t help)
if (valid == TRUE) {
removed = form_remove_value(current->form, tag, value);
if (removed) {
ui_current_print_line("Removed %s from %s", value, tag);
ui_show_form_field(current, current->form, tag);
} else {
ui_current_print_line("Value %s is not currently set for %s", value, tag);
}
@ -1998,7 +1998,7 @@ cmd_form(gchar **args, struct cmd_help_t help)
removed = form_remove_text_multi_value(current->form, tag, index);
if (removed) {
ui_current_print_line("Removed %s from %s", value, tag);
ui_show_form_field(current, current->form, tag);
} else {
ui_current_print_line("Could not remove %s from %s", value, tag);
}
@ -2006,7 +2006,7 @@ cmd_form(gchar **args, struct cmd_help_t help)
case FIELD_JID_MULTI:
removed = form_remove_value(current->form, tag, value);
if (removed) {
ui_current_print_line("Removed %s from %s", value, tag);
ui_show_form_field(current, current->form, tag);
} else {
ui_current_print_line("Field %s does not contain %s", tag, value);
}

View File

@ -2054,6 +2054,14 @@ TODO add command to get help for a field
win_save_println(window, "");
}
static void
_ui_show_form_field(ProfWin *window, DataForm *form, char *tag)
{
FormField *field = form_get_field_by_tag(form, tag);
_ui_handle_form_field(window, tag, field);
win_save_println(window, "");
}
static void
_ui_handle_room_configuration(const char * const room, DataForm *form)
{
@ -2317,4 +2325,5 @@ ui_init_module(void)
ui_handle_room_config_submit_result = _ui_handle_room_config_submit_result;
ui_win_has_unsaved_form = _ui_win_has_unsaved_form;
ui_show_form = _ui_show_form;
ui_show_form_field = _ui_show_form_field;
}

View File

@ -163,6 +163,7 @@ void (*ui_handle_room_join_error)(const char * const room, const char * const er
void (*ui_handle_room_configuration)(const char * const room, DataForm *form);
void (*ui_handle_room_config_submit_result)(void);
void (*ui_show_form)(ProfWin *window, const char * const room, DataForm *form);
void (*ui_show_form_field)(ProfWin *window, DataForm *form, char *tag);
// contact status functions
void (*ui_status_room)(const char * const contact);

View File

@ -593,6 +593,23 @@ _form_field_contains_option(DataForm *form, const char * const tag, char *value)
return FALSE;
}
static FormField *
_form_get_field_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;
}
curr = g_slist_next(curr);
}
}
return NULL;
}
void
form_init_module(void)
{
@ -607,4 +624,5 @@ form_init_module(void)
form_field_contains_option = _form_field_contains_option;
form_tag_exists = _form_tag_exists;
form_get_value_count = _form_get_value_count;
form_get_field_by_tag = _form_get_field_by_tag;
}

View File

@ -218,5 +218,6 @@ gboolean (*form_tag_exists)(DataForm *form, const char * const tag);
form_field_type_t (*form_get_field_type)(DataForm *form, const char * const tag);
gboolean (*form_field_contains_option)(DataForm *form, const char * const tag, char *value);
int (*form_get_value_count)(DataForm *form, const char * const tag);
FormField* (*form_get_field_by_tag)(DataForm *form, const char * const tag);
#endif