* make it compile again with latest Tinymail; does not work yet though.
[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-protocol-mgr.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  * some convenience structs to get bulk data about an account 
69  */
70 struct _ModestServerAccountData {
71         gchar *account_name;
72         gchar *hostname;
73         gchar *username;
74         gchar *proto;
75         gchar *password;
76 };
77 typedef struct _ModestServerAccountData ModestServerAccountData;
78
79 struct _ModestAccountData {
80         gchar *account_name;
81         gchar *full_name;
82         gchar *email;
83         gboolean enabled;
84         
85         ModestServerAccountData *transport_account;
86         ModestServerAccountData *store_account;
87 };
88 typedef struct _ModestAccountData ModestAccountData;
89
90
91
92 /**
93  * modest_ui_get_type:
94  * 
95  * get the GType for ModestAccountMgr
96  *  
97  * Returns: the GType
98  */
99 GType           modest_account_mgr_get_type       (void) G_GNUC_CONST;
100
101
102 /**
103  * modest_account_mgr_new:
104  * @modest_conf: a ModestConf instance 
105  *  
106  * Returns: a new ModestAccountMgr, or NULL in case of error
107  */
108 ModestAccountMgr*        modest_account_mgr_new            (ModestConf *modest_conf);
109
110
111
112 /**
113  * modest_account_mgr_add_account:
114  * @self: a ModestAccountMgr instance
115  * @name: the name of the account to create
116  * @store_name: the store account (ie. POP/IMAP)
117  * @transport_name: the transport account (ie. sendmail/SMTP)
118  * @err: a GError ptr, or NULL to ignore.
119  * 
120  * create a new account. the account with @name should not already exist
121  *
122  * Returns: TRUE if the creation succeeded, FALSE otherwise,
123  * @err gives details in case of error
124  */
125 gboolean        modest_account_mgr_add_account    (ModestAccountMgr *self,
126                                                    const gchar* name,
127                                                    const gchar* store_name,
128                                                    const gchar* transport_name,
129                                                    GError **err);
130
131
132 /**
133  * modest_account_mgr_add_server_account:
134  * @self: a ModestAccountMgr instance
135  * @name: name (id) of the account
136  * @hostname: the hostname
137  * @username: the username
138  * @password: the password
139  * @proto:    the protocol (imap, smtp, ...) used for this account
140  * 
141  * add a server account to the configuration.
142  * the server account with @name should not already exist
143  * 
144  * Returns: TRUE if succeeded, FALSE otherwise,
145  */
146 gboolean modest_account_mgr_add_server_account    (ModestAccountMgr *self,
147                                                    const gchar *name,
148                                                    const gchar *hostname,
149                                                    const gchar *username,
150                                                    const gchar *password,
151                                                    const gchar *proto);  
152
153 /**
154  * modest_account_mgr_remove_account:
155  * @self: a ModestAccountMgr instance
156  * @name: the name of the account to remove
157  * @err: a GError ptr, or NULL to ignore.
158  * 
159  * remove an existing account. the account with @name should already exist
160  *
161  * Returns: TRUE if the creation succeeded, FALSE otherwise,
162  * @err gives details in case of error
163  */
164 gboolean        modest_account_mgr_remove_account         (ModestAccountMgr *self,
165                                                            const gchar* name,
166                                                            gboolean server_account,
167                                                            GError **err);
168
169
170 /**
171  * modest_account_mgr_account_names:
172  * @self: a ModestAccountMgr instance
173  * @err: a GError ptr, or NULL to ignore.
174  * 
175  * list all account names
176  *
177  * Returns: a newly allocated list of account names, or NULL in case of error or
178  * if there are no accounts. The caller must free the returned GSList
179  * @err gives details in case of error
180  */
181 GSList*         modest_account_mgr_account_names    (ModestAccountMgr *self, GError **err);
182
183
184 /**
185  * modest_account_mgr_server_account_names:
186  * @self: a ModestAccountMgr instance
187  * @account_name: get only server accounts for @account_name, or NULL for any
188  * @type: get only server accounts from protocol type @type, or MODEST_PROTO_TYPE_ANY
189  * @proto: get only server account with protocol @proto, or NULL for any
190  * @only_enabled: get only enabled server accounts if TRUE
191  * 
192  * list all the server account names
193  *
194  * Returns: a newly allocated list of server account names, or NULL in case of
195  * error or if there are no server accounts. The caller must free the returned GSList
196  */
197 GSList*  modest_account_mgr_search_server_accounts  (ModestAccountMgr *self,
198                                                      const gchar*       account_name,
199                                                      ModestProtocolType type,
200                                                      const gchar*       proto);
201
202 /**
203  * modest_account_mgr_account_exists:
204  * @self: a ModestAccountMgr instance
205  * @name: the account name to check
206  * @server_account: if TRUE, this is a server account
207  * @err: a GError ptr, or NULL to ignore.
208  * 
209  * check whether account @name exists
210  *
211  * Returns: TRUE if the account with name @name exists, FALSE otherwise (or in case of error)
212  * @err gives details in case of error
213  */
214 gboolean        modest_account_mgr_account_exists         (ModestAccountMgr *self,
215                                                            const gchar *name,
216                                                            gboolean server_account,
217                                                            GError **err);
218
219 /**
220  * modest_account_mgr_get_account_data:
221  * @self: a ModestAccountMgr instance
222  * @name: the name of the account
223  * 
224  * get information about an account
225  *
226  * Returns: a ModestAccountData structure with information about the account.
227  * the data should not be changed, and be freed with modest_account_mgr_free_account_data
228  */
229 ModestAccountData *modest_account_mgr_get_account_data     (ModestAccountMgr *self,
230                                                             const gchar* name);
231
232
233 /**
234  * modest_account_mgr_free_account_data:
235  * @self: a ModestAccountMgr instance
236  * @data: a ModestAccountData instance
237  * 
238  * free the account data structure
239  */
240 void       modest_account_mgr_free_account_data     (ModestAccountMgr *self,
241                                                      ModestAccountData *data);
242
243 /**
244  * modest_account_mgr_account_set_enabled
245  * @self: a ModestAccountMgr instance
246  * @name: the account name 
247  * @enabled: if TRUE, the account will be enabled, if FALSE, it will be disabled
248  * 
249  * enable/disabled an account
250  *
251  * Returns: TRUE if it worked, FALSE otherwise
252  */
253 gboolean modest_account_mgr_account_set_enabled (ModestAccountMgr *self, const gchar* name,
254                                                  gboolean enabled);
255
256
257 /**
258  * modest_account_mgr_account_get_enabled:
259  * @self: a ModestAccountMgr instance
260  * @name: the account name to check
261  *
262  * check whether a certain account is enabled
263  *
264  * Returns: TRUE if it is enabled, FALSE otherwise
265  */
266 gboolean modest_account_mgr_account_get_enabled (ModestAccountMgr *self, const gchar* name);
267
268
269 /**
270  * modest_account_mgr_get_account_string:
271  * @self: self a ModestAccountMgr instance
272  * @name: the name of the account
273  * @key: the key of the value to retrieve
274  * @server_account: if TRUE, this is a server account
275  * @err: a GError ptr, or NULL to ignore.
276  * 
277  * get a config string from an account
278  *
279  * Returns: a newly allocated string with the value for the key,
280  * or NULL in case of error. @err gives details in case of error
281  */
282 gchar*          modest_account_mgr_get_string     (ModestAccountMgr *self,
283                                                    const gchar *name,
284                                                    const gchar *key,
285                                                    gboolean server_account,
286                                                    GError **err);
287
288
289 /**
290  * modest_account_mgr_get_account_int:
291  * @self: a ModestAccountMgr instance
292  * @name: the name of the account
293  * @key: the key of the value to retrieve
294  * @server_account: if TRUE, this is a server account
295  * @err: a GError ptr, or NULL to ignore.
296  * 
297  * get a config int from an account
298  *
299  * Returns: an integer with the value for the key, or -1 in case of
300  * error (but of course -1 does not necessarily imply an error)
301  * @err gives details in case of error
302  */
303 gint            modest_account_mgr_get_int        (ModestAccountMgr *self,
304                                                    const gchar *name,
305                                                    const gchar *key,
306                                                    gboolean server_account,
307                                                    GError **err);
308
309 /**
310  * modest_account_mgr_get_account_bool:
311  * @self: a ModestAccountMgr instance
312  * @name: the name of the account
313  * @key: the key of the value to retrieve
314  * @server_account: if TRUE, this is a server account
315  * @err: a GError ptr, or NULL to ignore.
316  * 
317  * get a config boolean from an account
318  *
319  * Returns: an boolean with the value for the key, or FALSE in case of
320  * error (but of course FALSE does not necessarily imply an error)
321  * @err gives details in case of error
322  */
323 gboolean        modest_account_mgr_get_bool       (ModestAccountMgr *self,
324                                                    const gchar *name,
325                                                    const gchar *key,
326                                                    gboolean server_account,
327                                                    GError **err);
328
329 /**
330  * modest_account_mgr_set_account_string:
331  * @self: a ModestAccountMgr instance
332  * @name: the name of the account
333  * @key: the key of the value to set
334  * @val: the value to set
335  * @server_account: if TRUE, this is a server account
336  * @err: a GError ptr, or NULL to ignore.
337  * 
338  * set a config string for an account
339  *
340  * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
341  * @err gives details in case of error
342  */
343 gboolean        modest_account_mgr_set_string     (ModestAccountMgr *self,
344                                                    const gchar *name,
345                                                    const gchar *key, const gchar* val,
346                                                    gboolean server_account,
347                                                    GError **err);
348
349 /**
350  * modest_account_mgr_set_account_int:
351  * @self: a ModestAccountMgr instance
352  * @name: the name of the account
353  * @key: the key of the value to set
354  * @val: the value to set
355  * @server_account: if TRUE, this is a server account
356  * @err: a GError ptr, or NULL to ignore.
357  * 
358  * set a config int for an account
359  *
360  * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
361  * @err gives details in case of error
362  */
363 gboolean        modest_account_mgr_set_int        (ModestAccountMgr *self,
364                                                    const gchar *name,
365                                                    const gchar *key, gint val,
366                                                    gboolean server_account,
367                                                    GError **err);
368
369
370 /**
371  * modest_account_mgr_set_account_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  * @err: a GError ptr, or NULL to ignore.
378  * 
379  * set a config bool for an account
380  *
381  * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
382  * @err gives details in case of error
383  */
384 gboolean        modest_account_mgr_set_bool       (ModestAccountMgr *self,
385                                                    const gchar *name,
386                                                    const gchar *key, gboolean val,
387                                                    gboolean server_account,
388                                                    GError **err);
389
390
391
392 G_END_DECLS
393
394 #endif /* __MODEST_ACCOUNT_MGR_H__ */