1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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"
35 #include "widgets/modest-validating-entry.h"
36 #include <modest-scrollable.h>
37 #include <hildon/hildon-entry.h>
38 #include <modest-ui-constants.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 #include <modest-toolkit-factory.h>
47 #include <glib/gi18n.h>
49 #define PORT_RANGE_MIN 1
50 #define PORT_RANGE_MAX 65535
52 G_DEFINE_TYPE (ModestConnectionSpecificSmtpEditWindow, modest_connection_specific_smtp_edit_window, GTK_TYPE_DIALOG);
54 #define CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE(o) \
55 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW, ModestConnectionSpecificSmtpEditWindowPrivate))
57 static void on_response (GtkDialog *dialog,
61 typedef struct _ModestConnectionSpecificSmtpEditWindowPrivate ModestConnectionSpecificSmtpEditWindowPrivate;
63 struct _ModestConnectionSpecificSmtpEditWindowPrivate
65 GtkWidget *entry_outgoingserver;
66 GtkWidget *outgoing_auth_selector;
67 GtkWidget *entry_user_username;
68 GtkWidget *entry_user_password;
69 GtkWidget *outgoing_security_selector;
70 GtkWidget *entry_port;
73 GtkWidget *button_cancel;
78 gboolean range_error_occured;
82 modest_connection_specific_smtp_edit_window_get_property (GObject *object, guint property_id,
83 GValue *value, GParamSpec *pspec)
85 switch (property_id) {
87 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
92 modest_connection_specific_smtp_edit_window_set_property (GObject *object, guint property_id,
93 const GValue *value, GParamSpec *pspec)
95 switch (property_id) {
97 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
102 modest_connection_specific_smtp_edit_window_dispose (GObject *object)
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);
111 modest_connection_specific_smtp_edit_window_finalize (GObject *object)
113 ModestConnectionSpecificSmtpEditWindow *self = (ModestConnectionSpecificSmtpEditWindow *) object;
114 ModestConnectionSpecificSmtpEditWindowPrivate *priv =
115 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
117 if (priv->account_name) {
118 g_free (priv->account_name);
119 priv->account_name = NULL;
121 G_OBJECT_CLASS (modest_connection_specific_smtp_edit_window_parent_class)->finalize (object);
125 modest_connection_specific_smtp_edit_window_class_init (ModestConnectionSpecificSmtpEditWindowClass *klass)
127 GObjectClass *object_class = G_OBJECT_CLASS (klass);
129 g_type_class_add_private (klass, sizeof (ModestConnectionSpecificSmtpEditWindowPrivate));
131 object_class->get_property = modest_connection_specific_smtp_edit_window_get_property;
132 object_class->set_property = modest_connection_specific_smtp_edit_window_set_property;
133 object_class->dispose = modest_connection_specific_smtp_edit_window_dispose;
134 object_class->finalize = modest_connection_specific_smtp_edit_window_finalize;
139 MODEL_COL_SERVER_NAME = 1,
144 on_change(GtkWidget* widget, ModestConnectionSpecificSmtpEditWindow *self)
146 ModestConnectionSpecificSmtpEditWindowPrivate *priv =
147 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
148 priv->is_dirty = TRUE;
152 on_mandatory_entry_changed (GtkWidget* widget, ModestConnectionSpecificSmtpEditWindow *self)
155 gboolean sensitive = TRUE;
156 ModestConnectionSpecificSmtpEditWindowPrivate *priv;
157 ModestProtocolType auth_proto;
159 priv = CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
161 /* Check all mandatory entries */
162 on_change (widget, self);
164 auth_proto = modest_secureauth_selector_get_active_secureauth (priv->outgoing_auth_selector);
165 if (modest_protocol_registry_protocol_type_is_secure (modest_runtime_get_protocol_registry (),
167 text = modest_entry_get_text (priv->entry_user_username);
168 if (!text || (strlen(text) == 0))
172 text = modest_entry_get_text (priv->entry_outgoingserver);
173 if (!text || (strlen(text) == 0))
176 gtk_dialog_set_response_sensitive (GTK_DIALOG (self), GTK_RESPONSE_OK, sensitive);
181 on_value_changed(GtkWidget* widget, GValue* value, ModestConnectionSpecificSmtpEditWindow *self)
183 ModestConnectionSpecificSmtpEditWindowPrivate *priv =
184 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
186 priv->range_error_occured = FALSE;
187 on_change(widget, self);
191 on_range_error (GtkWidget *widget, ModestNumberEditorErrorType type, gpointer user_data)
194 ModestConnectionSpecificSmtpEditWindow *self = user_data;
195 ModestConnectionSpecificSmtpEditWindowPrivate *priv =
196 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
198 /* We want to prevent the closure of the dialog when a range error occured. The problem is that
199 * the hildon number editor already resets the value to the default value, so we have to
200 * remember that such an error occured. */
201 priv->range_error_occured = TRUE;
203 if (type == MODEST_NUMBER_EDITOR_ERROR_MAXIMUM_VALUE_EXCEED) {
204 msg = g_strdup_printf (dgettext ("hildon-libs", "ckct_ib_maximum_value"), 65535);
205 } else if (type == MODEST_NUMBER_EDITOR_ERROR_MINIMUM_VALUE_EXCEED) {
206 msg = g_strdup_printf (dgettext ("hildon-libs", "ckct_ib_minimum_value"), 1);
208 msg = g_strdup_printf (_HL("ckct_ib_set_a_value_within_range"), PORT_RANGE_MIN, PORT_RANGE_MAX);
210 modest_platform_information_banner (widget, NULL, msg);
213 /* Show error message by not returning TRUE */
218 on_delete_event (GtkWidget *widget,
222 ModestConnectionSpecificSmtpEditWindow *self = user_data;
223 ModestConnectionSpecificSmtpEditWindowPrivate *priv =
224 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
226 /* If it's dirty, them the response method already asked the
227 user, because it's always executed before (see GtkDialog
228 code). If it's not then simply close */
229 return priv->is_dirty;
233 on_response (GtkDialog *dialog, int response_id, gpointer user_data)
235 const gchar *hostname;
236 ModestConnectionSpecificSmtpEditWindow *self = user_data;
237 ModestConnectionSpecificSmtpEditWindowPrivate *priv =
238 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
240 hostname = modest_entry_get_text (priv->entry_outgoingserver);
242 /* Don't close the dialog if a range error occured */
243 if(response_id == GTK_RESPONSE_OK && priv->range_error_occured)
245 priv->range_error_occured = FALSE;
246 g_signal_stop_emission_by_name (dialog, "response");
247 gtk_widget_grab_focus (priv->entry_port);
251 /* Don't close the dialog if a range error occured */
252 if (response_id == GTK_RESPONSE_OK) {
253 if (hostname && (hostname[0] != '\0') &&
254 (!modest_text_utils_validate_domain_name (hostname))) {
255 g_signal_stop_emission_by_name (dialog, "response");
256 modest_platform_system_banner (NULL, NULL, _("mcen_ib_invalid_servername"));
257 gtk_widget_grab_focus (priv->entry_outgoingserver);
258 gtk_editable_select_region (GTK_EDITABLE (priv->entry_outgoingserver), 0, -1);
262 /* Ask user if they want to discard changes */
263 if (priv->is_dirty) {
265 response = modest_platform_run_confirmation_dialog (GTK_WINDOW (user_data),
266 _("imum_nc_wizard_confirm_lose_changes"));
268 if (response != GTK_RESPONSE_OK)
269 g_signal_stop_emission_by_name (dialog, "response");
275 on_set_focus_child (GtkContainer *container, GtkWidget *widget, gpointer user_data)
277 ModestConnectionSpecificSmtpEditWindow *self = user_data;
278 ModestConnectionSpecificSmtpEditWindowPrivate *priv =
279 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
281 /* Another child gained focus. Since the number editor already reset a
282 * possible range error to the default value, we allow closure of the
284 priv->range_error_occured = FALSE;
288 security_selector_set_port (ModestConnectionSpecificSmtpEditWindowPrivate *priv)
290 const gint port_number =
291 modest_serversecurity_selector_get_active_serversecurity_port (priv->outgoing_security_selector);
293 if(port_number != 0) {
294 modest_number_entry_set_value (
295 priv->entry_port, port_number);
300 on_security_selector_changed (GtkWidget *widget, gpointer user_data)
302 ModestConnectionSpecificSmtpEditWindow *self =
303 MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (user_data);
304 ModestConnectionSpecificSmtpEditWindowPrivate *priv =
305 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
307 on_change(GTK_WIDGET(widget), self);
309 /* Enable/disable username and password fields */
310 security_selector_set_port (priv);
314 auth_selector_set_sensitive (ModestConnectionSpecificSmtpEditWindowPrivate *priv)
316 ModestProtocolType auth_proto;
319 modest_secureauth_selector_get_active_secureauth (priv->outgoing_auth_selector);
321 if (auth_proto == modest_protocol_registry_get_none_auth_type_id ()) {
322 gtk_widget_set_sensitive (priv->entry_user_username, FALSE);
323 gtk_widget_set_sensitive (priv->entry_user_password, FALSE);
325 gtk_widget_set_sensitive (priv->entry_user_username, TRUE);
326 gtk_widget_set_sensitive (priv->entry_user_password, TRUE);
332 on_auth_selector_changed (GtkWidget *widget, gpointer user_data)
334 ModestConnectionSpecificSmtpEditWindow *self;
335 ModestConnectionSpecificSmtpEditWindowPrivate *priv;
337 self = MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (user_data);
338 priv = CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
340 on_change (GTK_WIDGET(widget), self);
342 /* Enable/disable username and password fields */
343 auth_selector_set_sensitive (priv);
345 /* Check missing mandatory data */
346 on_mandatory_entry_changed (priv->entry_user_username, self);
350 modest_connection_specific_smtp_edit_window_init (ModestConnectionSpecificSmtpEditWindow *self)
352 ModestConnectionSpecificSmtpEditWindowPrivate *priv;
353 GtkWidget *dialog_box;
354 GtkWidget *scrollable, *vbox, *align;
357 /* The title of this dialog is quite long, so make the window wide enough */
358 gtk_widget_set_size_request (GTK_WIDGET (self), 600, 320);
360 priv = CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
361 dialog_box = GTK_DIALOG(self)->vbox; /* gtk_vbox_new (FALSE, MODEST_MARGIN_HALF); */
362 gtk_box_set_spacing (GTK_BOX (dialog_box), MODEST_MARGIN_NONE);
364 vbox = gtk_vbox_new (FALSE, 0);
365 align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
366 gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
368 /* Create a size group to be used by all captions.
369 * Note that HildonCaption does not create a default size group if we do not specify one.
370 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
371 GtkSizeGroup *title_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
372 GtkSizeGroup *value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
374 /* The outgoing server widgets: */
375 if (!priv->entry_outgoingserver)
376 priv->entry_outgoingserver = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
377 /* Auto-capitalization is the default, so let's turn it off: */
378 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
379 g_signal_connect(G_OBJECT(priv->entry_outgoingserver), "changed", G_CALLBACK(on_mandatory_entry_changed), self);
381 server_label = g_strconcat (_("mcen_li_emailsetup_smtp"), "\n<small>(SMTP)</small>", NULL);
383 GtkWidget *captioned =
384 modest_maemo_utils_create_captioned (title_sizegroup, value_sizegroup,
386 priv->entry_outgoingserver);
387 g_free (server_label);
388 gtk_widget_show (priv->entry_outgoingserver);
389 gtk_box_pack_start (GTK_BOX (vbox), captioned, FALSE, FALSE, 0);
390 gtk_widget_show (captioned);
392 /* The secure authentication widgets: */
393 if (!priv->outgoing_auth_selector) {
394 priv->outgoing_auth_selector =
395 modest_toolkit_factory_create_secureauth_selector (modest_runtime_get_toolkit_factory ());
397 if (GTK_IS_COMBO_BOX (priv->outgoing_auth_selector)) {
398 GtkWidget *captioned;
399 captioned = modest_maemo_utils_create_captioned (title_sizegroup, value_sizegroup,
400 _("mcen_li_emailsetup_secure_authentication"), FALSE,
401 priv->outgoing_auth_selector);
402 gtk_widget_show (captioned);
403 gtk_box_pack_start (GTK_BOX (vbox), captioned, FALSE, FALSE, 0);
405 modest_maemo_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
406 _("mcen_li_emailsetup_secure_authentication"),
407 priv->outgoing_auth_selector);
408 gtk_box_pack_start (GTK_BOX (vbox), priv->outgoing_auth_selector, FALSE, FALSE, 0);
410 gtk_widget_show (priv->outgoing_auth_selector);
412 /* The username widgets: */
413 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
414 /* Auto-capitalization is the default, so let's turn it off: */
415 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
416 captioned = modest_maemo_utils_create_captioned (title_sizegroup, value_sizegroup,
417 _("mail_fi_username"), FALSE,
418 priv->entry_user_username);
419 g_signal_connect(G_OBJECT(priv->entry_user_username), "changed", G_CALLBACK(on_mandatory_entry_changed), self);
420 gtk_widget_show (priv->entry_user_username);
421 gtk_box_pack_start (GTK_BOX (vbox), captioned, FALSE, FALSE, 0);
422 gtk_widget_show (captioned);
424 /* Prevent the use of some characters in the username,
425 * as required by our UI specification: */
426 modest_validating_entry_set_unallowed_characters_whitespace (
427 MODEST_VALIDATING_ENTRY (priv->entry_user_username));
429 /* Set max length as in the UI spec:
430 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
431 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
433 /* The password widgets: */
434 priv->entry_user_password = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
435 /* Auto-capitalization is the default, so let's turn it off: */
436 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password),
437 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
438 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
439 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
440 captioned = modest_maemo_utils_create_captioned (title_sizegroup, value_sizegroup,
441 _("mail_fi_password"), FALSE, priv->entry_user_password);
442 g_signal_connect(G_OBJECT(priv->entry_user_password), "changed", G_CALLBACK(on_change), self);
443 gtk_widget_show (priv->entry_user_password);
444 gtk_box_pack_start (GTK_BOX (vbox), captioned, FALSE, FALSE, 0);
445 gtk_widget_show (captioned);
447 /* The secure connection widgets: */
448 if (!priv->outgoing_security_selector)
449 priv->outgoing_security_selector =
450 modest_toolkit_factory_create_serversecurity_selector (modest_runtime_get_toolkit_factory ());
451 modest_serversecurity_selector_fill (priv->outgoing_security_selector, MODEST_PROTOCOLS_TRANSPORT_SMTP);
452 modest_serversecurity_selector_set_active_serversecurity (priv->outgoing_security_selector, MODEST_PROTOCOLS_CONNECTION_NONE);
453 if (GTK_IS_COMBO_BOX (priv->outgoing_security_selector)) {
454 GtkWidget *captioned;
456 captioned = modest_maemo_utils_create_captioned (title_sizegroup, value_sizegroup,
457 _("mcen_li_emailsetup_secure_connection"), FALSE,
458 priv->outgoing_security_selector);
459 gtk_box_pack_start (GTK_BOX (vbox), captioned, FALSE, FALSE, MODEST_MARGIN_HALF);
460 gtk_widget_show (captioned);
462 modest_maemo_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
463 _("mcen_li_emailsetup_secure_connection"),
464 priv->outgoing_security_selector);
465 gtk_box_pack_start (GTK_BOX (vbox), priv->outgoing_security_selector, FALSE, FALSE, 0);
467 gtk_widget_show (priv->outgoing_security_selector);
469 /* The port number widgets: */
470 if (!priv->entry_port)
471 priv->entry_port = modest_toolkit_factory_create_number_entry (modest_runtime_get_toolkit_factory (),
472 PORT_RANGE_MIN, PORT_RANGE_MAX);
473 captioned = modest_maemo_utils_create_captioned (title_sizegroup, value_sizegroup,
474 _("mcen_fi_emailsetup_port"), FALSE, priv->entry_port);
475 gtk_widget_add_events(GTK_WIDGET(priv->entry_port), GDK_FOCUS_CHANGE_MASK);
476 gtk_widget_show (priv->entry_port);
477 gtk_box_pack_start (GTK_BOX (vbox), captioned, FALSE, FALSE, 0);
478 gtk_widget_show (captioned);
480 /* Add the button. Disabled by default */
481 gtk_dialog_add_button (GTK_DIALOG (self), _HL("wdgt_bd_save"), GTK_RESPONSE_OK);
482 gtk_dialog_set_response_sensitive (GTK_DIALOG (self), GTK_RESPONSE_OK, FALSE);
484 priv->is_dirty = FALSE;
485 priv->range_error_occured = FALSE;
486 g_signal_connect(G_OBJECT(self), "response", G_CALLBACK(on_response), self);
487 g_signal_connect(G_OBJECT(self), "delete-event", G_CALLBACK(on_delete_event), self);
488 g_signal_connect(G_OBJECT(vbox), "set-focus-child", G_CALLBACK(on_set_focus_child), self);
490 priv->account_name = NULL;
492 scrollable = modest_toolkit_factory_create_scrollable (modest_runtime_get_toolkit_factory ());
493 gtk_container_add (GTK_CONTAINER (align), vbox);
494 modest_scrollable_add_with_viewport (MODEST_SCROLLABLE (scrollable), align);
495 gtk_box_pack_start (GTK_BOX (dialog_box), scrollable, TRUE, TRUE, 0);
497 gtk_widget_show_all (dialog_box);
498 gtk_window_set_default_size (GTK_WINDOW (self), -1, MODEST_DIALOG_WINDOW_MAX_HEIGHT);
500 g_object_unref (title_sizegroup);
501 g_object_unref (value_sizegroup);
503 /* When this window is shown, hibernation should not be possible,
504 * because there is no sensible way to save the state: */
505 modest_window_mgr_prevent_hibernation_while_window_is_shown (
506 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
508 /* Refresh view with current settings */
509 auth_selector_set_sensitive (priv);
510 security_selector_set_port (priv);
512 /* Connect signals to track changes */
513 if (GTK_IS_COMBO_BOX (priv->outgoing_security_selector)) {
514 g_signal_connect (G_OBJECT (priv->outgoing_security_selector),
516 (GCallback) on_security_selector_changed,
519 g_signal_connect (G_OBJECT (priv->outgoing_security_selector),
521 (GCallback) on_security_selector_changed,
524 if (GTK_IS_COMBO_BOX (priv->outgoing_auth_selector)) {
525 g_signal_connect (G_OBJECT (priv->outgoing_auth_selector),
527 (GCallback) on_auth_selector_changed,
530 g_signal_connect (G_OBJECT (priv->outgoing_auth_selector),
532 (GCallback) on_auth_selector_changed,
535 g_signal_connect(G_OBJECT(priv->entry_port),
537 G_CALLBACK(on_range_error),
539 g_signal_connect(G_OBJECT(priv->entry_port),
541 G_CALLBACK(on_value_changed),
546 ModestConnectionSpecificSmtpEditWindow*
547 modest_connection_specific_smtp_edit_window_new (void)
549 return g_object_new (MODEST_TYPE_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW, NULL);
553 modest_connection_specific_smtp_edit_window_set_connection (
554 ModestConnectionSpecificSmtpEditWindow *window, const gchar* iap_id, const gchar* iap_name,
555 ModestServerAccountSettings *server_settings)
557 ModestConnectionSpecificSmtpEditWindowPrivate *priv =
558 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (window);
560 /* This causes a warning because of the %s in the translation, but not in the original string: */
561 gchar* title = g_strdup_printf (_("mcen_ti_connection_connection_name"), iap_name);
562 gtk_window_set_title (GTK_WINDOW (window), title);
567 /* Setting known values */
568 if (priv->account_name)
569 g_free (priv->account_name);
570 priv->account_name = g_strdup (modest_server_account_settings_get_account_name (server_settings));
571 modest_entry_set_text (priv->entry_outgoingserver,
572 modest_server_account_settings_get_hostname (server_settings));
573 modest_entry_set_text (priv->entry_user_username,
574 modest_server_account_settings_get_username (server_settings));
575 modest_entry_set_text (priv->entry_user_password,
576 modest_server_account_settings_get_password (server_settings));
578 modest_serversecurity_selector_set_active_serversecurity
579 (priv->outgoing_security_selector,
580 modest_server_account_settings_get_security_protocol (server_settings));
582 modest_secureauth_selector_set_active_secureauth (priv->outgoing_auth_selector,
583 modest_server_account_settings_get_auth_protocol (server_settings));
586 modest_number_entry_set_value (
588 modest_server_account_settings_get_port (server_settings));
591 /* This will cause changed signals so we set dirty back to FALSE */
592 priv->is_dirty = FALSE;
596 ModestServerAccountSettings*
597 modest_connection_specific_smtp_edit_window_get_settings (ModestConnectionSpecificSmtpEditWindow *window)
599 ModestConnectionSpecificSmtpEditWindowPrivate *priv = NULL;
600 ModestServerAccountSettings *server_settings = NULL;
601 const gchar *outgoing_server = NULL;
603 priv = CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (window);
604 outgoing_server = modest_entry_get_text (priv->entry_outgoingserver);
606 /* If the outgoing server is NULL, we are removing the connection specific
608 if ((outgoing_server == NULL) || (outgoing_server[0] == '\0')) {
612 server_settings = modest_server_account_settings_new ();
614 modest_server_account_settings_set_hostname (server_settings,
615 modest_entry_get_text (priv->entry_outgoingserver));
616 modest_server_account_settings_set_protocol (server_settings,
617 MODEST_PROTOCOLS_TRANSPORT_SMTP);
618 modest_server_account_settings_set_username (server_settings,
619 modest_entry_get_text (priv->entry_user_username));
620 modest_server_account_settings_set_password (server_settings,
621 modest_entry_get_text (priv->entry_user_password));
623 modest_server_account_settings_set_security_protocol (server_settings,
624 modest_serversecurity_selector_get_active_serversecurity (
625 priv->outgoing_security_selector));
626 modest_server_account_settings_set_auth_protocol
628 modest_secureauth_selector_get_active_secureauth (priv->outgoing_auth_selector));
629 modest_server_account_settings_set_account_name (server_settings,
633 modest_server_account_settings_set_port (server_settings,
634 modest_number_entry_get_value (priv->entry_port));
636 return server_settings;
640 modest_connection_specific_smtp_edit_window_is_dirty(ModestConnectionSpecificSmtpEditWindow *window)
642 ModestConnectionSpecificSmtpEditWindowPrivate *priv =
643 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (window);
645 return priv->is_dirty;