about summary refs log tree commit diff stats
path: root/src/ui/core.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/core.c')
-rw-r--r--src/ui/core.c193
1 files changed, 137 insertions, 56 deletions
diff --git a/src/ui/core.c b/src/ui/core.c
index 2e8ae9ff..e0f46f6e 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -122,7 +122,7 @@ ui_update(void)
 
     win_update_virtual(current);
 
-    if (prefs_get_boolean(PREF_TITLEBAR)) {
+    if (prefs_get_boolean(PREF_TITLEBAR_SHOW)) {
         _ui_draw_term_title();
     }
     title_bar_update_virtual();
@@ -180,7 +180,11 @@ ui_get_char(char *input, int *size, int *result)
     wint_t ch = inp_get_char(input, size, result);
     if (ch != ERR && *result != ERR) {
         ui_reset_idle_time();
+        ui_input_nonblocking(TRUE);
+    } else {
+        ui_input_nonblocking(FALSE);
     }
+
     return ch;
 }
 
@@ -197,9 +201,34 @@ ui_replace_input(char *input, const char * const new_input, int *size)
 }
 
 void
-ui_input_nonblocking(void)
+ui_input_nonblocking(gboolean reset)
 {
-    inp_non_block();
+    static gint timeout = 0;
+    static gint no_input_count = 0;
+
+    if (! prefs_get_boolean(PREF_INPBLOCK_DYNAMIC)) {
+        inp_non_block(prefs_get_inpblock());
+        return;
+    }
+
+    if (reset) {
+        timeout = 0;
+        no_input_count = 0;
+    }
+
+    if (timeout < prefs_get_inpblock()) {
+        no_input_count++;
+
+        if (no_input_count % 10 == 0) {
+            timeout += no_input_count;
+
+            if (timeout > prefs_get_inpblock()) {
+                timeout = prefs_get_inpblock();
+            }
+        }
+    }
+
+    inp_non_block(timeout);
 }
 
 void
@@ -272,11 +301,19 @@ ui_handle_stanza(const char * const msg)
     }
 }
 
+gboolean
+ui_chat_win_exists(const char * const barejid)
+{
+    ProfChatWin *chatwin = wins_get_chat(barejid);
+    return (chatwin != NULL);
+}
+
 void
