1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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.
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.
30 #ifndef __MODEST_CONF_H__
31 #define __MODEST_CONF_H__
33 #include <glib-object.h>
34 #include "modest-defs.h"
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))
46 typedef struct _ModestConf ModestConf;
47 typedef struct _ModestConfClass ModestConfClass;
49 typedef guint ModestConfNotificationId;
52 MODEST_CONF_VALUE_INT,
53 MODEST_CONF_VALUE_BOOL,
54 MODEST_CONF_VALUE_FLOAT,
55 MODEST_CONF_VALUE_STRING
56 } ModestConfValueType;
59 MODEST_CONF_EVENT_KEY_CHANGED,
60 MODEST_CONF_EVENT_KEY_UNSET
67 struct _ModestConfClass {
68 GObjectClass parent_class;
69 void (* key_changed) (ModestConf* self,
71 ModestConfEvent event,
72 ModestConfNotificationId id);
76 * modest_conf_get_type:
78 * get the #GType for #ModestConf
82 GType modest_conf_get_type (void) G_GNUC_CONST;
88 * create a new modest #ModestConf object.
90 * Returns: a new #ModestConf instance, or NULL in case
93 ModestConf* modest_conf_new (void);
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.
102 * get a string from the configuration system
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
107 gchar* modest_conf_get_string (ModestConf* self, const gchar* key, GError **err);
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.
116 * get an integer from the configuration system
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
122 gint modest_conf_get_int (ModestConf* self, const gchar* key, GError **err);
126 * modest_conf_get_bool:
127 * @self: a ModestConf instance
128 * @key: the key of the value to retrieve
129 * @err: a GError ptr, or NULL to ignore.
131 * get a boolean value from the configuration system
133 * Returns: a boolean value with the value for the key, or FALSE in case of error
134 * (of course, FALSE can also be returned in non-error cases).
135 * @err gives details in case of error
137 gboolean modest_conf_get_bool (ModestConf* self, const gchar* key, GError **err);
141 * modest_conf_get_list:
142 * @self: a ModestConf instance
143 * @key: the key of the value to retrieve
144 * @list_type: the type of the elements of the list
145 * @err: a GError ptr, or NULL to ignore.
147 * get a list of values from the configuration system
149 * Returns: a list with the values for the key, or NULL in case of error
150 * @err gives details in case of error
152 GSList* modest_conf_get_list (ModestConf* self, const gchar* key,
153 ModestConfValueType list_type, GError **err);
156 * modest_conf_set_string:
157 * @self: a ModestConf instance
158 * @key: the key of the value to set
159 * @val: the value to set
160 * @err: a GError ptr, or NULL if not interested.
162 * store a string value in the configuration system
164 * Returns: TRUE if succeeded or FALSE in case of error.
165 * @err gives details in case of error
167 gboolean modest_conf_set_string (ModestConf* self, const gchar* key, const gchar *val,
171 * modest_conf_set_int:
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.
177 * store an integer value in the configuration system
179 * Returns: TRUE if succeeded or FALSE in case of error.
180 * @err gives details in case of error
182 gboolean modest_conf_set_int (ModestConf* self, const gchar* key, int val,
186 * modest_conf_set_bool:
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.
192 * store a boolean value in the configuration system
194 * Returns: TRUE if succeeded or FALSE in case of error.
195 * @err gives details in case of error
197 gboolean modest_conf_set_bool (ModestConf* self, const gchar* key, gboolean val,
202 * modest_conf_set_list:
203 * @self: a ModestConf instance
204 * @key: the key of the value to retrieve
205 * @val: the list with the values to set
206 * @list_type: the type of the elements of the list
207 * @err: a GError ptr, or NULL to ignore.
209 * set a list of values in the configuration system
211 * Returns: TRUE if succeeded or FALSE in case of error.
212 * @err gives details in case of error
214 gboolean modest_conf_set_list (ModestConf* self, const gchar* key,
215 GSList *val, ModestConfValueType list_type,
220 * modest_conf_list_subkeys:
221 * @self: a ModestConf instance
222 * @key: the key whose subkeys will be listed
223 * @err: a GError ptr, or NULL if not interested.
225 * list all the subkeys for a given key
227 * Returns: a newly allocated list or NULL in case of error
228 * the returned GSList must be freed by the caller
229 * @err might give details in case of error
231 GSList* modest_conf_list_subkeys (ModestConf* self, const gchar* key,
236 * modest_conf_remove_key:
237 * @self: a ModestConf instance
238 * @key: the key to remove
239 * @err: a GError ptr, or NULL if not interested.
241 * attempts to remove @key and all its subkeys
243 * Returns: TRUE if succeeded or FALSE in case of error.
244 * @err might give details in case of error
246 gboolean modest_conf_remove_key (ModestConf* self, const gchar* key, GError **err);
250 * modest_conf_key_exists:
251 * @self: a ModestConf instance
252 * @key: the key to remove
253 * @err: a GError ptr, or NULL if not interested.
255 * checks if the given key exists in the configuration system
257 * Returns: TRUE if it exists, FALSE otherwise.
258 * @err gives details in case of error
260 gboolean modest_conf_key_exists (ModestConf* self, const gchar* key, GError **err);
265 * modest_conf_key_valid:
268 * check whether @str is a valid key in the config system
269 * This is a *class* function, and therefore does not require a ModestConf
272 * Returns: TRUE if it is valid, FALSE otherwise
274 gboolean modest_conf_key_is_valid (const gchar* str);
278 * modest_conf_key_escape:
279 * @str: a non-empty string to escape
281 * returns an escaped version of @str, ie. something suitable as a key
282 * This is a *class* function, and therefore does not require a ModestConf
283 * instance. Note: this for is invidual elements in a key
285 * Returns: a newly allocated string with the escaped version
287 gchar* modest_conf_key_escape (const gchar* str);
291 * modest_conf_key_escape:
292 * @str: a string to escape
294 * returns an unescaped version of @str. This is a *class* function, and
295 * therefore does not require a ModestConf instance
296 * Note: this for is invidual elements in a key
298 * Returns: a newly allocated string with the unescaped version
300 gchar* modest_conf_key_unescape (const gchar* str);
303 ModestConfNotificationId modest_conf_listen_to_namespace (ModestConf *self,
304 const gchar *namespace);
306 void modest_conf_forget_namespace (ModestConf *self,
307 const gchar *namespace,
308 ModestConfNotificationId id);
312 #endif /* __MODEST_CONF_H__ */