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