Show OTR coloured status

Customisable within theme files e.g.:
titlebar.unencrypted=red
titlebar.encrypted=green
titlebar.trusted=red
titlebar.untrusted=green

Shows [unencrypted] for all non-OTR chat

Disable with '/otr warn off'
This commit is contained in:
James Booth
2014-01-16 22:44:23 +00:00
parent 6c59bb26da
commit 4f98bc8c25
11 changed files with 161 additions and 39 deletions

View File

@@ -60,6 +60,8 @@ test_sources = \
src/config/accounts.h \ src/config/accounts.h \
src/config/preferences.c src/config/preferences.h \ src/config/preferences.c src/config/preferences.h \
src/config/theme.c src/config/theme.h \ src/config/theme.c src/config/theme.h \
src/ui/windows.c src/ui/windows.h \
src/ui/window.c src/ui/window.h \
tests/xmpp/mock_xmpp.h tests/xmpp/mock_xmpp.c \ tests/xmpp/mock_xmpp.h tests/xmpp/mock_xmpp.c \
tests/ui/mock_ui.h tests/ui/mock_ui.c \ tests/ui/mock_ui.h tests/ui/mock_ui.c \
tests/config/mock_accounts.h tests/config/mock_accounts.c \ tests/config/mock_accounts.h tests/config/mock_accounts.c \

View File

