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