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