1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Merge branch 'master' into plugins

Conflicts:
	Makefile.am
	src/command/command.c
	src/command/commands.c
	src/server_events.c
This commit is contained in:
James Booth 2014-01-18 00:23:56 +00:00
commit 4a97ec9293
16 changed files with 485 additions and 288 deletions

View File

@ -54,7 +54,6 @@ test_sources = \
src/xmpp/xmpp.h \
src/ui/ui.h src/ui/window.c src/ui/window.h \
src/ui/windows.c src/ui/windows.h \
src/ui/muc_window.c src/ui/muc_window.h \
src/command/command.h src/command/command.c src/command/history.c \
src/command/commands.h src/command/commands.c \
src/command/history.h src/tools/parser.c \

View File

@ -233,6 +233,8 @@ AM_CONDITIONAL([BUILD_OTR], [true])
if test "x$enable_otr" = xyes; then
AC_CHECK_LIB([otr], [main], [],
[AC_MSG_ERROR([libotr is required for otr encryption support])])
elif test "x$enable_otr" = xno; then
AM_CONDITIONAL([BUILD_OTR], [false])
elif test "x$enable_otr" = x; then
AC_CHECK_LIB([otr], [main], [],
[AM_CONDITIONAL([BUILD_OTR], [false]) AC_MSG_NOTICE([libotr not found, otr entryption support not enabled])])

View File

