1 /* connection-specific-smtp-window.c */
3 #include "modest-connection-specific-smtp-edit-window.h"
4 #include "widgets/modest-ui-constants.h"
5 #include "modest-hildon-includes.h"
6 #include "modest-runtime.h"
8 #include "widgets/modest-serversecurity-combo-box.h"
9 #include "widgets/modest-secureauth-combo-box.h"
10 #include "widgets/modest-validating-entry.h"
11 #include <modest-account-mgr-helpers.h>
12 #include <gtk/gtkbutton.h>
13 #include <gtk/gtkhbox.h>
14 #include <gtk/gtkvbox.h>
15 #include <gtk/gtkstock.h>
17 #include <glib/gi18n.h>
19 G_DEFINE_TYPE (ModestConnectionSpecificSmtpEditWindow, modest_connection_specific_smtp_edit_window, GTK_TYPE_DIALOG);
21 #define CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE(o) \
22 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW, ModestConnectionSpecificSmtpEditWindowPrivate))
24 typedef struct _ModestConnectionSpecificSmtpEditWindowPrivate ModestConnectionSpecificSmtpEditWindowPrivate;
26 struct _ModestConnectionSpecificSmtpEditWindowPrivate
28 GtkWidget *entry_outgoingserver;
29 GtkWidget *combo_outgoing_auth;
30 GtkWidget *entry_user_username;
31 GtkWidget *entry_user_password;
32 GtkWidget *combo_outgoing_security;
33 GtkWidget *entry_port;
36 GtkWidget *button_cancel;
40 modest_connection_specific_smtp_edit_window_get_property (GObject *object, guint property_id,
41 GValue *value, GParamSpec *pspec)
43 switch (property_id) {
45 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
50 modest_connection_specific_smtp_edit_window_set_property (GObject *object, guint property_id,
51 const GValue *value, GParamSpec *pspec)
53 switch (property_id) {
55 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
60 modest_connection_specific_smtp_edit_window_dispose (GObject *object)
62 if (G_OBJECT_CLASS (modest_connection_specific_smtp_edit_window_parent_class)->dispose)
63 G_OBJECT_CLASS (modest_connection_specific_smtp_edit_window_parent_class)->dispose (object);
67 modest_connection_specific_smtp_edit_window_finalize (GObject *object)
69 G_OBJECT_CLASS (modest_connection_specific_smtp_edit_window_parent_class)->finalize (object);
73 modest_connection_specific_smtp_edit_window_class_init (ModestConnectionSpecificSmtpEditWindowClass *klass)
75 GObjectClass *object_class = G_OBJECT_CLASS (klass);
77 g_type_class_add_private (klass, sizeof (ModestConnectionSpecificSmtpEditWindowPrivate));
79 object_class->get_property = modest_connection_specific_smtp_edit_window_get_property;
80 object_class->set_property = modest_connection_specific_smtp_edit_window_set_property;
81 object_class->dispose = modest_connection_specific_smtp_edit_window_dispose;
82 object_class->finalize = modest_connection_specific_smtp_edit_window_finalize;
87 MODEL_COL_SERVER_NAME = 1,
92 on_combo_security_changed (GtkComboBox *widget, gpointer user_data)
94 ModestConnectionSpecificSmtpEditWindow *self =
95 MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (user_data);
96 ModestConnectionSpecificSmtpEditWindowPrivate *priv =
97 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
99 const gint port_number =
100 modest_serversecurity_combo_box_get_active_serversecurity_port (
101 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security));
103 if(port_number != 0) {
104 hildon_number_editor_set_value (
105 HILDON_NUMBER_EDITOR (priv->entry_port), port_number);
110 modest_connection_specific_smtp_edit_window_init (ModestConnectionSpecificSmtpEditWindow *self)
112 ModestConnectionSpecificSmtpEditWindowPrivate *priv =
113 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
115 GtkWidget *box = GTK_DIALOG(self)->vbox; /* gtk_vbox_new (FALSE, MODEST_MARGIN_HALF); */
116 gtk_box_set_spacing (GTK_BOX (box), MODEST_MARGIN_NONE);
117 gtk_container_set_border_width (GTK_CONTAINER (box), MODEST_MARGIN_HALF);
119 /* Create a size group to be used by all captions.
120 * Note that HildonCaption does not create a default size group if we do not specify one.
121 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
122 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
124 /* The outgoing server widgets: */
125 if (!priv->entry_outgoingserver)
126 priv->entry_outgoingserver = gtk_entry_new ();
127 /* Auto-capitalization is the default, so let's turn it off: */
128 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
129 GtkWidget *caption = hildon_caption_new (sizegroup,
130 _("mcen_li_emailsetup_smtp"), priv->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
131 gtk_widget_show (priv->entry_outgoingserver);
132 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
133 gtk_widget_show (caption);
135 /* Show a default port number when the security method changes, as per the UI spec: */
136 g_signal_connect (G_OBJECT (priv->combo_outgoing_security), "changed", (GCallback)on_combo_security_changed, self);
139 /* The secure authentication widgets: */
140 if (!priv->combo_outgoing_auth)
141 priv->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
142 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
143 priv->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
144 gtk_widget_show (priv->combo_outgoing_auth);
145 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
146 gtk_widget_show (caption);
148 /* The username widgets: */
149 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
150 /* Auto-capitalization is the default, so let's turn it off: */
151 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
152 caption = hildon_caption_new (sizegroup, _("mail_fi_username"),
153 priv->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
154 gtk_widget_show (priv->entry_user_username);
155 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
156 gtk_widget_show (caption);
158 /* Prevent the use of some characters in the username,
159 * as required by our UI specification: */
160 modest_validating_entry_set_unallowed_characters_whitespace (
161 MODEST_VALIDATING_ENTRY (priv->entry_user_username));
163 /* Set max length as in the UI spec:
164 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
165 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
167 /* The password widgets: */
168 priv->entry_user_password = gtk_entry_new ();
169 /* Auto-capitalization is the default, so let's turn it off: */
170 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password), HILDON_GTK_INPUT_MODE_FULL);
171 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
172 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
173 caption = hildon_caption_new (sizegroup,
174 _("mail_fi_password"), priv->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
175 gtk_widget_show (priv->entry_user_password);
176 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
177 gtk_widget_show (caption);
179 /* The secure connection widgets: */
180 if (!priv->combo_outgoing_security)
181 priv->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
182 modest_serversecurity_combo_box_fill (
183 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
184 modest_serversecurity_combo_box_set_active_serversecurity (
185 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), MODEST_PROTOCOL_SECURITY_NONE);
186 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
187 priv->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
188 gtk_widget_show (priv->combo_outgoing_security);
189 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
190 gtk_widget_show (caption);
192 /* The port number widgets: */
193 if (!priv->entry_port)
194 priv->entry_port = GTK_WIDGET (hildon_number_editor_new (0, 65535));
195 caption = hildon_caption_new (sizegroup,
196 _("mcen_li_emailsetup_smtp"), priv->entry_port, NULL, HILDON_CAPTION_OPTIONAL);
197 gtk_widget_show (priv->entry_port);
198 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
199 gtk_widget_show (caption);
201 /* Add the buttons: */
202 gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_OK, GTK_RESPONSE_OK);
203 gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
206 gtk_widget_show (box);
209 /* When this window is shown, hibernation should not be possible,
210 * because there is no sensible way to save the state: */
211 modest_window_mgr_prevent_hibernation_while_window_is_shown (
212 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
215 ModestConnectionSpecificSmtpEditWindow*
216 modest_connection_specific_smtp_edit_window_new (void)
218 return g_object_new (MODEST_TYPE_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW, NULL);
222 modest_connection_specific_smtp_edit_window_set_connection (
223 ModestConnectionSpecificSmtpEditWindow *window, const gchar* iap_id, const gchar* iap_name,
224 const ModestServerAccountData *data)
226 ModestConnectionSpecificSmtpEditWindowPrivate *priv =
227 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (window);
229 /* This causes a warning because of the %s in the translation, but not in the original string: */
230 gchar* title = g_strdup_printf (_("mcen_ti_connection_connection_name"), iap_name);
231 gtk_window_set_title (GTK_WINDOW (window), title);
236 gtk_entry_set_text (GTK_ENTRY (priv->entry_outgoingserver), data->hostname);
237 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_username), data->username);
238 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_password), data->password);
240 modest_serversecurity_combo_box_set_active_serversecurity (
241 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), data->security);
243 modest_secureauth_combo_box_set_active_secureauth (
244 MODEST_SECUREAUTH_COMBO_BOX (priv->combo_outgoing_auth), data->secure_auth);
247 hildon_number_editor_set_value (
248 HILDON_NUMBER_EDITOR (priv->entry_port), data->port);
253 * The result must be freed with modest_account_mgr_free_server_account_data(). */
254 ModestServerAccountData*
255 modest_connection_specific_smtp_edit_window_get_settings (
256 ModestConnectionSpecificSmtpEditWindow *window,
257 ModestAccountMgr *account_manager, const gchar* server_account_name)
259 ModestConnectionSpecificSmtpEditWindowPrivate *priv =
260 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (window);
262 g_assert (server_account_name);
264 /* Use g_slice_new0(), because that's what modest_account_mgr_free_server_account_data()
265 * expects us to use. */
266 ModestServerAccountData *result = g_slice_new0 (ModestServerAccountData);
268 result->hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver)));
269 result->username = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username)));
270 result->password = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_user_password)));
272 result->security = modest_serversecurity_combo_box_get_active_serversecurity (
273 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security));
275 result->secure_auth = modest_secureauth_combo_box_get_active_secureauth (
276 MODEST_SECUREAUTH_COMBO_BOX (priv->combo_outgoing_auth));
279 result->port = hildon_number_editor_get_value (
280 HILDON_NUMBER_EDITOR (priv->entry_port));