1 /* Copyright (c) 2008, 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.
32 #include "modest-utils.h"
33 #include "modest-runtime.h"
34 #include "modest-platform.h"
35 #include "modest-security-options-view.h"
36 #include "modest-security-options-view-priv.h"
37 #ifdef MODEST_TOOLKIT_HILDON2
38 #include "modest-secureauth-picker.h"
39 #include <modest-hildon-includes.h>
41 #include "widgets/modest-secureauth-combo-box.h"
45 MISSING_MANDATORY_DATA_SIGNAL,
49 static guint signals[LAST_SIGNAL] = {0};
52 modest_security_options_view_load_settings (ModestSecurityOptionsView* self,
53 ModestAccountSettings *settings)
55 ModestSecurityOptionsViewPrivate *priv;
56 ModestServerAccountSettings *server_settings;
57 ModestProtocolType server_proto, secure_protocol, secure_auth;
59 priv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
61 /* Save initial settings */
62 if (self->type == MODEST_SECURITY_OPTIONS_INCOMING)
63 server_settings = modest_account_settings_get_store_settings (settings);
65 server_settings = modest_account_settings_get_transport_settings (settings);
67 server_proto = modest_server_account_settings_get_protocol (server_settings);
68 secure_protocol = modest_server_account_settings_get_security_protocol (server_settings);
69 secure_auth = modest_server_account_settings_get_auth_protocol (server_settings);
71 priv->initial_state.security = secure_protocol;
72 priv->initial_state.auth = secure_auth;
73 priv->initial_state.port = modest_server_account_settings_get_port (server_settings);
76 modest_security_options_view_set_server_type (self, server_proto);
77 modest_serversecurity_selector_set_active_serversecurity (priv->security_view, secure_protocol);
79 /* update_incoming_server_title (dialog, dialog->incoming_protocol); */
81 /* Username and password */
82 if (priv->full && self->type == MODEST_SECURITY_OPTIONS_OUTGOING) {
83 priv->initial_state.user =
84 modest_server_account_settings_get_username (server_settings);
85 priv->initial_state.pwd =
86 modest_server_account_settings_get_password (server_settings);
88 if (priv->initial_state.user)
89 gtk_entry_set_text(GTK_ENTRY (priv->user_entry),
90 priv->initial_state.user);
91 if (priv->initial_state.pwd)
92 gtk_entry_set_text(GTK_ENTRY (priv->pwd_entry),
93 priv->initial_state.pwd);
97 if (self->type == MODEST_SECURITY_OPTIONS_INCOMING) {
98 /* Active the authentication checkbox */
99 if (modest_protocol_registry_protocol_type_is_secure (modest_runtime_get_protocol_registry (),
101 modest_togglable_set_active (priv->auth_view,
104 if (MODEST_IS_SECUREAUTH_COMBO_BOX (priv->auth_view)) {
105 modest_secureauth_combo_box_set_active_secureauth (
106 MODEST_SECUREAUTH_COMBO_BOX (priv->auth_view), secure_auth);
108 #ifdef MODEST_TOOLKIT_HILDON2
109 modest_secureauth_picker_set_active_secureauth (
110 MODEST_SECUREAUTH_PICKER (priv->auth_view), secure_auth);
115 MODEST_SECURITY_OPTIONS_VIEW_GET_CLASS (self)->load_settings (self, settings);
118 g_object_unref (server_settings);
122 modest_security_options_view_save_settings (ModestSecurityOptionsView* self,
123 ModestAccountSettings *settings)
125 ModestServerAccountSettings *server_settings;
126 ModestProtocolType security_proto, auth_protocol;
127 ModestSecurityOptionsViewPrivate *priv;
128 ModestProtocolRegistry *proto_registry;
130 priv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
131 proto_registry = modest_runtime_get_protocol_registry ();
133 if (self->type == MODEST_SECURITY_OPTIONS_INCOMING)
134 server_settings = modest_account_settings_get_store_settings (settings);
136 server_settings = modest_account_settings_get_transport_settings (settings);
139 security_proto = MODEST_PROTOCOLS_CONNECTION_NONE;
140 auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
143 security_proto = modest_serversecurity_selector_get_active_serversecurity (priv->security_view);
145 if (self->type == MODEST_SECURITY_OPTIONS_INCOMING) {
146 if (modest_togglable_get_active (priv->auth_view)) {
147 if (!modest_protocol_registry_protocol_type_is_secure (proto_registry,
150 /* auth_protocol = check_first_supported_auth_method (self); */
151 auth_protocol = MODEST_PROTOCOLS_AUTH_PASSWORD;
153 auth_protocol = MODEST_PROTOCOLS_AUTH_PASSWORD;
157 if (MODEST_IS_SECUREAUTH_COMBO_BOX (priv->auth_view)) {
158 auth_protocol = modest_secureauth_combo_box_get_active_secureauth (
159 MODEST_SECUREAUTH_COMBO_BOX (priv->auth_view));
161 #ifdef MODEST_TOOLKIT_HILDON2
162 auth_protocol = modest_secureauth_picker_get_active_secureauth (
163 MODEST_SECUREAUTH_PICKER (priv->auth_view));
169 modest_server_account_settings_set_security_protocol (server_settings,
171 modest_server_account_settings_set_auth_protocol (server_settings,
174 if (priv->full && self->type == MODEST_SECURITY_OPTIONS_OUTGOING) {
175 const gchar *username, *password;
177 username = gtk_entry_get_text (GTK_ENTRY (priv->user_entry));
178 password = gtk_entry_get_text (GTK_ENTRY (priv->pwd_entry));
180 modest_server_account_settings_set_username (server_settings, username);
181 modest_server_account_settings_set_password (server_settings, password);
184 MODEST_SECURITY_OPTIONS_VIEW_GET_CLASS (self)->save_settings (self, settings);
188 g_object_unref (server_settings);
192 modest_security_options_view_set_server_type (ModestSecurityOptionsView* self,
193 ModestProtocolType server_type)
195 ModestSecurityOptionsViewPrivate *priv;
196 priv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
198 modest_serversecurity_selector_fill (priv->security_view, server_type);
199 modest_serversecurity_selector_set_active_serversecurity (priv->security_view,
200 MODEST_PROTOCOLS_CONNECTION_NONE);
204 get_current_state (ModestSecurityOptionsView* self,
205 ModestSecurityOptionsState *state)
207 ModestSecurityOptionsViewPrivate *priv;
208 ModestProtocolRegistry *proto_registry;
210 priv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
211 proto_registry = modest_runtime_get_protocol_registry ();
215 modest_serversecurity_selector_get_active_serversecurity (priv->security_view);
217 modest_serversecurity_selector_get_active_serversecurity_port (priv->security_view);
220 if (self->type == MODEST_SECURITY_OPTIONS_OUTGOING) {
221 if (MODEST_IS_SECUREAUTH_COMBO_BOX (priv->auth_view)) {
222 state->auth = modest_secureauth_combo_box_get_active_secureauth (MODEST_SECUREAUTH_COMBO_BOX (priv->auth_view));
224 #ifdef MODEST_TOOLKIT_HILDON2
225 state->auth = modest_secureauth_picker_get_active_secureauth (MODEST_SECUREAUTH_PICKER (priv->auth_view));
231 if (modest_togglable_get_active (priv->auth_view))
232 state->auth = priv->initial_state.auth;
234 state->auth = MODEST_PROTOCOLS_AUTH_NONE;
239 modest_security_options_view_changed (ModestSecurityOptionsView* self,
240 ModestAccountSettings *settings)
242 ModestSecurityOptionsViewPrivate *priv;
243 ModestSecurityOptionsState state = {0};
245 priv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
247 get_current_state (self, &state);
249 if (state.security != priv->initial_state.security ||
250 state.auth != priv->initial_state.auth)
253 if (priv->full && self->type == MODEST_SECURITY_OPTIONS_OUTGOING) {
254 const gchar *username, *password;
256 username = gtk_entry_get_text (GTK_ENTRY (priv->user_entry));
257 password = gtk_entry_get_text (GTK_ENTRY (priv->pwd_entry));
259 if (!priv->initial_state.user && strcmp (username, ""))
261 if (!priv->initial_state.pwd && strcmp (password, ""))
264 if ((priv->initial_state.user &&
265 strcmp (priv->initial_state.user, username)) ||
266 (priv->initial_state.pwd &&
267 strcmp (priv->initial_state.pwd, password)))
272 return MODEST_SECURITY_OPTIONS_VIEW_GET_CLASS (self)->changed (self, settings);
276 modest_security_options_view_enable_changes (ModestSecurityOptionsView* self,
279 ModestSecurityOptionsViewPrivate *priv;
281 priv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
282 gtk_widget_set_sensitive (priv->port_view, enable);
283 gtk_widget_set_sensitive (priv->security_view, enable);
287 modest_security_options_view_auth_check (ModestSecurityOptionsView* self)
289 ModestSecurityOptionsViewPrivate *priv;
290 ModestProtocolType security_incoming_type;
291 gboolean auth_active, is_secure;
292 ModestProtocolRegistry *protocol_registry;
294 priv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
295 protocol_registry = modest_runtime_get_protocol_registry ();
297 /* Check if the server supports secure authentication */
298 security_incoming_type =
299 modest_serversecurity_selector_get_active_serversecurity (priv->security_view);
302 modest_togglable_get_active (priv->auth_view);
304 modest_protocol_registry_protocol_type_has_tag (protocol_registry,
305 security_incoming_type,
306 MODEST_PROTOCOL_REGISTRY_SECURE_PROTOCOLS);
308 if (auth_active && !is_secure)
315 modest_security_options_view_get_connection_protocol (ModestSecurityOptionsView *self)
317 ModestSecurityOptionsViewPrivate *priv;
319 g_return_val_if_fail (MODEST_IS_SECURITY_OPTIONS_VIEW (self), MODEST_PROTOCOL_REGISTRY_TYPE_INVALID);
320 priv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
322 return modest_serversecurity_selector_get_active_serversecurity (priv->security_view);
326 modest_security_options_view_init (ModestSecurityOptionsView *self)
328 ModestSecurityOptionsViewPrivate *priv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
330 memset (&(priv->initial_state), 0, sizeof (ModestSecurityOptionsState));
332 priv->security_view = NULL;
333 priv->port_view = NULL;
334 priv->auth_view = NULL;
335 priv->user_entry = NULL;
336 priv->pwd_entry = NULL;
338 priv->changed = FALSE;
342 modest_security_options_view_class_init (ModestSecurityOptionsViewClass *klass)
344 GObjectClass *gobject_class = (GObjectClass*) klass;
346 g_type_class_add_private (gobject_class, sizeof (ModestSecurityOptionsViewPrivate));
348 /* Register signals */
349 signals[MISSING_MANDATORY_DATA_SIGNAL] =
350 g_signal_new ("missing_mandatory_data",
351 MODEST_TYPE_SECURITY_OPTIONS_VIEW,
353 G_STRUCT_OFFSET(ModestSecurityOptionsViewClass, missing_mandatory_data),
355 g_cclosure_marshal_VOID__BOOLEAN,
356 G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
359 /* Type definition */
360 G_DEFINE_ABSTRACT_TYPE (ModestSecurityOptionsView,
361 modest_security_options_view,