* modest-account-mgr*.[ch]:
[modest] / src / modest-account-mgr.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 #ifndef __MODEST_ACCOUNT_MGR_H__
32 #define __MODEST_ACCOUNT_MGR_H__
33
34 #include <glib-object.h>
35 #include <modest-conf.h>
36 #include <modest-defs.h>
37 #include <modest-protocol-info.h>
38
39 G_BEGIN_DECLS
40
41 /* convenience macros */
42 #define MODEST_TYPE_ACCOUNT_MGR             (modest_account_mgr_get_type())
43 #define MODEST_ACCOUNT_MGR(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj),MODEST_TYPE_ACCOUNT_MGR,ModestAccountMgr))
44 #define MODEST_ACCOUNT_MGR_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass),MODEST_TYPE_ACCOUNT_MGR,ModestAccountMgrClass))
45 #define MODEST_IS_ACCOUNT_MGR(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj),MODEST_TYPE_ACCOUNT_MGR))
46 #define MODEST_IS_ACCOUNT_MGR_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass),MODEST_TYPE_ACCOUNT_MGR))
47 #define MODEST_ACCOUNT_MGR_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj),MODEST_TYPE_ACCOUNT_MGR,ModestAccountMgrClass))
48
49 typedef struct _ModestAccountMgr      ModestAccountMgr;
50 typedef struct _ModestAccountMgrClass ModestAccountMgrClass;
51
52
53 struct _ModestAccountMgr {
54          GObject parent;
55 };
56
57 struct _ModestAccountMgrClass {
58         GObjectClass parent_class;
59
60         void (* account_removed)   (ModestAccountMgr *obj, const gchar* account,
61                                     gboolean server_account, gpointer user_data);
62         void (* account_changed)   (ModestAccountMgr *obj, const gchar* account,
63                                     const gchar* key, gboolean server_account,
64                                     gpointer user_data);
65 };
66
67
68 /**
69  * modest_account_mgr_get_type:
70  * 
71  * get the GType for ModestAccountMgr
72  *  
73  * Returns: the GType
74  */
75 GType           modest_account_mgr_get_type       (void) G_GNUC_CONST;
76
77
78 /**
79  * modest_account_mgr_new:
80  * @modest_conf: a ModestConf instance 
81  *  
82  * Returns: a new ModestAccountMgr, or NULL in case of error
83  */
84 ModestAccountMgr*        modest_account_mgr_new            (ModestConf *modest_conf);
85
86
87
88 /**
89  * modest_account_mgr_add_account:
90  * @self: a ModestAccountMgr instance
91  * @name: name (id) of the account, which is a valid UTF8 string that does not contain '/'
92  * @store_name: the store account (ie. POP/IMAP)
93  * @transport_name: the transport account (ie. sendmail/SMTP)
94  * @err: a GError ptr, or NULL to ignore.
95  * 
96  * create a new account. the account with @name should not already exist
97  *
98  * Returns: TRUE if the creation succeeded, FALSE otherwise,
99  * @err gives details in case of error
100  */
101 gboolean        modest_account_mgr_add_account    (ModestAccountMgr *self,
102                                                    const gchar* name,
103                                                    const gchar* store_name,
104                                                    const gchar* transport_name,
105                                                    GError **err);
106
107
108 /**
109  * modest_account_mgr_add_server_account:
110  * @self: a ModestAccountMgr instance
111  * @name: name (id) of the account, which is a valid UTF8 string that does not contain '/'
112  * @hostname: the hostname
113  * @username: the username
114  * @password: the password
115  * @proto:    the protocol (imap, smtp, ...) used for this account
116  * 
117  * add a server account to the configuration.
118  * the server account with @name should not already exist
119  * 
120  * Returns: TRUE if succeeded, FALSE otherwise,
121  */
122 gboolean modest_account_mgr_add_server_account    (ModestAccountMgr *self,
123                                                    const gchar *name,
124                                                    const gchar *hostname,
125                                                    const gchar *username,
126                                                    const gchar *password,
127                                                    ModestProtocol proto);  
128
129 /**
130  * modest_account_mgr_remove_account:
131  * @self: a ModestAccountMgr instance
132  * @name: the name of the account to remove
133  * @server_account: TRUE if the account to remove is a server account
134  * @err: a #GError ptr, or NULL to ignore.
135  * 
136  * remove an existing account. the account with @name should already exist
137  *
138  * Returns: TRUE if the creation succeeded, FALSE otherwise,
139  * @err gives details in case of error
140  */
141 gboolean        modest_account_mgr_remove_account         (ModestAccountMgr *self,
142                                                            const gchar* name,
143                                                            gboolean server_account,
144                                                            GError **err);
145
146
147 /**
148  * modest_account_mgr_account_names:
149  * @self: a ModestAccountMgr instance
150  * @err: a GError ptr, or NULL to ignore.
151  * 
152  * list all account names
153  *
154  * Returns: a newly allocated list of account names, or NULL in case of error or
155  * if there are no accounts. The caller must free the returned GSList
156  * @err gives details in case of error
157  */
158 GSList*         modest_account_mgr_account_names    (ModestAccountMgr *self, GError **err);
159
160
161 /**
162  * modest_account_mgr_server_account_names:
163  * @self: a ModestAccountMgr instance
164  * @account_name: get only server accounts for @account_name, or NULL for any
165  * @type: get only server accounts from protocol type @type, or MODEST_PROTO_TYPE_ANY
166  * @proto: get only server account with protocol @proto, or NULL for any
167  * @only_enabled: get only enabled server accounts if TRUE
168  * 
169  * list all the server account names
170  *
171  * Returns: a newly allocated list of server account names, or NULL in case of
172  * error or if there are no server accounts. The caller must free the returned GSList
173  */
174 GSList*  modest_account_mgr_search_server_accounts  (ModestAccountMgr *self,
175                                                      const gchar*       account_name,
176                                                      ModestProtocolType type,
177                                                      ModestProtocol     proto);
178
179 /**
180  * modest_account_mgr_account_exists:
181  * @self: a ModestAccountMgr instance
182  * @name: the account name to check
183  * @server_account: if TRUE, this is a server account
184  * @err: a GError ptr, or NULL to ignore.
185  * 
186  * check whether account @name exists
187  *
188  * Returns: TRUE if the account with name @name exists, FALSE otherwise (or in case of error)
189  * @err gives details in case of error
190  */
191 gboolean        modest_account_mgr_account_exists         (ModestAccountMgr *self,
192                                                            const gchar *name,
193                                                            gboolean server_account,
194                                                            GError **err);
195
196
197 /**
198  * modest_account_mgr_get_account_string:
199  * @self: self a ModestAccountMgr instance
200  * @name: the name of the account
201  * @key: the key of the value to retrieve
202  * @server_account: if TRUE, this is a server account
203  * @err: a GError ptr, or NULL to ignore.
204  * 
205  * get a config string from an account
206  *
207  * Returns: a newly allocated string with the value for the key,
208  * or NULL in case of error. @err gives details in case of error
209  */
210 gchar*          modest_account_mgr_get_string     (ModestAccountMgr *self,
211                                                    const gchar *name,
212                                                    const gchar *key,
213                                                    gboolean server_account,
214                                                    GError **err);
215
216 /**
217  * modest_account_mgr_get_account_int:
218  * @self: a ModestAccountMgr instance
219  * @name: the name of the account
220  * @key: the key of the value to retrieve
221  * @server_account: if TRUE, this is a server account
222  * @err: a GError ptr, or NULL to ignore.
223  * 
224  * get a config int from an account
225  *
226  * Returns: an integer with the value for the key, or -1 in case of
227  * error (but of course -1 does not necessarily imply an error)
228  * @err gives details in case of error
229  */
230 gint            modest_account_mgr_get_int        (ModestAccountMgr *self,
231                                                    const gchar *name,
232                                                    const gchar *key,
233                                                    gboolean server_account,
234                                                    GError **err);
235
236 /**
237  * modest_account_mgr_get_account_bool:
238  * @self: a ModestAccountMgr instance
239  * @name: the name of the account
240  * @key: the key of the value to retrieve
241  * @server_account: if TRUE, this is a server account
242  * @err: a GError ptr, or NULL to ignore.
243  * 
244  * get a config boolean from an account
245  *
246  * Returns: an boolean with the value for the key, or FALSE in case of
247  * error (but of course FALSE does not necessarily imply an error)
248  * @err gives details in case of error
249  */
250 gboolean        modest_account_mgr_get_bool       (ModestAccountMgr *self,
251                                                    const gchar *name,
252                                                    const gchar *key,
253                                                    gboolean server_account,
254                                                    GError **err);
255
256 /**
257  * modest_account_mgr_get_list:
258  * @self: a ModestAccountMgr instance
259  * @name: the name of the account
260  * @key: the key of the value to get
261  * @list_type: the type of the members of the list
262  * @server_account: if TRUE, this is a server account
263  * @err: a GError ptr, or NULL to ignore.
264  * 
265  * get a config list of values of type @list_type of an account
266  *
267  * Returns: a newly allocated list of elements
268  * @err gives details in case of error
269  */
270 GSList*         modest_account_mgr_get_list       (ModestAccountMgr *self,
271                                                    const gchar *name,
272                                                    const gchar *key,
273                                                    ModestConfValueType list_type,
274                                                    gboolean server_account,
275                                                    GError **err);
276
277 /**
278  * modest_account_mgr_set_account_string:
279  * @self: a ModestAccountMgr instance
280  * @name: the name of the account
281  * @key: the key of the value to set
282  * @val: the value to set
283  * @server_account: if TRUE, this is a server account
284  * @err: a GError ptr, or NULL to ignore.
285  * 
286  * set a config string for an account.
287  *
288  * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
289  * @err gives details in case of error
290  */
291 gboolean        modest_account_mgr_set_string     (ModestAccountMgr *self,
292                                                    const gchar *name,
293                                                    const gchar *key, const gchar* val,
294                                                    gboolean server_account,
295                                                    GError **err);
296
297 /**
298  * modest_account_mgr_set_account_int:
299  * @self: a ModestAccountMgr instance
300  * @name: the name of the account
301  * @key: the key of the value to set
302  * @val: the value to set
303  * @server_account: if TRUE, this is a server account
304  * @err: a GError ptr, or NULL to ignore.
305  * 
306  * set a config int for an account
307  *
308  * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
309  * @err gives details in case of error
310  */
311 gboolean        modest_account_mgr_set_int        (ModestAccountMgr *self,
312                                                    const gchar *name,
313                                                    const gchar *key, gint val,
314                                                    gboolean server_account,
315                                                    GError **err);
316
317
318 /**
319  * modest_account_mgr_set_account_bool:
320  * @self: a ModestAccountMgr instance
321  * @name: the name of the account
322  * @key: the key of the value to set
323  * @val: the value to set
324  * @server_account: if TRUE, this is a server account
325  * @err: a GError ptr, or NULL to ignore.
326  * 
327  * set a config bool for an account
328  *
329  * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
330  * @err gives details in case of error
331  */
332 gboolean        modest_account_mgr_set_bool       (ModestAccountMgr *self,
333                                                    const gchar *name,
334                                                    const gchar *key, gboolean val,
335                                                    gboolean server_account,
336                                                    GError **err);
337
338 /**
339  * modest_account_mgr_set_list:
340  * @self: a ModestAccountMgr instance
341  * @name: the name of the account
342  * @key: the key of the value to set
343  * @val: the list with the values to set
344  * @list_type: the type of the members of the list
345  * @server_account: if TRUE, this is a server account
346  * @err: a GError ptr, or NULL to ignore.
347  * 
348  * set a config list of values of type @list_type of an account
349  * @err gives details in case of error
350  */
351 void            modest_account_mgr_set_list       (ModestAccountMgr *self,
352                                                    const gchar *name,
353                                                    const gchar *key,
354                                                    GSList *val,
355                                                    ModestConfValueType list_type,
356                                                    gboolean server_account,
357                                                    GError **err);
358
359 /**
360  * modest_account_mgr_unset:
361  * @self: a ModestAccountMgr instance
362  * @name: the name of the account
363  * @key: the key of the value to unset
364  * @server_account: if TRUE, this is a server account
365  * @err: a GError ptr, or NULL to ignore.
366  * 
367  * unsets the config value of an account and all their children keys
368  *
369  * Returns: TRUE if unsetting the value succeeded, or FALSE in case of error.
370  * @err gives details in case of error
371  */
372 gboolean        modest_account_mgr_unset           (ModestAccountMgr *self,
373                                                    const gchar *name,
374                                                    const gchar *key,
375                                                    gboolean server_account,
376                                                    GError **err);
377
378 G_END_DECLS
379
380 #endif /* __MODEST_ACCOUNT_MGR_H__ */