1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

refactor parts of title bar render out of _title_bar_draw

This commit is contained in:
James Booth 2014-11-20 21:32:19 +00:00
parent 81b1009fd9
commit f24b348739

View File

@ -58,6 +58,9 @@ static gboolean typing;
static GTimer *typing_elapsed; 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_self_presence(void);
static void _show_privacy(void);
void void
create_title_bar(void) create_title_bar(void)
@ -85,7 +88,6 @@ title_bar_update_virtual(void)
g_timer_destroy(typing_elapsed); g_timer_destroy(typing_elapsed);
typing_elapsed = NULL; typing_elapsed = NULL;
} }
} }
} }
@ -174,55 +176,95 @@ _title_bar_draw(void)
waddch(win, ' '); waddch(win, ' ');
mvwprintw(win, 0, 0, " %s", current_title); mvwprintw(win, 0, 0, " %s", current_title);
int bracket_attrs = theme_attrs(THEME_TITLE_BRACKET); _show_contact_presence();
// 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);
theme_item_t 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);
}
}
}
#ifdef HAVE_LIBOTR #ifdef HAVE_LIBOTR
// show privacy _show_privacy();
#endif
// show indicator for unsaved forms
ProfWin *current = wins_get_current();
if ((current != NULL ) && (current->type == WIN_MUC_CONFIG)) {
if ((current->form != NULL) && (current->form->modified)) {
wprintw(win, " *");
}
}
// show contact typing
if (typing) {
wprintw(win, " (typing...)");
}
_show_self_presence();
wnoutrefresh(win);
inp_put_back();
}
static void
_show_self_presence(void)
{
int bracket_attrs = theme_attrs(THEME_TITLE_BRACKET);
int cols = getmaxx(stdscr);
wattron(win, bracket_attrs);
mvwaddch(win, 0, cols - 14, '[');
wattroff(win, bracket_attrs);
int presence_attrs = 0;
switch (current_presence)
{
case CONTACT_ONLINE:
presence_attrs = theme_attrs(THEME_TITLE_ONLINE);
wattron(win, presence_attrs);
mvwprintw(win, 0, cols - 13, " ...online ");
wattroff(win, presence_attrs);
break;
case CONTACT_AWAY:
presence_attrs = theme_attrs(THEME_TITLE_AWAY);
wattron(win, presence_attrs);
mvwprintw(win, 0, cols - 13, " .....away ");
wattroff(win, presence_attrs);
break;
case CONTACT_DND:
presence_attrs = theme_attrs(THEME_TITLE_DND);
wattron(win, presence_attrs);
mvwprintw(win, 0, cols - 13, " ......dnd ");
wattroff(win, presence_attrs);
break;
case CONTACT_CHAT:
presence_attrs = theme_attrs(THEME_TITLE_CHAT);
wattron(win, presence_attrs);
mvwprintw(win, 0, cols - 13, " .....chat ");
wattroff(win, presence_attrs);
break;
case CONTACT_XA:
presence_attrs = theme_attrs(THEME_TITLE_XA);
wattron(win, presence_attrs);
mvwprintw(win, 0, cols - 13, " .......xa ");
wattroff(win, presence_attrs);
break;
case CONTACT_OFFLINE:
presence_attrs = theme_attrs(THEME_TITLE_OFFLINE);
wattron(win, presence_attrs);
mvwprintw(win, 0, cols - 13, " ..offline ");
wattroff(win, presence_attrs);
break;
}
wattron(win, bracket_attrs);
mvwaddch(win, 0, cols - 2, ']');
wattroff(win, bracket_attrs);
}
static void
_show_privacy(void)
{
int bracket_attrs = theme_attrs(THEME_TITLE_BRACKET);
if (current_recipient != NULL) { if (current_recipient != NULL) {
char *recipient_jid = NULL; char *recipient_jid = NULL;
char *found_contact = roster_find_contact(current_recipient); char *found_contact = roster_find_contact(current_recipient);
@ -290,74 +332,54 @@ _title_bar_draw(void)
} }
} }
} }
#endif
// show indicator for unsaved forms
ProfWin *current = wins_get_current();
if ((current != NULL ) && (current->type == WIN_MUC_CONFIG)) {
if ((current->form != NULL) && (current->form->modified)) {
wprintw(win, " *");
}
} }
// show contact typing static void
if (typing) { _show_contact_presence(void)
wprintw(win, " (typing...)");
}
// show presence
int cols = getmaxx(stdscr);
wattron(win, bracket_attrs);
mvwaddch(win, 0, cols - 14, '[');
wattroff(win, bracket_attrs);
int presence_attrs = 0;
switch (current_presence)
{ {
case CONTACT_ONLINE: int bracket_attrs = theme_attrs(THEME_TITLE_BRACKET);
presence_attrs = theme_attrs(THEME_TITLE_ONLINE);
wattron(win, presence_attrs); if (prefs_get_boolean(PREF_PRESENCE) && current_recipient) {
mvwprintw(win, 0, cols - 13, " ...online "); char *recipient_jid = NULL;
wattroff(win, presence_attrs); char *found_contact = roster_find_contact(current_recipient);
break; if (found_contact) {
case CONTACT_AWAY: recipient_jid = roster_barejid_from_name(current_recipient);
presence_attrs = theme_attrs(THEME_TITLE_AWAY); free(found_contact);
wattron(win, presence_attrs); } else {
mvwprintw(win, 0, cols - 13, " .....away "); recipient_jid = current_recipient;
wattroff(win, presence_attrs); }
break; ProfWin *current = wins_get_by_recipient(recipient_jid);
case CONTACT_DND: if (current) {
presence_attrs = theme_attrs(THEME_TITLE_DND); if (current->type == WIN_CHAT) {
wattron(win, presence_attrs); PContact contact = roster_get_contact(recipient_jid);
mvwprintw(win, 0, cols - 13, " ......dnd "); const char *presence = p_contact_presence(contact);
wattroff(win, presence_attrs);
break; theme_item_t presence_colour = THEME_TITLE_ONLINE;
case CONTACT_CHAT: if (g_strcmp0(presence, "offline") == 0) {
presence_attrs = theme_attrs(THEME_TITLE_CHAT); presence_colour = THEME_TITLE_OFFLINE;
wattron(win, presence_attrs); } else if (g_strcmp0(presence, "away") == 0) {
mvwprintw(win, 0, cols - 13, " .....chat "); presence_colour = THEME_TITLE_AWAY;
wattroff(win, presence_attrs); } else if (g_strcmp0(presence, "xa") == 0) {
break; presence_colour = THEME_TITLE_XA;
case CONTACT_XA: } else if (g_strcmp0(presence, "chat") == 0) {
presence_attrs = theme_attrs(THEME_TITLE_XA); presence_colour = THEME_TITLE_CHAT;
wattron(win, presence_attrs); } else if (g_strcmp0(presence, "dnd") == 0) {
mvwprintw(win, 0, cols - 13, " .......xa "); presence_colour = THEME_TITLE_DND;
wattroff(win, presence_attrs);
break;
case CONTACT_OFFLINE:
presence_attrs = theme_attrs(THEME_TITLE_OFFLINE);
wattron(win, presence_attrs);
mvwprintw(win, 0, cols - 13, " ..offline ");
wattroff(win, presence_attrs);
break;
} }
int presence_attrs = theme_attrs(presence_colour);
wprintw(win, " ");
wattron(win, bracket_attrs); wattron(win, bracket_attrs);
mvwaddch(win, 0, cols - 2, ']'); 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); wattroff(win, bracket_attrs);
}
wnoutrefresh(win); }
inp_put_back(); }
} }