2007-04-18 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         GSList           *options;
53 } ModestServerAccountData;
54
55 typedef struct {
56         gchar            *account_name;
57         gchar            *display_name;
58         gchar            *fullname;
59         gchar            *email;
60         gboolean         is_enabled;
61         gboolean         is_default;
62         ModestServerAccountData *transport_account;
63         ModestServerAccountData *store_account;
64 } ModestAccountData;
65
66
67
68 /**
69  * modest_account_mgr_get_account_data:
70  * @self: a ModestAccountMgr instance
71  * @name: the name of the account
72  * 
73  * get information about an account
74  *
75  * Returns: a ModestAccountData structure with information about the account.
76  * the data should not be changed, and be freed with modest_account_mgr_free_account_data
77  * The function does a sanity check, an if it's not returning NULL,
78  * it is a valid account
79  */
80 ModestAccountData *modest_account_mgr_get_account_data     (ModestAccountMgr *self,
81                                                             const gchar* name);
82
83 /**
84  * modest_account_mgr_get_default_account:
85  * @self: a ModestAccountMgr instance
86  * 
87  * get the default account name, or NULL if none is found
88  *
89  * Returns: the default account name (as newly allocated string, which
90  * must be g_free'd), or NULL
91  */
92 gchar* modest_account_mgr_get_default_account  (ModestAccountMgr *self);
93
94 /**
95  * modest_account_mgr_get_default_account:
96  * @self: a ModestAccountMgr instance
97  * @account: the name of an existing account
98  * 
99  * set the default account name (which must be valid account)
100  *
101  * Returns: TRUE if succeeded, FALSE otherwise
102  */
103 gboolean modest_account_mgr_set_default_account  (ModestAccountMgr *self,
104                                                   const gchar* account);
105
106 /**
107  * modest_account_mgr_free_account_data:
108  * @self: a ModestAccountMgr instance
109  * @data: a ModestAccountData instance
110  * 
111  * free the account data structure
112  */
113 void       modest_account_mgr_free_account_data     (ModestAccountMgr *self,
114                                                      ModestAccountData *data);
115
116 /**
117  * modest_account_mgr_set_enabled
118  * @self: a ModestAccountMgr instance
119  * @name: the account name 
120  * @enabled: if TRUE, the account will be enabled, if FALSE, it will be disabled
121  * 
122  * enable/disabled an account
123  *
124  * Returns: TRUE if it worked, FALSE otherwise
125  */
126 gboolean modest_account_mgr_set_enabled (ModestAccountMgr *self, const gchar* name,
127                                          gboolean enabled);
128
129 /**
130  * modest_account_mgr_get_enabled:
131  * @self: a ModestAccountMgr instance
132  * @name: the account name to check
133  *
134  * check whether a certain account is enabled
135  *
136  * Returns: TRUE if it is enabled, FALSE otherwise
137  */
138 gboolean modest_account_mgr_get_enabled (ModestAccountMgr *self, const gchar* name);
139
140 /**
141  * modest_server_account_get_option_secure_auth:
142  * @self: a ModestAccountMgr instance
143  * @account_name: The name of a server account.
144  *
145  * Gets the secure authentication method for this server account.
146  *
147  * Returns: The secure authentication enum value.
148  */
149 ModestProtocol
150 modest_server_account_get_option_secure_auth (ModestAccountMgr *self, const gchar* account_name);
151
152 /**
153  * modest_server_account_data_get_option_secure_auth:
154  * @self: a ModestAccountMgr instance
155  * @account_name: The name of a server account.
156  * @secure_auth: The secure authentication enum value.
157  *
158  * Gets the secure authentication method for this server account.
159  */
160 void
161 modest_server_account_set_option_secure_auth (ModestAccountMgr *self, const gchar* account_name, 
162         ModestProtocol secure_auth);
163         
164 /**
165  * modest_server_account_data_get_option_security:
166  * @account_data: a ModestAccountData instance.
167  *
168  * Gets the security method for this server account.
169  *
170  * Returns: The security enum value.
171  */
172 ModestProtocol
173 modest_server_account_data_get_option_security (ModestServerAccountData *account_data);
174
175 /**
176  * modest_server_account_set_option_security:
177  * @self: a ModestAccountMgr instance
178  * @secure_auth: The security enum value.
179  *
180  * Gets the security method for this server account.
181  */
182 void
183 modest_server_account_set_option_security (ModestAccountMgr *self, const gchar* account_name, 
184         ModestProtocol security);
185
186 /**
187  * modest_account_mgr_get_account_option:
188  * @self: a ModestAccountMgr instance
189  * @account_name: the account name to check
190  * @account_name: the option name to check
191  *
192  * Returns: The account option value. This must be freed with g_free().
193  */
194 gchar* modest_account_mgr_get_server_account_option (ModestAccountMgr *self, 
195         const gchar* account_name, const gchar* option_name);
196
197 /**
198  * modest_server_account_data_get_option_value:
199  * @options_list: a ModestServerAccountData::options list.
200  * @option_name: the option name to check
201  *
202  * Returns: The account option value. This must be freed with g_free().
203  */
204 gchar* modest_server_account_data_get_option_value (GSList* options_list, const gchar* option_name);
205
206 /**
207  * modest_server_account_data_get_option_bool:
208  * @options_list: a ModestServerAccountData::options list.
209  * @option_name: the option name to check
210  *
211  * Returns: Whether the account option is present.
212  */
213 gboolean modest_server_account_data_get_option_bool (GSList* options_list, const gchar* option_name);
214
215
216 /**
217  * modest_account_mgr_get_from_string
218  * @self: a #ModestAccountMgr instance
219  * @name: the account name
220  *
221  * get the From: string for some account; ie. "Foo Bar" <foo.bar@cuux.yy>"
222  *
223  * Returns: the newly allocated from-string, or NULL in case of error
224  */
225 gchar * modest_account_mgr_get_from_string (ModestAccountMgr *self, const gchar* name);
226
227
228 G_END_DECLS
229
230 #endif /* __MODEST_ACCOUNT_MGR_H__ */