From 373b3a2d7c493200207201f5bd3ec185a9207fa1 Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 7 Nov 2014 22:38:34 +0000 Subject: Added /presence command to show contacts presence --- src/command/command.c | 10 +++++- src/command/commands.c | 8 ++++- src/command/commands.h | 1 + src/config/preferences.c | 4 +++ src/config/preferences.h | 1 + src/config/theme.c | 82 ++++++++++++++++++++++++++++++++++-------------- src/config/theme.h | 52 ++++++++++++++++-------------- src/ui/console.c | 11 +++++++ src/ui/titlebar.c | 55 ++++++++++++++++++++++++++++++++ src/ui/ui.h | 1 + themes/boothj5 | 6 ++++ themes/original | 6 ++++ 12 files changed, 189 insertions(+), 48 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index b87e50e6..c898f4b7 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -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], diff --git a/src/command/commands.c b/src/command/commands.c index e81c1714..45421829 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -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) { diff --git a/src/command/commands.h b/src/command/commands.h index 55f11df1..245a2944 100644 --- a/src/command/commands.h +++ b/src/command/commands.h @@ -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); diff --git a/src/config/preferences.c b/src/config/preferences.c index 9f084951..1447160b 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -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; diff --git a/src/config/preferences.h b/src/config/preferences.h index 528d9661..a4dfa1f1 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -59,6 +59,7 @@ typedef enum { PREF_MOUSE, PREF_OCCUPANTS, PREF_MUC_PRIVILEGES, + PREF_PRESENCE, PREF_STATUSES, PREF_STATUSES_CONSOLE, PREF_STATUSES_CHAT, diff --git a/src/config/theme.c b/src/config/theme.c index b3b70db7..b79d3070 100644 --- a/src/config/theme.c +++ b/src/config/theme.c @@ -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); diff --git a/src/config/theme.h b/src/config/theme.h index b3d96681..4424807a 100644 --- a/src/config/theme.h +++ b/src/config/theme.h @@ -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); diff --git a/src/ui/console.c b/src/ui/console.c index 885dd19d..2b5dec8a 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -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; diff --git a/src/ui/titlebar.c b/src/ui/titlebar.c index 811ac2c2..256f8e57 100644 --- a/src/ui/titlebar.c +++ b/src/ui/titlebar.c @@ -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; } diff --git a/src/ui/ui.h b/src/ui/ui.h index b3c5be1f..f5c9b621 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -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); diff --git a/themes/boothj5 b/themes/boothj5 index 50ce7d94..40a26927 100644 --- a/themes/boothj5 +++ b/themes/boothj5 @@ -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 diff --git a/themes/original b/themes/original index 9ee1e15b..237623b6 100644 --- a/themes/original +++ b/themes/original @@ -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 -- cgit 1.4.1-2-gfad0