Changes in connection specific smtp edit window:
[modest] / src / hildon2 / modest-connection-specific-smtp-edit-window.c
1 /* Copyright (c) 2006, Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
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.
16  *
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.
28  */
29
30 #include "modest-connection-specific-smtp-edit-window.h"
31 #include "widgets/modest-ui-constants.h"
32 #include "modest-hildon-includes.h"
33 #include "modest-runtime.h"
34
35 #include "modest-serversecurity-picker.h"
36 #include "modest-secureauth-picker.h"
37 #include "widgets/modest-validating-entry.h"
38 #include <hildon/hildon-pannable-area.h>
39 #include <gtk/gtkbutton.h>
40 #include <gtk/gtkhbox.h>
41 #include <gtk/gtkvbox.h>
42 #include <gtk/gtkstock.h>
43 #include "modest-text-utils.h"
44 #include "modest-maemo-utils.h"
45
46 #include <glib/gi18n.h>
47
48 #define PORT_RANGE_MIN 1
49 #define PORT_RANGE_MAX 65535
50
51 G_DEFINE_TYPE (ModestConnectionSpecificSmtpEditWindow, modest_connection_specific_smtp_edit_window, GTK_TYPE_DIALOG);
52
53 #define CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE(o) \
54         (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW, ModestConnectionSpecificSmtpEditWindowPrivate))
55
56 static void on_response (GtkDialog *dialog,
57                          gint arg1,
58                          gpointer user_data);
59
60 typedef struct _ModestConnectionSpecificSmtpEditWindowPrivate ModestConnectionSpecificSmtpEditWindowPrivate;
61
62 struct _ModestConnectionSpecificSmtpEditWindowPrivate
63 {
64         GtkWidget *entry_outgoingserver;
65         GtkWidget *outgoing_auth_picker;
66         GtkWidget *entry_user_username;
67         GtkWidget *entry_user_password;
68         GtkWidget *outgoing_security_picker;
69         GtkWidget *entry_port;
70         
71         GtkWidget *button_ok;
72         GtkWidget *button_cancel;
73
74         gchar     *account_name;
75         
76         gboolean is_dirty;
77         gboolean range_error_occured;
78         guint range_error_banner_timeout;
79 };
80
81 static void
82 modest_connection_specific_smtp_edit_window_get_property (GObject *object, guint property_id,
83                                                                                                                         GValue *value, GParamSpec *pspec)
84 {
85         switch (property_id) {
86         default:
87                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
88         }
89 }
90
91 static void
92 modest_connection_specific_smtp_edit_window_set_property (GObject *object, guint property_id,
93                                                                                                                         const GValue *value, GParamSpec *pspec)
94 {
95         switch (property_id) {
96         default:
97                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
98         }
99 }
100
101 static void
102 modest_connection_specific_smtp_edit_window_dispose (GObject *object)
103 {
104
105         
106         if (G_OBJECT_CLASS (modest_connection_specific_smtp_edit_window_parent_class)->dispose)
107                 G_OBJECT_CLASS (modest_connection_specific_smtp_edit_window_parent_class)->dispose (object);
108 }
109
110 static void
111 modest_connection_specific_smtp_edit_window_finalize (GObject *object)
112 {
113         ModestConnectionSpecificSmtpEditWindow *self = (ModestConnectionSpecificSmtpEditWindow *) object;
114         ModestConnectionSpecificSmtpEditWindowPrivate *priv =
115                 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
116
117         if (priv->range_error_banner_timeout > 0) {
118                 g_source_remove (priv->range_error_banner_timeout);
119                 priv->range_error_banner_timeout = 0;
120         }
121         if (priv->account_name) {
122                 g_free (priv->account_name);
123                 priv->account_name = NULL;
124         }
125         G_OBJECT_CLASS (modest_connection_specific_smtp_edit_window_parent_class)->finalize (object);
126 }
127
128 static void
129 modest_connection_specific_smtp_edit_window_class_init (ModestConnectionSpecificSmtpEditWindowClass *klass)
130 {
131         GObjectClass *object_class = G_OBJECT_CLASS (klass);
132
133         g_type_class_add_private (klass, sizeof (ModestConnectionSpecificSmtpEditWindowPrivate));
134
135         object_class->get_property = modest_connection_specific_smtp_edit_window_get_property;
136         object_class->set_property = modest_connection_specific_smtp_edit_window_set_property;
137         object_class->dispose = modest_connection_specific_smtp_edit_window_dispose;
138         object_class->finalize = modest_connection_specific_smtp_edit_window_finalize;
139 }
140
141 enum MODEL_COLS {
142         MODEL_COL_NAME = 0,
143         MODEL_COL_SERVER_NAME = 1,
144         MODEL_COL_ID = 2
145 };
146
147 static void
148 on_change(GtkWidget* widget, ModestConnectionSpecificSmtpEditWindow *self)
149 {
150         ModestConnectionSpecificSmtpEditWindowPrivate *priv = 
151                 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
152         priv->is_dirty = TRUE;
153 }
154
155 static void
156 on_value_changed(GtkWidget* widget, GValue* value, ModestConnectionSpecificSmtpEditWindow *self)
157 {
158         ModestConnectionSpecificSmtpEditWindowPrivate *priv =
159                 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
160
161         priv->range_error_occured = FALSE;
162         on_change(widget, self);
163 }
164
165 gboolean
166 show_banner_handler (gpointer userdata)
167 {
168         ModestConnectionSpecificSmtpEditWindow *self = userdata;
169         ModestConnectionSpecificSmtpEditWindowPrivate *priv =
170                 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
171         gchar *msg;
172
173         msg = g_strdup_printf (dgettext("hildon-libs", "ckct_ib_set_a_value_within_range"), PORT_RANGE_MIN, PORT_RANGE_MAX);
174
175         hildon_banner_show_information (NULL, NULL, msg);
176         g_free (msg);
177
178         priv->range_error_banner_timeout = 0;
179         return FALSE;
180 }
181
182 static gboolean
183 on_range_error (GtkWidget *widget, HildonNumberEditorErrorType type, gpointer user_data)
184 {
185         ModestConnectionSpecificSmtpEditWindow *self = user_data;
186         ModestConnectionSpecificSmtpEditWindowPrivate *priv =
187                 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
188
189         /* We want to prevent the closure of the dialog when a range error occured. The problem is that
190          * the hildon number editor already resets the value to the default value, so we have to
191          * remember that such an error occured. */
192         priv->range_error_occured = TRUE;
193         if (priv->range_error_banner_timeout == 0)
194                 priv->range_error_banner_timeout = g_timeout_add (200, show_banner_handler, self);
195
196         /* Show error message by not returning TRUE */
197         return TRUE;
198 }
199
200 static void
201 on_response (GtkDialog *dialog, int response_id, gpointer user_data)
202 {
203         const gchar *hostname;
204         ModestConnectionSpecificSmtpEditWindow *self = user_data;
205         ModestConnectionSpecificSmtpEditWindowPrivate *priv =
206                 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
207
208         hostname = gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver));
209
210         if ((response_id != GTK_RESPONSE_OK) &&
211             (priv->range_error_banner_timeout > 0)) {
212                 g_source_remove (priv->range_error_banner_timeout);
213                 priv->range_error_banner_timeout = 0;
214         }
215
216         /* Don't close the dialog if a range error occured */
217         if(response_id == GTK_RESPONSE_OK && priv->range_error_occured)
218         {
219                 priv->range_error_occured = FALSE;
220                 g_signal_stop_emission_by_name (dialog, "response");
221                 gtk_widget_grab_focus (priv->entry_port);
222                 return;
223         }
224
225         /* Don't close the dialog if a range error occured */
226         if(response_id == GTK_RESPONSE_OK) {
227                 if (hostname && (hostname[0] != '\0') &&
228                     (!modest_text_utils_validate_domain_name (hostname))) { 
229                         g_signal_stop_emission_by_name (dialog, "response");
230                         hildon_banner_show_information (NULL, NULL, _("mcen_ib_invalid_servername"));
231                         gtk_widget_grab_focus (priv->entry_outgoingserver);
232                         gtk_editable_select_region (GTK_EDITABLE (priv->entry_outgoingserver), 0, -1);
233                         return;
234                 }
235         } else {
236                 /* Ask user if they want to discard changes */
237                 if (priv->is_dirty) {
238                         gint response;
239                         response = modest_platform_run_confirmation_dialog (GTK_WINDOW (user_data), 
240                                                                             _("imum_nc_wizard_confirm_lose_changes"));
241                         if (response != GTK_RESPONSE_OK)
242                                 g_signal_stop_emission_by_name (dialog, "response");
243                 }
244         }
245 }
246
247 static void on_set_focus_child (GtkContainer *container, GtkWidget *widget, gpointer user_data)
248 {
249         ModestConnectionSpecificSmtpEditWindow *self = user_data;
250         ModestConnectionSpecificSmtpEditWindowPrivate *priv =
251                 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
252
253         /* Another child gained focus. Since the number editor already reset a
254          * possible range error to the default value, we allow closure of the
255          * dialog */
256         priv->range_error_occured = FALSE;
257 }
258
259 static void
260 on_security_picker_changed (HildonPickerButton *widget, gpointer user_data)
261 {
262         ModestConnectionSpecificSmtpEditWindow *self = 
263                 MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (user_data);
264         ModestConnectionSpecificSmtpEditWindowPrivate *priv = 
265                 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
266         
267         on_change(GTK_WIDGET(widget), self);
268         
269         const gint port_number = 
270                 modest_serversecurity_picker_get_active_serversecurity_port (
271                         MODEST_SERVERSECURITY_PICKER (priv->outgoing_security_picker));
272
273         if(port_number != 0) {
274                 hildon_number_editor_set_value (
275                         HILDON_NUMBER_EDITOR (priv->entry_port), port_number);
276         }               
277 }
278
279 static void
280 modest_connection_specific_smtp_edit_window_init (ModestConnectionSpecificSmtpEditWindow *self)
281 {
282         ModestConnectionSpecificSmtpEditWindowPrivate *priv; 
283         GtkWidget *dialog_box;
284         GtkWidget *pannable, *vbox;
285
286         /* The title of this dialog is quite long, so make the window wide enough */
287         gtk_widget_set_size_request (GTK_WIDGET (self), 600, 320);
288
289         priv = CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
290         dialog_box = GTK_DIALOG(self)->vbox; /* gtk_vbox_new (FALSE, MODEST_MARGIN_HALF); */
291         gtk_box_set_spacing (GTK_BOX (dialog_box), MODEST_MARGIN_NONE);
292         gtk_container_set_border_width (GTK_CONTAINER (dialog_box), MODEST_MARGIN_HALF);
293
294         vbox = gtk_vbox_new (FALSE, 0);
295         
296         /* Create a size group to be used by all captions.
297          * Note that HildonCaption does not create a default size group if we do not specify one.
298          * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
299         GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
300          
301         /* The outgoing server widgets: */
302         if (!priv->entry_outgoingserver)
303                 priv->entry_outgoingserver = gtk_entry_new ();
304         /* Auto-capitalization is the default, so let's turn it off: */
305         hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
306         g_signal_connect(G_OBJECT(priv->entry_outgoingserver), "changed", G_CALLBACK(on_change), self);
307         
308         GtkWidget *captioned = 
309           modest_maemo_utils_create_captioned (sizegroup, 
310                                                _("mcen_li_emailsetup_smtp"), 
311                                                priv->entry_outgoingserver);
312         gtk_widget_show (priv->entry_outgoingserver);
313         gtk_box_pack_start (GTK_BOX (vbox), captioned, FALSE, FALSE, MODEST_MARGIN_HALF);
314         gtk_widget_show (captioned);
315         
316         /* The secure authentication widgets: */
317         if (!priv->outgoing_auth_picker) {
318                 priv->outgoing_auth_picker = 
319                         GTK_WIDGET (modest_secureauth_picker_new (MODEST_EDITABLE_SIZE,
320                                                                   MODEST_EDITABLE_ARRANGEMENT));
321         }
322         modest_maemo_utils_create_picker_layout (sizegroup, 
323                                                  _("mcen_li_emailsetup_secure_authentication"),
324                                                  priv->outgoing_auth_picker);
325         g_signal_connect (G_OBJECT (priv->outgoing_auth_picker), "value-changed", G_CALLBACK(on_change), self);
326         gtk_widget_show (priv->outgoing_auth_picker);
327         gtk_box_pack_start (GTK_BOX (vbox), priv->outgoing_auth_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
328         
329         /* The username widgets: */     
330         priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
331         /* Auto-capitalization is the default, so let's turn it off: */
332         hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
333         captioned = modest_maemo_utils_create_captioned (sizegroup, _("mail_fi_username"), 
334                                                          priv->entry_user_username);
335         g_signal_connect(G_OBJECT(priv->entry_user_username), "changed", G_CALLBACK(on_change), self);
336         gtk_widget_show (priv->entry_user_username);
337         gtk_box_pack_start (GTK_BOX (vbox), captioned, FALSE, FALSE, MODEST_MARGIN_HALF);
338         gtk_widget_show (captioned);
339         
340         /* Prevent the use of some characters in the username, 
341          * as required by our UI specification: */
342         modest_validating_entry_set_unallowed_characters_whitespace (
343                 MODEST_VALIDATING_ENTRY (priv->entry_user_username));
344         
345         /* Set max length as in the UI spec:
346          * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
347         gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
348         
349         /* The password widgets: */     
350         priv->entry_user_password = gtk_entry_new ();
351         /* Auto-capitalization is the default, so let's turn it off: */
352         hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password), 
353                 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
354         gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
355         /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
356         captioned = modest_maemo_utils_create_captioned (sizegroup, 
357                 _("mail_fi_password"), priv->entry_user_password);
358         g_signal_connect(G_OBJECT(priv->entry_user_password), "changed", G_CALLBACK(on_change), self);
359         gtk_widget_show (priv->entry_user_password);
360         gtk_box_pack_start (GTK_BOX (vbox), captioned, FALSE, FALSE, MODEST_MARGIN_HALF);
361         gtk_widget_show (captioned);
362         
363         /* The secure connection widgets: */    
364         if (!priv->outgoing_security_picker)
365                 priv->outgoing_security_picker = 
366                         GTK_WIDGET (modest_serversecurity_picker_new (MODEST_EDITABLE_SIZE,
367                                                                       MODEST_EDITABLE_ARRANGEMENT));
368         modest_serversecurity_picker_fill (
369                 MODEST_SERVERSECURITY_PICKER (priv->outgoing_security_picker), MODEST_PROTOCOLS_TRANSPORT_SMTP);
370         modest_serversecurity_picker_set_active_serversecurity (
371                 MODEST_SERVERSECURITY_PICKER (priv->outgoing_security_picker), MODEST_PROTOCOLS_CONNECTION_NONE);
372         modest_maemo_utils_create_picker_layout (sizegroup,  _("mcen_li_emailsetup_secure_connection"), priv->outgoing_security_picker);
373         gtk_widget_show (priv->outgoing_security_picker);
374         gtk_box_pack_start (GTK_BOX (vbox), priv->outgoing_security_picker, FALSE, FALSE, MODEST_MARGIN_HALF);
375         
376         /* The port number widgets: */
377         if (!priv->entry_port)
378                 priv->entry_port = GTK_WIDGET (hildon_number_editor_new (PORT_RANGE_MIN, PORT_RANGE_MAX));
379         captioned = modest_maemo_utils_create_captioned (sizegroup, 
380                 _("mcen_fi_emailsetup_port"), priv->entry_port);
381         gtk_widget_add_events(GTK_WIDGET(priv->entry_port), GDK_FOCUS_CHANGE_MASK);
382         g_signal_connect(G_OBJECT(priv->entry_port), "range-error", G_CALLBACK(on_range_error), self);
383         g_signal_connect(G_OBJECT(priv->entry_port), "notify::value", G_CALLBACK(on_value_changed), self);
384         gtk_widget_show (priv->entry_port);
385         gtk_box_pack_start (GTK_BOX (vbox), captioned, FALSE, FALSE, MODEST_MARGIN_HALF);
386         gtk_widget_show (captioned);
387         
388         /* Show a default port number when the security method changes, as per the UI spec: */
389         g_signal_connect (G_OBJECT (priv->outgoing_security_picker), "value-changed", (GCallback)on_security_picker_changed, self);
390         on_security_picker_changed (HILDON_PICKER_BUTTON (priv->outgoing_security_picker), self);
391         
392         /* Add the buttons: */
393         gtk_dialog_add_button (GTK_DIALOG (self), _("mcen_bd_dialog_ok"), GTK_RESPONSE_OK);
394         
395         priv->is_dirty = FALSE;
396         priv->range_error_occured = FALSE;
397         g_signal_connect(G_OBJECT(self), "response", G_CALLBACK(on_response), self);
398         g_signal_connect(G_OBJECT(vbox), "set-focus-child", G_CALLBACK(on_set_focus_child), self);
399
400         priv->range_error_banner_timeout = 0;
401         priv->account_name = NULL;
402
403         pannable = hildon_pannable_area_new ();
404         g_object_set (G_OBJECT (pannable), "initial-hint", TRUE, NULL);
405         hildon_pannable_area_add_with_viewport (HILDON_PANNABLE_AREA (pannable), vbox);
406         gtk_box_pack_start (GTK_BOX (dialog_box), pannable, TRUE, TRUE, 0);
407         
408         gtk_widget_show_all (dialog_box);
409         gtk_window_set_default_size (GTK_WINDOW (self), -1, 220);
410         
411         
412         /* When this window is shown, hibernation should not be possible, 
413          * because there is no sensible way to save the state: */
414         modest_window_mgr_prevent_hibernation_while_window_is_shown (
415                 modest_runtime_get_window_mgr (), GTK_WINDOW (self)); 
416         
417         hildon_help_dialog_help_enable (GTK_DIALOG(self),
418                                         "applications_email_connectionspecificsmtpconf",
419                                         modest_maemo_utils_get_osso_context());
420 }
421
422 ModestConnectionSpecificSmtpEditWindow*
423 modest_connection_specific_smtp_edit_window_new (void)
424 {
425         return g_object_new (MODEST_TYPE_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW, NULL);
426 }
427
428 void
429 modest_connection_specific_smtp_edit_window_set_connection (
430         ModestConnectionSpecificSmtpEditWindow *window, const gchar* iap_id, const gchar* iap_name,
431         ModestServerAccountSettings *server_settings)
432 {
433         ModestConnectionSpecificSmtpEditWindowPrivate *priv = 
434                 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (window);
435
436         /* This causes a warning because of the %s in the translation, but not in the original string: */
437         gchar* title = g_strdup_printf (_("mcen_ti_connection_connection_name"), iap_name);
438         gtk_window_set_title (GTK_WINDOW (window), title);
439         g_free (title);
440
441         if (server_settings) 
442         {
443                 /* Setting known values */
444                 if (priv->account_name)
445                         g_free (priv->account_name);
446                 priv->account_name = g_strdup (modest_server_account_settings_get_account_name (server_settings));
447                 gtk_entry_set_text (GTK_ENTRY (priv->entry_outgoingserver), 
448                                     modest_server_account_settings_get_hostname (server_settings));
449                 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_username),
450                                     modest_server_account_settings_get_username (server_settings));     
451                 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_password), 
452                                     modest_server_account_settings_get_password (server_settings));
453         
454                 modest_serversecurity_picker_set_active_serversecurity (
455                 MODEST_SERVERSECURITY_PICKER (priv->outgoing_security_picker), 
456                 modest_server_account_settings_get_security_protocol (server_settings));
457         
458                 modest_secureauth_picker_set_active_secureauth (
459                 MODEST_SECUREAUTH_PICKER (priv->outgoing_auth_picker), 
460                 modest_server_account_settings_get_auth_protocol (server_settings));
461                 
462                 /* port: */
463                 hildon_number_editor_set_value (
464                         HILDON_NUMBER_EDITOR (priv->entry_port), 
465                         modest_server_account_settings_get_port (server_settings));
466                 
467                 
468                 /* This will cause changed signals so we set dirty back to FALSE */
469                 priv->is_dirty = FALSE;
470                 if (priv->range_error_banner_timeout > 0) {
471                         g_source_remove (priv->range_error_banner_timeout);
472                         priv->range_error_banner_timeout = 0;
473                 }
474         
475         }
476 }
477
478 ModestServerAccountSettings*
479 modest_connection_specific_smtp_edit_window_get_settings (ModestConnectionSpecificSmtpEditWindow *window)
480 {
481         ModestConnectionSpecificSmtpEditWindowPrivate *priv = NULL;
482         ModestServerAccountSettings *server_settings = NULL;
483         const gchar *outgoing_server = NULL;
484
485         priv =  CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (window);
486         outgoing_server = gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver));
487
488         /* If the outgoing server is NULL, we are removing the connection specific
489          * settings */
490         if ((outgoing_server == NULL) || (outgoing_server[0] == '\0')) {
491                 return NULL;
492         }
493         
494         server_settings = modest_server_account_settings_new ();
495         
496         modest_server_account_settings_set_hostname (server_settings, 
497                                                      gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver)));
498         modest_server_account_settings_set_protocol (server_settings,
499                                                      MODEST_PROTOCOLS_TRANSPORT_SMTP);
500         modest_server_account_settings_set_username (server_settings,
501                                                      gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username)));
502         modest_server_account_settings_set_password (server_settings,
503                                                      gtk_entry_get_text (GTK_ENTRY (priv->entry_user_password)));
504         
505         modest_server_account_settings_set_security_protocol (server_settings, 
506                                                      modest_serversecurity_picker_get_active_serversecurity (
507                                                      MODEST_SERVERSECURITY_PICKER (priv->outgoing_security_picker)));
508         modest_server_account_settings_set_auth_protocol (server_settings,
509                                                           modest_secureauth_picker_get_active_secureauth (
510                                                           MODEST_SECUREAUTH_PICKER (priv->outgoing_auth_picker)));
511         modest_server_account_settings_set_account_name (server_settings,
512                                                          priv->account_name);
513         
514         /* port: */
515         modest_server_account_settings_set_port (server_settings,
516                                                  hildon_number_editor_get_value (HILDON_NUMBER_EDITOR (priv->entry_port)));
517                         
518         return server_settings;
519 }
520
521 gboolean 
522 modest_connection_specific_smtp_edit_window_is_dirty(ModestConnectionSpecificSmtpEditWindow *window)
523 {
524         ModestConnectionSpecificSmtpEditWindowPrivate *priv = 
525                 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (window);
526         
527         return priv->is_dirty;
528 }