diff options
Diffstat (limited to 'src/core/channels-setup.c')
-rw-r--r-- | src/core/channels-setup.c | 45 |
1 files changed, 37 insertions, 8 deletions
diff --git a/src/core/channels-setup.c b/src/core/channels-setup.c index 2902ef8e..33f58022 100644 --- a/src/core/channels-setup.c +++ b/src/core/channels-setup.c @@ -30,16 +30,34 @@ GSList *setupchannels; +static int compare_channel_name (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 (name == NULL || chatnet == NULL) + return 1; + + return !!strcmp(name, channel->name) | !!strcmp(chatnet, channel->chatnet); +} + static void channel_setup_save(CHANNEL_SETUP_REC *channel) { CONFIG_NODE *parentnode, *node; - int index; - - index = g_slist_index(setupchannels, channel); + GSList *config_node; parentnode = iconfig_node_traverse("(channels", TRUE); - node = config_node_nth(parentnode, index); - if (node == NULL) + + /* Try to find this channel in the configuration */ + config_node = g_slist_find_custom(parentnode->value, channel, + (GCompareFunc)compare_channel_name); + 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(parentnode, NULL, NODE_TYPE_BLOCK); iconfig_node_clear(node); @@ -65,10 +83,21 @@ void channel_setup_create(CHANNEL_SETUP_REC *channel) static void channel_config_remove(CHANNEL_SETUP_REC *channel) { - CONFIG_NODE *node; + CONFIG_NODE *parentnode; + GSList *config_node; - node = iconfig_node_traverse("channels", FALSE); - if (node != NULL) iconfig_node_list_remove(node, g_slist_index(setupchannels, channel)); + parentnode = iconfig_node_traverse("channels", FALSE); + + if (parentnode == NULL) + return; + + /* Try to find this channel in the configuration */ + config_node = g_slist_find_custom(parentnode->value, channel, + (GCompareFunc)compare_channel_name); + + if (config_node != NULL) + /* Delete the channel from the configuration */ + iconfig_node_remove(parentnode, config_node->data); } static void channel_setup_destroy(CHANNEL_SETUP_REC *channel) |