6581609393f4f047f0f1469ba374fc5f47f7a415
[modest] / src / modest-conf.h
1 /* Copyright (c) 2006, Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  *   notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  *   notice, this list of conditions and the following disclaimer in the
12  *   documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Nokia Corporation nor the names of its
14  *   contributors may be used to endorse or promote products derived from
15  *   this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29
30 #ifndef __MODEST_CONF_H__
31 #define __MODEST_CONF_H__
32
33 #include <glib-object.h>
34 #include "modest-defs.h"
35
36 G_BEGIN_DECLS
37
38 /* convenience macros */
39 #define MODEST_TYPE_CONF             (modest_conf_get_type())
40 #define MODEST_CONF(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj),MODEST_TYPE_CONF,ModestConf))
41 #define MODEST_CONF_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass),MODEST_TYPE_CONF,GObject))
42 #define MODEST_IS_CONF(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj),MODEST_TYPE_CONF))
43 #define MODEST_IS_CONF_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass),MODEST_TYPE_CONF))
44 #define MODEST_CONF_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj),MODEST_TYPE_CONF,ModestConfClass))
45
46 typedef struct _ModestConf        ModestConf;
47 typedef struct _ModestConfClass   ModestConfClass;
48
49 typedef enum {
50         MODEST_CONF_VALUE_INT,
51         MODEST_CONF_VALUE_BOOL,
52         MODEST_CONF_VALUE_FLOAT,
53         MODEST_CONF_VALUE_STRING
54 } ModestConfValueType;
55
56 typedef enum {
57         MODEST_CONF_EVENT_KEY_CHANGED,
58         MODEST_CONF_EVENT_KEY_UNSET
59 } ModestConfEvent;
60
61 struct _ModestConf {
62          GObject parent;
63 };
64
65 struct _ModestConfClass {
66         GObjectClass parent_class;      
67         void (* key_changed) (ModestConf* self, const gchar *key, ModestConfEvent event);
68 };
69
70 /**
71  * modest_conf_get_type:
72  * 
73  * get the GType for ModestConf
74  *  
75  * Returns: the GType
76  */
77 GType        modest_conf_get_type    (void) G_GNUC_CONST;
78
79
80 /**
81  * modest_conf_new:
82  * 
83  * create a new modest ModestConf object. 
84  * 
85  * Returns: a new ModestConf instance, or NULL in case
86  * of any error
87  */
88 ModestConf*     modest_conf_new         (void);
89
90
91 /**
92  * modest_conf_get_string:
93  * @self: a ModestConf instance
94  * @key: the key of the value to retrieve
95  * @err: a GError ptr, or NULL to ignore.
96  * 
97  * get a string from the configuration system
98  *
99  * Returns: a newly allocated string with the value for the key,
100  * or NULL in case of error. @err gives details in case of error
101  */
102 gchar*       modest_conf_get_string  (ModestConf* self, const gchar* key, GError **err);
103
104
105 /** 
106  * modest_conf_get_int:
107  * @self: a ModestConf instance
108  * @key: the key of the value to retrieve
109  * @err: a GError ptr, or NULL to ignore.
110  * 
111  * get an integer from the configuration system
112  *  
113  * Returns: an integer with the value for the key, or -1 in case of error
114  * (of course, -1 can also be returned in non-error cases).
115  * @err gives details in case of error
116  */
117 gint         modest_conf_get_int     (ModestConf* self, const gchar* key, GError **err);
118
119
120 /** 
121  * modest_conf_get_bool:
122  * @self: a ModestConf instance
123  * @key: the key of the value to retrieve
124  * @err: a GError ptr, or NULL to ignore.
125  * 
126  * get a boolean value from the configuration system
127  *  
128  * Returns: a boolean value with the value for the key, or FALSE in case of error
129  * (of course, FALSE can also be returned in non-error cases).
130  * @err gives details in case of error
131  */
132 gboolean     modest_conf_get_bool    (ModestConf* self, const gchar* key, GError **err);
133
134
135 /** 
136  * modest_conf_get_list:
137  * @self: a ModestConf instance
138  * @key: the key of the value to retrieve
139  * @list_type: the type of the elements of the list
140  * @err: a GError ptr, or NULL to ignore.
141  * 
142  * get a list of values from the configuration system
143  *  
144  * Returns: a list with the values for the key, or NULL in case of error
145  * @err gives details in case of error
146  */
147 GSList *     modest_conf_get_list    (ModestConf* self, const gchar* key, 
148                                       ModestConfValueType list_type, GError **err);
149
150 /**
151  * modest_conf_set_string:
152  * @self: a ModestConf instance
153  * @key: the key of the value to set
154  * @val: the value to set
155  * @err: a GError ptr, or NULL if not interested.
156  *
157  * store a string value in the configuration system
158  * 
159  * Returns: TRUE if succeeded or FALSE in case of error.
160  * @err gives details in case of error
161  */
162 gboolean     modest_conf_set_string (ModestConf* self, const gchar* key, const gchar *val,
163                                      GError **err);
164
165 /**
166  * modest_conf_set_int:
167  * @self: a ModestConf instance
168  * @key: the key of the value to set
169  * @val: the value to set
170  * @err: a GError ptr, or NULL if not interested.
171  *
172  * store an integer value in the configuration system
173  * 
174  * Returns: TRUE if succeeded or FALSE in case of error.
175  * @err gives details in case of error
176  */
177 gboolean     modest_conf_set_int    (ModestConf* self, const gchar* key, int val,
178                                      GError **err);
179
180 /**
181  * modest_conf_set_bool:
182  * @self: a ModestConf instance
183  * @key: the key of the value to set
184  * @val: the value to set
185  * @err: a GError ptr, or NULL if not interested.
186  *
187  * store a boolean value in the configuration system
188  * 
189  * Returns: TRUE if succeeded or FALSE in case of error.
190  * @err gives details in case of error
191  */
192 gboolean     modest_conf_set_bool    (ModestConf* self, const gchar* key, gboolean val,
193                                       GError **err);
194
195
196 /** 
197  * modest_conf_set_list:
198  * @self: a ModestConf instance
199  * @key: the key of the value to retrieve
200  * @val: the list with the values to set
201  * @list_type: the type of the elements of the list
202  * @err: a GError ptr, or NULL to ignore.
203  * 
204  * set a list of values in the configuration system
205  * @err gives details in case of error
206  */
207 void         modest_conf_set_list    (ModestConf* self, const gchar* key, 
208                                       GSList *val, ModestConfValueType list_type, 
209                                       GError **err);
210
211
212 /**
213  * modest_conf_list_subkeys:
214  * @self: a ModestConf instance
215  * @key: the key whose subkeys will be listed
216  * @err: a GError ptr, or NULL if not interested.
217  *
218  * list all the subkeys for a given key
219  * 
220  * Returns: a newly allocated list or NULL in case of error
221  * the returned GSList must be freed by the caller
222  * @err might give details in case of error
223  */
224 GSList*     modest_conf_list_subkeys    (ModestConf* self, const gchar* key,
225                                         GError **err);
226
227
228 /**
229  * modest_conf_remove_key:
230  * @self: a ModestConf instance
231  * @key: the key to remove
232  * @err: a GError ptr, or NULL if not interested.
233  *
234  * attempts to remove @key and all its subkeys
235  * 
236  * Returns: TRUE if succeeded or FALSE in case of error.
237  * @err might give details in case of error
238  */
239 gboolean   modest_conf_remove_key    (ModestConf* self, const gchar* key, GError **err);
240
241
242 /**
243  * modest_conf_key_exists:
244  * @self: a ModestConf instance
245  * @key: the key to remove
246  * @err: a GError ptr, or NULL if not interested.
247  *
248  * checks if the given key exists in the configuration system
249  * 
250  * Returns: TRUE if it exists, FALSE otherwise.
251  * @err gives details in case of error
252  */
253 gboolean   modest_conf_key_exists   (ModestConf* self, const gchar* key, GError **err);
254
255
256
257 /**
258  * modest_conf_key_valid:
259  * @str: some key
260  *
261  * check whether @str is a valid key in the config system
262  * This is a *class* function, and therefore does not require a ModestConf
263  * instance
264  * 
265  * Returns: TRUE if it is valid, FALSE otherwise
266  */
267 gboolean modest_conf_key_is_valid (const gchar* str);
268
269
270 /**
271  * modest_conf_key_escape:
272  * @str: a string to escape
273  *
274  * returns an escaped version of @str, ie. something suitable as a key
275  * This is a *class* function, and therefore does not require a ModestConf
276  * instance. Note: this for is invidual elements in a key
277  * 
278  * Returns: a newly allocated string with the escaped version
279  */
280 gchar* modest_conf_key_escape (const gchar* str);
281
282
283 /**
284  * modest_conf_key_escape:
285  * @str: a string to escape
286  *
287  * returns an unescaped version of @str. This is a *class* function, and
288  * therefore does not require a ModestConf instance
289  * Note: this for is invidual elements in a key
290  * 
291  * Returns: a newly allocated string with the unescaped version
292  */
293 gchar* modest_conf_key_unescape (const gchar* str);
294
295
296 G_END_DECLS
297
298 #endif /* __MODEST_CONF_H__ */
299