* infrastructure for locking added, small cosmetics
[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-account-keys.h"
37 #include "modest-proto.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, gboolean server_account, gpointer user_data);
61         void (* account_changed)   (ModestAccountMgr *obj, const gchar* account, const gchar* key, gboolean server_account,
62                                     gpointer user_data);
63 };
64
65
66 /**
67  * modest_ui_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: the name of the account to create
90  * @store_name: the store account (ie. POP/IMAP)
91  * @transport_name: the transport account (ie. sendmail/SMTP)
92  * @err: a GError ptr, or NULL to ignore.
93  * 
94  * create a new account. the account with @name should not already exist
95  *
96  * Returns: TRUE if the creation succeeded, FALSE otherwise,
97  * @err gives details in case of error
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                                                    GError **err);
104
105
106 /**
107  * modest_account_mgr_add_server_account:
108  * @self: a ModestAccountMgr instance
109  * @name: name (id) of the account
110  * @hostname: the hostname
111  * @username: the username
112  * @password: the password
113  * @proto:    the protocol (imap, smtp, ...) used for this account
114  * 
115  * add a server account to the configuration.
116  * the server account with @name should not already exist
117  * 
118  * Returns: TRUE if succeeded, FALSE otherwise,
119  */
120 gboolean modest_account_mgr_add_server_account    (ModestAccountMgr *self,
121                                                    const gchar *name,
122                                                    const gchar *hostname,
123                                                    const gchar *username,
124                                                    const gchar *password,
125                                                    const gchar *proto);  
126
127 /**
128  * modest_account_mgr_remove_account:
129  * @self: a ModestAccountMgr instance
130  * @name: the name of the account to remove
131  * @err: a GError ptr, or NULL to ignore.
132  * 
133  * remove an existing account. the account with @name should already exist
134  *
135  * Returns: TRUE if the creation succeeded, FALSE otherwise,
136  * @err gives details in case of error
137  */
138 gboolean        modest_account_mgr_remove_account         (ModestAccountMgr *self,
139                                                            const gchar* name,
140                                                            gboolean server_account,
141                                                            GError **err);
142
143
144 /**
145  * modest_account_mgr_account_names:
146  * @self: a ModestAccountMgr instance
147  * @err: a GError ptr, or NULL to ignore.
148  * 
149  * list all account names
150  *
151  * Returns: a newly allocated list of account names, or NULL in case of error or
152  * if there are no accounts. The caller must free the returned GSList
153  * @err gives details in case of error
154  */
155 GSList*         modest_account_mgr_account_names    (ModestAccountMgr *self, GError **err);
156
157
158 /**
159  * modest_account_mgr_server_account_names:
160  * @self: a ModestAccountMgr instance
161  * @account_name: get only server accounts for @account_name, or NULL for any
162  * @type: get only server accounts from protocol type @type, or MODEST_PROTO_TYPE_ANY
163  * @proto: get only server account with protocol @proto, or NULL for any
164  * @only_enabled: get only enabled server accounts if TRUE
165  * 
166  * list all the server account names
167  *
168  * Returns: a newly allocated list of server account names, or NULL in case of
169  * error or if there are no server accounts. The caller must free the returned GSList
170  */
171 GSList*  modest_account_mgr_search_server_accounts  (ModestAccountMgr *self,
172                                                      const gchar*    account_name,
173                                                      ModestProtoType type,
174                                                      const gchar*    proto,
175                                                      gboolean only_enabled);
176
177 /**
178  * modest_account_mgr_account_exists:
179  * @self: a ModestAccountMgr instance
180  * @name: the account name to check
181  * @server_account: if TRUE, this is a server account
182  * @err: a GError ptr, or NULL to ignore.
183  * 
184  * check whether account @name exists
185  *
186  * Returns: TRUE if the account with name @name exists, FALSE otherwise (or in case of error)
187  * @err gives details in case of error
188  */
189 gboolean        modest_account_mgr_account_exists         (ModestAccountMgr *self,
190                                                            const gchar *name,
191                                                            gboolean server_account,
192                                                            GError **err);
193
194
195 /**
196  * modest_account_mgr_enable_account:
197  * @self: a ModestAccountMgr instance
198  * @name: the account name to disable
199  * @server_account: if TRUE, this is a server account
200  * 
201  * enable an account that has been disabled with 'modest_account_mgr_disable_account'
202  *
203  * Returns: TRUE if it worked, FALSE otherwise
204  */
205 gboolean modest_account_mgr_enable_account (ModestAccountMgr *self, const gchar* name,
206                                             gboolean is_server_account);
207
208
209
210 /**
211  * modest_account_mgr_disable_account:
212  * @self: a ModestAccountMgr instance
213  * @name: the account name to disable
214  * @server_account: if TRUE, this is a server account
215  * 
216  * disable an account. this will also stop change notification until
217  * modest_account_mgr_enable_account is called. However, in case of removal, the
218  * appropriate signal will still be emitted.
219  *
220  * Returns: TRUE if it worked, FALSE otherwise
221  */
222 gboolean modest_account_mgr_disable_account (ModestAccountMgr *self, const gchar* name,
223                                              gboolean is_server_account);
224
225
226
227 /**
228  * modest_account_mgr_account_is_enabled:
229  * @self: a ModestAccountMgr instance
230  * @name: the account name to check
231  * @server_account: if TRUE, this is a server account
232  *
233  * check whether a certain account is enabled
234  *
235  * Returns: TRUE if it is enabled, FALSE otherwise
236  */
237 gboolean modest_account_mgr_account_is_enabled (ModestAccountMgr *self, const gchar* name,
238                                                 gboolean is_server_account);
239
240
241
242
243 /**
244  * modest_account_mgr_get_account_string:
245  * @self: self a ModestAccountMgr instance
246  * @name: the name of the account
247  * @key: the key of the value to retrieve
248  * @server_account: if TRUE, this is a server account
249  * @err: a GError ptr, or NULL to ignore.
250  * 
251  * get a config string from an account
252  *
253  * Returns: a newly allocated string with the value for the key,
254  * or NULL in case of error. @err gives details in case of error
255  */
256 gchar*          modest_account_mgr_get_string     (ModestAccountMgr *self,
257                                                    const gchar *name,
258                                                    const gchar *key,
259                                                    gboolean server_account,
260                                                    GError **err);
261
262
263 /**
264  * modest_account_mgr_get_account_int:
265  * @self: a ModestAccountMgr instance
266  * @name: the name of the account
267  * @key: the key of the value to retrieve
268  * @server_account: if TRUE, this is a server account
269  * @err: a GError ptr, or NULL to ignore.
270  * 
271  * get a config int from an account
272  *
273  * Returns: an integer with the value for the key, or -1 in case of
274  * error (but of course -1 does not necessarily imply an error)
275  * @err gives details in case of error
276  */
277 gint            modest_account_mgr_get_int        (ModestAccountMgr *self,
278                                                    const gchar *name,
279                                                    const gchar *key,
280                                                    gboolean server_account,
281                                                    GError **err);
282
283 /**
284  * modest_account_mgr_get_account_bool:
285  * @self: a ModestAccountMgr instance
286  * @name: the name of the account
287  * @key: the key of the value to retrieve
288  * @server_account: if TRUE, this is a server account
289  * @err: a GError ptr, or NULL to ignore.
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  * @err gives details in case of error
296  */
297 gboolean        modest_account_mgr_get_bool       (ModestAccountMgr *self,
298                                                    const gchar *name,
299                                                    const gchar *key,
300                                                    gboolean server_account,
301                                                    GError **err);
302
303 /**
304  * modest_account_mgr_set_account_string:
305  * @self: a ModestAccountMgr instance
306  * @name: the name of the account
307  * @key: the key of the value to set
308  * @val: the value to set
309  * @server_account: if TRUE, this is a server account
310  * @err: a GError ptr, or NULL to ignore.
311  * 
312  * set a config string for an account
313  *
314  * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
315  * @err gives details in case of error
316  */
317 gboolean        modest_account_mgr_set_string     (ModestAccountMgr *self,
318                                                    const gchar *name,
319                                                    const gchar *key, const gchar* val,
320                                                    gboolean server_account,
321                                                    GError **err);
322
323 /**
324  * modest_account_mgr_set_account_int:
325  * @self: a ModestAccountMgr instance
326  * @name: the name of the account
327  * @key: the key of the value to set
328  * @val: the value to set
329  * @server_account: if TRUE, this is a server account
330  * @err: a GError ptr, or NULL to ignore.
331  * 
332  * set a config int for an account
333  *
334  * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
335  * @err gives details in case of error
336  */
337 gboolean        modest_account_mgr_set_int        (ModestAccountMgr *self,
338                                                    const gchar *name,
339                                                    const gchar *key, gint val,
340                                                    gboolean server_account,
341                                                    GError **err);
342
343
344 /**
345  * modest_account_mgr_set_account_bool:
346  * @self: a ModestAccountMgr instance
347  * @name: the name of the account
348  * @key: the key of the value to set
349  * @val: the value to set
350  * @server_account: if TRUE, this is a server account
351  * @err: a GError ptr, or NULL to ignore.
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  * @err gives details in case of error
357  */
358 gboolean        modest_account_mgr_set_bool       (ModestAccountMgr *self,
359                                                    const gchar *name,
360                                                    const gchar *key, gboolean val,
361                                                    gboolean server_account,
362                                                    GError **err);
363
364 G_END_DECLS
365
366 #endif /* __MODEST_ACCOUNT_MGR_H__ */