about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-11-22 20:41:57 +0000
committerJames Booth <boothj5@gmail.com>2014-11-22 20:41:57 +0000
commitc0420e9cfb2d4a7edb2853b44ffd7a877c24993b (patch)
tree2f5c517241b43b30efe26823750f7878d08d1e49 /src
parent3e98df7a2fc61085623d30c6b383ac39215db885 (diff)
parentd9657099103b7fe764644dd5ce0fe052d9441354 (diff)
downloadprofani-tty-c0420e9cfb2d4a7edb2853b44ffd7a877c24993b.tar.gz
Merge branch 'autocomplete_fix'
Diffstat (limited to 'src')
-rw-r--r--src/ui/titlebar.c235
1 files changed, 127 insertions, 108 deletions
diff --git a/src/ui/titlebar.c b/src/ui/titlebar.c
index c8fd292a..42da14b6 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,92 @@ _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 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);
+
+    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 +329,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