Merge Irssi 0.8.16-rc1
[silc.git] / apps / irssi / src / core / settings.h
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 } SettingType;
12
13 typedef struct {
14         char *v_string;
15         int v_int;
16         unsigned int v_bool:1;
17 } SettingValue;
18
19 typedef struct {
20         int refcount;
21
22         char *module;
23         char *key;
24         char *section;
25
26         SettingType type;
27         SettingValue default_value;
28 } SETTINGS_REC;
29
30 /* macros for handling the default Irssi configuration */
31 #define iconfig_get_str(a, b, c) config_get_str(mainconfig, a, b, c)
32 #define iconfig_get_int(a, b, c) config_get_int(mainconfig, a, b, c)
33 #define iconfig_get_bool(a, b, c) config_get_bool(mainconfig, a, b, c)
34
35 #define iconfig_set_str(a, b, c) config_set_str(mainconfig, a, b, c)
36 #define iconfig_set_int(a, b, c) config_set_int(mainconfig, a, b, c)
37 #define iconfig_set_bool(a, b, c) config_set_bool(mainconfig, a, b, c)
38
39 #define iconfig_node_traverse(a, b) config_node_traverse(mainconfig, a, b)
40 #define iconfig_node_set_str(a, b, c) config_node_set_str(mainconfig, a, b, c)
41 #define iconfig_node_set_int(a, b, c) config_node_set_int(mainconfig, a, b, c)
42 #define iconfig_node_set_bool(a, b, c) config_node_set_bool(mainconfig, a, b, c)
43 #define iconfig_node_list_remove(a, b) config_node_list_remove(mainconfig, a, b)
44 #define iconfig_node_remove(a, b) config_node_remove(mainconfig, a, b)
45 #define iconfig_node_clear(a) config_node_clear(mainconfig, a)
46 #define iconfig_node_add_list(a, b) config_node_add_list(mainconfig, a, b)
47
48 extern struct _CONFIG_REC *mainconfig;
49 extern const char *default_config;
50
51 /* Functions for handling the "settings" node of Irssi configuration */
52 const char *settings_get_str(const char *key);
53 int settings_get_int(const char *key);
54 int settings_get_bool(const char *key);
55 int settings_get_time(const char *key); /* as milliseconds */
56 int settings_get_level(const char *key);
57 int settings_get_size(const char *key); /* as bytes */
58 char *settings_get_print(SETTINGS_REC *rec);
59
60 /* Functions to add/remove settings */
61 void settings_add_str_module(const char *module, const char *section,
62                              const char *key, const char *def);
63 void settings_add_int_module(const char *module, const char *section,
64                              const char *key, int def);
65 void settings_add_bool_module(const char *module, const char *section,
66                               const char *key, int def);
67 void settings_add_time_module(const char *module, const char *section,
68                               const char *key, const char *def);
69 void settings_add_level_module(const char *module, const char *section,
70                                const char *key, const char *def);
71 void settings_add_size_module(const char *module, const char *section,
72                               const char *key, const char *def);
73 void settings_remove(const char *key);
74 void settings_remove_module(const char *module);
75
76 #define settings_add_str(section, key, def) \
77         settings_add_str_module(MODULE_NAME, section, key, def)
78 #define settings_add_int(section, key, def) \
79         settings_add_int_module(MODULE_NAME, section, key, def)
80 #define settings_add_bool(section, key, def) \
81         settings_add_bool_module(MODULE_NAME, section, key, def)
82 #define settings_add_time(section, key, def) \
83         settings_add_time_module(MODULE_NAME, section, key, def)
84 #define settings_add_level(section, key, def) \
85         settings_add_level_module(MODULE_NAME, section, key, def)
86 #define settings_add_size(section, key, def) \
87         settings_add_size_module(MODULE_NAME, section, key, def)
88
89 void settings_set_str(const char *key, const char *value);
90 void settings_set_int(const char *key, int value);
91 void settings_set_bool(const char *key, int value);
92 int settings_set_time(const char *key, const char *value);
93 int settings_set_level(const char *key, const char *value);
94 int settings_set_size(const char *key, const char *value);
95
96 /* Get the type (SETTING_TYPE_xxx) of `key' */
97 SettingType settings_get_type(const char *key);
98 /* Get all settings sorted by section. Free the result with g_slist_free() */
99 GSList *settings_get_sorted(void);
100 /* Get the record of the setting */
101 SETTINGS_REC *settings_get_record(const char *key);
102
103 /* verify that all settings in config file for `module' are actually found
104    from /SET list */
105 void settings_check_module(const char *module);
106 #define settings_check() settings_check_module(MODULE_NAME)
107
108 /* remove all invalid settings from config file. works only with the
109    modules that have already called settings_check() */
110 void settings_clean_invalid(void);
111
112 /* if `fname' is NULL, the default is used */
113 int settings_reread(const char *fname);
114 int settings_save(const char *fname, int autosave);
115 int irssi_config_is_changed(const char *fname);
116
117 void settings_init(void);
118 void settings_deinit(void);
119
120 #endif