-ui_contact_typing(const char * const barejid)
+ui_contact_typing(const char * const barejid, const char * const resource)
 {
     ProfChatWin *chatwin = wins_get_chat(barejid);
     ProfWin *window = (ProfWin*) chatwin;
+    ChatSession *session = chat_session_get(barejid);
 
     if (prefs_get_boolean(PREF_INTYPE)) {
         // no chat window for user
@@ -287,8 +324,8 @@ ui_contact_typing(const char * const barejid)
         } else if (!wins_is_current(window)) {
             cons_show_typing(barejid);
 
-        // in chat window with user
-        } else {
+        // in chat window with user, no session or session with resource
+        } else if (!session || (session && g_strcmp0(session->resource, resource) == 0)) {
             title_bar_set_typing(TRUE);
 
             int num = wins_get_num(window);
@@ -328,20 +365,25 @@ ui_get_current_chat(void)
 }
 
 void
-ui_incoming_msg(const char * const barejid, const char * const message, GTimeVal *tv_stamp)
+ui_incoming_msg(const char * const barejid, const char * const resource, const char * const message, GTimeVal *tv_stamp)
 {
     gboolean win_created = FALSE;
-    char *display_from = NULL;
+    GString *user = g_string_new("");
 
     PContact contact = roster_get_contact(barejid);
     if (contact != NULL) {
         if (p_contact_name(contact) != NULL) {
-            display_from = strdup(p_contact_name(contact));
+            g_string_append(user, p_contact_name(contact));
         } else {
-            display_from = strdup(barejid);
+            g_string_append(user, barejid);
         }
     } else {
-        display_from = strdup(barejid);
+        g_string_append(user, barejid);
+    }
+
+    if (resource && prefs_get_boolean(PREF_RESOURCE_MESSAGE)) {
+        g_string_append(user, "/");
+        g_string_append(user, resource);
     }
 
     ProfChatWin *chatwin = wins_get_chat(barejid);
@@ -362,14 +404,14 @@ ui_incoming_msg(const char * const barejid, const char * const message, GTimeVal
 
     // currently viewing chat window with sender
     if (wins_is_current(window)) {
-        win_print_incoming_message(window, tv_stamp, display_from, message);
+        win_print_incoming_message(window, tv_stamp, user->str, message);
         title_bar_set_typing(FALSE);
         status_bar_active(num);
 
     // not currently viewing chat window with sender
     } else {
         status_bar_new(num);
-        cons_show_incoming_message(display_from, num);
+        cons_show_incoming_message(user->str, num);
 
         if (prefs_get_boolean(PREF_FLASH)) {
             flash();
@@ -388,7 +430,7 @@ ui_incoming_msg(const char * const barejid, const char * const message, GTimeVal
             }
         }
 
-        win_print_incoming_message(window, tv_stamp, display_from, message);
+        win_print_incoming_message(window, tv_stamp, user->str, message);
     }
 
     int ui_index = num;
@@ -404,14 +446,14 @@ ui_incoming_msg(const char * const barejid, const char * const message, GTimeVal
         gboolean is_current = wins_is_current(window);
         if ( !is_current || (is_current && prefs_get_boolean(PREF_NOTIFY_MESSAGE_CURRENT)) ) {
             if (prefs_get_boolean(PREF_NOTIFY_MESSAGE_TEXT)) {
-                notify_message(display_from, ui_index, message);
+                notify_message(user->str, ui_index, message);
             } else {
-                notify_message(display_from, ui_index, NULL);
+                notify_message(user->str, ui_index, NULL);
             }
         }
     }
 
-    free(display_from);
+    g_string_free(user, TRUE);
 }
 
 void
@@ -586,14 +628,6 @@ ui_update_presence(const resource_presence_t resource_presence,
 void
 ui_handle_recipient_not_found(const char * const recipient, const char * const err_msg)
 {
-    // unknown chat recipient
-    ProfChatWin *chatwin = wins_get_chat(recipient);
-    if (chatwin) {
-        cons_show_error("Recipient %s not found: %s", recipient, err_msg);
-        win_save_vprint((ProfWin*) chatwin, '!', NULL, 0, THEME_ERROR, "", "Recipient %s not found: %s", recipient, err_msg);
-        return;
-    }
-
     // intended recipient was invalid chat room
     ProfMucWin *mucwin = wins_get_muc(recipient);
     if (mucwin) {
@@ -601,17 +635,6 @@ ui_handle_recipient_not_found(const char * const recipient, const char * const e
         win_save_vprint((ProfWin*) mucwin, '!', NULL, 0, THEME_ERROR, "", "Room %s not found: %s", recipient, err_msg);
         return;
     }
-
-    // unknown private recipient
-    ProfPrivateWin *privatewin = wins_get_private(recipient);
-    if (privatewin) {
-        cons_show_error("Recipient %s not found: %s", recipient, err_msg);
-        win_save_vprint((ProfWin*) privatewin, '!', NULL, 0, THEME_ERROR, "", "Recipient %s not found: %s", recipient, err_msg);
-        return;
-    }
-
-    // no window
-    cons_show_error("Recipient %s not found: %s", recipient, err_msg);
 }
 
 void
@@ -705,7 +728,8 @@ ui_close_connected_win(int index)
                 otr_end_session(chatwin->barejid);
             }
 #endif
-            chat_session_on_window_close(chatwin->barejid);
+            chat_state_gone(chatwin->barejid, chatwin->state);
+            chat_session_remove(chatwin->barejid);
         }
     }
 }
@@ -945,8 +969,6 @@ ui_gone_secure(const char * const barejid, gboolean trusted)
         chatwin = (ProfChatWin*)window;
     }
 
