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