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

Added form to WIN_MUC_CONFIG type

This commit is contained in:
James Booth 2014-12-10 01:14:11 +00:00
parent 0ce924465f
commit 7b44ac97cc
7 changed files with 51 additions and 32 deletions

View File

@ -1666,8 +1666,8 @@ cmd_reset_autocomplete()
if (ui_current_win_type() == WIN_MUC_CONFIG) {
ProfWin *window = wins_get_current();
if (window && window->form) {
form_reset_autocompleters(window->form);
if (window && window->wins.conf.form) {
form_reset_autocompleters(window->wins.conf.form);
}
}
@ -2455,10 +2455,14 @@ _resource_autocomplete(char *input, int *size)
static char *
_form_autocomplete(char *input, int *size)
{
ProfWin *current = wins_get_current();
if (current->type != WIN_MUC_CONFIG) {
return NULL;
}
char *found = NULL;
ProfWin *current = wins_get_current();
DataForm *form = current->form;
DataForm *form = current->wins.conf.form;
if (form) {
found = autocomplete_param_with_ac(input, size, "/form help", form->tag_ac, TRUE);
if (found != NULL) {
@ -2477,11 +2481,14 @@ _form_autocomplete(char *input, int *size)
static char *
_form_field_autocomplete(char *input, int *size)
{
ProfWin *current = wins_get_current();
if (current->type != WIN_MUC_CONFIG) {
return NULL;
}
char *found = NULL;
ProfWin *current = wins_get_current();
DataForm *form = current->form;
DataForm *form = current->wins.conf.form;
if (form == NULL) {
return NULL;
}

View File

@ -1985,7 +1985,11 @@ gboolean
cmd_form_field(char *tag, gchar **args)
{
ProfWin *current = wins_get_current();
DataForm *form = current->form;
if (current->type != WIN_MUC_CONFIG) {
return TRUE;
}
DataForm *form = current->wins.conf.form;
if (form) {
if (!form_tag_exists(form, tag)) {
ui_current_print_line("Form does not contain a field with tag %s", tag);
@ -2177,10 +2181,10 @@ cmd_form_field(char *tag, gchar **args)
break;
}
if (g_strcmp0(args[0], "remove") == 0) {
removed = form_remove_value(current->form, tag, value);
removed = form_remove_value(form, tag, value);
if (removed) {
ui_current_print_line("Field updated...");
ui_show_form_field(current, current->form, tag);
ui_show_form_field(current, form, tag);
} else {
ui_current_print_line("Field %s does not contain %s", tag, value);
}
@ -2225,7 +2229,7 @@ cmd_form(gchar **args, struct cmd_help_t help)
char *room = split_recipient[0];
if (g_strcmp0(args[0], "show") == 0) {
ui_show_form(current, room, current->form);
ui_show_form(current, room, current->wins.conf.form);
g_strfreev(split_recipient);
return TRUE;
}
@ -2233,9 +2237,9 @@ cmd_form(gchar **args, struct cmd_help_t help)
if (g_strcmp0(args[0], "help") == 0) {
char *tag = args[1];
if (tag != NULL) {
ui_show_form_field_help(current, current->form, tag);
ui_show_form_field_help(current, current->wins.conf.form, tag);
} else {
ui_show_form_help(current, current->form);
ui_show_form_help(current, current->wins.conf.form);
const gchar **help_text = NULL;
Command *command = g_hash_table_lookup(commands, "/form");
@ -2252,7 +2256,7 @@ cmd_form(gchar **args, struct cmd_help_t help)
}
if (g_strcmp0(args[0], "submit") == 0) {
iq_submit_room_config(room, current->form);
iq_submit_room_config(room, current->wins.conf.form);
}
@ -2261,8 +2265,8 @@ cmd_form(gchar **args, struct cmd_help_t help)
}
if ((g_strcmp0(args[0], "submit") == 0) || (g_strcmp0(args[0], "cancel") == 0)) {
if (current->form) {
cmd_autocomplete_remove_form_fields(current->form);
if (current->wins.conf.form) {
cmd_autocomplete_remove_form_fields(current->wins.conf.form);
}
wins_close_current();
current = wins_get_by_recipient(room);

View File

@ -754,10 +754,11 @@ _ui_win_has_unsaved_form(int num)
if (window->type != WIN_MUC_CONFIG) {
return FALSE;
}
if (window->form == NULL) {
if (window->wins.conf.form == NULL) {
return FALSE;
}
return window->form->modified;
return window->wins.conf.form->modified;
}
GString *
@ -784,12 +785,12 @@ _ui_switch_win(const int i)
if (ui_win_exists(i)) {
ProfWin *old_current = wins_get_current();
if (old_current->type == WIN_MUC_CONFIG) {
cmd_autocomplete_remove_form_fields(old_current->form);
cmd_autocomplete_remove_form_fields(old_current->wins.conf.form);
}
ProfWin *new_current = wins_get_by_num(i);
if (new_current->type == WIN_MUC_CONFIG) {
cmd_autocomplete_add_form_fields(new_current->form);
cmd_autocomplete_add_form_fields(new_current->wins.conf.form);
}
wins_set_current_by_num(i);
@ -818,12 +819,12 @@ _ui_previous_win(void)
{
ProfWin *old_current = wins_get_current();
if (old_current->type == WIN_MUC_CONFIG) {
cmd_autocomplete_remove_form_fields(old_current->form);
cmd_autocomplete_remove_form_fields(old_current->wins.conf.form);
}
ProfWin *new_current = wins_get_previous();
if (new_current->type == WIN_MUC_CONFIG) {
cmd_autocomplete_add_form_fields(new_current->form);
cmd_autocomplete_add_form_fields(new_current->wins.conf.form);
}
int i = wins_get_num(new_current);
@ -849,12 +850,12 @@ _ui_next_win(void)
{
ProfWin *old_current = wins_get_current();
if (old_current->type == WIN_MUC_CONFIG) {
cmd_autocomplete_remove_form_fields(old_current->form);
cmd_autocomplete_remove_form_fields(old_current->wins.conf.form);
}
ProfWin *new_current = wins_get_next();
if (new_current->type == WIN_MUC_CONFIG) {
cmd_autocomplete_add_form_fields(new_current->form);
cmd_autocomplete_add_form_fields(new_current->wins.conf.form);
}
int i = wins_get_num(new_current);
@ -1073,8 +1074,8 @@ _ui_close_win(int index)
{
ProfWin *window = wins_get_by_num(index);
if (window) {
if (window->type == WIN_MUC_CONFIG && window->form) {
cmd_autocomplete_remove_form_fields(window->form);
if (window->type == WIN_MUC_CONFIG && window->wins.conf.form) {
cmd_autocomplete_remove_form_fields(window->wins.conf.form);
}
}
@ -2652,7 +2653,7 @@ _ui_handle_room_configuration(const char * const room, DataForm *form)
ProfWin *window = wins_new(title->str, WIN_MUC_CONFIG);
g_string_free(title, TRUE);
window->form = form;
window->wins.conf.form = form;
int num = wins_get_num(window);
ui_switch_win(num);

View File

@ -189,7 +189,7 @@ _title_bar_draw(void)
wprintw(win, " (typing...)");
}
} else if (current && current->type == WIN_MUC_CONFIG) {
if (current->form && current->form->modified) {
if (current->wins.conf.form && current->wins.conf.form->modified) {
wprintw(win, " *");
}
}

View File

@ -106,6 +106,10 @@ win_create(const char * const title, win_type_t type)
break;
}
if (new_win->type == WIN_MUC_CONFIG) {
new_win->wins.conf.form = NULL;
}
new_win->from = strdup(title);
new_win->buffer = buffer_create();
new_win->y_pos = 0;
@ -115,7 +119,6 @@ win_create(const char * const title, win_type_t type)
new_win->type = type;
new_win->is_otr = FALSE;
new_win->is_trusted = FALSE;
new_win->form = NULL;
new_win->chat_resource = NULL;
scrollok(new_win->win, TRUE);
@ -198,7 +201,11 @@ win_free(ProfWin* window)
free(window->chat_resource);
free(window->from);
form_destroy(window->form);
if (window->type == WIN_MUC_CONFIG) {
form_destroy(window->wins.conf.form);
}
free(window);
}

View File

@ -79,7 +79,6 @@ typedef struct prof_win_t {
gboolean is_trusted;
int unread;
int history_shown;
DataForm *form;
union {
// WIN_CONSOLE
@ -100,6 +99,7 @@ typedef struct prof_win_t {
// WIN_MUC_CONFIG
struct {
DataForm *form;
} conf;
// WIN_PRIVATE

View File

@ -656,7 +656,7 @@ wins_create_summary(void)
case WIN_MUC_CONFIG:
muc_config_string = g_string_new("");
g_string_printf(muc_config_string, "%d: %s", ui_index, window->from);
if ((window->form != NULL) && (window->form->modified)) {
if ((window->wins.conf.form) && (window->wins.conf.form->modified)) {
g_string_append(muc_config_string, " *");
}
result = g_slist_append(result, strdup(muc_config_string->str));