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