about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--Makefile.am2
-rw-r--r--src/ui/console.c19
-rw-r--r--src/ui/console.h35
-rw-r--r--src/ui/ui.h26
-rw-r--r--src/ui/window.c37
-rw-r--r--src/ui/window.h15
-rw-r--r--src/ui/windows.c88
7 files changed, 90 insertions, 132 deletions
diff --git a/Makefile.am b/Makefile.am
index dcd43704..ef2752b5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -10,7 +10,7 @@ profanity_SOURCES = src/contact.c src/contact.h src/log.c src/common.c \
 	src/xmpp/capabilities.h src/xmpp/connection.h \
 	src/ui/ui.h src/ui/window.c src/ui/window.h src/ui/windows.c \
 	src/ui/titlebar.c src/ui/statusbar.c src/ui/inputwin.c \
-	src/ui/console.h src/ui/console.c \
+	src/ui/console.c \
 	src/command/command.h src/command/command.c src/command/history.c \
 	src/command/history.h src/command/parser.c \
 	src/command/parser.h \
diff --git a/src/ui/console.c b/src/ui/console.c
index c28eb4e0..52dac651 100644
--- a/src/ui/console.c
+++ b/src/ui/console.c
@@ -33,6 +33,7 @@
 #include "config/preferences.h"
 #include "config/theme.h"
 #include "ui/window.h"
+#include "ui/ui.h"
 
 #define CONS_WIN_TITLE "_cons"
 
@@ -149,6 +150,24 @@ cons_check_version(gboolean not_available_msg)
     }
 }
 
+void
+cons_show_login_success(ProfAccount *account)
+{
+    window_show_time(console, '-');
+    wprintw(console->win, "%s logged in successfully, ", account->jid);
+
+    resource_presence_t presence = accounts_get_login_presence(account->name);
+    const char *presence_str = string_from_resource_presence(presence);
+
+    window_presence_colour_on(console, presence_str);
+    wprintw(console->win, "%s", presence_str);
+    window_presence_colour_off(console, presence_str);
+    wprintw(console->win, " (priority %d)",
+        accounts_get_priority_for_presence_type(account->name, presence));
+    wprintw(console->win, ".\n");
+}
+
+
 static void
 _cons_splash_logo(void)
 {
diff --git a/src/ui/console.h b/src/ui/console.h
deleted file mode 100644
index 6b24dee7..00000000
--- a/src/ui/console.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * console.h
- *
- * Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com>
- *
- * This file is part of Profanity.
- *
- * Profanity is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Profanity is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Profanity.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#ifndef CONSOLE_H
-#define CONSOLE_H
-
-#include "ui/window.h"
-
-ProfWin* cons_create(void);
-void cons_refresh(void);
-void cons_show(const char * const msg, ...);
-void cons_about(void);
-void cons_check_version(gboolean not_available_msg);
-
-#endif
-
diff --git a/src/ui/ui.h b/src/ui/ui.h
index 226dadbd..b324f8c3 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -36,28 +36,10 @@
 
 #include "contact.h"
 #include "jid.h"
+#include "ui/window.h"
 #include "xmpp/xmpp.h"
 
 #define INP_WIN_MAX 1000
-#define PAD_SIZE 1000
-
-typedef enum {
-    WIN_UNUSED,
-    WIN_CONSOLE,
-    WIN_CHAT,
-    WIN_MUC,
-    WIN_PRIVATE
-} win_type_t;
-
-struct prof_win {
-    char from[100];
-    WINDOW *win;
-    win_type_t type;
-    int y_pos;
-    int paged;
-    int unread;
-    int history_shown;
-};
 
 // gui startup and shutdown, resize
 void ui_init(void);
@@ -140,6 +122,9 @@ void win_show_status(void);
 void win_private_show_status(void);
 
 // console window actions
+ProfWin* cons_create(void);
+void cons_refresh(void);
+void cons_show(const char * const msg, ...);
 void cons_about(void);
 void cons_help(void);
 void cons_basic_help(void);
@@ -155,14 +140,12 @@ void cons_show_presence_prefs(void);
 void cons_show_connection_prefs(void);
 void cons_show_account(ProfAccount *account);
 void cons_bad_command(const char * const cmd);
-void cons_show(const char * const cmd, ...);
 void cons_debug(const char * const msg, ...);
 void cons_show_time(void);
 void cons_show_word(const char * const word);
 void cons_bad_show(const char * const cmd, ...);
 void cons_highlight_show(const char * const cmd);
 void cons_show_contacts(GSList * list);
-void cons_check_version(gboolean not_available_msg);
 void cons_show_wins(void);
 void cons_show_status(const char * const contact);
 void cons_show_info(PContact pcontact);
@@ -178,6 +161,7 @@ void cons_show_disco_items(GSList *items, const char * const jid);
 void cons_show_disco_info(const char *from, GSList *identities, GSList *features);
 void cons_show_room_invite(const char * const invitor, const char * const room,
     const char * const reason);
+void cons_check_version(gboolean not_available_msg);
 
 // status bar actions
 void status_bar_refresh(void);
diff --git a/src/ui/window.c b/src/ui/window.c
index 8bf3311c..d07ce989 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -76,3 +76,40 @@ window_show_time(ProfWin* window, char show_char)
     g_date_time_unref(time);
     g_free(date_fmt);
 }
