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-serversecurity-combo-box.h"
36 #include "widgets/modest-secureauth-combo-box.h"
37 #include "widgets/modest-validating-entry.h"
38 #include <modest-account-mgr-helpers.h>
39 #include <gtk/gtkbutton.h>
40 #include <gtk/gtkhbox.h>
41 #include <gtk/gtkvbox.h>
42 #include <gtk/gtkstock.h>
44 #include <glib/gi18n.h>
46 G_DEFINE_TYPE (ModestConnectionSpecificSmtpEditWindow, modest_connection_specific_smtp_edit_window, GTK_TYPE_DIALOG);
48 #define CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE(o) \
49 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW, ModestConnectionSpecificSmtpEditWindowPrivate))
51 typedef struct _ModestConnectionSpecificSmtpEditWindowPrivate ModestConnectionSpecificSmtpEditWindowPrivate;
53 struct _ModestConnectionSpecificSmtpEditWindowPrivate
55 GtkWidget *entry_outgoingserver;
56 GtkWidget *combo_outgoing_auth;
57 GtkWidget *entry_user_username;
58 GtkWidget *entry_user_password;
59 GtkWidget *combo_outgoing_security;
60 GtkWidget *entry_port;
63 GtkWidget *button_cancel;
69 modest_connection_specific_smtp_edit_window_get_property (GObject *object, guint property_id,
70 GValue *value, GParamSpec *pspec)
72 switch (property_id) {
74 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
79 modest_connection_specific_smtp_edit_window_set_property (GObject *object, guint property_id,
80 const GValue *value, GParamSpec *pspec)
82 switch (property_id) {
84 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
89 modest_connection_specific_smtp_edit_window_dispose (GObject *object)
91 if (G_OBJECT_CLASS (modest_connection_specific_smtp_edit_window_parent_class)->dispose)
92 G_OBJECT_CLASS (modest_connection_specific_smtp_edit_window_parent_class)->dispose (object);
96 modest_connection_specific_smtp_edit_window_finalize (GObject *object)
98 G_OBJECT_CLASS (modest_connection_specific_smtp_edit_window_parent_class)->finalize (object);
102 modest_connection_specific_smtp_edit_window_class_init (ModestConnectionSpecificSmtpEditWindowClass *klass)
104 GObjectClass *object_class = G_OBJECT_CLASS (klass);
106 g_type_class_add_private (klass, sizeof (ModestConnectionSpecificSmtpEditWindowPrivate));
108 object_class->get_property = modest_connection_specific_smtp_edit_window_get_property;
109 object_class->set_property = modest_connection_specific_smtp_edit_window_set_property;
110 object_class->dispose = modest_connection_specific_smtp_edit_window_dispose;
111 object_class->finalize = modest_connection_specific_smtp_edit_window_finalize;
116 MODEL_COL_SERVER_NAME = 1,
121 on_change(GtkWidget* widget, ModestConnectionSpecificSmtpEditWindow *self)
123 ModestConnectionSpecificSmtpEditWindowPrivate *priv =
124 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
125 priv->is_dirty = TRUE;
129 on_value_changed(GtkWidget* widget, GValue* value, ModestConnectionSpecificSmtpEditWindow *self)
131 on_change(widget, self);
135 on_combo_security_changed (GtkComboBox *widget, gpointer user_data)
137 ModestConnectionSpecificSmtpEditWindow *self =
138 MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (user_data);
139 ModestConnectionSpecificSmtpEditWindowPrivate *priv =
140 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
142 on_change(GTK_WIDGET(widget), self);
144 const gint port_number =
145 modest_serversecurity_combo_box_get_active_serversecurity_port (
146 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security));
148 if(port_number != 0) {
149 hildon_number_editor_set_value (
150 HILDON_NUMBER_EDITOR (priv->entry_port), port_number);
155 modest_connection_specific_smtp_edit_window_init (ModestConnectionSpecificSmtpEditWindow *self)
157 ModestConnectionSpecificSmtpEditWindowPrivate *priv =
158 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
160 GtkWidget *box = GTK_DIALOG(self)->vbox; /* gtk_vbox_new (FALSE, MODEST_MARGIN_HALF); */
161 gtk_box_set_spacing (GTK_BOX (box), MODEST_MARGIN_NONE);
162 gtk_container_set_border_width (GTK_CONTAINER (box), MODEST_MARGIN_HALF);
164 /* Create a size group to be used by all captions.
165 * Note that HildonCaption does not create a default size group if we do not specify one.
166 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
167 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
169 /* The outgoing server widgets: */
170 if (!priv->entry_outgoingserver)
171 priv->entry_outgoingserver = gtk_entry_new ();
172 /* Auto-capitalization is the default, so let's turn it off: */
173 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_outgoingserver), HILDON_GTK_INPUT_MODE_FULL);
174 g_signal_connect(G_OBJECT(priv->entry_outgoingserver), "changed", G_CALLBACK(on_change), self);
176 GtkWidget *caption = hildon_caption_new (sizegroup,
177 _("mcen_li_emailsetup_smtp"), priv->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
178 gtk_widget_show (priv->entry_outgoingserver);
179 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
180 gtk_widget_show (caption);
182 /* The secure authentication widgets: */
183 if (!priv->combo_outgoing_auth)
184 priv->combo_outgoing_auth = GTK_WIDGET (modest_secureauth_combo_box_new ());
185 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
186 priv->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
187 g_signal_connect (G_OBJECT (priv->combo_outgoing_auth), "changed", G_CALLBACK(on_change), self);
188 gtk_widget_show (priv->combo_outgoing_auth);
189 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
190 gtk_widget_show (caption);
192 /* The username widgets: */
193 priv->entry_user_username = GTK_WIDGET (modest_validating_entry_new ());
194 /* Auto-capitalization is the default, so let's turn it off: */
195 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_username), HILDON_GTK_INPUT_MODE_FULL);
196 caption = hildon_caption_new (sizegroup, _("mail_fi_username"),
197 priv->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
198 g_signal_connect(G_OBJECT(priv->entry_user_username), "changed", G_CALLBACK(on_change), self);
199 gtk_widget_show (priv->entry_user_username);
200 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
201 gtk_widget_show (caption);
203 /* Prevent the use of some characters in the username,
204 * as required by our UI specification: */
205 modest_validating_entry_set_unallowed_characters_whitespace (
206 MODEST_VALIDATING_ENTRY (priv->entry_user_username));
208 /* Set max length as in the UI spec:
209 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
210 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
212 /* The password widgets: */
213 priv->entry_user_password = gtk_entry_new ();
214 /* Auto-capitalization is the default, so let's turn it off: */
215 hildon_gtk_entry_set_input_mode (GTK_ENTRY (priv->entry_user_password),
216 HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
217 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
218 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
219 caption = hildon_caption_new (sizegroup,
220 _("mail_fi_password"), priv->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
221 g_signal_connect(G_OBJECT(priv->entry_user_password), "changed", G_CALLBACK(on_change), self);
222 gtk_widget_show (priv->entry_user_password);
223 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
224 gtk_widget_show (caption);
226 /* The secure connection widgets: */
227 if (!priv->combo_outgoing_security)
228 priv->combo_outgoing_security = GTK_WIDGET (modest_serversecurity_combo_box_new ());
229 modest_serversecurity_combo_box_fill (
230 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
231 modest_serversecurity_combo_box_set_active_serversecurity (
232 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), MODEST_PROTOCOL_CONNECTION_NORMAL);
233 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
234 priv->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
235 gtk_widget_show (priv->combo_outgoing_security);
236 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
237 gtk_widget_show (caption);
239 /* The port number widgets: */
240 if (!priv->entry_port)
241 priv->entry_port = GTK_WIDGET (hildon_number_editor_new (0, 65535));
242 caption = hildon_caption_new (sizegroup,
243 _("mcen_li_emailsetup_smtp"), priv->entry_port, NULL, HILDON_CAPTION_OPTIONAL);
244 g_signal_connect(G_OBJECT(priv->entry_port), "notify::value", G_CALLBACK(on_value_changed), self);
245 gtk_widget_show (priv->entry_port);
246 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF);
247 gtk_widget_show (caption);
249 /* Show a default port number when the security method changes, as per the UI spec: */
250 g_signal_connect (G_OBJECT (priv->combo_outgoing_security), "changed", (GCallback)on_combo_security_changed, self);
251 on_combo_security_changed (GTK_COMBO_BOX (priv->combo_outgoing_security), self);
253 /* Add the buttons: */
254 gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_OK, GTK_RESPONSE_OK);
255 gtk_dialog_add_button (GTK_DIALOG (self), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
257 priv->is_dirty = FALSE;
259 gtk_widget_show (box);
262 /* When this window is shown, hibernation should not be possible,
263 * because there is no sensible way to save the state: */
264 modest_window_mgr_prevent_hibernation_while_window_is_shown (
265 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
268 ModestConnectionSpecificSmtpEditWindow*
269 modest_connection_specific_smtp_edit_window_new (void)
271 return g_object_new (MODEST_TYPE_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW, NULL);
275 modest_connection_specific_smtp_edit_window_set_connection (
276 ModestConnectionSpecificSmtpEditWindow *window, const gchar* iap_id, const gchar* iap_name,
277 const ModestServerAccountData *data)
279 ModestConnectionSpecificSmtpEditWindowPrivate *priv =
280 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (window);
282 /* This causes a warning because of the %s in the translation, but not in the original string: */
283 gchar* title = g_strdup_printf (_("mcen_ti_connection_connection_name"), iap_name);
284 gtk_window_set_title (GTK_WINDOW (window), title);
289 gtk_entry_set_text (GTK_ENTRY (priv->entry_outgoingserver), data->hostname);
290 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_username), data->username);
291 gtk_entry_set_text (GTK_ENTRY (priv->entry_user_password), data->password);
293 modest_serversecurity_combo_box_set_active_serversecurity (
294 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), data->security);
296 modest_secureauth_combo_box_set_active_secureauth (
297 MODEST_SECUREAUTH_COMBO_BOX (priv->combo_outgoing_auth), data->secure_auth);
300 hildon_number_editor_set_value (
301 HILDON_NUMBER_EDITOR (priv->entry_port), data->port);
304 /* This will cause changed signals so we set dirty back to FALSE */
305 priv->is_dirty = FALSE;
310 * The result must be freed with modest_account_mgr_free_server_account_data(). */
311 ModestServerAccountData*
312 modest_connection_specific_smtp_edit_window_get_settings (
313 ModestConnectionSpecificSmtpEditWindow *window,
314 ModestAccountMgr *account_manager)
316 ModestConnectionSpecificSmtpEditWindowPrivate *priv =
317 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (window);
319 /* Use g_slice_new0(), because that's what modest_account_mgr_free_server_account_data()
320 * expects us to use. */
321 ModestServerAccountData *result = g_slice_new0 (ModestServerAccountData);
323 result->hostname = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_outgoingserver)));
324 result->username = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_user_username)));
325 result->password = g_strdup (gtk_entry_get_text (GTK_ENTRY (priv->entry_user_password)));
327 result->security = modest_serversecurity_combo_box_get_active_serversecurity (
328 MODEST_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security));
330 result->secure_auth = modest_secureauth_combo_box_get_active_secureauth (
331 MODEST_SECUREAUTH_COMBO_BOX (priv->combo_outgoing_auth));
334 result->port = hildon_number_editor_get_value (
335 HILDON_NUMBER_EDITOR (priv->entry_port));
340 gboolean modest_connection_specific_smtp_edit_window_is_dirty(
341 ModestConnectionSpecificSmtpEditWindow *window)
343 ModestConnectionSpecificSmtpEditWindowPrivate *priv =
344 CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (window);
346 return priv->is_dirty;