Minor config code refactor.

This commit is contained in:
Håvard Pettersson 2015-01-04 15:05:18 +01:00
parent 1e7be52e5b
commit 4794097872

View File

@ -50,30 +50,6 @@ char *twc_profile_option_names[TWC_PROFILE_NUM_OPTIONS] =
"ipv6", "ipv6",
}; };
char *twc_profile_option_defaults[TWC_PROFILE_NUM_OPTIONS] =
{
"%h/tox/%p",
"off",
"100",
NULL,
NULL,
"none",
"on",
"on",
};
bool twc_profile_option_null_allowed[TWC_PROFILE_NUM_OPTIONS] =
{
false,
false,
false,
true, // we allow proxy information to be null
true, // -------------------------------------
false,
false,
false,
};
/** /**
* Get the index of a profile option name. * Get the index of a profile option name.
*/ */
@ -208,6 +184,10 @@ twc_config_init_option(struct t_config_section *section,
char *description; char *description;
char *string_values = NULL; char *string_values = NULL;
int min = 0, max = 0; int min = 0, max = 0;
char *value;
char *default_value = NULL;
bool null_allowed = false;
switch (option_index) switch (option_index)
{ {
@ -215,50 +195,56 @@ twc_config_init_option(struct t_config_section *section,
type = "boolean"; type = "boolean";
description = "automatically load profile and connect to the Tox " description = "automatically load profile and connect to the Tox "
"network when WeeChat starts"; "network when WeeChat starts";
default_value = "off";
break; break;
case TWC_PROFILE_OPTION_IPV6: case TWC_PROFILE_OPTION_IPV6:
type = "boolean"; type = "boolean";
description = "use IPv6 as well as IPv4 to connect to the Tox " description = "use IPv6 as well as IPv4 to connect to the Tox "
"network"; "network";
default_value = "on";
break; break;
case TWC_PROFILE_OPTION_MAX_FRIEND_REQUESTS: case TWC_PROFILE_OPTION_MAX_FRIEND_REQUESTS:
type = "integer"; type = "integer";
description = "maximum amount of friend requests to retain before " description = "maximum amount of friend requests to retain before "
"ignoring new ones"; "ignoring new ones";
min = 0; max = INT_MAX; min = 0; max = INT_MAX;
default_value = "100";
break; break;
case TWC_PROFILE_OPTION_PROXY_ADDRESS: case TWC_PROFILE_OPTION_PROXY_ADDRESS:
type = "string"; type = "string";
description = "proxy address"; description = "proxy address";
null_allowed = true;
break; break;
case TWC_PROFILE_OPTION_PROXY_PORT: case TWC_PROFILE_OPTION_PROXY_PORT:
type = "integer"; type = "integer";
description = "proxy port"; description = "proxy port";
min = 0; max = UINT16_MAX; min = 0; max = UINT16_MAX;
null_allowed = true;
break; break;
case TWC_PROFILE_OPTION_PROXY_TYPE: case TWC_PROFILE_OPTION_PROXY_TYPE:
type = "integer"; type = "integer";
description = "proxy type; requires profile reload to take effect"; description = "proxy type; requires profile reload to take effect";
string_values = "none|socks5|http"; string_values = "none|socks5|http";
min = 0; max = 0; min = 0; max = 0;
default_value = "none";
break; break;
case TWC_PROFILE_OPTION_SAVEFILE: case TWC_PROFILE_OPTION_SAVEFILE:
type = "string"; type = "string";
description = "path to Tox data file (\"%h\" will be replaced by " description = "path to Tox data file (\"%h\" will be replaced by "
"WeeChat home folder and \"%p\" by profile name"; "WeeChat home folder and \"%p\" by profile name";
default_value = "%h/tox/%p";
break; break;
case TWC_PROFILE_OPTION_UDP: case TWC_PROFILE_OPTION_UDP:
type = "boolean"; type = "boolean";
description = "use UDP when communicating with the Tox network"; description = "use UDP when communicating with the Tox network";
default_value = "on";
break; break;
default: default:
return NULL; return NULL;
} }
char *default_value = twc_profile_option_defaults[option_index]; null_allowed = null_allowed || !is_default_profile;
char *value = is_default_profile ? default_value : NULL; value = is_default_profile ? default_value : NULL;
bool null_allowed = !is_default_profile
|| twc_profile_option_null_allowed[option_index];
return weechat_config_new_option( return weechat_config_new_option(
twc_config_file, section, twc_config_file, section,