13810812c3b1158208d1a610bd22c317d028706a
[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-defs.h>
37 #include <modest-protocol-info.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 struct _ModestAccountMgr {
53          GObject parent;
54 };
55
56 struct _ModestAccountMgrClass {
57         GObjectClass parent_class;
58
59         void (* account_inserted)  (ModestAccountMgr *obj, 
60                                     const gchar* account,
61                                     gpointer user_data);
62
63         void (* account_removed)   (ModestAccountMgr *obj, 
64                                     const gchar* account,
65                                     gpointer user_data);
66         
67         void (* account_changed)   (ModestAccountMgr *obj, 
68                                     const gchar* account,
69                                     gpointer user_data);
70
71         void (* account_busy_changed)   (ModestAccountMgr *obj, 
72                                          const gchar* account,
73                                          gboolean busy,
74                                          gpointer user_data);   
75
76         void (* default_account_changed)(ModestAccountMgr *obj, 
77                                          gpointer user_data);
78
79         void (* display_name_changed)   (ModestAccountMgr *obj, 
80                                          const gchar *account,
81                                          gpointer user_data);
82 };
83
84 /**
85  * modest_account_mgr_get_type:
86  * 
87  * get the GType for ModestAccountMgr
88  *  
89  * Returns: the GType
90  */
91 GType           modest_account_mgr_get_type       (void) G_GNUC_CONST;
92
93
94 /**
95  * modest_account_mgr_new:
96  * @modest_conf: a ModestConf instance 
97  *  
98  * Returns: a new ModestAccountMgr, or NULL in case of error
99  */
100 ModestAccountMgr*        modest_account_mgr_new            (ModestConf *modest_conf);
101
102
103
104 /**
105  * modest_account_mgr_add_account:
106  * @self: a ModestAccountMgr instance
107  * @name: name (id) of the account, which is a valid UTF8 string that does not contain '/'
108  * @store_name: the store account (ie. POP/IMAP)
109  * @transport_name: the transport account (ie. sendmail/SMTP)
110  * @enabled: Whether the account should be enabled initially.
111  * 
112  * Create a new account. The account with @name should not already exist. The @name will 
113  * be used as the initial display name of the new account.
114  *
115  * Returns: TRUE if the creation succeeded, FALSE otherwise,
116  */
117 gboolean        modest_account_mgr_add_account    (ModestAccountMgr *self,
118                                                    const gchar* name,
119                                                    const gchar* store_name,
120                                                    const gchar* transport_name,
121                                                    gboolean enabled);
122
123 /**
124  * modest_account_mgr_add_server_account:
125  * @self: a ModestAccountMgr instance
126  * @name: name (id) of the account, which is a valid UTF8 string that does not contain '/'
127  * @hostname: the hostname
128  * @portnumber: the portnumber, or 0 for default
129  * @username: the username
130  * @password: the password
131  * @proto:    the protocol (imap, smtp, ...) used for this account
132  * @security: the security options, (SSL, TLS ...) used to access the server
133  * @auth: the authentication method (password, none ...) used to access the server
134  * 
135  * add a server account to the configuration.
136  * the server account with @name should not already exist
137  * 
138  * Returns: TRUE if succeeded, FALSE otherwise,
139  */
140 gboolean modest_account_mgr_add_server_account    (ModestAccountMgr *self,
141                                                    const gchar *name,
142                                                    const gchar *hostname,
143                                                    const guint portnumber,
144                                                    const gchar *username,
145                                                    const gchar *password,
146                                                    ModestTransportStoreProtocol proto,
147                                                    ModestConnectionProtocol security,
148                                                    ModestAuthProtocol auth);
149
150
151 /**
152  * modest_account_mgr_add_server_account_uri:
153  * @self: a ModestAccountMgr instance
154  * @name: name (id) of the account, which is a valid UTF8 string that does not contain '/'
155  * @proto:    the protocol (imap, smtp, ...) used for this account
156  * @uri: the URI
157  * 
158  * add a server account to the configuration, based on the account-URI
159  * 
160  * Returns: TRUE if succeeded, FALSE otherwise,
161  */
162 gboolean modest_account_mgr_add_server_account_uri    (ModestAccountMgr *self,
163                                                        const gchar *name,
164                                                        ModestTransportStoreProtocol proto,
165                                                        const gchar* uri);
166
167 /**
168  * modest_account_mgr_remove_account:
169  * @self: a ModestAccountMgr instance
170  * @name: the name of the account to remove
171  * @err: a #GError ptr, or NULL to ignore.
172  * 
173  * remove an existing account. the account with @name should already exist; note
174  * that when deleting an account, also the corresponding server accounts will
175  * be deleted
176  *
177  * Returns: TRUE if the creation succeeded, FALSE otherwise,
178  * @err gives details in case of error
179  */
180 gboolean        modest_account_mgr_remove_account         (ModestAccountMgr *self,
181                                                            const gchar* name);
182
183 /**
184  * modest_account_mgr_account_names:
185  * @self: a ModestAccountMgr instance
186  * @only_enabled: Whether only enabled accounts should be returned.
187  * 
188  * list all account names
189  *
190  * Returns: a newly allocated list of account names, or NULL in case of error or
191  * if there are no accounts. The caller must free the returned GSList.
192  *
193  */
194 GSList*         modest_account_mgr_account_names    (ModestAccountMgr *self,
195                                                      gboolean only_enabled);
196
197 /**
198  * modest_account_mgr_free_account_names:
199  * @account_name: a gslist of account names
200  * 
201  * list all account names
202  *
203  * free the list of account names
204  */
205 void            modest_account_mgr_free_account_names    (GSList *account_names);
206                                                           
207
208 /**
209  * modest_account_mgr_account_exists:
210  * @self: a ModestAccountMgr instance
211  * @name: the account name to check
212  * @server_account: if TRUE, this is a server account
213  * 
214  * check whether account @name exists. Note that this does not check the display name.
215  *
216  * Returns: TRUE if the account with name @name exists, FALSE otherwise (or in case of error)
217  */
218 gboolean        modest_account_mgr_account_exists         (ModestAccountMgr *self,
219                                                            const gchar *name,
220                                                            gboolean server_account);
221
222 /**
223  * modest_account_mgr_account_exists:
224  * @self: a ModestAccountMgr instance
225  * @name: the account name to check
226  * 
227  * check whether a non-server account with the @display_name exists.
228  *
229  * Returns: TRUE if the account with name @name exists, FALSE otherwise (or in case of error)
230  */
231 gboolean        modest_account_mgr_account_with_display_name_exists (ModestAccountMgr *self,
232                                                                      const gchar *display_name);
233
234 /**
235  * modest_account_mgr_unset:
236  * @self: a ModestAccountMgr instance
237  * @name: the name of the account
238  * @key: the key of the value to unset
239  * @server_account: if TRUE, this is a server account
240  * @err: a GError ptr, or NULL to ignore.
241  * 
242  * unsets the config value of an account and all their children keys
243  *
244  * Returns: TRUE if unsetting the value succeeded, or FALSE in case of error.
245  * @err gives details in case of error
246  */
247 gboolean        modest_account_mgr_unset           (ModestAccountMgr *self,
248                                                     const gchar *name,
249                                                     const gchar *key,
250                                                     gboolean server_account);
251
252 /**
253  * modest_account_mgr_has_accounts:
254  * @self: a ModestAccountMgr instance
255  * @enabled: TRUE to search for enabled accounts only
256  * 
257  * Checks if any accounts exist
258  *
259  * Returns: TRUE if accounts exist, FALSE otherwise
260  */
261
262 gboolean modest_account_mgr_has_accounts (ModestAccountMgr* self, gboolean enabled);
263
264 /**
265  * modest_account_mgr_set_account_busy
266  * @self: a ModestAccountMgr instance
267  * @account_name: name of the account
268  * @busy: whether to set busy or not busy
269  * 
270  * Changes the busy flag of an account
271  *
272  */
273
274 void modest_account_mgr_set_account_busy(ModestAccountMgr* self, const gchar* account_name, 
275                                                                                                                                                 gboolean busy);
276
277 /**
278  * modest_account_mgr_account_is_busy
279  * @self: a ModestAccountMgr instance
280  * @account_name: name of the account
281  * 
282  * Returns: If the account is currently busy or not
283  *
284  */
285 gboolean modest_account_mgr_account_is_busy (ModestAccountMgr* self, 
286                                              const gchar* account_name);
287
288
289 void modest_account_mgr_notify_account_update (ModestAccountMgr* self, 
290                                                const gchar *server_account_name);
291
292 /**
293  * modest_account_mgr_set_default_account:
294  * @self: a ModestAccountMgr instance
295  * @account: the name of an existing account
296  * 
297  * set the default account name (which must be valid account)
298  *
299  * Returns: TRUE if succeeded, FALSE otherwise
300  */
301 gboolean modest_account_mgr_set_default_account  (ModestAccountMgr *self,
302                                                   const gchar* account);
303
304 /**
305  * modest_account_mgr_get_default_account:
306  * @self: a ModestAccountMgr instance
307  * 
308  * get the default account name, or NULL if none is found
309  *
310  * Returns: the default account name (as newly allocated string, which
311  * must be g_free'd), or NULL
312  */
313 gchar* modest_account_mgr_get_default_account  (ModestAccountMgr *self);
314
315 /**
316  * modest_account_mgr_get_display_name:
317  * @self: a ModestAccountMgr instance
318  * @name: the account name to check
319  *
320  * Return the human-readable account title for this account, or NULL.
321  */
322 gchar* modest_account_mgr_get_display_name (ModestAccountMgr *self, 
323                                             const gchar* name);
324
325 void  modest_account_mgr_set_display_name (ModestAccountMgr *self, 
326                                            const gchar *account_name,
327                                            const gchar *display_name);
328
329
330 G_END_DECLS
331
332 #endif /* __MODEST_ACCOUNT_MGR_H__ */