* added licensing boilerplate to source files
[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 /* modest-account-mgr.h */
32
33 #ifndef __MODEST_ACCOUNT_MGR_H__
34 #define __MODEST_ACCOUNT_MGR_H__
35
36 #include <glib-object.h>
37 #include "modest-conf.h"
38 #include "modest-account-keys.h"
39 #include "modest-proto.h"
40
41 G_BEGIN_DECLS
42
43 /* convenience macros */
44 #define MODEST_TYPE_ACCOUNT_MGR             (modest_account_mgr_get_type())
45 #define MODEST_ACCOUNT_MGR(obj)             (G_TYPE_CHECK_INSTANCE_CAST((obj),MODEST_TYPE_ACCOUNT_MGR,ModestAccountMgr))
46 #define MODEST_ACCOUNT_MGR_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass),MODEST_TYPE_ACCOUNT_MGR,GObject))
47 #define MODEST_IS_ACCOUNT_MGR(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj),MODEST_TYPE_ACCOUNT_MGR))
48 #define MODEST_IS_ACCOUNT_MGR_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass),MODEST_TYPE_ACCOUNT_MGR))
49 #define MODEST_ACCOUNT_MGR_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS((obj),MODEST_TYPE_ACCOUNT_MGR,ModestAccountMgrClass))
50
51 typedef struct _ModestAccountMgr      ModestAccountMgr;
52 typedef struct _ModestAccountMgrClass ModestAccountMgrClass;
53
54
55
56 struct _ModestAccountMgr {
57          GObject parent;
58         /* insert public members, if any */
59 };
60
61 struct _ModestAccountMgrClass {
62         GObjectClass parent_class;
63         /* insert signal callback declarations, eg. */
64         /* void (* my_event) (ModestAccountMgr* obj); */
65 };
66
67
68 /**
69  * modest_ui_get_type:
70  * 
71  * get the GType for ModestAccountMgr
72  *  
73  * Returns: the GType
74  */
75 GType           modest_account_mgr_get_type       (void) G_GNUC_CONST;
76
77
78 /**
79  * modest_account_mgr_new:
80  * @modest_conf: a ModestConf instance 
81  *  
82  * Returns: a new ModestAccountMgr, or NULL in case of error
83  */
84 GObject*        modest_account_mgr_new            (ModestConf *modest_conf);
85
86
87
88 /**
89  * modest_account_mgr_add_account:
90  * @self: a ModestAccountMgr instance
91  * @name: the name of the account to create
92  * @store_name: the store account (ie. POP/IMAP)
93  * @transport_name: the transport account (ie. sendmail/SMTP)
94  * @err: a GError ptr, or NULL to ignore.
95  * 
96  * create a new account. the account with @name should not already exist
97  *
98  * Returns: TRUE if the creation succeeded, FALSE otherwise,
99  * @err gives details in case of error
100  */
101 gboolean        modest_account_mgr_add_account    (ModestAccountMgr *self,
102                                                    const gchar* name,
103                                                    const gchar* store_name,
104                                                    const gchar* transport_name,
105                                                    GError **err);
106 /**
107  * modest_account_mgr_remove_account:
108  * @self: a ModestAccountMgr instance
109  * @name: the name of the account to remove
110  * @err: a GError ptr, or NULL to ignore.
111  * 
112  * remove an existing account. the account with @name should already exist
113  *
114  * Returns: TRUE if the creation succeeded, FALSE otherwise,
115  * @err gives details in case of error
116  */
117 gboolean        modest_account_mgr_remove_account         (ModestAccountMgr *self,
118                                                            const gchar* name,
119                                                            GError **err);
120
121
122 /**
123  * modest_account_mgr_add_server_account:
124  * @self: a ModestAccountMgr instance
125  * @name: name (id) of the account
126  * @hostname: the hostname
127  * @username: the username
128  * @password: the password
129  * @proto:    the protocol (imap, smtp, ...) used for this account
130  * 
131  * add a server account to the configuration.
132  * the server account with @name should not already exist
133  * 
134  * Returns: TRUE if succeeded, FALSE otherwise,
135  */
136 gboolean modest_account_mgr_add_server_account    (ModestAccountMgr *self,
137                                                    const gchar *name,
138                                                    const gchar *hostname,
139                                                    const gchar *username,
140                                                    const gchar *password,
141                                                    const gchar *proto);  
142
143 /**
144  * modest_account_mgr_remove_server_account:
145  * @self: a ModestAccountMgr instance
146  * @name: the name for the server account to remove
147  * @err: a GError ptr, or NULL to ignore.
148  * 
149  * remove a server account from the configuration
150  * the server account with @name should exist
151  *
152  * Returns: TRUE if the removal succeeded, FALSE otherwise,
153  * @err gives details in case of error
154  */
155 gboolean        modest_account_mgr_remove_server_account    (ModestAccountMgr *self,
156                                                              const gchar *name,
157                                                              GError **err);
158
159 /**
160  * modest_account_mgr_account_names:
161  * @self: a ModestAccountMgr instance
162  * @err: a GError ptr, or NULL to ignore.
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  * @err gives details in case of error
169  */
170 GSList*         modest_account_mgr_account_names    (ModestAccountMgr *self, GError **err);
171
172
173 /**
174  * modest_account_mgr_server_account_names:
175  * @self: a ModestAccountMgr instance
176  * @account_name: get only server accounts for @account_name, or NULL for any
177  * @type: get only server accounts from protocol type @type, or MODEST_PROTO_TYPE_ANY
178  * @proto: get only server account with protocol @proto, or NULL for any
179  * @only_enabled: get only enabled server accounts if TRUE
180  * 
181  * list all the server account names
182  *
183  * Returns: a newly allocated list of server account names, or NULL in case of
184  * error or if there are no server accounts. The caller must free the returned GSList
185  */
186 GSList*  modest_account_mgr_server_account_names   (ModestAccountMgr *self,
187                                                     const gchar*    account_name,
188                                                     ModestProtoType type,
189                                                     const gchar*    proto,
190                                                     gboolean only_enabled);
191
192 /**
193  * modest_account_mgr_account_exists:
194  * @self: a ModestAccountMgr instance
195  * @name: the account name to check
196  * @err: a GError ptr, or NULL to ignore.
197  * 
198  * check whether account @name exists
199  *
200  * Returns: TRUE if the account with name @name exists, FALSE otherwise (or in case of error)
201  * @err gives details in case of error
202  */
203 gboolean        modest_account_mgr_account_exists         (ModestAccountMgr *self,
204                                                            const gchar *name,
205                                                            GError **err);
206                                                            
207 gboolean        modest_account_mgr_server_account_exists          (ModestAccountMgr *self,
208                                                                    const gchar *name,
209                                                                    GError **err);
210
211
212
213 /* account specific functions */
214
215 /**
216  * modest_account_mgr_get_account_string:
217  * @self: self a ModestAccountMgr instance
218  * @name: the name of the account
219  * @key: the key of the value to retrieve
220  * @err: a GError ptr, or NULL to ignore.
221  * 
222  * get a config string from an account
223  *
224  * Returns: a newly allocated string with the value for the key,
225  * or NULL in case of error. @err gives details in case of error
226  */
227 gchar*          modest_account_mgr_get_account_string     (ModestAccountMgr *self,
228                                                            const gchar *name,
229                                                            const gchar *key, GError **err);
230
231 gchar*          modest_account_mgr_get_server_account_string     (ModestAccountMgr *self,
232                                                            const gchar *name,
233                                                            const gchar *key, GError **err);
234
235 /**
236  * modest_account_mgr_get_account_int:
237  * @self: a ModestAccountMgr instance
238  * @name: the name of the account
239  * @key: the key of the value to retrieve
240  * @err: a GError ptr, or NULL to ignore.
241  * 
242  * get a config int from an account
243  *
244  * Returns: an integer with the value for the key, or -1 in case of
245  * error (but of course -1 does not necessarily imply an error)
246  * @err gives details in case of error
247  */
248 gint            modest_account_mgr_get_account_int        (ModestAccountMgr *self,
249                                                            const gchar *name,
250                                                            const gchar *key, GError **err);
251
252 gint            modest_account_mgr_get_server_account_int        (ModestAccountMgr *self,
253                                                            const gchar *name,
254                                                            const gchar *key, GError **err);
255
256
257 /**
258  * modest_account_mgr_get_account_bool:
259  * @self: a ModestAccountMgr instance
260  * @name: the name of the account
261  * @key: the key of the value to retrieve
262  * @err: a GError ptr, or NULL to ignore.
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  * @err gives details in case of error
269  */
270 gboolean        modest_account_mgr_get_account_bool       (ModestAccountMgr *self,
271                                                            const gchar *name,
272                                                            const gchar *key, GError **err);
273
274 gboolean        modest_account_mgr_get_server_account_bool       (ModestAccountMgr *self,
275                                                                   const gchar *name,
276                                                                   const gchar *key, GError **err);
277
278 /**
279  * modest_account_mgr_set_account_string:
280  * @self: a ModestAccountMgr instance
281  * @name: the name of the account
282  * @key: the key of the value to set
283  * @val: the value to set
284  * @err: a GError ptr, or NULL to ignore.
285  * 
286  * set a config string for an account
287  *
288  * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
289  * @err gives details in case of error
290  */
291 gboolean        modest_account_mgr_set_account_string     (ModestAccountMgr *self,
292                                                            const gchar *name,
293                                                            const gchar *key, const gchar* val,
294                                                            GError **err);
295
296 gboolean        modest_account_mgr_set_server_account_string     (ModestAccountMgr *self,
297                                                            const gchar *name,
298                                                            const gchar *key, const gchar* val,
299                                                            GError **err);
300
301
302 /**
303  * modest_account_mgr_set_account_int:
304  * @self: a ModestAccountMgr instance
305  * @name: the name of the account
306  * @key: the key of the value to set
307  * @val: the value to set
308  * @err: a GError ptr, or NULL to ignore.
309  * 
310  * set a config int for an account
311  *
312  * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
313  * @err gives details in case of error
314  */
315 gboolean        modest_account_mgr_set_account_int        (ModestAccountMgr *self,
316                                                            const gchar *name,
317                                                            const gchar *key, gint val,
318                                                            GError **err);
319
320 gboolean        modest_account_mgr_set_server_account_int        (ModestAccountMgr *self,
321                                                                   const gchar *name,
322                                                                   const gchar *key, gint val,
323                                                                   GError **err);
324
325
326 /**
327  * modest_account_mgr_set_account_bool:
328  * @self: a ModestAccountMgr instance
329  * @name: the name of the account
330  * @key: the key of the value to set
331  * @val: the value to set
332  * @err: a GError ptr, or NULL to ignore.
333  * 
334  * set a config bool for an account
335  *
336  * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
337  * @err gives details in case of error
338  */
339 gboolean        modest_account_mgr_set_account_bool       (ModestAccountMgr *self,
340                                                            const gchar *name,
341                                                            const gchar *key, gboolean val,
342                                                            GError **err);
343
344 gboolean        modest_account_mgr_set_server_account_bool       (ModestAccountMgr *self,
345                                                                   const gchar *name,
346                                                                   const gchar *key, gboolean val,
347                                                                   GError **err);
348
349
350 G_END_DECLS
351
352 #endif /* __MODEST_ACCOUNT_MGR_H__ */