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.
30 #include <modest-account-mgr-helpers.h>
31 #include <modest-account-mgr-priv.h>
35 modest_account_mgr_account_set_enabled (ModestAccountMgr *self, const gchar* name,
38 return modest_account_mgr_set_bool (self, name,
39 MODEST_ACCOUNT_ENABLED, enabled,
45 modest_account_mgr_account_get_enabled (ModestAccountMgr *self, const gchar* name)
47 return modest_account_mgr_get_bool (self, name,
48 MODEST_ACCOUNT_ENABLED, FALSE,
53 static ModestServerAccountData*
54 modest_account_mgr_get_server_account_data (ModestAccountMgr *self, const gchar* name)
56 ModestServerAccountData *data;
59 g_return_val_if_fail (modest_account_mgr_account_exists (self, name,
61 data = g_new0 (ModestServerAccountData, 1);
63 data->account_name = g_strdup (name);
64 data->hostname = modest_account_mgr_get_string (self, name,
65 MODEST_ACCOUNT_HOSTNAME,
67 data->username = modest_account_mgr_get_string (self, name,
68 MODEST_ACCOUNT_USERNAME,
71 proto = modest_account_mgr_get_string (self, name, MODEST_ACCOUNT_PROTO,
73 data->proto = modest_protocol_info_get_protocol (proto);
76 data->password = modest_account_mgr_get_string (self, name,
77 MODEST_ACCOUNT_PASSWORD,
80 data->options = modest_account_mgr_get_list (self, name,
81 MODEST_ACCOUNT_OPTIONS,
82 MODEST_CONF_VALUE_STRING,
89 modest_account_mgr_free_server_account_data (ModestAccountMgr *self,
90 ModestServerAccountData* data)
92 g_return_if_fail (self);
95 return; /* not an error */
97 g_free (data->account_name);
98 data->account_name = NULL;
100 g_free (data->hostname);
101 data->hostname = NULL;
103 g_free (data->username);
104 data->username = NULL;
106 g_free (data->password);
107 data->password = NULL;
110 GSList *tmp = data->options;
113 tmp = g_slist_next (tmp);
115 g_slist_free (data->options);
122 modest_account_mgr_get_account_data (ModestAccountMgr *self, const gchar* name)
124 ModestAccountData *data;
125 gchar *server_account;
127 g_return_val_if_fail (self, NULL);
128 g_return_val_if_fail (name, NULL);
129 g_return_val_if_fail (modest_account_mgr_account_exists (self, name,
131 data = g_new0 (ModestAccountData, 1);
133 data->account_name = g_strdup (name);
135 data->display_name = modest_account_mgr_get_string (self, name,
136 MODEST_ACCOUNT_DISPLAY_NAME,
138 data->fullname = modest_account_mgr_get_string (self, name,
139 MODEST_ACCOUNT_FULLNAME,
141 data->email = modest_account_mgr_get_string (self, name,
142 MODEST_ACCOUNT_EMAIL,
144 data->enabled = modest_account_mgr_account_get_enabled (self, name);
147 server_account = modest_account_mgr_get_string (self, name,
148 MODEST_ACCOUNT_STORE_ACCOUNT,
150 if (server_account) {
151 data->store_account =
152 modest_account_mgr_get_server_account_data (self,
154 g_free (server_account);
158 server_account = modest_account_mgr_get_string (self, name,
159 MODEST_ACCOUNT_TRANSPORT_ACCOUNT,
161 if (server_account) {
162 data->transport_account =
163 modest_account_mgr_get_server_account_data (self,
165 g_free (server_account);
173 modest_account_mgr_free_account_data (ModestAccountMgr *self, ModestAccountData *data)
175 g_return_if_fail (self);
177 if (!data) /* not an error */
180 g_free (data->account_name);
181 g_free (data->display_name);
182 g_free (data->fullname);
183 g_free (data->email);
185 modest_account_mgr_free_server_account_data (self, data->store_account);
186 modest_account_mgr_free_server_account_data (self, data->transport_account);
193 modest_account_mgr_get_default_account (ModestAccountMgr *self)
198 g_return_val_if_fail (self, NULL);
200 conf = MODEST_ACCOUNT_MGR_GET_PRIVATE (self)->modest_conf;
201 account = modest_conf_get_string (conf, MODEST_CONF_DEFAULT_ACCOUNT,
204 /* it's not really an error if there is no default account */
209 if (!modest_account_mgr_account_exists (self, account, FALSE, NULL)) {
210 g_printerr ("modest: default account does not exist\n");
220 modest_account_mgr_set_default_account (ModestAccountMgr *self, const gchar* account)
224 g_return_val_if_fail (self, FALSE);
225 g_return_val_if_fail (account, FALSE);
226 g_return_val_if_fail (modest_account_mgr_account_exists (self, account, FALSE, NULL),
229 conf = MODEST_ACCOUNT_MGR_GET_PRIVATE (self)->modest_conf;
231 return modest_conf_set_string (conf, MODEST_CONF_DEFAULT_ACCOUNT,