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