diff options
author | James Booth <boothj5@gmail.com> | 2014-12-02 21:06:29 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2014-12-02 21:06:29 +0000 |
commit | d652c3c7ac27dee68fb8cf01dbf3b31426d8ddd4 (patch) | |
tree | a6e8446996379706629316a760edf0ee3dc1d87b /src/ui/titlebar.c | |
parent | 1a8c805319eb7fea0068bde124f5900877e61ec6 (diff) | |
download | profani-tty-d652c3c7ac27dee68fb8cf01dbf3b31426d8ddd4.tar.gz |
Show resource presence with /resource command
Diffstat (limited to 'src/ui/titlebar.c')
-rw-r--r-- | src/ui/titlebar.c | 99 |
1 files changed, 48 insertions, 51 deletions
diff --git a/src/ui/titlebar.c b/src/ui/titlebar.c index 6ef3ec70..521d5919 100644 --- a/src/ui/titlebar.c +++ b/src/ui/titlebar.c @@ -60,7 +60,6 @@ static GTimer *typing_elapsed; static void _title_bar_draw(void); static void _show_contact_presence(void); static void _show_self_presence(void); -static void _show_contact_resource(void); #ifdef HAVE_LIBOTR static void _show_privacy(void); #endif @@ -182,13 +181,7 @@ _title_bar_draw(void) mvwprintw(win, 0, 0, " %s", current_title); if (current && current->type == WIN_CHAT) { - if (TRUE) { -// if (prefs_get_boolean(PREF_RESOURCE)) { - _show_contact_resource(); - } - if (prefs_get_boolean(PREF_PRESENCE)) { - _show_contact_presence(); - } + _show_contact_presence(); #ifdef HAVE_LIBOTR _show_privacy(); #endif @@ -326,60 +319,64 @@ _show_privacy(void) #endif static void -_show_contact_resource(void) +_show_contact_presence(void) { int bracket_attrs = theme_attrs(THEME_TITLE_BRACKET); ProfWin *current = wins_get_current(); if (current && current->chat_resource) { + wprintw(win, "/"); + wprintw(win, current->chat_resource); + } + + if (prefs_get_boolean(PREF_PRESENCE)) { + theme_item_t presence_colour = THEME_TITLE_OFFLINE; + const char *presence = "offline"; + + if (current && current->chat_resource) { + char *barejid = roster_barejid_from_name(current_recipient); + if (barejid) { + PContact contact = roster_get_contact(barejid); + if (contact) { + Resource *resource = p_contact_get_resource(contact, current->chat_resource); + if (resource) { + presence = string_from_resource_presence(resource->presence); + } + } + } + } else { + char *barejid = roster_barejid_from_name(current_recipient); + if (barejid) { + PContact contact = roster_get_contact(barejid); + if (contact) { + presence = p_contact_presence(contact); + } + } + } + + presence_colour = THEME_TITLE_ONLINE; + if (g_strcmp0(presence, "offline") == 0) { + presence_colour = THEME_TITLE_OFFLINE; + } else if (g_strcmp0(presence, "away") == 0) { + presence_colour = THEME_TITLE_AWAY; + } else if (g_strcmp0(presence, "xa") == 0) { + presence_colour = THEME_TITLE_XA; + } else if (g_strcmp0(presence, "chat") == 0) { + presence_colour = THEME_TITLE_CHAT; + } else if (g_strcmp0(presence, "dnd") == 0) { + presence_colour = THEME_TITLE_DND; + } + + int presence_attrs = theme_attrs(presence_colour); wprintw(win, " "); wattron(win, bracket_attrs); wprintw(win, "["); wattroff(win, bracket_attrs); - wprintw(win, current->chat_resource); + wattron(win, presence_attrs); + wprintw(win, presence); + wattroff(win, presence_attrs); wattron(win, bracket_attrs); wprintw(win, "]"); wattroff(win, bracket_attrs); } } - -static void -_show_contact_presence(void) -{ - int bracket_attrs = theme_attrs(THEME_TITLE_BRACKET); - - theme_item_t presence_colour = THEME_TITLE_OFFLINE; - const char *presence = "offline"; - - char *barejid = roster_barejid_from_name(current_recipient); - if (barejid) { - PContact contact = roster_get_contact(barejid); - if (contact) { - presence = p_contact_presence(contact); - presence_colour = THEME_TITLE_ONLINE; - if (g_strcmp0(presence, "offline") == 0) { - presence_colour = THEME_TITLE_OFFLINE; - } else if (g_strcmp0(presence, "away") == 0) { - presence_colour = THEME_TITLE_AWAY; - } else if (g_strcmp0(presence, "xa") == 0) { - presence_colour = THEME_TITLE_XA; - } else if (g_strcmp0(presence, "chat") == 0) { - presence_colour = THEME_TITLE_CHAT; - } else if (g_strcmp0(presence, "dnd") == 0) { - presence_colour = THEME_TITLE_DND; - } - } - } - - int presence_attrs = theme_attrs(presence_colour); - wprintw(win, " "); - wattron(win, bracket_attrs); - wprintw(win, "["); - wattroff(win, bracket_attrs); - wattron(win, presence_attrs); - wprintw(win, presence); - wattroff(win, presence_attrs); - wattron(win, bracket_attrs); - wprintw(win, "]"); - wattroff(win, bracket_attrs); -} |