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;
52 struct _ModestAccountMgr {
56 struct _ModestAccountMgrClass {
57 GObjectClass parent_class;
59 void (* account_removed) (ModestAccountMgr *obj,
61 gboolean server_account,
63 void (* account_changed) (ModestAccountMgr *obj,
66 gboolean server_account,
71 * modest_account_mgr_get_type:
73 * get the GType for ModestAccountMgr
77 GType modest_account_mgr_get_type (void) G_GNUC_CONST;
81 * modest_account_mgr_new:
82 * @modest_conf: a ModestConf instance
84 * Returns: a new ModestAccountMgr, or NULL in case of error
86 ModestAccountMgr* modest_account_mgr_new (ModestConf *modest_conf);
91 * modest_account_mgr_add_account:
92 * @self: a ModestAccountMgr instance
93 * @name: name (id) of the account, which is a valid UTF8 string that does not contain '/'
94 * @store_name: the store account (ie. POP/IMAP)
95 * @transport_name: the transport account (ie. sendmail/SMTP)
96 * @enabled: Whether the account should be enabled initially.
98 * Create a new account. The account with @name should not already exist. The @name will
99 * be used as the initial display name of the new account.
101 * Returns: TRUE if the creation succeeded, FALSE otherwise,
103 gboolean modest_account_mgr_add_account (ModestAccountMgr *self,
105 const gchar* store_name,
106 const gchar* transport_name,
110 * modest_account_mgr_add_server_account:
111 * @self: a ModestAccountMgr instance
112 * @name: name (id) of the account, which is a valid UTF8 string that does not contain '/'
113 * @hostname: the hostname
114 * @portnumber: the portnumber, or 0 for default
115 * @username: the username
116 * @password: the password
117 * @proto: the protocol (imap, smtp, ...) used for this account
118 * @security: the security options, (SSL, TLS ...) used to access the server
119 * @auth: the authentication method (password, none ...) used to access the server
121 * add a server account to the configuration.
122 * the server account with @name should not already exist
124 * Returns: TRUE if succeeded, FALSE otherwise,
126 gboolean modest_account_mgr_add_server_account (ModestAccountMgr *self,
128 const gchar *hostname,
129 const guint portnumber,
130 const gchar *username,
131 const gchar *password,
132 ModestTransportStoreProtocol proto,
133 ModestConnectionProtocol security,
134 ModestAuthProtocol auth);
138 * modest_account_mgr_add_server_account_uri:
139 * @self: a ModestAccountMgr instance
140 * @name: name (id) of the account, which is a valid UTF8 string that does not contain '/'
141 * @proto: the protocol (imap, smtp, ...) used for this account
144 * add a server account to the configuration, based on the account-URI
146 * Returns: TRUE if succeeded, FALSE otherwise,
148 gboolean modest_account_mgr_add_server_account_uri (ModestAccountMgr *self,
150 ModestTransportStoreProtocol proto,
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; note
161 * that when deleting an account, also the corresponding server accounts will
164 * Returns: TRUE if the creation succeeded, FALSE otherwise,
165 * @err gives details in case of error
167 gboolean modest_account_mgr_remove_account (ModestAccountMgr *self,
169 gboolean server_account);
173 * modest_account_mgr_account_names:
174 * @self: a ModestAccountMgr instance
175 * @only_enabled: Whether only enabled accounts should be returned.
177 * list all account names
179 * Returns: a newly allocated list of account names, or NULL in case of error or
180 * if there are no accounts. The caller must free the returned GSList.
182 * TODO: I believe that the caller must free the strings in the GSList items too,
183 * because this is implemented via gconf_client_all_dirs() which also requires a deep free,
184 * though that's not documented. murrayc.
186 GSList* modest_account_mgr_account_names (ModestAccountMgr *self,
187 gboolean only_enabled);
192 * modest_account_mgr_search_server_account:
193 * @self: a ModestAccountMgr instance
194 * @account_name: get only server accounts for @account_name, or NULL for any
195 * @type: get only server accounts from protocol type @type, or MODEST_PROTOCOL_TYPE_UNKNOWN
196 * @proto: get only server account with protocol @proto, or MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN for any
198 * List all the server account names, optionally narrowing the result down to one account.
200 * Returns: a newly allocated list of server account names, or NULL in case of
201 * error or if there are no server accounts. The caller must free the returned GSList
203 GSList* modest_account_mgr_search_server_accounts (ModestAccountMgr *self,
204 const gchar* account_name,
205 ModestProtocolType type,
206 ModestTransportStoreProtocol proto);
210 * modest_account_mgr_account_exists:
211 * @self: a ModestAccountMgr instance
212 * @name: the account name to check
213 * @server_account: if TRUE, this is a server account
215 * check whether account @name exists. Note that this does not check the display name.
217 * Returns: TRUE if the account with name @name exists, FALSE otherwise (or in case of error)
219 gboolean modest_account_mgr_account_exists (ModestAccountMgr *self,
221 gboolean server_account);
224 * modest_account_mgr_account_exists:
225 * @self: a ModestAccountMgr instance
226 * @name: the account name to check
228 * check whether a non-server account with the @display_name exists.
230 * Returns: TRUE if the account with name @name exists, FALSE otherwise (or in case of error)
232 gboolean modest_account_mgr_account_with_display_name_exists (ModestAccountMgr *self,
233 const gchar *display_name);
237 * modest_account_mgr_get_string:
238 * @self: self a ModestAccountMgr instance
239 * @name: the name of the account
240 * @key: the key of the value to retrieve
241 * @server_account: if TRUE, this is a server account
243 * get a config string from an account
245 * Returns: a newly allocated string with the value for the key,
246 * or NULL in case of error.
248 gchar* modest_account_mgr_get_string (ModestAccountMgr *self,
251 gboolean server_account);
255 * modest_account_mgr_get_password:
256 * @self: self a ModestAccountMgr instance
257 * @name: the name of the account
258 * @key: the key of the value to retrieve
259 * @server_account: if TRUE, this is a server account
261 * get a password from an account
263 * Returns: a newly allocated string with the value for the key,
264 * or NULL in case of error.
266 gchar* modest_account_mgr_get_password (ModestAccountMgr *self,
269 gboolean server_account);
272 * modest_account_mgr_get_int:
273 * @self: a ModestAccountMgr instance
274 * @name: the name of the account
275 * @key: the key of the value to retrieve
276 * @server_account: if TRUE, this is a server account
278 * get a config int from an account
280 * Returns: an integer with the value for the key, or -1 in case of
281 * error (but of course -1 does not necessarily imply an error)
283 gint modest_account_mgr_get_int (ModestAccountMgr *self,
286 gboolean server_account);
289 * modest_account_mgr_get_bool:
290 * @self: a ModestAccountMgr instance
291 * @name: the name of the account
292 * @key: the key of the value to retrieve
293 * @server_account: if TRUE, this is a server account
295 * get a config boolean from an account
297 * Returns: an boolean with the value for the key, or FALSE in case of
298 * error (but of course FALSE does not necessarily imply an error)
300 gboolean modest_account_mgr_get_bool (ModestAccountMgr *self,
303 gboolean server_account);
306 * modest_account_mgr_get_list:
307 * @self: a ModestAccountMgr instance
308 * @name: the name of the account
309 * @key: the key of the value to get
310 * @list_type: the type of the members of the list
311 * @server_account: if TRUE, this is a server account
313 * get a config list of values of type @list_type of an account
315 * Returns: a newly allocated list of elements
317 GSList* modest_account_mgr_get_list (ModestAccountMgr *self,
320 ModestConfValueType list_type,
321 gboolean server_account);
324 * modest_account_mgr_set_string:
325 * @self: a ModestAccountMgr instance
326 * @name: the name of the account
327 * @key: the key of the value to set
328 * @val: the value to set
329 * @server_account: if TRUE, this is a server account
331 * set a config string for an account.
333 * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
335 gboolean modest_account_mgr_set_string (ModestAccountMgr *self,
337 const gchar *key, const gchar* val,
338 gboolean server_account);
342 * modest_account_mgr_set_password:
343 * @self: a ModestAccountMgr instance
344 * @name: the name of the account
345 * @key: the key of the value to set
346 * @val: the value to set
347 * @server_account: if TRUE, this is a server account
349 * set a password for an account.
351 * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
352 * @err gives details in case of error
354 gboolean modest_account_mgr_set_password (ModestAccountMgr *self,
356 const gchar *key, const gchar* val,
357 gboolean server_account);
360 * modest_account_mgr_set_int:
361 * @self: a ModestAccountMgr instance
362 * @name: the name of the account
363 * @key: the key of the value to set
364 * @val: the value to set
365 * @server_account: if TRUE, this is a server account
367 * set a config int for an account
369 * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
371 gboolean modest_account_mgr_set_int (ModestAccountMgr *self,
373 const gchar *key, gint val,
374 gboolean server_account);
377 * modest_account_mgr_set_bool:
378 * @self: a ModestAccountMgr instance
379 * @name: the name of the account
380 * @key: the key of the value to set
381 * @val: the value to set
382 * @server_account: if TRUE, this is a server account
384 * set a config bool for an account
386 * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
388 gboolean modest_account_mgr_set_bool (ModestAccountMgr *self,
390 const gchar *key, gboolean val,
391 gboolean server_account);
394 * modest_account_mgr_set_list:
395 * @self: a ModestAccountMgr instance
396 * @name: the name of the account
397 * @key: the key of the value to set
398 * @val: the list with the values to set
399 * @list_type: the type of the members of the list
400 * @server_account: if TRUE, this is a server account
402 * * set a config list of values of type @list_type of an account
404 * returns TRUE if this succeeded, FALSE otherwise
406 gboolean modest_account_mgr_set_list (ModestAccountMgr *self,
410 ModestConfValueType list_type,
411 gboolean server_account);
414 * modest_account_mgr_unset:
415 * @self: a ModestAccountMgr instance
416 * @name: the name of the account
417 * @key: the key of the value to unset
418 * @server_account: if TRUE, this is a server account
419 * @err: a GError ptr, or NULL to ignore.
421 * unsets the config value of an account and all their children keys
423 * Returns: TRUE if unsetting the value succeeded, or FALSE in case of error.
424 * @err gives details in case of error
426 gboolean modest_account_mgr_unset (ModestAccountMgr *self,
429 gboolean server_account);
432 * modest_account_mgr_has_accounts:
433 * @self: a ModestAccountMgr instance
434 * @enabled: TRUE to search for enabled accounts only
436 * Checks if any accounts exist
438 * Returns: TRUE if accounts exist, FALSE otherwise
441 gboolean modest_account_mgr_has_accounts (ModestAccountMgr* self, gboolean enabled);
445 #endif /* __MODEST_ACCOUNT_MGR_H__ */