+
+void
+window_presence_colour_on(ProfWin *window, const char * const presence)
+{
+    if (g_strcmp0(presence, "online") == 0) {
+        wattron(window->win, COLOUR_ONLINE);
+    } else if (g_strcmp0(presence, "away") == 0) {
+        wattron(window->win, COLOUR_AWAY);
+    } else if (g_strcmp0(presence, "chat") == 0) {
+        wattron(window->win, COLOUR_CHAT);
+    } else if (g_strcmp0(presence, "dnd") == 0) {
+        wattron(window->win, COLOUR_DND);
+    } else if (g_strcmp0(presence, "xa") == 0) {
+        wattron(window->win, COLOUR_XA);
+    } else {
+        wattron(window->win, COLOUR_OFFLINE);
+    }
+}
+
+void
+window_presence_colour_off(ProfWin *window, const char * const presence)
+{
+    if (g_strcmp0(presence, "online") == 0) {
+        wattroff(window->win, COLOUR_ONLINE);
+    } else if (g_strcmp0(presence, "away") == 0) {
+        wattroff(window->win, COLOUR_AWAY);
+    } else if (g_strcmp0(presence, "chat") == 0) {
+        wattroff(window->win, COLOUR_CHAT);
+    } else if (g_strcmp0(presence, "dnd") == 0) {
+        wattroff(window->win, COLOUR_DND);
+    } else if (g_strcmp0(presence, "xa") == 0) {
+        wattroff(window->win, COLOUR_XA);
+    } else {
+        wattroff(window->win, COLOUR_OFFLINE);
+    }
+}
+
diff --git a/src/ui/window.h b/src/ui/window.h
index 16428c6b..2793cd42 100644
--- a/src/ui/window.h
+++ b/src/ui/window.h
@@ -23,7 +23,15 @@
 #ifndef WINDOW_H
 #define WINDOW_H
 
