af1fa2cf2a9e7e736f6c80410f348cdb0e4a9b6f
[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
31 /* modest-conf.h */
32
33 #ifndef __MODEST_CONF_H__
34 #define __MODEST_CONF_H__
35
36 #include <glib-object.h>
37 #include "modest-conf-keys.h"
38
39 G_BEGIN_DECLS
40
41 /* convenience macros */
42 #define MODEST_TYPE_CONF             (modest_conf_get_type())
43 #define MODEST_CONF(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj),MODEST_TYPE_CONF,ModestConf))
44 #define MODEST_CONF_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass),MODEST_TYPE_CONF,GObject))
45 #define MODEST_IS_CONF(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj),MODEST_TYPE_CONF))
46 #define MODEST_IS_CONF_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass),MODEST_TYPE_CONF))
47 #define MODEST_CONF_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj),MODEST_TYPE_CONF,ModestConfClass))
48
49 typedef struct _ModestConf      ModestConf;
50 typedef struct _ModestConfClass ModestConfClass;
51
52 struct _ModestConf {
53          GObject parent;
54 };
55
56 struct _ModestConfClass {
57         GObjectClass parent_class;
58         
59         void (* key_changed) (ModestConf* self, const gchar *key, const gchar *new_value);
60 };
61
62
63 /**
64  * modest_conf_get_type:
65  * 
66  * get the GType for ModestConf
67  *  
68  * Returns: the GType
69  */
70 GType        modest_conf_get_type    (void) G_GNUC_CONST;
71
72
73 /**
74  * modest_conf_new:
75  * 
76  * create a new modest ModestConf object. 
77  * 
78  * Returns: a new ModestConf instance, or NULL in case
79  * of any error
80  */
81 GObject*     modest_conf_new         (void);
82
83
84 /**
85  * modest_conf_get_string:
86  * @self: a ModestConf instance
87  * @key: the key of the value to retrieve
88  * @err: a GError ptr, or NULL to ignore.
89  * 
90  * get a string from the configuration system
91  *
92  * Returns: a newly allocated string with the value for the key,
93  * or NULL in case of error. @err gives details in case of error
94  */
95 gchar*       modest_conf_get_string  (ModestConf* self, const gchar* key, GError **err);
96
97
98 /** 
99  * modest_conf_get_int:
100  * @self: a ModestConf instance
101  * @key: the key of the value to retrieve
102  * @err: a GError ptr, or NULL to ignore.
103  * 
104  * get an integer from the configuration system
105  *  
106  * Returns: an integer with the value for the key, or -1 in case of error
107  * (of course, -1 can also be returned in non-error cases).
108  * @err gives details in case of error
109  */
110 int          modest_conf_get_int     (ModestConf* self, const gchar* key, GError **err);
111
112
113 /** 
114  * modest_conf_get_bool:
115  * @self: a ModestConf instance
116  * @key: the key of the value to retrieve
117  * @err: a GError ptr, or NULL to ignore.
118  * 
119  * get a boolean value from the configuration system
120  *  
121  * Returns: a boolean value with the value for the key, or -1 in case of error
122  * (of course, -1 can also be returned in non-error cases).
123  * @err gives details in case of error
124  */
125 gboolean     modest_conf_get_bool    (ModestConf* self, const gchar* key, GError **err);
126
127
128 /**
129  * modest_conf_set_string:
130  * @self: a ModestConf instance
131  * @key: the key of the value to set
132  * @val: the value to set
133  * @err: a GError ptr, or NULL if not interested.
134  *
135  * store a string value in the configuration system
136  * 
137  * Returns: TRUE if succeeded or FALSE in case of error.
138  * @err gives details in case of error
139  */
140 gboolean     modest_conf_set_string (ModestConf* self, const gchar* key, const gchar *val,
141                                      GError **err);
142
143 /**
144  * modest_conf_set_int:
145  * @self: a ModestConf instance
146  * @key: the key of the value to set
147  * @val: the value to set
148  * @err: a GError ptr, or NULL if not interested.
149  *
150  * store an integer value in the configuration system
151  * 
152  * Returns: TRUE if succeeded or FALSE in case of error.
153  * @err gives details in case of error
154  */
155 gboolean     modest_conf_set_int    (ModestConf* self, const gchar* key, int val,
156                                      GError **err);
157
158 /**
159  * modest_conf_set_bool:
160  * @self: a ModestConf instance
161  * @key: the key of the value to set
162  * @val: the value to set
163  * @err: a GError ptr, or NULL if not interested.
164  *
165  * store a boolean value in the configuration system
166  * 
167  * Returns: TRUE if succeeded or FALSE in case of error.
168  * @err gives details in case of error
169  */
170 gboolean     modest_conf_set_bool    (ModestConf* self, const gchar* key, gboolean val,
171                                       GError **err);
172
173
174 /**
175  * modest_conf_list_subkeys:
176  * @self: a ModestConf instance
177  * @key: the key whose subkeys will be listed
178  * @err: a GError ptr, or NULL if not interested.
179  *
180  * list all the subkeys for a given key
181  * 
182  * Returns: a newly allocated list or NULL in case of error
183  * the returned GSList must be freed by the caller
184  * @err gives details in case of error
185  */
186 GSList*     modest_conf_list_subkeys    (ModestConf* self, const gchar* key,
187                                         GError **err);
188
189
190 /**
191  * modest_conf_remove_key:
192  * @self: a ModestConf instance
193  * @key: the key to remove
194  * @err: a GError ptr, or NULL if not interested.
195  *
196  * attempts to remove @key and all its subkeys
197  * 
198  * Returns: TRUE if succeeded or FALSE in case of error.
199  * @err gives details in case of error
200  */
201 gboolean   modest_conf_remove_key    (ModestConf* self, const gchar* key, GError **err);
202
203
204 /**
205  * modest_conf_key_exists:
206  * @self: a ModestConf instance
207  * @key: the key to remove
208  * @err: a GError ptr, or NULL if not interested.
209  *
210  * checks if the given key exists in the configuration system
211  * 
212  * Returns: TRUE if it exists, FALSE otherwise.
213  * @err gives details in case of error
214  */
215 gboolean   modest_conf_key_exists   (ModestConf* self, const gchar* key, GError **err);
216
217
218 G_END_DECLS
219
220 #endif /* __MODEST_CONF_H__ */
221