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 along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include "fe-windows.h"
30 #include "window-items.h"
32 #include "hilight-text.h"
34 #include "fe-common-core.h"
36 static char **hide_targets;
37 static int hide_level, msg_level, hilight_level;
39 void window_activity(WINDOW_REC *window, int data_level,
40 const char *hilight_color)
44 old_data_level = window->data_level;
45 if (data_level == 0 || window->data_level < data_level) {
46 window->data_level = data_level;
47 g_free_not_null(window->hilight_color);
48 window->hilight_color = g_strdup(hilight_color);
49 signal_emit("window hilight", 1, window);
52 signal_emit("window activity", 2, window,
53 GINT_TO_POINTER(old_data_level));
56 void window_item_activity(WI_ITEM_REC *item, int data_level,
57 const char *hilight_color)
61 old_data_level = item->data_level;
62 if (data_level == 0 || item->data_level < data_level) {
63 item->data_level = data_level;
64 g_free_not_null(item->hilight_color);
65 item->hilight_color = g_strdup(hilight_color);
66 signal_emit("window item hilight", 1, item);
69 signal_emit("window item activity", 2, item,
70 GINT_TO_POINTER(old_data_level));
73 static void sig_hilight_text(TEXT_DEST_REC *dest, const char *msg)
78 if (dest->window == active_win || (dest->level & hide_level))
81 if (dest->level & hilight_level) {
82 data_level = DATA_LEVEL_HILIGHT+dest->hilight_priority;
84 data_level = (dest->level & msg_level) ?
85 DATA_LEVEL_MSG : DATA_LEVEL_TEXT;
88 if (hide_targets != NULL && (dest->level & MSGLEVEL_HILIGHT) == 0 && dest->target != NULL) {
89 /* check for both target and tag/target */
90 if (strarray_find_dest(hide_targets, dest))
94 if (dest->target != NULL) {
95 item = window_item_find(dest->server, dest->target);
97 window_item_activity(item, data_level,
101 window_activity(dest->window, data_level, dest->hilight_color);
104 static void sig_dehilight_window(WINDOW_REC *window)
108 g_return_if_fail(window != NULL);
110 if (window->data_level != 0) {
111 window_activity(window, 0, NULL);
112 for (tmp = window->items; tmp != NULL; tmp = tmp->next)
113 window_item_activity(tmp->data, 0, NULL);
117 static void read_settings(void)
121 if (hide_targets != NULL)
122 g_strfreev(hide_targets);
124 targets = settings_get_str("activity_hide_targets");
125 hide_targets = *targets == '\0' ? NULL :
126 g_strsplit(targets, " ", -1);
128 hide_level = MSGLEVEL_NEVER | MSGLEVEL_NO_ACT |
129 settings_get_level("activity_hide_level");
130 msg_level = settings_get_level("activity_msg_level");
131 hilight_level = MSGLEVEL_HILIGHT |
132 settings_get_level("activity_hilight_level");
135 void window_activity_init(void)
137 settings_add_str("lookandfeel", "activity_hide_targets", "");
138 settings_add_level("lookandfeel", "activity_hide_level", "");
139 settings_add_level("lookandfeel", "activity_msg_level", "PUBLIC");
140 settings_add_level("lookandfeel", "activity_hilight_level", "MSGS DCCMSGS");
143 signal_add("print text", (SIGNAL_FUNC) sig_hilight_text);
144 signal_add("window changed", (SIGNAL_FUNC) sig_dehilight_window);
145 signal_add("window dehilight", (SIGNAL_FUNC) sig_dehilight_window);
146 signal_add("setup changed", (SIGNAL_FUNC) read_settings);
149 void window_activity_deinit(void)
151 if (hide_targets != NULL)
152 g_strfreev(hide_targets);
154 signal_remove("print text", (SIGNAL_FUNC) sig_hilight_text);
155 signal_remove("window changed", (SIGNAL_FUNC) sig_dehilight_window);
156 signal_remove("window dehilight", (SIGNAL_FUNC) sig_dehilight_window);
157 signal_remove("setup changed", (SIGNAL_FUNC) read_settings);