1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-09-08 19:34:14 -04:00

Added /presence command to show contacts presence

This commit is contained in:
James Booth 2014-11-07 22:38:34 +00:00
parent 571db23150
commit 373b3a2d7c
12 changed files with 189 additions and 48 deletions

View File

@ -570,6 +570,14 @@ static struct cmd_t command_defs[] =
"If the terminal does not support sounds, it may attempt to flash the screen instead.",
NULL } } },
{ "/presence",
cmd_presence, parse_args, 1, 1, &cons_presence_setting,
{ "/presence on|off", "Show the contacts presence in the titlebar.",
{ "/presence on|off",
"----------------",
"Switch display of the contacts presence on or off.",
NULL } } },
{ "/notify",
cmd_notify, parse_args, 2, 3, &cons_notify_setting,
{ "/notify [type value]|[type setting value]", "Control various desktop noficiations.",
@ -1765,7 +1773,7 @@ _cmd_complete_parameters(char *input, int *size)
// autocomplete boolean settings
gchar *boolean_choices[] = { "/beep", "/intype", "/states", "/outtype",
"/flash", "/splash", "/chlog", "/grlog", "/mouse", "/history", "/titlebar",
"/vercheck", "/privileges" };
"/vercheck", "/privileges", "/presence" };
for (i = 0; i < ARRAY_SIZE(boolean_choices); i++) {
result = autocomplete_param_with_func(input, size, boolean_choices[i],

View File

@ -620,7 +620,7 @@ cmd_help(gchar **args, struct cmd_help_t help)
"/chlog", "/flash", "/gone", "/grlog", "/history", "/intype",
"/log", "/mouse", "/notify", "/outtype", "/prefs", "/priority",
"/reconnect", "/roster", "/splash", "/states", "/statuses", "/theme",
"/titlebar", "/vercheck", "/privileges", "/occupants" };
"/titlebar", "/vercheck", "/privileges", "/occupants", "/presence" };
_cmd_show_filtered_help("Settings commands", filter, ARRAY_SIZE(filter));
} else if (strcmp(args[0], "navigation") == 0) {
@ -2922,6 +2922,12 @@ cmd_beep(gchar **args, struct cmd_help_t help)
return _cmd_set_boolean_preference(args[0], help, "Sound", PREF_BEEP);
}
gboolean
cmd_presence(gchar **args, struct cmd_help_t help)
{
return _cmd_set_boolean_preference(args[0], help, "Contact presence", PREF_PRESENCE);
}
gboolean
cmd_states(gchar **args, struct cmd_help_t help)
{

View File

@ -132,6 +132,7 @@ gboolean cmd_subject(gchar **args, struct cmd_help_t help);
gboolean cmd_affiliation(gchar **args, struct cmd_help_t help);
gboolean cmd_role(gchar **args, struct cmd_help_t help);
gboolean cmd_privileges(gchar **args, struct cmd_help_t help);
gboolean cmd_presence(gchar **args, struct cmd_help_t help);
gboolean cmd_form_field(char *tag, gchar **args);

View File

@ -451,6 +451,7 @@ _get_group(preference_t pref)
case PREF_STATUSES_CHAT:
case PREF_STATUSES_MUC:
case PREF_MUC_PRIVILEGES:
case PREF_PRESENCE:
return PREF_GROUP_UI;
case PREF_STATES:
case PREF_OUTTYPE:
@ -567,6 +568,8 @@ _get_key(preference_t pref)
return "rotate";
case PREF_LOG_SHARED:
return "shared";
case PREF_PRESENCE:
return "presence";
default:
return NULL;
}
@ -588,6 +591,7 @@ _get_default_boolean(preference_t pref)
case PREF_SPLASH:
case PREF_OCCUPANTS:
case PREF_MUC_PRIVILEGES:
case PREF_PRESENCE:
return TRUE;
default:
return FALSE;

View File

