5 Author: Jochen Eisinger <c0ffee@penguin-breeder.org>
7 Copyright (C) 2002 Jochen Eisinger
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
27 #include "special-vars.h"
35 #include "window-items.h"
36 #include "fe-queries.h"
37 #include "fe-messages.h"
38 #include "hilight-text.h"
39 #include "printtext.h"
40 #include "module-formats.h"
42 #define VERIFIED_MSG(v,msg) (v == SILC_MSG_SIGNED_VERIFIED ? \
43 msg##_SIGNED : (v == SILC_MSG_SIGNED_UNKNOWN ? \
44 msg##_UNKNOWN : msg##_FAILED))
46 static void sig_signed_message_public(SERVER_REC * server, const char *msg,
53 NICK_REC *nickrec = NULL; /* we cheat here a little to keep the limit of
54 6 parameters to a signal handler ... */
55 const char *nickmode, *printnick;
56 int for_me, print_channel, level;
57 char *color, *freemsg = NULL;
59 /* NOTE: this may return NULL if some channel is just closed with
60 /WINDOW CLOSE and server still sends the few last messages */
61 chanrec = channel_find(server, target);
62 if (nickrec == NULL && chanrec != NULL)
63 nickrec = nicklist_find(chanrec, nick);
65 for_me = !settings_get_bool("hilight_nick_matches") ? FALSE :
66 nick_match_msg(chanrec, msg, server->nick);
67 color = for_me ? NULL :
68 hilight_match_nick(server, target, nick, address, MSGLEVEL_PUBLIC,
71 print_channel = chanrec == NULL ||
72 !window_item_is_active((WI_ITEM_REC *) chanrec);
73 if (!print_channel && settings_get_bool("print_active_channel") &&
74 window_item_window((WI_ITEM_REC *) chanrec)->items->next != NULL)
77 level = MSGLEVEL_PUBLIC;
78 if (for_me || color != NULL)
79 level |= MSGLEVEL_HILIGHT;
81 if (settings_get_bool("emphasis"))
82 msg = freemsg = expand_emphasis((WI_ITEM_REC *) chanrec, msg);
84 /* get nick mode & nick what to print the msg with
85 (in case there's multiple identical nicks) */
86 nickmode = channel_get_nickmode(chanrec, nick);
87 printnick = nickrec == NULL ? nick :
88 g_hash_table_lookup(printnicks, nickrec);
89 if (printnick == NULL)
93 /* message to active channel in window */
95 /* highlighted nick */
96 printformat_module("fe-common/silc", server, target,
97 level, VERIFIED_MSG(verified, SILCTXT_PUBMSG_HILIGHT),
98 color, printnick, msg, nickmode);
100 printformat_module("fe-common/silc", server, target, level,
101 for_me ? VERIFIED_MSG(verified, SILCTXT_PUBMSG_ME) :
102 VERIFIED_MSG(verified,SILCTXT_PUBMSG),
103 printnick, msg, nickmode);
106 /* message to not existing/active channel */
108 /* highlighted nick */
109 printformat_module("fe-common/silc", server, target, level,
110 VERIFIED_MSG(verified, SILCTXT_PUBMSG_HILIGHT_CHANNEL),
111 color, printnick, target, msg, nickmode);
113 printformat_module("fe-common/silc", server, target, level,
114 for_me ? VERIFIED_MSG(verified, SILCTXT_PUBMSG_ME_CHANNEL) :
115 VERIFIED_MSG(verified, SILCTXT_PUBMSG_CHANNEL),
116 printnick, target, msg, nickmode);
120 g_free_not_null(freemsg);
121 g_free_not_null(color);
124 static void sig_signed_message_own_public(SERVER_REC * server,
129 CHANNEL_REC *channel;
130 const char *nickmode;
131 char *freemsg = NULL;
134 channel = channel_find(server, target);
136 target = channel->visible_name;
138 nickmode = channel_get_nickmode(channel, server->nick);
140 window = channel == NULL ? NULL :
141 window_item_window((WI_ITEM_REC *) channel);
143 print_channel = window == NULL ||
144 window->active != (WI_ITEM_REC *) channel;
146 if (!print_channel && settings_get_bool("print_active_channel") &&
147 window != NULL && g_slist_length(window->items) > 1)
148 print_channel = TRUE;
150 if (settings_get_bool("emphasis"))
151 msg = freemsg = expand_emphasis((WI_ITEM_REC *) channel, msg);
153 if (!print_channel) {
154 printformat_module("fe-common/silc", server, target,
155 MSGLEVEL_PUBLIC | MSGLEVEL_NOHILIGHT |
156 MSGLEVEL_NO_ACT, SILCTXT_OWN_MSG_SIGNED, server->nick, msg,
159 printformat_module("fe-common/silc", server, target,
160 MSGLEVEL_PUBLIC | MSGLEVEL_NOHILIGHT |
161 MSGLEVEL_NO_ACT, SILCTXT_OWN_MSG_CHANNEL_SIGNED,
162 server->nick, target, msg, nickmode);
165 g_free_not_null(freemsg);
169 void fe_silc_messages_init(void)
171 signal_add_last("message signed_public",
172 (SIGNAL_FUNC) sig_signed_message_public);
173 signal_add_last("message signed_own_public",
174 (SIGNAL_FUNC) sig_signed_message_own_public);
177 void fe_silc_messages_deinit(void)
179 signal_remove("message signed_public",
180 (SIGNAL_FUNC) sig_signed_message_public);
181 signal_remove("message signed_own_public",
182 (SIGNAL_FUNC) sig_signed_message_own_public);