about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-02-13 00:53:10 +0000
committerJames Booth <boothj5@gmail.com>2012-02-13 00:53:10 +0000
commit0e473e34aa76328f0709df830d8688773a7369fc (patch)
tree3d899f0905b8264cd3a67206024ede0f65030421
parentda0fd22761a80e415a731bef92ab2149f4759c93 (diff)
downloadprofani-tty-0e473e34aa76328f0709df830d8688773a7369fc.tar.gz
Tidy up printing to message windows
-rw-r--r--windows.c134
1 files changed, 50 insertions, 84 deletions
diff --git a/windows.c b/windows.c
index b82b98b6..94620dcf 100644
--- a/windows.c
+++ b/windows.c
@@ -7,6 +7,7 @@ static struct prof_win _wins[10];
 static int _curr_win = 0;
 
 static void _create_windows(void);
+static void _send_message_to_win(char *contact, char *line);
 
 void gui_init(void)
 {
@@ -98,48 +99,7 @@ void win_show_incomming_msg(char *from, char *message)
     get_time(tstmp);
 
     sprintf(line, " [%s] <%s> %s\n", tstmp, short_from, message);
-
-    // find the chat window for sender
-    int i;
-    for (i = 1; i < 10; i++)
-        if (strcmp(_wins[i].from, short_from) == 0)
-            break;
-
-    // if we didn't find a window
-    if (i == 10) {
-        // find the first unused one
-        for (i = 1; i < 10; i++)
-            if (strcmp(_wins[i].from, "") == 0)
-                break;
-
-        // set it up and print the message to it
-        strcpy(_wins[i].from, short_from);
-        wclear(_wins[i].win);
-        wprintw(_wins[i].win, line);
-        
-        // signify active window in status bar
-        status_bar_active(i);
-        
-        // if its the current window, draw it
-        if (_curr_win == i) {
-            touchwin(_wins[i].win);
-            wrefresh(_wins[i].win);
-        }
-    }
-    // otherwise 
-    else {
-        // add the line to the senders window
-        wprintw(_wins[i].win, line);
-        
-        // signify active window in status bar
-        status_bar_active(i);
-        
-        // if its the current window, draw it
-        if (_curr_win == i) {
-            touchwin(_wins[i].win);
-            wrefresh(_wins[i].win);
-        }
-    }
+    _send_message_to_win(short_from, line);
 }
 
 void win_show_outgoing_msg(char *from, char *to, char *message)
@@ -147,49 +107,9 @@ void win_show_outgoing_msg(char *from, char *to, char *message)
     char line[100];
     char tstmp[80];
     get_time(tstmp);
-    sprintf(line, " [%s] <%s> %s\n", tstmp, from, message);
-
-    // find the chat window for recipient
-    int i;
-    for (i = 1; i < 10; i++)
-        if (strcmp(_wins[i].from, to) == 0)
-            break;
-
-    // if we didn't find a window
-    if (i == 10) {
-        // find the first unused one
-        for (i = 1; i < 10; i++)
-            if (strcmp(_wins[i].from, "") == 0)
-                break;
-
-        // set it up and print the message to it
-        strcpy(_wins[i].from, to);
-        wclear(_wins[i].win);
-        wprintw(_wins[i].win, line);
 
-        // signify active window in status bar
-        status_bar_active(i);
-
-        // if its the current window, draw it
-        if (_curr_win == i) {
-            touchwin(_wins[i].win);
-            wrefresh(_wins[i].win);
-        }
-    }
-    // otherwise 
-    else {
-        // add the line to the senders window
-        wprintw(_wins[i].win, line);
-
-        // signify active window in status bar
-        status_bar_active(i);
-
-        // if its the current window, draw it
-        if (_curr_win == i) {
-            touchwin(_wins[i].win);
-            wrefresh(_wins[i].win);
-        }
-    }
+    sprintf(line, " [%s] <%s> %s\n", tstmp, from, message);
+    _send_message_to_win(to, line);
 }
 
 void cons_help(void)
@@ -284,3 +204,49 @@ static void _create_windows(void)
         _wins[i] = chat;
     }    
 }
+
+static void _send_message_to_win(char *contact, char *line)
+{
+    // find the chat window for recipient
+    int i;
+    for (i = 1; i < 10; i++)
+        if (strcmp(_wins[i].from, contact) == 0)
+            break;
+
+    // if we didn't find a window
+    if (i == 10) {
+        // find the first unused one
+        for (i = 1; i < 10; i++)
+            if (strcmp(_wins[i].from, "") == 0)
+                break;
+
+        // set it up and print the message to it
+        strcpy(_wins[i].from, contact);
+        wclear(_wins[i].win);
+        wprintw(_wins[i].win, line);
+
+        // signify active window in status bar
+        status_bar_active(i);
+
+        // if its the current window, draw it
+        if (_curr_win == i) {
+            touchwin(_wins[i].win);
+            wrefresh(_wins[i].win);
+        }
+    }
+    // otherwise 
+    else {
+        // add the line to the senders window
+        wprintw(_wins[i].win, line);
+
+        // signify active window in status bar
+        status_bar_active(i);
+
+        // if its the current window, draw it
+        if (_curr_win == i) {
+            touchwin(_wins[i].win);
+            wrefresh(_wins[i].win);
+        }
+    }
+}
+