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