about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-11-14 00:39:34 +0000
committerJames Booth <boothj5@gmail.com>2012-11-14 00:39:34 +0000
commitde2f060742ee4aa7d47fae12eefe0da1977b4125 (patch)
tree74053452ff451a6a331010784a5c732914429ac9 /src
parenta574f7ff40c5c82e47dfb2c705fef9d7cf78a7da (diff)
downloadprofani-tty-de2f060742ee4aa7d47fae12eefe0da1977b4125.tar.gz
Added /wins command to list active windows
Diffstat (limited to 'src')
-rw-r--r--src/command.c20
-rw-r--r--src/ui.h2
-rw-r--r--src/windows.c61
3 files changed, 80 insertions, 3 deletions
diff --git a/src/command.c b/src/command.c
index ae59e7b3..35e0968f 100644
--- a/src/command.c
+++ b/src/command.c
@@ -114,6 +114,7 @@ static gboolean _cmd_dnd(const char * const inp, struct cmd_help_t help);
 static gboolean _cmd_chat(const char * const inp, struct cmd_help_t help);
 static gboolean _cmd_xa(const char * const inp, struct cmd_help_t help);
 static gboolean _cmd_status(const char * const inp, struct cmd_help_t help);
+static gboolean _cmd_wins(const char * const inp, struct cmd_help_t help);
 
 /*
  * The commands are broken down into three groups:
@@ -219,6 +220,14 @@ static struct cmd_t main_commands[] =
           "Example : /join jdev@conference.jabber.org mynick",
           NULL } } },
 
+    { "/wins",
+        _cmd_wins,
+        { "/wins", "List active windows.",
+        { "/wins",
+          "-----",
+          "List all currently active windows and information about them.",
+          NULL } } },
+
     { "/sub",
         _cmd_sub,
         { "/sub <add|del|req|show> [jid]", "Manage subscriptions.",
@@ -688,7 +697,7 @@ cmd_execute_default(const char * const inp)
         char *recipient = win_get_recipient();
         jabber_send_groupchat(inp, recipient);
         free(recipient);
-    } else if (win_in_chat()) {
+    } else if (win_in_chat() || win_in_private_chat()) {
         char *recipient = win_get_recipient();
         jabber_send(inp, recipient);
 
@@ -941,6 +950,13 @@ _cmd_quit(const char * const inp, struct cmd_help_t help)
 }
 
 static gboolean
+_cmd_wins(const char * const inp, struct cmd_help_t help)
+{
+    win_show_wins();
+    return TRUE;
+}
+
+static gboolean
 _cmd_help(const char * const inp, struct cmd_help_t help)
 {
     if (strcmp(inp, "/help") == 0) {
@@ -1316,7 +1332,7 @@ _cmd_close(const char * const inp, struct cmd_help_t help)
         char *room_jid = win_get_recipient();
         jabber_leave_chat_room(room_jid);
         win_close_win();
-    } else if (win_in_chat()) {
+    } else if (win_in_chat() || win_in_private_chat()) {
 
         if (prefs_get_states()) {
             char *recipient = win_get_recipient();
diff --git a/src/ui.h b/src/ui.h
index 2d883835..bb2fb8cb 100644
--- a/src/ui.h
+++ b/src/ui.h
@@ -128,6 +128,8 @@ void win_show_room_subject(const char * const room_jid,
 void win_show_room_member_offline(const char * const room, const char * const nick);
 void win_show_room_member_online(const char * const room, const char * const nick);
 void win_show_status(const char * const contact);
+void win_show_wins(void);
+int win_in_private_chat(void);
 
 // console window actions
 void cons_about(void);
diff --git a/src/windows.c b/src/windows.c
index 0e747fef..00b77b14 100644
--- a/src/windows.c
+++ b/src/windows.c
@@ -205,6 +205,59 @@ win_in_groupchat(void)
     return (_wins[_curr_prof_win].type == WIN_MUC);
 }
 
+int
+win_in_private_chat(void)
+{
+    return (_wins[_curr_prof_win].type == WIN_PRIVATE);
+}
+
+void
+win_show_wins(void)
+{
+    int i = 0;
+    int count = 0;
+
+    for (i = 1; i < NUM_WINS; i++) {
+        if (_wins[i].type != WIN_UNUSED) {
+            count++;
+        }
+    }
+
+    cons_show("");
+
+    if (count == 0) {
+        cons_show("No active windows.");
+    } else if (count == 1) {
+        cons_show("1 active window:");
+    } else {
+        cons_show("%d active windows:", count);
+    }
+
+    if (count != 0) {
+        for (i = 1; i < NUM_WINS; i++) {
+            if (_wins[i].type != WIN_UNUSED) {
+                _win_show_time(_cons_win);
+                wprintw(_cons_win, "[%d] - ", i + 1);
+
+                switch (_wins[i].type)
+                {
+                    case WIN_CHAT:
+                        wprintw(_cons_win, "conversation : %s\n", _wins[i].from);
+                        break;
+                    case WIN_PRIVATE:
+                        wprintw(_cons_win, "private      : %s\n", _wins[i].from);
+                        break;
+                    case WIN_MUC:
+                        wprintw(_cons_win, "chat room    : %s\n", _wins[i].from);
+                        break;
+                    default:
+                        break;
+                }
+            }
+        }
+    }
+}
+
 char *
 win_get_recipient(void)
 {
@@ -535,7 +588,13 @@ win_show_outgoing_msg(const char * const from, const char * const to,
 
     // create new window
     if (win_index == NUM_WINS) {
-        win_index = _new_prof_win(to, WIN_CHAT);
+
+        if (room_is_active(to)) {
+            win_index = _new_prof_win(to, WIN_PRIVATE);
+        } else {
+            win_index = _new_prof_win(to, WIN_CHAT);
+        }
+
         win = _wins[win_index].win;
 
         if (prefs_get_chlog() && prefs_get_history()) {