@@ -571,9 +571,9 @@ static struct cmd_t command_defs[] =
{ "/otr", { "/otr",
cmd_otr, parse_args, 1, 2, NULL, cmd_otr, parse_args, 1, 2, NULL,
{ "/otr gen|myfp|theirfp|start|end|trust|untrust|log", "Off The Record encryption commands.", { "/otr gen|myfp|theirfp|start|end|trust|untrust|log|warn", "Off The Record encryption commands.",
{ "/otr gen|myfp|theirfp|start|end|trust|untrust|log", { "/otr gen|myfp|theirfp|start|end|trust|untrust|log|warn",
"-------------------------------------------------", "------------------------------------------------------",
"gen - Generate your private key.", "gen - Generate your private key.",
"myfp - Show your fingerprint.", "myfp - Show your fingerprint.",
"theirfp - Show contacts fingerprint.", "theirfp - Show contacts fingerprint.",
@@ -582,6 +582,7 @@ static struct cmd_t command_defs[] =
"trust - Indicate that you have verified the contact's fingerprint.", "trust - Indicate that you have verified the contact's fingerprint.",
"untrust - Indicate the the contact's fingerprint is not verified,", "untrust - Indicate the the contact's fingerprint is not verified,",
"log - How to log OTR messages, options are 'on', 'off' and 'redact', with redaction being the default.", "log - How to log OTR messages, options are 'on', 'off' and 'redact', with redaction being the default.",
"warn - Show when unencrypted messaging is being used in the title bar, options are 'on' and 'off' with 'on' being the default.",
NULL } } }, NULL } } },
{ "/outtype", { "/outtype",
@@ -997,6 +998,7 @@ cmd_init(void)
autocomplete_add(otr_ac, "trust"); autocomplete_add(otr_ac, "trust");
autocomplete_add(otr_ac, "untrust"); autocomplete_add(otr_ac, "untrust");
autocomplete_add(otr_ac, "log"); autocomplete_add(otr_ac, "log");
autocomplete_add(otr_ac, "warn");
otr_log_ac = autocomplete_new(); otr_log_ac = autocomplete_new();
autocomplete_add(otr_log_ac, "on"); autocomplete_add(otr_log_ac, "on");
@@ -1588,6 +1590,12 @@ _otr_autocomplete(char *input, int *size)
return result; return result;
} }
result = autocomplete_param_with_func(input, size, "/otr warn",
prefs_autocomplete_boolean_choice);
if (result != NULL) {
return result;
}
result = autocomplete_param_with_ac(input, size, "/otr", otr_ac); result = autocomplete_param_with_ac(input, size, "/otr", otr_ac);
if (result != NULL) { if (result != NULL) {
return result; return result;

View File

@@ -2327,6 +2327,12 @@ cmd_otr(gchar **args, struct cmd_help_t help)
cons_show("Usage: %s", help.usage); cons_show("Usage: %s", help.usage);
} }
return TRUE; return TRUE;
} else if (strcmp(args[0], "warn") == 0) {
gboolean result = _cmd_set_boolean_preference(args[1], help,
"OTR warning message", PREF_OTR_WARN);
// update the current window
ui_switch_win(wins_get_current_num());
return result;
} }
if (jabber_get_connection_status() != JABBER_CONNECTED) { if (jabber_get_connection_status() != JABBER_CONNECTED) {
@@ -2493,7 +2499,11 @@ _cmd_set_boolean_preference(gchar *arg, struct cmd_help_t help,
GString *disabled = g_string_new(display); GString *disabled = g_string_new(display);
g_string_append(disabled, " disabled."); g_string_append(disabled, " disabled.");
if (strcmp(arg, "on") == 0) { if (arg == NULL) {
char usage[strlen(help.usage) + 8];
sprintf(usage, "Usage: %s", help.usage);
cons_show(usage);
} else if (strcmp(arg, "on") == 0) {
cons_show(enabled->str); cons_show(enabled->str);
prefs_set_boolean(pref, TRUE); prefs_set_boolean(pref, TRUE);
} else if (strcmp(arg, "off") == 0) { } else if (strcmp(arg, "off") == 0) {

View File

@@ -293,6 +293,7 @@ _get_group(preference_t pref)
case PREF_HISTORY: case PREF_HISTORY:
case PREF_MOUSE: case PREF_MOUSE:
case PREF_STATUSES: case PREF_STATUSES:
case PREF_OTR_WARN:
return "ui"; return "ui";
case PREF_STATES: case PREF_STATES:
case PREF_OUTTYPE: case PREF_OUTTYPE:
@@ -368,6 +369,8 @@ _get_key(preference_t pref)
return "account"; return "account";
case PREF_OTR_LOG: case PREF_OTR_LOG:
return "otr"; return "otr";
case PREF_OTR_WARN:
return "otr.warn";
default: default:
return NULL; return NULL;
} }
@@ -380,6 +383,7 @@ _get_default_boolean(preference_t pref)
{ {
case PREF_STATUSES: case PREF_STATUSES:
case PREF_AUTOAWAY_CHECK: case PREF_AUTOAWAY_CHECK:
case PREF_OTR_WARN:
return TRUE; return TRUE;
default: default:
return FALSE; return FALSE;

View File

@@ -58,7 +58,8 @@ typedef enum {
PREF_AUTOAWAY_MODE, PREF_AUTOAWAY_MODE,
PREF_AUTOAWAY_MESSAGE, PREF_AUTOAWAY_MESSAGE,
PREF_CONNECT_ACCOUNT, PREF_CONNECT_ACCOUNT,
PREF_OTR_LOG PREF_OTR_LOG,
PREF_OTR_WARN
} preference_t; } preference_t;
void prefs_load(void); void prefs_load(void);

View File

@@ -64,6 +64,10 @@ static struct colours_t {
NCURSES_COLOR_T statusbar; NCURSES_COLOR_T statusbar;
NCURSES_COLOR_T titlebartext; NCURSES_COLOR_T titlebartext;
NCURSES_COLOR_T titlebarbrackets; NCURSES_COLOR_T titlebarbrackets;
NCURSES_COLOR_T titlebarunencrypted;
NCURSES_COLOR_T titlebarencrypted;
NCURSES_COLOR_T titlebaruntrusted;
NCURSES_COLOR_T titlebartrusted;
NCURSES_COLOR_T statusbartext; NCURSES_COLOR_T statusbartext;
NCURSES_COLOR_T statusbarbrackets; NCURSES_COLOR_T statusbarbrackets;
NCURSES_COLOR_T statusbaractive; NCURSES_COLOR_T statusbaractive;
@@ -197,6 +201,10 @@ theme_init_colours(void)
// title bar // title bar
init_pair(10, colour_prefs.titlebartext, colour_prefs.titlebar); init_pair(10, colour_prefs.titlebartext, colour_prefs.titlebar);
init_pair(11, colour_prefs.titlebarbrackets, colour_prefs.titlebar); init_pair(11, colour_prefs.titlebarbrackets, colour_prefs.titlebar);
init_pair(12, colour_prefs.titlebarunencrypted, colour_prefs.titlebar);
init_pair(13, colour_prefs.titlebarencrypted, colour_prefs.titlebar);
init_pair(14, colour_prefs.titlebaruntrusted, colour_prefs.titlebar);
init_pair(15, colour_prefs.titlebartrusted, colour_prefs.titlebar);
// status bar // status bar
init_pair(20, colour_prefs.statusbartext, colour_prefs.statusbar); init_pair(20, colour_prefs.statusbartext, colour_prefs.statusbar);
@@ -280,6 +288,22 @@ _load_colours(void)
_set_colour(titlebarbrackets_val, &colour_prefs.titlebarbrackets, COLOR_CYAN); _set_colour(titlebarbrackets_val, &colour_prefs.titlebarbrackets, COLOR_CYAN);
g_free(titlebarbrackets_val); g_free(titlebarbrackets_val);
gchar *titlebarunencrypted_val = g_key_file_get_string(theme, "colours", "titlebar.unencrypted", NULL);
_set_colour(titlebarunencrypted_val, &colour_prefs.titlebarunencrypted, COLOR_RED);
g_free(titlebarunencrypted_val);
gchar *titlebarencrypted_val = g_key_file_get_string(theme, "colours", "titlebar.encrypted", NULL);
_set_colour(titlebarencrypted_val, &colour_prefs.titlebarencrypted, COLOR_WHITE);
g_free(titlebarencrypted_val);
gchar *titlebaruntrusted_val = g_key_file_get_string(theme, "colours", "titlebar.untrusted", NULL);
_set_colour(titlebaruntrusted_val, &colour_prefs.titlebaruntrusted, COLOR_RED);
g_free(titlebaruntrusted_val);
gchar *titlebartrusted_val = g_key_file_get_string(theme, "colours", "titlebar.trusted", NULL);
_set_colour(titlebartrusted_val, &colour_prefs.titlebartrusted, COLOR_WHITE);
g_free(titlebartrusted_val);
gchar *statusbartext_val = g_key_file_get_string(theme, "colours", "statusbar.text", NULL); gchar *statusbartext_val = g_key_file_get_string(theme, "colours", "statusbar.text", NULL);
_set_colour(statusbartext_val, &colour_prefs.statusbartext, COLOR_WHITE); _set_colour(statusbartext_val, &colour_prefs.statusbartext, COLOR_WHITE);
g_free(statusbartext_val); g_free(statusbartext_val);

View File

@@ -32,31 +32,35 @@
#include <ncurses.h> #include <ncurses.h>
#endif #endif
#define COLOUR_TEXT COLOR_PAIR(1) #define COLOUR_TEXT COLOR_PAIR(1)
#define COLOUR_SPLASH COLOR_PAIR(2) #define COLOUR_SPLASH COLOR_PAIR(2)
#define COLOUR_ERROR COLOR_PAIR(3) #define COLOUR_ERROR COLOR_PAIR(3)
#define COLOUR_INCOMING COLOR_PAIR(4) #define COLOUR_INCOMING COLOR_PAIR(4)
#define COLOUR_INPUT_TEXT COLOR_PAIR(5) #define COLOUR_INPUT_TEXT COLOR_PAIR(5)
#define COLOUR_TIME COLOR_PAIR(6) #define COLOUR_TIME COLOR_PAIR(6)
#define COLOUR_TITLE_TEXT COLOR_PAIR(10) #define COLOUR_TITLE_TEXT COLOR_PAIR(10)
#define COLOUR_TITLE_BRACKET COLOR_PAIR(11) #define COLOUR_TITLE_BRACKET COLOR_PAIR(11)
#define COLOUR_STATUS_TEXT COLOR_PAIR(20) #define COLOUR_TITLE_UNENCRYPTED COLOR_PAIR(12)
#define COLOUR_STATUS_BRACKET COLOR_PAIR(21) #define COLOUR_TITLE_ENCRYPTED COLOR_PAIR(13)
#define COLOUR_STATUS_ACTIVE COLOR_PAIR(22) #define COLOUR_TITLE_UNTRUSTED COLOR_PAIR(14)
#define COLOUR_STATUS_NEW COLOR_PAIR(23) #define COLOUR_TITLE_TRUSTED COLOR_PAIR(15)
#define COLOUR_ME COLOR_PAIR(30) #define COLOUR_STATUS_TEXT COLOR_PAIR(20)
#define COLOUR_THEM COLOR_PAIR(31) #define COLOUR_STATUS_BRACKET COLOR_PAIR(21)
#define COLOUR_ROOMINFO COLOR_PAIR(40) #define COLOUR_STATUS_ACTIVE COLOR_PAIR(22)
#define COLOUR_ONLINE COLOR_PAIR(50) #define COLOUR_STATUS_NEW COLOR_PAIR(23)
#define COLOUR_OFFLINE COLOR_PAIR(51) #define COLOUR_ME COLOR_PAIR(30)
#define COLOUR_AWAY COLOR_PAIR(52) #define COLOUR_THEM COLOR_PAIR(31)
#define COLOUR_CHAT COLOR_PAIR(53) #define COLOUR_ROOMINFO COLOR_PAIR(40)
#define COLOUR_DND COLOR_PAIR(54) #define COLOUR_ONLINE COLOR_PAIR(50)
#define COLOUR_XA COLOR_PAIR(55) #define COLOUR_OFFLINE COLOR_PAIR(51)
#define COLOUR_TYPING COLOR_PAIR(60) #define COLOUR_AWAY COLOR_PAIR(52)
#define COLOUR_GONE COLOR_PAIR(61) #define COLOUR_CHAT COLOR_PAIR(53)
#define COLOUR_SUBSCRIBED COLOR_PAIR(70) #define COLOUR_DND COLOR_PAIR(54)
#define COLOUR_UNSUBSCRIBED COLOR_PAIR(71) #define COLOUR_XA COLOR_PAIR(55)
#define COLOUR_TYPING COLOR_PAIR(60)
#define COLOUR_GONE COLOR_PAIR(61)
#define COLOUR_SUBSCRIBED COLOR_PAIR(70)
#define COLOUR_UNSUBSCRIBED COLOR_PAIR(71)
void theme_init(const char * const theme_name); void theme_init(const char * const theme_name);
void theme_init_colours(void); void theme_init_colours(void);

View File

@@ -983,6 +983,16 @@ _cons_titlebar_setting(void)
} }
} }
static void
_cons_otrwarn_setting(void)
{
if (prefs_get_boolean(PREF_OTR_WARN)) {
cons_show("Warn non-OTR (/otr warn) : ON");
} else {
cons_show("Warn non-OTR (/otr warn) : OFF");
}
}
static void static void
_cons_show_ui_prefs(void) _cons_show_ui_prefs(void)
{ {
@@ -996,6 +1006,7 @@ _cons_show_ui_prefs(void)
cons_mouse_setting(); cons_mouse_setting();
cons_statuses_setting(); cons_statuses_setting();
cons_titlebar_setting(); cons_titlebar_setting();
cons_otrwarn_setting();
wins_refresh_console(); wins_refresh_console();
cons_alert(); cons_alert();
@@ -1564,6 +1575,7 @@ console_init_module(void)
cons_chlog_setting = _cons_chlog_setting; cons_chlog_setting = _cons_chlog_setting;
cons_grlog_setting = _cons_grlog_setting; cons_grlog_setting = _cons_grlog_setting;
cons_otr_log_setting = _cons_otr_log_setting; cons_otr_log_setting = _cons_otr_log_setting;
cons_otrwarn_setting = _cons_otrwarn_setting;
cons_show_log_prefs = _cons_show_log_prefs; cons_show_log_prefs = _cons_show_log_prefs;
cons_autoaway_setting = _cons_autoaway_setting; cons_autoaway_setting = _cons_autoaway_setting;
cons_show_presence_prefs = _cons_show_presence_prefs; cons_show_presence_prefs = _cons_show_presence_prefs;

View File

@@ -525,15 +525,6 @@ _get_recipient_string(ProfWin *window)
g_string_append(result, window->from); g_string_append(result, window->from);
} }
if (window->is_otr) {
g_string_append(result, " [OTR]");
if (window->is_trusted) {
g_string_append(result, " (trusted)");
} else {
g_string_append(result, " (untrusted)");
}
}
return result; return result;
} }

