about summary refs log tree commit diff stats
path: root/src/ui
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-11-07 22:38:34 +0000
committerJames Booth <boothj5@gmail.com>2014-11-07 22:38:34 +0000
commit373b3a2d7c493200207201f5bd3ec185a9207fa1 (patch)
tree256f57c3c4f411d7a3acdc058e0e07cb822d4f88 /src/ui
parent571db231509577fe1e528595c3aae61e2f8ccf3f (diff)
downloadprofani-tty-373b3a2d7c493200207201f5bd3ec185a9207fa1.tar.gz
Added /presence command to show contacts presence
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/console.c11
-rw-r--r--src/ui/titlebar.c55
-rw-r--r--src/ui/ui.h1
3 files changed, 67 insertions, 0 deletions
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
@@ -841,6 +841,15 @@ _cons_beep_setting(void)
 }
 
 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)
 {
     if (prefs_get_boolean(PREF_FLASH))
@@ -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);