Add support for monitors "All" to span panel over all monitors.
[lxde/lxpanel.git] / src / conf.h
1 /*
2 * Copyright (c) 2014 LxDE Developers, see the file AUTHORS for details.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19 /* This is a config file parser with API similar to one used by libconfig
20 for convenience but contents of the file is the own config format
21 therefore it is much more restricted than libconfig is.
22 Strings cannot be numeric and are not quoted (similarly to INI file format).
23 Groups cannot be inside other group but only inside an anonymous list.
24 That anonymous list is the only list type which is supported and there
25 can be only one anonymous member in any group. */
26
27 #ifndef __CONF_H__
28 #define __CONF_H__ 1
29
30 #include <glib.h>
31 #include <stdio.h>
32
33 G_BEGIN_DECLS
34
35 typedef struct _config_setting_t config_setting_t;
36 typedef struct _PanelConf PanelConf;
37
38 typedef enum
39 {
40 PANEL_CONF_TYPE_GROUP,
41 PANEL_CONF_TYPE_INT,
42 PANEL_CONF_TYPE_STRING,
43 PANEL_CONF_TYPE_LIST
44 } PanelConfType;
45
46 typedef void (*PanelConfSaveHook)(const config_setting_t * setting, FILE * f, gpointer user_data);
47
48 PanelConf *config_new(void);
49 void config_destroy(PanelConf * config);
50 gboolean config_read_file(PanelConf * config, const char * filename);
51 gboolean config_write_file(PanelConf * config, const char * filename);
52 char * config_setting_to_string(const config_setting_t * setting);
53
54 config_setting_t * config_root_setting(const PanelConf * config);
55 config_setting_t * config_setting_get_member(const config_setting_t * setting, const char * name);
56 config_setting_t * config_setting_get_elem(const config_setting_t * setting, unsigned int index);
57 const char * config_setting_get_name(const config_setting_t * setting);
58 config_setting_t * config_setting_get_parent(const config_setting_t * setting);
59
60 int config_setting_get_int(const config_setting_t * setting);
61 const char * config_setting_get_string(const config_setting_t * setting);
62
63 gboolean config_setting_lookup_int(const config_setting_t * setting,
64 const char * name, int * value);
65 gboolean config_setting_lookup_string(const config_setting_t * setting,
66 const char * name, const char ** value);
67
68 config_setting_t * config_setting_add(config_setting_t * parent, const char * name, PanelConfType type);
69
70 gboolean config_setting_move_member(config_setting_t * setting, config_setting_t * parent, const char * name);
71 gboolean config_setting_move_elem(config_setting_t * setting, config_setting_t * parent, int index);
72
73 gboolean config_setting_set_int(config_setting_t * setting, int value);
74 gboolean config_setting_set_string(config_setting_t * setting, const char * value);
75 gboolean config_setting_remove(config_setting_t * parent, const char * name);
76 gboolean config_setting_remove_elem(config_setting_t * parent, unsigned int index);
77 gboolean config_setting_destroy(config_setting_t * setting);
78
79 #define config_group_set_int(_group,_name,_value) \
80 config_setting_set_int(config_setting_add(_group, _name, \
81 PANEL_CONF_TYPE_INT), \
82 _value)
83 #define config_group_set_string(_group,_name,_value) \
84 config_setting_set_string(config_setting_add(_group, _name, \
85 PANEL_CONF_TYPE_STRING), \
86 _value)
87 #define config_group_add_subgroup(_group,_name) \
88 config_setting_add(config_setting_add(_group, "", PANEL_CONF_TYPE_LIST), \
89 _name, PANEL_CONF_TYPE_GROUP)
90
91 PanelConfType config_setting_type(const config_setting_t * setting);
92 #define config_setting_is_group(_s) config_setting_type(_s) == PANEL_CONF_TYPE_GROUP
93 #define config_setting_is_list(_s) config_setting_type(_s) == PANEL_CONF_TYPE_LIST
94 #define config_setting_is_scalar(_s) \
95 (config_setting_type(_s) == PANEL_CONF_TYPE_INT || \
96 config_setting_type(_s) == PANEL_CONF_TYPE_STRING)
97
98 void config_setting_set_save_hook(config_setting_t * setting, PanelConfSaveHook hook, gpointer user_data);
99
100 G_END_DECLS
101
102 #endif /* __CONF_H__ */