1 /* connection-specific-smtp-window.c */
3 #include "modest-connection-specific-smtp-edit-window.h"
4 #include <hildon-widgets/hildon-caption.h>
5 #include "widgets/modest-serversecurity-combo-box.h"
6 #include "widgets/modest-secureauth-combo-box.h"
7 #include "widgets/modest-validating-entry.h"
8 #include <modest-account-mgr-helpers.h>
9 #include <gtk/gtkbutton.h>
10 #include <gtk/gtkhbox.h>
11 #include <gtk/gtkvbox.h>
12 #include <gtk/gtkstock.h>
14 #include <glib/gi18n.h>
16 G_DEFINE_TYPE (ModestConnectionSpecificSmtpEditWindow, modest_connection_specific_smtp_edit_window, GTK_TYPE_DIALOG);
18 #define CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE(o) \
19 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW, ModestConnectionSpecificSmtpEditWindowPrivate))
21 typedef struct _ModestConnectionSpecificSmtpEditWindowPrivate ModestConnectionSpecificSmtpEditWindowPrivate;
23 struct _ModestConnectionSpecificSmtpEditWindowPrivate
25 GtkWidget *entry_outgoingserver;
26 GtkWidget *combo_outgoing_auth;
27 GtkWidget *entry_user_username;
28 GtkWidget *entry_user_password;
29 GtkWidget *combo_outgoing_security;
30 GtkWidget *entry_port;
33 GtkWidget *button_cancel;
37 modest_connection_specific_smtp_edit_window_get_property (GObject *object, guint property_id,
38 GValue *value, GParamSpec *pspec)
40 switch (property_id) {
42 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
47 modest_connection_specific_smtp_edit_window_set_property (GObject *object, guint property_id,
48 const GValue *value, GParamSpec *pspec)
50 switch (property_id) {
52 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
57 modest_connection_specific_smtp_edit_window_dispose (GObject *object)
59 if (G_OBJECT_CLASS (modest_connection_specific_smtp_edit_window_parent_class)->dispose)
60 G_OBJECT_CLASS (modest_connection_specific_smtp_edit_window_parent_class)->dispose (object);
64 modest_connection_specific_smtp_edit_window_finalize (GObject *object)
66 G_OBJECT_CLASS (modest_connection_specific_smtp_edit_window_parent_class)->finalize (object);
70 modest_connection_specific_smtp_edit_window_class_init (ModestConnectionSpecificSmtpEditWindowClass *klass)
72 GObjectClass *object_class = G_OBJECT_CLASS (klass);
74 g_type_class_add_private (klass, sizeof (ModestConnectionSpecificSmtpEditWindowPrivate));
76 object_class->get_property = modest_connection_specific_smtp_edit_window_get_property;
77 object_class->set_property = modest_connection_specific_smtp_edit_window_set_property;
78 object_class->dispose = modest_connection_specific_smtp_edit_window_dispose;
79 object_class->finalize = modest_connection_specific_smtp_edit_window_finalize;
84 MODEL_COL_SERVER_NAME = 1,
89 on_combo_security_changed (GtkComboBox *widget, gpointer user_data)
91 ModestConnectionSpecificSmtpEditWindow *self =
92 MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (user_data);
93 ModestConnectionSpecificSmtpEditWindowPrivate *priv =
94 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
96 const gint port_number =
97 modest_serversecurity_combo_box_get_active_serversecurity_port (
98 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security));
100 if(port_number != 0) {
101 gchar* str = g_strdup_printf ("%d", port_number);
102 gtk_entry_set_text (GTK_ENTRY (priv->entry_port), str);
108 modest_connection_specific_smtp_edit_window_init (ModestConnectionSpecificSmtpEditWindow *self)
110 ModestConnectionSpecificSmtpEditWindowPrivate *priv =
111 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
113 GtkWidget *box = GTK_DIALOG(self)->vbox; /* gtk_vbox_new (FALSE, 2); */
115 /* Create a size group to be used by all captions.
116 * Note that HildonCaption does not create a default size group if we do not specify one.
117 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
118 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
120 /* The outgoing server widgets: */
121 if (!priv->entry_outgoingserver)
122 priv->entry_outgoingserver = gtk_entry_new ();
123 GtkWidget *caption = hildon_caption_new (sizegroup,
124 _("mcen_li_emailsetup_smtp"), priv->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
125 gtk_widget_show (priv->entry_outgoingserver);
126 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
127 gtk_widget_show (caption);
129 /* Show a default port number when the security method changes, as per the UI spec: */
130 g_signal_connect (G_OBJECT (priv->combo_outgoing_security), "changed", (GCallback)on_combo_security_changed, self);
133 /* The secure authentication widgets: */
134 if (!priv->combo_outgoing_auth)
135 priv->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
136 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
137 priv->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
138 gtk_widget_show (priv->combo_outgoing_auth);
139 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
140 gtk_widget_show (caption);
142 /* The username widgets: */
143 priv->entry_user_username = GTK_WIDGET (easysetup_validating_entry_new ());
144 caption = hildon_caption_new (sizegroup, _("mail_fi_username"),
145 priv->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
146 gtk_widget_show (priv->entry_user_username);
147 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
148 gtk_widget_show (caption);
150 /* Prevent the use of some characters in the username,
151 * as required by our UI specification: */
152 easysetup_validating_entry_set_unallowed_characters_whitespace (
153 EASYSETUP_VALIDATING_ENTRY (priv->entry_user_username));
155 /* Set max length as in the UI spec:
156 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
157 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
159 /* The password widgets: */
160 priv->entry_user_password = gtk_entry_new ();
161 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
162 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
163 caption = hildon_caption_new (sizegroup,
164 _("mail_fi_password"), priv->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
165 gtk_widget_show (priv->entry_user_password);
166 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
167 gtk_widget_show (caption);
169 /* The secure connection widgets: */
170 if (!priv->combo_outgoing_security)
171 priv->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
172 modest_serversecurity_combo_box_fill (
173 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
174 modest_serversecurity_combo_box_set_active_serversecurity (
175 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), MODEST_PROTOCOL_SECURITY_NONE);
176 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
177 priv->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
178 gtk_widget_show (priv->combo_outgoing_security);
179 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
180 gtk_widget_show (caption);
182 /* The port number widgets: */
183 if (!priv->entry_port)
184 priv->entry_port = gtk_entry_new ();
185 caption = hildon_caption_new (sizegroup,
186 _("mcen_li_emailsetup_smtp"), priv->entry_port, NULL, HILDON_CAPTION_OPTIONAL);
187 gtk_widget_show (priv->entry_port);
188 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
189 gtk_widget_show (caption);
191 /* Add the buttons: */
192 gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_OK, GTK_RESPONSE_OK);
193 gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
196 gtk_widget_show (box);
199 ModestConnectionSpecificSmtpEditWindow*
200 modest_connection_specific_smtp_edit_window_new (void)
202 return g_object_new (MODEST_TYPE_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW, NULL);
206 modest_connection_specific_smtp_edit_window_set_connection (
207 ModestConnectionSpecificSmtpEditWindow *window, const gchar* iap_id, const gchar* iap_name,
208 const ModestServerAccountData *data)
210 ModestConnectionSpecificSmtpEditWindowPrivate *priv =
211 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (window);
213 /* This causes a warning because of the %s in the translation, but not in the original string: */
214 gchar* title = g_strdup_printf (_("mcen_ti_connection_connection_name"), iap_name);
215 gtk_window_set_title (GTK_WINDOW (window), title);
220 gtk_entry_set_text (GTK_ENTRY (priv->entry_outgoingserver), data->hostname);
221 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_username), data->username);
222 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_password), data->password);
224 modest_serversecurity_combo_box_set_active_serversecurity (
225 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), data->security);
227 modest_secureauth_combo_box_set_active_secureauth (
228 MODEST_SECUREAUTH_COMBO_BOX (priv->combo_outgoing_auth), data->secure_auth);
231 gchar * port_str = g_strdup_printf ("%d", data->port);
232 gtk_entry_set_text (GTK_ENTRY (priv->entry_port), port_str);
238 * The result must be freed with modest_account_mgr_free_server_account_data(). */
239 ModestServerAccountData*
240 modest_connection_specific_smtp_edit_window_get_settings (
241 ModestConnectionSpecificSmtpEditWindow *window,
242 ModestAccountMgr *account_manager, const gchar* server_account_name)
244 ModestConnectionSpecificSmtpEditWindowPrivate *priv =
245 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (window);
247 g_assert (server_account_name);
249 /* Use g_slice_new0(), because that's what modest_account_mgr_free_server_account_data()
250 * expects us to use. */
251 ModestServerAccountData *result = g_slice_new0 (ModestServerAccountData);
253 result->hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver)));
254 result->username = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username)));
255 result->password = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_user_password)));
257 result->security = modest_serversecurity_combo_box_get_active_serversecurity (
258 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security));
260 result->secure_auth = modest_secureauth_combo_box_get_active_secureauth (
261 MODEST_SECUREAUTH_COMBO_BOX (priv->combo_outgoing_auth));
264 const gchar * port_str = gtk_entry_get_text (GTK_ENTRY (priv->entry_port));
266 result->port = atoi (port_str);