* updated test case, code cleanup, documentation fixes
[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-conf-keys.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 /* typedef enum   _ModestConfEvent   ModestConfEvent; */
49 /* typedef enum   _ModestConfValueType   ModestConfValueType; */
50
51 typedef enum _ModestConfValueType {
52         MODEST_CONF_VALUE_INT,
53         MODEST_CONF_VALUE_BOOL,
54         MODEST_CONF_VALUE_FLOAT,
55         MODEST_CONF_VALUE_STRING
56 } ModestConfValueType;
57
58 typedef enum _ModestConfEvent {
59         MODEST_CONF_EVENT_KEY_CHANGED,
60         MODEST_CONF_EVENT_KEY_UNSET
61 } ModestConfEvent;
62
63 struct _ModestConf {
64          GObject parent;
65 };
66
67 struct _ModestConfClass {
68         GObjectClass parent_class;      
69         void (* key_changed) (ModestConf* self, const gchar *key, ModestConfEvent event);
70 };
71
72 /**
73  * modest_conf_get_type:
74  * 
75  * get the GType for ModestConf
76  *  
77  * Returns: the GType
78  */
79 GType        modest_conf_get_type    (void) G_GNUC_CONST;
80
81
82 /**
83  * modest_conf_new:
84  * 
85  * create a new modest ModestConf object. 
86  * 
87  * Returns: a new ModestConf instance, or NULL in case
88  * of any error
89  */
90 ModestConf*     modest_conf_new         (void);
91
92
93 /**
94  * modest_conf_get_string:
95  * @self: a ModestConf instance
96  * @key: the key of the value to retrieve
97  * @err: a GError ptr, or NULL to ignore.
98  * 
99  * get a string from the configuration system
100  *
101  * Returns: a newly allocated string with the value for the key,
102  * or NULL in case of error. @err gives details in case of error
103  */
104 gchar*       modest_conf_get_string  (ModestConf* self, const gchar* key, GError **err);
105
106
107 /** 
108  * modest_conf_get_int:
109  * @self: a ModestConf instance
110  * @key: the key of the value to retrieve
111  * @err: a GError ptr, or NULL to ignore.
112  * 
113  * get an integer from the configuration system
114  *  
115  * Returns: an integer with the value for the key, or -1 in case of error
116  * (of course, -1 can also be returned in non-error cases).
117  * @err gives details in case of error
118  */
119 gint         modest_conf_get_int     (ModestConf* self, const gchar* key, GError **err);
120
121
122 /** 
123  * modest_conf_get_bool:
124  * @self: a ModestConf instance
125  * @key: the key of the value to retrieve
126  * @err: a GError ptr, or NULL to ignore.
127  * 
128  * get a boolean value from the configuration system
129  *  
130  * Returns: a boolean value with the value for the key, or FALSE in case of error
131  * (of course, FALSE can also be returned in non-error cases).
132  * @err gives details in case of error
133  */
134 gboolean     modest_conf_get_bool    (ModestConf* self, const gchar* key, GError **err);
135
136
137
138 /**
139  * modest_conf_get_string_or_default:
140  * @self: a ModestConf instance
141  * @key: the key of the value to retrieve
142  * @err: a GError ptr, or NULL to ignore.
143  * 
144  * get a string from the configuration system; if the value is not set,
145  * or some error occurs, return @defaultval (copied)
146  *
147  * Returns: a newly allocated string with the value for the key,
148  * or the @defaultval in case of any error
149  */
150 gchar*       modest_conf_get_string_or_default  (ModestConf* self, const gchar* key,
151                                                  const gchar *defaultval);
152
153
154 /**
155  * modest_conf_get_int_or_default:
156  * @self: a ModestConf instance
157  * @key: the key of the value to retrieve
158  * @err: a GError ptr, or NULL to ignore.
159  * 
160  * get an integer from the configuration system; if the value is not set,
161  * or some error occurs, return @defaultval.
162  * 
163  * Returns: an integer with the value for the key, or the @defaultval in case
164  * of any error
165  */
166 gint          modest_conf_get_int_or_default     (ModestConf* self, const gchar* key,
167                                                   int defaultval);
168
169
170 /**
171  * modest_conf_set_string:
172  * @self: a ModestConf instance
173  * @key: the key of the value to set
174  * @val: the value to set
175  * @err: a GError ptr, or NULL if not interested.
176  *
177  * store a string value in the configuration system
178  * 
179  * Returns: TRUE if succeeded or FALSE in case of error.
180  * @err gives details in case of error
181  */
182 gboolean     modest_conf_set_string (ModestConf* self, const gchar* key, const gchar *val,
183                                      GError **err);
184
185 /**
186  * modest_conf_set_int:
187  * @self: a ModestConf instance
188  * @key: the key of the value to set
189  * @val: the value to set
190  * @err: a GError ptr, or NULL if not interested.
191  *
192  * store an integer value in the configuration system
193  * 
194  * Returns: TRUE if succeeded or FALSE in case of error.
195  * @err gives details in case of error
196  */
197 gboolean     modest_conf_set_int    (ModestConf* self, const gchar* key, int val,
198                                      GError **err);
199
200 /**
201  * modest_conf_set_bool:
202  * @self: a ModestConf instance
203  * @key: the key of the value to set
204  * @val: the value to set
205  * @err: a GError ptr, or NULL if not interested.
206  *
207  * store a boolean value in the configuration system
208  * 
209  * Returns: TRUE if succeeded or FALSE in case of error.
210  * @err gives details in case of error
211  */
212 gboolean     modest_conf_set_bool    (ModestConf* self, const gchar* key, gboolean val,
213                                       GError **err);
214
215
216 /**
217  * modest_conf_list_subkeys:
218  * @self: a ModestConf instance
219  * @key: the key whose subkeys will be listed
220  * @err: a GError ptr, or NULL if not interested.
221  *
222  * list all the subkeys for a given key
223  * 
224  * Returns: a newly allocated list or NULL in case of error
225  * the returned GSList must be freed by the caller
226  * @err gives details in case of error
227  */
228 GSList*     modest_conf_list_subkeys    (ModestConf* self, const gchar* key,
229                                         GError **err);
230
231
232 /**
233  * modest_conf_remove_key:
234  * @self: a ModestConf instance
235  * @key: the key to remove
236  * @err: a GError ptr, or NULL if not interested.
237  *
238  * attempts to remove @key and all its subkeys
239  * 
240  * Returns: TRUE if succeeded or FALSE in case of error.
241  * @err gives details in case of error
242  */
243 gboolean   modest_conf_remove_key    (ModestConf* self, const gchar* key, GError **err);
244
245
246 /**
247  * modest_conf_key_exists:
248  * @self: a ModestConf instance
249  * @key: the key to remove
250  * @err: a GError ptr, or NULL if not interested.
251  *
252  * checks if the given key exists in the configuration system
253  * 
254  * Returns: TRUE if it exists, FALSE otherwise.
255  * @err gives details in case of error
256  */
257 gboolean   modest_conf_key_exists   (ModestConf* self, const gchar* key, GError **err);
258
259
260 /**
261  * modest_conf_key_escape:
262  * @self: a ModestConf instance. Not used, but for consistency with other ModestConf funcs
263  * @str: a string to escape
264  *
265  * returns an escaped version of @str, ie. something suitable as a key
266  * 
267  * Returns: a newly allocated string with the escaped version
268  */
269 gchar* modest_conf_key_escape (ModestConf *self, const gchar* str);
270
271
272 /**
273  * modest_conf_key_escape:
274  * @self: a ModestConf instance. Not used, but for consistency with other ModestConf funcs
275  * @str: a string to escape
276  *
277  * returns an unescaped version of @str
278  * 
279  * Returns: a newly allocated string with the unescaped version
280  */
281 gchar* modest_conf_key_unescape (ModestConf *self, const gchar* str);
282
283
284 GSList* modest_conf_get_list (ModestConf* self, const gchar* key, ModestConfValueType list_type, GError **err);
285
286 G_END_DECLS
287
288 #endif /* __MODEST_CONF_H__ */
289