2000-04-26 08:03:38 +00:00
|
|
|
/*
|
|
|
|
|
fe-settings.c : irssi
|
|
|
|
|
|
|
|
|
|
Copyright (C) 1999 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.
|
|
|
|
|
|
2007-05-08 18:41:10 +00:00
|
|
|
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.,
|
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2000-04-26 08:03:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "module.h"
|
2019-05-01 16:33:47 +02:00
|
|
|
#include <irssi/src/fe-common/core/module-formats.h>
|
|
|
|
|
#include <irssi/src/core/signals.h>
|
|
|
|
|
#include <irssi/src/core/commands.h>
|
|
|
|
|
#include <irssi/src/core/servers.h>
|
|
|
|
|
#include <irssi/src/core/misc.h>
|
|
|
|
|
#include <irssi/src/lib-config/iconfig.h>
|
|
|
|
|
#include <irssi/src/core/settings.h>
|
|
|
|
|
#include <irssi/src/fe-common/core/fe-settings.h>
|
|
|
|
|
#include <irssi/src/core/levels.h>
|
|
|
|
|
#include <irssi/src/fe-common/core/printtext.h>
|
|
|
|
|
#include <irssi/src/fe-common/core/keyboard.h>
|
2000-04-26 08:03:38 +00:00
|
|
|
|
|
|
|
|
static void set_print(SETTINGS_REC *rec)
|
|
|
|
|
{
|
2007-04-29 11:20:36 +00:00
|
|
|
char *value;
|
2000-04-26 08:03:38 +00:00
|
|
|
|
2007-04-29 11:20:36 +00:00
|
|
|
value = settings_get_print(rec);
|
2001-05-26 19:20:45 +00:00
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_SET_ITEM,
|
|
|
|
|
rec->key, value);
|
2007-04-29 11:20:36 +00:00
|
|
|
g_free(value);
|
2000-04-26 08:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
2017-11-01 15:48:35 +01:00
|
|
|
void fe_settings_set_print(const char *key)
|
|
|
|
|
{
|
|
|
|
|
set_print(settings_get_record(key));
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-05 12:03:18 +00:00
|
|
|
static void set_print_pattern(const char *pattern)
|
|
|
|
|
{
|
|
|
|
|
GSList *sets, *tmp;
|
|
|
|
|
const char *last_section;
|
|
|
|
|
|
|
|
|
|
last_section = "";
|
|
|
|
|
sets = settings_get_sorted();
|
|
|
|
|
for (tmp = sets; tmp != NULL; tmp = tmp->next) {
|
|
|
|
|
SETTINGS_REC *rec = tmp->data;
|
|
|
|
|
|
|
|
|
|
if (stristr(rec->key, pattern) == NULL)
|
|
|
|
|
continue;
|
2015-04-07 22:39:05 -03:00
|
|
|
if (g_strcmp0(last_section, rec->section) != 0) {
|
2007-06-05 12:03:18 +00:00
|
|
|
/* print section */
|
|
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP,
|
|
|
|
|
TXT_SET_TITLE, rec->section);
|
|
|
|
|
last_section = rec->section;
|
|
|
|
|
}
|
|
|
|
|
set_print(rec);
|
|
|
|
|
}
|
|
|
|
|
g_slist_free(sets);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-28 14:00:04 +02:00
|
|
|
static void set_print_section(const char *pattern)
|
|
|
|
|
{
|
|
|
|
|
GSList *sets, *tmp;
|
|
|
|
|
const char *last_section;
|
|
|
|
|
|
|
|
|
|
last_section = "";
|
|
|
|
|
sets = settings_get_sorted();
|
|
|
|
|
for (tmp = sets; tmp != NULL; tmp = tmp->next) {
|
|
|
|
|
SETTINGS_REC *rec = tmp->data;
|
|
|
|
|
|
|
|
|
|
if (stristr(rec->section, pattern) != NULL) {
|
|
|
|
|
if (g_strcmp0(last_section, rec->section) != 0) {
|
|
|
|
|
/* print section */
|
|
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP,
|
|
|
|
|
TXT_SET_TITLE, rec->section);
|
|
|
|
|
last_section = rec->section;
|
|
|
|
|
}
|
|
|
|
|
set_print(rec);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
g_slist_free(sets);
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-26 08:03:38 +00:00
|
|
|
static void set_boolean(const char *key, const char *value)
|
|
|
|
|
{
|
2010-10-02 21:52:35 +00:00
|
|
|
char *stripped_value;
|
2016-06-12 23:39:22 +02:00
|
|
|
|
2010-10-02 21:52:35 +00:00
|
|
|
stripped_value = g_strdup(value);
|
|
|
|
|
g_strstrip(stripped_value);
|
|
|
|
|
|
|
|
|
|
if (g_ascii_strcasecmp(stripped_value, "ON") == 0)
|
2000-12-17 05:44:45 +00:00
|
|
|
settings_set_bool(key, TRUE);
|
2010-10-02 21:52:35 +00:00
|
|
|
else if (g_ascii_strcasecmp(stripped_value, "OFF") == 0)
|
2000-12-17 05:44:45 +00:00
|
|
|
settings_set_bool(key, FALSE);
|
2010-10-02 21:52:35 +00:00
|
|
|
else if (g_ascii_strcasecmp(stripped_value, "TOGGLE") == 0)
|
2000-12-17 05:44:45 +00:00
|
|
|
settings_set_bool(key, !settings_get_bool(key));
|
2000-04-26 08:03:38 +00:00
|
|
|
else
|
2009-02-21 17:22:32 +00:00
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_NOT_TOGGLE);
|
2010-10-02 21:52:35 +00:00
|
|
|
|
2016-06-12 23:39:22 +02:00
|
|
|
g_free(stripped_value);
|
2000-04-26 08:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
2009-02-21 17:20:13 +00:00
|
|
|
static void set_int(const char *key, const char *value)
|
|
|
|
|
{
|
|
|
|
|
char *endp;
|
|
|
|
|
long longval;
|
|
|
|
|
int error;
|
|
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
|
longval = strtol(value, &endp, 10);
|
|
|
|
|
error = errno;
|
2009-02-21 17:34:13 +00:00
|
|
|
while (i_isspace(*endp))
|
2009-02-21 17:20:13 +00:00
|
|
|
endp++;
|
|
|
|
|
if (error != 0 || *endp != '\0' || longval < INT_MIN || longval > INT_MAX)
|
|
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_INVALID_NUMBER);
|
|
|
|
|
else
|
|
|
|
|
settings_set_int(key, (int)longval);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-12 23:39:22 +02:00
|
|
|
static void set_choice(const char *key, const char *value)
|
|
|
|
|
{
|
|
|
|
|
char *stripped_value;
|
|
|
|
|
|
|
|
|
|
stripped_value = g_strdup(value);
|
|
|
|
|
g_strstrip(stripped_value);
|
2016-06-13 14:03:00 +02:00
|
|
|
|
|
|
|
|
if (settings_set_choice(key, stripped_value) == FALSE) {
|
|
|
|
|
SETTINGS_REC *rec = settings_get_record(key);
|
2016-06-13 20:27:37 +02:00
|
|
|
char *msg = g_strjoinv(", ", rec->choices);
|
2016-06-13 14:03:00 +02:00
|
|
|
|
|
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_INVALID_CHOICE, msg);
|
|
|
|
|
g_free(msg);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-12 23:39:22 +02:00
|
|
|
g_free(stripped_value);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-28 14:00:04 +02:00
|
|
|
/* SYNTAX: SET [-clear | -default | -section] [<key> [<value>]] */
|
2000-04-26 08:03:38 +00:00
|
|
|
static void cmd_set(char *data)
|
|
|
|
|
{
|
2000-07-04 19:36:36 +00:00
|
|
|
GHashTable *optlist;
|
2000-07-10 23:00:56 +00:00
|
|
|
char *key, *value;
|
2000-06-18 01:18:12 +00:00
|
|
|
void *free_arg;
|
2019-05-28 14:00:04 +02:00
|
|
|
int clear, set_default, list_section;
|
2007-06-05 12:03:18 +00:00
|
|
|
SETTINGS_REC *rec;
|
2000-04-26 08:03:38 +00:00
|
|
|
|
2015-11-09 23:02:41 +01:00
|
|
|
if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST |
|
2016-03-20 22:39:06 +01:00
|
|
|
PARAM_FLAG_OPTIONS,
|
2000-07-04 19:36:36 +00:00
|
|
|
"set", &optlist, &key, &value))
|
2000-06-18 01:18:12 +00:00
|
|
|
return;
|
2000-04-26 08:03:38 +00:00
|
|
|
|
2000-07-04 19:36:36 +00:00
|
|
|
clear = g_hash_table_lookup(optlist, "clear") != NULL;
|
2002-06-06 20:22:38 +00:00
|
|
|
set_default = g_hash_table_lookup(optlist, "default") != NULL;
|
2019-05-28 14:00:04 +02:00
|
|
|
list_section = g_hash_table_lookup(optlist, "section") != NULL;
|
2000-07-04 19:36:36 +00:00
|
|
|
|
2004-03-23 19:20:45 +00:00
|
|
|
if (*key == '\0')
|
2019-05-28 14:00:04 +02:00
|
|
|
clear = set_default = list_section = FALSE;
|
2004-03-23 19:20:45 +00:00
|
|
|
|
2019-05-28 14:00:04 +02:00
|
|
|
if (list_section)
|
|
|
|
|
set_print_section(key);
|
|
|
|
|
else if (!(clear || set_default || *value != '\0'))
|
2007-06-05 12:03:18 +00:00
|
|
|
set_print_pattern(key);
|
|
|
|
|
else {
|
|
|
|
|
rec = settings_get_record(key);
|
|
|
|
|
if (rec != NULL) {
|
2000-04-26 08:03:38 +00:00
|
|
|
/* change the setting */
|
|
|
|
|
switch (rec->type) {
|
|
|
|
|
case SETTING_TYPE_BOOLEAN:
|
2015-10-02 20:25:14 +02:00
|
|
|
if (clear)
|
2001-03-03 16:14:28 +00:00
|
|
|
settings_set_bool(key, FALSE);
|
2002-06-06 20:22:38 +00:00
|
|
|
else if (set_default)
|
2002-12-28 17:54:13 +00:00
|
|
|
settings_set_bool(key, rec->default_value.v_bool);
|
2002-06-06 20:22:38 +00:00
|
|
|
else
|
2001-03-03 16:14:28 +00:00
|
|
|
set_boolean(key, value);
|
2000-04-26 08:03:38 +00:00
|
|
|
break;
|
|
|
|
|
case SETTING_TYPE_INT:
|
2009-02-21 17:20:13 +00:00
|
|
|
if (clear)
|
|
|
|
|
settings_set_int(key, 0);
|
|
|
|
|
else if (set_default)
|
|
|
|
|
settings_set_int(key, rec->default_value.v_int);
|
|
|
|
|
else
|
|
|
|
|
set_int(key, value);
|
2000-04-26 08:03:38 +00:00
|
|
|
break;
|
2016-06-12 15:26:07 +02:00
|
|
|
case SETTING_TYPE_CHOICE:
|
2016-06-12 23:39:22 +02:00
|
|
|
if (clear || set_default)
|
|
|
|
|
settings_set_choice(key, rec->choices[rec->default_value.v_int]);
|
|
|
|
|
else
|
|
|
|
|
set_choice(key, value);
|
2016-06-12 15:26:07 +02:00
|
|
|
break;
|
2000-04-26 08:03:38 +00:00
|
|
|
case SETTING_TYPE_STRING:
|
2002-06-06 20:22:38 +00:00
|
|
|
settings_set_str(key, clear ? "" :
|
2002-12-28 17:54:13 +00:00
|
|
|
set_default ? rec->default_value.v_string :
|
2002-06-06 20:22:38 +00:00
|
|
|
value);
|
2000-04-26 08:03:38 +00:00
|
|
|
break;
|
2002-12-28 17:54:13 +00:00
|
|
|
case SETTING_TYPE_TIME:
|
|
|
|
|
if (!settings_set_time(key, clear ? "0" :
|
|
|
|
|
set_default ? rec->default_value.v_string : value))
|
2015-10-02 20:25:14 +02:00
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_INVALID_TIME);
|
2002-12-28 17:54:13 +00:00
|
|
|
break;
|
|
|
|
|
case SETTING_TYPE_LEVEL:
|
|
|
|
|
if (!settings_set_level(key, clear ? "" :
|
|
|
|
|
set_default ? rec->default_value.v_string : value))
|
2015-10-02 20:25:14 +02:00
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_INVALID_LEVEL);
|
2002-12-28 17:54:13 +00:00
|
|
|
break;
|
|
|
|
|
case SETTING_TYPE_SIZE:
|
|
|
|
|
if (!settings_set_size(key, clear ? "0" :
|
|
|
|
|
set_default ? rec->default_value.v_string : value))
|
2015-10-02 20:25:14 +02:00
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_INVALID_SIZE);
|
|
|
|
|
break;
|
|
|
|
|
case SETTING_TYPE_ANY:
|
|
|
|
|
/* Unpossible! */
|
2002-12-28 17:54:13 +00:00
|
|
|
break;
|
2000-04-26 08:03:38 +00:00
|
|
|
}
|
|
|
|
|
signal_emit("setup changed", 0);
|
2015-10-02 20:25:14 +02:00
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_SET_TITLE, rec->section);
|
2007-06-05 12:03:18 +00:00
|
|
|
set_print(rec);
|
|
|
|
|
} else
|
2015-10-02 20:25:14 +02:00
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_SET_UNKNOWN, key);
|
2000-04-26 08:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
2015-10-02 20:25:14 +02:00
|
|
|
cmd_params_free(free_arg);
|
2000-04-26 08:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
2000-07-23 23:19:22 +00:00
|
|
|
/* SYNTAX: TOGGLE <key> [on|off|toggle] */
|
2000-04-26 08:03:38 +00:00
|
|
|
static void cmd_toggle(const char *data)
|
|
|
|
|
{
|
2000-06-18 01:18:12 +00:00
|
|
|
char *key, *value;
|
|
|
|
|
void *free_arg;
|
2000-04-26 08:03:38 +00:00
|
|
|
int type;
|
|
|
|
|
|
2015-11-09 23:02:41 +01:00
|
|
|
if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST | PARAM_FLAG_STRIP_TRAILING_WS, &key, &value))
|
2000-06-18 01:18:12 +00:00
|
|
|
return;
|
2000-04-26 08:03:38 +00:00
|
|
|
|
2015-10-02 20:25:14 +02:00
|
|
|
if (*key == '\0')
|
|
|
|
|
cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
|
2001-02-19 07:16:32 +00:00
|
|
|
|
2000-04-26 08:03:38 +00:00
|
|
|
type = settings_get_type(key);
|
2015-10-02 20:25:14 +02:00
|
|
|
if (type == SETTING_TYPE_ANY)
|
2001-05-26 19:20:45 +00:00
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_SET_UNKNOWN, key);
|
2000-04-26 08:03:38 +00:00
|
|
|
else if (type != SETTING_TYPE_BOOLEAN)
|
2001-05-26 19:20:45 +00:00
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_SET_NOT_BOOLEAN, key);
|
2000-04-26 08:03:38 +00:00
|
|
|
else {
|
|
|
|
|
set_boolean(key, *value != '\0' ? value : "TOGGLE");
|
2015-10-02 20:25:14 +02:00
|
|
|
set_print(settings_get_record(key));
|
2001-07-30 12:24:24 +00:00
|
|
|
signal_emit("setup changed", 0);
|
2000-04-26 08:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
2015-10-02 20:25:14 +02:00
|
|
|
cmd_params_free(free_arg);
|
2000-04-26 08:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
2000-06-18 10:25:39 +00:00
|
|
|
static int config_key_compare(CONFIG_NODE *node1, CONFIG_NODE *node2)
|
|
|
|
|
{
|
2014-06-10 12:06:19 -04:00
|
|
|
return g_ascii_strcasecmp(node1->key, node2->key);
|
2000-06-18 10:25:39 +00:00
|
|
|
}
|
|
|
|
|
|
2000-04-26 08:03:38 +00:00
|
|
|
static void show_aliases(const char *alias)
|
|
|
|
|
{
|
|
|
|
|
CONFIG_NODE *node;
|
2000-06-18 10:25:39 +00:00
|
|
|
GSList *tmp, *list;
|
2000-04-26 08:03:38 +00:00
|
|
|
int aliaslen;
|
|
|
|
|
|
2001-01-07 19:42:59 +00:00
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_ALIASLIST_HEADER);
|
2000-04-26 08:03:38 +00:00
|
|
|
|
|
|
|
|
node = iconfig_node_traverse("aliases", FALSE);
|
2002-02-02 17:37:44 +00:00
|
|
|
tmp = node == NULL ? NULL : config_node_first(node->value);
|
2000-04-26 08:03:38 +00:00
|
|
|
|
2000-06-18 10:25:39 +00:00
|
|
|
/* first get the list of aliases sorted */
|
|
|
|
|
list = NULL;
|
2000-04-26 08:03:38 +00:00
|
|
|
aliaslen = strlen(alias);
|
2002-02-02 17:37:44 +00:00
|
|
|
for (; tmp != NULL; tmp = config_node_next(tmp)) {
|
2000-04-26 08:03:38 +00:00
|
|
|
CONFIG_NODE *node = tmp->data;
|
|
|
|
|
|
|
|
|
|
if (node->type != NODE_TYPE_KEY)
|
|
|
|
|
continue;
|
|
|
|
|
|
2014-06-10 12:06:19 -04:00
|
|
|
if (aliaslen != 0 && g_ascii_strncasecmp(node->key, alias, aliaslen) != 0)
|
2000-04-26 08:03:38 +00:00
|
|
|
continue;
|
|
|
|
|
|
2000-06-18 10:25:39 +00:00
|
|
|
list = g_slist_insert_sorted(list, node, (GCompareFunc) config_key_compare);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* print the aliases */
|
|
|
|
|
for (tmp = list; tmp != NULL; tmp = tmp->next) {
|
|
|
|
|
CONFIG_NODE *node = tmp->data;
|
|
|
|
|
|
2001-01-07 19:42:59 +00:00
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_ALIASLIST_LINE,
|
2000-04-26 08:03:38 +00:00
|
|
|
node->key, node->value);
|
|
|
|
|
}
|
2000-06-18 10:25:39 +00:00
|
|
|
g_slist_free(list);
|
2000-04-26 08:03:38 +00:00
|
|
|
|
2001-01-07 19:42:59 +00:00
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_ALIASLIST_FOOTER);
|
2000-04-26 08:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void alias_remove(const char *alias)
|
|
|
|
|
{
|
|
|
|
|
if (iconfig_get_str("aliases", alias, NULL) == NULL)
|
2001-01-07 19:42:59 +00:00
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_ALIAS_NOT_FOUND, alias);
|
2000-04-26 08:03:38 +00:00
|
|
|
else {
|
2001-01-07 19:42:59 +00:00
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_ALIAS_REMOVED, alias);
|
2000-04-26 08:03:38 +00:00
|
|
|
iconfig_set_str("aliases", alias, NULL);
|
2002-05-12 14:06:08 +00:00
|
|
|
|
2002-05-12 14:23:05 +00:00
|
|
|
signal_emit("alias removed", 1, alias);
|
2000-04-26 08:03:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-07-23 23:19:22 +00:00
|
|
|
/* SYNTAX: ALIAS [[-]<alias> [<command>]] */
|
2000-04-26 08:03:38 +00:00
|
|
|
static void cmd_alias(const char *data)
|
|
|
|
|
{
|
2000-06-18 01:18:12 +00:00
|
|
|
char *alias, *value;
|
|
|
|
|
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, 2 | PARAM_FLAG_GETREST, &alias, &value))
|
|
|
|
|
return;
|
|
|
|
|
|
2000-04-26 08:03:38 +00:00
|
|
|
if (*alias == '-') {
|
|
|
|
|
if (alias[1] != '\0') alias_remove(alias+1);
|
|
|
|
|
} else if (*alias == '\0' || *value == '\0')
|
|
|
|
|
show_aliases(alias);
|
|
|
|
|
else {
|
2001-01-07 19:42:59 +00:00
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE, TXT_ALIAS_ADDED, alias);
|
2000-04-26 08:03:38 +00:00
|
|
|
iconfig_set_str("aliases", alias, value);
|
2002-05-12 14:23:05 +00:00
|
|
|
signal_emit("alias added", 2, alias, value);
|
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: UNALIAS <alias> */
|
2000-04-26 08:03:38 +00:00
|
|
|
static void cmd_unalias(const char *data)
|
|
|
|
|
{
|
2002-06-04 21:23:34 +00:00
|
|
|
char *alias;
|
|
|
|
|
void *free_arg;
|
2000-04-26 08:03:38 +00:00
|
|
|
|
2002-06-04 21:23:34 +00:00
|
|
|
g_return_if_fail(data != NULL);
|
|
|
|
|
|
|
|
|
|
if (!cmd_get_params(data, &free_arg, 1, &alias))
|
|
|
|
|
return;
|
|
|
|
|
if (*alias == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
|
|
|
|
|
|
|
|
|
|
alias_remove(alias);
|
|
|
|
|
cmd_params_free(free_arg);
|
2000-04-26 08:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
2000-07-23 23:19:22 +00:00
|
|
|
/* SYNTAX: RELOAD [<file>] */
|
2000-07-22 22:05:29 +00:00
|
|
|
static void cmd_reload(const char *data)
|
|
|
|
|
{
|
2001-07-29 00:27:23 +00:00
|
|
|
const char *fname;
|
|
|
|
|
|
|
|
|
|
fname = *data == '\0' ? get_irssi_config() : data;
|
2000-07-22 22:05:29 +00:00
|
|
|
|
|
|
|
|
if (settings_reread(fname)) {
|
|
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
|
2001-01-07 19:42:59 +00:00
|
|
|
TXT_CONFIG_RELOADED, fname);
|
2000-07-22 22:05:29 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-10-15 19:21:21 +00:00
|
|
|
static void settings_save_fe(const char *fname)
|
|
|
|
|
{
|
2001-11-14 16:28:56 +00:00
|
|
|
if (settings_save(fname, FALSE /* not autosaved */)) {
|
2000-10-15 19:21:21 +00:00
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
|
2001-01-07 19:42:59 +00:00
|
|
|
TXT_CONFIG_SAVED, fname);
|
2000-10-15 19:21:21 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void settings_save_confirm(const char *line, char *fname)
|
|
|
|
|
{
|
2002-01-27 20:45:59 +00:00
|
|
|
if (i_toupper(line[0]) == 'Y')
|
2000-10-15 19:21:21 +00:00
|
|
|
settings_save_fe(fname);
|
|
|
|
|
g_free(fname);
|
|
|
|
|
}
|
|
|
|
|
|
2000-07-23 23:19:22 +00:00
|
|
|
/* SYNTAX: SAVE [<file>] */
|
2000-07-22 22:05:29 +00:00
|
|
|
static void cmd_save(const char *data)
|
|
|
|
|
{
|
2002-01-18 16:23:57 +00:00
|
|
|
GHashTable *optlist;
|
|
|
|
|
char *format, *fname;
|
|
|
|
|
void *free_arg;
|
2001-05-17 20:13:59 +00:00
|
|
|
|
2002-01-18 16:23:57 +00:00
|
|
|
if (!cmd_get_params(data, &free_arg, 1 | PARAM_FLAG_OPTIONS,
|
|
|
|
|
"save", &optlist, &fname))
|
2000-10-15 19:21:21 +00:00
|
|
|
return;
|
2002-01-18 16:23:57 +00:00
|
|
|
|
|
|
|
|
if (*fname == '\0')
|
|
|
|
|
fname = mainconfig->fname;
|
|
|
|
|
|
|
|
|
|
if (!irssi_config_is_changed(fname))
|
|
|
|
|
settings_save_fe(fname);
|
|
|
|
|
else {
|
|
|
|
|
/* config file modified outside irssi */
|
|
|
|
|
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
|
|
|
|
|
TXT_CONFIG_MODIFIED, fname);
|
|
|
|
|
|
|
|
|
|
format = format_get_text(MODULE_NAME, NULL, NULL, NULL,
|
|
|
|
|
TXT_OVERWRITE_CONFIG);
|
|
|
|
|
keyboard_entry_redirect((SIGNAL_FUNC) settings_save_confirm,
|
|
|
|
|
format, 0, g_strdup(fname));
|
|
|
|
|
g_free(format);
|
2000-07-22 22:05:29 +00:00
|
|
|
}
|
2000-10-15 19:21:21 +00:00
|
|
|
|
2002-01-18 16:23:57 +00:00
|
|
|
cmd_params_free(free_arg);
|
2000-07-22 22:05:29 +00:00
|
|
|
}
|
|
|
|
|
|
2001-03-16 23:57:24 +00:00
|
|
|
static void settings_clean_confirm(const char *line)
|
|
|
|
|
{
|
2002-01-27 20:45:59 +00:00
|
|
|
if (i_toupper(line[0]) == 'Y')
|
2001-03-16 23:57:24 +00:00
|
|
|
settings_clean_invalid();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void sig_settings_errors(const char *msg)
|
|
|
|
|
{
|
|
|
|
|
printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "%s", msg);
|
|
|
|
|
keyboard_entry_redirect((SIGNAL_FUNC) settings_clean_confirm,
|
2001-05-17 20:13:59 +00:00
|
|
|
"Remove unknown settings from config file (Y/n)?",
|
2001-03-16 23:57:24 +00:00
|
|
|
0, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-26 08:03:38 +00:00
|
|
|
void fe_settings_init(void)
|
|
|
|
|
{
|
|
|
|
|
command_bind("set", NULL, (SIGNAL_FUNC) cmd_set);
|
|
|
|
|
command_bind("toggle", NULL, (SIGNAL_FUNC) cmd_toggle);
|
|
|
|
|
command_bind("alias", NULL, (SIGNAL_FUNC) cmd_alias);
|
|
|
|
|
command_bind("unalias", NULL, (SIGNAL_FUNC) cmd_unalias);
|
2000-07-22 22:05:29 +00:00
|
|
|
command_bind("reload", NULL, (SIGNAL_FUNC) cmd_reload);
|
|
|
|
|
command_bind("save", NULL, (SIGNAL_FUNC) cmd_save);
|
2019-05-28 14:00:04 +02:00
|
|
|
command_set_options("set", "clear default section");
|
2001-03-16 23:57:24 +00:00
|
|
|
|
|
|
|
|
signal_add("settings errors", (SIGNAL_FUNC) sig_settings_errors);
|
2000-04-26 08:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void fe_settings_deinit(void)
|
|
|
|
|
{
|
|
|
|
|
command_unbind("set", (SIGNAL_FUNC) cmd_set);
|
|
|
|
|
command_unbind("toggle", (SIGNAL_FUNC) cmd_toggle);
|
|
|
|
|
command_unbind("alias", (SIGNAL_FUNC) cmd_alias);
|
|
|
|
|
command_unbind("unalias", (SIGNAL_FUNC) cmd_unalias);
|
2000-07-22 22:05:29 +00:00
|
|
|
command_unbind("reload", (SIGNAL_FUNC) cmd_reload);
|
|
|
|
|
command_unbind("save", (SIGNAL_FUNC) cmd_save);
|
2001-03-16 23:57:24 +00:00
|
|
|
|
|
|
|
|
signal_remove("settings errors", (SIGNAL_FUNC) sig_settings_errors);
|
2000-04-26 08:03:38 +00:00
|
|
|
}
|