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