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