@ -59,6 +59,7 @@ typedef enum {
PREF_MOUSE,
PREF_OCCUPANTS,
PREF_MUC_PRIVILEGES,
PREF_PRESENCE,
PREF_STATUSES,
PREF_STATUSES_CONSOLE,
PREF_STATUSES_CHAT,

View File

@ -80,6 +80,12 @@ static struct colours_t {
NCURSES_COLOR_T titlebarencrypted;
NCURSES_COLOR_T titlebaruntrusted;
NCURSES_COLOR_T titlebartrusted;
NCURSES_COLOR_T titlebaronline;
NCURSES_COLOR_T titlebaroffline;
NCURSES_COLOR_T titlebaraway;
NCURSES_COLOR_T titlebarxa;
NCURSES_COLOR_T titlebardnd;
NCURSES_COLOR_T titlebarchat;
NCURSES_COLOR_T statusbartext;
NCURSES_COLOR_T statusbarbrackets;
NCURSES_COLOR_T statusbaractive;
@ -206,43 +212,49 @@ theme_init_colours(void)
init_pair(12, colour_prefs.titlebarencrypted, colour_prefs.titlebar);
init_pair(13, colour_prefs.titlebaruntrusted, colour_prefs.titlebar);
init_pair(14, colour_prefs.titlebartrusted, colour_prefs.titlebar);
init_pair(15, colour_prefs.titlebaronline, colour_prefs.titlebar);
init_pair(16, colour_prefs.titlebaroffline, colour_prefs.titlebar);
init_pair(17, colour_prefs.titlebaraway, colour_prefs.titlebar);
init_pair(18, colour_prefs.titlebarchat, colour_prefs.titlebar);
init_pair(19, colour_prefs.titlebardnd, colour_prefs.titlebar);
init_pair(20, colour_prefs.titlebarxa, colour_prefs.titlebar);
// status bar
init_pair(15, colour_prefs.statusbartext, colour_prefs.statusbar);
init_pair(16, colour_prefs.statusbarbrackets, colour_prefs.statusbar);
init_pair(17, colour_prefs.statusbaractive, colour_prefs.statusbar);
init_pair(18, colour_prefs.statusbarnew, colour_prefs.statusbar);
init_pair(21, colour_prefs.statusbartext, colour_prefs.statusbar);
init_pair(22, colour_prefs.statusbarbrackets, colour_prefs.statusbar);
init_pair(23, colour_prefs.statusbaractive, colour_prefs.statusbar);
init_pair(24, colour_prefs.statusbarnew, colour_prefs.statusbar);
// chat
init_pair(19, colour_prefs.me, colour_prefs.bkgnd);
init_pair(20, colour_prefs.them, colour_prefs.bkgnd);
init_pair(25, colour_prefs.me, colour_prefs.bkgnd);
init_pair(26, colour_prefs.them, colour_prefs.bkgnd);
// room chat
init_pair(21, colour_prefs.roominfo, colour_prefs.bkgnd);
init_pair(22, colour_prefs.roommention, colour_prefs.bkgnd);
init_pair(27, colour_prefs.roominfo, colour_prefs.bkgnd);
init_pair(28, colour_prefs.roommention, colour_prefs.bkgnd);
// statuses
init_pair(23, colour_prefs.online, colour_prefs.bkgnd);
init_pair(24, colour_prefs.offline, colour_prefs.bkgnd);
init_pair(25, colour_prefs.away, colour_prefs.bkgnd);
init_pair(26, colour_prefs.chat, colour_prefs.bkgnd);
init_pair(27, colour_prefs.dnd, colour_prefs.bkgnd);
init_pair(28, colour_prefs.xa, colour_prefs.bkgnd);
init_pair(29, colour_prefs.online, colour_prefs.bkgnd);
init_pair(30, colour_prefs.offline, colour_prefs.bkgnd);
init_pair(31, colour_prefs.away, colour_prefs.bkgnd);
init_pair(32, colour_prefs.chat, colour_prefs.bkgnd);
init_pair(33, colour_prefs.dnd, colour_prefs.bkgnd);
init_pair(34, colour_prefs.xa, colour_prefs.bkgnd);
// states
init_pair(29, colour_prefs.typing, colour_prefs.bkgnd);
init_pair(30, colour_prefs.gone, colour_prefs.bkgnd);
init_pair(35, colour_prefs.typing, colour_prefs.bkgnd);
init_pair(36, colour_prefs.gone, colour_prefs.bkgnd);
// subscription status
init_pair(31, colour_prefs.subscribed, colour_prefs.bkgnd);
init_pair(32, colour_prefs.unsubscribed, colour_prefs.bkgnd);
init_pair(37, colour_prefs.subscribed, colour_prefs.bkgnd);
init_pair(38, colour_prefs.unsubscribed, colour_prefs.bkgnd);
// otr messages
init_pair(33, colour_prefs.otrstartedtrusted, colour_prefs.bkgnd);
init_pair(34, colour_prefs.otrstarteduntrusted, colour_prefs.bkgnd);
init_pair(35, colour_prefs.otrended, colour_prefs.bkgnd);
init_pair(36, colour_prefs.otrtrusted, colour_prefs.bkgnd);
init_pair(37, colour_prefs.otruntrusted, colour_prefs.bkgnd);
init_pair(39, colour_prefs.otrstartedtrusted, colour_prefs.bkgnd);
init_pair(40, colour_prefs.otrstarteduntrusted, colour_prefs.bkgnd);
init_pair(41, colour_prefs.otrended, colour_prefs.bkgnd);
init_pair(42, colour_prefs.otrtrusted, colour_prefs.bkgnd);
init_pair(43, colour_prefs.otruntrusted, colour_prefs.bkgnd);
}
static NCURSES_COLOR_T
@ -313,6 +325,30 @@ _load_colours(void)
_set_colour(titlebartrusted_val, &colour_prefs.titlebartrusted, COLOR_WHITE);
g_free(titlebartrusted_val);
gchar *titlebaronline_val = g_key_file_get_string(theme, "colours", "titlebar.online", NULL);
_set_colour(titlebaronline_val, &colour_prefs.titlebaronline, COLOR_WHITE);
g_free(titlebaronline_val);
gchar *titlebaroffline_val = g_key_file_get_string(theme, "colours", "titlebar.offline", NULL);
_set_colour(titlebaroffline_val, &colour_prefs.titlebaroffline, COLOR_WHITE);
g_free(titlebaroffline_val);
gchar *titlebaraway_val = g_key_file_get_string(theme, "colours", "titlebar.away", NULL);
_set_colour(titlebaraway_val, &colour_prefs.titlebaraway, COLOR_WHITE);
g_free(titlebaraway_val);
gchar *titlebarchat_val = g_key_file_get_string(theme, "colours", "titlebar.chat", NULL);
_set_colour(titlebarchat_val, &colour_prefs.titlebarchat, COLOR_WHITE);
g_free(titlebarchat_val);
gchar *titlebardnd_val = g_key_file_get_string(theme, "colours", "titlebar.dnd", NULL);
_set_colour(titlebardnd_val, &colour_prefs.titlebardnd, COLOR_WHITE);
g_free(titlebardnd_val);
gchar *titlebarxa_val = g_key_file_get_string(theme, "colours", "titlebar.xa", NULL);
_set_colour(titlebarxa_val, &colour_prefs.titlebarxa, COLOR_WHITE);
g_free(titlebarxa_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);

View File

@ -58,29 +58,35 @@
#define COLOUR_TITLE_ENCRYPTED COLOR_PAIR(12)
#define COLOUR_TITLE_UNTRUSTED COLOR_PAIR(13)
#define COLOUR_TITLE_TRUSTED COLOR_PAIR(14)
#define COLOUR_STATUS_TEXT COLOR_PAIR(15)
#define COLOUR_STATUS_BRACKET COLOR_PAIR(16)
#define COLOUR_STATUS_ACTIVE COLOR_PAIR(17)
#define COLOUR_STATUS_NEW COLOR_PAIR(18)
#define COLOUR_ME COLOR_PAIR(19)
#define COLOUR_THEM COLOR_PAIR(20)
#define COLOUR_ROOMINFO COLOR_PAIR(21)
#define COLOUR_ROOMMENTION COLOR_PAIR(22)
#define COLOUR_ONLINE COLOR_PAIR(23)
#define COLOUR_OFFLINE COLOR_PAIR(24)
#define COLOUR_AWAY COLOR_PAIR(25)
#define COLOUR_CHAT COLOR_PAIR(26)
#define COLOUR_DND COLOR_PAIR(27)
#define COLOUR_XA COLOR_PAIR(28)
#define COLOUR_TYPING COLOR_PAIR(29)
#define COLOUR_GONE COLOR_PAIR(30)
#define COLOUR_SUBSCRIBED COLOR_PAIR(31)
#define COLOUR_UNSUBSCRIBED COLOR_PAIR(32)
#define COLOUR_OTR_STARTED_TRUSTED COLOR_PAIR(33)
#define COLOUR_OTR_STARTED_UNTRUSTED COLOR_PAIR(34)
#define COLOUR_OTR_ENDED COLOR_PAIR(35)
#define COLOUR_OTR_TRUSTED COLOR_PAIR(36)
#define COLOUR_OTR_UNTRUSTED COLOR_PAIR(37)
#define COLOUR_TITLE_ONLINE COLOR_PAIR(15)
#define COLOUR_TITLE_OFFLINE COLOR_PAIR(16)
#define COLOUR_TITLE_AWAY COLOR_PAIR(17)
#define COLOUR_TITLE_CHAT COLOR_PAIR(18)
#define COLOUR_TITLE_DND COLOR_PAIR(19)
#define COLOUR_TITLE_XA COLOR_PAIR(20)
#define COLOUR_STATUS_TEXT COLOR_PAIR(21)
#define COLOUR_STATUS_BRACKET COLOR_PAIR(22)
#define COLOUR_STATUS_ACTIVE COLOR_PAIR(23)
#define COLOUR_STATUS_NEW COLOR_PAIR(24)
#define COLOUR_ME COLOR_PAIR(25)
#define COLOUR_THEM COLOR_PAIR(26)
#define COLOUR_ROOMINFO COLOR_PAIR(27)
#define COLOUR_ROOMMENTION COLOR_PAIR(28)
#define COLOUR_ONLINE COLOR_PAIR(29)
#define COLOUR_OFFLINE COLOR_PAIR(30)
#define COLOUR_AWAY COLOR_PAIR(31)
#define COLOUR_CHAT COLOR_PAIR(32)
#define COLOUR_DND COLOR_PAIR(33)
#define COLOUR_XA COLOR_PAIR(34)
#define COLOUR_TYPING COLOR_PAIR(35)
#define COLOUR_GONE COLOR_PAIR(36)
#define COLOUR_SUBSCRIBED COLOR_PAIR(37)
#define COLOUR_UNSUBSCRIBED COLOR_PAIR(38)
#define COLOUR_OTR_STARTED_TRUSTED COLOR_PAIR(39)
#define COLOUR_OTR_STARTED_UNTRUSTED COLOR_PAIR(40)
#define COLOUR_OTR_ENDED COLOR_PAIR(41)
#define COLOUR_OTR_TRUSTED COLOR_PAIR(42)
#define COLOUR_OTR_UNTRUSTED COLOR_PAIR(43)
void theme_init(const char * const theme_name);
void theme_init_colours(void);

View File

@ -840,6 +840,15 @@ _cons_beep_setting(void)
cons_show("Terminal beep (/beep) : OFF");
}
static void
_cons_presence_setting(void)
{
if (prefs_get_boolean(PREF_PRESENCE))
cons_show("Contact presence (/presence) : ON");
else
cons_show("Contact presence (/presence) : OFF");
}
static void
_cons_flash_setting(void)
{
@ -938,6 +947,7 @@ _cons_show_ui_prefs(void)
cons_occupants_setting();
cons_privileges_setting();
cons_titlebar_setting();
cons_presence_setting();
cons_alert();
}
@ -1547,6 +1557,7 @@ console_init_module(void)
cons_theme_setting = _cons_theme_setting;
cons_privileges_setting = _cons_privileges_setting;
cons_beep_setting = _cons_beep_setting;
cons_presence_setting = _cons_presence_setting;
cons_flash_setting = _cons_flash_setting;
cons_splash_setting = _cons_splash_setting;
cons_autoconnect_setting = _cons_autoconnect_setting;