View File

@@ -25,7 +25,10 @@
#include "common.h" #include "common.h"
#include "config/theme.h" #include "config/theme.h"
#include "config/preferences.h"
#include "ui/ui.h" #include "ui/ui.h"
#include "ui/windows.h"
#include "ui/window.h"
#define CONSOLE_TITLE "Profanity. Type /help for help information." #define CONSOLE_TITLE "Profanity. Type /help for help information."
@@ -150,6 +153,68 @@ _title_bar_draw(void)
for (i = 0; i < 45; i++) for (i = 0; i < 45; i++)
waddch(win, ' '); waddch(win, ' ');
mvwprintw(win, 0, 0, " %s", current_title); mvwprintw(win, 0, 0, " %s", current_title);
#ifdef HAVE_LIBOTR
// show privacy
if (current_recipient != NULL) {
ProfWin *current = wins_get_by_recipient(current_recipient);
if (current != NULL) {
if (current->type == WIN_CHAT) {
if (!current->is_otr) {
if (prefs_get_boolean(PREF_OTR_WARN)) {
wprintw(win, " ");
wattron(win, COLOUR_TITLE_BRACKET);
wprintw(win, "[");
wattroff(win, COLOUR_TITLE_BRACKET);
wattron(win, COLOUR_TITLE_UNENCRYPTED);
wprintw(win, "unencrypted");
wattroff(win, COLOUR_TITLE_UNENCRYPTED);
wattron(win, COLOUR_TITLE_BRACKET);
wprintw(win, "]");
wattroff(win, COLOUR_TITLE_BRACKET);
}
} else {
wprintw(win, " ");
wattron(win, COLOUR_TITLE_BRACKET);
wprintw(win, "[");
wattroff(win, COLOUR_TITLE_BRACKET);
wattron(win, COLOUR_TITLE_ENCRYPTED);
wprintw(win, "OTR");
wattroff(win, COLOUR_TITLE_ENCRYPTED);
wattron(win, COLOUR_TITLE_BRACKET);
wprintw(win, "]");
wattroff(win, COLOUR_TITLE_BRACKET);
if (current->is_trusted) {
wprintw(win, " ");
wattron(win, COLOUR_TITLE_BRACKET);
wprintw(win, "[");
wattroff(win, COLOUR_TITLE_BRACKET);
wattron(win, COLOUR_TITLE_TRUSTED);
wprintw(win, "trusted");
wattroff(win, COLOUR_TITLE_TRUSTED);
wattron(win, COLOUR_TITLE_BRACKET);
wprintw(win, "]");
wattroff(win, COLOUR_TITLE_BRACKET);
} else {
wprintw(win, " ");
wattron(win, COLOUR_TITLE_BRACKET);
wprintw(win, "[");
wattroff(win, COLOUR_TITLE_BRACKET);
wattron(win, COLOUR_TITLE_UNTRUSTED);
wprintw(win, "untrusted");
wattroff(win, COLOUR_TITLE_UNTRUSTED);
wattron(win, COLOUR_TITLE_BRACKET);
wprintw(win, "]");
wattroff(win, COLOUR_TITLE_BRACKET);
}
}
}
}
}
#endif
// show contact typing
if (typing) { if (typing) {
wprintw(win, " (typing...)"); wprintw(win, " (typing...)");
} }

View File

@@ -221,6 +221,7 @@ void (*cons_log_setting)(void);
void (*cons_chlog_setting)(void); void (*cons_chlog_setting)(void);
void (*cons_grlog_setting)(void); void (*cons_grlog_setting)(void);
void (*cons_otr_log_setting)(void); void (*cons_otr_log_setting)(void);
void (*cons_otrwarn_setting)(void);
void (*cons_autoaway_setting)(void); void (*cons_autoaway_setting)(void);
void (*cons_reconnect_setting)(void); void (*cons_reconnect_setting)(void);
void (*cons_autoping_setting)(void); void (*cons_autoping_setting)(void);