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-account-keys.h>
37 #include <modest-protocol-mgr.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,
68 * some convenience structs to get bulk data about an account
70 struct _ModestServerAccountData {
77 typedef struct _ModestServerAccountData ModestServerAccountData;
79 struct _ModestAccountData {
85 ModestServerAccountData *transport_account;
86 ModestServerAccountData *store_account;
88 typedef struct _ModestAccountData ModestAccountData;
95 * get the GType for ModestAccountMgr
99 GType modest_account_mgr_get_type (void) G_GNUC_CONST;
103 * modest_account_mgr_new:
104 * @modest_conf: a ModestConf instance
106 * Returns: a new ModestAccountMgr, or NULL in case of error
108 ModestAccountMgr* modest_account_mgr_new (ModestConf *modest_conf);
113 * modest_account_mgr_add_account:
114 * @self: a ModestAccountMgr instance
115 * @name: name (id) of the account, which is a valid UTF8 string that does not contain '/'
116 * @store_name: the store account (ie. POP/IMAP)
117 * @transport_name: the transport account (ie. sendmail/SMTP)
118 * @err: a GError ptr, or NULL to ignore.
120 * create a new account. the account with @name should not already exist
122 * Returns: TRUE if the creation succeeded, FALSE otherwise,
123 * @err gives details in case of error
125 gboolean modest_account_mgr_add_account (ModestAccountMgr *self,
127 const gchar* store_name,
128 const gchar* transport_name,
133 * modest_account_mgr_add_server_account:
134 * @self: a ModestAccountMgr instance
135 * @name: name (id) of the account, which is a valid UTF8 string that does not contain '/'
136 * @hostname: the hostname
137 * @username: the username
138 * @password: the password
139 * @proto: the protocol (imap, smtp, ...) used for this account
141 * add a server account to the configuration.
142 * the server account with @name should not already exist
144 * Returns: TRUE if succeeded, FALSE otherwise,
146 gboolean modest_account_mgr_add_server_account (ModestAccountMgr *self,
148 const gchar *hostname,
149 const gchar *username,
150 const gchar *password,
154 * modest_account_mgr_remove_account:
155 * @self: a ModestAccountMgr instance
156 * @name: the name of the account to remove
157 * @server_account: TRUE if the account to remove is a server account
158 * @err: a #GError ptr, or NULL to ignore.
160 * remove an existing account. the account with @name should already exist
162 * Returns: TRUE if the creation succeeded, FALSE otherwise,
163 * @err gives details in case of error
165 gboolean modest_account_mgr_remove_account (ModestAccountMgr *self,
167 gboolean server_account,
172 * modest_account_mgr_account_names:
173 * @self: a ModestAccountMgr instance
174 * @err: a GError ptr, or NULL to ignore.
176 * list all account names
178 * Returns: a newly allocated list of account names, or NULL in case of error or
179 * if there are no accounts. The caller must free the returned GSList
180 * @err gives details in case of error
182 GSList* modest_account_mgr_account_names (ModestAccountMgr *self, GError **err);
186 * modest_account_mgr_server_account_names:
187 * @self: a ModestAccountMgr instance
188 * @account_name: get only server accounts for @account_name, or NULL for any
189 * @type: get only server accounts from protocol type @type, or MODEST_PROTO_TYPE_ANY
190 * @proto: get only server account with protocol @proto, or NULL for any
191 * @only_enabled: get only enabled server accounts if TRUE
193 * list all the server account names
195 * Returns: a newly allocated list of server account names, or NULL in case of
196 * error or if there are no server accounts. The caller must free the returned GSList
198 GSList* modest_account_mgr_search_server_accounts (ModestAccountMgr *self,
199 const gchar* account_name,
200 ModestProtocolType type,
204 * modest_account_mgr_account_exists:
205 * @self: a ModestAccountMgr instance
206 * @name: the account name to check
207 * @server_account: if TRUE, this is a server account
208 * @err: a GError ptr, or NULL to ignore.
210 * check whether account @name exists
212 * Returns: TRUE if the account with name @name exists, FALSE otherwise (or in case of error)
213 * @err gives details in case of error
215 gboolean modest_account_mgr_account_exists (ModestAccountMgr *self,
217 gboolean server_account,
221 * modest_account_mgr_get_account_data:
222 * @self: a ModestAccountMgr instance
223 * @name: the name of the account
225 * get information about an account
227 * Returns: a ModestAccountData structure with information about the account.
228 * the data should not be changed, and be freed with modest_account_mgr_free_account_data
230 ModestAccountData *modest_account_mgr_get_account_data (ModestAccountMgr *self,
235 * modest_account_mgr_free_account_data:
236 * @self: a ModestAccountMgr instance
237 * @data: a ModestAccountData instance
239 * free the account data structure
241 void modest_account_mgr_free_account_data (ModestAccountMgr *self,
242 ModestAccountData *data);
245 * modest_account_mgr_account_set_enabled
246 * @self: a ModestAccountMgr instance
247 * @name: the account name
248 * @enabled: if TRUE, the account will be enabled, if FALSE, it will be disabled
250 * enable/disabled an account
252 * Returns: TRUE if it worked, FALSE otherwise
254 gboolean modest_account_mgr_account_set_enabled (ModestAccountMgr *self, const gchar* name,
259 * modest_account_mgr_account_get_enabled:
260 * @self: a ModestAccountMgr instance
261 * @name: the account name to check
263 * check whether a certain account is enabled
265 * Returns: TRUE if it is enabled, FALSE otherwise
267 gboolean modest_account_mgr_account_get_enabled (ModestAccountMgr *self, const gchar* name);
271 * modest_account_mgr_get_account_string:
272 * @self: self a ModestAccountMgr instance
273 * @name: the name of the account
274 * @key: the key of the value to retrieve
275 * @server_account: if TRUE, this is a server account
276 * @err: a GError ptr, or NULL to ignore.
278 * get a config string from an account
280 * Returns: a newly allocated string with the value for the key,
281 * or NULL in case of error. @err gives details in case of error
283 gchar* modest_account_mgr_get_string (ModestAccountMgr *self,
286 gboolean server_account,
291 * modest_account_mgr_get_account_int:
292 * @self: a ModestAccountMgr instance
293 * @name: the name of the account
294 * @key: the key of the value to retrieve
295 * @server_account: if TRUE, this is a server account
296 * @err: a GError ptr, or NULL to ignore.
298 * get a config int from an account
300 * Returns: an integer with the value for the key, or -1 in case of
301 * error (but of course -1 does not necessarily imply an error)
302 * @err gives details in case of error
304 gint modest_account_mgr_get_int (ModestAccountMgr *self,
307 gboolean server_account,
311 * modest_account_mgr_get_account_bool:
312 * @self: a ModestAccountMgr instance
313 * @name: the name of the account
314 * @key: the key of the value to retrieve
315 * @server_account: if TRUE, this is a server account
316 * @err: a GError ptr, or NULL to ignore.
318 * get a config boolean from an account
320 * Returns: an boolean with the value for the key, or FALSE in case of
321 * error (but of course FALSE does not necessarily imply an error)
322 * @err gives details in case of error
324 gboolean modest_account_mgr_get_bool (ModestAccountMgr *self,
327 gboolean server_account,
331 * modest_account_mgr_get_list:
332 * @self: a ModestAccountMgr instance
333 * @name: the name of the account
334 * @key: the key of the value to get
335 * @list_type: the type of the members of the list
336 * @server_account: if TRUE, this is a server account
337 * @err: a GError ptr, or NULL to ignore.
339 * get a config list of values of type @list_type of an account
341 * Returns: a newly allocated list of elements
342 * @err gives details in case of error
344 GSList* modest_account_mgr_get_list (ModestAccountMgr *self,
347 ModestConfValueType list_type,
348 gboolean server_account,
352 * modest_account_mgr_set_account_string:
353 * @self: a ModestAccountMgr instance
354 * @name: the name of the account
355 * @key: the key of the value to set
356 * @val: the value to set
357 * @server_account: if TRUE, this is a server account
358 * @err: a GError ptr, or NULL to ignore.
360 * set a config string for an account.
362 * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
363 * @err gives details in case of error
365 gboolean modest_account_mgr_set_string (ModestAccountMgr *self,
367 const gchar *key, const gchar* val,
368 gboolean server_account,
372 * modest_account_mgr_set_account_int:
373 * @self: a ModestAccountMgr instance
374 * @name: the name of the account
375 * @key: the key of the value to set
376 * @val: the value to set
377 * @server_account: if TRUE, this is a server account
378 * @err: a GError ptr, or NULL to ignore.
380 * set a config int for an account
382 * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
383 * @err gives details in case of error
385 gboolean modest_account_mgr_set_int (ModestAccountMgr *self,
387 const gchar *key, gint val,
388 gboolean server_account,
393 * modest_account_mgr_set_account_bool:
394 * @self: a ModestAccountMgr instance
395 * @name: the name of the account
396 * @key: the key of the value to set
397 * @val: the value to set
398 * @server_account: if TRUE, this is a server account
399 * @err: a GError ptr, or NULL to ignore.
401 * set a config bool for an account
403 * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
404 * @err gives details in case of error
406 gboolean modest_account_mgr_set_bool (ModestAccountMgr *self,
408 const gchar *key, gboolean val,
409 gboolean server_account,
413 * modest_account_mgr_set_list:
414 * @self: a ModestAccountMgr instance
415 * @name: the name of the account
416 * @key: the key of the value to set
417 * @val: the list with the values to set
418 * @list_type: the type of the members of the list
419 * @server_account: if TRUE, this is a server account
420 * @err: a GError ptr, or NULL to ignore.
422 * set a config list of values of type @list_type of an account
423 * @err gives details in case of error
425 void modest_account_mgr_set_list (ModestAccountMgr *self,
429 ModestConfValueType list_type,
430 gboolean server_account,
434 * modest_account_mgr_unset:
435 * @self: a ModestAccountMgr instance
436 * @name: the name of the account
437 * @key: the key of the value to unset
438 * @server_account: if TRUE, this is a server account
439 * @err: a GError ptr, or NULL to ignore.
441 * unsets the config value of an account and all their children keys
443 * Returns: TRUE if unsetting the value succeeded, or FALSE in case of error.
444 * @err gives details in case of error
446 gboolean modest_account_mgr_unset (ModestAccountMgr *self,
449 gboolean server_account,
454 #endif /* __MODEST_ACCOUNT_MGR_H__ */