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>
31 #include "modest-store-widget.h"
34 /* 'private'/'protected' functions */
35 static void modest_store_widget_class_init (ModestStoreWidgetClass *klass);
36 static void modest_store_widget_init (ModestStoreWidget *obj);
37 static void modest_store_widget_finalize (GObject *obj);
44 typedef struct _ModestStoreWidgetPrivate ModestStoreWidgetPrivate;
45 struct _ModestStoreWidgetPrivate {
49 GtkWidget *servername;
54 GtkWidget *remember_pwd;
56 ModestWidgetFactory *factory;
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);
126 maildir_configuration (ModestStoreWidget *self)
128 ModestStoreWidgetPrivate *priv;
129 GtkWidget *label, *box, *hbox;
131 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
132 box = gtk_vbox_new (FALSE, 6);
134 label = gtk_label_new (NULL);
135 gtk_label_set_markup (GTK_LABEL(label),
136 _("<b>Maildir configuration</b>"));
137 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 6);
138 label = gtk_label_new (NULL);
139 gtk_label_set_markup (GTK_LABEL(label),
140 _("Please select the path to your Maildir below"));
141 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 6);
143 label = gtk_label_new (_("Path:"));
146 gtk_file_chooser_button_new (_("(none)"),
147 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
149 hbox = gtk_hbox_new (FALSE, 6);
150 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 6);
151 gtk_box_pack_start (GTK_BOX(hbox), priv->chooser, FALSE, FALSE, 6);
153 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 6);
160 mbox_configuration (ModestStoreWidget *self)
162 ModestStoreWidgetPrivate *priv;
163 GtkWidget *label, *box, *hbox;
165 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
166 box = gtk_vbox_new (FALSE, 6);
168 label = gtk_label_new (NULL);
169 gtk_label_set_markup (GTK_LABEL(label),
170 _("<b>Mbox configuration</b>"));
171 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 6);
172 label = gtk_label_new (NULL);
173 gtk_label_set_markup (GTK_LABEL(label),
174 _("Please select your mbox file below"));
175 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 6);
177 label = gtk_label_new (_("mbox:"));
180 gtk_file_chooser_button_new (_("(none)"),
181 GTK_FILE_CHOOSER_ACTION_OPEN);
182 hbox = gtk_hbox_new (FALSE, 6);
183 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 6);
184 gtk_box_pack_start (GTK_BOX(hbox), priv->chooser, FALSE, FALSE, 6);
186 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 6);
192 on_entry_changed (GtkEntry *entry, gpointer user_data)
194 g_signal_emit (MODEST_STORE_WIDGET (user_data), signals[DATA_CHANGED_SIGNAL], 0);
198 imap_pop_configuration (ModestStoreWidget *self)
200 ModestStoreWidgetPrivate *priv;
201 GtkWidget *label, *box, *hbox;
203 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
204 box = gtk_vbox_new (FALSE, 6);
206 label = gtk_label_new (NULL);
207 gtk_label_set_markup (GTK_LABEL(label),_("<b>Server configuration</b>"));
208 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 6);
210 hbox = gtk_hbox_new (FALSE, 6);
211 label = gtk_label_new (_("Username:"));
213 priv->username = gtk_entry_new_with_max_length (40);
214 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
215 gtk_box_pack_start (GTK_BOX(hbox), priv->username,FALSE, FALSE, 6);
216 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 0);
218 hbox = gtk_hbox_new (FALSE, 6);
219 label = gtk_label_new (_("Server:"));
220 if (!priv->servername)
221 priv->servername = gtk_entry_new_with_max_length (40);
222 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
223 gtk_box_pack_start (GTK_BOX(hbox), priv->servername,FALSE, FALSE, 6);
224 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 0);
226 label = gtk_label_new(NULL);
227 gtk_label_set_markup (GTK_LABEL(label),_("<b>Security</b>"));
228 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 0);
230 priv->security = modest_widget_factory_get_combo_box (priv->factory,
231 MODEST_COMBO_BOX_TYPE_SECURITY_PROTOS);
232 hbox = gtk_hbox_new (FALSE, 6);
233 label = gtk_label_new(NULL);
234 gtk_label_set_text (GTK_LABEL(label),_("Connection type:"));
235 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
236 gtk_box_pack_start (GTK_BOX(hbox), priv->security, FALSE, FALSE,0);
237 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 0);
239 hbox = gtk_hbox_new (FALSE, 6);
240 label = gtk_label_new(NULL);
242 gtk_label_set_text (GTK_LABEL(label),_("Authentication:"));
243 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 6);
244 gtk_box_pack_start (GTK_BOX(hbox), modest_widget_factory_get_combo_box
245 (priv->factory, MODEST_COMBO_BOX_TYPE_AUTH_PROTOS),
249 gtk_check_button_new_with_label (_("Remember password"));
250 gtk_box_pack_start (GTK_BOX(hbox),priv->remember_pwd,
253 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 0);
255 /* Handle entry modifications */
256 g_signal_connect (priv->username, "changed", G_CALLBACK (on_entry_changed), self);
257 g_signal_connect (priv->servername, "changed", G_CALLBACK (on_entry_changed), self);
264 modest_store_widget_finalize (GObject *obj)
266 ModestStoreWidgetPrivate *priv;
267 priv = MODEST_STORE_WIDGET_GET_PRIVATE(obj);
270 g_object_unref (priv->factory);
271 priv->factory = NULL;
275 g_free (priv->proto);
279 G_OBJECT_CLASS(parent_class)->finalize (obj);
285 modest_store_widget_new (ModestWidgetFactory *factory, const gchar *proto)
289 ModestStoreWidget *self;
290 ModestStoreWidgetPrivate *priv;
292 g_return_val_if_fail (proto, NULL);
293 g_return_val_if_fail (factory, 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);
299 g_object_ref (factory);
300 priv->factory = factory;
302 priv->proto = g_strdup (proto);
304 if (strcmp (proto, MODEST_PROTOCOL_STORE_POP) == 0 ||
305 strcmp (proto, MODEST_PROTOCOL_STORE_IMAP) == 0) {
306 w = imap_pop_configuration (self);
307 } else if (strcmp (proto, MODEST_PROTOCOL_STORE_MAILDIR) == 0) {
308 w = maildir_configuration (self);
309 } else if (strcmp (proto, MODEST_PROTOCOL_STORE_MBOX) == 0) {
310 w = mbox_configuration (self);
312 w = gtk_label_new ("");
314 gtk_widget_show_all (w);
315 gtk_box_pack_start (GTK_BOX(self), w, FALSE, FALSE, 2);
317 return GTK_WIDGET(self);
321 modest_store_widget_get_remember_password (ModestStoreWidget *self)
323 ModestStoreWidgetPrivate *priv;
325 g_return_val_if_fail (self, FALSE);
326 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
328 return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(priv->remember_pwd));
333 modest_store_widget_get_username (ModestStoreWidget *self)
335 ModestStoreWidgetPrivate *priv;
337 g_return_val_if_fail (self, NULL);
338 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
340 return gtk_entry_get_text (GTK_ENTRY(priv->username));
344 modest_store_widget_get_servername (ModestStoreWidget *self)
346 ModestStoreWidgetPrivate *priv;
348 g_return_val_if_fail (self, NULL);
349 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
351 return gtk_entry_get_text (GTK_ENTRY(priv->servername));
356 modest_store_widget_get_proto (ModestStoreWidget *self)
358 ModestStoreWidgetPrivate *priv;
360 g_return_val_if_fail (self, NULL);
361 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);