diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ui/core.c | 43 | ||||
-rw-r--r-- | src/ui/titlebar.c | 4 | ||||
-rw-r--r-- | src/ui/window.c | 32 | ||||
-rw-r--r-- | src/ui/window.h | 8 |
4 files changed, 63 insertions, 24 deletions
diff --git a/src/ui/core.c b/src/ui/core.c index c6c1d01d..f8f564fc 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -344,8 +344,8 @@ _ui_incoming_msg(const char * const from, const char * const message, if (window == NULL) { window = wins_new(from, win_type); #ifdef HAVE_LIBOTR - if (otr_is_secure(from)) { - window->is_otr = TRUE; + if (win_type == WIN_CHAT && otr_is_secure(from)) { + window->wins.chat.is_otr = TRUE; } #endif win_created = TRUE; @@ -615,7 +615,7 @@ _ui_close_connected_win(int index) } else if ((win_type == WIN_CHAT) || (win_type == WIN_PRIVATE)) { #ifdef HAVE_LIBOTR ProfWin *window = wins_get_by_num(index); - if (window->is_otr) { + if (win_is_otr(window)) { otr_end_session(window->from); } #endif @@ -884,10 +884,14 @@ _ui_gone_secure(const char * const recipient, gboolean trusted) window = wins_new(recipient, WIN_CHAT); } + if (window->type != WIN_CHAT) { + return; + } + FREE_SET_NULL(window->chat_resource); - window->is_otr = TRUE; - window->is_trusted = trusted; + window->wins.chat.is_otr = TRUE; + window->wins.chat.is_trusted = trusted; if (trusted) { win_save_print(window, '!', NULL, 0, THEME_OTR_STARTED_TRUSTED, "", "OTR session started (trusted)."); } else { @@ -1006,8 +1010,11 @@ _ui_gone_insecure(const char * const recipient) { ProfWin *window = wins_get_by_recipient(recipient); if (window != NULL) { - window->is_otr = FALSE; - window->is_trusted = FALSE; + if (window->type != WIN_CHAT) { + return; + } + window->wins.chat.is_otr = FALSE; + window->wins.chat.is_trusted = FALSE; win_save_print(window, '!', NULL, 0, THEME_OTR_ENDED, "", "OTR session ended."); if (wins_is_current(window)) { @@ -1023,8 +1030,11 @@ _ui_trust(const char * const recipient) { ProfWin *window = wins_get_by_recipient(recipient); if (window != NULL) { - window->is_otr = TRUE; - window->is_trusted = TRUE; + if (window->type != WIN_CHAT) { + return; + } + window->wins.chat.is_otr = TRUE; + window->wins.chat.is_trusted = TRUE; win_save_print(window, '!', NULL, 0, THEME_OTR_TRUSTED, "", "OTR session trusted."); if (wins_is_current(window)) { @@ -1040,8 +1050,11 @@ _ui_untrust(const char * const recipient) { ProfWin *window = wins_get_by_recipient(recipient); if (window != NULL) { - window->is_otr = TRUE; - window->is_trusted = FALSE; + if (window->type != WIN_CHAT) { + return; + } + window->wins.chat.is_otr = TRUE; + window->wins.chat.is_trusted = FALSE; win_save_print(window, '!', NULL, 0, THEME_OTR_UNTRUSTED, "", "OTR session untrusted."); if (wins_is_current(window)) { @@ -1159,14 +1172,16 @@ static gboolean _ui_current_win_is_otr(void) { ProfWin *current = wins_get_current(); - return current->is_otr; + return win_is_otr(current); } static void _ui_current_set_otr(gboolean value) { ProfWin *current = wins_get_current(); - current->is_otr = value; + if (current->type == WIN_CHAT) { + current->wins.chat.is_otr = value; + } } static void @@ -1377,7 +1392,7 @@ _ui_outgoing_msg(const char * const from, const char * const to, window = wins_new(to, WIN_CHAT); #ifdef HAVE_LIBOTR if (otr_is_secure(to)) { - window->is_otr = TRUE; + window->wins.chat.is_otr = TRUE; } #endif } diff --git a/src/ui/titlebar.c b/src/ui/titlebar.c index 5ed974ce..cb593b4b 100644 --- a/src/ui/titlebar.c +++ b/src/ui/titlebar.c @@ -263,7 +263,7 @@ _show_privacy(void) int bracket_attrs = theme_attrs(THEME_TITLE_BRACKET); ProfWin *current = wins_get_current(); - if (!current->is_otr) { + if (!win_is_otr(current)) { if (prefs_get_boolean(PREF_OTR_WARN)) { int unencrypted_attrs = theme_attrs(THEME_TITLE_UNENCRYPTED); wprintw(win, " "); @@ -289,7 +289,7 @@ _show_privacy(void) wattron(win, bracket_attrs); wprintw(win, "]"); wattroff(win, bracket_attrs); - if (current->is_trusted) { + if (win_is_trusted(current)) { int trusted_attrs = theme_attrs(THEME_TITLE_TRUSTED); wprintw(win, " "); wattron(win, bracket_attrs); diff --git a/src/ui/window.c b/src/ui/window.c index 3b189134..89fde6c3 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -79,7 +79,9 @@ win_create(const char * const title, win_type_t type) ProfWin *new_win = malloc(sizeof(ProfWin)); int cols = getmaxx(stdscr); - switch (type) { + new_win->type = type; + + switch (new_win->type) { case WIN_CONSOLE: new_win->win = newpad(PAD_SIZE, (cols)); wbkgd(new_win->win, theme_attrs(THEME_TEXT)); @@ -116,10 +118,14 @@ win_create(const char * const title, win_type_t type) new_win->paged = 0; new_win->unread = 0; new_win->history_shown = 0; - new_win->type = type; - new_win->is_otr = FALSE; - new_win->is_trusted = FALSE; + + if (new_win->type == WIN_CHAT) { + new_win->wins.chat.is_otr = FALSE; + new_win->wins.chat.is_trusted = FALSE; + } + new_win->chat_resource = NULL; + scrollok(new_win->win, TRUE); return new_win; @@ -178,6 +184,24 @@ win_show_subwin(ProfWin *window) } } +gboolean win_is_otr(ProfWin *window) +{ + if (window->type == WIN_CHAT) { + return window->wins.chat.is_otr; + } else { + return FALSE; + } +} + +gboolean win_is_trusted(ProfWin *window) +{ + if (window->type == WIN_CHAT) { + return window->wins.chat.is_trusted; + } else { + return FALSE; + } +} + void win_free(ProfWin* window) { diff --git a/src/ui/window.h b/src/ui/window.h index c0e5ddca..c74b7cae 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -66,7 +66,6 @@ typedef enum { } win_type_t; typedef struct prof_win_t { - win_type_t type; WINDOW *win; @@ -75,11 +74,8 @@ typedef struct prof_win_t { char *chat_resource; int y_pos; int paged; - gboolean is_otr; - gboolean is_trusted; int unread; int history_shown; - union { // WIN_CONSOLE struct { @@ -89,6 +85,8 @@ typedef struct prof_win_t { // WIN_CHAT struct { + gboolean is_otr; + gboolean is_trusted; } chat; // WIN_MUC @@ -136,5 +134,7 @@ void win_show_subwin(ProfWin *window); int win_roster_cols(void); int win_occpuants_cols(void); void win_printline_nowrap(WINDOW *win, char *msg); +gboolean win_is_otr(ProfWin *window); +gboolean win_is_trusted(ProfWin *window); #endif |