-#include "ui/ui.h"
+#define PAD_SIZE 1000
+
+typedef enum {
+    WIN_UNUSED,
+    WIN_CONSOLE,
+    WIN_CHAT,
+    WIN_MUC,
+    WIN_PRIVATE
+} win_type_t;
 
 typedef struct prof_win_t {
     char *from;
@@ -35,10 +43,11 @@ typedef struct prof_win_t {
     int history_shown;
 } ProfWin;
 
-
 ProfWin* window_create(const char * const title, int cols, win_type_t type);
 void window_free(ProfWin *window);
 
-void window_show_time(ProfWin* window, char show_char);
+void window_show_time(ProfWin *window, char show_char);
+void window_presence_colour_on(ProfWin *window, const char * const presence);
+void window_presence_colour_off(ProfWin *window, const char * const presence);
 
 #endif
diff --git a/src/ui/windows.c b/src/ui/windows.c
index 8aaab1d1..77390751 100644
--- a/src/ui/windows.c
+++ b/src/ui/windows.c
@@ -50,7 +50,6 @@
 #include "jid.h"
 #include "log.h"
 #include "muc.h"
-#include "ui/console.h"
 #include "ui/ui.h"
 #include "ui/window.h"
 
@@ -102,8 +101,6 @@ static void _win_show_history(WINDOW *win, int win_index,
     const char * const contact);
 static void _win_show_info(ProfWin *window, PContact pcontact);
 static void _ui_draw_win_title(void);
-static void _presence_colour_on(WINDOW *win, const char * const presence);
-static void _presence_colour_off(WINDOW *win, const char * const presence);
 
 static void _notify(const char * const message, int timeout,
     const char * const category);
@@ -883,9 +880,9 @@ win_show_room_roster(const char * const room, GList *roster, const char * const
             const char const *nick = p_contact_barejid(member);
             const char const *show = p_contact_presence(member);
 
-            _presence_colour_on(window->win, show);
+            window_presence_colour_on(window, show);
             wprintw(window->win, "%s", nick);
-            _presence_colour_off(window->win, show);
+            window_presence_colour_off(window, show);
 
             if (roster->next != NULL) {
                 wprintw(window->win, ", ");
@@ -1115,23 +1112,6 @@ win_show_room_broadcast(const char * const room_jid, const char * const message)
     }
 }
 
-void
-cons_show_login_success(ProfAccount *account)
-{
-    window_show_time(console, '-');
-    wprintw(console->win, "%s logged in successfully, ", account->jid);
-
-    resource_presence_t presence = accounts_get_login_presence(account->name);
-    const char *presence_str = string_from_resource_presence(presence);
-
-    _presence_colour_on(console->win, presence_str);
-    wprintw(console->win, "%s", presence_str);
-    _presence_colour_off(console->win, presence_str);
-    wprintw(console->win, " (priority %d)",
-        accounts_get_priority_for_presence_type(account->name, presence));
-    wprintw(console->win, ".\n");
-}
-
 
 void
 cons_show_wins(void)
@@ -1222,9 +1202,9 @@ cons_show_caps(const char * const contact, Resource *resource)
     cons_show("");
     const char *resource_presence = string_from_resource_presence(resource->presence);
     window_show_time(console, '-');
-    _presence_colour_on(win, resource_presence);
+    window_presence_colour_on(console, resource_presence);
     wprintw(console->win, "%s", contact);
-    _presence_colour_off(win, resource_presence);
+    window_presence_colour_off(console, resource_presence);
     wprintw(win, ":\n");
 
     if (resource->caps_str != NULL) {
@@ -1302,9 +1282,9 @@ cons_show_software_version(const char * const jid, const char * const  presence,
     if ((name != NULL) || (version != NULL) || (os != NULL)) {
         cons_show("");
         window_show_time(console, '-');
-        _presence_colour_on(console->win, presence);
+        window_presence_colour_on(console, presence);
         wprintw(console->win, "%s", jid);
-        _presence_colour_off(console->win, presence);
+        window_presence_colour_off(console, presence);
         wprintw(console->win, ":\n");
     }
     if (name != NULL) {
@@ -1455,9 +1435,9 @@ cons_show_account_list(gchar **accounts)
                     (g_strcmp0(jabber_get_account_name(), accounts[i]) == 0)) {
                 resource_presence_t presence = accounts_get_last_presence(accounts[i]);
                 window_show_time(console, '-');
-                _presence_colour_on(console->win, string_from_resource_presence(presence));
+                window_presence_colour_on(console, string_from_resource_presence(presence));
                 wprintw(console->win, "%s\n", accounts[i]);
-                _presence_colour_off(console->win, string_from_resource_presence(presence));
+                window_presence_colour_off(console, string_from_resource_presence(presence));
             } else {
                 cons_show(accounts[i]);
             }
@@ -1519,13 +1499,13 @@ cons_show_account(ProfAccount *account)
             Resource *resource = ordered_resources->data;
             const char *resource_presence = string_from_resource_presence(resource->presence);
             window_show_time(console, '-');
-            _presence_colour_on(win, resource_presence);
+            window_presence_colour_on(console, resource_presence);
             wprintw(win, "  %s (%d), %s", resource->name, resource->priority, resource_presence);
             if (resource->status != NULL) {
                 wprintw(win, ", \"%s\"", resource->status);
             }
             wprintw(win, "\n");
-            _presence_colour_off(win, resource_presence);
+            window_presence_colour_off(console, resource_presence);
 
             if (resource->caps_str != NULL) {
                 Capabilities *caps = caps_get(resource->caps_str);
@@ -2227,42 +2207,6 @@ _win_resize_all(void)
 }
 
 static void
-_presence_colour_on(WINDOW *win, const char * const presence)
-{
-    if (g_strcmp0(presence, "online") == 0) {
-        wattron(win, COLOUR_ONLINE);
-    } else if (g_strcmp0(presence, "away") == 0) {
-        wattron(win, COLOUR_AWAY);
-    } else if (g_strcmp0(presence, "chat") == 0) {
-        wattron(win, COLOUR_CHAT);
-    } else if (g_strcmp0(presence, "dnd") == 0) {
-        wattron(win, COLOUR_DND);
-    } else if (g_strcmp0(presence, "xa") == 0) {
-        wattron(win, COLOUR_XA);
-    } else {
-        wattron(win, COLOUR_OFFLINE);
-    }
-}
-
-static void
-_presence_colour_off(WINDOW *win, const char * const presence)
-{
-    if (g_strcmp0(presence, "online") == 0) {
-        wattroff(win, COLOUR_ONLINE);
-    } else if (g_strcmp0(presence, "away") == 0) {
-        wattroff(win, COLOUR_AWAY);
-    } else if (g_strcmp0(presence, "chat") == 0) {
-        wattroff(win, COLOUR_CHAT);
-    } else if (g_strcmp0(presence, "dnd") == 0) {
-        wattroff(win, COLOUR_DND);
-    } else if (g_strcmp0(presence, "xa") == 0) {
-        wattroff(win, COLOUR_XA);
-    } else {
-        wattroff(win, COLOUR_OFFLINE);
-    }
-}
-
-static void
 _show_status_string(ProfWin *window, const char * const from,
     const char * const show, const char * const status,
     GDateTime *last_activity, const char * const pre,
@@ -2376,7 +2320,7 @@ _win_show_contact(ProfWin *window, PContact contact)
     GDateTime *last_activity = p_contact_last_activity(contact);
 
     window_show_time(window, '-');
-    _presence_colour_on(window->win, presence);
+    window_presence_colour_on(window, presence);
     wprintw(window->win, "%s", barejid);
 
     if (name != NULL) {
@@ -2410,7 +2354,7 @@ _win_show_contact(ProfWin *window, PContact contact)
     }
 
     wprintw(window->win, "\n");
-    _presence_colour_off(window->win, presence);
+    window_presence_colour_off(window, presence);
 }
 
 static void
@@ -2559,12 +2503,12 @@ _win_show_info(ProfWin *window, PContact pcontact)
     window_show_time(window, '-');
     wprintw(win, "\n");
     window_show_time(window, '-');
-    _presence_colour_on(win, presence);
+    window_presence_colour_on(window, presence);
     wprintw(win, "%s", barejid);
     if (name != NULL) {
         wprintw(win, " (%s)", name);
     }
-    _presence_colour_off(win, presence);
+    window_presence_colour_off(window, presence);
     wprintw(win, ":\n");
 
     if (sub != NULL) {
@@ -2614,13 +2558,13 @@ _win_show_info(ProfWin *window, PContact pcontact)
         Resource *resource = ordered_resources->data;
         const char *resource_presence = string_from_resource_presence(resource->presence);
         window_show_time(window, '-');
-        _presence_colour_on(win, resource_presence);
+        window_presence_colour_on(window, resource_presence);
         wprintw(win, "  %s (%d), %s", resource->name, resource->priority, resource_presence);
         if (resource->status != NULL) {
             wprintw(win, ", \"%s\"", resource->status);
         }
         wprintw(win, "\n");
-        _presence_colour_off(win, resource_presence);
+        window_presence_colour_off(window, resource_presence);
 
         if (resource->caps_str != NULL) {
             Capabilities *caps = caps_get(resource->caps_str);