eb9b0c7e35dcd4510a921aa127c2d80fb3477e9a
[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
176 /**
177  * modest_account_mgr_account_exists:
178  * @self: a ModestAccountMgr instance
179  * @name: the account name to check
180  * @server_account: if TRUE, this is a server account
181  * @err: a GError ptr, or NULL to ignore.
182  * 
183  * check whether account @name exists
184  *
185  * Returns: TRUE if the account with name @name exists, FALSE otherwise (or in case of error)
186  * @err gives details in case of error
187  */
188 gboolean        modest_account_mgr_account_exists         (ModestAccountMgr *self,
189                                                            const gchar *name,
190                                                            gboolean server_account,
191                                                            GError **err);
192
193
194 /**
195  * modest_account_mgr_account_set_enabled
196  * @self: a ModestAccountMgr instance
197  * @name: the account name 
198  * @enabled: if TRUE, the account will be enabled, if FALSE, it will be disabled
199  * 
200  * enable/disabled an account
201  *
202  * Returns: TRUE if it worked, FALSE otherwise
203  */
204 gboolean modest_account_mgr_account_set_enabled (ModestAccountMgr *self, const gchar* name,
205                                                  gboolean enabled);
206
207
208 /**
209  * modest_account_mgr_account_get_enabled:
210  * @self: a ModestAccountMgr instance
211  * @name: the account name to check
212  *
213  * check whether a certain account is enabled
214  *
215  * Returns: TRUE if it is enabled, FALSE otherwise
216  */
217 gboolean modest_account_mgr_account_get_enabled (ModestAccountMgr *self, const gchar* name);
218
219
220 /**
221  * modest_account_mgr_get_account_string:
222  * @self: self a ModestAccountMgr instance
223  * @name: the name of the account
224  * @key: the key of the value to retrieve
225  * @server_account: if TRUE, this is a server account
226  * @err: a GError ptr, or NULL to ignore.
227  * 
228  * get a config string from an account
229  *
230  * Returns: a newly allocated string with the value for the key,
231  * or NULL in case of error. @err gives details in case of error
232  */
233 gchar*          modest_account_mgr_get_string     (ModestAccountMgr *self,
234                                                    const gchar *name,
235                                                    const gchar *key,
236                                                    gboolean server_account,
237                                                    GError **err);
238
239
240 /**
241  * modest_account_mgr_get_account_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  * @err: a GError ptr, or NULL to ignore.
247  * 
248  * get a config int from an account
249  *
250  * Returns: an integer with the value for the key, or -1 in case of
251  * error (but of course -1 does not necessarily imply an error)
252  * @err gives details in case of error
253  */
254 gint            modest_account_mgr_get_int        (ModestAccountMgr *self,
255                                                    const gchar *name,
256                                                    const gchar *key,
257                                                    gboolean server_account,
258                                                    GError **err);
259
260 /**
261  * modest_account_mgr_get_account_bool:
262  * @self: a ModestAccountMgr instance
263  * @name: the name of the account
264  * @key: the key of the value to retrieve
265  * @server_account: if TRUE, this is a server account
266  * @err: a GError ptr, or NULL to ignore.
267  * 
268  * get a config boolean from an account
269  *
270  * Returns: an boolean with the value for the key, or FALSE in case of
271  * error (but of course FALSE does not necessarily imply an error)
272  * @err gives details in case of error
273  */
274 gboolean        modest_account_mgr_get_bool       (ModestAccountMgr *self,
275                                                    const gchar *name,
276                                                    const gchar *key,
277                                                    gboolean server_account,
278                                                    GError **err);
279
280 /**
281  * modest_account_mgr_set_account_string:
282  * @self: a ModestAccountMgr instance
283  * @name: the name of the account
284  * @key: the key of the value to set
285  * @val: the value to set
286  * @server_account: if TRUE, this is a server account
287  * @err: a GError ptr, or NULL to ignore.
288  * 
289  * set a config string for an account
290  *
291  * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
292  * @err gives details in case of error
293  */
294 gboolean        modest_account_mgr_set_string     (ModestAccountMgr *self,
295                                                    const gchar *name,
296                                                    const gchar *key, const gchar* val,
297                                                    gboolean server_account,
298                                                    GError **err);
299
300 /**
301  * modest_account_mgr_set_account_int:
302  * @self: a ModestAccountMgr instance
303  * @name: the name of the account
304  * @key: the key of the value to set
305  * @val: the value to set
306  * @server_account: if TRUE, this is a server account
307  * @err: a GError ptr, or NULL to ignore.
308  * 
309  * set a config int for an account
310  *
311  * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
312  * @err gives details in case of error
313  */
314 gboolean        modest_account_mgr_set_int        (ModestAccountMgr *self,
315                                                    const gchar *name,
316                                                    const gchar *key, gint val,
317                                                    gboolean server_account,
318                                                    GError **err);
319
320
321 /**
322  * modest_account_mgr_set_account_bool:
323  * @self: a ModestAccountMgr instance
324  * @name: the name of the account
325  * @key: the key of the value to set
326  * @val: the value to set
327  * @server_account: if TRUE, this is a server account
328  * @err: a GError ptr, or NULL to ignore.
329  * 
330  * set a config bool for an account
331  *
332  * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
333  * @err gives details in case of error
334  */
335 gboolean        modest_account_mgr_set_bool       (ModestAccountMgr *self,
336                                                    const gchar *name,
337                                                    const gchar *key, gboolean val,
338                                                    gboolean server_account,
339                                                    GError **err);
340
341 G_END_DECLS
342
343 #endif /* __MODEST_ACCOUNT_MGR_H__ */