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