View File

@ -174,6 +174,49 @@ _title_bar_draw(void)
waddch(win, ' ');
mvwprintw(win, 0, 0, " %s", current_title);
// show presence
if (prefs_get_boolean(PREF_PRESENCE) && current_recipient) {
char *recipient_jid = NULL;
char *found_contact = roster_find_contact(current_recipient);
if (found_contact) {
recipient_jid = roster_barejid_from_name(current_recipient);
free(found_contact);
} else {
recipient_jid = current_recipient;
}
ProfWin *current = wins_get_by_recipient(recipient_jid);
if (current) {
if (current->type == WIN_CHAT) {
PContact contact = roster_get_contact(recipient_jid);
const char *presence = p_contact_presence(contact);
int presence_colour = COLOUR_TITLE_ONLINE;
if (g_strcmp0(presence, "offline") == 0) {
presence_colour = COLOUR_TITLE_OFFLINE;
} else if (g_strcmp0(presence, "away") == 0) {
presence_colour = COLOUR_TITLE_AWAY;
} else if (g_strcmp0(presence, "xa") == 0) {
presence_colour = COLOUR_TITLE_XA;
} else if (g_strcmp0(presence, "chat") == 0) {
presence_colour = COLOUR_TITLE_CHAT;
} else if (g_strcmp0(presence, "dnd") == 0) {
presence_colour = COLOUR_TITLE_DND;
}
wprintw(win, " ");
wattron(win, COLOUR_TITLE_BRACKET);
wprintw(win, "[");
wattroff(win, COLOUR_TITLE_BRACKET);
wattron(win, presence_colour);
wprintw(win, presence);
wattroff(win, presence_colour);
wattron(win, COLOUR_TITLE_BRACKET);
wprintw(win, "]");
wattroff(win, COLOUR_TITLE_BRACKET);
}
}
}
#ifdef HAVE_LIBOTR
// show privacy
if (current_recipient != NULL) {
@ -264,22 +307,34 @@ _title_bar_draw(void)
switch (current_presence)
{
case CONTACT_ONLINE:
wattron(win, COLOUR_TITLE_ONLINE);
mvwprintw(win, 0, cols - 13, " ...online ");
wattroff(win, COLOUR_TITLE_ONLINE);
break;
case CONTACT_AWAY:
wattron(win, COLOUR_TITLE_AWAY);
mvwprintw(win, 0, cols - 13, " .....away ");
wattroff(win, COLOUR_TITLE_AWAY);
break;
case CONTACT_DND:
wattron(win, COLOUR_TITLE_DND);
mvwprintw(win, 0, cols - 13, " ......dnd ");
wattroff(win, COLOUR_TITLE_DND);
break;
case CONTACT_CHAT:
wattron(win, COLOUR_TITLE_CHAT);
mvwprintw(win, 0, cols - 13, " .....chat ");
wattroff(win, COLOUR_TITLE_CHAT);
break;
case CONTACT_XA:
wattron(win, COLOUR_TITLE_XA);
mvwprintw(win, 0, cols - 13, " .......xa ");
wattroff(win, COLOUR_TITLE_XA);
break;
case CONTACT_OFFLINE:
wattron(win, COLOUR_TITLE_OFFLINE);
mvwprintw(win, 0, cols - 13, " ..offline ");
wattroff(win, COLOUR_TITLE_OFFLINE);
break;
}

View File

@ -299,6 +299,7 @@ void (*cons_flash_setting)(void);
void (*cons_splash_setting)(void);
void (*cons_vercheck_setting)(void);
void (*cons_occupants_setting)(void);
void (*cons_presence_setting)(void);
void (*cons_mouse_setting)(void);
void (*cons_statuses_setting)(void);
void (*cons_titlebar_setting)(void);

View File

@ -32,6 +32,12 @@ titlebar.unencrypted=red
titlebar.encrypted=white
titlebar.untrusted=yellow
titlebar.trusted=white
titlebar.online=green
titlebar.offline=red
titlebar.away=cyan
titlebar.xa=cyan
titlebar.dnd=red
titlebar.chat=green
otr.started.trusted=green
otr.started.untrusted=yellow
otr.ended=red

View File

@ -32,6 +32,12 @@ titlebar.unencrypted=red
titlebar.encrypted=white
titlebar.untrusted=yellow
titlebar.trusted=white
titlebar.online=white
titlebar.offline=white
titlebar.away=white
titlebar.xa=white
titlebar.dnd=white
titlebar.chat=white
otr.started.trusted=green
otr.started.untrusted=yellow
otr.ended=red