about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/command.c33
-rw-r--r--src/input_win.c5
-rw-r--r--src/profanity.c25
-rw-r--r--src/profanity.h2
-rw-r--r--src/status_bar.c27
-rw-r--r--src/ui.h1
-rw-r--r--src/windows.c20
7 files changed, 96 insertions, 17 deletions
diff --git a/src/command.c b/src/command.c
index 864c0eba..715ad0ee 100644
--- a/src/command.c
+++ b/src/command.c
@@ -39,6 +39,7 @@
 #include "parser.h"
 #include "preferences.h"
 #include "prof_autocomplete.h"
+#include "profanity.h"
 #include "tinyurl.h"
 #include "ui.h"
 
@@ -728,20 +729,30 @@ gboolean
 cmd_execute_default(const char * const inp)
 {
     if (win_in_groupchat()) {
-        char *recipient = win_get_recipient();
-        jabber_send_groupchat(inp, recipient);
-        free(recipient);
+        jabber_conn_status_t status = jabber_get_connection_status();
+        if (status != JABBER_CONNECTED) {
+            win_show("You are not currently connected.");
+        } else {
+            char *recipient = win_get_recipient();
+            jabber_send_groupchat(inp, recipient);
+            free(recipient);
+        }
     } else if (win_in_chat() || win_in_private_chat()) {
-        char *recipient = win_get_recipient();
-        jabber_send(inp, recipient);
+        jabber_conn_status_t status = jabber_get_connection_status();
+        if (status != JABBER_CONNECTED) {
+            win_show("You are not currently connected.");
+        } else {
+            char *recipient = win_get_recipient();
+            jabber_send(inp, recipient);
 
-        if (prefs_get_chlog()) {
-            const char *jid = jabber_get_jid();
-            chat_log_chat(jid, recipient, inp, OUT, NULL);
-        }
+            if (prefs_get_chlog()) {
+                const char *jid = jabber_get_jid();
+                chat_log_chat(jid, recipient, inp, OUT, NULL);
+            }
 
-        win_show_outgoing_msg("me", recipient, inp);
-        free(recipient);
+            win_show_outgoing_msg("me", recipient, inp);
+            free(recipient);
+        }
     } else {
         cons_bad_command(inp);
     }
diff --git a/src/input_win.c b/src/input_win.c
index f04faba3..7d5a7485 100644
--- a/src/input_win.c
+++ b/src/input_win.c
@@ -57,6 +57,7 @@
 #include "history.h"
 #include "log.h"
 #include "preferences.h"
+#include "profanity.h"
 #include "ui.h"
 
 static WINDOW *inp_win;
@@ -145,11 +146,11 @@ inp_get_char(int *ch, char *input, int *size)
 
     if (prefs_get_states()) {
         if (*ch == ERR) {
-            win_no_activity();
+            prof_handle_idle();
         }
         if (prefs_get_outtype() && (*ch != ERR) && !in_command
                                                 && _printable(*ch)) {
-            win_activity();
+            prof_handle_activity();
         }
     }
 
diff --git a/src/profanity.c b/src/profanity.c
index cc6cb199..1b30296e 100644
--- a/src/profanity.c
+++ b/src/profanity.c
@@ -29,6 +29,7 @@
 #include <glib.h>
 
 #include "chat_log.h"
+#include "chat_session.h"
 #include "command.h"
 #include "common.h"
 #include "contact.h"
@@ -220,8 +221,14 @@ prof_handle_disconnect(const char * const jid)
 {
     jabber_disconnect();
     contact_list_clear();
+    chat_sessions_clear();
     jabber_restart();
+    win_disconnected();
+    title_bar_set_status(PRESENCE_OFFLINE);
+    status_bar_clear_message();
+    status_bar_refresh();
     cons_show("%s logged out successfully.", jid);
+    win_page_off();
 }
 
 void
@@ -348,6 +355,24 @@ prof_handle_room_nick_change(const char * const room,
     win_page_off();
 }
 
+void
+prof_handle_idle(void)
+{
+    jabber_conn_status_t status = jabber_get_connection_status();
+    if (status == JABBER_CONNECTED) {
+        win_no_activity();
+    }
+}
+
+void
+prof_handle_activity(void)
+{
+    jabber_conn_status_t status = jabber_get_connection_status();
+    if (status == JABBER_CONNECTED) {
+        win_activity();
+    }
+}
+
 static void
 _create_config_directory(void)
 {
diff --git a/src/profanity.h b/src/profanity.h
index a5b5b117..b91a17b2 100644
--- a/src/profanity.h
+++ b/src/profanity.h
@@ -62,5 +62,7 @@ void prof_handle_room_nick_change(const char * const room,
     const char * const nick);
 void prof_handle_room_broadcast(const char *const room_jid,
     const char * const message);
+void prof_handle_idle(void);
+void prof_handle_activity(void);
 
 #endif
diff --git a/src/status_bar.c b/src/status_bar.c
index 8d79fe5d..bfd25fca 100644
--- a/src/status_bar.c
+++ b/src/status_bar.c
@@ -219,6 +219,33 @@ status_bar_clear(void)
     dirty = TRUE;
 }
 
+void
+status_bar_clear_message(void)
+{
+    if (message != NULL) {
+        free(message);
+        message = NULL;
+    }
+
+    wclear(status_bar);
+
+    int cols = getmaxx(stdscr);
+
+    wattron(status_bar, COLOUR_BAR_DRAW);
+    mvwprintw(status_bar, 0, cols - 29, _active);
+    wattroff(status_bar, COLOUR_BAR_DRAW);
+
+    int i;
+    for(i = 0; i < 9; i++) {
+        if (is_new[i])
+            status_bar_new(i+1);
+        else if (is_active[i])
+            status_bar_active(i+1);
+    }
+
+    dirty = TRUE;
+}
+
 static void
 _status_bar_update_time(void)
 {
diff --git a/src/ui.h b/src/ui.h
index 0ef70a1f..68ee89d2 100644
--- a/src/ui.h
+++ b/src/ui.h
@@ -160,6 +160,7 @@ void cons_check_version(gboolean not_available_msg);
 void status_bar_refresh(void);
 void status_bar_resize(void);
 void status_bar_clear(void);
+void status_bar_clear_message(void);
 void status_bar_get_password(void);
 void status_bar_print_message(const char * const msg);
 void status_bar_inactive(const int win);
diff --git a/src/windows.c b/src/windows.c
index ecaa3c27..1881f23a 100644
--- a/src/windows.c
+++ b/src/windows.c
@@ -243,26 +243,38 @@ win_show_wins(void)
                     case WIN_CHAT:
                         wprintw(_cons_win, "%d: chat %s", i + 1, _wins[i].from);
                         PContact contact = contact_list_get_contact(_wins[i].from);
-                        if (p_contact_name(contact) != NULL) {
-                            wprintw(_cons_win, " (%s)", p_contact_name(contact));
+
+                        if (contact != NULL) {
+                            if (p_contact_name(contact) != NULL) {
+                                wprintw(_cons_win, " (%s)", p_contact_name(contact));
+                            }
+                            wprintw(_cons_win, " - %s", p_contact_presence(contact));
                         }
-                        wprintw(_cons_win, " - %s", p_contact_presence(contact));
+
                         if (_wins[i].unread > 0) {
                             wprintw(_cons_win, ", %d unread", _wins[i].unread);
                         }
+
                         break;
+
                     case WIN_PRIVATE:
                         wprintw(_cons_win, "%d: private %s", i + 1, _wins[i].from);
+
                         if (_wins[i].unread > 0) {
                             wprintw(_cons_win, ", %d unread", _wins[i].unread);
                         }
+
                         break;
+
                     case WIN_MUC:
                         wprintw(_cons_win, "%d: room %s", i + 1, _wins[i].from);
+
                         if (_wins[i].unread > 0) {
                             wprintw(_cons_win, ", %d unread", _wins[i].unread);
                         }
+
                         break;
+
                     default:
                         break;
                 }
@@ -976,7 +988,7 @@ win_disconnected(void)
     // show message in all active chats
     for (i = 1; i < NUM_WINS; i++) {
         if (strcmp(_wins[i].from, "") != 0) {
-            WINDOW *win = _wins[_curr_prof_win].win;
+            WINDOW *win = _wins[i].win;
             _win_show_time(win);
             wattron(win, COLOUR_ERR);
             wprintw(win, "%s\n", "Lost connection.");