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,
68 * modest_account_mgr_get_type:
70 * get the GType for ModestAccountMgr
74 GType modest_account_mgr_get_type (void) G_GNUC_CONST;
78 * modest_account_mgr_new:
79 * @modest_conf: a ModestConf instance
81 * Returns: a new ModestAccountMgr, or NULL in case of error
83 ModestAccountMgr* modest_account_mgr_new (ModestConf *modest_conf);
88 * modest_account_mgr_add_account:
89 * @self: a ModestAccountMgr instance
90 * @name: name (id) of the account, which is a valid UTF8 string that does not contain '/'
91 * @store_name: the store account (ie. POP/IMAP)
92 * @transport_name: the transport account (ie. sendmail/SMTP)
93 * @enabled: Whether the account should be enabled initially.
95 * Create a new account. The account with @name should not already exist. The @name will
96 * be used as the initial display name of the new account.
98 * Returns: TRUE if the creation succeeded, FALSE otherwise,
100 gboolean modest_account_mgr_add_account (ModestAccountMgr *self,
102 const gchar* store_name,
103 const gchar* transport_name,
107 * modest_account_mgr_add_server_account:
108 * @self: a ModestAccountMgr instance
109 * @name: name (id) of the account, which is a valid UTF8 string that does not contain '/'
110 * @hostname: the hostname
111 * @username: the username
112 * @password: the password
113 * @proto: the protocol (imap, smtp, ...) used for this account
114 * @security: the security options, (SSL, TLS ...) used to access the server
115 * @auth: the authentication method (password, none ...) used to access the server
117 * add a server account to the configuration.
118 * the server account with @name should not already exist
120 * Returns: TRUE if succeeded, FALSE otherwise,
122 gboolean modest_account_mgr_add_server_account (ModestAccountMgr *self,
124 const gchar *hostname,
125 const gchar *username,
126 const gchar *password,
127 ModestProtocol proto,
128 ModestProtocol security,
129 ModestProtocol auth);
133 * modest_account_mgr_add_server_account_uri:
134 * @self: a ModestAccountMgr instance
135 * @name: name (id) of the account, which is a valid UTF8 string that does not contain '/'
136 * @proto: the protocol (imap, smtp, ...) used for this account
139 * add a server account to the configuration, based on the account-URI
141 * Returns: TRUE if succeeded, FALSE otherwise,
143 gboolean modest_account_mgr_add_server_account_uri (ModestAccountMgr *self,
145 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; note
156 * that when deleting an account, also the corresponding server accounts will
159 * Returns: TRUE if the creation succeeded, FALSE otherwise,
160 * @err gives details in case of error
162 gboolean modest_account_mgr_remove_account (ModestAccountMgr *self,
164 gboolean server_account);
168 * modest_account_mgr_account_names:
169 * @self: a ModestAccountMgr instance
170 * @only_enabled: Whether only enabled accounts should be returned.
172 * list all account names
174 * Returns: a newly allocated list of account names, or NULL in case of error or
175 * if there are no accounts. The caller must free the returned GSList.
177 * TODO: I believe that the caller must free the strings in the GSList items too,
178 * because this is implemented via gconf_client_all_dirs() which also requires a deep free,
179 * though that's not documented. murrayc.
181 GSList* modest_account_mgr_account_names (ModestAccountMgr *self,
182 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_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 ModestProtocol proto);
203 * modest_account_mgr_account_exists:
204 * @self: a ModestAccountMgr instance
205 * @name: the account name to check
206 * @server_account: if TRUE, this is a server account
208 * check whether account @name exists. Note that this does not check the display name.
210 * Returns: TRUE if the account with name @name exists, FALSE otherwise (or in case of error)
212 gboolean modest_account_mgr_account_exists (ModestAccountMgr *self,
214 gboolean server_account);
217 * modest_account_mgr_account_exists:
218 * @self: a ModestAccountMgr instance
219 * @name: the account name to check
221 * check whether a non-server account with the @display_name exists.
223 * Returns: TRUE if the account with name @name exists, FALSE otherwise (or in case of error)
225 gboolean modest_account_mgr_account_with_display_name_exists (ModestAccountMgr *self,
226 const gchar *display_name);
230 * modest_account_mgr_get_string:
231 * @self: self a ModestAccountMgr instance
232 * @name: the name of the account
233 * @key: the key of the value to retrieve
234 * @server_account: if TRUE, this is a server account
236 * get a config string from an account
238 * Returns: a newly allocated string with the value for the key,
239 * or NULL in case of error.
241 gchar* modest_account_mgr_get_string (ModestAccountMgr *self,
244 gboolean server_account);
248 * modest_account_mgr_get_password:
249 * @self: self a ModestAccountMgr instance
250 * @name: the name of the account
251 * @key: the key of the value to retrieve
252 * @server_account: if TRUE, this is a server account
254 * get a password from an account
256 * Returns: a newly allocated string with the value for the key,
257 * or NULL in case of error.
259 gchar* modest_account_mgr_get_password (ModestAccountMgr *self,
262 gboolean server_account);
265 * modest_account_mgr_get_int:
266 * @self: a ModestAccountMgr instance
267 * @name: the name of the account
268 * @key: the key of the value to retrieve
269 * @server_account: if TRUE, this is a server account
271 * get a config int from an account
273 * Returns: an integer with the value for the key, or -1 in case of
274 * error (but of course -1 does not necessarily imply an error)
276 gint modest_account_mgr_get_int (ModestAccountMgr *self,
279 gboolean server_account);
282 * modest_account_mgr_get_bool:
283 * @self: a ModestAccountMgr instance
284 * @name: the name of the account
285 * @key: the key of the value to retrieve
286 * @server_account: if TRUE, this is a server account
288 * get a config boolean from an account
290 * Returns: an boolean with the value for the key, or FALSE in case of
291 * error (but of course FALSE does not necessarily imply an error)
293 gboolean modest_account_mgr_get_bool (ModestAccountMgr *self,
296 gboolean server_account);
299 * modest_account_mgr_get_list:
300 * @self: a ModestAccountMgr instance
301 * @name: the name of the account
302 * @key: the key of the value to get
303 * @list_type: the type of the members of the list
304 * @server_account: if TRUE, this is a server account
306 * get a config list of values of type @list_type of an account
308 * Returns: a newly allocated list of elements
310 GSList* modest_account_mgr_get_list (ModestAccountMgr *self,
313 ModestConfValueType list_type,
314 gboolean server_account);
317 * modest_account_mgr_set_string:
318 * @self: a ModestAccountMgr instance
319 * @name: the name of the account
320 * @key: the key of the value to set
321 * @val: the value to set
322 * @server_account: if TRUE, this is a server account
324 * set a config string for an account.
326 * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
328 gboolean modest_account_mgr_set_string (ModestAccountMgr *self,
330 const gchar *key, const gchar* val,
331 gboolean server_account);
335 * modest_account_mgr_set_password:
336 * @self: a ModestAccountMgr instance
337 * @name: the name of the account
338 * @key: the key of the value to set
339 * @val: the value to set
340 * @server_account: if TRUE, this is a server account
342 * set a password for an account.
344 * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
345 * @err gives details in case of error
347 gboolean modest_account_mgr_set_password (ModestAccountMgr *self,
349 const gchar *key, const gchar* val,
350 gboolean server_account);
353 * modest_account_mgr_set_int:
354 * @self: a ModestAccountMgr instance
355 * @name: the name of the account
356 * @key: the key of the value to set
357 * @val: the value to set
358 * @server_account: if TRUE, this is a server account
360 * set a config int for an account
362 * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
364 gboolean modest_account_mgr_set_int (ModestAccountMgr *self,
366 const gchar *key, gint val,
367 gboolean server_account);
370 * modest_account_mgr_set_bool:
371 * @self: a ModestAccountMgr instance
372 * @name: the name of the account
373 * @key: the key of the value to set
374 * @val: the value to set
375 * @server_account: if TRUE, this is a server account
377 * set a config bool for an account
379 * Returns: TRUE if setting the value succeeded, or FALSE in case of error.
381 gboolean modest_account_mgr_set_bool (ModestAccountMgr *self,
383 const gchar *key, gboolean val,
384 gboolean server_account);
387 * modest_account_mgr_set_list:
388 * @self: a ModestAccountMgr instance
389 * @name: the name of the account
390 * @key: the key of the value to set
391 * @val: the list with the values to set
392 * @list_type: the type of the members of the list
393 * @server_account: if TRUE, this is a server account
395 * * set a config list of values of type @list_type of an account
397 * returns TRUE if this succeeded, FALSE otherwise
399 gboolean modest_account_mgr_set_list (ModestAccountMgr *self,
403 ModestConfValueType list_type,
404 gboolean server_account);
407 * modest_account_mgr_unset:
408 * @self: a ModestAccountMgr instance
409 * @name: the name of the account
410 * @key: the key of the value to unset
411 * @server_account: if TRUE, this is a server account
412 * @err: a GError ptr, or NULL to ignore.
414 * unsets the config value of an account and all their children keys
416 * Returns: TRUE if unsetting the value succeeded, or FALSE in case of error.
417 * @err gives details in case of error
419 gboolean modest_account_mgr_unset (ModestAccountMgr *self,
422 gboolean server_account);
426 #endif /* __MODEST_ACCOUNT_MGR_H__ */