1
0
mirror of https://github.com/irssi/irssi.git synced 2024-12-04 14:46:39 -05:00

Make rejoin_channels_mode of type CHOICE

This commit is contained in:
LemonBoy 2016-06-12 16:26:18 +02:00
parent bf9d9494db
commit 86c5e56ef4

View File

@ -623,39 +623,25 @@ char *irc_server_get_channels(IRC_SERVER_REC *server)
GString *chans, *keys; GString *chans, *keys;
char *ret; char *ret;
int use_keys; int use_keys;
char *rejoin_channels_mode; int rejoin_channels_mode;
g_return_val_if_fail(server != NULL, FALSE); g_return_val_if_fail(server != NULL, FALSE);
rejoin_channels_mode = g_strdup(settings_get_str("rejoin_channels_on_reconnect")); rejoin_channels_mode = settings_get_choice("rejoin_channels_on_reconnect");
if (rejoin_channels_mode == NULL || /* do we want to rejoin channels in the first place? */
(g_ascii_strcasecmp(rejoin_channels_mode, "on") != 0 && if(rejoin_channels_mode == 0)
g_ascii_strcasecmp(rejoin_channels_mode, "off") != 0 && return g_strdup("");
g_ascii_strcasecmp(rejoin_channels_mode, "auto") != 0)) {
g_warning("Invalid value for 'rejoin_channels_on_reconnect', valid values are 'on', 'off', 'auto', using 'on' as default value.");
g_free(rejoin_channels_mode);
rejoin_channels_mode = g_strdup("on");
}
chans = g_string_new(NULL); chans = g_string_new(NULL);
keys = g_string_new(NULL); keys = g_string_new(NULL);
use_keys = FALSE; use_keys = FALSE;
/* do we want to rejoin channels in the first place? */
if(g_ascii_strcasecmp(rejoin_channels_mode, "off") == 0) {
g_string_free(chans, TRUE);
g_string_free(keys, TRUE);
g_free(rejoin_channels_mode);
return g_strdup("");
}
/* get currently joined channels */ /* get currently joined channels */
for (tmp = server->channels; tmp != NULL; tmp = tmp->next) { for (tmp = server->channels; tmp != NULL; tmp = tmp->next) {
CHANNEL_REC *channel = tmp->data; CHANNEL_REC *channel = tmp->data;
CHANNEL_SETUP_REC *setup = channel_setup_find(channel->name, channel->server->connrec->chatnet); CHANNEL_SETUP_REC *setup = channel_setup_find(channel->name, channel->server->connrec->chatnet);
if ((setup != NULL && setup->autojoin && g_ascii_strcasecmp(rejoin_channels_mode, "auto") == 0) || if ((setup != NULL && setup->autojoin && rejoin_channels_mode == 2) || rejoin_channels_mode == 1) {
g_ascii_strcasecmp(rejoin_channels_mode, "on") == 0) {
g_string_append_printf(chans, "%s,", channel->name); g_string_append_printf(chans, "%s,", channel->name);
g_string_append_printf(keys, "%s,", channel->key == NULL ? "x" : channel->key); g_string_append_printf(keys, "%s,", channel->key == NULL ? "x" : channel->key);
if (channel->key != NULL) if (channel->key != NULL)
@ -668,8 +654,7 @@ char *irc_server_get_channels(IRC_SERVER_REC *server)
REJOIN_REC *rec = tmp->data; REJOIN_REC *rec = tmp->data;
CHANNEL_SETUP_REC *setup = channel_setup_find(rec->channel, server->tag); CHANNEL_SETUP_REC *setup = channel_setup_find(rec->channel, server->tag);
if ((setup != NULL && setup->autojoin && g_ascii_strcasecmp(rejoin_channels_mode, "auto") == 0) || if ((setup != NULL && setup->autojoin && rejoin_channels_mode == 2) || rejoin_channels_mode == 1) {
g_ascii_strcasecmp(rejoin_channels_mode, "on") == 0) {
g_string_append_printf(chans, "%s,", rec->channel); g_string_append_printf(chans, "%s,", rec->channel);
g_string_append_printf(keys, "%s,", rec->key == NULL ? "x" : g_string_append_printf(keys, "%s,", rec->key == NULL ? "x" :
rec->key); rec->key);
@ -687,7 +672,6 @@ char *irc_server_get_channels(IRC_SERVER_REC *server)
ret = chans->str; ret = chans->str;
g_string_free(chans, FALSE); g_string_free(chans, FALSE);
g_string_free(keys, TRUE); g_string_free(keys, TRUE);
g_free(rejoin_channels_mode);
return ret; return ret;
} }
@ -1033,7 +1017,7 @@ void irc_server_init_isupport(IRC_SERVER_REC *server)
void irc_servers_init(void) void irc_servers_init(void)
{ {
settings_add_str("servers", "rejoin_channels_on_reconnect", "on"); settings_add_choice("servers", "rejoin_channels_on_reconnect", 1, "off,on,auto");
settings_add_str("misc", "usermode", DEFAULT_USER_MODE); settings_add_str("misc", "usermode", DEFAULT_USER_MODE);
settings_add_str("misc", "split_line_start", ""); settings_add_str("misc", "split_line_start", "");
settings_add_str("misc", "split_line_end", ""); settings_add_str("misc", "split_line_end", "");