eef1cdfc02438b92bfe4c9bc9c4083a6b7267735
[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 struct _ModestAccountMgr {
53          GObject parent;
54 };
55
56 struct _ModestAccountMgrClass {
57         GObjectClass parent_class;
58
59         void (* account_inserted)  (ModestAccountMgr *obj, 
60                                     const gchar* account,
61                                     gpointer user_data);
62
63         void (* account_removed)   (ModestAccountMgr *obj, 
64                                     const gchar* account,
65                                     gpointer user_data);
66         
67         void (* account_changed)   (ModestAccountMgr *obj, 
68                                     const gchar* account,
69                                     gpointer user_data);
70
71         void (* account_busy_changed)   (ModestAccountMgr *obj, 
72                                          const gchar* account,
73                                          gboolean busy,
74                                          gpointer user_data);   
75
76         void (* default_account_changed)(ModestAccountMgr *obj, 
77                                          gpointer user_data);
78 };
79
80 /**
81  * modest_account_mgr_get_type:
82  * 
83  * get the GType for ModestAccountMgr
84  *  
85  * Returns: the GType
86  */
87 GType           modest_account_mgr_get_type       (void) G_GNUC_CONST;
88
89
90 /**
91  * modest_account_mgr_new:
92  * @modest_conf: a ModestConf instance 
93  *  
94  * Returns: a new ModestAccountMgr, or NULL in case of error
95  */
96 ModestAccountMgr*        modest_account_mgr_new            (ModestConf *modest_conf);
97
98
99
100 /**
101  * modest_account_mgr_add_account:
102  * @self: a ModestAccountMgr instance
103  * @name: name (id) of the account, which is a valid UTF8 string that does not contain '/'
104  * @store_name: the store account (ie. POP/IMAP)
105  * @transport_name: the transport account (ie. sendmail/SMTP)
106  * @enabled: Whether the account should be enabled initially.
107  * 
108  * Create a new account. The account with @name should not already exist. The @name will 
109  * be used as the initial display name of the new account.
110  *
111  * Returns: TRUE if the creation succeeded, FALSE otherwise,
112  */
113 gboolean        modest_account_mgr_add_account    (ModestAccountMgr *self,
114                                                    const gchar* name,
115                                                    const gchar* store_name,
116                                                    const gchar* transport_name,
117                                                    gboolean enabled);
118
119 /**
120  * modest_account_mgr_add_server_account:
121  * @self: a ModestAccountMgr instance
122  * @name: name (id) of the account, which is a valid UTF8 string that does not contain '/'
123  * @hostname: the hostname
124  * @portnumber: the portnumber, or 0 for default
125  * @username: the username
126  * @password: the password
127  * @proto:    the protocol (imap, smtp, ...) used for this account
128  * @security: the security options, (SSL, TLS ...) used to access the server
129  * @auth: the authentication method (password, none ...) used to access the server
130  * 
131  * add a server account to the configuration.
132  * the server account with @name should not already exist
133  * 
134  * Returns: TRUE if succeeded, FALSE otherwise,
135  */
136 gboolean modest_account_mgr_add_server_account    (ModestAccountMgr *self,
137                                                    const gchar *name,
138                                                    const gchar *hostname,
139                                                    const guint portnumber,
140                                                    const gchar *username,
141                                                    const gchar *password,
142                                                    ModestTransportStoreProtocol proto,
143                                                    ModestConnectionProtocol security,
144                                                    ModestAuthProtocol auth);
145
146
147 /**
148  * modest_account_mgr_add_server_account_uri:
149  * @self: a ModestAccountMgr instance
150  * @name: name (id) of the account, which is a valid UTF8 string that does not contain '/'
151  * @proto:    the protocol (imap, smtp, ...) used for this account
152  * @uri: the URI
153  * 
154  * add a server account to the configuration, based on the account-URI
155  * 
156  * Returns: TRUE if succeeded, FALSE otherwise,
157  */
158 gboolean modest_account_mgr_add_server_account_uri    (ModestAccountMgr *self,
159                                                        const gchar *name,
160                                                        ModestTransportStoreProtocol proto,
161                                                        const gchar* uri);
162
163 /**
164  * modest_account_mgr_remove_account:
165  * @self: a ModestAccountMgr instance
166  * @name: the name of the account to remove
167  * @err: a #GError ptr, or NULL to ignore.
168  * 
169  * remove an existing account. the account with @name should already exist; note
170  * that when deleting an account, also the corresponding server accounts will
171  * be deleted
172  *
173  * Returns: TRUE if the creation succeeded, FALSE otherwise,
174  * @err gives details in case of error
175  */
176 gboolean        modest_account_mgr_remove_account         (ModestAccountMgr *self,
177                                                            const gchar* name);
178
179 /**
180  * modest_account_mgr_account_names:
181  * @self: a ModestAccountMgr instance
182  * @only_enabled: Whether only enabled accounts should be returned.
183  * 
184  * list all account names
185  *
186  * Returns: a newly allocated list of account names, or NULL in case of error or
187  * if there are no accounts. The caller must free the returned GSList.
188  *
189  */
190 GSList*         modest_account_mgr_account_names    (ModestAccountMgr *self,
191                                                      gboolean only_enabled);
192
193 /**
194  * modest_account_mgr_free_account_names:
195  * @account_name: a gslist of account names
196  * 
197  * list all account names
198  *
199  * free the list of account names
200  */
201 void            modest_account_mgr_free_account_names    (GSList *account_names);
202                                                           
203
204 /**
205  * modest_account_mgr_account_exists:
206  * @self: a ModestAccountMgr instance
207  * @name: the account name to check
208  * @server_account: if TRUE, this is a server account
209  * 
210  * check whether account @name exists. Note that this does not check the display name.
211  *
212  * Returns: TRUE if the account with name @name exists, FALSE otherwise (or in case of error)
213  */
214 gboolean        modest_account_mgr_account_exists         (ModestAccountMgr *self,
215                                                            const gchar *name,
216                                                            gboolean server_account);
217
218 /**
219  * modest_account_mgr_account_exists:
220  * @self: a ModestAccountMgr instance
221  * @name: the account name to check
222  * 
223  * check whether a non-server account with the @display_name exists.
224  *
225  * Returns: TRUE if the account with name @name exists, FALSE otherwise (or in case of error)
226  */
227 gboolean        modest_account_mgr_account_with_display_name_exists       (ModestAccountMgr *self,
228                                                            const gchar *display_name);
229
230
231 /**
232  * modest_account_mgr_get_string:
233  * @self: self a ModestAccountMgr instance
234  * @name: the name of the account
235  * @key: the key of the value to retrieve
236  * @server_account: if TRUE, this is a server account
237  * 
238  * get a config string from an account
239  *
240  * Returns: a newly allocated string with the value for the key,
241  * or NULL in case of error. 
242  */
243 gchar*          modest_account_mgr_get_string     (ModestAccountMgr *self,
244                                                    const gchar *name,
245                                                    const gchar *key,
246                                                    gboolean server_account);
247
248
249 /**
250  * modest_account_mgr_get_password:
251  * @self: self a ModestAccountMgr instance
252  * @name: the name of the account
253  * @key: the key of the value to retrieve
254  * @server_account: if TRUE, this is a server account
255  * 
256  * get a password from an account
257  *
258  * Returns: a newly allocated string with the value for the key,
259  * or NULL in case of error.
260  */
261 gchar*          modest_account_mgr_get_password     (ModestAccountMgr *self,
262                                                      const gchar *name,
263                                                      const gchar *key,
264                                                      gboolean server_account);
265
266 /**
267  * modest_account_mgr_get_int:
268  * @self: a ModestAccountMgr instance
269  * @name: the name of the account
270  * @key: the key of the value to retrieve
271  * @server_account: if TRUE, this is a server account
272  * 
273  * get a config int from an account
274  *
275  * Returns: an integer with the value for the key, or -1 in case of
276  * error (but of course -1 does not necessarily imply an error)
277  */
278 gint            modest_account_mgr_get_int        (ModestAccountMgr *self,
279                                                    const gchar *name,
280                                                    const gchar *key,
281                                                    gboolean server_account);
282
283 /**
284  * modest_account_mgr_get_bool:
285  * @self: a ModestAccountMgr instance
286  * @name: the name of the account
287  * @key: the key of the value to retrieve
288  * @server_account: if TRUE, this is a server account
289  * 
290  * get a config boolean from an account
291  *
292  * Returns: an boolean with the value for the key, or FALSE in case of
293  * error (but of course FALSE does not necessarily imply an error)
294  */
295 gboolean        modest_account_mgr_get_bool       (ModestAccountMgr *self,
296                                                    const gchar *name,
297                                                    const gchar *key,
298                                                    gboolean server_account);
299
300 /**
301  * modest_account_mgr_get_list:
302  * @self: a ModestAccountMgr instance
303  * @name: the name of the account
304  * @key: the key of the value to get
305  * @list_type: the type of the members of the list
306  * @server_account: if TRUE, this is a server account
307  * 
308  * get a config list of values of type @list_type of an account
309  *
310  * Returns: a newly allocated list of elements
311  */
312 GSList*         modest_account_mgr_get_list       (ModestAccountMgr *self,
313                                                    const gchar *name,
314                                                    const gchar *key,
315                                                    ModestConfValueType list_type,
316                                                    gboolean server_account);
317
318 /**
319  * modest_account_mgr_set_string:
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  * 
326  * set a config string for an account.
327  *
328  * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
329  */
330 gboolean        modest_account_mgr_set_string     (ModestAccountMgr *self,
331                                                    const gchar *name,
332                                                    const gchar *key, const gchar* val,
333                                                    gboolean server_account);
334
335
336 /**
337  * modest_account_mgr_set_password:
338  * @self: a ModestAccountMgr instance
339  * @name: the name of the account
340  * @key: the key of the value to set
341  * @val: the value to set
342  * @server_account: if TRUE, this is a server account
343  * 
344  * set a password for an account.
345  *
346  * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
347 * @err gives details in case of error
348  */
349 gboolean        modest_account_mgr_set_password     (ModestAccountMgr *self,
350                                                      const gchar *name,
351                                                      const gchar *key, const gchar* val,
352                                                      gboolean server_account);
353
354 /**
355  * modest_account_mgr_set_int:
356  * @self: a ModestAccountMgr instance
357  * @name: the name of the account
358  * @key: the key of the value to set
359  * @val: the value to set
360  * @server_account: if TRUE, this is a server account
361  * 
362  * set a config int for an account
363  *
364  * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
365  */
366 gboolean        modest_account_mgr_set_int        (ModestAccountMgr *self,
367                                                    const gchar *name,
368                                                    const gchar *key, gint val,
369                                                    gboolean server_account);
370
371 /**
372  * modest_account_mgr_set_bool:
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  * 
379  * set a config bool for an account
380  *
381  * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
382  */
383 gboolean        modest_account_mgr_set_bool       (ModestAccountMgr *self,
384                                                    const gchar *name,
385                                                    const gchar *key, gboolean val,
386                                                    gboolean server_account);
387
388 /**
389  * modest_account_mgr_set_list:
390  * @self: a ModestAccountMgr instance
391  * @name: the name of the account
392  * @key: the key of the value to set
393  * @val: the list with the values to set
394  * @list_type: the type of the members of the list
395  * @server_account: if TRUE, this is a server account
396  *
397  * * set a config list of values of type @list_type of an account
398  * 
399  * returns TRUE if this succeeded, FALSE otherwise 
400  */
401 gboolean                modest_account_mgr_set_list       (ModestAccountMgr *self,
402                                                            const gchar *name,
403                                                            const gchar *key,
404                                                            GSList *val,
405                                                            ModestConfValueType list_type,
406                                                            gboolean server_account);
407
408 /**
409  * modest_account_mgr_unset:
410  * @self: a ModestAccountMgr instance
411  * @name: the name of the account
412  * @key: the key of the value to unset
413  * @server_account: if TRUE, this is a server account
414  * @err: a GError ptr, or NULL to ignore.
415  * 
416  * unsets the config value of an account and all their children keys
417  *
418  * Returns: TRUE if unsetting the value succeeded, or FALSE in case of error.
419  * @err gives details in case of error
420  */
421 gboolean        modest_account_mgr_unset           (ModestAccountMgr *self,
422                                                     const gchar *name,
423                                                     const gchar *key,
424                                                     gboolean server_account);
425
426 /**
427  * modest_account_mgr_has_accounts:
428  * @self: a ModestAccountMgr instance
429  * @enabled: TRUE to search for enabled accounts only
430  * 
431  * Checks if any accounts exist
432  *
433  * Returns: TRUE if accounts exist, FALSE otherwise
434  */
435
436 gboolean modest_account_mgr_has_accounts (ModestAccountMgr* self, gboolean enabled);
437
438 /**
439  * modest_account_mgr_set_account_busy
440  * @self: a ModestAccountMgr instance
441  * @account_name: name of the account
442  * @busy: whether to set busy or not busy
443  * 
444  * Changes the busy flag of an account
445  *
446  */
447
448 void modest_account_mgr_set_account_busy(ModestAccountMgr* self, const gchar* account_name, 
449                                                                                                                                                 gboolean busy);
450
451 /**
452  * modest_account_mgr_account_is_busy
453  * @self: a ModestAccountMgr instance
454  * @account_name: name of the account
455  * 
456  * Returns: If the account is currently busy or not
457  *
458  */
459 gboolean
460 modest_account_mgr_account_is_busy(ModestAccountMgr* self, const gchar* account_name);
461
462
463 G_END_DECLS
464
465 #endif /* __MODEST_ACCOUNT_MGR_H__ */