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.
31 #include <gtk/gtkvbox.h>
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-serversecurity-picker.h"
39 #include "modest-secureauth-picker.h"
40 #include <modest-hildon-includes.h>
42 #include "widgets/modest-serversecurity-combo-box.h"
43 #include "widgets/modest-secureauth-combo-box.h"
48 MISSING_MANDATORY_DATA_SIGNAL,
52 static guint signals[LAST_SIGNAL] = {0};
55 modest_security_options_view_load_settings (ModestSecurityOptionsView* self,
56 ModestAccountSettings *settings)
58 ModestSecurityOptionsViewPrivate *priv;
59 ModestServerAccountSettings *server_settings;
60 ModestProtocolType server_proto, secure_protocol, secure_auth;
62 priv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
64 /* Save initial settings */
65 if (self->type == MODEST_SECURITY_OPTIONS_INCOMING)
66 server_settings = modest_account_settings_get_store_settings (settings);
68 server_settings = modest_account_settings_get_transport_settings (settings);
70 server_proto = modest_server_account_settings_get_protocol (server_settings);
71 secure_protocol = modest_server_account_settings_get_security_protocol (server_settings);
72 secure_auth = modest_server_account_settings_get_auth_protocol (server_settings);
74 priv->initial_state.security = secure_protocol;
75 priv->initial_state.auth = secure_auth;
76 priv->initial_state.port = modest_server_account_settings_get_port (server_settings);
79 modest_security_options_view_set_server_type (self, server_proto);
80 #ifdef MODEST_TOOLKIT_HILDON2
81 modest_serversecurity_picker_set_active_serversecurity (MODEST_SERVERSECURITY_PICKER (priv->security_view), secure_protocol);
83 modest_serversecurity_combo_box_set_active_serversecurity (MODEST_SERVERSECURITY_COMBO_BOX (priv->security_view), secure_protocol);
86 /* update_incoming_server_title (dialog, dialog->incoming_protocol); */
88 /* Username and password */
89 if (priv->full && self->type == MODEST_SECURITY_OPTIONS_OUTGOING) {
90 priv->initial_state.user =
91 modest_server_account_settings_get_username (server_settings);
92 priv->initial_state.pwd =
93 modest_server_account_settings_get_password (server_settings);
95 if (priv->initial_state.user)
96 gtk_entry_set_text(GTK_ENTRY (priv->user_entry),
97 priv->initial_state.user);
98 if (priv->initial_state.pwd)
99 gtk_entry_set_text(GTK_ENTRY (priv->pwd_entry),
100 priv->initial_state.pwd);
104 if (self->type == MODEST_SECURITY_OPTIONS_INCOMING) {
105 /* Active the authentication checkbox */
106 if (modest_protocol_registry_protocol_type_is_secure (modest_runtime_get_protocol_registry (),
108 #ifdef MODEST_TOOLKIT_HILDON2
109 hildon_check_button_set_active (HILDON_CHECK_BUTTON (priv->auth_view),
112 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->auth_view),
116 #ifdef MODEST_TOOLKIT_HILDON2
117 modest_secureauth_picker_set_active_secureauth (
118 MODEST_SECUREAUTH_PICKER (priv->auth_view), secure_auth);
120 modest_secureauth_combo_box_set_active_secureauth (
121 MODEST_SECUREAUTH_COMBO_BOX (priv->auth_view), secure_auth);
125 MODEST_SECURITY_OPTIONS_VIEW_GET_CLASS (self)->load_settings (self, settings);
128 g_object_unref (server_settings);
132 modest_security_options_view_save_settings (ModestSecurityOptionsView* self,
133 ModestAccountSettings *settings)
135 ModestServerAccountSettings *server_settings;
136 ModestProtocolType security_proto, auth_protocol;
137 ModestSecurityOptionsViewPrivate *priv;
138 ModestProtocolRegistry *proto_registry;
140 priv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
141 proto_registry = modest_runtime_get_protocol_registry ();
143 if (self->type == MODEST_SECURITY_OPTIONS_INCOMING)
144 server_settings = modest_account_settings_get_store_settings (settings);
146 server_settings = modest_account_settings_get_transport_settings (settings);
149 security_proto = MODEST_PROTOCOLS_CONNECTION_NONE;
150 auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
153 #ifdef MODEST_TOOLKIT_HILDON2
154 security_proto = modest_serversecurity_picker_get_active_serversecurity (MODEST_SERVERSECURITY_PICKER (priv->security_view));
156 security_proto = modest_serversecurity_combo_box_get_active_serversecurity (MODEST_SERVERSECURITY_COMBO_BOX (priv->security_view));
159 if (self->type == MODEST_SECURITY_OPTIONS_INCOMING) {
160 #ifdef MODEST_TOOLKIT_HILDON2
161 if (hildon_check_button_get_active (HILDON_CHECK_BUTTON (priv->auth_view))) {
163 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->auth_view))) {
165 if (!modest_protocol_registry_protocol_type_is_secure (proto_registry,
168 /* auth_protocol = check_first_supported_auth_method (self); */
169 auth_protocol = MODEST_PROTOCOLS_AUTH_PASSWORD;
171 auth_protocol = MODEST_PROTOCOLS_AUTH_PASSWORD;
175 #ifdef MODEST_TOOLKIT_HILDON2
176 auth_protocol = modest_secureauth_picker_get_active_secureauth (
177 MODEST_SECUREAUTH_PICKER (priv->auth_view));
179 auth_protocol = modest_secureauth_combo_box_get_active_secureauth (
180 MODEST_SECUREAUTH_COMBO_BOX (priv->auth_view));
185 modest_server_account_settings_set_security_protocol (server_settings,
187 modest_server_account_settings_set_auth_protocol (server_settings,
190 if (priv->full && self->type == MODEST_SECURITY_OPTIONS_OUTGOING) {
191 const gchar *username, *password;
193 username = gtk_entry_get_text (GTK_ENTRY (priv->user_entry));
194 password = gtk_entry_get_text (GTK_ENTRY (priv->pwd_entry));
196 modest_server_account_settings_set_username (server_settings, username);
197 modest_server_account_settings_set_password (server_settings, password);
200 MODEST_SECURITY_OPTIONS_VIEW_GET_CLASS (self)->save_settings (self, settings);
204 g_object_unref (server_settings);
208 modest_security_options_view_set_server_type (ModestSecurityOptionsView* self,
209 ModestProtocolType server_type)
211 ModestSecurityOptionsViewPrivate *priv;
212 priv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
214 #ifdef MODEST_TOOLKIT_HILDON2
215 modest_serversecurity_picker_fill (MODEST_SERVERSECURITY_PICKER (priv->security_view), server_type);
216 modest_serversecurity_picker_set_active_serversecurity (MODEST_SERVERSECURITY_PICKER (priv->security_view),
217 MODEST_PROTOCOLS_CONNECTION_NONE);
219 modest_serversecurity_combo_box_fill (MODEST_SERVERSECURITY_COMBO_BOX (priv->security_view), server_type);
220 modest_serversecurity_combo_box_set_active_serversecurity (MODEST_SERVERSECURITY_COMBO_BOX (priv->security_view),
221 MODEST_PROTOCOLS_CONNECTION_NONE);
226 get_current_state (ModestSecurityOptionsView* self,
227 ModestSecurityOptionsState *state)
229 ModestSecurityOptionsViewPrivate *priv;
230 ModestProtocolRegistry *proto_registry;
232 priv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
233 proto_registry = modest_runtime_get_protocol_registry ();
236 #ifdef MODEST_TOOLKIT_HILDON2
238 modest_serversecurity_picker_get_active_serversecurity (MODEST_SERVERSECURITY_PICKER (priv->security_view));
240 modest_serversecurity_picker_get_active_serversecurity_port (MODEST_SERVERSECURITY_PICKER (priv->security_view));
243 modest_serversecurity_combo_box_get_active_serversecurity (MODEST_SERVERSECURITY_COMBO_BOX (priv->security_view));
245 modest_serversecurity_combo_box_get_active_serversecurity_port (MODEST_SERVERSECURITY_COMBO_BOX (priv->security_view));
249 if (self->type == MODEST_SECURITY_OPTIONS_OUTGOING) {
250 #ifdef MODEST_TOOLKIT_HILDON2
251 state->auth = modest_secureauth_picker_get_active_secureauth (MODEST_SECUREAUTH_PICKER (priv->auth_view));
253 state->auth = modest_secureauth_combo_box_get_active_secureauth (MODEST_SECUREAUTH_COMBO_BOX (priv->auth_view));
258 #ifdef MODEST_TOOLKIT_HILDON2
259 if (hildon_check_button_get_active (HILDON_CHECK_BUTTON (priv->auth_view)))
261 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->auth_view)))
263 state->auth = priv->initial_state.auth;
265 state->auth = MODEST_PROTOCOLS_AUTH_NONE;
270 modest_security_options_view_changed (ModestSecurityOptionsView* self,
271 ModestAccountSettings *settings)
273 ModestSecurityOptionsViewPrivate *priv;
274 ModestSecurityOptionsState state = {0};
276 priv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
278 get_current_state (self, &state);
280 if (state.security != priv->initial_state.security ||
281 state.auth != priv->initial_state.auth)
284 if (priv->full && self->type == MODEST_SECURITY_OPTIONS_OUTGOING) {
285 const gchar *username, *password;
287 username = gtk_entry_get_text (GTK_ENTRY (priv->user_entry));
288 password = gtk_entry_get_text (GTK_ENTRY (priv->pwd_entry));
290 if (!priv->initial_state.user && strcmp (username, ""))
292 if (!priv->initial_state.pwd && strcmp (password, ""))
295 if ((priv->initial_state.user &&
296 strcmp (priv->initial_state.user, username)) ||
297 (priv->initial_state.pwd &&
298 strcmp (priv->initial_state.pwd, password)))
303 return MODEST_SECURITY_OPTIONS_VIEW_GET_CLASS (self)->changed (self, settings);
307 modest_security_options_view_enable_changes (ModestSecurityOptionsView* self,
310 ModestSecurityOptionsViewPrivate *priv;
312 priv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
313 gtk_widget_set_sensitive (priv->port_view, enable);
314 gtk_widget_set_sensitive (priv->security_view, enable);
318 modest_security_options_view_auth_check (ModestSecurityOptionsView* self)
320 ModestSecurityOptionsViewPrivate *priv;
321 ModestProtocolType security_incoming_type;
322 gboolean auth_active, is_secure;
323 ModestProtocolRegistry *protocol_registry;
325 priv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
326 protocol_registry = modest_runtime_get_protocol_registry ();
328 /* Check if the server supports secure authentication */
329 #ifdef MODEST_TOOLKIT_HILDON2
330 security_incoming_type =
331 modest_serversecurity_picker_get_active_serversecurity (MODEST_SERVERSECURITY_PICKER (priv->security_view));
333 security_incoming_type =
334 modest_serversecurity_combo_box_get_active_serversecurity (MODEST_SERVERSECURITY_COMBO_BOX (priv->security_view));
337 #ifdef MODEST_TOOLKIT_HILDON2
339 hildon_check_button_get_active (HILDON_CHECK_BUTTON (priv->auth_view));
342 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->auth_view));
345 modest_protocol_registry_protocol_type_has_tag (protocol_registry,
346 security_incoming_type,
347 MODEST_PROTOCOL_REGISTRY_SECURE_PROTOCOLS);
349 if (auth_active && !is_secure)
356 modest_security_options_view_get_connection_protocol (ModestSecurityOptionsView *self)
358 ModestSecurityOptionsViewPrivate *priv;
360 g_return_val_if_fail (MODEST_IS_SECURITY_OPTIONS_VIEW (self), MODEST_PROTOCOL_REGISTRY_TYPE_INVALID);
361 priv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
363 #ifdef MODEST_TOOLKIT_HILDON2
364 return modest_serversecurity_picker_get_active_serversecurity (MODEST_SERVERSECURITY_PICKER (priv->security_view));
366 return modest_serversecurity_combo_box_get_active_serversecurity (MODEST_SERVERSECURITY_COMBO_BOX (priv->security_view));
371 modest_security_options_view_init (ModestSecurityOptionsView *self)
373 ModestSecurityOptionsViewPrivate *priv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
375 memset (&(priv->initial_state), 0, sizeof (ModestSecurityOptionsState));
377 priv->security_view = NULL;
378 priv->port_view = NULL;
379 priv->auth_view = NULL;
380 priv->user_entry = NULL;
381 priv->pwd_entry = NULL;
383 priv->changed = FALSE;
387 modest_security_options_view_class_init (ModestSecurityOptionsViewClass *klass)
389 GObjectClass *gobject_class = (GObjectClass*) klass;
391 g_type_class_add_private (gobject_class, sizeof (ModestSecurityOptionsViewPrivate));
393 /* Register signals */
394 signals[MISSING_MANDATORY_DATA_SIGNAL] =
395 g_signal_new ("missing_mandatory_data",
396 MODEST_TYPE_SECURITY_OPTIONS_VIEW,
398 G_STRUCT_OFFSET(ModestSecurityOptionsViewClass, missing_mandatory_data),
400 g_cclosure_marshal_VOID__BOOLEAN,
401 G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
404 /* Type definition */
405 G_DEFINE_ABSTRACT_TYPE (ModestSecurityOptionsView,
406 modest_security_options_view,