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;
55 ModestTransportStoreProtocol proto;
57 #define MODEST_STORE_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
58 MODEST_TYPE_STORE_WIDGET, \
59 ModestStoreWidgetPrivate))
61 static GtkContainerClass *parent_class = NULL;
63 /* uncomment the following if you have defined any signals */
64 static guint signals[LAST_SIGNAL] = {0};
67 modest_store_widget_get_type (void)
69 static GType my_type = 0;
71 static const GTypeInfo my_info = {
72 sizeof(ModestStoreWidgetClass),
74 NULL, /* base finalize */
75 (GClassInitFunc) modest_store_widget_class_init,
76 NULL, /* class finalize */
77 NULL, /* class data */
78 sizeof(ModestStoreWidget),
80 (GInstanceInitFunc) modest_store_widget_init,
83 my_type = g_type_register_static (GTK_TYPE_VBOX,
91 modest_store_widget_class_init (ModestStoreWidgetClass *klass)
93 GObjectClass *gobject_class;
94 gobject_class = (GObjectClass*) klass;
96 parent_class = g_type_class_peek_parent (klass);
97 gobject_class->finalize = modest_store_widget_finalize;
99 g_type_class_add_private (gobject_class, sizeof(ModestStoreWidgetPrivate));
101 /* signal definitions go here, e.g.: */
102 signals[DATA_CHANGED_SIGNAL] =
103 g_signal_new ("data_changed",
104 G_TYPE_FROM_CLASS (klass),
106 G_STRUCT_OFFSET(ModestStoreWidgetClass, data_changed),
108 g_cclosure_marshal_VOID__VOID,
113 modest_store_widget_init (ModestStoreWidget *obj)
115 ModestStoreWidgetPrivate *priv;
117 priv = MODEST_STORE_WIDGET_GET_PRIVATE(obj);
118 priv->proto = MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN;
124 maildir_configuration (ModestStoreWidget *self)
126 ModestStoreWidgetPrivate *priv;
127 GtkWidget *label, *box, *hbox;
129 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
130 box = gtk_vbox_new (FALSE, 6);
132 label = gtk_label_new (NULL);
133 gtk_label_set_markup (GTK_LABEL(label),
134 _("<b>Maildir configuration</b>"));
135 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 6);
136 label = gtk_label_new (NULL);
137 gtk_label_set_markup (GTK_LABEL(label),
138 _("Please select the path to your Maildir below"));
139 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 6);
141 label = gtk_label_new (_("Path:"));
144 gtk_file_chooser_button_new (_("(none)"),
145 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
147 hbox = gtk_hbox_new (FALSE, 6);
148 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 6);
149 gtk_box_pack_start (GTK_BOX(hbox), priv->chooser, FALSE, FALSE, 6);
151 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 6);
158 mbox_configuration (ModestStoreWidget *self)
160 ModestStoreWidgetPrivate *priv;
161 GtkWidget *label, *box, *hbox;
163 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
164 box = gtk_vbox_new (FALSE, 6);
166 label = gtk_label_new (NULL);
167 gtk_label_set_markup (GTK_LABEL(label),
168 _("<b>Mbox configuration</b>"));
169 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 6);
170 label = gtk_label_new (NULL);
171 gtk_label_set_markup (GTK_LABEL(label),
172 _("Please select your mbox file below"));
173 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 6);
175 label = gtk_label_new (_("mbox:"));
178 gtk_file_chooser_button_new (_("(none)"),
179 GTK_FILE_CHOOSER_ACTION_OPEN);
180 hbox = gtk_hbox_new (FALSE, 6);
181 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 6);
182 gtk_box_pack_start (GTK_BOX(hbox), priv->chooser, FALSE, FALSE, 6);
184 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 6);
190 on_entry_changed (GtkEntry *entry, gpointer user_data)
192 g_signal_emit (MODEST_STORE_WIDGET (user_data), signals[DATA_CHANGED_SIGNAL], 0);
196 imap_pop_configuration (ModestStoreWidget *self)
198 ModestPairList *protos;
199 ModestStoreWidgetPrivate *priv;
200 GtkWidget *label, *box, *hbox;
202 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
203 box = gtk_vbox_new (FALSE, 6);
205 label = gtk_label_new (NULL);
206 gtk_label_set_markup (GTK_LABEL(label),_("<b>Server configuration</b>"));
207 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 6);
209 hbox = gtk_hbox_new (FALSE, 6);
210 label = gtk_label_new (_("Username:"));
212 priv->username = gtk_entry_new_with_max_length (40);
213 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
214 gtk_box_pack_start (GTK_BOX(hbox), priv->username,FALSE, FALSE, 6);
215 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 0);
217 hbox = gtk_hbox_new (FALSE, 6);
218 label = gtk_label_new (_("Server:"));
219 if (!priv->servername)
220 priv->servername = gtk_entry_new_with_max_length (40);
221 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
222 gtk_box_pack_start (GTK_BOX(hbox), priv->servername,FALSE, FALSE, 6);
223 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 0);
225 label = gtk_label_new(NULL);
226 gtk_label_set_markup (GTK_LABEL(label),_("<b>Security</b>"));
227 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 0);
229 protos = modest_protocol_info_get_connection_protocol_pair_list ();
230 priv->security = modest_combo_box_new (protos, g_str_equal);
231 modest_pair_list_free (protos);
233 hbox = gtk_hbox_new (FALSE, 6);
234 label = gtk_label_new(NULL);
235 gtk_label_set_text (GTK_LABEL(label),_("Connection type:"));
236 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
237 gtk_box_pack_start (GTK_BOX(hbox), priv->security, FALSE, FALSE,0);
238 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 0);
240 hbox = gtk_hbox_new (FALSE, 6);
241 label = gtk_label_new(NULL);
243 gtk_label_set_text (GTK_LABEL(label),_("Authentication:"));
244 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 6);
246 protos = modest_protocol_info_get_auth_protocol_pair_list (;
247 priv->auth = modest_combo_box_new (protos, g_str_equal);
248 modest_pair_list_free (protos);
250 gtk_box_pack_start (GTK_BOX(hbox), priv->auth, FALSE, FALSE, 0);
252 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 0);
254 /* Handle entry modifications */
255 g_signal_connect (priv->username, "changed", G_CALLBACK (on_entry_changed), self);
256 g_signal_connect (priv->servername, "changed", G_CALLBACK (on_entry_changed), self);
263 modest_store_widget_finalize (GObject *obj)
265 G_OBJECT_CLASS(parent_class)->finalize (obj);
271 modest_store_widget_new (ModestTransportStoreProtocol proto)
275 ModestStoreWidget *self;
276 ModestStoreWidgetPrivate *priv;
278 g_return_val_if_fail (proto, NULL);
280 obj = g_object_new(MODEST_TYPE_STORE_WIDGET, NULL);
281 self = MODEST_STORE_WIDGET(obj);
282 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
286 if (proto == MODEST_PROTOCOL_STORE_POP || proto == MODEST_PROTOCOL_STORE_IMAP)
287 w = imap_pop_configuration (self);
288 else if (proto == MODEST_PROTOCOL_STORE_MAILDIR)
289 w = maildir_configuration (self);
290 else if (proto == MODEST_PROTOCOL_STORE_MBOX)
291 w = mbox_configuration (self);
293 w = gtk_label_new ("");
295 gtk_widget_show_all (w);
296 gtk_box_pack_start (GTK_BOX(self), w, FALSE, FALSE, 2);
298 return GTK_WIDGET(self);
302 modest_store_widget_get_username (ModestStoreWidget *self)
304 ModestStoreWidgetPrivate *priv;
306 g_return_val_if_fail (self, NULL);
307 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
309 if (GTK_IS_ENTRY(priv->username))
310 return gtk_entry_get_text (GTK_ENTRY(priv->username));
316 modest_store_widget_get_servername (ModestStoreWidget *self)
318 ModestStoreWidgetPrivate *priv;
320 g_return_val_if_fail (self, NULL);
321 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
323 if (GTK_IS_ENTRY(priv->servername))
324 return gtk_entry_get_text (GTK_ENTRY(priv->servername));
330 ModestTransportStoreProtocol
331 modest_store_widget_get_proto (ModestStoreWidget *self)
333 ModestStoreWidgetPrivate *priv;
335 g_return_val_if_fail (self, MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN);
336 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
343 modest_store_widget_get_path (ModestStoreWidget *self)
345 ModestStoreWidgetPrivate *priv;
347 g_return_val_if_fail (self, NULL);
348 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
350 if (GTK_IS_FILE_CHOOSER(priv->chooser))
351 return gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(priv->chooser));
357 get_value_from_combo (GtkWidget *combo)
364 chosen = gtk_combo_box_get_active_text (GTK_COMBO_BOX (combo));
366 return modest_protocol_info_get_transport_store_protocol (chosen);
371 modest_store_widget_get_auth (ModestStoreWidget *self)
373 ModestStoreWidgetPrivate *priv;
375 g_return_val_if_fail (self, MODEST_PROTOCOL_AUTH_NONE);
376 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
378 return get_value_from_combo (priv->auth);
381 ModestConnectionProtocol
382 modest_store_widget_get_security (ModestStoreWidget *self)
384 ModestStoreWidgetPrivate *priv;
386 g_return_val_if_fail (self, MODEST_PROTOCOL_CONNECTION_NORMAL);
387 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
389 return get_value_from_combo (priv->security);