about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--Makefile.am3
-rw-r--r--src/command/commands.c14
-rw-r--r--src/main.c1
-rw-r--r--src/server_events.c6
-rw-r--r--src/ui/core.c129
-rw-r--r--src/ui/rosterwin.c135
-rw-r--r--src/ui/rosterwin.h35
-rw-r--r--src/ui/ui.h5
-rw-r--r--src/ui/windows.c2
-rw-r--r--tests/test_server_events.c2
-rw-r--r--tests/ui/mock_ui.c6
-rw-r--r--tests/ui/mock_ui.h2
12 files changed, 160 insertions, 180 deletions
diff --git a/Makefile.am b/Makefile.am
index fd10f688..d30fc0f3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -18,7 +18,7 @@ core_sources = \
 	src/ui/titlebar.h src/ui/statusbar.h src/ui/inputwin.h \
 	src/ui/console.c src/ui/notifier.c \
 	src/ui/windows.c src/ui/windows.h \
-	src/ui/rosterwin.c src/ui/rosterwin.h \
+	src/ui/rosterwin.c \
 	src/ui/buffer.c src/ui/buffer.h \
 	src/command/command.h src/command/command.c src/command/history.c \
 	src/command/commands.h src/command/commands.c \
@@ -57,7 +57,6 @@ tests_sources = \
 	src/config/theme.c src/config/theme.h \
 	src/ui/windows.c src/ui/windows.h \
 	src/ui/window.c src/ui/window.h \
-	src/ui/rosterwin.c src/ui/rosterwin.h \
 	src/ui/buffer.c \
 	src/ui/titlebar.c src/ui/statusbar.c src/ui/inputwin.c \
 	src/ui/titlebar.h src/ui/statusbar.h src/ui/inputwin.h \
diff --git a/src/command/commands.c b/src/command/commands.c
index 80c4d0a5..7c1a2ce8 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -1405,12 +1405,12 @@ cmd_roster(gchar **args, struct cmd_help_t help)
         } else if (g_strcmp0(args[1], "offline") == 0) {
             cons_show("Roster offline enabled");
             prefs_set_boolean(PREF_ROSTER_OFFLINE, TRUE);
-            ui_roster();
+            rosterwin_roster();
             return TRUE;
         } else if (g_strcmp0(args[1], "resource") == 0) {
             cons_show("Roster resource enabled");
             prefs_set_boolean(PREF_ROSTER_RESOURCE, TRUE);
-            ui_roster();
+            rosterwin_roster();
             return TRUE;
         } else {
             cons_show("Usage: %s", help.usage);
@@ -1425,12 +1425,12 @@ cmd_roster(gchar **args, struct cmd_help_t help)
         } else if (g_strcmp0(args[1], "offline") == 0) {
             cons_show("Roster offline disabled");
             prefs_set_boolean(PREF_ROSTER_OFFLINE, FALSE);
-            ui_roster();
+            rosterwin_roster();
             return TRUE;
         } else if (g_strcmp0(args[1], "resource") == 0) {
             cons_show("Roster resource disabled");
             prefs_set_boolean(PREF_ROSTER_RESOURCE, FALSE);
-            ui_roster();
+            rosterwin_roster();
             return TRUE;
         } else {
             cons_show("Usage: %s", help.usage);
@@ -1441,17 +1441,17 @@ cmd_roster(gchar **args, struct cmd_help_t help)
         if (g_strcmp0(args[1], "group") == 0) {
             cons_show("Grouping roster by roster group");
             prefs_set_string(PREF_ROSTER_BY, "group");
-            ui_roster();
+            rosterwin_roster();
             return TRUE;
         } else if (g_strcmp0(args[1], "presence") == 0) {
             cons_show("Grouping roster by presence");
             prefs_set_string(PREF_ROSTER_BY, "presence");
-            ui_roster();
+            rosterwin_roster();
             return TRUE;
         } else if (g_strcmp0(args[1], "none") == 0) {
             cons_show("Roster grouping disabled");
             prefs_set_string(PREF_ROSTER_BY, "none");
-            ui_roster();
+            rosterwin_roster();
             return TRUE;
         } else {
             cons_show("Usage: %s", help.usage);
diff --git a/src/main.c b/src/main.c
index e4643d2e..a8c02534 100644
--- a/src/main.c
+++ b/src/main.c
@@ -68,6 +68,7 @@ _init_modules(void)
     ui_init_module();
     console_init_module();
     notifier_init_module();
+    rosterwin_init_module();
 
     accounts_init_module();
 #ifdef HAVE_LIBOTR
diff --git a/src/server_events.c b/src/server_events.c
index be0b7d5e..47bca487 100644
--- a/src/server_events.c
+++ b/src/server_events.c
@@ -464,7 +464,7 @@ handle_contact_offline(char *barejid, char *resource, char *status)
         jid_destroy(jid);
     }
 
-    ui_roster();
+    rosterwin_roster();
 }
 
 void
