0b6873c5432a1ce8bebc9a657e99a53f85cc1222
[modest] / src / modest-account-mgr-helpers.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_HELPERS_H__
32 #define __MODEST_ACCOUNT_MGR_HELPERS_H__
33
34 #include <modest-account-mgr.h>
35 #include <modest-tny-account-store.h>
36
37 #include <tny-account.h>
38 #include <tny-store-account.h>
39 #include <tny-transport-account.h>
40
41 G_BEGIN_DECLS
42
43 typedef struct {
44         gchar            *account_name;
45         gchar            *hostname;
46         gchar            *username;
47         gchar            *uri;
48         ModestProtocol    proto; /*< The store or transport. Not ORed. */
49         gchar            *password;
50         time_t            last_updated;
51         gint             port; /* Or 0, if the default should be used. */
52         ModestProtocol   secure_auth;
53         ModestProtocol   security;
54         GSList           *options;
55 } ModestServerAccountData;
56
57 typedef struct {
58         gchar            *account_name;
59         gchar            *display_name;
60         gchar            *fullname;
61         gchar            *email;
62         gboolean         is_enabled;
63         gboolean         is_default;
64         ModestServerAccountData *transport_account;
65         ModestServerAccountData *store_account;
66 } ModestAccountData;
67
68
69
70 /**
71  * modest_account_mgr_get_account_data:
72  * @self: a ModestAccountMgr instance
73  * @name: the name of the account
74  * 
75  * get information about an account
76  *
77  * Returns: a ModestAccountData structure with information about the account.
78  * the data should not be changed, and be freed with modest_account_mgr_free_account_data
79  * The function does a sanity check, an if it's not returning NULL,
80  * it is a valid account
81  */
82 ModestAccountData *modest_account_mgr_get_account_data     (ModestAccountMgr *self,
83                                                             const gchar* name);
84
85 /**
86  * modest_account_mgr_get_default_account:
87  * @self: a ModestAccountMgr instance
88  * 
89  * get the default account name, or NULL if none is found
90  *
91  * Returns: the default account name (as newly allocated string, which
92  * must be g_free'd), or NULL
93  */
94 gchar* modest_account_mgr_get_default_account  (ModestAccountMgr *self);
95
96 /**
97  * modest_account_mgr_set_default_account:
98  * @self: a ModestAccountMgr instance
99  * @account: the name of an existing account
100  * 
101  * set the default account name (which must be valid account)
102  *
103  * Returns: TRUE if succeeded, FALSE otherwise
104  */
105 gboolean modest_account_mgr_set_default_account  (ModestAccountMgr *self,
106                                                   const gchar* account);
107
108 /**
109  * modest_account_mgr_unset_default_account:
110  * @self: a ModestAccountMgr instance
111  * @account: the name of an account
112  * 
113  * Unset the default account name, so that no account is the default.
114  *
115  * Returns: TRUE if succeeded, FALSE otherwise
116  */
117 gboolean modest_account_mgr_unset_default_account  (ModestAccountMgr *self);
118
119 /**
120  * modest_account_mgr_set_first_account_as_default:
121  * @self: a ModestAccountMgr instance
122  * 
123  * Guarantees that at least one account, if there are any accounts, is the default,
124  * so that modest_account_mgr_get_default_account() will return non-NULL if there 
125  * are any accounts.
126  *
127  * Returns: TRUE if succeeded, FALSE otherwise
128  */
129 gboolean
130 modest_account_mgr_set_first_account_as_default  (ModestAccountMgr *self);
131
132 /**
133  * modest_account_mgr_free_account_data:
134  * @self: a ModestAccountMgr instance
135  * @data: a ModestAccountData instance
136  * 
137  * free the account data structure
138  */
139 void       modest_account_mgr_free_account_data     (ModestAccountMgr *self,
140                                                      ModestAccountData *data);
141
142 /**
143  * modest_account_mgr_set_enabled
144  * @self: a ModestAccountMgr instance
145  * @name: the account name 
146  * @enabled: if TRUE, the account will be enabled, if FALSE, it will be disabled
147  * 
148  * enable/disabled an account
149  *
150  * Returns: TRUE if it worked, FALSE otherwise
151  */
152 gboolean modest_account_mgr_set_enabled (ModestAccountMgr *self, const gchar* name,
153                                          gboolean enabled);
154
155 /**
156  * modest_account_mgr_get_enabled:
157  * @self: a ModestAccountMgr instance
158  * @name: the account name to check
159  *
160  * check whether a certain account is enabled
161  *
162  * Returns: TRUE if it is enabled, FALSE otherwise
163  */
164 gboolean modest_account_mgr_get_enabled (ModestAccountMgr *self, const gchar* name);
165
166 /**
167  * modest_account_mgr_get_display_name:
168  * @self: a ModestAccountMgr instance
169  * @name: the account name to check
170  *
171  * Return the human-readable account title for this account, or NULL.
172  */
173 gchar* modest_account_mgr_get_display_name (ModestAccountMgr *self, 
174         const gchar* name);
175
176
177 /**
178  * modest_account_mgr_set_signature
179  * @self: a ModestAccountMgr instance
180  * @name: the account name to check
181  * @signature: the signature text 
182  * @use_signature: Whether the signature should be used.
183  * 
184  * Sets the signature text for the account.
185  *
186  * Returns: TRUE if it worked, FALSE otherwise
187  */
188 gboolean modest_account_mgr_set_signature (ModestAccountMgr *self, const gchar* name, 
189         const gchar* signature, gboolean use_signature);
190
191 /**
192  * modest_account_mgr_get_signature:
193  * @self: a ModestAccountMgr instance
194  * @name: the account name
195  * @use_signature: Pointer to a gboolean taht will be set to TRUE if the signature should be used.
196  *
197  * Gets the signature text for this account.
198  *
199  * Returns: The signature text, which should be freed with g_free().
200  */
201 gchar* modest_account_mgr_get_signature (ModestAccountMgr *self, const gchar* name, 
202         gboolean* use_signature);
203
204 /**
205  * modest_account_mgr_set_connection_specific_smtp
206  * @self: a ModestAccountMgr instance
207  * @name: the account name
208  * @connection_name: A libconic IAP connection name
209  * @server_account_name: a server account name to use for this connection.
210  * 
211  * Specify a server account to use with the specific connection for this account.
212  *
213  * Returns: TRUE if it worked, FALSE otherwise
214  */
215 gboolean modest_account_mgr_set_connection_specific_smtp (ModestAccountMgr *self, const gchar* name,
216                                          const gchar* connection_name, const gchar* server_account_name);
217
218 /**
219  * modest_account_mgr_remove_connection_specific_smtp
220  * @self: a ModestAccountMgr instance
221  * @name: the account name
222  * @connection_name: A libconic IAP connection name
223  * 
224  * Disassacoiate a server account to use with the specific connection for this account.
225  *
226  * Returns: TRUE if it worked, FALSE otherwise
227  */                              
228 gboolean modest_account_mgr_remove_connection_specific_smtp (ModestAccountMgr *self, const gchar* name,
229                                          const gchar* connection_name);
230
231 /**
232  * modest_account_mgr_get_connection_specific_smtp
233  * @self: a ModestAccountMgr instance
234  * @name: the account name
235  * @connection_name: A libconic IAP connection name
236  * 
237  * Retrieve a server account to use with this specific connection for this account.
238  *
239  * Returns: a server account name to use for this connection, or NULL if none is specified.
240  */                      
241 gchar* modest_account_mgr_get_connection_specific_smtp (ModestAccountMgr *self, const gchar* name,
242                                          const gchar* connection_name);
243
244
245 /**
246  * modest_server_account_get_username:
247  * @self: a ModestAccountMgr instance
248  * @account_name: The name of a server account.
249  *
250  * Gets the username this server account.
251  *
252  * Returns: The username.
253  */
254 gchar*
255 modest_server_account_get_username (ModestAccountMgr *self, const gchar* account_name);
256
257 /**
258  * modest_server_account_set_username:
259  * @self: a ModestAccountMgr instance
260  * @account_name: The name of a server account.
261  * @username: The new username.
262  *
263  * Sets the username this server account.
264  */
265 void
266 modest_server_account_set_username (ModestAccountMgr *self, const gchar* account_name, 
267         const gchar* username);
268
269 /**
270  * modest_server_account_get_username_has_succeeded:
271  * @self: a ModestAccountMgr instance
272  * @account_name: The name of a server account.
273  *
274  * Whether a connection has ever been successfully made to this account with 
275  * the current username. This can be used to avoid asking again for the username 
276  * when asking a second time for a non-stored password.
277  *
278  * Returns: TRUE if the username is known to be correct.
279  */
280 gboolean
281 modest_server_account_get_username_has_succeeded (ModestAccountMgr *self, const gchar* account_name);
282
283 /**
284  * modest_server_account_set_username_has_succeeded:
285  * @self: a ModestAccountMgr instance
286  * @account_name: The name of a server account.
287  * @succeeded: Whether the username has succeeded
288  *
289  * Sets whether the username is known to be correct.
290  */
291 void
292 modest_server_account_set_username_has_succeeded (ModestAccountMgr *self, const gchar* account_name, 
293         gboolean succeeded);
294         
295 /**
296  * modest_server_account_set_password:
297  * @self: a ModestAccountMgr instance
298  * @account_name: The name of a server account.
299  * @password: The new password.
300  *
301  * Sets the password this server account.
302  */
303 void
304 modest_server_account_set_password (ModestAccountMgr *self, const gchar* account_name, 
305         const gchar* password);
306                          
307
308 /**
309  * modest_server_account_modest_server_account_get_hostnameget_username:
310  * @self: a ModestAccountMgr instance
311  * @account_name: The name of a server account.
312  *
313  * Gets the hostname this server account.
314  *
315  * Returns: The hostname.
316  */
317 gchar*
318 modest_server_account_get_hostname (ModestAccountMgr *self, const gchar* account_name);
319
320
321 /**
322  * modest_server_account_get_secure_auth:
323  * @self: a ModestAccountMgr instance
324  * @account_name: The name of a server account.
325  *
326  * Gets the secure authentication method for this server account.
327  *
328  * Returns: The secure authentication enum value.
329  */
330 ModestProtocol
331 modest_server_account_get_secure_auth (ModestAccountMgr *self, const gchar* account_name);
332
333 /**
334  * modest_server_account_data_get_secure_auth:
335  * @self: a ModestAccountMgr instance
336  * @account_name: The name of a server account.
337  * @secure_auth: The secure authentication enum value.
338  *
339  * Gets the secure authentication method for this server account.
340  */
341 void
342 modest_server_account_set_secure_auth (ModestAccountMgr *self, const gchar* account_name, 
343         ModestProtocol secure_auth);
344         
345 /**
346  * modest_server_account_data_get_security:
347  * @self: a ModestAccountMgr instance
348  * @account_name: The name of a server account.
349  *
350  * Gets the security method for this server account.
351  *
352  * Returns: The security enum value.
353  */
354 ModestProtocol
355 modest_server_account_get_security (ModestAccountMgr *self, const gchar* account_name);
356
357 /**
358  * modest_server_account_set_security:
359  * @self: a ModestAccountMgr instance
360  * @secure_auth: The security enum value.
361  *
362  * Gets the security method for this server account.
363  */
364 void
365 modest_server_account_set_security (ModestAccountMgr *self, const gchar* account_name, 
366         ModestProtocol security);
367
368 ModestServerAccountData*
369 modest_account_mgr_get_server_account_data (ModestAccountMgr *self, const gchar* name);
370
371 void
372 modest_account_mgr_free_server_account_data (ModestAccountMgr *self,
373                                              ModestServerAccountData* data);
374         
375 #if 0
376 /**
377  * modest_account_mgr_get_account_option:
378  * @self: a ModestAccountMgr instance
379  * @account_name: the account name to check
380  * @account_name: the option name to check
381  *
382  * Returns: The account option value. This must be freed with g_free().
383  */
384 gchar* modest_account_mgr_get_server_account_option (ModestAccountMgr *self, 
385         const gchar* account_name, const gchar* option_name);
386
387 /**
388  * modest_server_account_data_get_option_value:
389  * @options_list: a ModestServerAccountData::options list.
390  * @option_name: the option name to check
391  *
392  * Returns: The account option value. This must be freed with g_free().
393  */
394 gchar* modest_server_account_data_get_option_string (GSList* options_list, const gchar* option_name);
395
396 /**
397  * modest_server_account_data_get_option_bool:
398  * @options_list: a ModestServerAccountData::options list.
399  * @option_name: the option name to check
400  *
401  * Returns: Whether the account option is present.
402  */
403 gboolean modest_server_account_data_get_option_bool (GSList* options_list, const gchar* option_name);
404 #endif
405
406 /**
407  * modest_account_mgr_get_from_string
408  * @self: a #ModestAccountMgr instance
409  * @name: the account name
410  *
411  * get the From: string for some account; ie. "Foo Bar" <foo.bar@cuux.yy>"
412  *
413  * Returns: the newly allocated from-string, or NULL in case of error
414  */
415 gchar * modest_account_mgr_get_from_string (ModestAccountMgr *self, const gchar* name);
416
417
418 /**
419  * modest_account_mgr_get_unused_account_name
420  * @self: a #ModestAccountMgr instance
421  * @name: The initial account name
422  *
423  * get an unused account name, based on a starting string.
424  *
425  * Returns: the newly allocated name.
426  */
427 gchar*
428 modest_account_mgr_get_unused_account_name (ModestAccountMgr *self, const gchar* starting_name,
429         gboolean server_account);
430
431 /**
432  * modest_account_mgr_get_unused_account_display name
433  * @self: a #ModestAccountMgr instance
434  * @name: The initial account display name
435  *
436  * get an unused account display name, based on a starting string.
437  *
438  * Returns: the newly allocated name.
439  */
440 gchar*
441 modest_account_mgr_get_unused_account_display_name (ModestAccountMgr *self, const gchar* starting_name);
442
443 G_END_DECLS
444
445 #endif /* __MODEST_ACCOUNT_MGR_H__ */