about summary refs log tree commit diff stats
path: root/src/windows.c
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-11-13 22:08:46 +0000
committerJames Booth <boothj5@gmail.com>2012-11-13 22:08:46 +0000
commite506986ef5dc713e16a20b04b68f0c00ab7dab5e (patch)
tree73f8c4ce99344283ba322434ae3927cc3f089222 /src/windows.c
parent2afe7b83aba2581cc33cee64b34eb9faf608bdab (diff)
downloadprofani-tty-e506986ef5dc713e16a20b04b68f0c00ab7dab5e.tar.gz
Added basic /status command to find out about a specific contact
Diffstat (limited to 'src/windows.c')
-rw-r--r--src/windows.c124
1 files changed, 72 insertions, 52 deletions
diff --git a/src/windows.c b/src/windows.c
index 0350cc59..a91d1940 100644
--- a/src/windows.c
+++ b/src/windows.c
@@ -69,6 +69,7 @@ static int max_cols = 0;
 static void _create_windows(void);
 static void _cons_splash_logo(void);
 static void _cons_show_basic_help(void);
+static void _cons_show_contact(PContact contact);
 static int _find_prof_win_index(const char * const contact);
 static int _new_prof_win(const char * const contact, win_type_t type);
 static void _current_window_refresh(void);
@@ -808,6 +809,20 @@ win_contact_offline(const char * const from, const char * const show,
 }
 
 void
+win_show_status(const char * const contact)
+{
+    PContact pcontact = contact_list_get_contact(contact);
+
+    cons_show("");
+    if (pcontact != NULL) {
+        _cons_show_contact(pcontact);
+    } else {
+        cons_show("No such contact %s in roster.", contact);
+    }
+    cons_show("");
+}
+
+void
 win_disconnected(void)
 {
     int i;
@@ -1017,58 +1032,7 @@ cons_show_contacts(GSList *list)
 
     while(curr) {
         PContact contact = curr->data;
-        const char *jid = p_contact_jid(contact);
-        const char *name = p_contact_name(contact);
-        const char *presence = p_contact_presence(contact);
-        const char *status = p_contact_status(contact);
-        const char *sub = p_contact_subscription(contact);
-
-        if (strcmp(sub, "none") != 0) {
-            _win_show_time(_cons_win);
-
-            if (strcmp(presence, "online") == 0) {
-                wattron(_cons_win, COLOUR_ONLINE);
-            } else if (strcmp(presence, "away") == 0) {
-                wattron(_cons_win, COLOUR_AWAY);
-            } else if (strcmp(presence, "chat") == 0) {
-                wattron(_cons_win, COLOUR_CHAT);
-            } else if (strcmp(presence, "dnd") == 0) {
-                wattron(_cons_win, COLOUR_DND);
-            } else if (strcmp(presence, "xa") == 0) {
-                wattron(_cons_win, COLOUR_XA);
-            } else {
-                wattron(_cons_win, COLOUR_OFFLINE);
-            }
-
-            wprintw(_cons_win, "%s", jid);
-
-            if (name != NULL) {
-                wprintw(_cons_win, " (%s)", name);
-            }
-
-            wprintw(_cons_win, " is %s", presence);
-
-            if (status != NULL) {
-                wprintw(_cons_win, ", \"%s\"", p_contact_status(contact));
-            }
-
-            wprintw(_cons_win, "\n");
-
-            if (strcmp(presence, "online") == 0) {
-                wattroff(_cons_win, COLOUR_ONLINE);
-            } else if (strcmp(presence, "away") == 0) {
-                wattroff(_cons_win, COLOUR_AWAY);
-            } else if (strcmp(presence, "chat") == 0) {
-                wattroff(_cons_win, COLOUR_CHAT);
-            } else if (strcmp(presence, "dnd") == 0) {
-                wattroff(_cons_win, COLOUR_DND);
-            } else if (strcmp(presence, "xa") == 0) {
-                wattroff(_cons_win, COLOUR_XA);
-            } else {
-                wattroff(_cons_win, COLOUR_OFFLINE);
-            }
-        }
-
+        _cons_show_contact(contact);
         curr = g_slist_next(curr);
     }
 }
@@ -1547,6 +1511,62 @@ _cons_show_incoming_message(const char * const short_from, const int win_index)
 }
 
 static void
+_cons_show_contact(PContact contact)
+{
+    const char *jid = p_contact_jid(contact);
+    const char *name = p_contact_name(contact);
+    const char *presence = p_contact_presence(contact);
+    const char *status = p_contact_status(contact);
+    const char *sub = p_contact_subscription(contact);
+
+    if (strcmp(sub, "none") != 0) {
+        _win_show_time(_cons_win);
+
+        if (strcmp(presence, "online") == 0) {
+            wattron(_cons_win, COLOUR_ONLINE);
+        } else if (strcmp(presence, "away") == 0) {
+            wattron(_cons_win, COLOUR_AWAY);
+        } else if (strcmp(presence, "chat") == 0) {
+            wattron(_cons_win, COLOUR_CHAT);
+        } else if (strcmp(presence, "dnd") == 0) {
+            wattron(_cons_win, COLOUR_DND);
+        } else if (strcmp(presence, "xa") == 0) {
+            wattron(_cons_win, COLOUR_XA);
+        } else {
+            wattron(_cons_win, COLOUR_OFFLINE);
+        }
+
+        wprintw(_cons_win, "%s", jid);
+
+        if (name != NULL) {
+            wprintw(_cons_win, " (%s)", name);
+        }
+
+        wprintw(_cons_win, " is %s", presence);
+
+        if (status != NULL) {
+            wprintw(_cons_win, ", \"%s\"", p_contact_status(contact));
+        }
+
+        wprintw(_cons_win, "\n");
+
+        if (strcmp(presence, "online") == 0) {
+            wattroff(_cons_win, COLOUR_ONLINE);
+        } else if (strcmp(presence, "away") == 0) {
+            wattroff(_cons_win, COLOUR_AWAY);
+        } else if (strcmp(presence, "chat") == 0) {
+            wattroff(_cons_win, COLOUR_CHAT);
+        } else if (strcmp(presence, "dnd") == 0) {
+            wattroff(_cons_win, COLOUR_DND);
+        } else if (strcmp(presence, "xa") == 0) {
+            wattroff(_cons_win, COLOUR_XA);
+        } else {
+            wattroff(_cons_win, COLOUR_OFFLINE);
+        }
+    }
+}
+
+static void
 _win_handle_switch(const int * const ch)
 {
     if (*ch == KEY_F(1)) {