@@ -506,7 +506,7 @@ handle_contact_online(char *barejid, Resource *resource,
         prefs_free_string(show_chat_win);
     }
 
-    ui_roster();
+    rosterwin_roster();
 }
 
 void
@@ -638,7 +638,7 @@ handle_roster_update(const char * const barejid, const char * const name,
     GSList *groups, const char * const subscription, gboolean pending_out)
 {
     roster_update(barejid, name, groups, subscription, pending_out);
-    ui_roster();
+    rosterwin_roster();
 }
 
 void
diff --git a/src/ui/core.c b/src/ui/core.c
index ff4784bc..c3f25544 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -69,7 +69,6 @@
 #include "ui/inputwin.h"
 #include "ui/window.h"
 #include "ui/windows.h"
-#include "ui/rosterwin.h"
 #include "xmpp/xmpp.h"
 
 static char *win_title;
@@ -466,42 +465,42 @@ _ui_roster_add(const char * const barejid, const char * const name)
     } else {
         cons_show("Roster item added: %s", barejid);
     }
-    ui_roster();
+    rosterwin_roster();
 }
 
 static void
 _ui_roster_remove(const char * const barejid)
 {
     cons_show("Roster item removed: %s", barejid);
-    ui_roster();
+    rosterwin_roster();
 }
 
 static void
 _ui_contact_already_in_group(const char * const contact, const char * const group)
 {
     cons_show("%s already in group %s", contact, group);
-    ui_roster();
+    rosterwin_roster();
 }
 
 static void
 _ui_contact_not_in_group(const char * const contact, const char * const group)
 {
     cons_show("%s is not currently in group %s", contact, group);
-    ui_roster();
+    rosterwin_roster();
 }
 
 static void
 _ui_group_added(const char * const contact, const char * const group)
 {
     cons_show("%s added to group %s", contact, group);
-    ui_roster();
+    rosterwin_roster();
 }
 
 static void
 _ui_group_removed(const char * const contact, const char * const group)
 {
     cons_show("%s removed from group %s", contact, group);
-    ui_roster();
+    rosterwin_roster();
 }
 
 static void
@@ -2939,119 +2938,6 @@ _ui_show_lines(ProfWin *window, const gchar** lines)
 }
 
 static void
