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 <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_WINDOW);
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_button_edit (GtkButton *button, gpointer user_data)
97 on_button_cancel (GtkButton *button, gpointer user_data)
99 ModestConnectionSpecificSmtpEditWindow *self = MODEST_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW (user_data);
102 * The code that showed it will respond to the hide signal. */
103 gtk_widget_hide (GTK_WIDGET (self));
107 modest_connection_specific_smtp_edit_window_init (ModestConnectionSpecificSmtpEditWindow *self)
109 ModestConnectionSpecificSmtpEditWindowPrivate *priv = CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW_GET_PRIVATE (self);
111 GtkWidget *box = gtk_vbox_new (FALSE, 2);
113 /* Create a size group to be used by all captions.
114 * Note that HildonCaption does not create a default size group if we do not specify one.
115 * We use GTK_SIZE_GROUP_HORIZONTAL, so that the widths are the same. */
116 GtkSizeGroup *sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
118 /* The outgoing server widgets: */
119 if (!priv->entry_outgoingserver)
120 priv->entry_outgoingserver = gtk_entry_new ();
121 GtkWidget *caption = hildon_caption_new (sizegroup,
122 _("mcen_li_emailsetup_smtp"), priv->entry_outgoingserver, NULL, HILDON_CAPTION_OPTIONAL);
123 gtk_widget_show (priv->entry_outgoingserver);
124 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
125 gtk_widget_show (caption);
127 /* The secure authentication widgets: */
128 if (!priv->combo_outgoing_auth)
129 priv->combo_outgoing_auth = GTK_WIDGET (easysetup_secureauth_combo_box_new ());
130 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_authentication"),
131 priv->combo_outgoing_auth, NULL, HILDON_CAPTION_OPTIONAL);
132 gtk_widget_show (priv->combo_outgoing_auth);
133 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
134 gtk_widget_show (caption);
136 /* The username widgets: */
137 priv->entry_user_username = GTK_WIDGET (easysetup_validating_entry_new ());
138 caption = hildon_caption_new (sizegroup, _("mail_fi_username"),
139 priv->entry_user_username, NULL, HILDON_CAPTION_MANDATORY);
140 gtk_widget_show (priv->entry_user_username);
141 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
142 gtk_widget_show (caption);
144 /* Prevent the use of some characters in the username,
145 * as required by our UI specification: */
146 easysetup_validating_entry_set_unallowed_characters_whitespace (
147 EASYSETUP_VALIDATING_ENTRY (priv->entry_user_username));
149 /* Set max length as in the UI spec:
150 * TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
151 gtk_entry_set_max_length (GTK_ENTRY (priv->entry_user_username), 64);
153 /* The password widgets: */
154 priv->entry_user_password = gtk_entry_new ();
155 gtk_entry_set_visibility (GTK_ENTRY (priv->entry_user_password), FALSE);
156 /* gtk_entry_set_invisible_char (GTK_ENTRY (priv->entry_user_password), '*'); */
157 caption = hildon_caption_new (sizegroup,
158 _("mail_fi_password"), priv->entry_user_password, NULL, HILDON_CAPTION_OPTIONAL);
159 gtk_widget_show (priv->entry_user_password);
160 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
161 gtk_widget_show (caption);
163 /* The secure connection widgets: */
164 if (!priv->combo_outgoing_security)
165 priv->combo_outgoing_security = GTK_WIDGET (easysetup_serversecurity_combo_box_new ());
166 easysetup_serversecurity_combo_box_fill (
167 EASYSETUP_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), MODEST_PROTOCOL_TRANSPORT_SMTP);
168 easysetup_serversecurity_combo_box_set_active_serversecurity (
169 EASYSETUP_SERVERSECURITY_COMBO_BOX (priv->combo_outgoing_security), MODEST_PROTOCOL_SECURITY_NONE);
170 caption = hildon_caption_new (sizegroup, _("mcen_li_emailsetup_secure_connection"),
171 priv->combo_outgoing_security, NULL, HILDON_CAPTION_OPTIONAL);
172 gtk_widget_show (priv->combo_outgoing_security);
173 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
174 gtk_widget_show (caption);
176 /* The port number widgets: */
177 if (!priv->entry_port)
178 priv->entry_port = gtk_entry_new ();
179 caption = hildon_caption_new (sizegroup,
180 _("mcen_li_emailsetup_smtp"), priv->entry_port, NULL, HILDON_CAPTION_OPTIONAL);
181 gtk_widget_show (priv->entry_port);
182 gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
183 gtk_widget_show (caption);
185 /* Add the buttons: */
186 GtkWidget *hbox = gtk_hbox_new (FALSE, 2);
187 gtk_box_pack_start (GTK_BOX (box), hbox, TRUE, TRUE, 2);
188 gtk_widget_show (hbox);
190 GtkWidget *button_edit = gtk_button_new_from_stock (GTK_STOCK_EDIT);
191 gtk_box_pack_start (GTK_BOX (hbox), button_edit, TRUE, FALSE, 2);
192 gtk_widget_show (button_edit);
193 g_signal_connect (G_OBJECT (button_edit), "clicked",
194 G_CALLBACK (on_button_edit), self);
196 GtkWidget *button_cancel = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
197 gtk_box_pack_start (GTK_BOX (hbox), button_cancel, TRUE, FALSE, 2);
198 gtk_widget_show (button_cancel);
199 g_signal_connect (G_OBJECT (button_edit), "clicked",
200 G_CALLBACK (on_button_cancel), self);
202 gtk_widget_show (box);
205 ModestConnectionSpecificSmtpEditWindow*
206 modest_connection_specific_smtp_edit_window_new (void)
208 return g_object_new (MODEST_TYPE_CONNECTION_SPECIFIC_SMTP_EDIT_WINDOW, NULL);