summaryrefslogtreecommitdiff
path: root/src/fe-common/core/fe-settings.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fe-common/core/fe-settings.c')
-rw-r--r--src/fe-common/core/fe-settings.c65
1 files changed, 45 insertions, 20 deletions
diff --git a/src/fe-common/core/fe-settings.c b/src/fe-common/core/fe-settings.c
index 96e03ceb..abbd45a8 100644
--- a/src/fe-common/core/fe-settings.c
+++ b/src/fe-common/core/fe-settings.c
@@ -53,7 +53,7 @@ static void set_print_pattern(const char *pattern)
if (stristr(rec->key, pattern) == NULL)
continue;
- if (strcmp(last_section, rec->section) != 0) {
+ if (g_strcmp0(last_section, rec->section) != 0) {
/* print section */
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP,
TXT_SET_TITLE, rec->section);
@@ -67,6 +67,7 @@ static void set_print_pattern(const char *pattern)
static void set_boolean(const char *key, const char *value)
{
char *stripped_value;
+
stripped_value = g_strdup(value);
g_strstrip(stripped_value);
@@ -79,7 +80,7 @@ static void set_boolean(const char *key, const char *value)
else
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_NOT_TOGGLE);
- g_free(stripped_value);
+ g_free(stripped_value);
}
static void set_int(const char *key, const char *value)
@@ -99,6 +100,24 @@ static void set_int(const char *key, const char *value)
settings_set_int(key, (int)longval);
}
+static void set_choice(const char *key, const char *value)
+{
+ char *stripped_value;
+
+ stripped_value = g_strdup(value);
+ g_strstrip(stripped_value);
+
+ if (settings_set_choice(key, stripped_value) == FALSE) {
+ SETTINGS_REC *rec = settings_get_record(key);
+ char *msg = g_strjoinv(", ", rec->choices);
+
+ printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_INVALID_CHOICE, msg);
+ g_free(msg);
+ }
+
+ g_free(stripped_value);
+}
+
/* SYNTAX: SET [-clear | -default] [<key> [<value>]] */
static void cmd_set(char *data)
{
@@ -108,7 +127,8 @@ static void cmd_set(char *data)
int clear, set_default;
SETTINGS_REC *rec;
- if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST | PARAM_FLAG_OPTIONS,
+ if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST |
+ PARAM_FLAG_OPTIONS,
"set", &optlist, &key, &value))
return;
@@ -126,7 +146,7 @@ static void cmd_set(char *data)
/* change the setting */
switch (rec->type) {
case SETTING_TYPE_BOOLEAN:
- if (clear)
+ if (clear)
settings_set_bool(key, FALSE);
else if (set_default)
settings_set_bool(key, rec->default_value.v_bool);
@@ -141,6 +161,12 @@ static void cmd_set(char *data)
else
set_int(key, value);
break;
+ case SETTING_TYPE_CHOICE:
+ if (clear || set_default)
+ settings_set_choice(key, rec->choices[rec->default_value.v_int]);
+ else
+ set_choice(key, value);
+ break;
case SETTING_TYPE_STRING:
settings_set_str(key, clear ? "" :
set_default ? rec->default_value.v_string :
@@ -149,32 +175,30 @@ static void cmd_set(char *data)
case SETTING_TYPE_TIME:
if (!settings_set_time(key, clear ? "0" :
set_default ? rec->default_value.v_string : value))
- printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
- TXT_INVALID_TIME);
+ printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_INVALID_TIME);
break;
case SETTING_TYPE_LEVEL:
if (!settings_set_level(key, clear ? "" :
set_default ? rec->default_value.v_string : value))
- printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
- TXT_INVALID_LEVEL);
+ printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_INVALID_LEVEL);
break;
case SETTING_TYPE_SIZE:
if (!settings_set_size(key, clear ? "0" :
set_default ? rec->default_value.v_string : value))
- printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
- TXT_INVALID_SIZE);
+ printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_INVALID_SIZE);
+ break;
+ case SETTING_TYPE_ANY:
+ /* Unpossible! */
break;
}
signal_emit("setup changed", 0);
- printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP,
- TXT_SET_TITLE, rec->section);
+ printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, TXT_SET_TITLE, rec->section);
set_print(rec);
} else
- printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
- TXT_SET_UNKNOWN, key);
+ printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_SET_UNKNOWN, key);
}
- cmd_params_free(free_arg);
+ cmd_params_free(free_arg);
}
/* SYNTAX: TOGGLE <key> [on|off|toggle] */
@@ -184,23 +208,24 @@ static void cmd_toggle(const char *data)
void *free_arg;
int type;
- if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST, &key, &value))
+ if (!cmd_get_params(data, &free_arg, 2 | PARAM_FLAG_GETREST | PARAM_FLAG_STRIP_TRAILING_WS, &key, &value))
return;
- if (*key == '\0') cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
+ if (*key == '\0')
+ cmd_param_error(CMDERR_NOT_ENOUGH_PARAMS);
type = settings_get_type(key);
- if (type == -1)
+ if (type == SETTING_TYPE_ANY)
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_SET_UNKNOWN, key);
else if (type != SETTING_TYPE_BOOLEAN)
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_SET_NOT_BOOLEAN, key);
else {
set_boolean(key, *value != '\0' ? value : "TOGGLE");
- set_print(settings_get_record(key));
+ set_print(settings_get_record(key));
signal_emit("setup changed", 0);
}
- cmd_params_free(free_arg);
+ cmd_params_free(free_arg);
}
static int config_key_compare(CONFIG_NODE *node1, CONFIG_NODE *node2)