-_ui_roster_contacts_by_presence(const char * const presence, char *title)
-{
-    ProfWin *window = wins_get_console();
-    ProfLayoutSplit *layout = (ProfLayoutSplit*)window->layout;
-
-    wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
-    win_printline_nowrap(layout->subwin, title);
-    wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
-    GSList *contacts = roster_get_contacts_by_presence(presence);
-    if (contacts) {
-        GSList *curr_contact = contacts;
-        while (curr_contact) {
-            PContact contact = curr_contact->data;
-            rosterwin_contact(contact);
-            curr_contact = g_slist_next(curr_contact);
-        }
-    }
-    g_slist_free(contacts);
-}
-
-static void
-_ui_roster_contacts_by_group(char *group)
-{
-    ProfWin *window = wins_get_console();
-    ProfLayoutSplit *layout = (ProfLayoutSplit*)window->layout;
-
-    wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
-    GString *title = g_string_new(" -");
-    g_string_append(title, group);
-    win_printline_nowrap(layout->subwin, title->str);
-    g_string_free(title, TRUE);
-    wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
-    GSList *contacts = roster_get_group(group);
-    if (contacts) {
-        GSList *curr_contact = contacts;
-        while (curr_contact) {
-            PContact contact = curr_contact->data;
-            rosterwin_contact(contact);
-            curr_contact = g_slist_next(curr_contact);
-        }
-    }
-    g_slist_free(contacts);
-}
-
-static void
-_ui_roster_contacts_by_no_group(void)
-{
-    ProfWin *window = wins_get_console();
-    ProfLayoutSplit *layout = (ProfLayoutSplit*)window->layout;
-
-    GSList *contacts = roster_get_nogroup();
-    if (contacts) {
-        wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
-        win_printline_nowrap(layout->subwin, " -no group");
-        wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
-        GSList *curr_contact = contacts;
-        while (curr_contact) {
-            PContact contact = curr_contact->data;
-            rosterwin_contact(contact);
-            curr_contact = g_slist_next(curr_contact);
-        }
-    }
-    g_slist_free(contacts);
-}
-
-static void
-_ui_roster(void)
-{
-    ProfWin *window = wins_get_console();
-    if (window) {
-        ProfLayoutSplit *layout = (ProfLayoutSplit*)window->layout;
-        char *by = prefs_get_string(PREF_ROSTER_BY);
-        if (g_strcmp0(by, "presence") == 0) {
-            werase(layout->subwin);
-            _ui_roster_contacts_by_presence("chat", " -Available for chat");
-            _ui_roster_contacts_by_presence("online", " -Online");
-            _ui_roster_contacts_by_presence("away", " -Away");
-            _ui_roster_contacts_by_presence("xa", " -Extended Away");
-            _ui_roster_contacts_by_presence("dnd", " -Do not disturb");
-            if (prefs_get_boolean(PREF_ROSTER_OFFLINE)) {
-                _ui_roster_contacts_by_presence("offline", " -Offline");
-            }
-        } else if (g_strcmp0(by, "group") == 0) {
-            werase(layout->subwin);
-            GSList *groups = roster_get_groups();
-            GSList *curr_group = groups;
-            while (curr_group) {
-                _ui_roster_contacts_by_group(curr_group->data);
-                curr_group = g_slist_next(curr_group);
-            }
-            g_slist_free_full(groups, free);
-            _ui_roster_contacts_by_no_group();
-        } else {
-            GSList *contacts = roster_get_contacts();
-            if (contacts) {
-                werase(layout->subwin);
-                wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
-                win_printline_nowrap(layout->subwin, " -Roster");
-                wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
-                GSList *curr_contact = contacts;
-                while (curr_contact) {
-                    PContact contact = curr_contact->data;
-                    rosterwin_contact(contact);
-                    curr_contact = g_slist_next(curr_contact);
-                }
-            }
-            g_slist_free(contacts);
-        }
-        free(by);
-    }
-}
-
-static void
 _ui_muc_roster(const char * const room)
 {
     ProfWin *window = wins_get_by_recipient(room);
@@ -3175,7 +3061,7 @@ _ui_show_roster(void)
     ProfWin *window = wins_get_console();
     if (window && !win_has_active_subwin(window)) {
         wins_show_subwin(window);
-        ui_roster();
+        rosterwin_roster();
     }
 }
 
@@ -3498,7 +3384,6 @@ ui_init_module(void)
     ui_handle_room_role_list_error = _ui_handle_room_role_list_error;
     ui_handle_room_role_list = _ui_handle_room_role_list;
     ui_muc_roster = _ui_muc_roster;
-    ui_roster = _ui_roster;
     ui_room_show_occupants = _ui_room_show_occupants;
     ui_room_hide_occupants = _ui_room_hide_occupants;
     ui_show_roster = _ui_show_roster;
diff --git a/src/ui/rosterwin.c b/src/ui/rosterwin.c
index 59222eb6..4eb91d4f 100644
--- a/src/ui/rosterwin.c
+++ b/src/ui/rosterwin.c
@@ -33,17 +33,20 @@
  */
 
 #include <assert.h>
+#include <stdlib.h>
 
 #include "contact.h"
+#include "ui/ui.h"
 #include "ui/window.h"
 #include "ui/windows.h"
 #include "config/preferences.h"
+#include "roster_list.h"
 
-void
-rosterwin_contact(PContact contact)
+static void
+_rosterwin_contact(PContact contact)
 {
     if (p_contact_subscribed(contact)) {
-        ProfWin *window = wins_get_console();
+        ProfWin *console = wins_get_console();
         const char *name = p_contact_name_or_jid(contact);
         const char *presence = p_contact_presence(contact);
 
@@ -51,7 +54,7 @@ rosterwin_contact(PContact contact)
                 (prefs_get_boolean(PREF_ROSTER_OFFLINE)))) {
             theme_item_t presence_colour = theme_main_presence_attrs(presence);
 
-            ProfLayoutSplit *layout = (ProfLayoutSplit*)window->layout;
+            ProfLayoutSplit *layout = (ProfLayoutSplit*)console->layout;
             assert(layout->memcheck == LAYOUT_SPLIT_MEMCHECK);
 
             wattron(layout->subwin, theme_attrs(presence_colour));
@@ -85,4 +88,128 @@ rosterwin_contact(PContact contact)
             }
         }
     }
