2000-04-26 04:03:38 -04:00
|
|
|
/*
|
2000-05-04 06:32:42 -04:00
|
|
|
window-activity.c : irssi
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
Copyright (C) 1999-2000 Timo Sirainen
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "module.h"
|
|
|
|
#include "signals.h"
|
|
|
|
#include "levels.h"
|
2000-08-26 11:39:44 -04:00
|
|
|
#include "servers.h"
|
2001-01-01 02:45:54 -05:00
|
|
|
#include "channels.h"
|
2000-06-09 12:19:42 -04:00
|
|
|
#include "misc.h"
|
|
|
|
#include "settings.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-11-17 11:27:14 -05:00
|
|
|
#include "fe-windows.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
#include "window-items.h"
|
2000-09-30 18:49:48 -04:00
|
|
|
#include "nicklist.h"
|
|
|
|
#include "hilight-text.h"
|
2000-11-12 15:20:05 -05:00
|
|
|
#include "formats.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-09 16:06:45 -05:00
|
|
|
static char **noact_channels;
|
2000-11-09 15:38:50 -05:00
|
|
|
static int hilight_level, activity_level;
|
2000-06-09 12:19:42 -04:00
|
|
|
|
2001-01-09 16:06:45 -05:00
|
|
|
static void window_activity(WINDOW_REC *window,
|
|
|
|
int data_level, int hilight_color)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-01-09 16:06:45 -05:00
|
|
|
int old_data_level;
|
2000-06-09 12:19:42 -04:00
|
|
|
|
2001-01-09 16:06:45 -05:00
|
|
|
old_data_level = window->data_level;
|
|
|
|
if (data_level == 0 || window->data_level < data_level) {
|
|
|
|
window->data_level = data_level;
|
|
|
|
window->hilight_color = hilight_color;
|
|
|
|
signal_emit("window hilight", 1, window);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-01-09 16:06:45 -05:00
|
|
|
signal_emit("window activity", 2, window,
|
|
|
|
GINT_TO_POINTER(old_data_level));
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-01-09 16:06:45 -05:00
|
|
|
static void window_item_activity(WI_ITEM_REC *item,
|
|
|
|
int data_level, int hilight_color)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-01-09 16:06:45 -05:00
|
|
|
int old_data_level;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-09 16:06:45 -05:00
|
|
|
old_data_level = item->data_level;
|
|
|
|
if (data_level == 0 || item->data_level < data_level) {
|
|
|
|
item->data_level = data_level;
|
|
|
|
item->hilight_color = hilight_color;
|
2000-04-26 04:03:38 -04:00
|
|
|
signal_emit("window item hilight", 1, item);
|
|
|
|
}
|
2001-01-09 16:06:45 -05:00
|
|
|
|
|
|
|
signal_emit("window item activity", 2, item,
|
|
|
|
GINT_TO_POINTER(old_data_level));
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-01-09 16:06:45 -05:00
|
|
|
#define hide_target_activity(data_level, target) \
|
|
|
|
((data_level) < DATA_LEVEL_HILIGHT && (target) != NULL && \
|
|
|
|
(noact_channels) != NULL && \
|
|
|
|
strarray_find((noact_channels), target) != -1)
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-09 16:06:45 -05:00
|
|
|
static void sig_hilight_text(TEXT_DEST_REC *dest, const char *msg)
|
|
|
|
{
|
|
|
|
WI_ITEM_REC *item;
|
|
|
|
int data_level;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-09 16:06:45 -05:00
|
|
|
if (dest->window == active_win ||
|
|
|
|
(dest->level & (MSGLEVEL_NEVER|MSGLEVEL_NO_ACT)))
|
2000-04-26 04:03:38 -04:00
|
|
|
return;
|
|
|
|
|
2001-01-09 16:06:45 -05:00
|
|
|
data_level = (dest->level & hilight_level) ?
|
|
|
|
DATA_LEVEL_HILIGHT+dest->hilight_priority :
|
|
|
|
((dest->level & activity_level) ?
|
|
|
|
DATA_LEVEL_MSG : DATA_LEVEL_TEXT);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-01-09 16:06:45 -05:00
|
|
|
if (hide_target_activity(data_level, dest->target))
|
2000-06-09 12:19:42 -04:00
|
|
|
return;
|
|
|
|
|
2001-01-09 16:06:45 -05:00
|
|
|
if (dest->target != NULL) {
|
|
|
|
item = window_item_find(dest->server, dest->target);
|
|
|
|
if (item != NULL) {
|
|
|
|
window_item_activity(item, data_level,
|
|
|
|
dest->hilight_color);
|
2000-06-30 15:50:56 -04:00
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
2001-01-09 16:06:45 -05:00
|
|
|
window_activity(dest->window, data_level, dest->hilight_color);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-01-09 16:06:45 -05:00
|
|
|
static void sig_dehilight_window(WINDOW_REC *window)
|
2000-09-30 18:49:48 -04:00
|
|
|
{
|
2001-01-09 16:06:45 -05:00
|
|
|
GSList *tmp;
|
2000-09-30 18:49:48 -04:00
|
|
|
|
2001-01-09 16:06:45 -05:00
|
|
|
g_return_if_fail(window != NULL);
|
2000-09-30 18:49:48 -04:00
|
|
|
|
2001-01-09 16:06:45 -05:00
|
|
|
if (window->data_level != 0) {
|
|
|
|
window_activity(window, 0, 0);
|
|
|
|
for (tmp = window->items; tmp != NULL; tmp = tmp->next)
|
|
|
|
window_item_activity(tmp->data, 0, 0);
|
2000-09-30 18:49:48 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-09 16:06:45 -05:00
|
|
|
static void read_settings(void)
|
2000-09-30 18:49:48 -04:00
|
|
|
{
|
2001-01-09 16:06:45 -05:00
|
|
|
const char *channels;
|
2000-12-16 20:20:21 -05:00
|
|
|
|
2001-01-09 16:06:45 -05:00
|
|
|
if (noact_channels != NULL)
|
|
|
|
g_strfreev(noact_channels);
|
2000-09-30 18:49:48 -04:00
|
|
|
|
2001-01-09 16:06:45 -05:00
|
|
|
channels = settings_get_str("noact_channels");
|
|
|
|
noact_channels = *channels == '\0' ? NULL :
|
|
|
|
g_strsplit(channels, " ", -1);
|
2000-09-30 18:49:48 -04:00
|
|
|
|
2000-11-09 15:38:50 -05:00
|
|
|
activity_level = level2bits(settings_get_str("activity_levels"));
|
2001-01-09 16:06:45 -05:00
|
|
|
hilight_level = MSGLEVEL_HILIGHT |
|
|
|
|
level2bits(settings_get_str("hilight_levels"));
|
2000-06-09 12:19:42 -04:00
|
|
|
}
|
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
void window_activity_init(void)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-06-09 12:19:42 -04:00
|
|
|
settings_add_str("lookandfeel", "noact_channels", "");
|
2000-11-09 15:38:50 -05:00
|
|
|
settings_add_str("lookandfeel", "activity_levels", "PUBLIC");
|
|
|
|
settings_add_str("lookandfeel", "hilight_levels", "MSGS DCCMSGS");
|
2000-06-09 12:19:42 -04:00
|
|
|
|
|
|
|
read_settings();
|
2000-04-26 04:03:38 -04:00
|
|
|
signal_add("print text", (SIGNAL_FUNC) sig_hilight_text);
|
|
|
|
signal_add("window changed", (SIGNAL_FUNC) sig_dehilight_window);
|
|
|
|
signal_add("window dehilight", (SIGNAL_FUNC) sig_dehilight_window);
|
2000-06-09 12:19:42 -04:00
|
|
|
signal_add("setup changed", (SIGNAL_FUNC) read_settings);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
void window_activity_deinit(void)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-01-09 16:06:45 -05:00
|
|
|
if (noact_channels != NULL)
|
|
|
|
g_strfreev(noact_channels);
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
signal_remove("print text", (SIGNAL_FUNC) sig_hilight_text);
|
|
|
|
signal_remove("window changed", (SIGNAL_FUNC) sig_dehilight_window);
|
|
|
|
signal_remove("window dehilight", (SIGNAL_FUNC) sig_dehilight_window);
|
2000-06-09 12:19:42 -04:00
|
|
|
signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|