mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
Merge pull request #371 from LemonBoy/rampage
Rewrite some faulty logic handling the saved channels. Fixes #340
This commit is contained in:
commit
4dc2bab4b4
@ -30,17 +30,36 @@
|
|||||||
|
|
||||||
GSList *setupchannels;
|
GSList *setupchannels;
|
||||||
|
|
||||||
|
static int compare_channel_setup (CONFIG_NODE *node, CHANNEL_SETUP_REC *channel)
|
||||||
|
{
|
||||||
|
char *name, *chatnet;
|
||||||
|
|
||||||
|
name = config_node_get_str(node, "name", NULL);
|
||||||
|
chatnet = config_node_get_str(node, "chatnet", NULL);
|
||||||
|
|
||||||
|
if (g_strcmp0(name, channel->name) != 0 ||
|
||||||
|
g_strcmp0(chatnet, channel->chatnet) != 0)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void channel_setup_save(CHANNEL_SETUP_REC *channel)
|
static void channel_setup_save(CHANNEL_SETUP_REC *channel)
|
||||||
{
|
{
|
||||||
CONFIG_NODE *parentnode, *node;
|
CONFIG_NODE *parent_node, *node;
|
||||||
int index;
|
GSList *config_node;
|
||||||
|
|
||||||
index = g_slist_index(setupchannels, channel);
|
parent_node = iconfig_node_traverse("(channels", TRUE);
|
||||||
|
|
||||||
parentnode = iconfig_node_traverse("(channels", TRUE);
|
/* Try to find this channel in the configuration */
|
||||||
node = config_node_nth(parentnode, index);
|
config_node = g_slist_find_custom(parent_node->value, channel,
|
||||||
if (node == NULL)
|
(GCompareFunc)compare_channel_setup);
|
||||||
node = iconfig_node_section(parentnode, NULL, NODE_TYPE_BLOCK);
|
if (config_node != NULL)
|
||||||
|
/* Let's update this channel record */
|
||||||
|
node = config_node->data;
|
||||||
|
else
|
||||||
|
/* Create a brand-new channel record */
|
||||||
|
node = iconfig_node_section(parent_node, NULL, NODE_TYPE_BLOCK);
|
||||||
|
|
||||||
iconfig_node_clear(node);
|
iconfig_node_clear(node);
|
||||||
iconfig_node_set_str(node, "name", channel->name);
|
iconfig_node_set_str(node, "name", channel->name);
|
||||||
@ -65,10 +84,21 @@ void channel_setup_create(CHANNEL_SETUP_REC *channel)
|
|||||||
|
|
||||||
static void channel_config_remove(CHANNEL_SETUP_REC *channel)
|
static void channel_config_remove(CHANNEL_SETUP_REC *channel)
|
||||||
{
|
{
|
||||||
CONFIG_NODE *node;
|
CONFIG_NODE *parent_node;
|
||||||
|
GSList *config_node;
|
||||||
|
|
||||||
node = iconfig_node_traverse("channels", FALSE);
|
parent_node = iconfig_node_traverse("channels", FALSE);
|
||||||
if (node != NULL) iconfig_node_list_remove(node, g_slist_index(setupchannels, channel));
|
|
||||||
|
if (parent_node == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* Try to find this channel in the configuration */
|
||||||
|
config_node = g_slist_find_custom(parent_node->value, channel,
|
||||||
|
(GCompareFunc)compare_channel_setup);
|
||||||
|
|
||||||
|
if (config_node != NULL)
|
||||||
|
/* Delete the channel from the configuration */
|
||||||
|
iconfig_node_remove(parent_node, config_node->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void channel_setup_destroy(CHANNEL_SETUP_REC *channel)
|
static void channel_setup_destroy(CHANNEL_SETUP_REC *channel)
|
||||||
|
@ -423,17 +423,39 @@ static SERVER_SETUP_REC *server_setup_read(CONFIG_NODE *node)
|
|||||||
return rec;
|
return rec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int compare_server_setup (CONFIG_NODE *node, SERVER_SETUP_REC *server)
|
||||||
|
{
|
||||||
|
char *address, *chatnet;
|
||||||
|
int port;
|
||||||
|
|
||||||
|
address = config_node_get_str(node, "address", NULL);
|
||||||
|
chatnet = config_node_get_str(node, "chatnet", NULL);
|
||||||
|
port = config_node_get_int(node, "port", 0);
|
||||||
|
|
||||||
|
if (g_strcmp0(address, server->address) != 0 ||
|
||||||
|
g_strcmp0(chatnet, server->chatnet) != 0 ||
|
||||||
|
port != server->port)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void server_setup_save(SERVER_SETUP_REC *rec)
|
static void server_setup_save(SERVER_SETUP_REC *rec)
|
||||||
{
|
{
|
||||||
CONFIG_NODE *parentnode, *node;
|
CONFIG_NODE *parent_node, *node;
|
||||||
int index;
|
GSList *config_node;
|
||||||
|
|
||||||
index = g_slist_index(setupservers, rec);
|
parent_node = iconfig_node_traverse("(servers", TRUE);
|
||||||
|
|
||||||
parentnode = iconfig_node_traverse("(servers", TRUE);
|
/* Try to find this channel in the configuration */
|
||||||
node = config_node_nth(parentnode, index);
|
config_node = g_slist_find_custom(parent_node->value, rec,
|
||||||
if (node == NULL)
|
(GCompareFunc)compare_server_setup);
|
||||||
node = iconfig_node_section(parentnode, NULL, NODE_TYPE_BLOCK);
|
if (config_node != NULL)
|
||||||
|
/* Let's update this server record */
|
||||||
|
node = config_node->data;
|
||||||
|
else
|
||||||
|
/* Create a brand-new server record */
|
||||||
|
node = iconfig_node_section(parent_node, NULL, NODE_TYPE_BLOCK);
|
||||||
|
|
||||||
iconfig_node_clear(node);
|
iconfig_node_clear(node);
|
||||||
iconfig_node_set_str(node, "address", rec->address);
|
iconfig_node_set_str(node, "address", rec->address);
|
||||||
@ -465,14 +487,21 @@ static void server_setup_save(SERVER_SETUP_REC *rec)
|
|||||||
|
|
||||||
static void server_setup_remove_config(SERVER_SETUP_REC *rec)
|
static void server_setup_remove_config(SERVER_SETUP_REC *rec)
|
||||||
{
|
{
|
||||||
CONFIG_NODE *node;
|
CONFIG_NODE *parent_node;
|
||||||
int index;
|
GSList *config_node;
|
||||||
|
|
||||||
node = iconfig_node_traverse("servers", FALSE);
|
parent_node = iconfig_node_traverse("servers", FALSE);
|
||||||
if (node != NULL) {
|
|
||||||
index = g_slist_index(setupservers, rec);
|
if (parent_node == NULL)
|
||||||
iconfig_node_list_remove(node, index);
|
return;
|
||||||
}
|
|
||||||
|
/* Try to find this server in the configuration */
|
||||||
|
config_node = g_slist_find_custom(parent_node->value, rec,
|
||||||
|
(GCompareFunc)compare_server_setup);
|
||||||
|
|
||||||
|
if (config_node != NULL)
|
||||||
|
/* Delete the server from the configuration */
|
||||||
|
iconfig_node_remove(parent_node, config_node->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void server_setup_destroy(SERVER_SETUP_REC *rec)
|
static void server_setup_destroy(SERVER_SETUP_REC *rec)
|
||||||
|
Loading…
Reference in New Issue
Block a user