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