From f24b34873961d82304383641a3e14421f442ce82 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 20 Nov 2014 21:32:19 +0000 Subject: refactor parts of title bar render out of _title_bar_draw --- src/ui/titlebar.c | 238 +++++++++++++++++++++++++++++------------------------- 1 file changed, 130 insertions(+), 108 deletions(-) (limited to 'src/ui') diff --git a/src/ui/titlebar.c b/src/ui/titlebar.c index c8fd292a..4d5484a1 100644 --- a/src/ui/titlebar.c +++ b/src/ui/titlebar.c @@ -58,6 +58,9 @@ static gboolean typing; 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_privacy(void); void create_title_bar(void) @@ -85,7 +88,6 @@ title_bar_update_virtual(void) g_timer_destroy(typing_elapsed); typing_elapsed = NULL; - } } } @@ -174,55 +176,95 @@ _title_bar_draw(void) waddch(win, ' '); 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; + +#ifdef HAVE_LIBOTR + _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, " *"); } - 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; - } + // show contact typing + if (typing) { + wprintw(win, " (typing...)"); + } - int presence_attrs = theme_attrs(presence_colour); + _show_self_presence(); - 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); - } - } + 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; } -#ifdef HAVE_LIBOTR - // show privacy + 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) { char *recipient_jid = NULL; 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 - if (typing) { - wprintw(win, " (typing...)"); - } +static void +_show_contact_presence(void) +{ + int bracket_attrs = theme_attrs(THEME_TITLE_BRACKET); - // show presence - int cols = getmaxx(stdscr); + 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); - wattron(win, bracket_attrs); - mvwaddch(win, 0, cols - 14, '['); - wattroff(win, bracket_attrs); + 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 = 0; + int presence_attrs = theme_attrs(presence_colour); - 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; + 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); + } + } } - - wattron(win, bracket_attrs); - mvwaddch(win, 0, cols - 2, ']'); - wattroff(win, bracket_attrs); - - wnoutrefresh(win); - inp_put_back(); -} +} \ No newline at end of file -- cgit 1.4.1-2-gfad0 From d9657099103b7fe764644dd5ce0fe052d9441354 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 22 Nov 2014 20:41:47 +0000 Subject: Tidied whitespace --- src/ui/titlebar.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/ui') diff --git a/src/ui/titlebar.c b/src/ui/titlebar.c index 4d5484a1..42da14b6 100644 --- a/src/ui/titlebar.c +++ b/src/ui/titlebar.c @@ -178,7 +178,6 @@ _title_bar_draw(void) _show_contact_presence(); - #ifdef HAVE_LIBOTR _show_privacy(); #endif @@ -205,16 +204,14 @@ _title_bar_draw(void) static void _show_self_presence(void) { + int presence_attrs = 0; 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: -- cgit 1.4.1-2-gfad0