about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-12-10 01:14:11 +0000
committerJames Booth <boothj5@gmail.com>2014-12-10 01:14:11 +0000
commit7b44ac97cc8894047f21233dcbec9a841a636876 (patch)
tree8fc448087a654799f8e0be0b23c5de6ed8661fe3
parent0ce924465f491b16d58b1bbe61eef673ddd32eb4 (diff)
downloadprofani-tty-7b44ac97cc8894047f21233dcbec9a841a636876.tar.gz
Added form to WIN_MUC_CONFIG type
-rw-r--r--src/command/command.c21
-rw-r--r--src/command/commands.c22
-rw-r--r--src/ui/core.c23
-rw-r--r--src/ui/titlebar.c2
-rw-r--r--src/ui/window.c11
-rw-r--r--src/ui/window.h2
-rw-r--r--src/ui/windows.c2
7 files changed, 51 insertions, 32 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 7dbdeed4..89ae17fc 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -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)
 {
-    char *found = NULL;
-
     ProfWin *current = wins_get_current();
-    DataForm *form = current->form;
+    if (current->type != WIN_MUC_CONFIG) {
+        return NULL;
+    }
+
+    char *found = NULL;
 
+    DataForm *form = current->wins.conf.form;
     if (form == NULL) {
         return NULL;
     }
diff --git a/src/command/commands.c b/src/command/commands.c
index 912e302e..e6e6923f 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -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);
diff --git a/src/ui/core.c b/src/ui/core.c
index 14b4ce45..c6c1d01d 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -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);
diff --git a/src/ui/titlebar.c b/src/ui/titlebar.c
index 521d5919..5ed974ce 100644
--- a/src/ui/titlebar.c
+++ b/src/ui/titlebar.c
@@ -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, " *");
         }
     }
diff --git a/src/ui/window.c b/src/ui/window.c
index 183b052d..3b189134 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -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);
 }
 
diff --git a/src/ui/window.h b/src/ui/window.h
index 3c74b8da..c0e5ddca 100644
--- a/src/ui/window.h
+++ b/src/ui/window.h
@@ -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
diff --git a/src/ui/windows.c b/src/ui/windows.c
index 020745f7..ca7bad36 100644
--- a/src/ui/windows.c
+++ b/src/ui/windows.c
@@ -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));