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);
45 typedef struct _ModestStoreWidgetPrivate ModestStoreWidgetPrivate;
46 struct _ModestStoreWidgetPrivate {
50 GtkWidget *servername;
55 GtkWidget *remember_pwd;
57 ModestWidgetFactory *factory;
59 #define MODEST_STORE_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), \
60 MODEST_TYPE_STORE_WIDGET, \
61 ModestStoreWidgetPrivate))
63 static GtkContainerClass *parent_class = NULL;
65 /* uncomment the following if you have defined any signals */
66 /* static guint signals[LAST_SIGNAL] = {0}; */
69 modest_store_widget_get_type (void)
71 static GType my_type = 0;
73 static const GTypeInfo my_info = {
74 sizeof(ModestStoreWidgetClass),
76 NULL, /* base finalize */
77 (GClassInitFunc) modest_store_widget_class_init,
78 NULL, /* class finalize */
79 NULL, /* class data */
80 sizeof(ModestStoreWidget),
82 (GInstanceInitFunc) modest_store_widget_init,
85 my_type = g_type_register_static (GTK_TYPE_VBOX,
93 modest_store_widget_class_init (ModestStoreWidgetClass *klass)
95 GObjectClass *gobject_class;
96 gobject_class = (GObjectClass*) klass;
98 parent_class = g_type_class_peek_parent (klass);
99 gobject_class->finalize = modest_store_widget_finalize;
101 g_type_class_add_private (gobject_class, sizeof(ModestStoreWidgetPrivate));
103 /* signal definitions go here, e.g.: */
104 /* signals[MY_SIGNAL_1] = */
105 /* g_signal_new ("my_signal_1",....); */
106 /* signals[MY_SIGNAL_2] = */
107 /* g_signal_new ("my_signal_2",....); */
112 modest_store_widget_init (ModestStoreWidget *obj)
114 ModestStoreWidgetPrivate *priv;
116 priv = MODEST_STORE_WIDGET_GET_PRIVATE(obj);
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);
191 imap_pop_configuration (ModestStoreWidget *self)
193 ModestStoreWidgetPrivate *priv;
194 GtkWidget *label, *box, *hbox;
196 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
197 box = gtk_vbox_new (FALSE, 6);
199 label = gtk_label_new (NULL);
200 gtk_label_set_markup (GTK_LABEL(label),_("<b>Server configuration</b>"));
201 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 6);
203 hbox = gtk_hbox_new (FALSE, 6);
204 label = gtk_label_new (_("Username:"));
206 priv->username = gtk_entry_new_with_max_length (40);
207 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
208 gtk_box_pack_start (GTK_BOX(hbox), priv->username,FALSE, FALSE, 6);
209 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 0);
211 hbox = gtk_hbox_new (FALSE, 6);
212 label = gtk_label_new (_("Server:"));
213 if (!priv->servername)
214 priv->servername = 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->servername,FALSE, FALSE, 6);
217 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 0);
219 label = gtk_label_new(NULL);
220 gtk_label_set_markup (GTK_LABEL(label),_("<b>Security</b>"));
221 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 0);
223 hbox = gtk_hbox_new (FALSE, 6);
224 label = gtk_label_new(NULL);
225 gtk_label_set_text (GTK_LABEL(label),_("Connection type:"));
226 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
227 gtk_box_pack_start (GTK_BOX(hbox), modest_widget_factory_get_combo_box
228 (priv->factory, MODEST_COMBO_BOX_TYPE_SECURITY_PROTOS),
230 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 0);
232 hbox = gtk_hbox_new (FALSE, 6);
233 label = gtk_label_new(NULL);
235 gtk_label_set_text (GTK_LABEL(label),_("Authentication:"));
236 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 6);
237 gtk_box_pack_start (GTK_BOX(hbox), modest_widget_factory_get_combo_box
238 (priv->factory, MODEST_COMBO_BOX_TYPE_AUTH_PROTOS),
242 gtk_check_button_new_with_label (_("Remember password"));
243 gtk_box_pack_start (GTK_BOX(hbox),priv->remember_pwd,
246 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 0);
253 modest_store_widget_finalize (GObject *obj)
255 ModestStoreWidgetPrivate *priv;
256 priv = MODEST_STORE_WIDGET_GET_PRIVATE(obj);
259 g_object_unref (priv->factory);
260 priv->factory = NULL;
264 g_free (priv->proto);
268 G_OBJECT_CLASS(parent_class)->finalize (obj);
274 modest_store_widget_new (ModestWidgetFactory *factory, const gchar *proto)
278 ModestStoreWidget *self;
279 ModestStoreWidgetPrivate *priv;
281 g_return_val_if_fail (proto, NULL);
282 g_return_val_if_fail (factory, NULL);
284 obj = g_object_new(MODEST_TYPE_STORE_WIDGET, NULL);
285 self = MODEST_STORE_WIDGET(obj);
286 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
288 g_object_ref (factory);
289 priv->factory = factory;
291 priv->proto = g_strdup (proto);
293 if (strcmp (proto, MODEST_PROTOCOL_STORE_POP) == 0 ||
294 strcmp (proto, MODEST_PROTOCOL_STORE_IMAP) == 0) {
295 w = imap_pop_configuration (self);
296 } else if (strcmp (proto, MODEST_PROTOCOL_STORE_MAILDIR) == 0) {
297 w = maildir_configuration (self);
298 } else if (strcmp (proto, MODEST_PROTOCOL_STORE_MBOX) == 0) {
299 w = mbox_configuration (self);
301 w = gtk_label_new ("");
303 gtk_widget_show_all (w);
304 gtk_box_pack_start (GTK_BOX(self), w, FALSE, FALSE, 2);
306 return GTK_WIDGET(self);
311 modest_store_widget_get_remember_password (ModestStoreWidget *self)
313 ModestStoreWidgetPrivate *priv;
315 g_return_val_if_fail (self, FALSE);
316 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
318 return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(priv->remember_pwd));
323 modest_store_widget_get_username (ModestStoreWidget *self)
325 ModestStoreWidgetPrivate *priv;
327 g_return_val_if_fail (self, NULL);
328 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
330 return gtk_entry_get_text (GTK_ENTRY(priv->username));
334 modest_store_widget_get_servername (ModestStoreWidget *self)
336 ModestStoreWidgetPrivate *priv;
338 g_return_val_if_fail (self, NULL);
339 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
341 return gtk_entry_get_text (GTK_ENTRY(priv->servername));
346 modest_store_widget_get_proto (ModestStoreWidget *self)
348 ModestStoreWidgetPrivate *priv;
350 g_return_val_if_fail (self, FALSE);
351 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);