2 window-activity.c : irssi
4 Copyright (C) 1999-2000 Timo Sirainen
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "fe-windows.h"
30 #include "window-items.h"
32 #include "hilight-text.h"
35 static char **hide_targets;
36 static int hide_level, msg_level, hilight_level;
38 void window_activity(WINDOW_REC *window, int data_level,
39 const char *hilight_color)
43 old_data_level = window->data_level;
44 if (data_level == 0 || window->data_level < data_level) {
45 window->data_level = data_level;
46 g_free_not_null(window->hilight_color);
47 window->hilight_color = g_strdup(hilight_color);
48 signal_emit("window hilight", 1, window);
51 signal_emit("window activity", 2, window,
52 GINT_TO_POINTER(old_data_level));
55 void window_item_activity(WI_ITEM_REC *item, int data_level,
56 const char *hilight_color)
60 old_data_level = item->data_level;
61 if (data_level == 0 || item->data_level < data_level) {
62 item->data_level = data_level;
63 g_free_not_null(item->hilight_color);
64 item->hilight_color = g_strdup(hilight_color);
65 signal_emit("window item hilight", 1, item);
68 signal_emit("window item activity", 2, item,
69 GINT_TO_POINTER(old_data_level));
72 #define hide_target_activity(data_level, target) \
73 ((target) != NULL && hide_targets != NULL && \
74 strarray_find(hide_targets, target) != -1)
76 static void sig_hilight_text(TEXT_DEST_REC *dest, const char *msg)
82 if (dest->window == active_win || (dest->level & hide_level))
85 if (dest->level & hilight_level) {
86 data_level = DATA_LEVEL_HILIGHT+dest->hilight_priority;
88 data_level = (dest->level & msg_level) ?
89 DATA_LEVEL_MSG : DATA_LEVEL_TEXT;
92 if ((dest->level & MSGLEVEL_HILIGHT) == 0 && dest->target != NULL) {
93 /* check for both target and tag/target */
94 if (hide_target_activity(data_level, dest->target))
97 tagtarget = dest->server_tag == NULL ? NULL :
98 g_strdup_printf("%s/%s", dest->server_tag,
100 if (hide_target_activity(data_level, tagtarget)) {
107 if (dest->target != NULL) {
108 item = window_item_find(dest->server, dest->target);
110 window_item_activity(item, data_level,
111 dest->hilight_color);
114 window_activity(dest->window, data_level, dest->hilight_color);
117 static void sig_dehilight_window(WINDOW_REC *window)
121 g_return_if_fail(window != NULL);
123 if (window->data_level != 0) {
124 window_activity(window, 0, NULL);
125 for (tmp = window->items; tmp != NULL; tmp = tmp->next)
126 window_item_activity(tmp->data, 0, NULL);
130 static void read_settings(void)
134 if (hide_targets != NULL)
135 g_strfreev(hide_targets);
137 targets = settings_get_str("activity_hide_targets");
138 hide_targets = *targets == '\0' ? NULL :
139 g_strsplit(targets, " ", -1);
141 hide_level = MSGLEVEL_NEVER | MSGLEVEL_NO_ACT |
142 settings_get_level("activity_hide_level");
143 msg_level = settings_get_level("activity_msg_level");
144 hilight_level = MSGLEVEL_HILIGHT |
145 settings_get_level("activity_hilight_level");
148 void window_activity_init(void)
150 settings_add_str("lookandfeel", "activity_hide_targets", "");
151 settings_add_level("lookandfeel", "activity_hide_level", "");
152 settings_add_level("lookandfeel", "activity_msg_level", "PUBLIC");
153 settings_add_level("lookandfeel", "activity_hilight_level", "MSGS DCCMSGS");
156 signal_add("print text", (SIGNAL_FUNC) sig_hilight_text);
157 signal_add("window changed", (SIGNAL_FUNC) sig_dehilight_window);
158 signal_add("window dehilight", (SIGNAL_FUNC) sig_dehilight_window);
159 signal_add("setup changed", (SIGNAL_FUNC) read_settings);
162 void window_activity_deinit(void)
164 if (hide_targets != NULL)
165 g_strfreev(hide_targets);
167 signal_remove("print text", (SIGNAL_FUNC) sig_hilight_text);
168 signal_remove("window changed", (SIGNAL_FUNC) sig_dehilight_window);
169 signal_remove("window dehilight", (SIGNAL_FUNC) sig_dehilight_window);
170 signal_remove("setup changed", (SIGNAL_FUNC) read_settings);