diff --git a/src/command/commands.c b/src/command/commands.c index 0f181f31..e96d2f7a 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -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); } diff --git a/src/ui/core.c b/src/ui/core.c index 051d8189..5e1a13ce 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -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; } diff --git a/src/ui/ui.h b/src/ui/ui.h index 51eed7b5..4790982f 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -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); diff --git a/src/xmpp/form.c b/src/xmpp/form.c index 66a5a981..a7b9fe0a 100644 --- a/src/xmpp/form.c +++ b/src/xmpp/form.c @@ -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; } diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index 1c26cd55..85704640 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -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