-    FREE_SET_NULL(chatwin->resource);
-
     chatwin->is_otr = TRUE;
     chatwin->is_trusted = trusted;
     if (trusted) {
@@ -1162,7 +1184,7 @@ ui_prune_wins(void)
         if (window->type == WIN_CHAT) {
             if (conn_status == JABBER_CONNECTED) {
                 ProfChatWin *chatwin = (ProfChatWin*)window;
-                chat_session_on_window_close(chatwin->barejid);
+                chat_session_remove(chatwin->barejid);
             }
         }
 
@@ -1280,26 +1302,36 @@ ui_print_system_msg_from_recipient(const char * const barejid, const char *messa
 }
 
 void
-ui_recipient_gone(const char * const barejid)
+ui_recipient_gone(const char * const barejid, const char * const resource)
 {
     if (barejid == NULL)
         return;
+    if (resource == NULL)
+        return;
 
-    const char * display_usr = NULL;
-    PContact contact = roster_get_contact(barejid);
-    if (contact != NULL) {
-        if (p_contact_name(contact) != NULL) {
-            display_usr = p_contact_name(contact);
-        } else {
-            display_usr = barejid;
+    gboolean show_message = TRUE;
+
+    ProfChatWin *chatwin = wins_get_chat(barejid);
+    if (chatwin) {
+        ChatSession *session = chat_session_get(barejid);
+        if (session && g_strcmp0(session->resource, resource) != 0) {
+            show_message = FALSE;
         }
-    } else {
-        display_usr = barejid;
-    }
+        if (show_message) {
+            const char * display_usr = NULL;
+            PContact contact = roster_get_contact(barejid);
+            if (contact != NULL) {
+                if (p_contact_name(contact) != NULL) {
+                    display_usr = p_contact_name(contact);
+                } else {
+                    display_usr = barejid;
+                }
+            } else {
+                display_usr = barejid;
+            }
 
-    ProfWin *window = (ProfWin*)wins_get_chat(barejid);
-    if (window != NULL) {
-        win_save_vprint(window, '!', NULL, 0, THEME_GONE, "", "<- %s has left the conversation.", display_usr);
+            win_save_vprint((ProfWin*)chatwin, '!', NULL, 0, THEME_GONE, "", "<- %s has left the conversation.", display_usr);
+        }
     }
 }
 
@@ -1381,9 +1413,9 @@ ui_outgoing_chat_msg(const char * const from, const char * const barejid,
     // create new window
     if (window == NULL) {
         window = wins_new_chat(barejid);
+        ProfChatWin *chatwin = (ProfChatWin*)window;
 #ifdef HAVE_LIBOTR
         if (otr_is_secure(barejid)) {
-            ProfChatWin *chatwin = (ProfChatWin*)window;
             chatwin->is_otr = TRUE;
         }
 #endif
@@ -1405,6 +1437,8 @@ ui_outgoing_chat_msg(const char * const from, const char * const barejid,
     } else {
         num = wins_get_num(window);
     }
+    ProfChatWin *chatwin = (ProfChatWin*)window;
+    chat_state_active(chatwin->state);
 
     win_save_print(window, '-', NULL, 0, THEME_TEXT_ME, from, message);
     ui_switch_win(num);
@@ -2213,7 +2247,7 @@ ui_ask_password(void)
   status_bar_update_virtual();
   inp_block();
   inp_get_password(passwd);
-  inp_non_block();
+  inp_non_block(prefs_get_inpblock());
 
   return passwd;
 }
@@ -2251,12 +2285,59 @@ ui_chat_win_contact_offline(PContact contact, char *resource, char *status)
 }
 
 void
+ui_contact_offline(char *barejid, char *resource, char *status)
+{
+    char *show_console = prefs_get_string(PREF_STATUSES_CONSOLE);
+    char *show_chat_win = prefs_get_string(PREF_STATUSES_CHAT);
+    Jid *jid = jid_create_from_bare_and_resource(barejid, resource);
+    PContact contact = roster_get_contact(barejid);
+    if (p_contact_subscription(contact) != NULL) {
+        if (strcmp(p_contact_subscription(contact), "none") != 0) {
+
+            // show in console if "all"
+            if (g_strcmp0(show_console, "all") == 0) {
+                cons_show_contact_offline(contact, resource, status);
+
+            // show in console of "online"
+            } else if (g_strcmp0(show_console, "online") == 0) {
+                cons_show_contact_offline(contact, resource, status);
+            }
+
+            // show in chat win if "all"
+            if (g_strcmp0(show_chat_win, "all") == 0) {
+                ui_chat_win_contact_offline(contact, resource, status);
+
+            // show in char win if "online" and presence online
+            } else if (g_strcmp0(show_chat_win, "online") == 0) {
+                ui_chat_win_contact_offline(contact, resource, status);
+            }
+        }
+    }
+
+    ProfChatWin *chatwin = wins_get_chat(barejid);
+    if (chatwin && chatwin->resource_override && (g_strcmp0(resource, chatwin->resource_override) == 0)) {
+        FREE_SET_NULL(chatwin->resource_override);
+    }
+
+    prefs_free_string(show_console);
+    prefs_free_string(show_chat_win);
+    jid_destroy(jid);
+}
+
+void
 ui_clear_win_title(void)
 {
     printf("%c]0;%c", '\033', '\007');
 }
 
 void
+ui_goodbye_title(void)
+{
+    int result = system("/bin/echo -ne \"\033]0;Thanks for using Profanity\007\"");
+    if(result == -1) log_error("Error printing title on shutdown");
+}
+
+void
 ui_statusbar_new(const int win)
 {
     status_bar_new(win);