about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--command.c7
-rw-r--r--contact_list.c27
-rw-r--r--jabber.c9
-rw-r--r--test_contact_list.c7
-rw-r--r--windows.c37
-rw-r--r--windows.h2
7 files changed, 61 insertions, 30 deletions
diff --git a/Makefile b/Makefile
index 7102b0be..9020ddd6 100644
--- a/Makefile
+++ b/Makefile
@@ -12,7 +12,7 @@ profanity: $(OBJS)
 	$(CC) -o profanity $(OBJS) $(LIBS)
 
 log.o: log.h
-windows.o: windows.h util.h
+windows.o: windows.h util.h contact_list.h
 title_bar.o: windows.h
 status_bar.o: windows.h util.h
 input_win.o: windows.h
diff --git a/command.c b/command.c
index 41792315..dd0e8a79 100644
--- a/command.c
+++ b/command.c
@@ -149,12 +149,7 @@ static int _cmd_who(void)
 static int _cmd_pres(void)
 {
     struct contact_list *list = get_contact_list();
-
-    int i;
-    for (i = 0; i < list->size; i++) {
-        char *contact = list->contacts[i];
-        cons_show(contact);
-    }
+    cons_show_online_contacts(list);
 
     return TRUE;
 }
diff --git a/contact_list.c b/contact_list.c
index 24f2a41a..04ca1d35 100644
--- a/contact_list.c
+++ b/contact_list.c
@@ -32,7 +32,31 @@ void contact_list_clear(void)
 
 int contact_list_remove(char *contact)
 {
-    return 0;
+    if (!_contact_list) {
+        return 0;
+    } else {
+        struct _contact_t *curr = _contact_list;
+        struct _contact_t *prev = NULL;
+        
+        while(curr) {
+            if (strcmp(curr->contact, contact) == 0) {
+                if (prev)
+                    prev->next = curr->next;
+                else
+                    _contact_list = curr->next;
+                
+                free(curr->contact);
+                free(curr);
+
+                return 1;
+            }
+
+            prev = curr;
+            curr = curr->next;
+        }
+
+        return 0;
+    }
 }
 
 int contact_list_add(char *contact)
@@ -81,7 +105,6 @@ struct contact_list *get_contact_list(void)
                 (char *) malloc((strlen(curr->contact) + 1) * sizeof(char));
             strcpy(list->contacts[count], curr->contact);
             count++;
-            
             curr = curr->next;
         }
     }
diff --git a/jabber.c b/jabber.c
index a77117dc..500838a8 100644
--- a/jabber.c
+++ b/jabber.c
@@ -244,13 +244,13 @@ static int _roster_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanz
             jid = xmpp_stanza_get_attribute(item, "jid");
 
             if (name != NULL) {
-                char line[2 + strlen(name) + 2 + strlen(jid) + 1 + 1];
-                sprintf(line, "  %s (%s)", name, jid);
+                char line[strlen(name) + 2 + strlen(jid) + 1 + 1];
+                sprintf(line, "%s (%s)", name, jid);
                 cons_show(line);
 
             } else {
-                char line[2 + strlen(jid) + 1];
-                sprintf(line, "  %s", jid);
+                char line[strlen(jid) + 1];
+                sprintf(line, "%s", jid);
                 cons_show(line);
             }
         
@@ -316,6 +316,7 @@ static int _jabber_presence_handler(xmpp_conn_t * const conn,
         contact_list_add(short_from);
     } else {// offline
         win_contact_offline(short_from, show_str, status_str);
+        contact_list_remove(short_from);
     }
 
     win_page_off();
diff --git a/test_contact_list.c b/test_contact_list.c
index 14777e8a..09bb66d6 100644
--- a/test_contact_list.c
+++ b/test_contact_list.c
@@ -113,7 +113,7 @@ static void add_twice_at_end_adds_once(void)
     assert_string_equals("Bob", list->contacts[2]);
 
 }
-/*
+
 static void remove_when_none_does_nothing(void)
 {
     contact_list_remove("James");
@@ -195,7 +195,7 @@ static void remove_third_when_three(void)
     assert_int_equals(2, list->size);
     assert_string_equals("James", list->contacts[0]);
     assert_string_equals("Dave", list->contacts[1]);
-}*/
+}
 
 void register_contact_list_tests(void)
 {
@@ -211,12 +211,11 @@ void register_contact_list_tests(void)
     TEST(add_twice_at_beginning_adds_once);
     TEST(add_twice_in_middle_adds_once);
     TEST(add_twice_at_end_adds_once);
-/*    TEST(remove_when_none_does_nothing);
+    TEST(remove_when_none_does_nothing);
     TEST(remove_when_one_removes);
     TEST(remove_first_when_two);
     TEST(remove_second_when_two);
     TEST(remove_first_when_three);
     TEST(remove_second_when_three);
     TEST(remove_third_when_three);
-*/
 }
diff --git a/windows.c b/windows.c
index 03d1b155..2f296f83 100644
--- a/windows.c
+++ b/windows.c
@@ -211,24 +211,35 @@ void cons_help(void)
     _win_show_time(_cons_win);
     wprintw(_cons_win, "Help:\n");
 
-    cons_show("  Commands:");
-    cons_show("    /help                : This help.");
-    cons_show("    /connect user@host   : Login to jabber.");
-    cons_show("    /who                 : Get roster.");
-    cons_show("    /close               : Close a chat window.");
-    cons_show("    /msg user@host mesg  : Send mesg to user.");
-    cons_show("    /quit                : Quit Profanity.");
-    cons_show("  Keys:");
-    cons_show("    F1                   : This console window.");
-    cons_show("    F2-10                : Chat windows.");
-    cons_show("    UP, DOWN             : Navigate input history.");
-    cons_show("    LEFT, RIGHT          : Edit current input.");
-    cons_show("    PAGE UP, PAGE DOWN   : Page the chat window.");
+    cons_show("/help                : This help.");
+    cons_show("/connect user@host   : Login to jabber.");
+    cons_show("/who                 : Get roster.");
+    cons_show("/close               : Close a chat window.");
+    cons_show("/msg user@host mesg  : Send mesg to user.");
+    cons_show("/quit                : Quit Profanity.");
+    cons_show("F1                   : This console window.");
+    cons_show("F2-10                : Chat windows.");
+    cons_show("UP, DOWN             : Navigate input history.");
+    cons_show("LEFT, RIGHT          : Edit current input.");
+    cons_show("PAGE UP, PAGE DOWN   : Page the chat window.");
 
     if (_curr_prof_win == 0)
         dirty = TRUE;
 }
 
+void cons_show_online_contacts(struct contact_list *list)
+{
+    _win_show_time(_cons_win);
+    wprintw(_cons_win, "Online contacts:\n");
+
+    int i;
+    for (i = 0; i < list->size; i++) {
+        char *contact = list->contacts[i];
+        cons_show(contact);
+    }
+
+}
+
 void cons_bad_show(char *msg)
 {
     _win_show_time(_cons_win);
diff --git a/windows.h b/windows.h
index 377d6092..8bc21bb6 100644
--- a/windows.h
+++ b/windows.h
@@ -24,6 +24,7 @@
 #define WINDOWS_h
 
 #include <ncurses.h>
+#include "contact_list.h"
 
 struct prof_win {
     char from[100];
@@ -60,6 +61,7 @@ void win_handle_page(int *ch);
 void win_page_off(void);
 void win_contact_online(char *from, char *show, char *status);
 void win_contact_offline(char *from, char *show, char *status);
+void cons_show_online_contacts(struct contact_list *list);
 
 // console window actions
 void cons_help(void);