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