2007-06-17 Johannes Schmid <johannes.schmid@openismus.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                                     gboolean server_account,
62                                     gpointer user_data);
63         void (* account_changed)   (ModestAccountMgr *obj, 
64                                     const gchar* account,
65                                     const GSList* key, 
66                                     gboolean server_account,
67                                     gpointer user_data);
68                 void (* account_busy_changed)   (ModestAccountMgr *obj, 
69                                     const gchar* account,
70                                     gboolean busy,
71                                     gpointer user_data);
72         
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  * @server_account: TRUE if the account to remove is a server account
163  * @err: a #GError ptr, or NULL to ignore.
164  * 
165  * remove an existing account. the account with @name should already exist; note
166  * that when deleting an account, also the corresponding server accounts will
167  * be deleted
168  *
169  * Returns: TRUE if the creation succeeded, FALSE otherwise,
170  * @err gives details in case of error
171  */
172 gboolean        modest_account_mgr_remove_account         (ModestAccountMgr *self,
173                                                            const gchar* name,
174                                                            gboolean server_account);
175
176
177 /**
178  * modest_account_mgr_account_names:
179  * @self: a ModestAccountMgr instance
180  * @only_enabled: Whether only enabled accounts should be returned.
181  * 
182  * list all account names
183  *
184  * Returns: a newly allocated list of account names, or NULL in case of error or
185  * if there are no accounts. The caller must free the returned GSList.
186  *
187  * TODO: I believe that the caller must free the strings in the GSList items too, 
188  * because this is implemented via gconf_client_all_dirs() which also requires a deep free, 
189  * though that's not documented. murrayc.
190  */
191 GSList*         modest_account_mgr_account_names    (ModestAccountMgr *self,
192                                                      gboolean only_enabled);
193
194 #if 0
195 /* Not used. */
196 /**
197  * modest_account_mgr_search_server_account:
198  * @self: a ModestAccountMgr instance
199  * @account_name: get only server accounts for @account_name, or NULL for any
200  * @type: get only server accounts from protocol type @type, or MODEST_PROTOCOL_TYPE_UNKNOWN
201  * @proto: get only server account with protocol @proto, or MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN for any
202  * 
203  * List all the server account names, optionally narrowing the result down to one account.
204  *
205  * Returns: a newly allocated list of server account names, or NULL in case of
206  * error or if there are no server accounts. The caller must free the returned GSList
207  */
208 GSList*  modest_account_mgr_search_server_accounts  (ModestAccountMgr *self,
209                                                      const gchar*       account_name,
210                                                      ModestProtocolType type,
211                                                      ModestTransportStoreProtocol     proto);
212 #endif
213
214 /**
215  * modest_account_mgr_account_exists:
216  * @self: a ModestAccountMgr instance
217  * @name: the account name to check
218  * @server_account: if TRUE, this is a server account
219  * 
220  * check whether account @name exists. Note that this does not check the display name.
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_exists         (ModestAccountMgr *self,
225                                                            const gchar *name,
226                                                            gboolean server_account);
227
228 /**
229  * modest_account_mgr_account_exists:
230  * @self: a ModestAccountMgr instance
231  * @name: the account name to check
232  * 
233  * check whether a non-server account with the @display_name exists.
234  *
235  * Returns: TRUE if the account with name @name exists, FALSE otherwise (or in case of error)
236  */
237 gboolean        modest_account_mgr_account_with_display_name_exists       (ModestAccountMgr *self,
238                                                            const gchar *display_name);
239
240
241 /**
242  * modest_account_mgr_get_string:
243  * @self: self a ModestAccountMgr instance
244  * @name: the name of the account
245  * @key: the key of the value to retrieve
246  * @server_account: if TRUE, this is a server account
247  * 
248  * get a config string from an account
249  *
250  * Returns: a newly allocated string with the value for the key,
251  * or NULL in case of error. 
252  */
253 gchar*          modest_account_mgr_get_string     (ModestAccountMgr *self,
254                                                    const gchar *name,
255                                                    const gchar *key,
256                                                    gboolean server_account);
257
258
259 /**
260  * modest_account_mgr_get_password:
261  * @self: self a ModestAccountMgr instance
262  * @name: the name of the account
263  * @key: the key of the value to retrieve
264  * @server_account: if TRUE, this is a server account
265  * 
266  * get a password from an account
267  *
268  * Returns: a newly allocated string with the value for the key,
269  * or NULL in case of error.
270  */
271 gchar*          modest_account_mgr_get_password     (ModestAccountMgr *self,
272                                                      const gchar *name,
273                                                      const gchar *key,
274                                                      gboolean server_account);
275
276 /**
277  * modest_account_mgr_get_int:
278  * @self: a ModestAccountMgr instance
279  * @name: the name of the account
280  * @key: the key of the value to retrieve
281  * @server_account: if TRUE, this is a server account
282  * 
283  * get a config int from an account
284  *
285  * Returns: an integer with the value for the key, or -1 in case of
286  * error (but of course -1 does not necessarily imply an error)
287  */
288 gint            modest_account_mgr_get_int        (ModestAccountMgr *self,
289                                                    const gchar *name,
290                                                    const gchar *key,
291                                                    gboolean server_account);
292
293 /**
294  * modest_account_mgr_get_bool:
295  * @self: a ModestAccountMgr instance
296  * @name: the name of the account
297  * @key: the key of the value to retrieve
298  * @server_account: if TRUE, this is a server account
299  * 
300  * get a config boolean from an account
301  *
302  * Returns: an boolean with the value for the key, or FALSE in case of
303  * error (but of course FALSE does not necessarily imply an error)
304  */
305 gboolean        modest_account_mgr_get_bool       (ModestAccountMgr *self,
306                                                    const gchar *name,
307                                                    const gchar *key,
308                                                    gboolean server_account);
309
310 /**
311  * modest_account_mgr_get_list:
312  * @self: a ModestAccountMgr instance
313  * @name: the name of the account
314  * @key: the key of the value to get
315  * @list_type: the type of the members of the list
316  * @server_account: if TRUE, this is a server account
317  * 
318  * get a config list of values of type @list_type of an account
319  *
320  * Returns: a newly allocated list of elements
321  */
322 GSList*         modest_account_mgr_get_list       (ModestAccountMgr *self,
323                                                    const gchar *name,
324                                                    const gchar *key,
325                                                    ModestConfValueType list_type,
326                                                    gboolean server_account);
327
328 /**
329  * modest_account_mgr_set_string:
330  * @self: a ModestAccountMgr instance
331  * @name: the name of the account
332  * @key: the key of the value to set
333  * @val: the value to set
334  * @server_account: if TRUE, this is a server account
335  * 
336  * set a config string for an account.
337  *
338  * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
339  */
340 gboolean        modest_account_mgr_set_string     (ModestAccountMgr *self,
341                                                    const gchar *name,
342                                                    const gchar *key, const gchar* val,
343                                                    gboolean server_account);
344
345
346 /**
347  * modest_account_mgr_set_password:
348  * @self: a ModestAccountMgr instance
349  * @name: the name of the account
350  * @key: the key of the value to set
351  * @val: the value to set
352  * @server_account: if TRUE, this is a server account
353  * 
354  * set a password for an account.
355  *
356  * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
357 * @err gives details in case of error
358  */
359 gboolean        modest_account_mgr_set_password     (ModestAccountMgr *self,
360                                                      const gchar *name,
361                                                      const gchar *key, const gchar* val,
362                                                      gboolean server_account);
363
364 /**
365  * modest_account_mgr_set_int:
366  * @self: a ModestAccountMgr instance
367  * @name: the name of the account
368  * @key: the key of the value to set
369  * @val: the value to set
370  * @server_account: if TRUE, this is a server account
371  * 
372  * set a config int for an account
373  *
374  * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
375  */
376 gboolean        modest_account_mgr_set_int        (ModestAccountMgr *self,
377                                                    const gchar *name,
378                                                    const gchar *key, gint val,
379                                                    gboolean server_account);
380
381 /**
382  * modest_account_mgr_set_bool:
383  * @self: a ModestAccountMgr instance
384  * @name: the name of the account
385  * @key: the key of the value to set
386  * @val: the value to set
387  * @server_account: if TRUE, this is a server account
388  * 
389  * set a config bool for an account
390  *
391  * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
392  */
393 gboolean        modest_account_mgr_set_bool       (ModestAccountMgr *self,
394                                                    const gchar *name,
395                                                    const gchar *key, gboolean val,
396                                                    gboolean server_account);
397
398 /**
399  * modest_account_mgr_set_list:
400  * @self: a ModestAccountMgr instance
401  * @name: the name of the account
402  * @key: the key of the value to set
403  * @val: the list with the values to set
404  * @list_type: the type of the members of the list
405  * @server_account: if TRUE, this is a server account
406  *
407  * * set a config list of values of type @list_type of an account
408  * 
409  * returns TRUE if this succeeded, FALSE otherwise 
410  */
411 gboolean                modest_account_mgr_set_list       (ModestAccountMgr *self,
412                                                            const gchar *name,
413                                                            const gchar *key,
414                                                            GSList *val,
415                                                            ModestConfValueType list_type,
416                                                            gboolean server_account);
417
418 /**
419  * modest_account_mgr_unset:
420  * @self: a ModestAccountMgr instance
421  * @name: the name of the account
422  * @key: the key of the value to unset
423  * @server_account: if TRUE, this is a server account
424  * @err: a GError ptr, or NULL to ignore.
425  * 
426  * unsets the config value of an account and all their children keys
427  *
428  * Returns: TRUE if unsetting the value succeeded, or FALSE in case of error.
429  * @err gives details in case of error
430  */
431 gboolean        modest_account_mgr_unset           (ModestAccountMgr *self,
432                                                     const gchar *name,
433                                                     const gchar *key,
434                                                     gboolean server_account);
435
436 /**
437  * modest_account_mgr_has_accounts:
438  * @self: a ModestAccountMgr instance
439  * @enabled: TRUE to search for enabled accounts only
440  * 
441  * Checks if any accounts exist
442  *
443  * Returns: TRUE if accounts exist, FALSE otherwise
444  */
445
446 gboolean modest_account_mgr_has_accounts (ModestAccountMgr* self, gboolean enabled);
447
448 /**
449  * modest_account_mgr_set_account_busy
450  * @self: a ModestAccountMgr instance
451  * @account_name: name of the account
452  * @busy: whether to set busy or not busy
453  * 
454  * Changes the busy flag of an account
455  *
456  */
457
458 void modest_account_mgr_set_account_busy(ModestAccountMgr* self, const gchar* account_name, 
459                                                                                                                                                 gboolean busy);
460
461 /**
462  * modest_account_mgr_account_is_busy
463  * @self: a ModestAccountMgr instance
464  * @account_name: name of the account
465  * 
466  * Returns: If the account is currently busy or not
467  *
468  */
469 gboolean
470 modest_account_mgr_account_is_busy(ModestAccountMgr* self, const gchar* account_name);
471
472
473 G_END_DECLS
474
475 #endif /* __MODEST_ACCOUNT_MGR_H__ */