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"
34 #include "modest-runtime.h"
37 /* 'private'/'protected' functions */
38 static void modest_store_widget_class_init (ModestStoreWidgetClass *klass);
39 static void modest_store_widget_init (ModestStoreWidget *obj);
40 static void modest_store_widget_finalize (GObject *obj);
47 typedef struct _ModestStoreWidgetPrivate ModestStoreWidgetPrivate;
48 struct _ModestStoreWidgetPrivate {
50 GtkWidget *servername;
53 ModestPairList *security_protos;
56 ModestPairList *auth_protos;
61 ModestProtocolType proto;
63 #define MODEST_STORE_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
64 MODEST_TYPE_STORE_WIDGET, \
65 ModestStoreWidgetPrivate))
67 static GtkContainerClass *parent_class = NULL;
69 /* uncomment the following if you have defined any signals */
70 static guint signals[LAST_SIGNAL] = {0};
73 modest_store_widget_get_type (void)
75 static GType my_type = 0;
77 static const GTypeInfo my_info = {
78 sizeof(ModestStoreWidgetClass),
80 NULL, /* base finalize */
81 (GClassInitFunc) modest_store_widget_class_init,
82 NULL, /* class finalize */
83 NULL, /* class data */
84 sizeof(ModestStoreWidget),
86 (GInstanceInitFunc) modest_store_widget_init,
89 my_type = g_type_register_static (GTK_TYPE_VBOX,
97 modest_store_widget_class_init (ModestStoreWidgetClass *klass)
99 GObjectClass *gobject_class;
100 gobject_class = (GObjectClass*) klass;
102 parent_class = g_type_class_peek_parent (klass);
103 gobject_class->finalize = modest_store_widget_finalize;
105 g_type_class_add_private (gobject_class, sizeof(ModestStoreWidgetPrivate));
107 /* signal definitions go here, e.g.: */
108 signals[DATA_CHANGED_SIGNAL] =
109 g_signal_new ("data_changed",
110 G_TYPE_FROM_CLASS (klass),
112 G_STRUCT_OFFSET(ModestStoreWidgetClass, data_changed),
114 g_cclosure_marshal_VOID__VOID,
119 modest_store_widget_init (ModestStoreWidget *obj)
121 ModestStoreWidgetPrivate *priv;
123 priv = MODEST_STORE_WIDGET_GET_PRIVATE(obj);
124 priv->proto = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
130 maildir_configuration (ModestStoreWidget *self)
132 ModestStoreWidgetPrivate *priv;
133 GtkWidget *label, *box, *hbox;
135 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
136 box = gtk_vbox_new (FALSE, 6);
138 label = gtk_label_new (NULL);
139 gtk_label_set_markup (GTK_LABEL(label),
140 _("<b>Maildir configuration</b>"));
141 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 6);
142 label = gtk_label_new (NULL);
143 gtk_label_set_markup (GTK_LABEL(label),
144 _("Please select the path to your Maildir below"));
145 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 6);
147 label = gtk_label_new (_("Path:"));
150 gtk_file_chooser_button_new (_("(none)"),
151 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
153 hbox = gtk_hbox_new (FALSE, 6);
154 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 6);
155 gtk_box_pack_start (GTK_BOX(hbox), priv->chooser, FALSE, FALSE, 6);
157 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 6);
164 mbox_configuration (ModestStoreWidget *self)
166 ModestStoreWidgetPrivate *priv;
167 GtkWidget *label, *box, *hbox;
169 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
170 box = gtk_vbox_new (FALSE, 6);
172 label = gtk_label_new (NULL);
173 gtk_label_set_markup (GTK_LABEL(label),
174 _("<b>Mbox configuration</b>"));
175 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 6);
176 label = gtk_label_new (NULL);
177 gtk_label_set_markup (GTK_LABEL(label),
178 _("Please select your mbox file below"));
179 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 6);
181 label = gtk_label_new (_("mbox:"));
184 gtk_file_chooser_button_new (_("(none)"),
185 GTK_FILE_CHOOSER_ACTION_OPEN);
186 hbox = gtk_hbox_new (FALSE, 6);
187 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 6);
188 gtk_box_pack_start (GTK_BOX(hbox), priv->chooser, FALSE, FALSE, 6);
190 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 6);
196 on_entry_changed (GtkEntry *entry, gpointer user_data)
198 g_signal_emit (MODEST_STORE_WIDGET (user_data), signals[DATA_CHANGED_SIGNAL], 0);
202 imap_pop_configuration (ModestStoreWidget *self)
204 ModestStoreWidgetPrivate *priv;
205 GtkWidget *label, *box, *hbox;
207 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
208 box = gtk_vbox_new (FALSE, 6);
210 label = gtk_label_new (NULL);
211 gtk_label_set_markup (GTK_LABEL(label),_("<b>Server configuration</b>"));
212 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 6);
214 hbox = gtk_hbox_new (FALSE, 6);
215 label = gtk_label_new (_("Username:"));
217 priv->username = gtk_entry_new_with_max_length (40);
218 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
219 gtk_box_pack_start (GTK_BOX(hbox), priv->username,FALSE, FALSE, 6);
220 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 0);
222 hbox = gtk_hbox_new (FALSE, 6);
223 label = gtk_label_new (_("Server:"));
224 if (!priv->servername)
225 priv->servername = gtk_entry_new_with_max_length (40);
226 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
227 gtk_box_pack_start (GTK_BOX(hbox), priv->servername,FALSE, FALSE, 6);
228 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 0);
230 label = gtk_label_new(NULL);
231 gtk_label_set_markup (GTK_LABEL(label),_("<b>Security</b>"));
232 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 0);
234 /* Note: This ModestPairList* must exist for as long as the combo
235 * that uses it, because the ModestComboBox uses the ID opaquely,
236 * so it can't know how to manage its memory. */
237 priv->security_protos = modest_protocol_info_get_connection_protocol_pair_list ();
239 priv->security = modest_combo_box_new (priv->security_protos, g_str_equal);
241 hbox = gtk_hbox_new (FALSE, 6);
242 label = gtk_label_new(NULL);
243 gtk_label_set_text (GTK_LABEL(label),_("Connection type:"));
244 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
245 gtk_box_pack_start (GTK_BOX(hbox), priv->security, FALSE, FALSE,0);
246 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 0);
248 hbox = gtk_hbox_new (FALSE, 6);
249 label = gtk_label_new(NULL);
251 gtk_label_set_text (GTK_LABEL(label),_("Authentication:"));
252 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 6);
254 /* Note: This ModestPairList* must exist for as long as the combo
255 * that uses it, because the ModestComboBox uses the ID opaquely,
256 * so it can't know how to manage its memory. */
257 priv->auth_protos = modest_protocol_info_get_auth_protocol_pair_list ();
258 priv->auth = modest_combo_box_new (priv->auth_protos, g_str_equal);
260 gtk_box_pack_start (GTK_BOX(hbox), priv->auth, FALSE, FALSE, 0);
262 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 0);
264 /* Handle entry modifications */
265 g_signal_connect (priv->username, "changed", G_CALLBACK (on_entry_changed), self);
266 g_signal_connect (priv->servername, "changed", G_CALLBACK (on_entry_changed), self);
273 modest_store_widget_finalize (GObject *obj)
275 ModestStoreWidgetPrivate *priv = MODEST_STORE_WIDGET_GET_PRIVATE(obj);
277 /* These had to stay alive for as long as the comboboxes that used them: */
278 modest_pair_list_free (priv->security_protos);
279 modest_pair_list_free (priv->auth_protos);
281 G_OBJECT_CLASS(parent_class)->finalize (obj);
287 modest_store_widget_new (ModestProtocolType proto)
291 ModestStoreWidget *self;
292 ModestStoreWidgetPrivate *priv;
294 g_return_val_if_fail (proto, NULL);
296 obj = g_object_new(MODEST_TYPE_STORE_WIDGET, NULL);
297 self = MODEST_STORE_WIDGET(obj);
298 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
302 if (proto == MODEST_PROTOCOLS_STORE_POP || proto == MODEST_PROTOCOLS_STORE_IMAP)
303 w = imap_pop_configuration (self);
304 else if (proto == MODEST_PROTOCOLS_STORE_MAILDIR)
305 w = maildir_configuration (self);
306 else if (proto == MODEST_PROTOCOLS_STORE_MBOX)
307 w = mbox_configuration (self);
309 w = gtk_label_new ("");
311 gtk_widget_show_all (w);
312 gtk_box_pack_start (GTK_BOX(self), w, FALSE, FALSE, 2);
314 return GTK_WIDGET(self);
318 modest_store_widget_get_username (ModestStoreWidget *self)
320 ModestStoreWidgetPrivate *priv;
322 g_return_val_if_fail (self, NULL);
323 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
325 if (GTK_IS_ENTRY(priv->username))
326 return gtk_entry_get_text (GTK_ENTRY(priv->username));
332 modest_store_widget_get_servername (ModestStoreWidget *self)
334 ModestStoreWidgetPrivate *priv;
336 g_return_val_if_fail (self, NULL);
337 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
339 if (GTK_IS_ENTRY(priv->servername))
340 return gtk_entry_get_text (GTK_ENTRY(priv->servername));
347 modest_store_widget_get_proto (ModestStoreWidget *self)
349 ModestStoreWidgetPrivate *priv;
351 g_return_val_if_fail (self, MODEST_PROTOCOL_REGISTRY_TYPE_INVALID);
352 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
359 modest_store_widget_get_path (ModestStoreWidget *self)
361 ModestStoreWidgetPrivate *priv;
363 g_return_val_if_fail (self, NULL);
364 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
366 if (GTK_IS_FILE_CHOOSER(priv->chooser))
367 return gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(priv->chooser));
372 static ModestProtocolType
373 get_value_from_combo (GtkWidget *combo)
376 ModestProtocol *proto;
379 g_return_val_if_fail (combo, MODEST_PROTOCOL_REGISTRY_TYPE_INVALID);
381 chosen = gtk_combo_box_get_active_text (GTK_COMBO_BOX (combo));
382 tag = MODEST_PROTOCOL_REGISTRY_TRANSPORT_STORE_PROTOCOLS;
383 proto = modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (),
387 return modest_protocol_get_type_id (proto);
392 modest_store_widget_get_auth (ModestStoreWidget *self)
394 ModestStoreWidgetPrivate *priv;
396 g_return_val_if_fail (self, MODEST_PROTOCOLS_AUTH_NONE);
397 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
399 return get_value_from_combo (priv->auth);
403 modest_store_widget_get_security (ModestStoreWidget *self)
405 ModestStoreWidgetPrivate *priv;
407 g_return_val_if_fail (self, MODEST_PROTOCOLS_CONNECTION_NONE);
408 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
410 return get_value_from_combo (priv->security);