1 /* connection-specific-smtp-window.c */
3 #include "modest-connection-specific-smtp-edit-window.h"
4 #include "maemo/modest-maemo-ui-constants.h"
5 #include <hildon-widgets/hildon-caption.h>
6 #include <hildon-widgets/hildon-number-editor.h>
7 #include "widgets/modest-serversecurity-combo-box.h"
8 #include "widgets/modest-secureauth-combo-box.h"
9 #include "widgets/modest-validating-entry.h"
10 #include <modest-account-mgr-helpers.h>
11 #include <gtk/gtkbutton.h>
12 #include <gtk/gtkhbox.h>
13 #include <gtk/gtkvbox.h>
14 #include <gtk/gtkstock.h>
16 #include <glib/gi18n.h>
18 G_DEFINE_TYPE (ModestConnectionSpecificSmtpEditWindow, modest_connection_specific_smtp_edit_window, GTK_TYPE_DIALOG);
20 #define CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE(o) \
21 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW, ModestConnectionSpecificSmtpEditWindowPrivate))
23 typedef struct _ModestConnectionSpecificSmtpEditWindowPrivate ModestConnectionSpecificSmtpEditWindowPrivate;
25 struct _ModestConnectionSpecificSmtpEditWindowPrivate
27 GtkWidget *entry_outgoingserver;
28 GtkWidget *combo_outgoing_auth;
29 GtkWidget *entry_user_username;
30 GtkWidget *entry_user_password;
31 GtkWidget *combo_outgoing_security;
32 GtkWidget *entry_port;
35 GtkWidget *button_cancel;
39 modest_connection_specific_smtp_edit_window_get_property (GObject *object, guint property_id,
40 GValue *value, GParamSpec *pspec)
42 switch (property_id) {
44 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
49 modest_connection_specific_smtp_edit_window_set_property (GObject *object, guint property_id,
50 const GValue *value, GParamSpec *pspec)
52 switch (property_id) {
54 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
59 modest_connection_specific_smtp_edit_window_dispose (GObject *object)
61 if (G_OBJECT_CLASS (modest_connection_specific_smtp_edit_window_parent_class)->dispose)
62 G_OBJECT_CLASS (modest_connection_specific_smtp_edit_window_parent_class)->dispose (object);
66 modest_connection_specific_smtp_edit_window_finalize (GObject *object)
68 G_OBJECT_CLASS (modest_connection_specific_smtp_edit_window_parent_class)->finalize (object);
72 modest_connection_specific_smtp_edit_window_class_init (ModestConnectionSpecificSmtpEditWindowClass *klass)
74 GObjectClass *object_class = G_OBJECT_CLASS (klass);
76 g_type_class_add_private (klass, sizeof (ModestConnectionSpecificSmtpEditWindowPrivate));
78 object_class->get_property = modest_connection_specific_smtp_edit_window_get_property;
79 object_class->set_property = modest_connection_specific_smtp_edit_window_set_property;
80 object_class->dispose = modest_connection_specific_smtp_edit_window_dispose;
81 object_class->finalize = modest_connection_specific_smtp_edit_window_finalize;
86 MODEL_COL_SERVER_NAME = 1,
91 on_combo_security_changed (GtkComboBox *widget, gpointer user_data)
93 ModestConnectionSpecificSmtpEditWindow *self =
94 MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (user_data);
95 ModestConnectionSpecificSmtpEditWindowPrivate *priv =
96 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
98 const gint port_number =
99 modest_serversecurity_combo_box_get_active_serversecurity_port (
100 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security));
102 if(port_number != 0) {
103 hildon_number_editor_set_value (
104 HILDON_NUMBER_EDITOR (priv->entry_port), port_number);
109 modest_connection_specific_smtp_edit_window_init (ModestConnectionSpecificSmtpEditWindow *self)
111 ModestConnectionSpecificSmtpEditWindowPrivate *priv =
112 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
114 GtkWidget *box = GTK_DIALOG(self)->vbox; /* gtk_vbox_new (FALSE, MODEST_MARGIN_HALF); */
115 gtk_container_set_border_width (GTK_CONTAINER (box), MODEST_MARGIN_HALF);
117 /* Create a size group to be used by all captions.
118 * Note that HildonCaption does not create a default size group if we do not specify one.
119 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
120 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
122 /* The outgoing server widgets: */
123 if (!priv->entry_outgoingserver)
124 priv->entry_outgoingserver = gtk_entry_new ();
125 GtkWidget *caption = hildon_caption_new (sizegroup,
126 _("mcen_li_emailsetup_smtp"), priv->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
127 gtk_widget_show (priv->entry_outgoingserver);
128 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
129 gtk_widget_show (caption);
131 /* Show a default port number when the security method changes, as per the UI spec: */
132 g_signal_connect (G_OBJECT (priv->combo_outgoing_security), "changed", (GCallback)on_combo_security_changed, self);
135 /* The secure authentication widgets: */
136 if (!priv->combo_outgoing_auth)
137 priv->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
138 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
139 priv->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
140 gtk_widget_show (priv->combo_outgoing_auth);
141 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
142 gtk_widget_show (caption);
144 /* The username widgets: */
145 priv->entry_user_username = GTK_WIDGET (easysetup_validating_entry_new ());
146 caption = hildon_caption_new (sizegroup, _("mail_fi_username"),
147 priv->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
148 gtk_widget_show (priv->entry_user_username);
149 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
150 gtk_widget_show (caption);
152 /* Prevent the use of some characters in the username,
153 * as required by our UI specification: */
154 easysetup_validating_entry_set_unallowed_characters_whitespace (
155 EASYSETUP_VALIDATING_ENTRY (priv->entry_user_username));
157 /* Set max length as in the UI spec:
158 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
159 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
161 /* The password widgets: */
162 priv->entry_user_password = gtk_entry_new ();
163 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
164 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
165 caption = hildon_caption_new (sizegroup,
166 _("mail_fi_password"), priv->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
167 gtk_widget_show (priv->entry_user_password);
168 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
169 gtk_widget_show (caption);
171 /* The secure connection widgets: */
172 if (!priv->combo_outgoing_security)
173 priv->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
174 modest_serversecurity_combo_box_fill (
175 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
176 modest_serversecurity_combo_box_set_active_serversecurity (
177 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), MODEST_PROTOCOL_SECURITY_NONE);
178 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
179 priv->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
180 gtk_widget_show (priv->combo_outgoing_security);
181 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
182 gtk_widget_show (caption);
184 /* The port number widgets: */
185 if (!priv->entry_port)
186 priv->entry_port = GTK_WIDGET (hildon_number_editor_new (0, 65535));
187 caption = hildon_caption_new (sizegroup,
188 _("mcen_li_emailsetup_smtp"), priv->entry_port, NULL, HILDON_CAPTION_OPTIONAL);
189 gtk_widget_show (priv->entry_port);
190 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
191 gtk_widget_show (caption);
193 /* Add the buttons: */
194 gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_OK, GTK_RESPONSE_OK);
195 gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
198 gtk_widget_show (box);
201 ModestConnectionSpecificSmtpEditWindow*
202 modest_connection_specific_smtp_edit_window_new (void)
204 return g_object_new (MODEST_TYPE_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW, NULL);
208 modest_connection_specific_smtp_edit_window_set_connection (
209 ModestConnectionSpecificSmtpEditWindow *window, const gchar* iap_id, const gchar* iap_name,
210 const ModestServerAccountData *data)
212 ModestConnectionSpecificSmtpEditWindowPrivate *priv =
213 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (window);
215 /* This causes a warning because of the %s in the translation, but not in the original string: */
216 gchar* title = g_strdup_printf (_("mcen_ti_connection_connection_name"), iap_name);
217 gtk_window_set_title (GTK_WINDOW (window), title);
222 gtk_entry_set_text (GTK_ENTRY (priv->entry_outgoingserver), data->hostname);
223 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_username), data->username);
224 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_password), data->password);
226 modest_serversecurity_combo_box_set_active_serversecurity (
227 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), data->security);
229 modest_secureauth_combo_box_set_active_secureauth (
230 MODEST_SECUREAUTH_COMBO_BOX (priv->combo_outgoing_auth), data->secure_auth);
233 hildon_number_editor_set_value (
234 HILDON_NUMBER_EDITOR (priv->entry_port), data->port);
239 * The result must be freed with modest_account_mgr_free_server_account_data(). */
240 ModestServerAccountData*
241 modest_connection_specific_smtp_edit_window_get_settings (
242 ModestConnectionSpecificSmtpEditWindow *window,
243 ModestAccountMgr *account_manager, const gchar* server_account_name)
245 ModestConnectionSpecificSmtpEditWindowPrivate *priv =
246 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (window);
248 g_assert (server_account_name);
250 /* Use g_slice_new0(), because that's what modest_account_mgr_free_server_account_data()
251 * expects us to use. */
252 ModestServerAccountData *result = g_slice_new0 (ModestServerAccountData);
254 result->hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver)));
255 result->username = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username)));
256 result->password = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_user_password)));
258 result->security = modest_serversecurity_combo_box_get_active_serversecurity (
259 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security));
261 result->secure_auth = modest_secureauth_combo_box_get_active_secureauth (
262 MODEST_SECUREAUTH_COMBO_BOX (priv->combo_outgoing_auth));
265 result->port = hildon_number_editor_get_value (
266 HILDON_NUMBER_EDITOR (priv->entry_port));