* Fixes NB#86562, grab the keyboard focus for the new accounts wizard when no accoun...
[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 guint ModestConfNotificationId; 
50
51 typedef enum {
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 {
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, 
70                               const gchar *key, 
71                               ModestConfEvent event,
72                               ModestConfNotificationId id);
73 };
74
75 /**
76  * modest_conf_get_type:
77  * 
78  * get the #GType for #ModestConf
79  *  
80  * Returns: the #GType
81  */
82 GType        modest_conf_get_type    (void) G_GNUC_CONST;
83
84
85 /**
86  * modest_conf_new:
87  * 
88  * create a new modest #ModestConf object. 
89  * 
90  * Returns: a new #ModestConf instance, or NULL in case
91  * of any error
92  */
93 ModestConf*     modest_conf_new         (void);
94
95
96 /**
97  * modest_conf_get_string:
98  * @self: a ModestConf instance
99  * @key: the key of the value to retrieve
100  * @err: a GError ptr, or NULL to ignore.
101  * 
102  * get a string from the configuration system
103  *
104  * Returns: a newly allocated string with the value for the key,
105  * or NULL in case of error. @err gives details in case of error
106  */
107 gchar*       modest_conf_get_string  (ModestConf* self, const gchar* key, GError **err);
108
109
110 /** 
111  * modest_conf_get_int:
112  * @self: a ModestConf instance
113  * @key: the key of the value to retrieve
114  * @err: a GError ptr, or NULL to ignore.
115  * 
116  * get an integer from the configuration system
117  *  
118  * Returns: an integer with the value for the key, or -1 in case of error
119  * (of course, -1 can also be returned in non-error cases).
120  * @err gives details in case of error
121  */
122 gint         modest_conf_get_int     (ModestConf* self, const gchar* key, GError **err);
123
124 /** 
125  * modest_conf_get_float:
126  * @self: a ModestConf instance
127  * @key: the key of the value to retrieve
128  * @err: a GError ptr, or NULL to ignore.
129  * 
130  * get an integer from the configuration system
131  *  
132  * Returns: an double with the value for the key, or -1 in case of
133  * error (of course, -1 can also be returned in non-error cases).
134  * @err gives details in case of error
135  */
136 gdouble      modest_conf_get_float   (ModestConf* self, const gchar* key, GError **err);
137
138 /** 
139  * modest_conf_get_bool:
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 boolean value from the configuration system
145  *  
146  * Returns: a boolean value with the value for the key, or FALSE in case of error
147  * (of course, FALSE can also be returned in non-error cases).
148  * @err gives details in case of error
149  */
150 gboolean     modest_conf_get_bool    (ModestConf* self, const gchar* key, GError **err);
151
152
153 /** 
154  * modest_conf_get_list:
155  * @self: a ModestConf instance
156  * @key: the key of the value to retrieve
157  * @list_type: the type of the elements of the list
158  * @err: a GError ptr, or NULL to ignore.
159  * 
160  * get a list of values from the configuration system
161  *  
162  * Returns: a list with the values for the key, or NULL in case of error
163  * @err gives details in case of error
164  */
165 GSList*     modest_conf_get_list    (ModestConf* self, const gchar* key, 
166                                       ModestConfValueType list_type, GError **err);
167
168 /**
169  * modest_conf_set_string:
170  * @self: a ModestConf instance
171  * @key: the key of the value to set
172  * @val: the value to set
173  * @err: a GError ptr, or NULL if not interested.
174  *
175  * store a string value in the configuration system
176  * 
177  * Returns: TRUE if succeeded or FALSE in case of error.
178  * @err gives details in case of error
179  */
180 gboolean     modest_conf_set_string (ModestConf* self, const gchar* key, const gchar *val,
181                                      GError **err);
182
183 /**
184  * modest_conf_set_int:
185  * @self: a ModestConf instance
186  * @key: the key of the value to set
187  * @val: the value to set
188  * @err: a GError ptr, or NULL if not interested.
189  *
190  * store an integer value in the configuration system
191  * 
192  * Returns: TRUE if succeeded or FALSE in case of error.
193  * @err gives details in case of error
194  */
195 gboolean     modest_conf_set_int    (ModestConf* self, const gchar* key, int val,
196                                      GError **err);
197
198 /**
199  * modest_conf_set_float:
200  * @self: a ModestConf instance
201  * @key: the key of the value to set
202  * @val: the value to set
203  * @err: a GError ptr, or NULL if not interested.
204  *
205  * store an integer value in the configuration system
206  * 
207  * Returns: TRUE if succeeded or FALSE in case of error.
208  * @err gives details in case of error
209  */
210 gboolean     modest_conf_set_float  (ModestConf* self, 
211                                      const gchar* key, 
212                                      gdouble val,
213                                      GError **err);
214
215 /**
216  * modest_conf_set_bool:
217  * @self: a ModestConf instance
218  * @key: the key of the value to set
219  * @val: the value to set
220  * @err: a GError ptr, or NULL if not interested.
221  *
222  * store a boolean value in the configuration system
223  * 
224  * Returns: TRUE if succeeded or FALSE in case of error.
225  * @err gives details in case of error
226  */
227 gboolean     modest_conf_set_bool    (ModestConf* self, const gchar* key, gboolean val,
228                                       GError **err);
229
230
231 /** 
232  * modest_conf_set_list:
233  * @self: a ModestConf instance
234  * @key: the key of the value to retrieve
235  * @val: the list with the values to set
236  * @list_type: the type of the elements of the list
237  * @err: a GError ptr, or NULL to ignore.
238  * 
239  * set a list of values in the configuration system
240  *
241  * Returns: TRUE if succeeded or FALSE in case of error.
242  * @err gives details in case of error
243  */
244 gboolean     modest_conf_set_list    (ModestConf* self, const gchar* key, 
245                                       GSList *val, ModestConfValueType list_type, 
246                                       GError **err);
247
248
249 /**
250  * modest_conf_list_subkeys:
251  * @self: a ModestConf instance
252  * @key: the key whose subkeys will be listed
253  * @err: a GError ptr, or NULL if not interested.
254  *
255  * list all the subkeys for a given key
256  * 
257  * Returns: a newly allocated list or NULL in case of error
258  * the returned GSList must be freed by the caller
259  * @err might give details in case of error
260  */
261 GSList*     modest_conf_list_subkeys    (ModestConf* self, const gchar* key,
262                                         GError **err);
263
264
265 /**
266  * modest_conf_remove_key:
267  * @self: a ModestConf instance
268  * @key: the key to remove
269  * @err: a GError ptr, or NULL if not interested.
270  *
271  * attempts to remove @key and all its subkeys
272  * 
273  * Returns: TRUE if succeeded or FALSE in case of error.
274  * @err might give details in case of error
275  */
276 gboolean   modest_conf_remove_key    (ModestConf* self, const gchar* key, GError **err);
277
278
279 /**
280  * modest_conf_key_exists:
281  * @self: a ModestConf instance
282  * @key: the key to remove
283  * @err: a GError ptr, or NULL if not interested.
284  *
285  * checks if the given key exists in the configuration system
286  * 
287  * Returns: TRUE if it exists, FALSE otherwise.
288  * @err gives details in case of error
289  */
290 gboolean   modest_conf_key_exists   (ModestConf* self, const gchar* key, GError **err);
291
292
293
294 /**
295  * modest_conf_key_valid:
296  * @str: some key
297  *
298  * check whether @str is a valid key in the config system
299  * This is a *class* function, and therefore does not require a ModestConf
300  * instance
301  * 
302  * Returns: TRUE if it is valid, FALSE otherwise
303  */
304 gboolean modest_conf_key_is_valid (const gchar* str);
305
306
307 /**
308  * modest_conf_key_escape:
309  * @str: a non-empty string to escape
310  *
311  * returns an escaped version of @str, ie. something suitable as a key
312  * This is a *class* function, and therefore does not require a ModestConf
313  * instance. Note: this for is invidual elements in a key
314  * 
315  * Returns: a newly allocated string with the escaped version
316  */
317 gchar* modest_conf_key_escape (const gchar* str);
318
319
320 /**
321  * modest_conf_key_escape:
322  * @str: a string to escape
323  *
324  * returns an unescaped version of @str. This is a *class* function, and
325  * therefore does not require a ModestConf instance
326  * Note: this for is invidual elements in a key
327  * 
328  * Returns: a newly allocated string with the unescaped version
329  */
330 gchar* modest_conf_key_unescape (const gchar* str);
331
332
333 void modest_conf_listen_to_namespace (ModestConf *self,
334                                       const gchar *namespace);
335
336 void modest_conf_forget_namespace    (ModestConf *self,
337                                       const gchar *namespace);
338 G_END_DECLS
339
340 #endif /* __MODEST_CONF_H__ */
341