1 /*
2  notify-setup.c : irssi
3 
4     Copyright (C) 1999-2000 Timo Sirainen
5 
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10 
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15 
16     You should have received a copy of the GNU General Public License along
17     with this program; if not, write to the Free Software Foundation, Inc.,
18     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20 
21 #include "module.h"
22 #include "lib-config/iconfig.h"
23 #include "settings.h"
24 
25 #include "irc-servers.h"
26 #include "notifylist.h"
27 
notifylist_add_config(NOTIFYLIST_REC * rec)28 void notifylist_add_config(NOTIFYLIST_REC *rec)
29 {
30 	CONFIG_NODE *node;
31 
32 	node = iconfig_node_traverse("notifies", TRUE);
33 	node = iconfig_node_section(node, rec->mask, NODE_TYPE_BLOCK);
34 
35 	if (rec->away_check)
36 		iconfig_node_set_bool(node, "away_check", TRUE);
37 	else
38 		iconfig_node_set_str(node, "away_check", NULL);
39 
40 	iconfig_node_set_str(node, "ircnets", NULL);
41 	if (rec->ircnets != NULL && *rec->ircnets != NULL) {
42 		node = iconfig_node_section(node, "ircnets", NODE_TYPE_LIST);
43 		iconfig_node_add_list(node, rec->ircnets);
44 	}
45 }
46 
notifylist_remove_config(NOTIFYLIST_REC * rec)47 void notifylist_remove_config(NOTIFYLIST_REC *rec)
48 {
49 	iconfig_set_str("notifies", rec->mask, NULL);
50 }
51 
notifylist_read_config(void)52 void notifylist_read_config(void)
53 {
54 	CONFIG_NODE *node;
55 	NOTIFYLIST_REC *rec;
56 	GSList *tmp;
57 
58 	notifylist_destroy_all();
59 
60 	node = iconfig_node_traverse("notifies", FALSE);
61 	if (node == NULL) return;
62 
63 	tmp = config_node_first(node->value);
64 	for (; tmp != NULL; tmp = config_node_next(tmp)) {
65 		node = tmp->data;
66 
67 		if (node->type != NODE_TYPE_BLOCK)
68 			continue;
69 
70 		rec = g_new0(NOTIFYLIST_REC, 1);
71 		notifies = g_slist_append(notifies, rec);
72 
73 		rec->mask = g_strdup(node->key);
74 		rec->away_check = config_node_get_bool(node, "away_check", FALSE);
75 
76 		node = iconfig_node_section(node, "ircnets", -1);
77 		if (node != NULL) rec->ircnets = config_node_get_list(node);
78 	}
79 }
80