summaryrefslogtreecommitdiff
path: root/src/core/channels-setup.c
diff options
context:
space:
mode:
authorailin-nemui <ailin-nemui@users.noreply.github.com>2015-12-09 23:07:48 +0100
committerailin-nemui <ailin-nemui@users.noreply.github.com>2015-12-09 23:07:48 +0100
commit4dc2bab4b4ae7ff05220c1121f0f11097f77b265 (patch)
tree3059fca7873f5478a1766df2ea9159b6879af552 /src/core/channels-setup.c
parent3468a326242066743803ea0b19f0359cec0ce398 (diff)
parent1749a7a5abf9801bb663b74d4b3e7c3bcbfeb271 (diff)
downloadirssi-4dc2bab4b4ae7ff05220c1121f0f11097f77b265.zip
Merge pull request #371 from LemonBoy/rampage
Rewrite some faulty logic handling the saved channels. Fixes #340
Diffstat (limited to 'src/core/channels-setup.c')
-rw-r--r--src/core/channels-setup.c50
1 files changed, 40 insertions, 10 deletions
diff --git a/src/core/channels-setup.c b/src/core/channels-setup.c
index 2902ef8e..4966d77d 100644
--- a/src/core/channels-setup.c
+++ b/src/core/channels-setup.c
@@ -30,17 +30,36 @@
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)
{
- CONFIG_NODE *parentnode, *node;
- int index;
+ CONFIG_NODE *parent_node, *node;
+ GSList *config_node;
- index = g_slist_index(setupchannels, channel);
+ parent_node = iconfig_node_traverse("(channels", TRUE);
- parentnode = iconfig_node_traverse("(channels", TRUE);
- node = config_node_nth(parentnode, index);
- if (node == NULL)
- node = iconfig_node_section(parentnode, NULL, NODE_TYPE_BLOCK);
+ /* 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)
+ /* 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_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)
{
- CONFIG_NODE *node;
+ CONFIG_NODE *parent_node;
+ GSList *config_node;
- node = iconfig_node_traverse("channels", FALSE);
- if (node != NULL) iconfig_node_list_remove(node, g_slist_index(setupchannels, channel));
+ parent_node = iconfig_node_traverse("channels", FALSE);
+
+ 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)