fdff38015e798ef3ed3e243ef9898ef180b2072d
[silc.git] / apps / irssi / src / core / settings.h
1 #ifndef __SETTINGS_H
2 #define __SETTINGS_H
3
4 enum {
5         SETTING_TYPE_STRING,
6         SETTING_TYPE_INT,
7         SETTING_TYPE_BOOLEAN
8 };
9
10 typedef struct {
11         char *module;
12         int type;
13         char *key;
14         char *section;
15         void *def;
16 } SETTINGS_REC;
17
18 /* macros for handling the default Irssi configuration */
19 #define iconfig_get_str(a, b, c) config_get_str(mainconfig, a, b, c)
20 #define iconfig_get_int(a, b, c) config_get_int(mainconfig, a, b, c)
21 #define iconfig_get_bool(a, b, c) config_get_bool(mainconfig, a, b, c)
22
23 #define iconfig_set_str(a, b, c) config_set_str(mainconfig, a, b, c)
24 #define iconfig_set_int(a, b, c) config_set_int(mainconfig, a, b, c)
25 #define iconfig_set_bool(a, b, c) config_set_bool(mainconfig, a, b, c)
26
27 #define iconfig_node_traverse(a, b) config_node_traverse(mainconfig, a, b)
28 #define iconfig_node_set_str(a, b, c) config_node_set_str(mainconfig, a, b, c)
29 #define iconfig_node_set_int(a, b, c) config_node_set_int(mainconfig, a, b, c)
30 #define iconfig_node_set_bool(a, b, c) config_node_set_bool(mainconfig, a, b, c)
31 #define iconfig_node_list_remove(a, b) config_node_list_remove(mainconfig, a, b)
32 #define iconfig_node_remove(a, b) config_node_remove(mainconfig, a, b)
33 #define iconfig_node_clear(a) config_node_clear(mainconfig, a)
34 #define iconfig_node_add_list(a, b) config_node_add_list(mainconfig, a, b)
35
36 extern CONFIG_REC *mainconfig;
37 extern const char *default_config;
38
39 /* Functions for handling the "settings" node of Irssi configuration */
40 const char *settings_get_str(const char *key);
41 int settings_get_int(const char *key);
42 int settings_get_bool(const char *key);
43
44 /* Functions to add/remove settings */
45 void settings_add_str_module(const char *module, const char *section,
46                              const char *key, const char *def);
47 void settings_add_int_module(const char *module, const char *section,
48                              const char *key, int def);
49 void settings_add_bool_module(const char *module, const char *section,
50                               const char *key, int def);
51 void settings_remove(const char *key);
52 void settings_remove_module(const char *module);
53
54 #define settings_add_str(section, key, def) \
55         settings_add_str_module(MODULE_NAME, section, key, def)
56 #define settings_add_int(section, key, def) \
57         settings_add_int_module(MODULE_NAME, section, key, def)
58 #define settings_add_bool(section, key, def) \
59         settings_add_bool_module(MODULE_NAME, section, key, def)
60
61 void settings_set_str(const char *key, const char *value);
62 void settings_set_int(const char *key, int value);
63 void settings_set_bool(const char *key, int value);
64
65 /* Get the type (SETTING_TYPE_xxx) of `key' */
66 int settings_get_type(const char *key);
67 /* Get all settings sorted by section. Free the result with g_slist_free() */
68 GSList *settings_get_sorted(void);
69 /* Get the record of the setting */
70 SETTINGS_REC *settings_get_record(const char *key);
71
72 /* verify that all settings in config file for `module' are actually found
73    from /SET list */
74 void settings_check_module(const char *module);
75 #define settings_check() settings_check_module(MODULE_NAME)
76
77 /* remove all invalid settings from config file. works only with the
78    modules that have already called settings_check() */
79 void settings_clean_invalid(void);
80
81 /* if `fname' is NULL, the default is used */
82 int settings_reread(const char *fname);
83 int settings_save(const char *fname, int autosave);
84 int irssi_config_is_changed(const char *fname);
85
86 void settings_init(void);
87 void settings_deinit(void);
88
89 #endif