Merged from silc_1_0_branch.
[silc.git] / apps / irssi / src / fe-common / core / fe-messages.c
index fa5e88af0200cf9852398c527e4895bbaf2d6744..31bbbfad056125c3ccee7b1dd7844af09ecbd423 100644 (file)
 #include "special-vars.h"
 #include "settings.h"
 
-#include "window-items.h"
-#include "fe-queries.h"
+#include "servers.h"
 #include "channels.h"
 #include "nicklist.h"
-#include "hilight-text.h"
 #include "ignore.h"
+
+#include "window-items.h"
+#include "fe-queries.h"
+#include "hilight-text.h"
 #include "printtext.h"
 
-#define ishighalnum(c) ((unsigned char) (c) >= 128 || isalnum(c))
+#define ishighalnum(c) ((unsigned char) (c) >= 128 || i_isalnum(c))
 
-static GHashTable *printnicks;
+GHashTable *printnicks;
 
 /* convert _underlined_ and *bold* words (and phrases) to use real
    underlining or bolding */
@@ -65,7 +67,7 @@ char *expand_emphasis(WI_ITEM_REC *item, const char *text)
 
                /* check that the beginning marker starts a word, and
                   that the matching end marker ends a word */
-               if ((pos > 0 && !isspace(bgn[-1])) || !ishighalnum(bgn[1]))
+               if ((pos > 0 && !i_isspace(bgn[-1])) || !ishighalnum(bgn[1]))
                        continue;
                if ((end = strchr(bgn+1, *bgn)) == NULL)
                        continue;
@@ -111,35 +113,28 @@ char *expand_emphasis(WI_ITEM_REC *item, const char *text)
        return ret;
 }
 
-char *channel_get_nickmode(CHANNEL_REC *channel, const char *nick)
+static char *channel_get_nickmode_rec(NICK_REC *nickrec)
 {
-        NICK_REC *nickrec;
         char *emptystr;
 
-       g_return_val_if_fail(nick != NULL, NULL);
-
        if (!settings_get_bool("show_nickmode"))
                 return "";
 
         emptystr = settings_get_bool("show_nickmode_empty") ? " " : "";
 
-       nickrec = channel == NULL ? NULL :
-               nicklist_find(channel, nick);
        return nickrec == NULL ? emptystr :
-               (nickrec->op ? "@" : (nickrec->voice ? "+" : emptystr));
+               nickrec->op ? "@" :
+               nickrec->halfop ? "%" :
+               nickrec->voice ? "+" :
+               emptystr;
 }
 
