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