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