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 {
47 GtkWidget *servername;
52 GtkWidget *remember_pwd;
55 ModestWidgetFactory *factory;
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_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 ModestStoreWidgetPrivate *priv;
199 GtkWidget *label, *box, *hbox;
201 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
202 box = gtk_vbox_new (FALSE, 6);
204 label = gtk_label_new (NULL);
205 gtk_label_set_markup (GTK_LABEL(label),_("<b>Server configuration</b>"));
206 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 6);
208 hbox = gtk_hbox_new (FALSE, 6);
209 label = gtk_label_new (_("Username:"));
211 priv->username = gtk_entry_new_with_max_length (40);
212 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
213 gtk_box_pack_start (GTK_BOX(hbox), priv->username,FALSE, FALSE, 6);
214 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 0);
216 hbox = gtk_hbox_new (FALSE, 6);
217 label = gtk_label_new (_("Server:"));
218 if (!priv->servername)
219 priv->servername = gtk_entry_new_with_max_length (40);
220 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
221 gtk_box_pack_start (GTK_BOX(hbox), priv->servername,FALSE, FALSE, 6);
222 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 0);
224 label = gtk_label_new(NULL);
225 gtk_label_set_markup (GTK_LABEL(label),_("<b>Security</b>"));
226 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 0);
228 priv->security = modest_widget_factory_get_combo_box (priv->factory,
229 MODEST_COMBO_BOX_TYPE_SECURITY_PROTOS);
230 hbox = gtk_hbox_new (FALSE, 6);
231 label = gtk_label_new(NULL);
232 gtk_label_set_text (GTK_LABEL(label),_("Connection type:"));
233 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
234 gtk_box_pack_start (GTK_BOX(hbox), priv->security, FALSE, FALSE,0);
235 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 0);
237 hbox = gtk_hbox_new (FALSE, 6);
238 label = gtk_label_new(NULL);
240 gtk_label_set_text (GTK_LABEL(label),_("Authentication:"));
241 gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 6);
242 gtk_box_pack_start (GTK_BOX(hbox), modest_widget_factory_get_combo_box
243 (priv->factory, MODEST_COMBO_BOX_TYPE_AUTH_PROTOS),
247 gtk_check_button_new_with_label (_("Remember password"));
248 gtk_box_pack_start (GTK_BOX(hbox),priv->remember_pwd,
251 gtk_box_pack_start (GTK_BOX(box), hbox, FALSE, FALSE, 0);
253 /* Handle entry modifications */
254 g_signal_connect (priv->username, "changed", G_CALLBACK (on_entry_changed), self);
255 g_signal_connect (priv->servername, "changed", G_CALLBACK (on_entry_changed), self);
262 modest_store_widget_finalize (GObject *obj)
264 ModestStoreWidgetPrivate *priv;
265 priv = MODEST_STORE_WIDGET_GET_PRIVATE(obj);
268 g_object_unref (priv->factory);
269 priv->factory = NULL;
272 G_OBJECT_CLASS(parent_class)->finalize (obj);
278 modest_store_widget_new (ModestWidgetFactory *factory, ModestProtocol proto)
282 ModestStoreWidget *self;
283 ModestStoreWidgetPrivate *priv;
285 g_return_val_if_fail (proto, NULL);
286 g_return_val_if_fail (factory, NULL);
288 obj = g_object_new(MODEST_TYPE_STORE_WIDGET, NULL);
289 self = MODEST_STORE_WIDGET(obj);
290 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
292 g_object_ref (factory);
293 priv->factory = factory;
297 if (proto == MODEST_PROTOCOL_STORE_POP || proto == MODEST_PROTOCOL_STORE_IMAP)
298 w = imap_pop_configuration (self);
299 else if (proto == MODEST_PROTOCOL_STORE_MAILDIR)
300 w = maildir_configuration (self);
301 else if (proto == MODEST_PROTOCOL_STORE_MBOX)
302 w = mbox_configuration (self);
304 w = gtk_label_new ("");
306 gtk_widget_show_all (w);
307 gtk_box_pack_start (GTK_BOX(self), w, FALSE, FALSE, 2);
309 return GTK_WIDGET(self);
313 modest_store_widget_get_remember_password (ModestStoreWidget *self)
315 ModestStoreWidgetPrivate *priv;
317 g_return_val_if_fail (self, FALSE);
318 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
320 if (GTK_IS_TOGGLE_BUTTON(priv->remember_pwd))
321 return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(priv->remember_pwd));
327 modest_store_widget_get_username (ModestStoreWidget *self)
329 ModestStoreWidgetPrivate *priv;
331 g_return_val_if_fail (self, NULL);
332 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
334 if (GTK_IS_ENTRY(priv->username))
335 return gtk_entry_get_text (GTK_ENTRY(priv->username));
341 modest_store_widget_get_servername (ModestStoreWidget *self)
343 ModestStoreWidgetPrivate *priv;
345 g_return_val_if_fail (self, NULL);
346 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
348 if (GTK_IS_ENTRY(priv->servername))
349 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, MODEST_PROTOCOL_UNKNOWN);
361 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
368 modest_store_widget_get_path (ModestStoreWidget *self)
370 ModestStoreWidgetPrivate *priv;
372 g_return_val_if_fail (self, MODEST_PROTOCOL_UNKNOWN);
373 priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
375 if (GTK_IS_FILE_CHOOSER(priv->chooser))
376 return gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(priv->chooser));