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