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