1 /* connection-specific-smtp-window.c */
3 #include "modest-connection-specific-smtp-edit-window.h"
4 #include <hildon-widgets/hildon-caption.h>
5 #include "maemo/easysetup/modest-easysetup-country-combo-box.h"
6 #include "maemo/easysetup/modest-easysetup-provider-combo-box.h"
7 #include "maemo/easysetup/modest-easysetup-servertype-combo-box.h"
8 #include "maemo/easysetup/modest-easysetup-serversecurity-combo-box.h"
9 #include "maemo/easysetup/modest-easysetup-secureauth-combo-box.h"
10 #include "maemo/easysetup/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 easysetup_serversecurity_combo_box_get_active_serversecurity_port (
101 EASYSETUP_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security));
103 if(port_number != 0) {
104 gchar* str = g_strdup_printf ("%d", port_number);
105 gtk_entry_set_text (GTK_ENTRY (priv->entry_port), str);
111 modest_connection_specific_smtp_edit_window_init (ModestConnectionSpecificSmtpEditWindow *self)
113 ModestConnectionSpecificSmtpEditWindowPrivate *priv =
114 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
116 GtkWidget *box = GTK_DIALOG(self)->vbox; /* gtk_vbox_new (FALSE, 2); */
118 /* Create a size group to be used by all captions.
119 * Note that HildonCaption does not create a default size group if we do not specify one.
120 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
121 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
123 /* The outgoing server widgets: */
124 if (!priv->entry_outgoingserver)
125 priv->entry_outgoingserver = gtk_entry_new ();
126 GtkWidget *caption = hildon_caption_new (sizegroup,
127 _("mcen_li_emailsetup_smtp"), priv->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
128 gtk_widget_show (priv->entry_outgoingserver);
129 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
130 gtk_widget_show (caption);
132 /* Show a default port number when the security method changes, as per the UI spec: */
133 g_signal_connect (G_OBJECT (priv->combo_outgoing_security), "changed", (GCallback)on_combo_security_changed, self);
136 /* The secure authentication widgets: */
137 if (!priv->combo_outgoing_auth)
138 priv->combo_outgoing_auth = GTK_WIDGET (easysetup_secureauth_combo_box_new ());
139 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
140 priv->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
141 gtk_widget_show (priv->combo_outgoing_auth);
142 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
143 gtk_widget_show (caption);
145 /* The username widgets: */
146 priv->entry_user_username = GTK_WIDGET (easysetup_validating_entry_new ());
147 caption = hildon_caption_new (sizegroup, _("mail_fi_username"),
148 priv->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
149 gtk_widget_show (priv->entry_user_username);
150 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
151 gtk_widget_show (caption);
153 /* Prevent the use of some characters in the username,
154 * as required by our UI specification: */
155 easysetup_validating_entry_set_unallowed_characters_whitespace (
156 EASYSETUP_VALIDATING_ENTRY (priv->entry_user_username));
158 /* Set max length as in the UI spec:
159 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
160 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
162 /* The password widgets: */
163 priv->entry_user_password = gtk_entry_new ();
164 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
165 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
166 caption = hildon_caption_new (sizegroup,
167 _("mail_fi_password"), priv->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
168 gtk_widget_show (priv->entry_user_password);
169 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
170 gtk_widget_show (caption);
172 /* The secure connection widgets: */
173 if (!priv->combo_outgoing_security)
174 priv->combo_outgoing_security = GTK_WIDGET (easysetup_serversecurity_combo_box_new ());
175 easysetup_serversecurity_combo_box_fill (
176 EASYSETUP_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
177 easysetup_serversecurity_combo_box_set_active_serversecurity (
178 EASYSETUP_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), MODEST_PROTOCOL_SECURITY_NONE);
179 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
180 priv->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
181 gtk_widget_show (priv->combo_outgoing_security);
182 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
183 gtk_widget_show (caption);
185 /* The port number widgets: */
186 if (!priv->entry_port)
187 priv->entry_port = gtk_entry_new ();
188 caption = hildon_caption_new (sizegroup,
189 _("mcen_li_emailsetup_smtp"), priv->entry_port, NULL, HILDON_CAPTION_OPTIONAL);
190 gtk_widget_show (priv->entry_port);
191 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
192 gtk_widget_show (caption);
194 /* Add the buttons: */
195 gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_OK, GTK_RESPONSE_OK);
196 gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
199 gtk_widget_show (box);
202 ModestConnectionSpecificSmtpEditWindow*
203 modest_connection_specific_smtp_edit_window_new (void)
205 return g_object_new (MODEST_TYPE_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW, NULL);
209 modest_connection_specific_smtp_edit_window_set_connection (
210 ModestConnectionSpecificSmtpEditWindow *window, const gchar* iap_id, const gchar* iap_name,
211 const ModestServerAccountData *data)
213 ModestConnectionSpecificSmtpEditWindowPrivate *priv =
214 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (window);
216 /* This causes a warning because of the %s in the translation, but not in the original string: */
217 gchar* title = g_strdup_printf (_("mcen_ti_connection_connection_name"), iap_name);
218 gtk_window_set_title (GTK_WINDOW (window), title);
223 gtk_entry_set_text (GTK_ENTRY (priv->entry_outgoingserver), data->hostname);
224 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_username), data->username);
225 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_password), data->password);
227 easysetup_serversecurity_combo_box_set_active_serversecurity (
228 EASYSETUP_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), data->security);
230 easysetup_secureauth_combo_box_set_active_secureauth (
231 EASYSETUP_SECUREAUTH_COMBO_BOX (priv->combo_outgoing_auth), data->secure_auth);
234 gchar * port_str = g_strdup_printf ("%d", data->port);
235 gtk_entry_set_text (GTK_ENTRY (priv->entry_port), port_str);
241 * The result must be freed with modest_account_mgr_free_server_account_data(). */
242 ModestServerAccountData*
243 modest_connection_specific_smtp_edit_window_get_settings (
244 ModestConnectionSpecificSmtpEditWindow *window,
245 ModestAccountMgr *account_manager, const gchar* server_account_name)
247 ModestConnectionSpecificSmtpEditWindowPrivate *priv =
248 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (window);
250 g_assert (server_account_name);
252 /* Use g_slice_new0(), because that's what modest_account_mgr_free_server_account_data()
253 * expects us to use. */
254 ModestServerAccountData *result = g_slice_new0 (ModestServerAccountData);
256 result->hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver)));
257 result->username = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username)));
258 result->password = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_user_password)));
260 result->security = easysetup_serversecurity_combo_box_get_active_serversecurity (
261 EASYSETUP_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security));
263 result->secure_auth = easysetup_secureauth_combo_box_get_active_secureauth (
264 EASYSETUP_SECUREAUTH_COMBO_BOX (priv->combo_outgoing_auth));
267 const gchar * port_str = gtk_entry_get_text (GTK_ENTRY (priv->entry_port));
269 result->port = atoi (port_str);