about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-12-21 22:01:56 +0000
committerJames Booth <boothj5@gmail.com>2014-12-21 22:01:56 +0000
commit0c1bbb63c08e1237dd2a329b6c085fe5ced1f1d7 (patch)
treeb341611f96fadcf47ae7bd7fb4c41a1fb3a9357f /src
parentd41ac71d276bbeb38192ee635cb10eda4fdfbf69 (diff)
downloadprofani-tty-0c1bbb63c08e1237dd2a329b6c085fe5ced1f1d7.tar.gz
Added win_get_title
Diffstat (limited to 'src')
-rw-r--r--src/command/commands.c16
-rw-r--r--src/ui/core.c40
-rw-r--r--src/ui/titlebar.c36
-rw-r--r--src/ui/titlebar.h2
-rw-r--r--src/ui/ui.h2
-rw-r--r--src/ui/window.c103
-rw-r--r--src/ui/window.h9
-rw-r--r--src/ui/windows.c17
-rw-r--r--src/ui/windows.h4
9 files changed, 87 insertions, 142 deletions
diff --git a/src/command/commands.c b/src/command/commands.c
index da3ee9ec..31a117fa 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -2289,16 +2289,13 @@ cmd_form(gchar **args, struct cmd_help_t help)
         return TRUE;
     }
 
-    gchar **split_recipient = g_strsplit(confwin->from, " ", 2);
-    char *roomjid = split_recipient[0];
-
     if (g_strcmp0(args[0], "submit") == 0) {
-        iq_submit_room_config(roomjid, confwin->form);
+        iq_submit_room_config(confwin->roomjid, confwin->form);
 
     }
 
     if (g_strcmp0(args[0], "cancel") == 0) {
-        iq_room_config_cancel(roomjid);
+        iq_room_config_cancel(confwin->roomjid);
     }
 
     if ((g_strcmp0(args[0], "submit") == 0) || (g_strcmp0(args[0], "cancel") == 0)) {
@@ -2306,7 +2303,7 @@ cmd_form(gchar **args, struct cmd_help_t help)
             cmd_autocomplete_remove_form_fields(confwin->form);
         }
         wins_close_current();
-        ProfWin *current = (ProfWin*)wins_get_muc(roomjid);
+        ProfWin *current = (ProfWin*)wins_get_muc(confwin->roomjid);
         if (current == NULL) {
             current = wins_get_console();
         }
@@ -2314,8 +2311,6 @@ cmd_form(gchar **args, struct cmd_help_t help)
         ui_switch_win(num);
     }
 
-    g_strfreev(split_recipient);
-
     return TRUE;
 }
 
@@ -2617,10 +2612,7 @@ cmd_room(gchar **args, struct cmd_help_t help)
     }
 
     if (g_strcmp0(args[0], "config") == 0) {
-        GString *win_title = g_string_new(mucwin->roomjid);
-        g_string_append(win_title, " config");
-        ProfMucConfWin *confwin = wins_get_muc_conf(win_title->str);
-        g_string_free(win_title, TRUE);
+        ProfMucConfWin *confwin = wins_get_muc_conf(mucwin->roomjid);
 
         if (confwin != NULL) {
             num = wins_get_num(window);
diff --git a/src/ui/core.c b/src/ui/core.c
index 55c1ba47..091ed0eb 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -861,9 +861,7 @@ _ui_switch_win(const int i)
             status_bar_current(1);
             status_bar_active(1);
         } else {
-            GString *recipient_str = win_get_recipient_string(new_current);
-            title_bar_set_recipient(recipient_str->str);
-            g_string_free(recipient_str, TRUE);
+            title_bar_switch();
             status_bar_current(i);
             status_bar_active(i);
         }
@@ -898,9 +896,7 @@ _ui_previous_win(void)
         status_bar_current(1);
         status_bar_active(1);
     } else {
-        GString *recipient_str = win_get_recipient_string(new_current);
-        title_bar_set_recipient(recipient_str->str);
-        g_string_free(recipient_str, TRUE);
+        title_bar_switch();
         status_bar_current(i);
         status_bar_active(i);
     }
