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;
54 GtkWidget *remember_pwd;
58 #define MODEST_STORE_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
59 MODEST_TYPE_STORE_WIDGET, \
60 ModestStoreWidgetPrivate))
62 static GtkContainerClass *parent_class = NULL;
64 /* uncomment the following if you have defined any signals */
65 static guint signals[LAST_SIGNAL] = {0};
68 modest_store_widget_get_type (void)
70 static GType my_type = 0;
72 static const GTypeInfo my_info = {
73 sizeof(ModestStoreWidgetClass),
75 NULL, /* base finalize */
76 (GClassInitFunc) modest_store_widget_class_init,
77 NULL, /* class finalize */
78 NULL, /* class data */
79 sizeof(ModestStoreWidget),
81 (GInstanceInitFunc) modest_store_widget_init,
84 my_type = g_type_register_static (GTK_TYPE_VBOX,
92 modest_store_widget_class_init (ModestStoreWidgetClass *klass)
94 GObjectClass *gobject_class;
95 gobject_class = (GObjectClass*) klass;
97 parent_class = g_type_class_peek_parent (klass);
98 gobject_class->finalize = modest_store_widget_finalize;
100 g_type_class_add_private (gobject_class, sizeof(ModestStoreWidgetPrivate));
102 /* signal definitions go here, e.g.: */
103 signals[DATA_CHANGED_SIGNAL] =
104 g_signal_new ("data_changed",
105 G_TYPE_FROM_CLASS (klass),
107 G_STRUCT_OFFSET(ModestStoreWidgetClass, data_changed),
109 g_cclosure_marshal_VOID__VOID,
114 modest_store_widget_init (ModestStoreWidget *obj)
116 ModestStoreWidgetPrivate *priv;
118 priv = MODEST_STORE_WIDGET_GET_PRIVATE(obj);
119 priv->proto = MODEST_PROTOCOL_UNKNOWN;
125 maildir_configuration (ModestStoreWidget *self)
127 ModestStoreWidgetPrivate *priv;
128 GtkWidget *label, *box, *hbox;
130 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
131 box = gtk_vbox_new (FALSE, 6);
133 label = gtk_label_new (NULL);
134 gtk_label_set_markup (GTK_LABEL(label),
135 _("<b>Maildir configuration</b>"));
136 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 6);
137 label = gtk_label_new (NULL);
138 gtk_label_set_markup (GTK_LABEL(label),
139 _("Please select the path to your Maildir below"));
140 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 6);
142 label = gtk_label_new (_("Path:"));
145 gtk_file_chooser_button_new (_("(none)"),
146 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
148 hbox = gtk_hbox_new (FALSE, 6);
149 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 6);
150 gtk_box_pack_start (GTK_BOX(hbox), priv->chooser, FALSE, FALSE, 6);
152 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 6);
159 mbox_configuration (ModestStoreWidget *self)
161 ModestStoreWidgetPrivate *priv;
162 GtkWidget *label, *box, *hbox;
164 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
165 box = gtk_vbox_new (FALSE, 6);
167 label = gtk_label_new (NULL);
168 gtk_label_set_markup (GTK_LABEL(label),
169 _("<b>Mbox configuration</b>"));
170 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 6);
171 label = gtk_label_new (NULL);
172 gtk_label_set_markup (GTK_LABEL(label),
173 _("Please select your mbox file below"));
174 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 6);
176 label = gtk_label_new (_("mbox:"));
179 gtk_file_chooser_button_new (_("(none)"),
180 GTK_FILE_CHOOSER_ACTION_OPEN);
181 hbox = gtk_hbox_new (FALSE, 6);
182 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 6);
183 gtk_box_pack_start (GTK_BOX(hbox), priv->chooser, FALSE, FALSE, 6);
185 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 6);
191 on_entry_changed (GtkEntry *entry, gpointer user_data)
193 g_signal_emit (MODEST_STORE_WIDGET (user_data), signals[DATA_CHANGED_SIGNAL], 0);
197 imap_pop_configuration (ModestStoreWidget *self)
199 ModestPairList *protos;
200 ModestStoreWidgetPrivate *priv;
201 GtkWidget *label, *box, *hbox;
204 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
205 box = gtk_vbox_new (FALSE, 6);
207 label = gtk_label_new (NULL);
208 gtk_label_set_markup (GTK_LABEL(label),_("<b>Server configuration</b>"));
209 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 6);
211 hbox = gtk_hbox_new (FALSE, 6);
212 label = gtk_label_new (_("Username:"));
214 priv->username = gtk_entry_new_with_max_length (40);
215 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
216 gtk_box_pack_start (GTK_BOX(hbox), priv->username,FALSE, FALSE, 6);
217 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 0);
219 hbox = gtk_hbox_new (FALSE, 6);
220 label = gtk_label_new (_("Server:"));
221 if (!priv->servername)
222 priv->servername = gtk_entry_new_with_max_length (40);
223 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
224 gtk_box_pack_start (GTK_BOX(hbox), priv->servername,FALSE, FALSE, 6);
225 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 0);
227 label = gtk_label_new(NULL);
228 gtk_label_set_markup (GTK_LABEL(label),_("<b>Security</b>"));
229 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 0);
231 protos = modest_protocol_info_get_protocol_pair_list (MODEST_PROTOCOL_TYPE_SECURITY);
232 priv->security = modest_combo_box_new (protos, g_str_equal);
233 modest_pair_list_free (protos);
235 hbox = gtk_hbox_new (FALSE, 6);
236 label = gtk_label_new(NULL);
237 gtk_label_set_text (GTK_LABEL(label),_("Connection type:"));
238 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
239 gtk_box_pack_start (GTK_BOX(hbox), priv->security, FALSE, FALSE,0);
240 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 0);
242 hbox = gtk_hbox_new (FALSE, 6);
243 label = gtk_label_new(NULL);
245 gtk_label_set_text (GTK_LABEL(label),_("Authentication:"));
246 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 6);
248 protos = modest_protocol_info_get_protocol_pair_list (MODEST_PROTOCOL_TYPE_AUTH);
249 combo = modest_combo_box_new (protos, g_str_equal);
250 modest_pair_list_free (protos);
252 gtk_box_pack_start (GTK_BOX(hbox), combo, FALSE, FALSE, 0);
254 gtk_check_button_new_with_label (_("Remember password"));
255 gtk_box_pack_start (GTK_BOX(hbox),priv->remember_pwd,
258 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 0);
260 /* Handle entry modifications */
261 g_signal_connect (priv->username, "changed", G_CALLBACK (on_entry_changed), self);
262 g_signal_connect (priv->servername, "changed", G_CALLBACK (on_entry_changed), self);
269 modest_store_widget_finalize (GObject *obj)
271 G_OBJECT_CLASS(parent_class)->finalize (obj);
277 modest_store_widget_new (ModestProtocol proto)
281 ModestStoreWidget *self;
282 ModestStoreWidgetPrivate *priv;
284 g_return_val_if_fail (proto, NULL);
286 obj = g_object_new(MODEST_TYPE_STORE_WIDGET, NULL);
287 self = MODEST_STORE_WIDGET(obj);
288 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
292 if (proto == MODEST_PROTOCOL_STORE_POP || proto == MODEST_PROTOCOL_STORE_IMAP)
293 w = imap_pop_configuration (self);
294 else if (proto == MODEST_PROTOCOL_STORE_MAILDIR)
295 w = maildir_configuration (self);
296 else if (proto == MODEST_PROTOCOL_STORE_MBOX)
297 w = mbox_configuration (self);
299 w = gtk_label_new ("");
301 gtk_widget_show_all (w);
302 gtk_box_pack_start (GTK_BOX(self), w, FALSE, FALSE, 2);
304 return GTK_WIDGET(self);
308 modest_store_widget_get_remember_password (ModestStoreWidget *self)
310 ModestStoreWidgetPrivate *priv;
312 g_return_val_if_fail (self, FALSE);
313 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
315 if (GTK_IS_TOGGLE_BUTTON(priv->remember_pwd))
316 return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(priv->remember_pwd));
322 modest_store_widget_get_username (ModestStoreWidget *self)
324 ModestStoreWidgetPrivate *priv;
326 g_return_val_if_fail (self, NULL);
327 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
329 if (GTK_IS_ENTRY(priv->username))
330 return gtk_entry_get_text (GTK_ENTRY(priv->username));
336 modest_store_widget_get_servername (ModestStoreWidget *self)
338 ModestStoreWidgetPrivate *priv;
340 g_return_val_if_fail (self, NULL);
341 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
343 if (GTK_IS_ENTRY(priv->servername))
344 return gtk_entry_get_text (GTK_ENTRY(priv->servername));
351 modest_store_widget_get_proto (ModestStoreWidget *self)
353 ModestStoreWidgetPrivate *priv;
355 g_return_val_if_fail (self, MODEST_PROTOCOL_UNKNOWN);
356 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
363 modest_store_widget_get_path (ModestStoreWidget *self)
365 ModestStoreWidgetPrivate *priv;
367 g_return_val_if_fail (self, MODEST_PROTOCOL_UNKNOWN);
368 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
370 if (GTK_IS_FILE_CHOOSER(priv->chooser))
371 return gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(priv->chooser));