about summary refs log tree commit diff stats
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-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
5 files changed, 143 insertions, 163 deletions
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);
             }