@@ -931,9 +927,7 @@ _ui_next_win(void)
         status_bar_current(1);
         status_bar_active(1);
     } else {
-        GString *recipient_str = win_get_recipient_string(new_current);
-        title_bar_set_recipient(recipient_str->str);
-        g_string_free(recipient_str, TRUE);
+        title_bar_switch();
         status_bar_current(i);
         status_bar_active(i);
     }
@@ -963,9 +957,7 @@ _ui_gone_secure(const char * const barejid, gboolean trusted)
     }
 
     if (wins_is_current(window)) {
-        GString *recipient_str = win_get_recipient_string(window);
-        title_bar_set_recipient(recipient_str->str);
-        g_string_free(recipient_str, TRUE);
+         title_bar_switch();
     } else {
         int num = wins_get_num(window);
         status_bar_new(num);
@@ -990,9 +982,7 @@ _ui_gone_insecure(const char * const barejid)
         ProfWin *window = (ProfWin*)chatwin;
         win_save_print(window, '!', NULL, 0, THEME_OTR_ENDED, "", "OTR session ended.");
         if (wins_is_current(window)) {
-            GString *recipient_str = win_get_recipient_string(window);
-            title_bar_set_recipient(recipient_str->str);
-            g_string_free(recipient_str, TRUE);
+            title_bar_switch();
         }
     }
 }
@@ -1100,9 +1090,7 @@ _ui_trust(const char * const barejid)
         ProfWin *window = (ProfWin*)chatwin;
         win_save_print(window, '!', NULL, 0, THEME_OTR_TRUSTED, "", "OTR session trusted.");
         if (wins_is_current(window)) {
-            GString *recipient_str = win_get_recipient_string(window);
-            title_bar_set_recipient(recipient_str->str);
-            g_string_free(recipient_str, TRUE);
+            title_bar_switch();
         }
     }
 }
@@ -1118,9 +1106,7 @@ _ui_untrust(const char * const barejid)
         ProfWin *window = (ProfWin*)chatwin;
         win_save_print(window, '!', NULL, 0, THEME_OTR_UNTRUSTED, "", "OTR session untrusted.");
         if (wins_is_current(window)) {
-            GString *recipient_str = win_get_recipient_string(window);
-            title_bar_set_recipient(recipient_str->str);
-            g_string_free(recipient_str, TRUE);
+            title_bar_switch();
         }
     }
 }
@@ -2605,10 +2591,7 @@ _ui_show_form(ProfMucConfWin *confwin)
         win_save_print(window, '-', NULL, NO_EOL, 0, "", "Form title: ");
         win_save_print(window, '-', NULL, NO_DATE, 0, "", confwin->form->title);
     } else {
-        gchar **split_recipient = g_strsplit(confwin->from, " ", 2);
-        char *roomjid = split_recipient[0];
-        win_save_vprint(window, '-', NULL, 0, 0, "", "Configuration for room %s.", roomjid);
-        g_strfreev(split_recipient);
+        win_save_vprint(window, '-', NULL, 0, 0, "", "Configuration for room %s.", confwin->roomjid);
     }
     win_save_print(window, '-', NULL, 0, 0, "", "");
 
@@ -2642,14 +2625,11 @@ _ui_show_form_field(ProfWin *window, DataForm *form, char *tag)
 }
 
 static void
