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, const gchar* account,
60 gboolean server_account, gpointer user_data);
61 void (* account_changed) (ModestAccountMgr *obj, const gchar* account,
62 const gchar* key, gboolean server_account,
67 * modest_account_mgr_get_type:
69 * get the GType for ModestAccountMgr
73 GType modest_account_mgr_get_type (void) G_GNUC_CONST;
77 * modest_account_mgr_new:
78 * @modest_conf: a ModestConf instance
80 * Returns: a new ModestAccountMgr, or NULL in case of error
82 ModestAccountMgr* modest_account_mgr_new (ModestConf *modest_conf);
87 * modest_account_mgr_add_account:
88 * @self: a ModestAccountMgr instance
89 * @name: name (id) of the account, which is a valid UTF8 string that does not contain '/'
90 * @store_name: the store account (ie. POP/IMAP)
91 * @transport_name: the transport account (ie. sendmail/SMTP)
92 * @enabled: Whether the account should be enabled initially.
94 * Create a new account. The account with @name should not already exist. The @name will
95 * be used as the initial display name of the new account.
97 * Returns: TRUE if the creation succeeded, FALSE otherwise,
99 gboolean modest_account_mgr_add_account (ModestAccountMgr *self,
101 const gchar* store_name,
102 const gchar* transport_name,
106 * modest_account_mgr_add_server_account:
107 * @self: a ModestAccountMgr instance
108 * @name: name (id) of the account, which is a valid UTF8 string that does not contain '/'
109 * @hostname: the hostname
110 * @username: the username
111 * @password: the password
112 * @proto: the protocol (imap, smtp, ...) used for this account
113 * @security: the security options, (SSL, TLS ...) used to access the server
114 * @auth: the authentication method (password, none ...) used to access the server
116 * add a server account to the configuration.
117 * the server account with @name should not already exist
119 * Returns: TRUE if succeeded, FALSE otherwise,
121 gboolean modest_account_mgr_add_server_account (ModestAccountMgr *self,
123 const gchar *hostname,
124 const gchar *username,
125 const gchar *password,
126 ModestTransportStoreProtocol proto,
127 ModestConnectionProtocol security,
128 ModestAuthProtocol auth);
132 * modest_account_mgr_add_server_account_uri:
133 * @self: a ModestAccountMgr instance
134 * @name: name (id) of the account, which is a valid UTF8 string that does not contain '/'
135 * @proto: the protocol (imap, smtp, ...) used for this account
138 * add a server account to the configuration, based on the account-URI
140 * Returns: TRUE if succeeded, FALSE otherwise,
142 gboolean modest_account_mgr_add_server_account_uri (ModestAccountMgr *self,
144 ModestTransportStoreProtocol proto,
148 * modest_account_mgr_remove_account:
149 * @self: a ModestAccountMgr instance
150 * @name: the name of the account to remove
151 * @server_account: TRUE if the account to remove is a server account
152 * @err: a #GError ptr, or NULL to ignore.
154 * remove an existing account. the account with @name should already exist; note
155 * that when deleting an account, also the corresponding server accounts will
158 * Returns: TRUE if the creation succeeded, FALSE otherwise,
159 * @err gives details in case of error
161 gboolean modest_account_mgr_remove_account (ModestAccountMgr *self,
163 gboolean server_account);
167 * modest_account_mgr_account_names:
168 * @self: a ModestAccountMgr instance
169 * @only_enabled: Whether only enabled accounts should be returned.
171 * list all account names
173 * Returns: a newly allocated list of account names, or NULL in case of error or
174 * if there are no accounts. The caller must free the returned GSList.
176 * TODO: I believe that the caller must free the strings in the GSList items too,
177 * because this is implemented via gconf_client_all_dirs() which also requires a deep free,
178 * though that's not documented. murrayc.
180 GSList* modest_account_mgr_account_names (ModestAccountMgr *self,
181 gboolean only_enabled);
186 * modest_account_mgr_search_server_account:
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_PROTOCOL_TYPE_UNKNOWN
190 * @proto: get only server account with protocol @proto, or MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN for any
192 * List all the server account names, optionally narrowing the result down to one account.
194 * Returns: a newly allocated list of server account names, or NULL in case of
195 * error or if there are no server accounts. The caller must free the returned GSList
197 GSList* modest_account_mgr_search_server_accounts (ModestAccountMgr *self,
198 const gchar* account_name,
199 ModestProtocolType type,
200 ModestTransportStoreProtocol proto);
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
209 * check whether account @name exists. Note that this does not check the display name.
211 * Returns: TRUE if the account with name @name exists, FALSE otherwise (or in case of error)
213 gboolean modest_account_mgr_account_exists (ModestAccountMgr *self,
215 gboolean server_account);
218 * modest_account_mgr_account_exists:
219 * @self: a ModestAccountMgr instance
220 * @name: the account name to check
222 * check whether a non-server account with the @display_name exists.
224 * Returns: TRUE if the account with name @name exists, FALSE otherwise (or in case of error)
226 gboolean modest_account_mgr_account_with_display_name_exists (ModestAccountMgr *self,
227 const gchar *display_name);
231 * modest_account_mgr_get_string:
232 * @self: self a ModestAccountMgr instance
233 * @name: the name of the account
234 * @key: the key of the value to retrieve
235 * @server_account: if TRUE, this is a server account
237 * get a config string from an account
239 * Returns: a newly allocated string with the value for the key,
240 * or NULL in case of error.
242 gchar* modest_account_mgr_get_string (ModestAccountMgr *self,
245 gboolean server_account);
249 * modest_account_mgr_get_password:
250 * @self: self a ModestAccountMgr instance
251 * @name: the name of the account
252 * @key: the key of the value to retrieve
253 * @server_account: if TRUE, this is a server account
255 * get a password from an account
257 * Returns: a newly allocated string with the value for the key,
258 * or NULL in case of error.
260 gchar* modest_account_mgr_get_password (ModestAccountMgr *self,
263 gboolean server_account);
266 * modest_account_mgr_get_int:
267 * @self: a ModestAccountMgr instance
268 * @name: the name of the account
269 * @key: the key of the value to retrieve
270 * @server_account: if TRUE, this is a server account
272 * get a config int from an account
274 * Returns: an integer with the value for the key, or -1 in case of
275 * error (but of course -1 does not necessarily imply an error)
277 gint modest_account_mgr_get_int (ModestAccountMgr *self,
280 gboolean server_account);
283 * modest_account_mgr_get_bool:
284 * @self: a ModestAccountMgr instance
285 * @name: the name of the account
286 * @key: the key of the value to retrieve
287 * @server_account: if TRUE, this is a server account
289 * get a config boolean from an account
291 * Returns: an boolean with the value for the key, or FALSE in case of
292 * error (but of course FALSE does not necessarily imply an error)
294 gboolean modest_account_mgr_get_bool (ModestAccountMgr *self,
297 gboolean server_account);
300 * modest_account_mgr_get_list:
301 * @self: a ModestAccountMgr instance
302 * @name: the name of the account
303 * @key: the key of the value to get
304 * @list_type: the type of the members of the list
305 * @server_account: if TRUE, this is a server account
307 * get a config list of values of type @list_type of an account
309 * Returns: a newly allocated list of elements
311 GSList* modest_account_mgr_get_list (ModestAccountMgr *self,
314 ModestConfValueType list_type,
315 gboolean server_account);
318 * modest_account_mgr_set_string:
319 * @self: a ModestAccountMgr instance
320 * @name: the name of the account
321 * @key: the key of the value to set
322 * @val: the value to set
323 * @server_account: if TRUE, this is a server account
325 * set a config string for an account.
327 * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
329 gboolean modest_account_mgr_set_string (ModestAccountMgr *self,
331 const gchar *key, const gchar* val,
332 gboolean server_account);
336 * modest_account_mgr_set_password:
337 * @self: a ModestAccountMgr instance
338 * @name: the name of the account
339 * @key: the key of the value to set
340 * @val: the value to set
341 * @server_account: if TRUE, this is a server account
343 * set a password for an account.
345 * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
346 * @err gives details in case of error
348 gboolean modest_account_mgr_set_password (ModestAccountMgr *self,
350 const gchar *key, const gchar* val,
351 gboolean server_account);
354 * modest_account_mgr_set_int:
355 * @self: a ModestAccountMgr instance
356 * @name: the name of the account
357 * @key: the key of the value to set
358 * @val: the value to set
359 * @server_account: if TRUE, this is a server account
361 * set a config int for an account
363 * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
365 gboolean modest_account_mgr_set_int (ModestAccountMgr *self,
367 const gchar *key, gint val,
368 gboolean server_account);
371 * modest_account_mgr_set_bool:
372 * @self: a ModestAccountMgr instance
373 * @name: the name of the account
374 * @key: the key of the value to set
375 * @val: the value to set
376 * @server_account: if TRUE, this is a server account
378 * set a config bool for an account
380 * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
382 gboolean modest_account_mgr_set_bool (ModestAccountMgr *self,
384 const gchar *key, gboolean val,
385 gboolean server_account);
388 * modest_account_mgr_set_list:
389 * @self: a ModestAccountMgr instance
390 * @name: the name of the account
391 * @key: the key of the value to set
392 * @val: the list with the values to set
393 * @list_type: the type of the members of the list
394 * @server_account: if TRUE, this is a server account
396 * * set a config list of values of type @list_type of an account
398 * returns TRUE if this succeeded, FALSE otherwise
400 gboolean modest_account_mgr_set_list (ModestAccountMgr *self,
404 ModestConfValueType list_type,
405 gboolean server_account);
408 * modest_account_mgr_unset:
409 * @self: a ModestAccountMgr instance
410 * @name: the name of the account
411 * @key: the key of the value to unset
412 * @server_account: if TRUE, this is a server account
413 * @err: a GError ptr, or NULL to ignore.
415 * unsets the config value of an account and all their children keys
417 * Returns: TRUE if unsetting the value succeeded, or FALSE in case of error.
418 * @err gives details in case of error
420 gboolean modest_account_mgr_unset (ModestAccountMgr *self,
423 gboolean server_account);
427 #endif /* __MODEST_ACCOUNT_MGR_H__ */