-static char *channel_get_nickmode_rec(NICK_REC *nickrec)
+char *channel_get_nickmode(CHANNEL_REC *channel, const char *nick)
 {
-        char *emptystr;
-
-       if (!settings_get_bool("show_nickmode"))
-                return "";
-
-        emptystr = settings_get_bool("show_nickmode_empty") ? " " : "";
+       g_return_val_if_fail(nick != NULL, NULL);
 
-       return nickrec == NULL ? emptystr :
-               (nickrec->op ? "@" : (nickrec->voice ? "+" : emptystr));
+        return channel_get_nickmode_rec(channel == NULL ? NULL :
+                                       nicklist_find(channel, nick));
 }
 
 static void sig_message_public(SERVER_REC *server, const char *msg,
@@ -157,7 +152,8 @@ static void sig_message_public(SERVER_REC *server, const char *msg,
        if (nickrec == NULL && chanrec != NULL)
                 nickrec = nicklist_find(chanrec, nick);
 
-       for_me = nick_match_msg(chanrec, msg, server->nick);
+       for_me = !settings_get_bool("hilight_nick_matches") ? FALSE :
+               nick_match_msg(chanrec, msg, server->nick);
        color = for_me ? NULL :
                hilight_match_nick(server, target, nick, address, MSGLEVEL_PUBLIC, msg);
 
@@ -167,8 +163,9 @@ static void sig_message_public(SERVER_REC *server, const char *msg,
            window_item_window((WI_ITEM_REC *) chanrec)->items->next != NULL)
                print_channel = TRUE;
 
-       level = MSGLEVEL_PUBLIC | (for_me || color != NULL ?
-                                  MSGLEVEL_HILIGHT : MSGLEVEL_NOHILIGHT);
+       level = MSGLEVEL_PUBLIC;
+       if (for_me || color != NULL)
+               level |= MSGLEVEL_HILIGHT;
 
        if (settings_get_bool("emphasis"))
                msg = freemsg = expand_emphasis((WI_ITEM_REC *) chanrec, msg);
@@ -230,14 +227,19 @@ static void sig_message_private(SERVER_REC *server, const char *msg,
        g_free_not_null(freemsg);
 }
 
-static void print_own_channel_message(SERVER_REC *server, CHANNEL_REC *channel,
-                                     const char *target, const char *msg)
+static void sig_message_own_public(SERVER_REC *server, const char *msg,
+                                  const char *target)
 {
        WINDOW_REC *window;
+       CHANNEL_REC *channel;
        const char *nickmode;
         char *freemsg = NULL;
        int print_channel;
 
+       channel = channel_find(server, target);
+       if (channel != NULL)
+               target = channel->visible_name;
+
        nickmode = channel_get_nickmode(channel, server->nick);
 
        window = channel == NULL ? NULL :
@@ -264,18 +266,6 @@ static void print_own_channel_message(SERVER_REC *server, CHANNEL_REC *channel,
        g_free_not_null(freemsg);
 }
 
-static void sig_message_own_public(SERVER_REC *server, const char *msg,
-                                  const char *target)
-{
-       CHANNEL_REC *channel;
-
-       g_return_if_fail(server != NULL);
-       g_return_if_fail(msg != NULL);
-
-       channel = channel_find(server, target);
-       print_own_channel_message(server, channel, target, msg);
-}
-
 static void sig_message_own_private(SERVER_REC *server, const char *msg,
                                    const char *target, const char *origtarget)
 {
@@ -350,7 +340,7 @@ static void sig_message_quit(SERVER_REC *server, const char *nick,
                if (!nicklist_find(rec, nick))
                        continue;
 
-               if (ignore_check(server, nick, address, rec->name,
+               if (ignore_check(server, nick, address, rec->visible_name,
                                 reason, MSGLEVEL_QUITS)) {
                        count++;
                        continue;
@@ -358,17 +348,18 @@ static void sig_message_quit(SERVER_REC *server, const char *nick,
 
                if (print_channel == NULL ||
                    active_win->active == (WI_ITEM_REC *) rec)
-                       print_channel = rec->name;
+                       print_channel = rec->visible_name;
 
                if (once)
-                       g_string_sprintfa(chans, "%s,", rec->name);
+                       g_string_sprintfa(chans, "%s,", rec->visible_name);
                else {
                        window = window_item_window((WI_ITEM_REC *) rec);
                        if (g_slist_find(windows, window) == NULL) {
                                windows = g_slist_append(windows, window);
-                               printformat(server, rec->name, MSGLEVEL_QUITS,
+                               printformat(server, rec->visible_name,
+                                           MSGLEVEL_QUITS,
                                            TXT_QUIT, nick, address, reason,
-                                           rec->name);
+                                           rec->visible_name);
                        }
                }
                count++;
@@ -400,7 +391,7 @@ static void sig_message_kick(SERVER_REC *server, const char *channel,
                             const char *address, const char *reason)
 {
        printformat(server, channel, MSGLEVEL_KICKS,
-                   TXT_KICK, nick, channel, kicker, reason);
+                   TXT_KICK, nick, channel, kicker, reason, address);
 }
 
 static void print_nick_change_channel(SERVER_REC *server, const char *channel,
@@ -408,13 +399,18 @@ static void print_nick_change_channel(SERVER_REC *server, const char *channel,
                                      const char *address,
                                      int ownnick)
 {
+       int level;
+
        if (ignore_check(server, oldnick, address,
                         channel, newnick, MSGLEVEL_NICKS))
                return;
 
-       printformat(server, channel, MSGLEVEL_NICKS,
+       level = MSGLEVEL_NICKS;
+        if (ownnick) level |= MSGLEVEL_NO_ACT;
+
+       printformat(server, channel, level,
                    ownnick ? TXT_YOUR_NICK_CHANGED : TXT_NICK_CHANGED,
-                   oldnick, newnick, channel);
+                   oldnick, newnick, channel, address);
 }
 
 static void print_nick_change(SERVER_REC *server, const char *newnick,
@@ -439,30 +435,17 @@ static void print_nick_change(SERVER_REC *server, const char *newnick,
                        continue;
 
                windows = g_slist_append(windows, window);
-               print_nick_change_channel(server, channel->name, newnick,
-                                         oldnick, address, ownnick);
+               print_nick_change_channel(server, channel->visible_name,
+                                         newnick, oldnick, address, ownnick);
                msgprint = TRUE;
        }
 
-       for (tmp = server->queries; tmp != NULL; tmp = tmp->next) {
-               QUERY_REC *query = tmp->data;
-               WINDOW_REC *window =
-                       window_item_window((WI_ITEM_REC *) query);
-
-               if (g_strcasecmp(query->name, oldnick) != 0 ||
-                   g_slist_find(windows, window) != NULL)
-                       continue;
-
-               windows = g_slist_append(windows, window);
-               print_nick_change_channel(server, query->name, newnick,
-                                         oldnick, address, ownnick);
-               msgprint = TRUE;
-       }
        g_slist_free(windows);
 
        if (!msgprint && ownnick) {
                printformat(server, NULL, MSGLEVEL_NICKS,
-                           TXT_YOUR_NICK_CHANGED, oldnick, newnick, "");
+                           TXT_YOUR_NICK_CHANGED, oldnick, newnick, "",
+                           address);
        }
 }
 
@@ -475,7 +458,13 @@ static void sig_message_nick(SERVER_REC *server, const char *newnick,
 static void sig_message_own_nick(SERVER_REC *server, const char *newnick,
                                 const char *oldnick, const char *address)
 {
-       print_nick_change(server, newnick, oldnick, address, TRUE);
+        if (!settings_get_bool("show_own_nickchange_once"))
+               print_nick_change(server, newnick, oldnick, address, TRUE);
+       else {
+               printformat(server, NULL, MSGLEVEL_NICKS,
+                           TXT_YOUR_NICK_CHANGED, oldnick, newnick, "",
+                           address);
+       }
 }
 
 static void sig_message_invite(SERVER_REC *server, const char *channel,
@@ -485,7 +474,7 @@ static void sig_message_invite(SERVER_REC *server, const char *channel,
 
        str = show_lowascii(channel);
        printformat(server, NULL, MSGLEVEL_INVITES,
-                   TXT_INVITE, nick, str);
+                   TXT_INVITE, nick, str, address);
        g_free(str);
 }
 
@@ -495,7 +484,7 @@ static void sig_message_topic(SERVER_REC *server, const char *channel,
 {
        printformat(server, channel, MSGLEVEL_TOPICS,
                    *topic != '\0' ? TXT_NEW_TOPIC : TXT_TOPIC_UNSET,
-                   nick, channel, topic);
+                   nick, channel, topic, address);
 }
 
 static int printnick_exists(NICK_REC *first, NICK_REC *ignore,
@@ -630,6 +619,7 @@ void fe_messages_init(void)
        printnicks = g_hash_table_new((GHashFunc) g_direct_hash,
                                      (GCompareFunc) g_direct_equal);
 
+       settings_add_bool("lookandfeel", "hilight_nick_matches", TRUE);
        settings_add_bool("lookandfeel", "emphasis", TRUE);
        settings_add_bool("lookandfeel", "emphasis_replace", FALSE);
        settings_add_bool("lookandfeel", "emphasis_multiword", FALSE);
@@ -637,19 +627,20 @@ void fe_messages_init(void)
        settings_add_bool("lookandfeel", "show_nickmode_empty", TRUE);
        settings_add_bool("lookandfeel", "print_active_channel", FALSE);
        settings_add_bool("lookandfeel", "show_quit_once", FALSE);
-
-       signal_add("message public", (SIGNAL_FUNC) sig_message_public);
-       signal_add("message private", (SIGNAL_FUNC) sig_message_private);
-       signal_add("message own_public", (SIGNAL_FUNC) sig_message_own_public);
-       signal_add("message own_private", (SIGNAL_FUNC) sig_message_own_private);
-       signal_add("message join", (SIGNAL_FUNC) sig_message_join);
-       signal_add("message part", (SIGNAL_FUNC) sig_message_part);
-       signal_add("message quit", (SIGNAL_FUNC) sig_message_quit);
-       signal_add("message kick", (SIGNAL_FUNC) sig_message_kick);
-       signal_add("message nick", (SIGNAL_FUNC) sig_message_nick);
-       signal_add("message own_nick", (SIGNAL_FUNC) sig_message_own_nick);
-       signal_add("message invite", (SIGNAL_FUNC) sig_message_invite);
-       signal_add("message topic", (SIGNAL_FUNC) sig_message_topic);
+       settings_add_bool("lookandfeel", "show_own_nickchange_once", FALSE);
+
+       signal_add_last("message public", (SIGNAL_FUNC) sig_message_public);
+       signal_add_last("message private", (SIGNAL_FUNC) sig_message_private);
+       signal_add_last("message own_public", (SIGNAL_FUNC) sig_message_own_public);
+       signal_add_last("message own_private", (SIGNAL_FUNC) sig_message_own_private);
+       signal_add_last("message join", (SIGNAL_FUNC) sig_message_join);
+       signal_add_last("message part", (SIGNAL_FUNC) sig_message_part);
+       signal_add_last("message quit", (SIGNAL_FUNC) sig_message_quit);
+       signal_add_last("message kick", (SIGNAL_FUNC) sig_message_kick);
+       signal_add_last("message nick", (SIGNAL_FUNC) sig_message_nick);
+       signal_add_last("message own_nick", (SIGNAL_FUNC) sig_message_own_nick);
+       signal_add_last("message invite", (SIGNAL_FUNC) sig_message_invite);
+       signal_add_last("message topic", (SIGNAL_FUNC) sig_message_topic);
 
        signal_add("nicklist new", (SIGNAL_FUNC) sig_nicklist_new);
        signal_add("nicklist remove", (SIGNAL_FUNC) sig_nicklist_remove);