-_ui_handle_room_configuration(const char * const room, DataForm *form)
+_ui_handle_room_configuration(const char * const roomjid, DataForm *form)
 {
-    GString *title = g_string_new(room);
-    g_string_append(title, " config");
-    ProfWin *window = wins_new_muc_config(title->str, form);
+    ProfWin *window = wins_new_muc_config(roomjid, form);
     ProfMucConfWin *confwin = (ProfMucConfWin*)window;
     assert(confwin->memcheck = PROFCONFWIN_MEMCHECK);
-    g_string_free(title, TRUE);
 
     int num = wins_get_num(window);
     ui_switch_win(num);
diff --git a/src/ui/titlebar.c b/src/ui/titlebar.c
index 36bde009..a8cb23fa 100644
--- a/src/ui/titlebar.c
+++ b/src/ui/titlebar.c
@@ -48,11 +48,7 @@
 #include "ui/window.h"
 #include "roster_list.h"
 
-#define CONSOLE_TITLE "Profanity. Type /help for help information."
-
 static WINDOW *win;
-static char *current_title = NULL;
-static char *current_recipient = NULL;
 static contact_presence_t current_presence;
 
 static gboolean typing;
@@ -81,8 +77,8 @@ create_title_bar(void)
 void
 title_bar_update_virtual(void)
 {
-    if (current_recipient != NULL) {
-
+    ProfWin *window = wins_get_current();
+    if (window->type != WIN_CONSOLE) {
         if (typing_elapsed != NULL) {
             gdouble seconds = g_timer_elapsed(typing_elapsed, NULL);
 
@@ -112,16 +108,9 @@ void
 title_bar_console(void)
 {
     werase(win);
-    if (current_recipient != NULL) {
-        free(current_recipient);
-    }
-    current_recipient = NULL;
     typing = FALSE;
     typing_elapsed = NULL;
 
-    free(current_title);
-    current_title = strdup(CONSOLE_TITLE);
-
     _title_bar_draw();
 }
 
@@ -132,8 +121,9 @@ title_bar_set_presence(contact_presence_t presence)
     _title_bar_draw();
 }
 
+// TODO remove
 void
-title_bar_set_recipient(const char * const recipient)
+title_bar_switch(void)
 {
     if (typing_elapsed != NULL) {
         g_timer_destroy(typing_elapsed);
@@ -141,12 +131,6 @@ title_bar_set_recipient(const char * const recipient)
         typing = FALSE;
     }
 
-    free(current_recipient);
-    current_recipient = strdup(recipient);
-
-    free(current_title);
-    current_title = strdup(recipient);
-
     _title_bar_draw();
 }
 
@@ -179,7 +163,9 @@ _title_bar_draw(void)
         waddch(win, ' ');
     }
 
-    mvwprintw(win, 0, 0, " %s", current_title);
+    char *title = win_get_title(current);
+    mvwprintw(win, 0, 0, " %s", title);
+    free(title);
 
     if (current && current->type == WIN_CHAT) {
         ProfChatWin *chatwin = (ProfChatWin*) current;
@@ -193,12 +179,6 @@ _title_bar_draw(void)
         if (typing) {
             wprintw(win, " (typing...)");
         }
-    } else if (current && current->type == WIN_MUC_CONFIG) {
-        ProfMucConfWin *confwin = (ProfMucConfWin*) current;
-        assert(confwin->memcheck == PROFCONFWIN_MEMCHECK);
-        if (confwin->form->modified) {
-            wprintw(win, " *");
-        }
     }
 
     _show_self_presence();
@@ -269,7 +249,7 @@ _show_privacy(ProfChatWin *chatwin)
 {
     int bracket_attrs = theme_attrs(THEME_TITLE_BRACKET);
 
-    if (chatwin->is_otr) {
+    if (!chatwin->is_otr) {
         if (prefs_get_boolean(PREF_OTR_WARN)) {
             int unencrypted_attrs = theme_attrs(THEME_TITLE_UNENCRYPTED);
             wprintw(win, " ");
diff --git a/src/ui/titlebar.h b/src/ui/titlebar.h
index 9aa4bd07..08a56514 100644
--- a/src/ui/titlebar.h
+++ b/src/ui/titlebar.h
@@ -40,7 +40,7 @@ void title_bar_update_virtual(void);
 void title_bar_resize(void);
 void title_bar_console(void);
 void title_bar_set_presence(contact_presence_t presence);
-void title_bar_set_recipient(const char * const from);
+void title_bar_switch(void);
 void title_bar_set_typing(gboolean is_typing);
 
 #endif
\ No newline at end of file
diff --git a/src/ui/ui.h b/src/ui/ui.h
index 3271d25b..a2d24786 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -199,7 +199,7 @@ void (*ui_handle_recipient_error)(const char * const recipient, const char * con
 void (*ui_handle_error)(const char * const err_msg);
 void (*ui_clear_win_title)(void);
 void (*ui_handle_room_join_error)(const char * const roomjid, const char * const err);
-void (*ui_handle_room_configuration)(const char * const room, DataForm *form);
+void (*ui_handle_room_configuration)(const char * const roomjid, DataForm *form);
 void (*ui_handle_room_configuration_form_error)(const char * const roomjid, const char * const message);
 void (*ui_handle_room_config_submit_result)(const char * const roomjid);
 void (*ui_handle_room_config_submit_result_error)(const char * const roomjid, const char * const message);
diff --git a/src/ui/window.c b/src/ui/window.c
index c84a76bb..6a944c7a 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -52,7 +52,7 @@
 #include "ui/window.h"
 #include "xmpp/xmpp.h"
 
-#define CONS_WIN_TITLE "_cons"
+#define CONS_WIN_TITLE "Profanity. Type /help for help information."
 #define XML_WIN_TITLE "XML Console"
 
 #define CEILING(X) (X-(int)(X) > 0 ? (int)(X+1) : (int)(X))
@@ -122,8 +122,6 @@ win_create_console(void)
     new_win->window.layout = _win_create_split_layout();
     new_win->window.unread = 0;
 
-    new_win->from = strdup(CONS_WIN_TITLE);
-
     return &new_win->window;
 }
 
@@ -185,14 +183,14 @@ win_create_muc(const char * const roomjid)
 }
 
 ProfWin*
-win_create_muc_config(const char * const title, DataForm *form)
+win_create_muc_config(const char * const roomjid, DataForm *form)
 {
     ProfMucConfWin *new_win = malloc(sizeof(ProfMucConfWin));
     new_win->window.type = WIN_MUC_CONFIG;
     new_win->window.layout = _win_create_simple_layout();
     new_win->window.unread = 0;
 
-    new_win->from = strdup(title);
+    new_win->roomjid = strdup(roomjid);
     new_win->form = form;
 
     new_win->memcheck = PROFCONFWIN_MEMCHECK;
@@ -223,11 +221,54 @@ win_create_xmlconsole(void)
     new_win->window.layout = _win_create_simple_layout();
     new_win->window.unread = 0;
 
-    new_win->from = strdup(XML_WIN_TITLE);
+    new_win->memcheck = PROFXMLWIN_MEMCHECK;
 
     return &new_win->window;
 }
 
+char *
+win_get_title(ProfWin *window)
+{
+    if (window == NULL) {
+        return strdup(CONS_WIN_TITLE);
+    }
+    if (window->type == WIN_CONSOLE) {
+        return strdup(CONS_WIN_TITLE);
+    }
+    if (window->type == WIN_CHAT) {
+        ProfChatWin *chatwin = (ProfChatWin*) window;
+        assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
+        return strdup(chatwin->barejid);
+    }
+    if (window->type == WIN_MUC) {
+        ProfMucWin *mucwin = (ProfMucWin*) window;
+        assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
+        return strdup(mucwin->roomjid);
+    }
+    if (window->type == WIN_MUC_CONFIG) {
+        ProfMucConfWin *confwin = (ProfMucConfWin*) window;
+        assert(confwin->memcheck == PROFCONFWIN_MEMCHECK);
+        GString *title = g_string_new(confwin->roomjid);
+        g_string_append(title, " config");
+        if (confwin->form->modified) {
+            g_string_append(title, " *");
+        }
+        char *title_str = title->str;
+        g_string_free(title, FALSE);
+        return title_str;
+    }
+    if (window->type == WIN_PRIVATE) {
+        ProfPrivateWin *privatewin = (ProfPrivateWin*) window;
+        assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK);
+        return strdup(privatewin->fulljid);
+    }
+    if (window->type == WIN_XML) {
+        return strdup(XML_WIN_TITLE);
+    }
+
+    return NULL;
+}
+
 void
 win_hide_subwin(ProfWin *window)
 {
@@ -292,11 +333,6 @@ win_free(ProfWin* window)
         free(chatwin->resource);
     }
 
-    if (window->type == WIN_CONSOLE) {
-        ProfConsoleWin *consolewin = (ProfConsoleWin*)window;
-        free(consolewin->from);
-    }
-
     if (window->type == WIN_MUC) {
         ProfMucWin *mucwin = (ProfMucWin*)window;
         free(mucwin->roomjid);
@@ -304,7 +340,7 @@ win_free(ProfWin* window)
 
     if (window->type == WIN_MUC_CONFIG) {
         ProfMucConfWin *mucconf = (ProfMucConfWin*)window;
-        free(mucconf->from);
+        free(mucconf->roomjid);
         form_destroy(mucconf->form);
     }
 
@@ -313,52 +349,9 @@ win_free(ProfWin* window)
         free(privatewin->fulljid);
     }
 
-    if (window->type == WIN_XML) {
-        ProfXMLWin *xmlwin = (ProfXMLWin*)window;
-        free(xmlwin->from);
-    }
-
     free(window);
 }
 
-GString *
-win_get_recipient_string(ProfWin *window)
-{
-    GString *result = g_string_new("");
-
-    if (window->type == WIN_CONSOLE) {
-        ProfConsoleWin *conswin = (ProfConsoleWin*)window;
-        g_string_append(result, conswin->from);
-    }
-    if (window->type == WIN_CHAT) {
-        ProfChatWin *chatwin = (ProfChatWin*)window;
-        PContact contact = roster_get_contact(chatwin->barejid);
-        if (p_contact_name(contact) != NULL) {
-            g_string_append(result, p_contact_name(contact));
-        } else {
-            g_string_append(result, chatwin->barejid);
-        }
-    }
-    if (window->type == WIN_MUC) {
-        ProfMucWin *mucwin = (ProfMucWin*)window;
-        g_string_append(result, mucwin->roomjid);
-    }
-    if (window->type == WIN_MUC_CONFIG) {
-        ProfMucConfWin *confwin = (ProfMucConfWin*)window;
-        g_string_append(result, confwin->from);
-    }
-    if (window->type == WIN_PRIVATE) {
-        ProfPrivateWin *privatewin = (ProfPrivateWin*)window;
-        g_string_append(result, privatewin->fulljid);
-    }
-    if (window->type == WIN_XML) {
-        ProfXMLWin *xmlwin = (ProfXMLWin*)window;
-        g_string_append(result, xmlwin->from);
-    }
-
-    return result;
-}
-
 void
 win_update_virtual(ProfWin *window)
 {
diff --git a/src/ui/window.h b/src/ui/window.h
index 39df44d7..5acade5e 100644
--- a/src/ui/window.h
+++ b/src/ui/window.h
@@ -61,6 +61,7 @@
 #define PROFMUCWIN_MEMCHECK         52345276
 #define PROFPRIVATEWIN_MEMCHECK     77437483
 #define PROFCONFWIN_MEMCHECK        64334685
+#define PROFXMLWIN_MEMCHECK         87333463
 
 typedef enum {
     LAYOUT_SIMPLE,
@@ -103,7 +104,6 @@ typedef struct prof_win_t {
 
 typedef struct prof_console_win_t {
     ProfWin window;
-    char *from;
 } ProfConsoleWin;
 
 typedef struct prof_chat_win_t {
@@ -124,7 +124,7 @@ typedef struct prof_muc_win_t {
 
 typedef struct prof_mucconf_win_t {
     ProfWin window;
-    char *from;
+    char *roomjid;
     DataForm *form;
     unsigned long memcheck;
 } ProfMucConfWin;
@@ -137,7 +137,7 @@ typedef struct prof_private_win_t {
 
 typedef struct prof_xml_win_t {
     ProfWin window;
-    char *from;
+    unsigned long memcheck;
 } ProfXMLWin;
 
 ProfWin* win_create_console(void);
@@ -147,6 +147,8 @@ ProfWin* win_create_muc_config(const char * const title, DataForm *form);
 ProfWin* win_create_private(const char * const fulljid);
 ProfWin* win_create_xmlconsole(void);
 
+char *win_get_title(ProfWin *window);
+
 void win_free(ProfWin *window);
 void win_update_virtual(ProfWin *window);
 void win_move_to_end(ProfWin *window);
@@ -170,7 +172,6 @@ void win_show_subwin(ProfWin *window);
 int win_roster_cols(void);
 int win_occpuants_cols(void);
 void win_printline_nowrap(WINDOW *win, char *msg);
-GString* win_get_recipient_string(ProfWin *window);
 
 gboolean win_has_active_subwin(ProfWin *window);
 gboolean win_has_modified_form(ProfWin *window);
diff --git a/src/ui/windows.c b/src/ui/windows.c
index 1d660164..bbd8a5f7 100644
--- a/src/ui/windows.c
+++ b/src/ui/windows.c
@@ -36,6 +36,7 @@
 
 #include <string.h>
 #include <assert.h>
+#include <stdlib.h>
 
 #include <glib.h>
 
@@ -99,7 +100,7 @@ wins_get_chat(const char * const barejid)
 }
 
 ProfMucConfWin *
-wins_get_muc_conf(const char * const title)
+wins_get_muc_conf(const char * const roomjid)
 {
     GList *values = g_hash_table_get_values(windows);
     GList *curr = values;
@@ -108,7 +109,7 @@ wins_get_muc_conf(const char * const title)
         ProfWin *window = curr->data;
         if (window->type == WIN_MUC_CONFIG) {
             ProfMucConfWin *confwin = (ProfMucConfWin*)window;
-            if (g_strcmp0(confwin->from, title) == 0) {
+            if (g_strcmp0(confwin->roomjid, roomjid) == 0) {
                 g_list_free(values);
                 return confwin;
             }
@@ -449,11 +450,11 @@ wins_new_muc(const char * const roomjid)
 }
 
 ProfWin *
-wins_new_muc_config(const char * const title, DataForm *form)
+wins_new_muc_config(const char * const roomjid, DataForm *form)
 {
     GList *keys = g_hash_table_get_keys(windows);
     int result = get_next_available_win_num(keys);
-    ProfWin *newwin = win_create_muc_config(title, form);
+    ProfWin *newwin = win_create_muc_config(roomjid, form);
     g_hash_table_insert(windows, GINT_TO_POINTER(result), newwin);
     g_list_free(keys);
     return newwin;
@@ -857,13 +858,11 @@ wins_create_summary(void)
 
             case WIN_MUC_CONFIG:
                 muc_config_string = g_string_new("");
-                ProfMucConfWin *confwin = (ProfMucConfWin*)window;
-                g_string_printf(muc_config_string, "%d: %s", ui_index, confwin->from);
-                if (win_has_modified_form(window)) {
-                    g_string_append(muc_config_string, " *");
-                }
+                char *title = win_get_title(window);
+                g_string_printf(muc_config_string, "%d: %s", ui_index, title);
                 result = g_slist_append(result, strdup(muc_config_string->str));
                 g_string_free(muc_config_string, TRUE);
+                free(title);
 
                 break;
 
diff --git a/src/ui/windows.h b/src/ui/windows.h
index be2e75a0..678e7298 100644
--- a/src/ui/windows.h
+++ b/src/ui/windows.h
@@ -40,13 +40,13 @@ void wins_init(void);
 ProfWin * wins_new_xmlconsole(void);
 ProfWin * wins_new_chat(const char * const barejid);
 ProfWin * wins_new_muc(const char * const roomjid);
-ProfWin * wins_new_muc_config(const char * const title, DataForm *form);
+ProfWin * wins_new_muc_config(const char * const roomjid, DataForm *form);
 ProfWin * wins_new_private(const char * const fulljid);
 
 ProfWin * wins_get_console(void);
 ProfChatWin *wins_get_chat(const char * const barejid);
 ProfMucWin * wins_get_muc(const char * const roomjid);
-ProfMucConfWin * wins_get_muc_conf(const char * const title);
+ProfMucConfWin * wins_get_muc_conf(const char * const roomjid);
 ProfPrivateWin *wins_get_private(const char * const fulljid);
 
 ProfWin * wins_get_current(void);