1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-01-03 14:57:42 -05:00

Moved otr properties to WIN_CHAT type

This commit is contained in:
James Booth 2014-12-10 01:33:46 +00:00
parent 7b44ac97cc
commit 12d0d22ab3
4 changed files with 63 additions and 24 deletions

View File

@ -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
}

View File

@ -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);

View File

@ -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)
{

View File

@ -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