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));
241 modest_serversecurity_combo_box_get_active_serversecurity (MODEST_SERVERSECURITY_COMBO_BOX (priv->security_view));
245 if (self->type == MODEST_SECURITY_OPTIONS_OUTGOING) {
246 #ifdef MODEST_TOOLKIT_HILDON2
247 state->auth = modest_secureauth_picker_get_active_secureauth (MODEST_SECUREAUTH_PICKER (priv->auth_view));
249 state->auth = modest_secureauth_combo_box_get_active_secureauth (MODEST_SECUREAUTH_COMBO_BOX (priv->auth_view));
254 #ifdef MODEST_TOOLKIT_HILDON2
255 if (hildon_check_button_get_active (HILDON_CHECK_BUTTON (priv->auth_view)))
257 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->auth_view)))
259 state->auth = priv->initial_state.auth;
261 state->auth = MODEST_PROTOCOLS_AUTH_NONE;
266 modest_security_options_view_changed (ModestSecurityOptionsView* self,
267 ModestAccountSettings *settings)
269 ModestSecurityOptionsViewPrivate *priv;
270 ModestSecurityOptionsState state = {0};
272 priv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
274 get_current_state (self, &state);
276 if (state.security != priv->initial_state.security ||
277 state.auth != priv->initial_state.auth)
280 if (priv->full && self->type == MODEST_SECURITY_OPTIONS_OUTGOING) {
281 const gchar *username, *password;
283 username = gtk_entry_get_text (GTK_ENTRY (priv->user_entry));
284 password = gtk_entry_get_text (GTK_ENTRY (priv->pwd_entry));
286 if (!priv->initial_state.user && strcmp (username, ""))
288 if (!priv->initial_state.pwd && strcmp (password, ""))
291 if ((priv->initial_state.user &&
292 strcmp (priv->initial_state.user, username)) ||
293 (priv->initial_state.pwd &&
294 strcmp (priv->initial_state.pwd, password)))
299 return MODEST_SECURITY_OPTIONS_VIEW_GET_CLASS (self)->changed (self, settings);
303 modest_security_options_view_enable_changes (ModestSecurityOptionsView* self,
306 ModestSecurityOptionsViewPrivate *priv;
308 priv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
309 gtk_widget_set_sensitive (priv->port_view, enable);
310 gtk_widget_set_sensitive (priv->security_view, enable);
314 modest_security_options_view_auth_check (ModestSecurityOptionsView* self)
316 ModestSecurityOptionsViewPrivate *priv;
317 ModestProtocolType security_incoming_type;
318 gboolean auth_active, is_secure;
319 ModestProtocolRegistry *protocol_registry;
321 priv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
322 protocol_registry = modest_runtime_get_protocol_registry ();
324 /* Check if the server supports secure authentication */
325 #ifdef MODEST_TOOLKIT_HILDON2
326 security_incoming_type =
327 modest_serversecurity_picker_get_active_serversecurity (MODEST_SERVERSECURITY_PICKER (priv->security_view));
329 security_incoming_type =
330 modest_serversecurity_combo_box_get_active_serversecurity (MODEST_SERVERSECURITY_COMBO_BOX (priv->security_view));
333 #ifdef MODEST_TOOLKIT_HILDON2
335 hildon_check_button_get_active (HILDON_CHECK_BUTTON (priv->auth_view));
338 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->auth_view));
341 modest_protocol_registry_protocol_type_has_tag (protocol_registry,
342 security_incoming_type,
343 MODEST_PROTOCOL_REGISTRY_SECURE_PROTOCOLS);
345 if (auth_active && !is_secure)
352 modest_security_options_view_get_supported_auth_methods (ModestSecurityOptionsView *self,
353 const gchar *hostname,
354 const gchar *username,
355 ModestProtocolType server_type)
358 GError *error = NULL;
359 GList *list_auth_methods, *retval = NULL;
360 ModestSecurityOptionsViewPrivate *priv;
361 ModestAccountSettings current_settings;
362 ModestServerAccountSettings *server_settings;
364 priv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
366 window = GTK_WINDOW (gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_WINDOW));
368 /* Get current settings */
369 modest_security_options_view_save_settings (self, ¤t_settings);
371 if (self->type == MODEST_SECURITY_OPTIONS_INCOMING)
372 server_settings = modest_account_settings_get_store_settings (¤t_settings);
374 server_settings = modest_account_settings_get_transport_settings (¤t_settings);
377 modest_utils_get_supported_secure_authentication_methods (server_type,
379 modest_server_account_settings_get_port (server_settings),
384 if (list_auth_methods) {
385 GList *list = NULL, *method = NULL;
386 ModestProtocolRegistry *registry = modest_runtime_get_protocol_registry ();
388 for (method = list_auth_methods; method != NULL; method = g_list_next(method)) {
389 ModestProtocolType auth_protocol_type =
390 (ModestProtocolType) (GPOINTER_TO_INT(method->data));
391 if (modest_protocol_registry_protocol_type_is_secure (registry,
392 auth_protocol_type)) {
393 list = g_list_append(list, GINT_TO_POINTER(auth_protocol_type));
396 g_list_free(list_auth_methods);
404 error->domain != modest_utils_get_supported_secure_authentication_error_quark() ||
405 error->code != MODEST_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED) {
406 modest_platform_information_banner (GTK_WIDGET(self),
408 _("mcen_ib_unableto_discover_auth_methods"));
416 g_object_unref (server_settings);
422 modest_security_options_view_init (ModestSecurityOptionsView *self)
424 ModestSecurityOptionsViewPrivate *priv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
426 memset (&(priv->initial_state), 0, sizeof (ModestSecurityOptionsState));
428 priv->security_view = NULL;
429 priv->port_view = NULL;
430 priv->auth_view = NULL;
431 priv->user_entry = NULL;
432 priv->pwd_entry = NULL;
436 modest_security_options_view_class_init (ModestSecurityOptionsViewClass *klass)
438 GObjectClass *gobject_class = (GObjectClass*) klass;
440 g_type_class_add_private (gobject_class, sizeof (ModestSecurityOptionsViewPrivate));
442 /* Register signals */
443 signals[MISSING_MANDATORY_DATA_SIGNAL] =
444 g_signal_new ("missing_mandatory_data",
445 MODEST_TYPE_SECURITY_OPTIONS_VIEW,
447 G_STRUCT_OFFSET(ModestSecurityOptionsViewClass, missing_mandatory_data),
449 g_cclosure_marshal_VOID__BOOLEAN,
450 G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
453 /* Type definition */
454 G_DEFINE_ABSTRACT_TYPE (ModestSecurityOptionsView,
455 modest_security_options_view,