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-conf-keys.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;
48 /* typedef enum _ModestConfEvent ModestConfEvent; */
49 /* typedef enum _ModestConfValueType ModestConfValueType; */
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;
58 typedef enum _ModestConfEvent {
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, const gchar *key, ModestConfEvent event);
73 * modest_conf_get_type:
75 * get the GType for ModestConf
79 GType modest_conf_get_type (void) G_GNUC_CONST;
85 * create a new modest ModestConf object.
87 * Returns: a new ModestConf instance, or NULL in case
90 ModestConf* modest_conf_new (void);
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.
99 * get a string from the configuration system
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
104 gchar* modest_conf_get_string (ModestConf* self, const gchar* key, GError **err);
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.
113 * get an integer from the configuration system
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
119 gint modest_conf_get_int (ModestConf* self, const gchar* key, GError **err);
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.
128 * get a boolean value from the configuration system
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
134 gboolean modest_conf_get_bool (ModestConf* self, const gchar* key, GError **err);
138 * modest_conf_get_list:
139 * @self: a ModestConf instance
140 * @key: the key of the value to retrieve
141 * @list_type: the type of the elements of the list
142 * @err: a GError ptr, or NULL to ignore.
144 * get a list of values from the configuration system
146 * Returns: a list with the values for the key, or NULL in case of error
147 * @err gives details in case of error
149 GSList * modest_conf_get_list (ModestConf* self, const gchar* key,
150 ModestConfValueType list_type, GError **err);
153 * modest_conf_set_string:
154 * @self: a ModestConf instance
155 * @key: the key of the value to set
156 * @val: the value to set
157 * @err: a GError ptr, or NULL if not interested.
159 * store a string value in the configuration system
161 * Returns: TRUE if succeeded or FALSE in case of error.
162 * @err gives details in case of error
164 gboolean modest_conf_set_string (ModestConf* self, const gchar* key, const gchar *val,
168 * modest_conf_set_int:
169 * @self: a ModestConf instance
170 * @key: the key of the value to set
171 * @val: the value to set
172 * @err: a GError ptr, or NULL if not interested.
174 * store an integer value in the configuration system
176 * Returns: TRUE if succeeded or FALSE in case of error.
177 * @err gives details in case of error
179 gboolean modest_conf_set_int (ModestConf* self, const gchar* key, int val,
183 * modest_conf_set_bool:
184 * @self: a ModestConf instance
185 * @key: the key of the value to set
186 * @val: the value to set
187 * @err: a GError ptr, or NULL if not interested.
189 * store a boolean value in the configuration system
191 * Returns: TRUE if succeeded or FALSE in case of error.
192 * @err gives details in case of error
194 gboolean modest_conf_set_bool (ModestConf* self, const gchar* key, gboolean val,
199 * modest_conf_get_list:
200 * @self: a ModestConf instance
201 * @key: the key of the value to retrieve
202 * @list_type: the type of the elements of the list
203 * @err: a GError ptr, or NULL to ignore.
205 * get a list of values from the configuration system
207 * Returns: a list with the values for the key, or NULL in case of error or
208 * if the list is empty; @err gives details in case of error
210 GSList * modest_conf_get_list (ModestConf* self, const gchar* key,
211 ModestConfValueType list_type, GError **err);
215 * modest_conf_list_subkeys:
216 * @self: a ModestConf instance
217 * @key: the key whose subkeys will be listed
218 * @err: a GError ptr, or NULL if not interested.
220 * list all the subkeys for a given key
222 * Returns: a newly allocated list or NULL in case of error
223 * the returned GSList must be freed by the caller
224 * @err might give details in case of error
226 GSList* modest_conf_list_subkeys (ModestConf* self, const gchar* key,
231 * modest_conf_remove_key:
232 * @self: a ModestConf instance
233 * @key: the key to remove
234 * @err: a GError ptr, or NULL if not interested.
236 * attempts to remove @key and all its subkeys
238 * Returns: TRUE if succeeded or FALSE in case of error.
239 * @err might give details in case of error
241 gboolean modest_conf_remove_key (ModestConf* self, const gchar* key, GError **err);
245 * modest_conf_key_exists:
246 * @self: a ModestConf instance
247 * @key: the key to remove
248 * @err: a GError ptr, or NULL if not interested.
250 * checks if the given key exists in the configuration system
252 * Returns: TRUE if it exists, FALSE otherwise.
253 * @err gives details in case of error
255 gboolean modest_conf_key_exists (ModestConf* self, const gchar* key, GError **err);
259 * modest_conf_key_escape:
260 * @str: a string to escape
262 * returns an escaped version of @str, ie. something suitable as a key
263 * This is a *class* function, and therefore does not require a ModestConf
266 * Returns: a newly allocated string with the escaped version
268 gchar* modest_conf_key_escape (const gchar* str);
272 * modest_conf_key_escape:
273 * @str: a string to escape
275 * returns an unescaped version of @str. This is a *class* function, and
276 * therefore does not require a ModestConf instance
278 * Returns: a newly allocated string with the unescaped version
280 gchar* modest_conf_key_unescape (const gchar* str);
285 #endif /* __MODEST_CONF_H__ */