Show resource presence with /resource command

This commit is contained in:
James Booth
2014-12-02 21:06:29 +00:00
parent 1a8c805319
commit d652c3c7ac

View File

@@ -60,7 +60,6 @@ static GTimer *typing_elapsed;
static void _title_bar_draw(void); static void _title_bar_draw(void);
static void _show_contact_presence(void); static void _show_contact_presence(void);
static void _show_self_presence(void); static void _show_self_presence(void);
static void _show_contact_resource(void);
#ifdef HAVE_LIBOTR #ifdef HAVE_LIBOTR
static void _show_privacy(void); static void _show_privacy(void);
#endif #endif
@@ -182,13 +181,7 @@ _title_bar_draw(void)
mvwprintw(win, 0, 0, " %s", current_title); mvwprintw(win, 0, 0, " %s", current_title);
if (current && current->type == WIN_CHAT) { if (current && current->type == WIN_CHAT) {
if (TRUE) { _show_contact_presence();
// if (prefs_get_boolean(PREF_RESOURCE)) {
_show_contact_resource();
}
if (prefs_get_boolean(PREF_PRESENCE)) {
_show_contact_presence();
}
#ifdef HAVE_LIBOTR #ifdef HAVE_LIBOTR
_show_privacy(); _show_privacy();
#endif #endif
@@ -326,60 +319,64 @@ _show_privacy(void)
#endif #endif
static void static void
_show_contact_resource(void) _show_contact_presence(void)
{ {
int bracket_attrs = theme_attrs(THEME_TITLE_BRACKET); int bracket_attrs = theme_attrs(THEME_TITLE_BRACKET);
ProfWin *current = wins_get_current(); ProfWin *current = wins_get_current();
if (current && current->chat_resource) { 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, " "); wprintw(win, " ");
wattron(win, bracket_attrs); wattron(win, bracket_attrs);
wprintw(win, "["); wprintw(win, "[");
wattroff(win, bracket_attrs); wattroff(win, bracket_attrs);
wprintw(win, current->chat_resource); wattron(win, presence_attrs);
wprintw(win, presence);
wattroff(win, presence_attrs);
wattron(win, bracket_attrs); wattron(win, bracket_attrs);
wprintw(win, "]"); wprintw(win, "]");
wattroff(win, bracket_attrs); 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);
}