updates.
[silc.git] / apps / irssi / src / fe-common / core / fe-queries.c
index 44d7ef012bdea1da61cdea9539287f4961491e74..93f1304014c805088abbb128aa9780a172f45b03 100644 (file)
@@ -98,6 +98,10 @@ static void signal_query_destroyed(QUERY_REC *query)
 
        if (!query->unwanted)
                window_auto_destroy(window);
+       else {
+               /* eg. connection lost to dcc chat */
+               window_bind_add(window, query->server_tag, query->name);
+       }
 }
 
 static void signal_query_server_changed(QUERY_REC *query)
@@ -119,8 +123,13 @@ static void signal_query_nick_changed(QUERY_REC *query, const char *oldnick)
 
        format_create_dest_tag(&dest, query->server, query->server_tag,
                               query->name, MSGLEVEL_CLIENTNOTICE, NULL);
-       printformat_dest(&dest,  TXT_NICK_CHANGED, oldnick,
-                        query->name, query->name);
+
+       /* don't print the nick change message if only the case was changed */
+       if (g_strcasecmp(query->name, oldnick) != 0) {
+               printformat_dest(&dest,  TXT_NICK_CHANGED, oldnick,
+                                query->name, query->name,
+                                query->address == NULL ? "" : query->address);
+       }
 
        signal_emit("window item changed", 2,
                    window_item_window((WI_ITEM_REC *) query), query);
@@ -243,22 +252,12 @@ static void cmd_query(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
                query = CHAT_PROTOCOL(server)->
                        query_create(server->tag, nick, FALSE);
        else {
-               /* query already exists */
+               /* query already exists, set it active */
                WINDOW_REC *window = window_item_window(query);
 
-               if (window == active_win) {
-                        /* query is in active window, set it active */
-                       window_item_set_active(active_win,
-                                              (WI_ITEM_REC *) query);
-               } else {
-                       /* notify user how to move the query to active
-                          window. this was used to be done automatically
-                          but it just confused everyone who did it
-                          accidentally */
-                       printformat_window(active_win, MSGLEVEL_CLIENTNOTICE,
-                                          TXT_QUERY_MOVE_NOTIFY, query->name,
-                                          window->refnum);
-               }
+               if (window != active_win)
+                       window_set_active(window);
+               window_item_set_active(active_win, (WI_ITEM_REC *) query);
        }
 
        if (g_hash_table_lookup(optlist, "window") != NULL) {
@@ -275,32 +274,28 @@ static void cmd_query(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
        cmd_params_free(free_arg);
 }
 
-static int window_has_query(WINDOW_REC *window)
+static void window_reset_query_timestamps(WINDOW_REC *window)
 {
        GSList *tmp;
 
-       g_return_val_if_fail(window != NULL, FALSE);
+       if (window == NULL)
+                return;
 
        for (tmp = window->items; tmp != NULL; tmp = tmp->next) {
-               if (IS_QUERY(tmp->data))
-                       return TRUE;
-       }
+               QUERY_REC *query = QUERY(tmp->data);
 
-       return FALSE;
+               if (query != NULL)
+                        query->last_unread_msg = time(NULL);
+       }
 }
 
 static void sig_window_changed(WINDOW_REC *window, WINDOW_REC *old_window)
 {
-       if (query_auto_close <= 0)
-               return;
-
-       /* reset the window's last_line timestamp so that query doesn't get
-          closed immediately after switched to the window, or after changed
-          to some other window from it */
-       if (window != NULL && window_has_query(window))
-               window->last_line = time(NULL);
-       if (old_window != NULL && window_has_query(old_window))
-               old_window->last_line = time(NULL);
+       /* reset the queries last_unread_msg so query doesn't get closed
+          immediately after switched to the window, or after changed to
+          some other window from it */
+        window_reset_query_timestamps(window);
+        window_reset_query_timestamps(old_window);
 }
 
 static int sig_query_autoclose(void)
@@ -315,8 +310,8 @@ static int sig_query_autoclose(void)
 
                next = tmp->next;
                window = window_item_window((WI_ITEM_REC *) rec);
-               if (window != active_win && rec->data_level == 0 &&
-                   now-window->last_line > query_auto_close)
+               if (window != active_win && rec->data_level < DATA_LEVEL_MSG &&
+                   now-rec->last_unread_msg > query_auto_close)
                        query_destroy(rec);
        }
         return 1;
@@ -325,8 +320,14 @@ static int sig_query_autoclose(void)
 static void sig_message_private(SERVER_REC *server, const char *msg,
                                const char *nick, const char *address)
 {
+       QUERY_REC *query;
+
        /* create query window if needed */
-       privmsg_get_query(server, nick, FALSE, MSGLEVEL_MSGS);
+       query = privmsg_get_query(server, nick, FALSE, MSGLEVEL_MSGS);
+
+       /* reset the query's last_unread_msg timestamp */
+        if (query != NULL)
+               query->last_unread_msg = time(NULL);
 }
 
 static void read_settings(void)