+}
+
+static void
+_rosterwin_contacts_by_presence(const char * const presence, char *title)
+{
+    ProfWin *window = wins_get_console();
+    ProfLayoutSplit *layout = (ProfLayoutSplit*)window->layout;
+    assert(layout->memcheck == LAYOUT_SPLIT_MEMCHECK);
+
+    wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
+    win_printline_nowrap(layout->subwin, title);
+    wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
+    GSList *contacts = roster_get_contacts_by_presence(presence);
+    if (contacts) {
+        GSList *curr_contact = contacts;
+        while (curr_contact) {
+            PContact contact = curr_contact->data;
+            _rosterwin_contact(contact);
+            curr_contact = g_slist_next(curr_contact);
+        }
+    }
+    g_slist_free(contacts);
+}
+
+static void
+_rosterwin_contacts_by_group(char *group)
+{
+    ProfWin *console = wins_get_console();
+    ProfLayoutSplit *layout = (ProfLayoutSplit*)console->layout;
+    assert(layout->memcheck == LAYOUT_SPLIT_MEMCHECK);
+
+    wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
+    GString *title = g_string_new(" -");
+    g_string_append(title, group);
+    win_printline_nowrap(layout->subwin, title->str);
+    g_string_free(title, TRUE);
+    wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
+    GSList *contacts = roster_get_group(group);
+    if (contacts) {
+        GSList *curr_contact = contacts;
+        while (curr_contact) {
+            PContact contact = curr_contact->data;
+            _rosterwin_contact(contact);
+            curr_contact = g_slist_next(curr_contact);
+        }
+    }
+    g_slist_free(contacts);
+}
+
+static void
+_rosterwin_contacts_by_no_group(void)
+{
+    ProfWin *console = wins_get_console();
+    ProfLayoutSplit *layout = (ProfLayoutSplit*)console->layout;
+    assert(layout->memcheck == LAYOUT_SPLIT_MEMCHECK);
+
+    GSList *contacts = roster_get_nogroup();
+    if (contacts) {
+        wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
+        win_printline_nowrap(layout->subwin, " -no group");
+        wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
+        GSList *curr_contact = contacts;
+        while (curr_contact) {
+            PContact contact = curr_contact->data;
+            _rosterwin_contact(contact);
+            curr_contact = g_slist_next(curr_contact);
+        }
+    }
+    g_slist_free(contacts);
+}
+
+static void
+_rosterwin_roster(void)
+{
+    ProfWin *console = wins_get_console();
+    if (console) {
+        ProfLayoutSplit *layout = (ProfLayoutSplit*)console->layout;
+        assert(layout->memcheck == LAYOUT_SPLIT_MEMCHECK);
+
+       char *by = prefs_get_string(PREF_ROSTER_BY);
+        if (g_strcmp0(by, "presence") == 0) {
+            werase(layout->subwin);
+            _rosterwin_contacts_by_presence("chat", " -Available for chat");
+            _rosterwin_contacts_by_presence("online", " -Online");
+            _rosterwin_contacts_by_presence("away", " -Away");
+            _rosterwin_contacts_by_presence("xa", " -Extended Away");
+            _rosterwin_contacts_by_presence("dnd", " -Do not disturb");
+            if (prefs_get_boolean(PREF_ROSTER_OFFLINE)) {
+                _rosterwin_contacts_by_presence("offline", " -Offline");
+            }
+        } else if (g_strcmp0(by, "group") == 0) {
+            werase(layout->subwin);
+            GSList *groups = roster_get_groups();
+            GSList *curr_group = groups;
+            while (curr_group) {
+                _rosterwin_contacts_by_group(curr_group->data);
+                curr_group = g_slist_next(curr_group);
+            }
+            g_slist_free_full(groups, free);
+            _rosterwin_contacts_by_no_group();
+        } else {
+            GSList *contacts = roster_get_contacts();
+            if (contacts) {
+                werase(layout->subwin);
+                wattron(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
+                win_printline_nowrap(layout->subwin, " -Roster");
+                wattroff(layout->subwin, theme_attrs(THEME_ROSTER_HEADER));
+                GSList *curr_contact = contacts;
+                while (curr_contact) {
+                    PContact contact = curr_contact->data;
+                    _rosterwin_contact(contact);
+                    curr_contact = g_slist_next(curr_contact);
+                }
+            }
+            g_slist_free(contacts);
+        }
+        free(by);
+    }
+}
+
+void
+rosterwin_init_module(void)
+{
+    rosterwin_roster = _rosterwin_roster;
 }
\ No newline at end of file
diff --git a/src/ui/rosterwin.h b/src/ui/rosterwin.h
deleted file mode 100644
index 8272950e..00000000
--- a/src/ui/rosterwin.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * rosterwin.h
- *
- * Copyright (C) 2012 - 2014 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/>.
- *
- * In addition, as a special exception, the copyright holders give permission to
- * link the code of portions of this program with the OpenSSL library under
- * certain conditions as described in each individual source file, and
- * distribute linked combinations including the two.
- *
- * You must obey the GNU General Public License in all respects for all of the
- * code used other than OpenSSL. If you modify file(s) with this exception, you
- * may extend this exception to your version of the file(s), but you are not
- * obligated to do so. If you do not wish to do so, delete this exception
- * statement from your version. If you delete this exception statement from all
- * source files in the program, then also delete it here.
- *
- */
-
-void rosterwin_contact(PContact contact);
diff --git a/src/ui/ui.h b/src/ui/ui.h
index da43a5e1..27fddffa 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -55,6 +55,7 @@
 
 void ui_init_module(void);
 void console_init_module(void);
+void rosterwin_init_module(void);
 void notifier_init_module(void);
 
 // ui startup and control
@@ -248,7 +249,6 @@ void (*ui_open_xmlconsole_win)(void);
 gboolean (*ui_win_has_unsaved_form)(int num);
 
 void (*ui_muc_roster)(const char * const room);
-void (*ui_roster)(void);
 
 // console window actions
 void (*cons_show)(const char * const msg, ...);
@@ -328,6 +328,9 @@ void (*cons_show_contact_online)(PContact contact, Resource *resource, GDateTime
 void (*cons_show_contact_offline)(PContact contact, char *resource, char *status);
 void (*cons_theme_colours)(void);
 
+// roster window
+void (*rosterwin_roster)(void);
+
 // desktop notifier actions
 void (*notifier_uninit)(void);
 
diff --git a/src/ui/windows.c b/src/ui/windows.c
index 4c5a7e1c..751f068d 100644
--- a/src/ui/windows.c
+++ b/src/ui/windows.c
@@ -345,7 +345,7 @@ wins_resize_all(void)
                 }
                 wresize(layout->super.win, PAD_SIZE, cols - subwin_cols);
                 wresize(layout->subwin, PAD_SIZE, subwin_cols);
-                ui_roster();
+                rosterwin_roster();
             } else {
                 wresize(layout->super.win, PAD_SIZE, cols);
             }
