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,
84 modest_account_mgr_free_server_account_data (ModestAccountMgr *self,
85 ModestServerAccountData* data)
87 g_return_if_fail (self);
90 return; /* not an error */
92 g_free (data->account_name);
93 data->account_name = NULL;
95 g_free (data->hostname);
96 data->hostname = NULL;
98 g_free (data->username);
99 data->username = NULL;
101 g_free (data->password);
102 data->password = NULL;
108 modest_account_mgr_get_account_data (ModestAccountMgr *self, const gchar* name)
110 ModestAccountData *data;
111 gchar *server_account;
113 g_return_val_if_fail (self, NULL);
114 g_return_val_if_fail (name, NULL);
115 g_return_val_if_fail (modest_account_mgr_account_exists (self, name,
117 data = g_new0 (ModestAccountData, 1);
119 data->account_name = g_strdup (name);
121 data->display_name = modest_account_mgr_get_string (self, name,
122 MODEST_ACCOUNT_DISPLAY_NAME,
124 data->fullname = modest_account_mgr_get_string (self, name,
125 MODEST_ACCOUNT_FULLNAME,
127 data->email = modest_account_mgr_get_string (self, name,
128 MODEST_ACCOUNT_EMAIL,
130 data->enabled = modest_account_mgr_account_get_enabled (self, name);
133 server_account = modest_account_mgr_get_string (self, name,
134 MODEST_ACCOUNT_STORE_ACCOUNT,
136 if (server_account) {
137 data->store_account =
138 modest_account_mgr_get_server_account_data (self,
140 g_free (server_account);
144 server_account = modest_account_mgr_get_string (self, name,
145 MODEST_ACCOUNT_TRANSPORT_ACCOUNT,
147 if (server_account) {
148 data->transport_account =
149 modest_account_mgr_get_server_account_data (self,
151 g_free (server_account);
159 modest_account_mgr_free_account_data (ModestAccountMgr *self, ModestAccountData *data)
161 g_return_if_fail (self);
163 if (!data) /* not an error */
166 g_free (data->account_name);
167 g_free (data->display_name);
168 g_free (data->fullname);
169 g_free (data->email);
171 modest_account_mgr_free_server_account_data (self, data->store_account);
172 modest_account_mgr_free_server_account_data (self, data->transport_account);
179 modest_account_mgr_get_default_account (ModestAccountMgr *self)
184 g_return_val_if_fail (self, NULL);
186 conf = MODEST_ACCOUNT_MGR_GET_PRIVATE (self)->modest_conf;
187 account = modest_conf_get_string (conf, MODEST_CONF_DEFAULT_ACCOUNT,
190 /* it's not really an error if there is no default account */
195 if (!modest_account_mgr_account_exists (self, account, FALSE, NULL)) {
196 g_printerr ("modest: default account does not exist\n");
205 modest_account_mgr_set_default_account (ModestAccountMgr *self, const gchar* account)
209 g_return_val_if_fail (self, FALSE);
210 g_return_val_if_fail (account, FALSE);
211 g_return_val_if_fail (modest_account_mgr_account_exists (self, account, FALSE, NULL),
214 conf = MODEST_ACCOUNT_MGR_GET_PRIVATE (self)->modest_conf;
216 return modest_conf_set_string (conf, MODEST_CONF_DEFAULT_ACCOUNT,