@ -64,6 +64,7 @@ static char * _who_autocomplete(char *input, int *size);
static char * _roster_autocomplete(char *input, int *size);
static char * _group_autocomplete(char *input, int *size);
static char * _bookmark_autocomplete(char *input, int *size);
static char * _otr_autocomplete(char *input, int *size);
GHashTable *commands = NULL;
@ -569,16 +570,18 @@ static struct cmd_t command_defs[] =
{ "/otr",
cmd_otr, parse_args, 1, 2, NULL,
{ "/otr gen|myfp|theirfp|start|end|trust|untrust", "Off The Record encryption commands.",
{ "/otr gen|myfp|theirfp|start|end|trust|untrust",
"---------------------------------------------",
{ "/otr gen|myfp|theirfp|start|end|trust|untrust|log|warn", "Off The Record encryption commands.",
{ "/otr gen|myfp|theirfp|start|end|trust|untrust|log|warn",
"------------------------------------------------------",
"gen - Generate your private key.",
"myfp - Show your fingerprint.",
"theirfp - Show contacts fingerprint.",
"start - Start an OTR session with the current recipient.",
"start <contact> - Start an OTR session with the contact, or the current recipient if in a chat window and no argument supplied.",
"end - End the current OTR session,",
"trust - Indicate that you have verified the contact's fingerprint.",
"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.",
"warn - Show when unencrypted messaging is being used in the title bar, options are 'on' and 'off' with 'on' being the default.",
NULL } } },
{ "/outtype",
@ -840,6 +843,7 @@ static Autocomplete roster_ac;
static Autocomplete group_ac;
static Autocomplete bookmark_ac;
static Autocomplete otr_ac;
static Autocomplete otr_log_ac;
/*
* Initialise command autocompleter and history
@ -1000,6 +1004,13 @@ cmd_init(void)
autocomplete_add(otr_ac, "theirfp");
autocomplete_add(otr_ac, "trust");
autocomplete_add(otr_ac, "untrust");
autocomplete_add(otr_ac, "log");
autocomplete_add(otr_ac, "warn");
otr_log_ac = autocomplete_new();
autocomplete_add(otr_log_ac, "on");
autocomplete_add(otr_log_ac, "off");
autocomplete_add(otr_log_ac, "redact");
cmd_history_init();
}
@ -1038,6 +1049,7 @@ cmd_uninit(void)
autocomplete_free(group_ac);
autocomplete_free(bookmark_ac);
autocomplete_free(otr_ac);
autocomplete_free(otr_log_ac);
}
// Command autocompletion functions
@ -1112,6 +1124,7 @@ cmd_reset_autocomplete()
autocomplete_reset(group_ac);
autocomplete_reset(bookmark_ac);
autocomplete_reset(otr_ac);
autocomplete_reset(otr_log_ac);
bookmark_autocomplete_reset();
}
@ -1191,7 +1204,11 @@ cmd_execute_default(const char * const inp)
if (prefs_get_boolean(PREF_CHLOG)) {
const char *jid = jabber_get_fulljid();
Jid *jidp = jid_create(jid);
chat_log_chat(jidp->barejid, recipient, plugin_message, PROF_OUT_LOG, NULL);
if (strcmp(prefs_get_string(PREF_OTR_LOG), "on") == 0) {
chat_log_chat(jidp->barejid, recipient, plugin_message, PROF_OUT_LOG, NULL);
} else if (strcmp(prefs_get_string(PREF_OTR_LOG), "redact") == 0) {
chat_log_chat(jidp->barejid, recipient, "[redacted]", PROF_OUT_LOG, NULL);
}
jid_destroy(jidp);
}
@ -1361,8 +1378,8 @@ _cmd_complete_parameters(char *input, int *size)
return;
}
gchar *cmds[] = { "/help", "/prefs", "/log", "/disco", "/close", "/wins", "/otr" };
Autocomplete completers[] = { help_ac, prefs_ac, log_ac, disco_ac, close_ac, wins_ac, otr_ac };
gchar *cmds[] = { "/help", "/prefs", "/log", "/disco", "/close", "/wins" };
Autocomplete completers[] = { help_ac, prefs_ac, log_ac, disco_ac, close_ac, wins_ac };
for (i = 0; i < ARRAY_SIZE(cmds); i++) {
result = autocomplete_param_with_ac(input, size, cmds[i], completers[i]);
@ -1376,7 +1393,7 @@ _cmd_complete_parameters(char *input, int *size)
autocompleter acs[] = { _who_autocomplete, _sub_autocomplete, _notify_autocomplete,
_autoaway_autocomplete, _titlebar_autocomplete, _theme_autocomplete,
_account_autocomplete, _roster_autocomplete, _group_autocomplete,
_bookmark_autocomplete, _autoconnect_autocomplete };
_bookmark_autocomplete, _autoconnect_autocomplete, _otr_autocomplete };
for (i = 0; i < ARRAY_SIZE(acs); i++) {
result = acs[i](input, size);
@ -1572,6 +1589,35 @@ _sub_autocomplete(char *input, int *size)
return NULL;
}
static char *
_otr_autocomplete(char *input, int *size)
{
char *result = NULL;
result = autocomplete_param_with_func(input, size, "/otr start", roster_find_contact);
if (result != NULL) {
return result;
}
result = autocomplete_param_with_ac(input, size, "/otr log", otr_log_ac);
if (result != NULL) {
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);
if (result != NULL) {
return result;
}
return NULL;
}
static char *
_who_autocomplete(char *input, int *size)
{

View File

@ -495,7 +495,7 @@ cmd_help(gchar **args, struct cmd_help_t help)
_cmd_show_filtered_help("Basic commands", filter, ARRAY_SIZE(filter));
} else if (strcmp(args[0], "chatting") == 0) {
gchar *filter[] = { "/chlog", "/duck", "/gone", "/history",
gchar *filter[] = { "/chlog", "/otr", "/duck", "/gone", "/history",
"/info", "/intype", "/msg", "/notify", "/outtype", "/status",
"/close", "/clear", "/tiny" };
_cmd_show_filtered_help("Chat commands", filter, ARRAY_SIZE(filter));
@ -931,7 +931,11 @@ cmd_msg(gchar **args, struct cmd_help_t help)
if (((win_type == WIN_CHAT) || (win_type == WIN_CONSOLE)) && prefs_get_boolean(PREF_CHLOG)) {
const char *jid = jabber_get_fulljid();
Jid *jidp = jid_create(jid);
chat_log_chat(jidp->barejid, usr_jid, plugin_message, PROF_OUT_LOG, NULL);
if (strcmp(prefs_get_string(PREF_OTR_LOG), "on") == 0) {
chat_log_chat(jidp->barejid, usr_jid, plugin_message, PROF_OUT_LOG, NULL);
} else if (strcmp(prefs_get_string(PREF_OTR_LOG), "redact") == 0) {
chat_log_chat(jidp->barejid, usr_jid, "[redacted]", PROF_OUT_LOG, NULL);
}
jid_destroy(jidp);
}
} else {
@ -2326,6 +2330,35 @@ gboolean
cmd_otr(gchar **args, struct cmd_help_t help)
{
#ifdef PROF_HAVE_LIBOTR
if (strcmp(args[0], "log") == 0) {
char *choice = args[1];
if (g_strcmp0(choice, "on") == 0) {
prefs_set_string(PREF_OTR_LOG, "on");
cons_show("OTR messages will be logged as plaintext.");
if (!prefs_get_boolean(PREF_CHLOG)) {
cons_show("Chat logging is currently disabled, use '/chlog on' to enable.");
}
} else if (g_strcmp0(choice, "off") == 0) {
prefs_set_string(PREF_OTR_LOG, "off");
cons_show("OTR message logging disabled.");
} else if (g_strcmp0(choice, "redact") == 0) {
prefs_set_string(PREF_OTR_LOG, "redact");
cons_show("OTR messages will be logged as '[redacted]'.");
if (!prefs_get_boolean(PREF_CHLOG)) {
cons_show("Chat logging is currently disabled, use '/chlog on' to enable.");
}
} else {
cons_show("Usage: %s", help.usage);
}
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) {
cons_show("You must be connected with an account to load OTR information.");
return TRUE;
@ -2337,7 +2370,7 @@ cmd_otr(gchar **args, struct cmd_help_t help)
return TRUE;
} else if (strcmp(args[0], "myfp") == 0) {
char *fingerprint = otr_get_my_fingerprint();
ui_current_print_line("Your OTR fingerprint: %s", fingerprint);
ui_current_print_formatted_line('!', 0, "Your OTR fingerprint: %s", fingerprint);
free(fingerprint);
return TRUE;
} else if (strcmp(args[0], "theirfp") == 0) {
@ -2346,27 +2379,55 @@ cmd_otr(gchar **args, struct cmd_help_t help)
if (win_type != WIN_CHAT) {
ui_current_print_line("You must be in a regular chat window to view a recipient's fingerprint.");
} else if (!ui_current_win_is_otr()) {
ui_current_print_line("You not currently in an OTR session with this recipient.");
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
} else {
char *recipient = ui_current_recipient();
char *fingerprint = otr_get_their_fingerprint(recipient);
ui_current_print_line("OTR fingerprint for %s: %s", recipient, fingerprint);
ui_current_print_formatted_line('!', 0, "%s's OTR fingerprint: %s", recipient, fingerprint);
free(fingerprint);
}
return TRUE;
} else if (strcmp(args[0], "start") == 0) {
win_type_t win_type = ui_current_win_type();
if (args[1] != NULL) {
char *contact = args[1];
char *barejid = roster_barejid_from_name(contact);
if (barejid == NULL) {
barejid = contact;
}
if (win_type != WIN_CHAT) {
ui_current_print_line("You must be in a regular chat window to start an OTR session.");
} else if (ui_current_win_is_otr()) {
ui_current_print_line("You are already in an OTR session.");
} else {
if (!otr_key_loaded()) {
ui_current_print_line("You have not generated or loaded a private key, use '/otr gen'");
if (prefs_get_boolean(PREF_STATES)) {
if (!chat_session_exists(barejid)) {
chat_session_start(barejid, TRUE);
}
}
ui_new_chat_win(barejid);
if (ui_current_win_is_otr()) {
ui_current_print_formatted_line('!', 0, "You are already in an OTR session.");
} else {
char *recipient = ui_current_recipient();
message_send("?OTR?", recipient);
if (!otr_key_loaded()) {
ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'");
} else if (!otr_is_secure(barejid)) {
message_send("?OTR?", barejid);
} else {
ui_gone_secure(barejid, otr_is_trusted(barejid));
}
}
} else {
win_type_t win_type = ui_current_win_type();
if (win_type != WIN_CHAT) {
ui_current_print_line("You must be in a regular chat window to start an OTR session.");
} else if (ui_current_win_is_otr()) {
ui_current_print_formatted_line('!', 0, "You are already in an OTR session.");
} else {
if (!otr_key_loaded()) {
ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'");
} else {
char *recipient = ui_current_recipient();
message_send("?OTR?", recipient);
}
}
}
return TRUE;
@ -2376,7 +2437,7 @@ cmd_otr(gchar **args, struct cmd_help_t help)
if (win_type != WIN_CHAT) {
ui_current_print_line("You must be in a regular chat window to use OTR.");
} else if (!ui_current_win_is_otr()) {
ui_current_print_line("You are not currently in an OTR session.");
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
} else {
char *recipient = ui_current_recipient();
ui_gone_insecure(recipient);
@ -2389,7 +2450,7 @@ cmd_otr(gchar **args, struct cmd_help_t help)
if (win_type != WIN_CHAT) {
ui_current_print_line("You must be in an OTR session to trust a recipient.");
} else if (!ui_current_win_is_otr()) {
ui_current_print_line("You are not currently in an OTR session.");
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
} else {
char *recipient = ui_current_recipient();
ui_trust(recipient);
@ -2402,7 +2463,7 @@ cmd_otr(gchar **args, struct cmd_help_t help)
if (win_type != WIN_CHAT) {
ui_current_print_line("You must be in an OTR session to untrust a recipient.");
} else if (!ui_current_win_is_otr()) {
ui_current_print_line("You are not currently in an OTR session.");
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
} else {
char *recipient = ui_current_recipient();
ui_untrust(recipient);
@ -2439,7 +2500,7 @@ _update_presence(const resource_presence_t resource_presence,
presence_update(resource_presence, msg, 0);
contact_presence_t contact_presence = contact_presence_from_resource_presence(resource_presence);
title_bar_set_status(contact_presence);
title_bar_set_presence(contact_presence);
gint priority = accounts_get_priority_for_presence_type(jabber_get_account_name(), resource_presence);
if (msg != NULL) {
@ -2462,7 +2523,11 @@ _cmd_set_boolean_preference(gchar *arg, struct cmd_help_t help,
GString *disabled = g_string_new(display);
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);
prefs_set_boolean(pref, TRUE);
} else if (strcmp(arg, "off") == 0) {

View File

@ -306,6 +306,7 @@ _get_group(preference_t pref)
case PREF_HISTORY:
case PREF_MOUSE:
case PREF_STATUSES:
case PREF_OTR_WARN:
return "ui";
case PREF_STATES:
case PREF_OUTTYPE:
@ -317,6 +318,7 @@ _get_group(preference_t pref)
return "notifications";
case PREF_CHLOG:
case PREF_GRLOG:
case PREF_OTR_LOG:
return "logging";
case PREF_AUTOAWAY_CHECK:
case PREF_AUTOAWAY_MODE:
@ -378,6 +380,10 @@ _get_key(preference_t pref)
return "autoaway.message";
case PREF_CONNECT_ACCOUNT:
return "account";
case PREF_OTR_LOG:
return "otr";
case PREF_OTR_WARN:
return "otr.warn";
default:
return NULL;
}
@ -390,6 +396,7 @@ _get_default_boolean(preference_t pref)
{
case PREF_STATUSES:
case PREF_AUTOAWAY_CHECK:
case PREF_OTR_WARN:
return TRUE;
default:
return FALSE;
@ -403,6 +410,8 @@ _get_default_string(preference_t pref)
{
case PREF_AUTOAWAY_MODE:
return "off";
case PREF_OTR_LOG:
return "redact";
default:
return NULL;
}

View File

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

View File

@ -64,6 +64,10 @@ static struct colours_t {
NCURSES_COLOR_T statusbar;
NCURSES_COLOR_T titlebartext;
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 statusbarbrackets;
NCURSES_COLOR_T statusbaractive;
@ -87,6 +91,11 @@ static struct colours_t {
NCURSES_COLOR_T roominfo;
NCURSES_COLOR_T me;
NCURSES_COLOR_T them;
NCURSES_COLOR_T otrstartedtrusted;
NCURSES_COLOR_T otrstarteduntrusted;
NCURSES_COLOR_T otrended;
NCURSES_COLOR_T otrtrusted;
NCURSES_COLOR_T otruntrusted;
} colour_prefs;
static NCURSES_COLOR_T _lookup_colour(const char * const colour);
@ -195,37 +204,48 @@ theme_init_colours(void)
init_pair(6, colour_prefs.timetext, colour_prefs.bkgnd);
// title bar
init_pair(10, colour_prefs.titlebartext, colour_prefs.titlebar);
init_pair(11, colour_prefs.titlebarbrackets, colour_prefs.titlebar);
init_pair(7, colour_prefs.titlebartext, colour_prefs.titlebar);
init_pair(8, colour_prefs.titlebarbrackets, colour_prefs.titlebar);
init_pair(9, colour_prefs.titlebarunencrypted, colour_prefs.titlebar);
init_pair(10, colour_prefs.titlebarencrypted, colour_prefs.titlebar);
init_pair(11, colour_prefs.titlebaruntrusted, colour_prefs.titlebar);
init_pair(12, colour_prefs.titlebartrusted, colour_prefs.titlebar);
// status bar
init_pair(20, colour_prefs.statusbartext, colour_prefs.statusbar);
init_pair(21, colour_prefs.statusbarbrackets, colour_prefs.statusbar);
init_pair(22, colour_prefs.statusbaractive, colour_prefs.statusbar);
init_pair(23, colour_prefs.statusbarnew, colour_prefs.statusbar);
init_pair(13, colour_prefs.statusbartext, colour_prefs.statusbar);
init_pair(14, colour_prefs.statusbarbrackets, colour_prefs.statusbar);
init_pair(15, colour_prefs.statusbaractive, colour_prefs.statusbar);
init_pair(16, colour_prefs.statusbarnew, colour_prefs.statusbar);
// chat
init_pair(30, colour_prefs.me, colour_prefs.bkgnd);
init_pair(31, colour_prefs.them, colour_prefs.bkgnd);
init_pair(17, colour_prefs.me, colour_prefs.bkgnd);
init_pair(18, colour_prefs.them, colour_prefs.bkgnd);
// room chat
init_pair(40, colour_prefs.roominfo, colour_prefs.bkgnd);
init_pair(19, colour_prefs.roominfo, colour_prefs.bkgnd);
// statuses
init_pair(50, colour_prefs.online, colour_prefs.bkgnd);
init_pair(51, colour_prefs.offline, colour_prefs.bkgnd);
init_pair(52, colour_prefs.away, colour_prefs.bkgnd);
init_pair(53, colour_prefs.chat, colour_prefs.bkgnd);
init_pair(54, colour_prefs.dnd, colour_prefs.bkgnd);
init_pair(55, colour_prefs.xa, colour_prefs.bkgnd);
init_pair(20, colour_prefs.online, colour_prefs.bkgnd);
init_pair(21, colour_prefs.offline, colour_prefs.bkgnd);
init_pair(22, colour_prefs.away, colour_prefs.bkgnd);
init_pair(23, colour_prefs.chat, colour_prefs.bkgnd);
init_pair(24, colour_prefs.dnd, colour_prefs.bkgnd);
init_pair(25, colour_prefs.xa, colour_prefs.bkgnd);
// states
init_pair(60, colour_prefs.typing, colour_prefs.bkgnd);
init_pair(61, colour_prefs.gone, colour_prefs.bkgnd);
init_pair(26, colour_prefs.typing, colour_prefs.bkgnd);
init_pair(27, colour_prefs.gone, colour_prefs.bkgnd);
// subscription status
init_pair(70, colour_prefs.subscribed, colour_prefs.bkgnd);
init_pair(71, colour_prefs.unsubscribed, colour_prefs.bkgnd);
init_pair(28, colour_prefs.subscribed, colour_prefs.bkgnd);
init_pair(29, colour_prefs.unsubscribed, colour_prefs.bkgnd);
// otr messages
init_pair(30, colour_prefs.otrstartedtrusted, colour_prefs.bkgnd);
init_pair(31, colour_prefs.otrstarteduntrusted, colour_prefs.bkgnd);
init_pair(32, colour_prefs.otrended, colour_prefs.bkgnd);
init_pair(33, colour_prefs.otrtrusted, colour_prefs.bkgnd);
init_pair(34, colour_prefs.otruntrusted, colour_prefs.bkgnd);
}
static NCURSES_COLOR_T
@ -280,6 +300,22 @@ _load_colours(void)
_set_colour(titlebarbrackets_val, &colour_prefs.titlebarbrackets, COLOR_CYAN);
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_YELLOW);
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);
_set_colour(statusbartext_val, &colour_prefs.statusbartext, COLOR_WHITE);
g_free(statusbartext_val);
@ -320,6 +356,26 @@ _load_colours(void)
_set_colour(unsubscribed_val, &colour_prefs.unsubscribed, COLOR_RED);
g_free(unsubscribed_val);
gchar *otrstartedtrusted_val = g_key_file_get_string(theme, "colours", "otr.started.trusted", NULL);
_set_colour(otrstartedtrusted_val, &colour_prefs.otrstartedtrusted, COLOR_GREEN);
g_free(otrstartedtrusted_val);
gchar *otrstarteduntrusted_val = g_key_file_get_string(theme, "colours", "otr.started.untrusted", NULL);
_set_colour(otrstarteduntrusted_val, &colour_prefs.otrstarteduntrusted, COLOR_YELLOW);
g_free(otrstarteduntrusted_val);
gchar *otrended_val = g_key_file_get_string(theme, "colours", "otr.ended", NULL);
_set_colour(otrended_val, &colour_prefs.otrended, COLOR_RED);
g_free(otrended_val);
gchar *otrtrusted_val = g_key_file_get_string(theme, "colours", "otr.trusted", NULL);
_set_colour(otrtrusted_val, &colour_prefs.otrtrusted, COLOR_GREEN);
g_free(otrtrusted_val);
gchar *otruntrusted_val = g_key_file_get_string(theme, "colours", "otr.untrusted", NULL);
_set_colour(otruntrusted_val, &colour_prefs.otruntrusted, COLOR_YELLOW);
g_free(otruntrusted_val);
gchar *online_val = g_key_file_get_string(theme, "colours", "online", NULL);
_set_colour(online_val, &colour_prefs.online, COLOR_GREEN);
g_free(online_val);

View File

@ -32,31 +32,40 @@
#include <ncurses.h>
#endif
#define COLOUR_TEXT COLOR_PAIR(1)
#define COLOUR_SPLASH COLOR_PAIR(2)
#define COLOUR_ERROR COLOR_PAIR(3)
#define COLOUR_INCOMING COLOR_PAIR(4)
#define COLOUR_INPUT_TEXT COLOR_PAIR(5)
#define COLOUR_TIME COLOR_PAIR(6)
#define COLOUR_TITLE_TEXT COLOR_PAIR(10)
#define COLOUR_TITLE_BRACKET COLOR_PAIR(11)
#define COLOUR_STATUS_TEXT COLOR_PAIR(20)
#define COLOUR_STATUS_BRACKET COLOR_PAIR(21)
#define COLOUR_STATUS_ACTIVE COLOR_PAIR(22)
#define COLOUR_STATUS_NEW COLOR_PAIR(23)
#define COLOUR_ME COLOR_PAIR(30)
#define COLOUR_THEM COLOR_PAIR(31)
#define COLOUR_ROOMINFO COLOR_PAIR(40)
#define COLOUR_ONLINE COLOR_PAIR(50)
#define COLOUR_OFFLINE COLOR_PAIR(51)
#define COLOUR_AWAY COLOR_PAIR(52)
#define COLOUR_CHAT COLOR_PAIR(53)
#define COLOUR_DND COLOR_PAIR(54)
#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)
#define COLOUR_TEXT COLOR_PAIR(1)
#define COLOUR_SPLASH COLOR_PAIR(2)
#define COLOUR_ERROR COLOR_PAIR(3)
#define COLOUR_INCOMING COLOR_PAIR(4)
#define COLOUR_INPUT_TEXT COLOR_PAIR(5)
#define COLOUR_TIME COLOR_PAIR(6)
#define COLOUR_TITLE_TEXT COLOR_PAIR(7)
#define COLOUR_TITLE_BRACKET COLOR_PAIR(8)
#define COLOUR_TITLE_UNENCRYPTED COLOR_PAIR(9)
#define COLOUR_TITLE_ENCRYPTED COLOR_PAIR(10)
#define COLOUR_TITLE_UNTRUSTED COLOR_PAIR(11)
#define COLOUR_TITLE_TRUSTED COLOR_PAIR(12)
#define COLOUR_STATUS_TEXT COLOR_PAIR(13)
#define COLOUR_STATUS_BRACKET COLOR_PAIR(14)
#define COLOUR_STATUS_ACTIVE COLOR_PAIR(15)
#define COLOUR_STATUS_NEW COLOR_PAIR(16)
#define COLOUR_ME COLOR_PAIR(17)
#define COLOUR_THEM COLOR_PAIR(18)
#define COLOUR_ROOMINFO COLOR_PAIR(19)
#define COLOUR_ONLINE COLOR_PAIR(20)
#define COLOUR_OFFLINE COLOR_PAIR(21)
#define COLOUR_AWAY COLOR_PAIR(22)
#define COLOUR_CHAT COLOR_PAIR(23)
#define COLOUR_DND COLOR_PAIR(24)
#define COLOUR_XA COLOR_PAIR(25)
#define COLOUR_TYPING COLOR_PAIR(26)
#define COLOUR_GONE COLOR_PAIR(27)
#define COLOUR_SUBSCRIBED COLOR_PAIR(28)
#define COLOUR_UNSUBSCRIBED COLOR_PAIR(29)
#define COLOUR_OTR_STARTED_TRUSTED COLOR_PAIR(30)
#define COLOUR_OTR_STARTED_UNTRUSTED COLOR_PAIR(31)
#define COLOUR_OTR_ENDED COLOR_PAIR(32)
#define COLOUR_OTR_TRUSTED COLOR_PAIR(33)
#define COLOUR_OTR_UNTRUSTED COLOR_PAIR(34)
void theme_init(const char * const theme_name);
void theme_init_colours(void);

View File

@ -43,12 +43,6 @@ cb_policy(void *opdata, ConnContext *context)
return OTRL_POLICY_DEFAULT ;
}
static void
cb_create_privkey(void *opdata, const char *accountname,
const char *protocol)
{
}
static int
cb_is_logged_in(void *opdata, const char *accountname,
const char *protocol, const char *recipient)
@ -68,13 +62,6 @@ cb_inject_message(void *opdata, const char *accountname,
message_send(message, recipient);
}
static void
cb_notify(void *opdata, OtrlNotifyLevel level,
const char *accountname, const char *protocol, const char *username,
const char *title, const char *primary, const char *secondary)
{
}
static int
cb_display_otr_message(void *opdata, const char *accountname,
const char *protocol, const char *username, const char *msg)
@ -83,28 +70,6 @@ cb_display_otr_message(void *opdata, const char *accountname,
return 0;
}
static const char *
cb_protocol_name(void *opdata, const char *protocol)
{
return "xmpp";
}
static void
cb_new_fingerprint(void *opdata, OtrlUserState us, const char *accountname,
const char *protocol, const char *username, unsigned char fingerprint[20])
{
}
static void
cb_protocol_name_free(void *opdata, const char *protocol_name)
{
}
static void
cb_update_context_list(void *opdata)
{
}
static void
cb_write_fingerprints(void *opdata)
{
@ -134,21 +99,6 @@ cb_gone_secure(void *opdata, ConnContext *context)
ui_gone_secure(context->username, otr_is_trusted(context->username));
}
static void
cb_gone_insecure(void *opdata, ConnContext *context)
{
}
static void
cb_still_secure(void *opdata, ConnContext *context, int is_reply)
{
}
static void
cb_log_message(void *opdata, const char *message)
{
}
void
otr_init(void)
{
@ -156,20 +106,11 @@ otr_init(void)
OTRL_INIT;
ops.policy = cb_policy;
ops.create_privkey = cb_create_privkey;
ops.is_logged_in = cb_is_logged_in;
ops.inject_message = cb_inject_message;
ops.notify = cb_notify;
ops.display_otr_message = cb_display_otr_message;
ops.update_context_list = cb_update_context_list;
ops.protocol_name = cb_protocol_name;
ops.protocol_name_free = cb_protocol_name_free;
ops.new_fingerprint = cb_new_fingerprint;
ops.write_fingerprints = cb_write_fingerprints;
ops.gone_secure = cb_gone_secure;
ops.gone_insecure = cb_gone_insecure;
ops.still_secure = cb_still_secure;
ops.log_message = cb_log_message;
data_loaded = FALSE;
}
@ -189,9 +130,9 @@ otr_on_connect(ProfAccount *account)
g_string_append(basedir, "/");
if (!mkdir_recursive(basedir->str)) {
g_string_free(basedir, TRUE);
log_error("Could not create %s for account %s.", basedir->str, jid);
cons_show_error("Could not create %s for account %s.", basedir->str, jid);
g_string_free(basedir, TRUE);
return;
}
@ -270,9 +211,9 @@ otr_keygen(ProfAccount *account)
g_string_append(basedir, "/");
if (!mkdir_recursive(basedir->str)) {
g_string_free(basedir, TRUE);
log_error("Could not create %s for account %s.", basedir->str, jid);
cons_show_error("Could not create %s for account %s.", basedir->str, jid);
g_string_free(basedir, TRUE);
return;
}
@ -488,14 +429,14 @@ otr_encrypt_message(const char * const to, const char * const message)
}
char *
otr_decrypt_message(const char * const from, const char * const message)
otr_decrypt_message(const char * const from, const char * const message, gboolean *was_decrypted)
{
char *decrypted = NULL;
OtrlTLV *tlvs = NULL;
OtrlTLV *tlv = NULL;
int result = otrl_message_receiving(user_state, &ops, NULL, jid, "xmpp", from, message, &decrypted, &tlvs, NULL, NULL);
// internal libotr message, ignore
// internal libotr message
if (result == 1) {
tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED);
if (tlv) {
@ -511,10 +452,12 @@ otr_decrypt_message(const char * const from, const char * const message)
// message was decrypted, return to user
} else if (decrypted != NULL) {
*was_decrypted = TRUE;
return decrypted;
// normal non OTR message
} else {
*was_decrypted = FALSE;
return strdup(message);
}
}

View File

@ -42,7 +42,8 @@ char * otr_get_my_fingerprint(void);
char * otr_get_their_fingerprint(const char * const recipient);
char * otr_encrypt_message(const char * const to, const char * const message);
char * otr_decrypt_message(const char * const from, const char * const message);
char * otr_decrypt_message(const char * const from, const char * const message,
gboolean *was_decrypted);
void otr_free_message(char *message);

View File

@ -231,7 +231,7 @@ _handle_idle_time()
RESOURCE_AWAY);
cons_show("Idle for %d minutes, status set to away (priority %d), \"%s\".",
prefs_get_autoaway_time(), pri, prefs_get_string(PREF_AUTOAWAY_MESSAGE));
title_bar_set_status(CONTACT_AWAY);
title_bar_set_presence(CONTACT_AWAY);
ui_current_page_off();
} else {
int pri =
@ -239,7 +239,7 @@ _handle_idle_time()
RESOURCE_AWAY);
cons_show("Idle for %d minutes, status set to away (priority %d).",
prefs_get_autoaway_time(), pri);
title_bar_set_status(CONTACT_AWAY);
title_bar_set_presence(CONTACT_AWAY);
ui_current_page_off();
}
@ -263,11 +263,11 @@ _handle_idle_time()
accounts_get_priority_for_presence_type(jabber_get_account_name(),
RESOURCE_ONLINE);
cons_show("No longer idle, status set to online (priority %d).", pri);
title_bar_set_status(CONTACT_ONLINE);
title_bar_set_presence(CONTACT_ONLINE);
ui_current_page_off();
} else if (strcmp(prefs_get_string(PREF_AUTOAWAY_MODE), "idle") == 0) {
presence_update(RESOURCE_ONLINE, NULL, 0);
title_bar_set_status(CONTACT_ONLINE);
title_bar_set_presence(CONTACT_ONLINE);
}
}
}

View File

@ -59,7 +59,7 @@ handle_login_account_success(char *account_name)
resource_presence_t resource_presence = accounts_get_login_presence(account->name);
contact_presence_t contact_presence = contact_presence_from_resource_presence(resource_presence);
cons_show_login_success(account);
title_bar_set_status(contact_presence);
title_bar_set_presence(contact_presence);
log_info("%s logged in successfully", account->jid);
ui_current_page_off();
status_bar_print_message(account->jid);
@ -189,9 +189,11 @@ handle_incoming_message(char *from, char *message, gboolean priv)
char *plugin_message = NULL;
#ifdef PROF_HAVE_LIBOTR
gboolean was_decrypted = FALSE;
char *decrypted;
if (!priv) {
decrypted = otr_decrypt_message(from, message);
decrypted = otr_decrypt_message(from, message, &was_decrypted);
// internal OTR message
if (decrypted == NULL) {
return;
}
@ -216,7 +218,13 @@ handle_incoming_message(char *from, char *message, gboolean priv)
Jid *from_jid = jid_create(from);
const char *jid = jabber_get_fulljid();
Jid *jidp = jid_create(jid);
chat_log_chat(jidp->barejid, from_jid->barejid, plugin_message, PROF_IN_LOG, NULL);
if (!was_decrypted || (strcmp(prefs_get_string(PREF_OTR_LOG), "on") == 0)) {
chat_log_chat(jidp->barejid, from_jid->barejid, plugin_message, PROF_IN_LOG, NULL);
} else if (strcmp(prefs_get_string(PREF_OTR_LOG), "redact") == 0) {
chat_log_chat(jidp->barejid, from_jid->barejid, "[redacted]", PROF_IN_LOG, NULL);
}
jid_destroy(jidp);
jid_destroy(from_jid);
}

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
_cons_show_ui_prefs(void)
{
@ -996,6 +1006,7 @@ _cons_show_ui_prefs(void)
cons_mouse_setting();
cons_statuses_setting();
cons_titlebar_setting();
cons_otrwarn_setting();
wins_refresh_console();
cons_alert();
@ -1133,6 +1144,20 @@ _cons_grlog_setting(void)
cons_show("Groupchat logging (/grlog) : OFF");
}
static void
_cons_otr_log_setting(void)
{
char *value = prefs_get_string(PREF_OTR_LOG);
if (strcmp(value, "on") == 0) {
cons_show("OTR logging (/otr log) : ON");
} else if (strcmp(value, "off") == 0) {
cons_show("OTR logging (/otr log) : OFF");
} else {
cons_show("OTR logging (/otr log) : Redacted");
}
}
static void
_cons_show_log_prefs(void)
{
@ -1141,6 +1166,7 @@ _cons_show_log_prefs(void)
cons_log_setting();
cons_chlog_setting();
cons_grlog_setting();
cons_otr_log_setting();
wins_refresh_console();
cons_alert();
@ -1548,6 +1574,8 @@ console_init_module(void)
cons_log_setting = _cons_log_setting;
cons_chlog_setting = _cons_chlog_setting;
cons_grlog_setting = _cons_grlog_setting;
cons_otr_log_setting = _cons_otr_log_setting;
cons_otrwarn_setting = _cons_otrwarn_setting;
cons_show_log_prefs = _cons_show_log_prefs;
cons_autoaway_setting = _cons_autoaway_setting;
cons_show_presence_prefs = _cons_show_presence_prefs;

View File

@ -192,7 +192,6 @@ _ui_contact_typing(const char * const barejid)
// in chat window with user
} else {
title_bar_set_typing(TRUE);
title_bar_draw();
int num = wins_get_num(window);
status_bar_active(num);
@ -263,7 +262,6 @@ _ui_incoming_msg(const char * const from, const char * const message,
if (wins_is_current(window)) {
win_print_incoming_message(window, tv_stamp, display_from, new_message);
title_bar_set_typing(FALSE);
title_bar_draw();
status_bar_active(num);
wins_refresh_current();
@ -417,7 +415,7 @@ static void
_ui_disconnected(void)
{
wins_lost_connection();
title_bar_set_status(CONTACT_OFFLINE);
title_bar_set_presence(CONTACT_OFFLINE);
status_bar_clear_message();
status_bar_refresh();
}
@ -530,15 +528,6 @@ _get_recipient_string(ProfWin *window)
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;
}
@ -554,14 +543,13 @@ _ui_switch_win(const int i)
new_current->unread = 0;
if (i == 1) {
title_bar_title();
title_bar_console();
status_bar_current(1);
status_bar_active(1);
} else {
GString *recipient_str = _get_recipient_string(new_current);
title_bar_set_recipient(recipient_str->str);
g_string_free(recipient_str, TRUE);
title_bar_draw();
status_bar_current(i);
status_bar_active(i);
}
@ -581,14 +569,13 @@ _ui_next_win(void)
new_current->unread = 0;
if (i == 1) {
title_bar_title();
title_bar_console();
status_bar_current(1);
status_bar_active(1);
} else {
GString *recipient_str = _get_recipient_string(new_current);
title_bar_set_recipient(recipient_str->str);
g_string_free(recipient_str, TRUE);
title_bar_draw();
status_bar_current(i);
status_bar_active(i);
}
@ -602,13 +589,16 @@ _ui_gone_secure(const char * const recipient, gboolean trusted)
if (window != NULL) {
window->is_otr = TRUE;
window->is_trusted = trusted;
win_vprint_line(window, '!', 0, "OTR session started.");
if (trusted) {
win_vprint_line(window, '!', COLOUR_OTR_STARTED_TRUSTED, "OTR session started (trusted).");
} else {
win_vprint_line(window, '!', COLOUR_OTR_STARTED_UNTRUSTED, "OTR session started (untrusted).");
}
if (wins_is_current(window)) {
GString *recipient_str = _get_recipient_string(window);
title_bar_set_recipient(recipient_str->str);
g_string_free(recipient_str, TRUE);
title_bar_draw();
wins_refresh_current();
}
}
@ -621,13 +611,12 @@ _ui_gone_insecure(const char * const recipient)
if (window != NULL) {
window->is_otr = FALSE;
window->is_trusted = FALSE;
win_vprint_line(window, '!', 0, "OTR session ended.");
win_vprint_line(window, '!', COLOUR_OTR_ENDED, "OTR session ended.");
if (wins_is_current(window)) {
GString *recipient_str = _get_recipient_string(window);
title_bar_set_recipient(recipient_str->str);
g_string_free(recipient_str, TRUE);
title_bar_draw();
wins_refresh_current();
}
}
@ -640,12 +629,12 @@ _ui_trust(const char * const recipient)
if (window != NULL) {
window->is_otr = TRUE;
window->is_trusted = TRUE;
win_vprint_line(window, '!', COLOUR_OTR_TRUSTED, "OTR session trusted.");
if (wins_is_current(window)) {
GString *recipient_str = _get_recipient_string(window);
title_bar_set_recipient(recipient_str->str);
g_string_free(recipient_str, TRUE);
title_bar_draw();
wins_refresh_current();
}
}
@ -658,12 +647,12 @@ _ui_untrust(const char * const recipient)
if (window != NULL) {
window->is_otr = TRUE;
window->is_trusted = FALSE;
win_vprint_line(window, '!', COLOUR_OTR_UNTRUSTED, "OTR session untrusted.");
if (wins_is_current(window)) {
GString *recipient_str = _get_recipient_string(window);
title_bar_set_recipient(recipient_str->str);
g_string_free(recipient_str, TRUE);
title_bar_draw();
wins_refresh_current();
}
}
@ -681,14 +670,13 @@ _ui_previous_win(void)
new_current->unread = 0;
if (i == 1) {
title_bar_title();
title_bar_console();
status_bar_current(1);
status_bar_active(1);
} else {
GString *recipient_str = _get_recipient_string(new_current);
title_bar_set_recipient(recipient_str->str);
g_string_free(recipient_str, TRUE);
title_bar_draw();
status_bar_current(i);
status_bar_active(i);
}
@ -707,18 +695,18 @@ _ui_close_current(void)
int current_index = wins_get_current_num();
status_bar_inactive(current_index);
wins_close_current();
title_bar_console();
status_bar_current(1);
status_bar_active(1);
title_bar_title();
}
static void
_ui_close_win(int index)
{
wins_close_by_num(index);
title_bar_console();
status_bar_current(1);
status_bar_active(1);
title_bar_title();
wins_refresh_current();
}
@ -842,6 +830,20 @@ _ui_current_print_line(const char * const msg, ...)
win_refresh(current);
}
static void
_ui_current_print_formatted_line(const char show_char, int attrs, const char * const msg, ...)
{
ProfWin *current = wins_get_current();
va_list arg;
va_start(arg, msg);
GString *fmt_msg = g_string_new(NULL);
g_string_vprintf(fmt_msg, msg, arg);
win_print_line(current, show_char, attrs, fmt_msg->str);
va_end(arg);
g_string_free(fmt_msg, TRUE);
win_refresh(current);
}
static void
_ui_current_error_line(const char * const msg)
{
@ -1699,6 +1701,7 @@ ui_init_module(void)
ui_recipient = _ui_recipient;
ui_current_recipient = _ui_current_recipient;
ui_current_print_line = _ui_current_print_line;
ui_current_print_formatted_line = _ui_current_print_formatted_line;
ui_current_error_line = _ui_current_error_line;
ui_current_page_off = _ui_current_page_off;
ui_print_error_from_recipient = _ui_print_error_from_recipient;

View File

@ -25,39 +25,48 @@
#include "common.h"
#include "config/theme.h"
#include "config/preferences.h"
#include "ui/ui.h"
#include "ui/windows.h"
#include "ui/window.h"
static WINDOW *title_bar;
#define CONSOLE_TITLE "Profanity. Type /help for help information."
static WINDOW *win;
static char *current_title = NULL;
static char *recipient = NULL;
static GTimer *typing_elapsed;
static int dirty;
static contact_presence_t current_status;
static char *current_recipient = NULL;
static contact_presence_t current_presence;
static void _title_bar_draw_title(void);
static void _title_bar_draw_status(void);
static gboolean typing;
static GTimer *typing_elapsed;
static void _title_bar_draw(void);
static void
_create_title_bar(void)
{
int cols = getmaxx(stdscr);
title_bar = newwin(1, cols, 0, 0);
wbkgd(title_bar, COLOUR_TITLE_TEXT);
title_bar_title();
title_bar_set_status(CONTACT_OFFLINE);
dirty = TRUE;
win = newwin(1, cols, 0, 0);
wbkgd(win, COLOUR_TITLE_TEXT);
title_bar_console();
title_bar_set_presence(CONTACT_OFFLINE);
wrefresh(win);
inp_put_back();
}
static void
_title_bar_title(void)
_title_bar_console(void)
{
werase(title_bar);
recipient = NULL;
werase(win);
current_recipient = NULL;
typing = FALSE;
typing_elapsed = NULL;
title_bar_show("Profanity. Type /help for help information.");
_title_bar_draw_status();
dirty = TRUE;
free(current_title);
current_title = strdup(CONSOLE_TITLE);
_title_bar_draw();
}
static void
@ -65,84 +74,55 @@ _title_bar_resize(void)
{
int cols = getmaxx(stdscr);
wresize(title_bar, 1, cols);
wbkgd(title_bar, COLOUR_TITLE_TEXT);
werase(title_bar);
_title_bar_draw_title();
_title_bar_draw_status();
dirty = TRUE;
wresize(win, 1, cols);
wbkgd(win, COLOUR_TITLE_TEXT);
_title_bar_draw();
}
static void
_title_bar_refresh(void)
{
if (recipient != NULL) {
if (current_recipient != NULL) {
if (typing_elapsed != NULL) {
gdouble seconds = g_timer_elapsed(typing_elapsed, NULL);
if (seconds >= 10) {
if (current_title != NULL) {
free(current_title);
}
current_title = (char *) malloc(strlen(recipient) + 1);
strcpy(current_title, recipient);
title_bar_draw();
typing = FALSE;
g_timer_destroy(typing_elapsed);
typing_elapsed = NULL;
dirty = TRUE;
_title_bar_draw();
}
}
}
if (dirty) {
wrefresh(title_bar);
inp_put_back();
dirty = FALSE;
}
}
static void
_title_bar_show(const char * const title)
_title_bar_set_presence(contact_presence_t presence)
{
if (current_title != NULL)
free(current_title);
current_title = (char *) malloc(strlen(title) + 1);
strcpy(current_title, title);
_title_bar_draw_title();
current_presence = presence;
_title_bar_draw();
}
static void
_title_bar_set_status(contact_presence_t status)
{
current_status = status;
_title_bar_draw_status();
}
static void
_title_bar_set_recipient(const char * const from)
_title_bar_set_recipient(const char * const recipient)
{
if (typing_elapsed != NULL) {
g_timer_destroy(typing_elapsed);
typing_elapsed = NULL;
}
free(recipient);
recipient = strdup(from);
if (current_title != NULL) {
free(current_title);
typing = FALSE;
}
current_title = (char *) malloc(strlen(from) + 1);
strcpy(current_title, from);
free(current_recipient);
current_recipient = strdup(recipient);
dirty = TRUE;
free(current_title);
current_title = strdup(recipient);
_title_bar_draw();
}
static void
@ -156,89 +136,134 @@ _title_bar_set_typing(gboolean is_typing)
}
}
if (current_title != NULL) {
free(current_title);
}
typing = is_typing;
if (is_typing) {
current_title = (char *) malloc(strlen(recipient) + 13);
sprintf(current_title, "%s (typing...)", recipient);
} else {
current_title = (char *) malloc(strlen(recipient) + 1);
strcpy(current_title, recipient);
}
dirty = TRUE;
_title_bar_draw();
}
static void
_title_bar_draw(void)
{
werase(title_bar);
_title_bar_draw_status();
_title_bar_draw_title();
}
werase(win);
static void
_title_bar_draw_status(void)
{
// show title
wmove(win, 0, 0);
int i;
for (i = 0; i < 45; i++)
waddch(win, ' ');
mvwprintw(win, 0, 0, " %s", current_title);
#ifdef PROF_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) {
wprintw(win, " (typing...)");
}
// show presence
int cols = getmaxx(stdscr);
wattron(title_bar, COLOUR_TITLE_BRACKET);
mvwaddch(title_bar, 0, cols - 14, '[');
wattroff(title_bar, COLOUR_TITLE_BRACKET);
wattron(win, COLOUR_TITLE_BRACKET);
mvwaddch(win, 0, cols - 14, '[');
wattroff(win, COLOUR_TITLE_BRACKET);
switch (current_status)
switch (current_presence)
{
case CONTACT_ONLINE:
mvwprintw(title_bar, 0, cols - 13, " ...online ");
mvwprintw(win, 0, cols - 13, " ...online ");
break;
case CONTACT_AWAY:
mvwprintw(title_bar, 0, cols - 13, " .....away ");
mvwprintw(win, 0, cols - 13, " .....away ");
break;
case CONTACT_DND:
mvwprintw(title_bar, 0, cols - 13, " ......dnd ");
mvwprintw(win, 0, cols - 13, " ......dnd ");
break;
case CONTACT_CHAT:
mvwprintw(title_bar, 0, cols - 13, " .....chat ");
mvwprintw(win, 0, cols - 13, " .....chat ");
break;
case CONTACT_XA:
mvwprintw(title_bar, 0, cols - 13, " .......xa ");
mvwprintw(win, 0, cols - 13, " .......xa ");
break;
case CONTACT_OFFLINE:
mvwprintw(title_bar, 0, cols - 13, " ..offline ");
mvwprintw(win, 0, cols - 13, " ..offline ");
break;
}
wattron(title_bar, COLOUR_TITLE_BRACKET);
mvwaddch(title_bar, 0, cols - 2, ']');
wattroff(title_bar, COLOUR_TITLE_BRACKET);
wattron(win, COLOUR_TITLE_BRACKET);
mvwaddch(win, 0, cols - 2, ']');
wattroff(win, COLOUR_TITLE_BRACKET);
dirty = TRUE;
}
static void
_title_bar_draw_title(void)
{
wmove(title_bar, 0, 0);
int i;
for (i = 0; i < 45; i++)
waddch(title_bar, ' ');
mvwprintw(title_bar, 0, 0, " %s", current_title);
dirty = TRUE;
wrefresh(win);
inp_put_back();
}
void
titlebar_init_module(void)
{
create_title_bar = _create_title_bar;
title_bar_title = _title_bar_title;
title_bar_console = _title_bar_console;
title_bar_resize = _title_bar_resize;
title_bar_refresh = _title_bar_refresh;
title_bar_show = _title_bar_show;
title_bar_set_status = _title_bar_set_status;
title_bar_set_presence = _title_bar_set_presence;
title_bar_set_recipient = _title_bar_set_recipient;
title_bar_set_typing = _title_bar_set_typing;
title_bar_draw = _title_bar_draw;
}

View File

@ -85,6 +85,7 @@ gboolean (*ui_current_win_is_otr)(void);
void (*ui_current_set_otr)(gboolean value);
char* (*ui_current_recipient)(void);
void (*ui_current_print_line)(const char * const msg, ...);
void (*ui_current_print_formatted_line)(const char show_chat, int attrs, const char * const msg, ...);
void (*ui_current_error_line)(const char * const msg);
void (*ui_current_page_off)(void);
@ -154,12 +155,10 @@ void (*create_input_window)(void);
// title bar actions
void (*title_bar_refresh)(void);
void (*title_bar_resize)(void);
void (*title_bar_show)(const char * const title);
void (*title_bar_title)(void);
void (*title_bar_set_status)(contact_presence_t status);
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_set_typing)(gboolean is_typing);
void (*title_bar_draw)(void);
// console window actions
void (*cons_show)(const char * const msg, ...);
@ -222,6 +221,8 @@ void (*cons_history_setting)(void);
void (*cons_log_setting)(void);
void (*cons_chlog_setting)(void);
void (*cons_grlog_setting)(void);
void (*cons_otr_log_setting)(void);
void (*cons_otrwarn_setting)(void);
void (*cons_autoaway_setting)(void);
void (*cons_reconnect_setting)(void);
void (*cons_autoping_setting)(void);