diff --git a/tests/test_server_events.c b/tests/test_server_events.c
index f64ce2b4..d4a2ce01 100644
--- a/tests/test_server_events.c
+++ b/tests/test_server_events.c
@@ -18,7 +18,7 @@ void console_doesnt_show_online_presence_when_set_none(void **state)
 {
     mock_cons_show_contact_online();
     stub_ui_chat_win_contact_online();
-    stub_ui_roster();
+    stub_rosterwin_roster();
     prefs_set_string(PREF_STATUSES_CONSOLE, "none");
     roster_init();
     roster_add("test1@server", "bob", NULL, "both", FALSE);
diff --git a/tests/ui/mock_ui.c b/tests/ui/mock_ui.c
index 17d58c04..f84ce2e2 100644
--- a/tests/ui/mock_ui.c
+++ b/tests/ui/mock_ui.c
@@ -29,7 +29,7 @@ void _stub_cons_show(const char * const msg, ...)
 }
 
 static
-void _stub_ui_roster(void)
+void _stub_rosterwin_roster(void)
 {
 }
 
@@ -206,9 +206,9 @@ stub_ui_chat_win_contact_online(void)
 }
 
 void
-stub_ui_roster(void)
+stub_rosterwin_roster(void)
 {
-    ui_roster = _stub_ui_roster;
+    rosterwin_roster = _stub_rosterwin_roster;
 }
 
 void
diff --git a/tests/ui/mock_ui.h b/tests/ui/mock_ui.h
index 99a460ac..7214ca52 100644
--- a/tests/ui/mock_ui.h
+++ b/tests/ui/mock_ui.h
@@ -10,7 +10,7 @@
 #include "ui/window.h"
 
 void stub_cons_show(void);
-void stub_ui_roster(void);
+void stub_rosterwin_roster(void);
 
 void mock_cons_show(void);
 void expect_cons_show(char *output);