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