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"
|
2000-06-09 12:19:42 -04:00
|
|
|
#include "misc.h"
|
|
|
|
#include "settings.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
#include "windows.h"
|
|
|
|
#include "window-items.h"
|
2000-09-30 18:49:48 -04:00
|
|
|
#include "nicklist.h"
|
|
|
|
#include "hilight-text.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-09 12:19:42 -04:00
|
|
|
static const 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
|
|
|
|
2000-10-01 21:04:39 -04:00
|
|
|
static void sig_hilight_text(WINDOW_REC *window, SERVER_REC *server,
|
|
|
|
const char *channel, void *levelptr,
|
|
|
|
const char *msg)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2000-06-09 12:19:42 -04:00
|
|
|
int level, oldlevel, new_data;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
level = GPOINTER_TO_INT(levelptr);
|
2000-07-31 18:16:50 -04:00
|
|
|
if (window == active_win || (level & (MSGLEVEL_NEVER|MSGLEVEL_NO_ACT)))
|
2000-04-26 04:03:38 -04:00
|
|
|
return;
|
|
|
|
|
2000-10-01 21:04:39 -04:00
|
|
|
/* hilights and private messages get HILIGHT status,
|
|
|
|
public messages get MSGS status and rest get TEXT */
|
2000-11-09 15:38:50 -05:00
|
|
|
new_data = (level & (MSGLEVEL_HILIGHT|hilight_level)) ?
|
2000-09-04 19:39:42 -04:00
|
|
|
NEWDATA_HILIGHT :
|
2000-11-09 15:38:50 -05:00
|
|
|
((level & activity_level) ? NEWDATA_MSG : NEWDATA_TEXT);
|
2000-06-09 12:19:42 -04:00
|
|
|
|
2000-10-01 21:04:39 -04:00
|
|
|
/* check that channel isn't in "don't show activity" list */
|
2000-06-30 15:50:56 -04:00
|
|
|
if (new_data < NEWDATA_HILIGHT &&
|
2000-06-09 12:19:42 -04:00
|
|
|
channel != NULL && find_substr(noact_channels, channel))
|
|
|
|
return;
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
oldlevel = window->new_data;
|
2000-06-09 12:19:42 -04:00
|
|
|
if (window->new_data < new_data) {
|
|
|
|
window->new_data = new_data;
|
2000-10-01 21:04:39 -04:00
|
|
|
window->last_color = hilight_last_nick_color();;
|
2000-04-26 04:03:38 -04:00
|
|
|
signal_emit("window hilight", 1, window);
|
|
|
|
}
|
|
|
|
|
|
|
|
signal_emit("window activity", 2, window, GINT_TO_POINTER(oldlevel));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sig_dehilight(WINDOW_REC *window, WI_ITEM_REC *item)
|
|
|
|
{
|
|
|
|
g_return_if_fail(window != NULL);
|
|
|
|
|
|
|
|
if (item != NULL && item->new_data != 0) {
|
|
|
|
item->new_data = 0;
|
2000-06-30 15:50:56 -04:00
|
|
|
item->last_color = 0;
|
2000-04-26 04:03:38 -04:00
|
|
|
signal_emit("window item hilight", 1, item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sig_dehilight_window(WINDOW_REC *window)
|
|
|
|
{
|
2000-05-04 06:32:42 -04:00
|
|
|
GSList *tmp;
|
2000-04-26 04:03:38 -04:00
|
|
|
int oldlevel;
|
|
|
|
|
|
|
|
g_return_if_fail(window != NULL);
|
|
|
|
|
|
|
|
if (window->new_data == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (window->new_data != 0) {
|
|
|
|
oldlevel = window->new_data;
|
|
|
|
window->new_data = 0;
|
2000-06-30 15:50:56 -04:00
|
|
|
window->last_color = 0;
|
2000-04-26 04:03:38 -04:00
|
|
|
signal_emit("window hilight", 2, window, GINT_TO_POINTER(oldlevel));
|
|
|
|
}
|
|
|
|
signal_emit("window activity", 2, window, GINT_TO_POINTER(oldlevel));
|
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
for (tmp = window->items; tmp != NULL; tmp = tmp->next)
|
|
|
|
sig_dehilight(window, tmp->data);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sig_hilight_window_item(WI_ITEM_REC *item)
|
|
|
|
{
|
|
|
|
WINDOW_REC *window;
|
|
|
|
GSList *tmp;
|
2000-06-30 15:50:56 -04:00
|
|
|
int level, oldlevel, color;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-30 15:50:56 -04:00
|
|
|
if (item->new_data < NEWDATA_HILIGHT &&
|
2000-06-09 12:19:42 -04:00
|
|
|
find_substr(noact_channels, item->name))
|
|
|
|
return;
|
|
|
|
|
2000-06-30 15:50:56 -04:00
|
|
|
window = window_item_window(item); level = 0; color = 0;
|
2000-04-26 04:03:38 -04:00
|
|
|
for (tmp = window->items; tmp != NULL; tmp = tmp->next) {
|
|
|
|
item = tmp->data;
|
|
|
|
|
2000-06-30 15:50:56 -04:00
|
|
|
if (item->new_data > level) {
|
2000-04-26 04:03:38 -04:00
|
|
|
level = item->new_data;
|
2000-06-30 15:50:56 -04:00
|
|
|
color = item->last_color;
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
oldlevel = window->new_data;
|
2000-07-02 08:07:49 -04:00
|
|
|
if (level == NEWDATA_HILIGHT)
|
2000-06-30 15:50:56 -04:00
|
|
|
window->last_color = color;
|
2000-04-26 04:03:38 -04:00
|
|
|
if (window->new_data < level || level == 0) {
|
|
|
|
window->new_data = level;
|
|
|
|
signal_emit("window hilight", 2, window, GINT_TO_POINTER(oldlevel));
|
|
|
|
}
|
|
|
|
signal_emit("window activity", 2, window, GINT_TO_POINTER(oldlevel));
|
|
|
|
}
|
|
|
|
|
2000-09-30 18:49:48 -04:00
|
|
|
static void sig_message(SERVER_REC *server, const char *msg,
|
|
|
|
const char *nick, const char *addr,
|
|
|
|
const char *target, int level)
|
|
|
|
{
|
|
|
|
WINDOW_REC *window;
|
|
|
|
WI_ITEM_REC *item;
|
|
|
|
|
|
|
|
/* get window and window item */
|
|
|
|
item = window_item_find(server, target);
|
|
|
|
window = item == NULL ?
|
|
|
|
window_find_closest(server, target, level) :
|
|
|
|
window_item_window(item);
|
|
|
|
|
|
|
|
if (window == active_win)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* hilight */
|
|
|
|
if (item != NULL) item->last_color = hilight_last_nick_color();
|
|
|
|
level = (item != NULL && item->last_color > 0) ||
|
2000-11-09 15:38:50 -05:00
|
|
|
(level & hilight_level) ||
|
2000-09-30 18:49:48 -04:00
|
|
|
nick_match_msg(SERVER(server), msg, server->nick) ?
|
|
|
|
NEWDATA_HILIGHT : NEWDATA_MSG;
|
|
|
|
if (item != NULL && item->new_data < level) {
|
|
|
|
item->new_data = level;
|
|
|
|
signal_emit("window item hilight", 1, item);
|
|
|
|
} else {
|
|
|
|
int oldlevel = window->new_data;
|
|
|
|
|
|
|
|
if (window->new_data < level) {
|
|
|
|
window->new_data = level;
|
|
|
|
window->last_color = hilight_last_nick_color();
|
|
|
|
signal_emit("window hilight", 2, window,
|
|
|
|
GINT_TO_POINTER(oldlevel));
|
|
|
|
}
|
|
|
|
signal_emit("window activity", 2, window,
|
|
|
|
GINT_TO_POINTER(oldlevel));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sig_message_public(SERVER_REC *server, const char *msg,
|
|
|
|
const char *nick, const char *addr,
|
|
|
|
const char *target)
|
|
|
|
{
|
|
|
|
sig_message(server, msg, nick, addr, target, MSGLEVEL_PUBLIC);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sig_message_private(SERVER_REC *server, const char *msg,
|
|
|
|
const char *nick, const char *addr)
|
|
|
|
{
|
|
|
|
sig_message(server, msg, nick, addr, nick, MSGLEVEL_MSGS);
|
|
|
|
}
|
|
|
|
|
2000-06-09 12:19:42 -04:00
|
|
|
static void read_settings(void)
|
|
|
|
{
|
|
|
|
noact_channels = settings_get_str("noact_channels");
|
2000-11-09 15:38:50 -05:00
|
|
|
activity_level = level2bits(settings_get_str("activity_levels"));
|
|
|
|
hilight_level = 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 item changed", (SIGNAL_FUNC) sig_dehilight);
|
|
|
|
signal_add("window changed", (SIGNAL_FUNC) sig_dehilight_window);
|
|
|
|
signal_add("window dehilight", (SIGNAL_FUNC) sig_dehilight_window);
|
|
|
|
signal_add("window item hilight", (SIGNAL_FUNC) sig_hilight_window_item);
|
2000-10-01 21:04:39 -04:00
|
|
|
signal_add("message public", (SIGNAL_FUNC) sig_message_public);
|
|
|
|
signal_add("message private", (SIGNAL_FUNC) sig_message_private);
|
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
|
|
|
{
|
|
|
|
signal_remove("print text", (SIGNAL_FUNC) sig_hilight_text);
|
|
|
|
signal_remove("window item changed", (SIGNAL_FUNC) sig_dehilight);
|
|
|
|
signal_remove("window changed", (SIGNAL_FUNC) sig_dehilight_window);
|
|
|
|
signal_remove("window dehilight", (SIGNAL_FUNC) sig_dehilight_window);
|
|
|
|
signal_remove("window item hilight", (SIGNAL_FUNC) sig_hilight_window_item);
|
2000-09-30 18:49:48 -04:00
|
|
|
signal_remove("message public", (SIGNAL_FUNC) sig_message_public);
|
|
|
|
signal_remove("message private", (SIGNAL_FUNC) sig_message_private);
|
2000-06-09 12:19:42 -04:00
|
|
|
signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|