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 <glib/gi18n.h>
32 #include <widgets/modest-combo-box.h>
33 #include "modest-store-widget.h"
36 /* 'private'/'protected' functions */
37 static void modest_store_widget_class_init (ModestStoreWidgetClass *klass);
38 static void modest_store_widget_init (ModestStoreWidget *obj);
39 static void modest_store_widget_finalize (GObject *obj);
46 typedef struct _ModestStoreWidgetPrivate ModestStoreWidgetPrivate;
47 struct _ModestStoreWidgetPrivate {
49 GtkWidget *servername;
52 ModestProtoList *security_protos;
55 ModestProtoList *auth_protos;
60 ModestTransportStoreProtocol proto;
62 #define MODEST_STORE_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
63 MODEST_TYPE_STORE_WIDGET, \
64 ModestStoreWidgetPrivate))
66 static GtkContainerClass *parent_class = NULL;
68 /* uncomment the following if you have defined any signals */
69 static guint signals[LAST_SIGNAL] = {0};
72 modest_store_widget_get_type (void)
74 static GType my_type = 0;
76 static const GTypeInfo my_info = {
77 sizeof(ModestStoreWidgetClass),
79 NULL, /* base finalize */
80 (GClassInitFunc) modest_store_widget_class_init,
81 NULL, /* class finalize */
82 NULL, /* class data */
83 sizeof(ModestStoreWidget),
85 (GInstanceInitFunc) modest_store_widget_init,
88 my_type = g_type_register_static (GTK_TYPE_VBOX,
96 modest_store_widget_class_init (ModestStoreWidgetClass *klass)
98 GObjectClass *gobject_class;
99 gobject_class = (GObjectClass*) klass;
101 parent_class = g_type_class_peek_parent (klass);
102 gobject_class->finalize = modest_store_widget_finalize;
104 g_type_class_add_private (gobject_class, sizeof(ModestStoreWidgetPrivate));
106 /* signal definitions go here, e.g.: */
107 signals[DATA_CHANGED_SIGNAL] =
108 g_signal_new ("data_changed",
109 G_TYPE_FROM_CLASS (klass),
111 G_STRUCT_OFFSET(ModestStoreWidgetClass, data_changed),
113 g_cclosure_marshal_VOID__VOID,
118 modest_store_widget_init (ModestStoreWidget *obj)
120 ModestStoreWidgetPrivate *priv;
122 priv = MODEST_STORE_WIDGET_GET_PRIVATE(obj);
123 priv->proto = MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN;
129 maildir_configuration (ModestStoreWidget *self)
131 ModestStoreWidgetPrivate *priv;
132 GtkWidget *label, *box, *hbox;
134 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
135 box = gtk_vbox_new (FALSE, 6);
137 label = gtk_label_new (NULL);
138 gtk_label_set_markup (GTK_LABEL(label),
139 _("<b>Maildir configuration</b>"));
140 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 6);
141 label = gtk_label_new (NULL);
142 gtk_label_set_markup (GTK_LABEL(label),
143 _("Please select the path to your Maildir below"));
144 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 6);
146 label = gtk_label_new (_("Path:"));
149 gtk_file_chooser_button_new (_("(none)"),
150 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
152 hbox = gtk_hbox_new (FALSE, 6);
153 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 6);
154 gtk_box_pack_start (GTK_BOX(hbox), priv->chooser, FALSE, FALSE, 6);
156 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 6);
163 mbox_configuration (ModestStoreWidget *self)
165 ModestStoreWidgetPrivate *priv;
166 GtkWidget *label, *box, *hbox;
168 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
169 box = gtk_vbox_new (FALSE, 6);
171 label = gtk_label_new (NULL);
172 gtk_label_set_markup (GTK_LABEL(label),
173 _("<b>Mbox configuration</b>"));
174 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 6);
175 label = gtk_label_new (NULL);
176 gtk_label_set_markup (GTK_LABEL(label),
177 _("Please select your mbox file below"));
178 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 6);
180 label = gtk_label_new (_("mbox:"));
183 gtk_file_chooser_button_new (_("(none)"),
184 GTK_FILE_CHOOSER_ACTION_OPEN);
185 hbox = gtk_hbox_new (FALSE, 6);
186 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 6);
187 gtk_box_pack_start (GTK_BOX(hbox), priv->chooser, FALSE, FALSE, 6);
189 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 6);
195 on_entry_changed (GtkEntry *entry, gpointer user_data)
197 g_signal_emit (MODEST_STORE_WIDGET (user_data), signals[DATA_CHANGED_SIGNAL], 0);
201 imap_pop_configuration (ModestStoreWidget *self)
203 ModestStoreWidgetPrivate *priv;
204 GtkWidget *label, *box, *hbox;
206 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
207 box = gtk_vbox_new (FALSE, 6);
209 label = gtk_label_new (NULL);
210 gtk_label_set_markup (GTK_LABEL(label),_("<b>Server configuration</b>"));
211 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 6);
213 hbox = gtk_hbox_new (FALSE, 6);
214 label = gtk_label_new (_("Username:"));
216 priv->username = gtk_entry_new_with_max_length (40);
217 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
218 gtk_box_pack_start (GTK_BOX(hbox), priv->username,FALSE, FALSE, 6);
219 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 0);
221 hbox = gtk_hbox_new (FALSE, 6);
222 label = gtk_label_new (_("Server:"));
223 if (!priv->servername)
224 priv->servername = gtk_entry_new_with_max_length (40);
225 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
226 gtk_box_pack_start (GTK_BOX(hbox), priv->servername,FALSE, FALSE, 6);
227 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 0);
229 label = gtk_label_new(NULL);
230 gtk_label_set_markup (GTK_LABEL(label),_("<b>Security</b>"));
231 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 0);
233 /* Note: This ModestPairList* must exist for as long as the combo
234 * that uses it, because the ModestComboBox uses the ID opaquely,
235 * so it can't know how to manage its memory. */
236 priv->security_protos = modest_protocol_info_get_connection_protocol_pair_list ();
238 priv->security = modest_combo_box_new (priv->security_protos, g_str_equal);
240 hbox = gtk_hbox_new (FALSE, 6);
241 label = gtk_label_new(NULL);
242 gtk_label_set_text (GTK_LABEL(label),_("Connection type:"));
243 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
244 gtk_box_pack_start (GTK_BOX(hbox), priv->security, FALSE, FALSE,0);
245 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 0);
247 hbox = gtk_hbox_new (FALSE, 6);
248 label = gtk_label_new(NULL);
250 gtk_label_set_text (GTK_LABEL(label),_("Authentication:"));
251 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 6);
253 /* Note: This ModestPairList* must exist for as long as the combo
254 * that uses it, because the ModestComboBox uses the ID opaquely,
255 * so it can't know how to manage its memory. */
256 priv->auth_protos = modest_protocol_info_get_auth_protocol_pair_list (;
257 priv->auth = modest_combo_box_new (priv->auth_protos, g_str_equal);
259 gtk_box_pack_start (GTK_BOX(hbox), priv->auth, FALSE, FALSE, 0);
261 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 0);
263 /* Handle entry modifications */
264 g_signal_connect (priv->username, "changed", G_CALLBACK (on_entry_changed), self);
265 g_signal_connect (priv->servername, "changed", G_CALLBACK (on_entry_changed), self);
272 modest_store_widget_finalize (GObject *obj)
274 ModestStoreWidgetPrivate *priv = MODEST_STORE_WIDGET_GET_PRIVATE(obj);
276 /* These had to stay alive for as long as the comboboxes that used them: */
277 modest_pair_list_free (priv->security_protos);
278 modest_pair_list_free (priv->auth_protos);
280 G_OBJECT_CLASS(parent_class)->finalize (obj);
286 modest_store_widget_new (ModestTransportStoreProtocol proto)
290 ModestStoreWidget *self;
291 ModestStoreWidgetPrivate *priv;
293 g_return_val_if_fail (proto, NULL);
295 obj = g_object_new(MODEST_TYPE_STORE_WIDGET, NULL);
296 self = MODEST_STORE_WIDGET(obj);
297 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
301 if (proto == MODEST_PROTOCOL_STORE_POP || proto == MODEST_PROTOCOL_STORE_IMAP)
302 w = imap_pop_configuration (self);
303 else if (proto == MODEST_PROTOCOL_STORE_MAILDIR)
304 w = maildir_configuration (self);
305 else if (proto == MODEST_PROTOCOL_STORE_MBOX)
306 w = mbox_configuration (self);
308 w = gtk_label_new ("");
310 gtk_widget_show_all (w);
311 gtk_box_pack_start (GTK_BOX(self), w, FALSE, FALSE, 2);
313 return GTK_WIDGET(self);
317 modest_store_widget_get_username (ModestStoreWidget *self)
319 ModestStoreWidgetPrivate *priv;
321 g_return_val_if_fail (self, NULL);
322 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
324 if (GTK_IS_ENTRY(priv->username))
325 return gtk_entry_get_text (GTK_ENTRY(priv->username));
331 modest_store_widget_get_servername (ModestStoreWidget *self)
333 ModestStoreWidgetPrivate *priv;
335 g_return_val_if_fail (self, NULL);
336 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
338 if (GTK_IS_ENTRY(priv->servername))
339 return gtk_entry_get_text (GTK_ENTRY(priv->servername));
345 ModestTransportStoreProtocol
346 modest_store_widget_get_proto (ModestStoreWidget *self)
348 ModestStoreWidgetPrivate *priv;
350 g_return_val_if_fail (self, MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN);
351 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
358 modest_store_widget_get_path (ModestStoreWidget *self)
360 ModestStoreWidgetPrivate *priv;
362 g_return_val_if_fail (self, NULL);
363 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
365 if (GTK_IS_FILE_CHOOSER(priv->chooser))
366 return gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(priv->chooser));
372 get_value_from_combo (GtkWidget *combo)
379 chosen = gtk_combo_box_get_active_text (GTK_COMBO_BOX (combo));
381 return modest_protocol_info_get_transport_store_protocol (chosen);
386 modest_store_widget_get_auth (ModestStoreWidget *self)
388 ModestStoreWidgetPrivate *priv;
390 g_return_val_if_fail (self, MODEST_PROTOCOL_AUTH_NONE);
391 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
393 return get_value_from_combo (priv->auth);
396 ModestConnectionProtocol
397 modest_store_widget_get_security (ModestStoreWidget *self)
399 ModestStoreWidgetPrivate *priv;
401 g_return_val_if_fail (self, MODEST_PROTOCOL_CONNECTION_NORMAL);
402 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
404 return get_value_from_combo (priv->security);