1 #ifndef __SETTINGS_H
2 #define __SETTINGS_H
3 
4 typedef enum {
5 	SETTING_TYPE_STRING,
6 	SETTING_TYPE_INT,
7 	SETTING_TYPE_BOOLEAN,
8 	SETTING_TYPE_TIME,
9 	SETTING_TYPE_LEVEL,
10 	SETTING_TYPE_SIZE,
11 	SETTING_TYPE_CHOICE,
12 	SETTING_TYPE_ANY
13 } SettingType;
14 
15 typedef struct {
16 	char *v_string;
17 	int v_int;
18 	unsigned int v_bool:1;
19 } SettingValue;
20 
21 typedef struct {
22 	int refcount;
23 
24 	char *module;
25 	char *key;
26 	char *section;
27 
28 	SettingType type;
29 	SettingValue default_value;
30 	char **choices;
31 } SETTINGS_REC;
32 
33 enum {
34 	USER_SETTINGS_REAL_NAME = 0x1,
35 	USER_SETTINGS_USER_NAME = 0x2,
36 	USER_SETTINGS_NICK	= 0x4,
37 	USER_SETTINGS_HOSTNAME	= 0x8,
38 };
39 
40 /* macros for handling the default Irssi configuration */
41 #define iconfig_get_str(a, b, c) config_get_str(mainconfig, a, b, c)
42 #define iconfig_get_int(a, b, c) config_get_int(mainconfig, a, b, c)
43 #define iconfig_get_bool(a, b, c) config_get_bool(mainconfig, a, b, c)
44 
45 #define iconfig_set_str(a, b, c) config_set_str(mainconfig, a, b, c)
46 #define iconfig_set_int(a, b, c) config_set_int(mainconfig, a, b, c)
47 #define iconfig_set_bool(a, b, c) config_set_bool(mainconfig, a, b, c)
48 
49 #define iconfig_node_section(a, b, c) config_node_section(mainconfig, a, b, c)
50 #define iconfig_node_section_index(a, b, c, d) config_node_section_index(mainconfig, a, b, c, d)
51 #define iconfig_node_traverse(a, b) config_node_traverse(mainconfig, a, b)
52 #define iconfig_node_set_str(a, b, c) config_node_set_str(mainconfig, a, b, c)
53 #define iconfig_node_set_int(a, b, c) config_node_set_int(mainconfig, a, b, c)
54 #define iconfig_node_set_bool(a, b, c) config_node_set_bool(mainconfig, a, b, c)
55 #define iconfig_node_list_remove(a, b) config_node_list_remove(mainconfig, a, b)
56 #define iconfig_node_remove(a, b) config_node_remove(mainconfig, a, b)
57 #define iconfig_node_clear(a) config_node_clear(mainconfig, a)
58 #define iconfig_node_add_list(a, b) config_node_add_list(mainconfig, a, b)
59 
60 extern struct _CONFIG_REC *mainconfig;
61 extern const char *default_config;
62 
63 /* Functions for handling the "settings" node of Irssi configuration */
64 const char *settings_get_str(const char *key);
65 int settings_get_int(const char *key);
66 int settings_get_bool(const char *key);
67 int settings_get_time(const char *key); /* as milliseconds */
68 int settings_get_level(const char *key);
69 int settings_get_size(const char *key); /* as bytes */
70 int settings_get_choice(const char *key);
71 char *settings_get_print(SETTINGS_REC *rec);
72 
73 /* Functions to add/remove settings */
74 void settings_add_str_module(const char *module, const char *section,
75 			     const char *key, const char *def);
76 void settings_add_int_module(const char *module, const char *section,
77 			     const char *key, int def);
78 void settings_add_bool_module(const char *module, const char *section,
79 			      const char *key, int def);
80 void settings_add_time_module(const char *module, const char *section,
81 			      const char *key, const char *def);
82 void settings_add_level_module(const char *module, const char *section,
83 			       const char *key, const char *def);
84 void settings_add_size_module(const char *module, const char *section,
85 			      const char *key, const char *def);
86 void settings_add_choice_module(const char *module, const char *section,
87 				const char *key, int def, const char *choices);
88 void settings_remove(const char *key);
89 void settings_remove_module(const char *module);
90 
91 #define settings_add_str(section, key, def) \
92 	settings_add_str_module(MODULE_NAME, section, key, def)
93 #define settings_add_int(section, key, def) \
94 	settings_add_int_module(MODULE_NAME, section, key, def)
95 #define settings_add_bool(section, key, def) \
96 	settings_add_bool_module(MODULE_NAME, section, key, def)
97 #define settings_add_time(section, key, def) \
98 	settings_add_time_module(MODULE_NAME, section, key, def)
99 #define settings_add_level(section, key, def) \
100 	settings_add_level_module(MODULE_NAME, section, key, def)
101 #define settings_add_size(section, key, def) \
102 	settings_add_size_module(MODULE_NAME, section, key, def)
103 #define settings_add_choice(section, key, def, choices) \
104 	settings_add_choice_module(MODULE_NAME, section, key, def, choices)
105 
106 void settings_set_str(const char *key, const char *value);
107 void settings_set_int(const char *key, int value);
108 void settings_set_bool(const char *key, int value);
109 gboolean settings_set_time(const char *key, const char *value);
110 gboolean settings_set_level(const char *key, const char *value);
111 gboolean settings_set_size(const char *key, const char *value);
112 gboolean settings_set_choice(const char *key, const char *value);
113 
114 /* Get the type (SETTING_TYPE_xxx) of `key' */
115 SettingType settings_get_type(const char *key);
116 /* Get all settings sorted by section. Free the result with g_slist_free() */
117 GSList *settings_get_sorted(void);
118 /* Get the record of the setting */
119 SETTINGS_REC *settings_get_record(const char *key);
120 
121 /* verify that all settings in config file for `module' are actually found
122    from /SET list */
123 void settings_check_module(const char *module);
124 #define settings_check() settings_check_module(MODULE_NAME)
125 
126 /* remove all invalid settings from config file. works only with the
127    modules that have already called settings_check() */
128 void settings_clean_invalid(void);
129 
130 /* if `fname' is NULL, the default is used */
131 int settings_reread(const char *fname);
132 int settings_save(const char *fname, int autosave);
133 int irssi_config_is_changed(const char *fname);
134 
135 void settings_init(void);
136 void settings_deinit(void);
137 
138 #endif
139