2007-04-19 Murray Cumming <murrayc@murrayc.com>
[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_get_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_free_account_data:
110  * @self: a ModestAccountMgr instance
111  * @data: a ModestAccountData instance
112  * 
113  * free the account data structure
114  */
115 void       modest_account_mgr_free_account_data     (ModestAccountMgr *self,
116                                                      ModestAccountData *data);
117
118 /**
119  * modest_account_mgr_set_enabled
120  * @self: a ModestAccountMgr instance
121  * @name: the account name 
122  * @enabled: if TRUE, the account will be enabled, if FALSE, it will be disabled
123  * 
124  * enable/disabled an account
125  *
126  * Returns: TRUE if it worked, FALSE otherwise
127  */
128 gboolean modest_account_mgr_set_enabled (ModestAccountMgr *self, const gchar* name,
129                                          gboolean enabled);
130
131 /**
132  * modest_account_mgr_get_enabled:
133  * @self: a ModestAccountMgr instance
134  * @name: the account name to check
135  *
136  * check whether a certain account is enabled
137  *
138  * Returns: TRUE if it is enabled, FALSE otherwise
139  */
140 gboolean modest_account_mgr_get_enabled (ModestAccountMgr *self, const gchar* name);
141
142 /**
143  * modest_account_mgr_set_connection_specific_smtp
144  * @self: a ModestAccountMgr instance
145  * @name: the account name
146  * @connection_name: A libconic IAP connection name
147  * @server_account_name: a server account name to use for this connection.
148  * 
149  * Specify a server account to use with the specific connection for this account.
150  *
151  * Returns: TRUE if it worked, FALSE otherwise
152  */
153 gboolean modest_account_mgr_set_connection_specific_smtp (ModestAccountMgr *self, const gchar* name,
154                                          const gchar* connection_name, const gchar* server_account_name);
155
156 /**
157  * modest_account_mgr_remove_connection_specific_smtp
158  * @self: a ModestAccountMgr instance
159  * @name: the account name
160  * @connection_name: A libconic IAP connection name
161  * 
162  * Disassacoiate a server account to use with the specific connection for this account.
163  *
164  * Returns: TRUE if it worked, FALSE otherwise
165  */                              
166 gboolean modest_account_mgr_remove_connection_specific_smtp (ModestAccountMgr *self, const gchar* name,
167                                          const gchar* connection_name);
168
169 /**
170  * modest_account_mgr_get_connection_specific_smtp
171  * @self: a ModestAccountMgr instance
172  * @name: the account name
173  * @connection_name: A libconic IAP connection name
174  * 
175  * Retrieve a server account to use with this specific connection for this account.
176  *
177  * Returns: a server account name to use for this connection, or NULL if none is specified.
178  */                      
179 gchar* modest_account_mgr_get_connection_specific_smtp (ModestAccountMgr *self, const gchar* name,
180                                          const gchar* connection_name);
181                                          
182 /**
183  * modest_server_account_get_secure_auth:
184  * @self: a ModestAccountMgr instance
185  * @account_name: The name of a server account.
186  *
187  * Gets the secure authentication method for this server account.
188  *
189  * Returns: The secure authentication enum value.
190  */
191 ModestProtocol
192 modest_server_account_get_secure_auth (ModestAccountMgr *self, const gchar* account_name);
193
194 /**
195  * modest_server_account_data_get_secure_auth:
196  * @self: a ModestAccountMgr instance
197  * @account_name: The name of a server account.
198  * @secure_auth: The secure authentication enum value.
199  *
200  * Gets the secure authentication method for this server account.
201  */
202 void
203 modest_server_account_set_secure_auth (ModestAccountMgr *self, const gchar* account_name, 
204         ModestProtocol secure_auth);
205         
206 /**
207  * modest_server_account_data_get_security:
208  * @self: a ModestAccountMgr instance
209  * @account_name: The name of a server account.
210  *
211  * Gets the security method for this server account.
212  *
213  * Returns: The security enum value.
214  */
215 ModestProtocol
216 modest_server_account_get_security (ModestAccountMgr *self, const gchar* account_name);
217
218 /**
219  * modest_server_account_set_security:
220  * @self: a ModestAccountMgr instance
221  * @secure_auth: The security enum value.
222  *
223  * Gets the security method for this server account.
224  */
225 void
226 modest_server_account_set_security (ModestAccountMgr *self, const gchar* account_name, 
227         ModestProtocol security);
228
229 ModestServerAccountData*
230 modest_account_mgr_get_server_account_data (ModestAccountMgr *self, const gchar* name);
231
232 void
233 modest_account_mgr_free_server_account_data (ModestAccountMgr *self,
234                                              ModestServerAccountData* data);
235         
236 #if 0
237 /**
238  * modest_account_mgr_get_account_option:
239  * @self: a ModestAccountMgr instance
240  * @account_name: the account name to check
241  * @account_name: the option name to check
242  *
243  * Returns: The account option value. This must be freed with g_free().
244  */
245 gchar* modest_account_mgr_get_server_account_option (ModestAccountMgr *self, 
246         const gchar* account_name, const gchar* option_name);
247
248 /**
249  * modest_server_account_data_get_option_value:
250  * @options_list: a ModestServerAccountData::options list.
251  * @option_name: the option name to check
252  *
253  * Returns: The account option value. This must be freed with g_free().
254  */
255 gchar* modest_server_account_data_get_option_string (GSList* options_list, const gchar* option_name);
256
257 /**
258  * modest_server_account_data_get_option_bool:
259  * @options_list: a ModestServerAccountData::options list.
260  * @option_name: the option name to check
261  *
262  * Returns: Whether the account option is present.
263  */
264 gboolean modest_server_account_data_get_option_bool (GSList* options_list, const gchar* option_name);
265 #endif
266
267 /**
268  * modest_account_mgr_get_from_string
269  * @self: a #ModestAccountMgr instance
270  * @name: the account name
271  *
272  * get the From: string for some account; ie. "Foo Bar" <foo.bar@cuux.yy>"
273  *
274  * Returns: the newly allocated from-string, or NULL in case of error
275  */
276 gchar * modest_account_mgr_get_from_string (ModestAccountMgr *self, const gchar* name);
277
278
279 /**
280  * modest_account_mgr_get_unused_account_name
281  * @self: a #ModestAccountMgr instance
282  * @name: The initial account name
283  *
284  * get an unused account name, based on a starting string.
285  *
286  * Returns: the newly allocated name.
287  */
288 gchar*
289 modest_account_mgr_get_unused_account_name (ModestAccountMgr *self, const gchar* starting_name,
290         gboolean server_account);
291
292 /**
293  * modest_account_mgr_get_unused_account_display name
294  * @self: a #ModestAccountMgr instance
295  * @name: The initial account display name
296  *
297  * get an unused account display name, based on a starting string.
298  *
299  * Returns: the newly allocated name.
300  */
301 gchar*
302 modest_account_mgr_get_unused_account_display_name (ModestAccountMgr *self, const gchar* starting_name);
303
304 G_END_DECLS
305
306 #endif /* __MODEST_ACCOUNT_MGR_H__ */