2000-04-26 08:03:38 +00:00
|
|
|
/*
|
|
|
|
|
notify-commands.c : irssi
|
|
|
|
|
|
|
|
|
|
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
|
2007-05-08 18:16:58 +00:00
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
2000-04-26 08:03:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "module.h"
|
|
|
|
|
#include "signals.h"
|
|
|
|
|
#include "commands.h"
|
|
|
|
|
#include "misc.h"
|
|
|
|
|
#include "settings.h"
|
|
|
|
|
|
|
|
|
|
#include "notifylist.h"
|
|
|
|
|
|
2002-12-28 17:54:13 +00:00
|
|
|
/* SYNTAX: NOTIFY [-away] [-idle [<time>]] <mask> [<ircnets>] */
|
2000-04-26 08:03:38 +00:00
|
|
|
static void cmd_notify(gchar *data)
|
|
|
|
|
{
|
2000-06-18 01:18:12 +00:00
|
|
|
GHashTable *optlist;
|
|
|
|
|
char *mask, *ircnets, *idletime;
|
|
|
|
|
void *free_arg;
|
2000-04-26 08:03:38 +00:00
|
|
|
int away_check, idle_check_time;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail(data != NULL);
|
|
|
|
|
|
2000-06-18 01:18:12 +00:00
|
|
|
if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_OPTIONS | PARAM_FLAG_GETREST,
|
|
|
|
|
"notify", &optlist, &mask, &ircnets))
|
|
|
|
|
return;
|
2000-04-26 08:03:38 +00:00
|
|
|
if (*mask == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
|
|
|
|
|
|
2000-06-18 01:18:12 +00:00
|
|
|
idletime = g_hash_table_lookup(optlist, "idle");
|
|
|
|
|
if (idletime == NULL)
|
2000-04-26 08:03:38 +00:00
|
|
|
idle_check_time = 0;
|
2002-12-28 17:54:13 +00:00
|
|
|
else if (*idletime == '\0')
|
|
|
|
|
idle_check_time = settings_get_time("notify_idle_time");
|
2000-04-26 08:03:38 +00:00
|
|
|
else {
|
2002-12-28 17:54:13 +00:00
|
|
|
if (!parse_time_interval(idletime, &idle_check_time))
|
2005-03-06 18:45:47 +00:00
|
|
|
cmd_param_error(CMDERR_INVALID_TIME);
|
2000-04-26 08:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
2000-06-18 01:18:12 +00:00
|
|
|
away_check = g_hash_table_lookup(optlist, "away") != NULL;
|
2000-04-26 08:03:38 +00:00
|
|
|
notifylist_remove(mask);
|
2002-12-28 17:54:13 +00:00
|
|
|
notifylist_add(mask, ircnets, away_check, idle_check_time/1000);
|
2000-04-26 08:03:38 +00:00
|
|
|
|
2000-06-18 01:18:12 +00:00
|
|
|
cmd_params_free(free_arg);
|
2000-04-26 08:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
2000-07-23 23:19:22 +00:00
|
|
|
/* SYNTAX: UNNOTIFY <mask> */
|
2000-04-26 08:03:38 +00:00
|
|
|
static void cmd_unnotify(const char *data)
|
|
|
|
|
{
|
2000-06-18 01:18:12 +00:00
|
|
|
char *mask;
|
|
|
|
|
void *free_arg;
|
2000-04-26 08:03:38 +00:00
|
|
|
|
|
|
|
|
g_return_if_fail(data != NULL);
|
|
|
|
|
|
2000-06-18 01:18:12 +00:00
|
|
|
if (!cmd_get_params(data, &free_arg, 1, &mask))
|
|
|
|
|
return;
|
2000-04-26 08:03:38 +00:00
|
|
|
if (*mask == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
|
|
|
|
|
|
|
|
|
|
notifylist_remove(mask);
|
|
|
|
|
|
2000-06-18 01:18:12 +00:00
|
|
|
cmd_params_free(free_arg);
|
2000-04-26 08:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void notifylist_commands_init(void)
|
|
|
|
|
{
|
2002-12-29 16:02:49 +00:00
|
|
|
settings_add_time("misc", "notify_idle_time", "1hour");
|
2000-04-26 08:03:38 +00:00
|
|
|
command_bind("notify", NULL, (SIGNAL_FUNC) cmd_notify);
|
|
|
|
|
command_bind("unnotify", NULL, (SIGNAL_FUNC) cmd_unnotify);
|
2000-06-18 01:18:12 +00:00
|
|
|
|
2002-12-28 17:54:13 +00:00
|
|
|
command_set_options("notify", "-idle away");
|
2000-04-26 08:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void notifylist_commands_deinit(void)
|
|
|
|
|
{
|
|
|
|
|
command_unbind("notify", (SIGNAL_FUNC) cmd_notify);
|
|
|
|
|
command_unbind("unnotify", (SIGNAL_FUNC) cmd_unnotify);
|
|
|
|
|
}
|