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 "modest-store-widget.h"
33 /* 'private'/'protected' functions */
34 static void modest_store_widget_class_init (ModestStoreWidgetClass *klass);
35 static void modest_store_widget_init (ModestStoreWidget *obj);
36 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[MY_SIGNAL_1] = */
104 /* g_signal_new ("my_signal_1",....); */
105 /* signals[MY_SIGNAL_2] = */
106 /* g_signal_new ("my_signal_2",....); */
111 modest_store_widget_init (ModestStoreWidget *obj)
113 ModestStoreWidgetPrivate *priv;
115 priv = MODEST_STORE_WIDGET_GET_PRIVATE(obj);
123 maildir_configuration (ModestStoreWidget *self)
125 ModestStoreWidgetPrivate *priv;
126 GtkWidget *label, *box, *hbox;
128 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
129 box = gtk_vbox_new (FALSE, 6);
131 label = gtk_label_new (NULL);
132 gtk_label_set_markup (GTK_LABEL(label),
133 _("<b>Maildir configuration</b>"));
134 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 6);
135 label = gtk_label_new (NULL);
136 gtk_label_set_markup (GTK_LABEL(label),
137 _("Please select the path to your Maildir below"));
138 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 6);
140 label = gtk_label_new (_("Path:"));
143 gtk_file_chooser_button_new (_("(none)"),
144 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
146 hbox = gtk_hbox_new (FALSE, 6);
147 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 6);
148 gtk_box_pack_start (GTK_BOX(hbox), priv->chooser, FALSE, FALSE, 6);
150 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 6);
157 mbox_configuration (ModestStoreWidget *self)
159 ModestStoreWidgetPrivate *priv;
160 GtkWidget *label, *box, *hbox;
162 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
163 box = gtk_vbox_new (FALSE, 6);
165 label = gtk_label_new (NULL);
166 gtk_label_set_markup (GTK_LABEL(label),
167 _("<b>Mbox configuration</b>"));
168 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 6);
169 label = gtk_label_new (NULL);
170 gtk_label_set_markup (GTK_LABEL(label),
171 _("Please select your mbox file below"));
172 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 6);
174 label = gtk_label_new (_("mbox:"));
177 gtk_file_chooser_button_new (_("(none)"),
178 GTK_FILE_CHOOSER_ACTION_OPEN);
179 hbox = gtk_hbox_new (FALSE, 6);
180 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 6);
181 gtk_box_pack_start (GTK_BOX(hbox), priv->chooser, FALSE, FALSE, 6);
183 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 6);
190 imap_pop_configuration (ModestStoreWidget *self)
192 ModestStoreWidgetPrivate *priv;
193 GtkWidget *label, *box, *hbox;
195 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
196 box = gtk_vbox_new (FALSE, 6);
198 label = gtk_label_new (NULL);
199 gtk_label_set_markup (GTK_LABEL(label),_("<b>Server configuration</b>"));
200 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 6);
202 hbox = gtk_hbox_new (FALSE, 6);
203 label = gtk_label_new (_("Username:"));
205 priv->username = gtk_entry_new_with_max_length (40);
206 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
207 gtk_box_pack_start (GTK_BOX(hbox), priv->username,FALSE, FALSE, 6);
208 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 0);
210 hbox = gtk_hbox_new (FALSE, 6);
211 label = gtk_label_new (_("Server:"));
212 if (!priv->servername)
213 priv->servername = 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->servername,FALSE, FALSE, 6);
216 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 0);
218 label = gtk_label_new(NULL);
219 gtk_label_set_markup (GTK_LABEL(label),_("<b>Security</b>"));
220 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 0);
222 hbox = gtk_hbox_new (FALSE, 6);
223 label = gtk_label_new(NULL);
224 gtk_label_set_text (GTK_LABEL(label),_("Connection type:"));
225 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
226 gtk_box_pack_start (GTK_BOX(hbox), modest_widget_factory_get_combo_box
227 (priv->factory, MODEST_COMBO_BOX_TYPE_SECURITY_PROTOS),
229 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 0);
231 hbox = gtk_hbox_new (FALSE, 6);
232 label = gtk_label_new(NULL);
234 gtk_label_set_text (GTK_LABEL(label),_("Authentication:"));
235 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 6);
236 gtk_box_pack_start (GTK_BOX(hbox), modest_widget_factory_get_combo_box
237 (priv->factory, MODEST_COMBO_BOX_TYPE_AUTH_PROTOS),
241 gtk_check_button_new_with_label (_("Remember password"));
242 gtk_box_pack_start (GTK_BOX(hbox),priv->remember_pwd,
245 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 0);
252 modest_store_widget_finalize (GObject *obj)
254 ModestStoreWidgetPrivate *priv;
255 priv = MODEST_STORE_WIDGET_GET_PRIVATE(obj);
258 g_object_unref (priv->factory);
259 priv->factory = NULL;
263 g_free (priv->proto);
267 G_OBJECT_CLASS(parent_class)->finalize (obj);
273 modest_store_widget_new (ModestWidgetFactory *factory, const gchar *proto)
277 ModestStoreWidget *self;
278 ModestStoreWidgetPrivate *priv;
280 g_return_val_if_fail (proto, NULL);
281 g_return_val_if_fail (factory, NULL);
283 obj = g_object_new(MODEST_TYPE_STORE_WIDGET, NULL);
284 self = MODEST_STORE_WIDGET(obj);
285 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
287 g_object_ref (factory);
288 priv->factory = factory;
290 priv->proto = g_strdup (proto);
292 if (strcmp (proto, MODEST_PROTO_POP) == 0 ||
293 strcmp (proto, MODEST_PROTO_IMAP) == 0) {
294 w = imap_pop_configuration (self);
295 } else if (strcmp (proto, MODEST_PROTO_MAILDIR) == 0) {
296 w = maildir_configuration (self);
297 } else if (strcmp (proto, MODEST_PROTO_MBOX) == 0) {
298 w = mbox_configuration (self);
300 w = gtk_label_new ("");
302 gtk_widget_show_all (w);
303 gtk_box_pack_start (GTK_BOX(self), w, FALSE, FALSE, 2);
305 return GTK_WIDGET(self);
310 modest_store_widget_get_remember_password (ModestStoreWidget *self)
312 ModestStoreWidgetPrivate *priv;
314 g_return_val_if_fail (self, FALSE);
315 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
317 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 return gtk_entry_get_text (GTK_ENTRY(priv->username));
333 modest_store_widget_get_servername (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->servername));
345 modest_store_widget_get_proto (ModestStoreWidget *self)
347 ModestStoreWidgetPrivate *priv;
349 g_return_val_if_fail (self, FALSE);
350 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);