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