aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-08-30 01:32:13 +0100
committerJames Booth <boothj5@gmail.com>2015-08-30 01:32:13 +0100
commitb4722632b6fa447386b7d786efc8dafd22a3671c (patch)
tree6a6d3e243415ef982a13412503890b4e6ae19565 /src/ui
parent1484e94b355dc8f41d7285206b114a3e8251a1d9 (diff)
downloadprofani-tty-b4722632b6fa447386b7d786efc8dafd22a3671c.tar.gz
Split PGP incoming and outgoing message handling
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/core.c18
-rw-r--r--src/ui/titlebar.c103
-rw-r--r--src/ui/ui.h6
-rw-r--r--src/ui/win_types.h10
-rw-r--r--src/ui/window.c8
5 files changed, 76 insertions, 69 deletions
diff --git a/src/ui/core.c b/src/ui/core.c
index d66806d4..9ee8b9a5 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -478,7 +478,7 @@ ui_incoming_private_msg(const char * const fulljid, const char * const message,
// currently viewing chat window with sender
if (wins_is_current(window)) {
- win_print_incoming_message(window, timestamp, display_from, message, PROF_ENC_NONE);
+ win_print_incoming_message(window, timestamp, display_from, message, PROF_MSG_PLAIN);
title_bar_set_typing(FALSE);
status_bar_active(num);
@@ -487,7 +487,7 @@ ui_incoming_private_msg(const char * const fulljid, const char * const message,
privatewin->unread++;
status_bar_new(num);
cons_show_incoming_message(display_from, num);
- win_print_incoming_message(window, timestamp, display_from, message, PROF_ENC_NONE);
+ win_print_incoming_message(window, timestamp, display_from, message, PROF_MSG_PLAIN);
if (prefs_get_boolean(PREF_FLASH)) {
flash();
@@ -713,7 +713,7 @@ ui_close_connected_win(int index)
ProfChatWin *chatwin = (ProfChatWin*) window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
#ifdef HAVE_LIBOTR
- if (chatwin->enc_mode == PROF_ENC_OTR) {
+ if (chatwin->is_otr) {
otr_end_session(chatwin->barejid);
}
#endif
@@ -895,7 +895,7 @@ ui_gone_secure(const char * const barejid, gboolean trusted)
chatwin = (ProfChatWin*)window;
}
- chatwin->enc_mode = PROF_ENC_OTR;
+ chatwin->is_otr = TRUE;
chatwin->otr_is_trusted = trusted;
if (trusted) {
win_print(window, '!', 0, NULL, 0, THEME_OTR_STARTED_TRUSTED, "", "OTR session started (trusted).");
@@ -923,7 +923,7 @@ ui_gone_insecure(const char * const barejid)
{
ProfChatWin *chatwin = wins_get_chat(barejid);
if (chatwin) {
- chatwin->enc_mode = PROF_ENC_NONE;
+ chatwin->is_otr = FALSE;
chatwin->otr_is_trusted = FALSE;
ProfWin *window = (ProfWin*)chatwin;
@@ -1042,7 +1042,7 @@ ui_trust(const char * const barejid)
{
ProfChatWin *chatwin = wins_get_chat(barejid);
if (chatwin) {
- chatwin->enc_mode = PROF_ENC_OTR;
+ chatwin->is_otr = TRUE;
chatwin->otr_is_trusted = TRUE;
ProfWin *window = (ProfWin*)chatwin;
@@ -1058,7 +1058,7 @@ ui_untrust(const char * const barejid)
{
ProfChatWin *chatwin = wins_get_chat(barejid);
if (chatwin) {
- chatwin->enc_mode = PROF_ENC_OTR;
+ chatwin->is_otr = TRUE;
chatwin->otr_is_trusted = FALSE;
ProfWin *window = (ProfWin*)chatwin;
@@ -1290,9 +1290,9 @@ void
ui_outgoing_chat_msg(ProfChatWin *chatwin, const char * const message, char *id, prof_enc_t enc_mode)
{
char enc_char = '-';
- if (enc_mode == PROF_ENC_OTR) {
+ if (enc_mode == PROF_MSG_OTR) {
enc_char = prefs_get_otr_char();
- } else if (enc_mode == PROF_ENC_PGP) {
+ } else if (enc_mode == PROF_MSG_PGP) {
enc_char = prefs_get_pgp_char();
}
diff --git a/src/ui/titlebar.c b/src/ui/titlebar.c
index 16a9eaff..3bf8ab22 100644
--- a/src/ui/titlebar.c
+++ b/src/ui/titlebar.c
@@ -250,70 +250,73 @@ _show_privacy(ProfChatWin *chatwin)
int trusted_attrs = theme_attrs(THEME_TITLE_TRUSTED);
int untrusted_attrs = theme_attrs(THEME_TITLE_UNTRUSTED);
- switch (chatwin->enc_mode) {
- case PROF_ENC_NONE:
- if (prefs_get_boolean(PREF_ENC_WARN)) {
- wprintw(win, " ");
- wattron(win, bracket_attrs);
- wprintw(win, "[");
- wattroff(win, bracket_attrs);
- wattron(win, unencrypted_attrs);
- wprintw(win, "unencrypted");
- wattroff(win, unencrypted_attrs);
- wattron(win, bracket_attrs);
- wprintw(win, "]");
- wattroff(win, bracket_attrs);
- }
- break;
-
- case PROF_ENC_OTR:
+ if (chatwin->is_otr) {
+ wprintw(win, " ");
+ wattron(win, bracket_attrs);
+ wprintw(win, "[");
+ wattroff(win, bracket_attrs);
+ wattron(win, encrypted_attrs);
+ wprintw(win, "OTR");
+ wattroff(win, encrypted_attrs);
+ wattron(win, bracket_attrs);
+ wprintw(win, "]");
+ wattroff(win, bracket_attrs);
+ if (chatwin->otr_is_trusted) {
wprintw(win, " ");
wattron(win, bracket_attrs);
wprintw(win, "[");
wattroff(win, bracket_attrs);
- wattron(win, encrypted_attrs);
- wprintw(win, "OTR");
- wattroff(win, encrypted_attrs);
+ wattron(win, trusted_attrs);
+ wprintw(win, "trusted");
+ wattroff(win, trusted_attrs);
wattron(win, bracket_attrs);
wprintw(win, "]");
wattroff(win, bracket_attrs);
- if (chatwin->otr_is_trusted) {
- wprintw(win, " ");
- wattron(win, bracket_attrs);
- wprintw(win, "[");
- wattroff(win, bracket_attrs);
- wattron(win, trusted_attrs);
- wprintw(win, "trusted");
- wattroff(win, trusted_attrs);
- wattron(win, bracket_attrs);
- wprintw(win, "]");
- wattroff(win, bracket_attrs);
- } else {
- wprintw(win, " ");
- wattron(win, bracket_attrs);
- wprintw(win, "[");
- wattroff(win, bracket_attrs);
- wattron(win, untrusted_attrs);
- wprintw(win, "untrusted");
- wattroff(win, untrusted_attrs);
- wattron(win, bracket_attrs);
- wprintw(win, "]");
- wattroff(win, bracket_attrs);
- }
- break;
-
- case PROF_ENC_PGP:
+ } else {
wprintw(win, " ");
wattron(win, bracket_attrs);
wprintw(win, "[");
wattroff(win, bracket_attrs);
- wattron(win, encrypted_attrs);
- wprintw(win, "PGP");
- wattroff(win, encrypted_attrs);
+ wattron(win, untrusted_attrs);
+ wprintw(win, "untrusted");
+ wattroff(win, untrusted_attrs);
wattron(win, bracket_attrs);
wprintw(win, "]");
wattroff(win, bracket_attrs);
- break;
+ }
+ } else if (chatwin->pgp_send || chatwin->pgp_recv) {
+ GString *pgpmsg = g_string_new("PGP ");
+ if (chatwin->pgp_send && !chatwin->pgp_recv) {
+ g_string_append(pgpmsg, "send");
+ } else if (!chatwin->pgp_send && chatwin->pgp_recv) {
+ g_string_append(pgpmsg, "recv");
+ } else {
+ g_string_append(pgpmsg, "send/recv");
+ }
+ wprintw(win, " ");
+ wattron(win, bracket_attrs);
+ wprintw(win, "[");
+ wattroff(win, bracket_attrs);
+ wattron(win, encrypted_attrs);
+ wprintw(win, pgpmsg->str);
+ wattroff(win, encrypted_attrs);
+ wattron(win, bracket_attrs);
+ wprintw(win, "]");
+ wattroff(win, bracket_attrs);
+ g_string_free(pgpmsg, TRUE);
+ } else {
+ if (prefs_get_boolean(PREF_ENC_WARN)) {
+ wprintw(win, " ");
+ wattron(win, bracket_attrs);
+ wprintw(win, "[");
+ wattroff(win, bracket_attrs);
+ wattron(win, unencrypted_attrs);
+ wprintw(win, "unencrypted");
+ wattroff(win, unencrypted_attrs);
+ wattron(win, bracket_attrs);
+ wprintw(win, "]");
+ wattroff(win, bracket_attrs);
+ }
}
}
diff --git a/src/ui/ui.h b/src/ui/ui.h
index bd38cbe8..e47cbddd 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -45,6 +45,12 @@
#define NO_COLOUR_FROM 8
#define NO_COLOUR_DATE 16
+typedef enum {
+ PROF_MSG_PLAIN,
+ PROF_MSG_OTR,
+ PROF_MSG_PGP
+} prof_enc_t;
+
// ui startup and control
void ui_init(void);
void ui_load_colours(void);
diff --git a/src/ui/win_types.h b/src/ui/win_types.h
index 3214fa94..bace4537 100644
--- a/src/ui/win_types.h
+++ b/src/ui/win_types.h
@@ -89,12 +89,6 @@ typedef enum {
WIN_XML
} win_type_t;
-typedef enum {
- PROF_ENC_NONE,
- PROF_ENC_OTR,
- PROF_ENC_PGP
-} prof_enc_t;
-
typedef struct prof_win_t {
win_type_t type;
ProfLayout *layout;
@@ -109,8 +103,10 @@ typedef struct prof_chat_win_t {
char *barejid;
int unread;
ChatState *state;
- prof_enc_t enc_mode;
+ gboolean is_otr;
gboolean otr_is_trusted;
+ gboolean pgp_send;
+ gboolean pgp_recv;
char *resource_override;
gboolean history_shown;
unsigned long memcheck;
diff --git a/src/ui/window.c b/src/ui/window.c
index f6ad7cee..a78b0e15 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -135,8 +135,10 @@ win_create_chat(const char * const barejid)
new_win->barejid = strdup(barejid);
new_win->resource_override = NULL;
- new_win->enc_mode = PROF_ENC_NONE;
+ new_win->is_otr = FALSE;
new_win->otr_is_trusted = FALSE;
+ new_win->pgp_recv = FALSE;
+ new_win->pgp_send = FALSE;
new_win->history_shown = FALSE;
new_win->unread = 0;
new_win->state = chat_state_new();
@@ -884,9 +886,9 @@ win_print_incoming_message(ProfWin *window, GDateTime *timestamp,
switch (window->type)
{
case WIN_CHAT:
- if (enc_mode == PROF_ENC_OTR) {
+ if (enc_mode == PROF_MSG_OTR) {
enc_char = prefs_get_otr_char();
- } else if (enc_mode == PROF_ENC_PGP) {
+ } else if (enc_mode == PROF_MSG_PGP) {
enc_char = prefs_get_pgp_char();
}
win_print(window, enc_char, 0, timestamp, NO_ME, THEME_TEXT_THEM, from, message);