1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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.
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.
31 #ifndef __MODEST_ACCOUNT_MGR_H__
32 #define __MODEST_ACCOUNT_MGR_H__
34 #include <glib-object.h>
35 #include <modest-conf.h>
36 #include <modest-defs.h>
37 #include <modest-protocol-info.h>
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))
49 typedef struct _ModestAccountMgr ModestAccountMgr;
50 typedef struct _ModestAccountMgrClass ModestAccountMgrClass;
53 struct _ModestAccountMgr {
57 struct _ModestAccountMgrClass {
58 GObjectClass parent_class;
60 void (* account_removed) (ModestAccountMgr *obj, const gchar* account,
61 gboolean server_account, gpointer user_data);
62 void (* account_changed) (ModestAccountMgr *obj, const gchar* account,
63 const gchar* key, gboolean server_account,
73 } ModestServerAccountData;
81 ModestServerAccountData *transport_account;
82 ModestServerAccountData *store_account;
88 * modest_account_mgr_get_type:
90 * get the GType for ModestAccountMgr
94 GType modest_account_mgr_get_type (void) G_GNUC_CONST;
98 * modest_account_mgr_new:
99 * @modest_conf: a ModestConf instance
101 * Returns: a new ModestAccountMgr, or NULL in case of error
103 ModestAccountMgr* modest_account_mgr_new (ModestConf *modest_conf);
108 * modest_account_mgr_add_account:
109 * @self: a ModestAccountMgr instance
110 * @name: name (id) of the account, which is a valid UTF8 string that does not contain '/'
111 * @store_name: the store account (ie. POP/IMAP)
112 * @transport_name: the transport account (ie. sendmail/SMTP)
113 * @err: a GError ptr, or NULL to ignore.
115 * create a new account. the account with @name should not already exist
117 * Returns: TRUE if the creation succeeded, FALSE otherwise,
118 * @err gives details in case of error
120 gboolean modest_account_mgr_add_account (ModestAccountMgr *self,
122 const gchar* store_name,
123 const gchar* transport_name,
128 * modest_account_mgr_add_server_account:
129 * @self: a ModestAccountMgr instance
130 * @name: name (id) of the account, which is a valid UTF8 string that does not contain '/'
131 * @hostname: the hostname
132 * @username: the username
133 * @password: the password
134 * @proto: the protocol (imap, smtp, ...) used for this account
136 * add a server account to the configuration.
137 * the server account with @name should not already exist
139 * Returns: TRUE if succeeded, FALSE otherwise,
141 gboolean modest_account_mgr_add_server_account (ModestAccountMgr *self,
143 const gchar *hostname,
144 const gchar *username,
145 const gchar *password,
146 ModestProtocol proto);
149 * modest_account_mgr_remove_account:
150 * @self: a ModestAccountMgr instance
151 * @name: the name of the account to remove
152 * @server_account: TRUE if the account to remove is a server account
153 * @err: a #GError ptr, or NULL to ignore.
155 * remove an existing account. the account with @name should already exist
157 * Returns: TRUE if the creation succeeded, FALSE otherwise,
158 * @err gives details in case of error
160 gboolean modest_account_mgr_remove_account (ModestAccountMgr *self,
162 gboolean server_account,
166 * modest_account_mgr_get_account_data:
167 * @self: a ModestAccountMgr instance
168 * @name: the name of the account
170 * get information about an account
172 * Returns: a ModestAccountData structure with information about the account.
173 * the data should not be changed, and be freed with modest_account_mgr_free_account_data
174 * The function does a sanity check, an if it's not returning NULL,
175 * it is a valid account
177 ModestAccountData *modest_account_mgr_get_account_data (ModestAccountMgr *self,
182 * modest_account_mgr_free_account_data:
183 * @self: a ModestAccountMgr instance
184 * @data: a ModestAccountData instance
186 * free the account data structure
188 void modest_account_mgr_free_account_data (ModestAccountMgr *self,
189 ModestAccountData *data);
193 * modest_account_mgr_account_names:
194 * @self: a ModestAccountMgr instance
195 * @err: a GError ptr, or NULL to ignore.
197 * list all account names
199 * Returns: a newly allocated list of account names, or NULL in case of error or
200 * if there are no accounts. The caller must free the returned GSList
201 * @err gives details in case of error
203 GSList* modest_account_mgr_account_names (ModestAccountMgr *self, GError **err);
207 * modest_account_mgr_server_account_names:
208 * @self: a ModestAccountMgr instance
209 * @account_name: get only server accounts for @account_name, or NULL for any
210 * @type: get only server accounts from protocol type @type, or MODEST_PROTO_TYPE_ANY
211 * @proto: get only server account with protocol @proto, or NULL for any
212 * @only_enabled: get only enabled server accounts if TRUE
214 * list all the server account names
216 * Returns: a newly allocated list of server account names, or NULL in case of
217 * error or if there are no server accounts. The caller must free the returned GSList
219 GSList* modest_account_mgr_search_server_accounts (ModestAccountMgr *self,
220 const gchar* account_name,
221 ModestProtocolType type,
222 ModestProtocol proto);
225 * modest_account_mgr_account_exists:
226 * @self: a ModestAccountMgr instance
227 * @name: the account name to check
228 * @server_account: if TRUE, this is a server account
229 * @err: a GError ptr, or NULL to ignore.
231 * check whether account @name exists
233 * Returns: TRUE if the account with name @name exists, FALSE otherwise (or in case of error)
234 * @err gives details in case of error
236 gboolean modest_account_mgr_account_exists (ModestAccountMgr *self,
238 gboolean server_account,
242 * modest_account_mgr_account_set_enabled
243 * @self: a ModestAccountMgr instance
244 * @name: the account name
245 * @enabled: if TRUE, the account will be enabled, if FALSE, it will be disabled
247 * enable/disabled an account
249 * Returns: TRUE if it worked, FALSE otherwise
251 gboolean modest_account_mgr_account_set_enabled (ModestAccountMgr *self, const gchar* name,
256 * modest_account_mgr_account_get_enabled:
257 * @self: a ModestAccountMgr instance
258 * @name: the account name to check
260 * check whether a certain account is enabled
262 * Returns: TRUE if it is enabled, FALSE otherwise
264 gboolean modest_account_mgr_account_get_enabled (ModestAccountMgr *self, const gchar* name);
268 * modest_account_mgr_get_account_string:
269 * @self: self a ModestAccountMgr instance
270 * @name: the name of the account
271 * @key: the key of the value to retrieve
272 * @server_account: if TRUE, this is a server account
273 * @err: a GError ptr, or NULL to ignore.
275 * get a config string from an account
277 * Returns: a newly allocated string with the value for the key,
278 * or NULL in case of error. @err gives details in case of error
280 gchar* modest_account_mgr_get_string (ModestAccountMgr *self,
283 gboolean server_account,
288 * modest_account_mgr_get_account_int:
289 * @self: a ModestAccountMgr instance
290 * @name: the name of the account
291 * @key: the key of the value to retrieve
292 * @server_account: if TRUE, this is a server account
293 * @err: a GError ptr, or NULL to ignore.
295 * get a config int from an account
297 * Returns: an integer with the value for the key, or -1 in case of
298 * error (but of course -1 does not necessarily imply an error)
299 * @err gives details in case of error
301 gint modest_account_mgr_get_int (ModestAccountMgr *self,
304 gboolean server_account,
308 * modest_account_mgr_get_account_bool:
309 * @self: a ModestAccountMgr instance
310 * @name: the name of the account
311 * @key: the key of the value to retrieve
312 * @server_account: if TRUE, this is a server account
313 * @err: a GError ptr, or NULL to ignore.
315 * get a config boolean from an account
317 * Returns: an boolean with the value for the key, or FALSE in case of
318 * error (but of course FALSE does not necessarily imply an error)
319 * @err gives details in case of error
321 gboolean modest_account_mgr_get_bool (ModestAccountMgr *self,
324 gboolean server_account,
328 * modest_account_mgr_get_list:
329 * @self: a ModestAccountMgr instance
330 * @name: the name of the account
331 * @key: the key of the value to get
332 * @list_type: the type of the members of the list
333 * @server_account: if TRUE, this is a server account
334 * @err: a GError ptr, or NULL to ignore.
336 * get a config list of values of type @list_type of an account
338 * Returns: a newly allocated list of elements
339 * @err gives details in case of error
341 GSList* modest_account_mgr_get_list (ModestAccountMgr *self,
344 ModestConfValueType list_type,
345 gboolean server_account,
349 * modest_account_mgr_set_account_string:
350 * @self: a ModestAccountMgr instance
351 * @name: the name of the account
352 * @key: the key of the value to set
353 * @val: the value to set
354 * @server_account: if TRUE, this is a server account
355 * @err: a GError ptr, or NULL to ignore.
357 * set a config string for an account.
359 * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
360 * @err gives details in case of error
362 gboolean modest_account_mgr_set_string (ModestAccountMgr *self,
364 const gchar *key, const gchar* val,
365 gboolean server_account,
369 * modest_account_mgr_set_account_int:
370 * @self: a ModestAccountMgr instance
371 * @name: the name of the account
372 * @key: the key of the value to set
373 * @val: the value to set
374 * @server_account: if TRUE, this is a server account
375 * @err: a GError ptr, or NULL to ignore.
377 * set a config int for an account
379 * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
380 * @err gives details in case of error
382 gboolean modest_account_mgr_set_int (ModestAccountMgr *self,
384 const gchar *key, gint val,
385 gboolean server_account,
390 * modest_account_mgr_set_account_bool:
391 * @self: a ModestAccountMgr instance
392 * @name: the name of the account
393 * @key: the key of the value to set
394 * @val: the value to set
395 * @server_account: if TRUE, this is a server account
396 * @err: a GError ptr, or NULL to ignore.
398 * set a config bool for an account
400 * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
401 * @err gives details in case of error
403 gboolean modest_account_mgr_set_bool (ModestAccountMgr *self,
405 const gchar *key, gboolean val,
406 gboolean server_account,
410 * modest_account_mgr_set_list:
411 * @self: a ModestAccountMgr instance
412 * @name: the name of the account
413 * @key: the key of the value to set
414 * @val: the list with the values to set
415 * @list_type: the type of the members of the list
416 * @server_account: if TRUE, this is a server account
417 * @err: a GError ptr, or NULL to ignore.
419 * set a config list of values of type @list_type of an account
420 * @err gives details in case of error
422 void modest_account_mgr_set_list (ModestAccountMgr *self,
426 ModestConfValueType list_type,
427 gboolean server_account,
431 * modest_account_mgr_unset:
432 * @self: a ModestAccountMgr instance
433 * @name: the name of the account
434 * @key: the key of the value to unset
435 * @server_account: if TRUE, this is a server account
436 * @err: a GError ptr, or NULL to ignore.
438 * unsets the config value of an account and all their children keys
440 * Returns: TRUE if unsetting the value succeeded, or FALSE in case of error.
441 * @err gives details in case of error
443 gboolean modest_account_mgr_unset (ModestAccountMgr *self,
446 gboolean server_account,
451 #endif /* __MODEST_ACCOUNT_MGR_H__ */