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 #include "widgets/modest-serversecurity-combo-box.h"
38 #include "widgets/modest-secureauth-combo-box.h"
42 MISSING_MANDATORY_DATA_SIGNAL,
46 static guint signals[LAST_SIGNAL] = {0};
49 modest_security_options_view_load_settings (ModestSecurityOptionsView* self,
50 ModestAccountSettings *settings)
52 ModestSecurityOptionsViewPrivate *priv;
53 ModestServerAccountSettings *server_settings;
54 ModestProtocolType server_proto, secure_protocol, secure_auth;
55 ModestServersecurityComboBox *combo;
57 priv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
59 /* Save initial settings */
60 if (self->type == MODEST_SECURITY_OPTIONS_INCOMING)
61 server_settings = modest_account_settings_get_store_settings (settings);
63 server_settings = modest_account_settings_get_transport_settings (settings);
65 server_proto = modest_server_account_settings_get_protocol (server_settings);
66 secure_protocol = modest_server_account_settings_get_security_protocol (server_settings);
67 secure_auth = modest_server_account_settings_get_auth_protocol (server_settings);
69 priv->initial_state.security = secure_protocol;
70 priv->initial_state.auth = secure_auth;
71 priv->initial_state.port = modest_server_account_settings_get_port (server_settings);
74 combo = MODEST_SERVERSECURITY_COMBO_BOX (priv->security_view);
75 modest_security_options_view_set_server_type (self, server_proto);
76 modest_serversecurity_combo_box_set_active_serversecurity (combo, secure_protocol);
78 /* update_incoming_server_title (dialog, dialog->incoming_protocol); */
80 /* Username and password */
81 if (priv->full && self->type == MODEST_SECURITY_OPTIONS_OUTGOING) {
82 priv->initial_state.user =
83 modest_server_account_settings_get_username (server_settings);
84 priv->initial_state.pwd =
85 modest_server_account_settings_get_password (server_settings);
87 if (priv->initial_state.user)
88 gtk_entry_set_text(GTK_ENTRY (priv->user_entry),
89 priv->initial_state.user);
90 if (priv->initial_state.pwd)
91 gtk_entry_set_text(GTK_ENTRY (priv->pwd_entry),
92 priv->initial_state.pwd);
96 if (self->type == MODEST_SECURITY_OPTIONS_INCOMING) {
97 /* Active the authentication checkbox */
98 if (modest_protocol_registry_protocol_type_is_secure (modest_runtime_get_protocol_registry (),
100 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->auth_view),
103 modest_secureauth_combo_box_set_active_secureauth (
104 MODEST_SECUREAUTH_COMBO_BOX (priv->auth_view), secure_auth);
107 MODEST_SECURITY_OPTIONS_VIEW_GET_CLASS (self)->load_settings (self, settings);
110 g_object_unref (server_settings);
114 modest_security_options_view_save_settings (ModestSecurityOptionsView* self,
115 ModestAccountSettings *settings)
117 ModestServerAccountSettings *server_settings;
118 ModestProtocolType security_proto, auth_protocol;
119 ModestSecurityOptionsViewPrivate *priv;
120 ModestProtocolRegistry *proto_registry;
122 priv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
123 proto_registry = modest_runtime_get_protocol_registry ();
125 if (self->type == MODEST_SECURITY_OPTIONS_INCOMING)
126 server_settings = modest_account_settings_get_store_settings (settings);
128 server_settings = modest_account_settings_get_transport_settings (settings);
131 security_proto = MODEST_PROTOCOLS_CONNECTION_NONE;
132 auth_protocol = MODEST_PROTOCOLS_AUTH_NONE;
135 security_proto = modest_serversecurity_combo_box_get_active_serversecurity (MODEST_SERVERSECURITY_COMBO_BOX (priv->security_view));
137 if (self->type == MODEST_SECURITY_OPTIONS_INCOMING) {
138 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->auth_view))) {
139 if (!modest_protocol_registry_protocol_type_is_secure (proto_registry,
142 /* auth_protocol = check_first_supported_auth_method (self); */
143 auth_protocol = MODEST_PROTOCOLS_AUTH_PASSWORD;
145 auth_protocol = MODEST_PROTOCOLS_AUTH_PASSWORD;
149 auth_protocol = modest_secureauth_combo_box_get_active_secureauth (
150 MODEST_SECUREAUTH_COMBO_BOX (priv->auth_view));
154 modest_server_account_settings_set_security_protocol (server_settings,
156 modest_server_account_settings_set_auth_protocol (server_settings,
159 if (priv->full && self->type == MODEST_SECURITY_OPTIONS_OUTGOING) {
160 const gchar *username, *password;
162 username = gtk_entry_get_text (GTK_ENTRY (priv->user_entry));
163 password = gtk_entry_get_text (GTK_ENTRY (priv->pwd_entry));
165 modest_server_account_settings_set_username (server_settings, username);
166 modest_server_account_settings_set_password (server_settings, password);
169 MODEST_SECURITY_OPTIONS_VIEW_GET_CLASS (self)->save_settings (self, settings);
173 g_object_unref (server_settings);
177 modest_security_options_view_set_server_type (ModestSecurityOptionsView* self,
178 ModestProtocolType server_type)
180 ModestSecurityOptionsViewPrivate *priv;
181 ModestServersecurityComboBox *combo;
183 priv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
184 combo = MODEST_SERVERSECURITY_COMBO_BOX (priv->security_view);
186 modest_serversecurity_combo_box_fill (combo, server_type);
187 modest_serversecurity_combo_box_set_active_serversecurity (combo,
188 MODEST_PROTOCOLS_CONNECTION_NONE);
192 get_current_state (ModestSecurityOptionsView* self,
193 ModestSecurityOptionsState *state)
195 ModestSecurityOptionsViewPrivate *priv;
196 ModestProtocolRegistry *proto_registry;
198 priv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
199 proto_registry = modest_runtime_get_protocol_registry ();
203 modest_serversecurity_combo_box_get_active_serversecurity (MODEST_SERVERSECURITY_COMBO_BOX (priv->security_view));
206 if (self->type == MODEST_SECURITY_OPTIONS_OUTGOING) {
207 state->auth = modest_secureauth_combo_box_get_active_secureauth (MODEST_SECUREAUTH_COMBO_BOX (priv->auth_view));
211 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->auth_view)))
212 state->auth = priv->initial_state.auth;
214 state->auth = MODEST_PROTOCOLS_AUTH_NONE;
219 modest_security_options_view_changed (ModestSecurityOptionsView* self,
220 ModestAccountSettings *settings)
222 ModestSecurityOptionsViewPrivate *priv;
223 ModestSecurityOptionsState state = {0};
225 priv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
227 get_current_state (self, &state);
229 if (state.security != priv->initial_state.security ||
230 state.auth != priv->initial_state.auth)
233 if (priv->full && self->type == MODEST_SECURITY_OPTIONS_OUTGOING) {
234 const gchar *username, *password;
236 username = gtk_entry_get_text (GTK_ENTRY (priv->user_entry));
237 password = gtk_entry_get_text (GTK_ENTRY (priv->pwd_entry));
239 if (!priv->initial_state.user && strcmp (username, ""))
241 if (!priv->initial_state.pwd && strcmp (password, ""))
244 if ((priv->initial_state.user &&
245 strcmp (priv->initial_state.user, username)) ||
246 (priv->initial_state.pwd &&
247 strcmp (priv->initial_state.pwd, password)))
252 return MODEST_SECURITY_OPTIONS_VIEW_GET_CLASS (self)->changed (self, settings);
256 modest_security_options_view_enable_changes (ModestSecurityOptionsView* self,
259 ModestSecurityOptionsViewPrivate *priv;
261 priv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
262 gtk_widget_set_sensitive (priv->port_view, enable);
263 gtk_widget_set_sensitive (priv->security_view, enable);
267 modest_security_options_view_auth_check (ModestSecurityOptionsView* self)
269 ModestSecurityOptionsViewPrivate *priv;
270 ModestProtocolType security_incoming_type;
271 gboolean auth_active, is_secure;
272 ModestProtocolRegistry *protocol_registry;
274 priv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
275 protocol_registry = modest_runtime_get_protocol_registry ();
277 /* Check if the server supports secure authentication */
278 security_incoming_type =
279 modest_serversecurity_combo_box_get_active_serversecurity (MODEST_SERVERSECURITY_COMBO_BOX (priv->security_view));
282 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->auth_view));
284 modest_protocol_registry_protocol_type_has_tag (protocol_registry,
285 security_incoming_type,
286 MODEST_PROTOCOL_REGISTRY_SECURE_PROTOCOLS);
288 if (auth_active && !is_secure)
295 modest_security_options_view_get_supported_auth_methods (ModestSecurityOptionsView *self,
296 const gchar *hostname,
297 const gchar *username,
298 ModestProtocolType server_type)
301 GError *error = NULL;
302 GList *list_auth_methods, *retval = NULL;
303 ModestSecurityOptionsViewPrivate *priv;
304 ModestAccountSettings current_settings;
305 ModestServerAccountSettings *server_settings;
307 priv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
309 window = GTK_WINDOW (gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_WINDOW));
311 /* Get current settings */
312 modest_security_options_view_save_settings (self, ¤t_settings);
314 if (self->type == MODEST_SECURITY_OPTIONS_INCOMING)
315 server_settings = modest_account_settings_get_store_settings (¤t_settings);
317 server_settings = modest_account_settings_get_transport_settings (¤t_settings);
320 modest_utils_get_supported_secure_authentication_methods (server_type,
322 modest_server_account_settings_get_port (server_settings),
327 if (list_auth_methods) {
328 GList *list = NULL, *method = NULL;
329 ModestProtocolRegistry *registry = modest_runtime_get_protocol_registry ();
331 for (method = list_auth_methods; method != NULL; method = g_list_next(method)) {
332 ModestProtocolType auth_protocol_type =
333 (ModestProtocolType) (GPOINTER_TO_INT(method->data));
334 if (modest_protocol_registry_protocol_type_is_secure (registry,
335 auth_protocol_type)) {
336 list = g_list_append(list, GINT_TO_POINTER(auth_protocol_type));
339 g_list_free(list_auth_methods);
347 error->domain != modest_utils_get_supported_secure_authentication_error_quark() ||
348 error->code != MODEST_UTILS_GET_SUPPORTED_SECURE_AUTHENTICATION_ERROR_CANCELED) {
349 modest_platform_information_banner (GTK_WIDGET(self),
351 _("mcen_ib_unableto_discover_auth_methods"));
359 g_object_unref (server_settings);
365 modest_security_options_view_init (ModestSecurityOptionsView *self)
367 ModestSecurityOptionsViewPrivate *priv = MODEST_SECURITY_OPTIONS_VIEW_GET_PRIVATE (self);
369 memset (&(priv->initial_state), 0, sizeof (ModestSecurityOptionsState));
371 priv->security_view = NULL;
372 priv->port_view = NULL;
373 priv->auth_view = NULL;
374 priv->user_entry = NULL;
375 priv->pwd_entry = NULL;
379 modest_security_options_view_class_init (ModestSecurityOptionsViewClass *klass)
381 GObjectClass *gobject_class = (GObjectClass*) klass;
383 g_type_class_add_private (gobject_class, sizeof (ModestSecurityOptionsViewPrivate));
385 /* Register signals */
386 signals[MISSING_MANDATORY_DATA_SIGNAL] =
387 g_signal_new ("missing_mandatory_data",
388 MODEST_TYPE_SECURITY_OPTIONS_VIEW,
390 G_STRUCT_OFFSET(ModestSecurityOptionsViewClass, missing_mandatory_data),
392 g_cclosure_marshal_VOID__BOOLEAN,
393 G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
396 /* Type definition */
397 G_DEFINE_ABSTRACT_TYPE (ModestSecurityOptionsView,
398 modest_security_options_view,