If no connection is available and bs embedded image is not fetched, show
[modest] / src / widgets / modest-wizard-dialog.c
1 /* Copyright (c) 2006, Nokia Corporation
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
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.
16  *
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.
28  */
29
30 /**
31  * SECTION:modest-wizard-dialog
32  * @short_description: A widget to create a guided installation
33  * process wizard
34  *
35  * #ModestWizardDialog is a widget to create a guided installation
36  * process. The dialog has four standard buttons, previous, next,
37  * finish, cancel, and contains several pages with optional icons.
38  * Response buttons are dimmed/undimmed automatically and the standard
39  * icon is shown/hidden in response to page navigation. The notebook
40  * widget provided by users contains the actual wizard pages.
41  */
42
43 #include <config.h>
44 #include <gtk/gtkdialog.h>
45 #include <gtk/gtknotebook.h>
46 #include <gtk/gtkimage.h>
47 #include <gtk/gtkbox.h>
48 #include <gtk/gtkhbox.h>
49 #include <gtk/gtkvbox.h>
50 #include <gtk/gtkbutton.h>
51 #include <gtk/gtk.h>
52
53 #ifdef HAVE_CONFIG_H
54 #include <config.h>
55 #endif
56
57 #ifndef MODEST_TOOLKIT_GTK
58 #include <hildon/hildon-defines.h>
59 #endif /*!MODEST_TOOLKIT_GTK*/
60
61 #include "modest-wizard-dialog.h"
62 #include "modest-debug.h"
63 #include "modest-text-utils.h"
64
65 static GtkDialogClass *parent_class;
66
67 static void class_init              (ModestWizardDialogClass   *wizard_dialog_class);
68
69 static void init                    (ModestWizardDialog        *wizard_dialog);
70
71 static void create_title            (ModestWizardDialog        *wizard_dialog);
72
73 static void set_property            (GObject                   *object,
74                                      guint                     property_id,
75                                      const GValue              *value,
76                                      GParamSpec                *pspec);
77
78 static void get_property            (GObject                   *object,
79                                      guint                     property_id,
80                                      GValue                    *value,
81                                      GParamSpec                *pspec);
82
83 static void finalize                (GObject                   *object);
84
85 static void response                (ModestWizardDialog        *wizard, 
86                                      gint                      response_id,
87                                      gpointer                  unused);
88
89 static void make_buttons_sensitive  (ModestWizardDialog *wizard_dialog,
90                                      gboolean           previous,
91                                      gboolean           finish,
92                                      gboolean next);
93
94 static gboolean invoke_before_next_vfunc (ModestWizardDialog *wizard_dialog);
95 static void invoke_enable_buttons_vfunc (ModestWizardDialog *wizard_dialog);
96 static void invoke_update_model_vfunc (ModestWizardDialog *wizard_dialog);
97 static gboolean invoke_save_vfunc (ModestWizardDialog *wizard_dialog);
98
99 enum {
100     PROP_ZERO,
101     PROP_WIZARD_NAME,
102     PROP_WIZARD_NOTEBOOK,
103     PROP_WIZARD_AUTOTITLE
104 };
105
106 struct _ModestWizardDialogPrivate {
107     gchar       *wizard_name;
108     GtkNotebook *notebook;
109     GtkBox      *box;
110     GtkWidget   *image;
111     gboolean    autotitle;
112
113     ModestWizardDialogResponseOverrideFunc override_func;
114 };
115
116
117 GType
118 modest_wizard_dialog_get_type (void)
119 {
120     static GType wizard_dialog_type = 0;
121
122     if (!wizard_dialog_type) {
123
124         static const GTypeInfo wizard_dialog_info = {
125             sizeof (ModestWizardDialogClass),
126             NULL,       /* base_init      */
127             NULL,       /* base_finalize  */
128             (GClassInitFunc) class_init,
129             NULL,       /* class_finalize */
130             NULL,       /* class_data     */
131             sizeof (ModestWizardDialog),
132             0,          /* n_preallocs    */
133             (GInstanceInitFunc) init,
134         };
135
136         wizard_dialog_type = g_type_register_static (GTK_TYPE_DIALOG,
137                                                      "ModestWizardDialog",
138                                                      &wizard_dialog_info,
139                                                      0);
140     }
141
142     return wizard_dialog_type;
143 }
144
145 static void
146 class_init (ModestWizardDialogClass *wizard_dialog_class)
147 {
148     GObjectClass *object_class = G_OBJECT_CLASS (wizard_dialog_class);
149
150     parent_class = g_type_class_peek_parent (wizard_dialog_class);
151
152     g_type_class_add_private (wizard_dialog_class,
153                               sizeof(ModestWizardDialogPrivate));
154
155     /* Override virtual methods */
156     object_class->set_property = set_property;
157     object_class->get_property = get_property;
158     object_class->finalize     = finalize;
159
160     wizard_dialog_class->before_next = NULL;
161     wizard_dialog_class->update_model = NULL;
162     wizard_dialog_class->save = NULL;
163     wizard_dialog_class->enable_buttons = NULL;
164
165     /**
166      * ModestWizardDialog:wizard-name:
167      *
168      * The name of the wizard.
169      */
170     g_object_class_install_property (object_class, PROP_WIZARD_NAME,
171             g_param_spec_string 
172             ("wizard-name",
173              "Wizard Name",
174              "The name of the ModestWizardDialog",
175              NULL,
176              G_PARAM_READWRITE));
177
178     /**
179      * ModestWizardDialog:wizard-notebook:
180      *
181      * The notebook object, which is used by the ModestWizardDialog.
182      */
183     g_object_class_install_property(object_class, PROP_WIZARD_NOTEBOOK,
184             g_param_spec_object 
185             ("wizard-notebook",
186              "Wizard Notebook",
187              "GtkNotebook object to be used in the "
188              "ModestWizardDialog",
189              GTK_TYPE_NOTEBOOK, G_PARAM_READWRITE));
190
191     /**
192      * ModestWizardDialog:autotitle
193      *
194      * If the wizard should automatically try to change the window title when changing steps. 
195      * Set to FALSE if you'd like to override the default behaviour. 
196      *
197      * Since: 0.14.5 
198      */
199     g_object_class_install_property(object_class, PROP_WIZARD_AUTOTITLE,
200             g_param_spec_boolean 
201             ("autotitle",
202              "AutoTitle",
203              "If the wizard should autotitle itself",
204              TRUE, 
205              G_PARAM_READWRITE));
206 }
207
208 static void 
209 finalize (GObject *object)
210 {
211     ModestWizardDialog *dialog = MODEST_WIZARD_DIALOG (object);
212     g_return_if_fail (dialog != NULL);
213
214     if (dialog->priv->wizard_name != NULL)
215         g_free (MODEST_WIZARD_DIALOG (object)->priv->wizard_name);
216     
217     if (G_OBJECT_CLASS (parent_class)->finalize)
218         G_OBJECT_CLASS (parent_class)->finalize(object);
219 }
220
221 /* Disable or enable the Previous, Next and Finish buttons */
222 static void
223 make_buttons_sensitive (ModestWizardDialog *wizard_dialog,
224                         gboolean previous,
225                         gboolean finish,
226                         gboolean next)
227 {
228     gtk_dialog_set_response_sensitive (GTK_DIALOG (wizard_dialog),
229                                        MODEST_WIZARD_DIALOG_PREVIOUS,
230                                        previous);
231
232     gtk_dialog_set_response_sensitive (GTK_DIALOG (wizard_dialog),
233                                        MODEST_WIZARD_DIALOG_FINISH,
234                                        finish);
235
236     gtk_dialog_set_response_sensitive (GTK_DIALOG (wizard_dialog),
237                                        MODEST_WIZARD_DIALOG_NEXT,
238                                        next);
239 }
240
241 static void 
242 init (ModestWizardDialog *wizard_dialog)
243 {
244     /* Initialize private structure for faster member access */
245     ModestWizardDialogPrivate *priv =
246         G_TYPE_INSTANCE_GET_PRIVATE (wizard_dialog,
247                 MODEST_TYPE_WIZARD_DIALOG,
248                 ModestWizardDialogPrivate);
249
250     GtkDialog *dialog = GTK_DIALOG (wizard_dialog);
251
252     /* Init internal widgets */
253     GtkWidget *vbox = gtk_vbox_new (FALSE, 0);
254     gtk_dialog_set_has_separator (dialog, FALSE);
255     wizard_dialog->priv = priv;
256     priv->override_func = NULL;
257     priv->box = GTK_BOX (gtk_hbox_new (FALSE, 0));
258 #ifdef MODEST_TOOLKIT_HILDON2
259     priv->image = NULL;
260 #else
261 #ifdef MODEST_TOOLKIT_GTK
262     priv->image = gtk_image_new_from_stock (GTK_STOCK_PREFERENCES, GTK_ICON_SIZE_DIALOG);
263 #else /*MODEST_TOOLKIT_GTK*/
264     static int icon_size = 0;
265     if (!icon_size)
266             icon_size = gtk_icon_size_register("modest_wizard", 50, 50);
267     priv->image = gtk_image_new_from_icon_name ("qgn_widg_wizard",
268                                                 icon_size);
269 #endif /*!MODEST_TOOLKIT_GTK*/
270 #endif /*MODEST_TOOLKIT_HILDON2 */
271     /* Default values for user provided properties */
272     priv->notebook = NULL;
273     priv->wizard_name = NULL;
274     priv->autotitle = TRUE;
275
276     /* Build wizard layout */
277     gtk_box_pack_start (GTK_BOX (dialog->vbox), GTK_WIDGET (priv->box), TRUE, TRUE, 0);
278     gtk_box_pack_start (GTK_BOX (priv->box), GTK_WIDGET (vbox), FALSE, FALSE, 0);
279     gtk_widget_show (vbox);
280     gtk_widget_show (GTK_WIDGET (priv->box));
281     if (priv->image) {
282             gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (priv->image), TRUE, TRUE, 0);
283             gtk_widget_show (priv->image);
284     }
285
286     /* Add response buttons: finish, previous, next, cancel */
287 #ifdef MODEST_TOOLKIT_HILDON1
288     gtk_dialog_add_button (dialog, _HL("ecdg_bd_wizard_finish"), MODEST_WIZARD_DIALOG_FINISH);
289     gtk_dialog_add_button (dialog, _HL("ecdg_bd_wizard_previous"), MODEST_WIZARD_DIALOG_PREVIOUS);
290     gtk_dialog_add_button (dialog, _HL("ecdg_bd_wizard_next"), MODEST_WIZARD_DIALOG_NEXT);
291     gtk_dialog_add_button (dialog, _HL("ecdg_bd_wizard_cancel"), MODEST_WIZARD_DIALOG_CANCEL);
292 #endif
293 #ifdef MODEST_TOOLKIT_HILDON2
294     gtk_dialog_add_button (dialog, _HL("wdgt_bd_finish"), MODEST_WIZARD_DIALOG_FINISH);
295     gtk_dialog_add_button (dialog, _HL("wdgt_bd_previous"), MODEST_WIZARD_DIALOG_PREVIOUS);
296     gtk_dialog_add_button (dialog, _HL("wdgt_bd_next"), MODEST_WIZARD_DIALOG_NEXT);
297 #endif
298 #ifdef MODEST_TOOLKIT_GTK
299     gtk_dialog_add_button (dialog, GTK_STOCK_SAVE, MODEST_WIZARD_DIALOG_FINISH);
300     gtk_dialog_add_button (dialog, GTK_STOCK_GO_BACK, MODEST_WIZARD_DIALOG_PREVIOUS);
301     gtk_dialog_add_button (dialog, GTK_STOCK_GO_FORWARD, MODEST_WIZARD_DIALOG_NEXT);
302     gtk_dialog_add_button (dialog, GTK_STOCK_CANCEL, MODEST_WIZARD_DIALOG_CANCEL);
303 #endif
304
305     /* Set initial button states: previous and finish buttons are disabled */
306     make_buttons_sensitive (wizard_dialog, FALSE, FALSE, TRUE);
307
308     gtk_widget_show (GTK_WIDGET (dialog->vbox));
309
310     /* connect to dialog's response signal */
311     g_signal_connect (G_OBJECT (dialog), "response",
312             G_CALLBACK (response), NULL);
313
314 }
315
316 #if GTK_CHECK_VERSION(2, 10, 0) /* These signals were added in GTK+ 2.10: */
317 static void on_notebook_page_added(GtkNotebook *notebook, 
318                                    GtkWidget   *child,
319                                    guint        page_num,
320                                    gpointer     user_data)
321 {
322         ModestWizardDialog* dialog = NULL;
323
324         g_return_if_fail (MODEST_IS_WIZARD_DIALOG(user_data));
325         dialog = MODEST_WIZARD_DIALOG(user_data);
326
327         /* The title should show the total number of pages: */
328         create_title (dialog);
329 }
330
331 static void on_notebook_page_removed(GtkNotebook *notebook, 
332                                      GtkWidget   *child,
333                                      guint        page_num,
334                                      gpointer     user_data)
335 {
336         ModestWizardDialog* dialog = NULL;
337
338         g_return_if_fail (MODEST_IS_WIZARD_DIALOG(user_data));
339         dialog = MODEST_WIZARD_DIALOG(user_data);
340
341         /* The title should show the total number of pages: */
342         create_title (dialog);
343 }
344 #endif /* GTK_CHECK_VERSION */
345
346 static void
347 on_notebook_switch_page (GtkNotebook *notebook,
348                          GtkNotebookPage *page,
349                          guint page_num,
350                          ModestWizardDialog *self)
351 {
352         g_return_if_fail (MODEST_IS_WIZARD_DIALOG(self));
353
354         create_title (self);
355 }
356
357 static void
358 connect_to_notebook_signals(ModestWizardDialog* dialog)
359 {
360 #if GTK_CHECK_VERSION(2, 10, 0) /* These signals were added in GTK+ 2.10: */
361         ModestWizardDialogPrivate *priv = MODEST_WIZARD_DIALOG(dialog)->priv;
362         g_return_if_fail (priv->notebook);
363         
364         /* Connect to the notebook signals,
365          * so we can update the title when necessary: */
366         g_signal_connect (G_OBJECT (priv->notebook), "page-added",
367                       G_CALLBACK (on_notebook_page_added), dialog);
368         g_signal_connect (G_OBJECT (priv->notebook), "page-removed",
369                       G_CALLBACK (on_notebook_page_removed), dialog);
370 #endif /* GTK_CHECK_VERSION */
371         g_signal_connect_after (G_OBJECT (priv->notebook), "switch-page",
372                                 G_CALLBACK (on_notebook_switch_page), dialog);
373 }
374
375
376 static void
377 set_property (GObject      *object, 
378               guint        property_id,
379               const GValue *value, 
380               GParamSpec   *pspec)
381 {
382     ModestWizardDialogPrivate *priv = MODEST_WIZARD_DIALOG(object)->priv;
383
384     switch (property_id) {
385
386         case PROP_WIZARD_AUTOTITLE:
387
388             priv->autotitle = g_value_get_boolean (value);
389
390             if (priv->autotitle && 
391                 priv->wizard_name && 
392                 priv->notebook)
393                 create_title (MODEST_WIZARD_DIALOG (object));
394             else if (priv->wizard_name)
395                 gtk_window_set_title (GTK_WINDOW (object), priv->wizard_name);
396             
397             break;
398
399         case PROP_WIZARD_NAME: 
400
401             /* Set new wizard name. This name will appear in titlebar */
402             if (priv->wizard_name)
403                 g_free (priv->wizard_name);
404
405             gchar *str = (gchar *) g_value_get_string (value);
406             g_return_if_fail (str != NULL);
407
408             priv->wizard_name = g_strdup (str);
409
410             /* We need notebook in order to create title, since page information
411                is used in title generation */
412             
413             if (priv->notebook && priv->autotitle)
414                 create_title (MODEST_WIZARD_DIALOG (object));
415     
416             break;
417
418         case PROP_WIZARD_NOTEBOOK: {
419
420             GtkNotebook *book = GTK_NOTEBOOK (g_value_get_object (value));
421             g_return_if_fail (book != NULL);
422
423             priv->notebook = book;
424
425             /* Set the default properties for the notebook (disable tabs,
426              * and remove borders) to make it look like a nice wizard widget */
427             gtk_notebook_set_show_tabs (priv->notebook, FALSE);
428             gtk_notebook_set_show_border (priv->notebook, FALSE);
429             gtk_box_pack_start (GTK_BOX( priv->box), GTK_WIDGET (priv->notebook), TRUE, TRUE, 0);
430
431             /* Show the notebook so that a gtk_widget_show on the dialog is
432              * all that is required to display the dialog correctly */
433             gtk_widget_show ( GTK_WIDGET (priv->notebook));
434
435             /* Update dialog title to reflect current page stats etc */ 
436             ModestWizardDialog *wizard_dialog = MODEST_WIZARD_DIALOG (object);      
437             if (priv->wizard_name && priv->autotitle)
438                 create_title (wizard_dialog);
439                 
440             connect_to_notebook_signals (wizard_dialog);
441             
442             }break;
443
444         default:
445             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
446             break;
447     }
448 }
449
450 static void
451 get_property (GObject      *object,
452               guint        property_id,
453               GValue       *value,
454               GParamSpec   *pspec)
455 {
456     ModestWizardDialogPrivate *priv = MODEST_WIZARD_DIALOG (object)->priv;
457
458     switch (property_id) {
459
460         case PROP_WIZARD_NAME:
461             g_value_set_string (value, priv->wizard_name);
462             break;
463
464         case PROP_WIZARD_NOTEBOOK:
465             g_value_set_object (value, priv->notebook);
466             break;
467
468         default:
469             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
470             break;
471     }
472 }
473
474 /*
475  * Creates the title of the dialog taking into account the current 
476  * page of the notebook.
477  */
478 static void
479 create_title (ModestWizardDialog *wizard_dialog)
480 {
481     gchar *str = NULL;
482     ModestWizardDialogPrivate *priv = NULL;
483     GtkNotebook *notebook = NULL;
484     gint pages, current;
485     const gchar *steps;
486
487     g_return_if_fail (MODEST_IS_WIZARD_DIALOG(wizard_dialog));
488     g_return_if_fail (wizard_dialog->priv != NULL);
489
490     priv = wizard_dialog->priv;
491     notebook = priv->notebook;
492
493     if (!notebook)
494         return;
495
496     /* Get page information, we'll need that when creating title */
497     pages = gtk_notebook_get_n_pages (notebook);
498     if (pages == 0)
499             return;
500
501     current = gtk_notebook_get_current_page (priv->notebook);
502     if (current < 0)
503             current = 0;
504
505     steps = gtk_notebook_get_tab_label_text (notebook,
506                                              gtk_notebook_get_nth_page (notebook, current));
507
508     str = g_strdup_printf ((steps&&*steps)?_HL("%s%s %s"):_HL("%s"),
509                            priv->wizard_name, _HL("ecdg_ti_caption_separator"),
510                            steps);
511
512     /* Update the dialog to display the generated title */
513     gtk_window_set_title (GTK_WINDOW (wizard_dialog), str);
514     g_free (str);
515 }
516
517 /*
518  * Response signal handler. This function is needed because GtkDialog's 
519  * handler for this signal closes the dialog and we don't want that, we 
520  * want to change pages and, dim certain response buttons. Overriding the 
521  * virtual function would not work because that would be called after the 
522  * signal handler implemented by GtkDialog.
523  * FIXME: There is a much saner way to do that [MDK]
524  */
525 static void 
526 response (ModestWizardDialog   *wizard_dialog,
527           gint                 response_id,
528           gpointer             unused)
529 {
530     ModestWizardDialogPrivate *priv = wizard_dialog->priv;
531     GtkNotebook *notebook = priv->notebook;
532     gint current = 0;
533     gboolean is_first, is_last;
534
535     if (priv->override_func) {
536             if (priv->override_func (wizard_dialog, response_id, gtk_notebook_get_current_page (notebook))) {
537                     /* Don't let the dialog close */
538                     g_signal_stop_emission_by_name (wizard_dialog, "response");
539                     
540                     /* Force refresh of title */
541                     if (priv->autotitle) 
542                             create_title (wizard_dialog);
543                     return;
544             }
545     }
546     
547     switch (response_id) {
548         
549         case MODEST_WIZARD_DIALOG_PREVIOUS:
550             gtk_notebook_prev_page (notebook); /* go to previous page */
551             break;
552
553         case MODEST_WIZARD_DIALOG_NEXT:
554                 if (invoke_before_next_vfunc (wizard_dialog))
555                         gtk_notebook_next_page (notebook); /* go to next page */
556                 
557             break;
558
559         case MODEST_WIZARD_DIALOG_CANCEL:
560                 return;
561                 break;      
562         case MODEST_WIZARD_DIALOG_FINISH:
563                 if (invoke_before_next_vfunc (wizard_dialog))
564                 return;
565             
566             break;
567
568     }
569
570     current = gtk_notebook_get_current_page (notebook);
571     gint last = gtk_notebook_get_n_pages (notebook) - 1;
572     is_last = current == last;
573     is_first = current == 0;
574
575     /* If first page, previous and finish are disabled, 
576        if last page, next is disabled */
577     make_buttons_sensitive (wizard_dialog,
578                             (is_first) ? FALSE : TRUE,
579                             TRUE,
580                             (is_last) ? FALSE : TRUE);
581
582     /* Allow derived classes to disable buttons to prevent navigation,
583      * according to their own validation logic: */
584     invoke_enable_buttons_vfunc (wizard_dialog);
585
586     /* Don't let the dialog close */
587     g_signal_stop_emission_by_name (wizard_dialog, "response");
588
589     /* We show the default image on first and last pages */
590     last = gtk_notebook_get_n_pages (notebook) - 1;
591     if (priv->image) {
592             if (current == last || current == 0)
593                     gtk_widget_show (GTK_WIDGET(priv->image));
594             else
595                     gtk_widget_hide (GTK_WIDGET(priv->image));
596     }
597
598     /* New page number may appear in the title, update it */
599     if (priv->autotitle) 
600         create_title (wizard_dialog);
601 }
602
603 /**
604  * modest_wizard_dialog_new:
605  * @parent: a #GtkWindow
606  * @wizard_name: the name of dialog
607  * @notebook: the notebook to be shown on the dialog
608  *
609  * Creates a new #ModestWizardDialog.
610  *
611  * Returns: a new #ModestWizardDialog
612  */
613 GtkWidget*
614 modest_wizard_dialog_new (GtkWindow   *parent,
615                           const char  *wizard_name,
616                           GtkNotebook *notebook)
617 {
618     GtkWidget *widget;
619
620     g_return_val_if_fail (GTK_IS_NOTEBOOK (notebook), NULL);
621
622     widget = GTK_WIDGET (g_object_new
623             (MODEST_TYPE_WIZARD_DIALOG,
624              "wizard-name", wizard_name,
625              "wizard-notebook", notebook, NULL));
626
627     if (parent)
628         gtk_window_set_transient_for (GTK_WINDOW (widget), parent);
629
630     return widget;
631 }
632
633 /**
634  * modest_wizard_dialog_force_title_update:
635  * @wizard_dialog: The wizard dialog
636  *
637  * Force the title to be rebuilt, for instance when you have added or 
638  * removed notebook pages. This function is not necessary when using GTK+ 2.10, 
639  * because that has GtkNotebook signals that will be used to update the title 
640  * automatically.
641  */
642 void
643 modest_wizard_dialog_force_title_update (ModestWizardDialog   *wizard_dialog)
644 {
645         create_title (wizard_dialog);
646 }
647
648 static gboolean
649 invoke_before_next_vfunc (ModestWizardDialog *wizard_dialog)
650 {
651         ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
652         
653         /* Call the vfunc, which may be overridden by derived classes: */
654         if (klass->before_next) {
655                 ModestWizardDialogPrivate *priv = MODEST_WIZARD_DIALOG(wizard_dialog)->priv;
656         
657                 gint current_page_num = gtk_notebook_get_current_page (priv->notebook);
658                 
659                 /* Get widgets for the two pages: */
660                 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (priv->notebook, current_page_num);
661                 
662                 GtkWidget* next_page_widget = NULL;
663                 if ((current_page_num + 1) < gtk_notebook_get_n_pages (priv->notebook))
664                         next_page_widget = gtk_notebook_get_nth_page (priv->notebook, current_page_num + 1);
665
666                 MODEST_DEBUG_BLOCK (
667                 g_debug ("Switching to page %d (%s)",
668                          gtk_notebook_page_num (priv->notebook, next_page_widget),
669                          gtk_notebook_get_tab_label_text (priv->notebook, next_page_widget));
670
671                 {
672                         GtkWidget *p;
673                         gint i;
674                         g_debug ("\t***************");
675                         for (i=0; i<gtk_notebook_get_n_pages(priv->notebook);i++) {
676                                 p = gtk_notebook_get_nth_page (priv->notebook, i);
677                                 g_debug ("\t%d - %s", i, gtk_notebook_get_tab_label_text (priv->notebook, p));
678                         }
679                         g_debug ("\t***************");
680                 }
681                                     );
682                 
683                 /* Ask the vfunc implementation whether navigation should be allowed: */
684                 return (*(klass->before_next))(wizard_dialog, current_page_widget, next_page_widget);
685         }
686         
687         /* Allow navigation by default if there is no vfunc implementation: */
688         return TRUE;
689 }
690
691 static void
692 invoke_enable_buttons_vfunc (ModestWizardDialog *wizard_dialog)
693 {
694         ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
695         
696         /* Call the vfunc, which may be overridden by derived classes: */
697         if (klass->enable_buttons) {
698                 ModestWizardDialogPrivate *priv = MODEST_WIZARD_DIALOG(wizard_dialog)->priv;
699         
700                 gint current_page_num = gtk_notebook_get_current_page (priv->notebook);
701                 
702                 GtkWidget* current_page_widget = gtk_notebook_get_nth_page (priv->notebook, current_page_num);
703                         
704                 (*(klass->enable_buttons))(wizard_dialog, current_page_widget);
705         }
706 }
707
708 static void
709 invoke_update_model_vfunc (ModestWizardDialog *wizard_dialog)
710 {
711         ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
712         
713         /* Call the vfunc, which may be overridden by derived classes: */
714         if (klass->update_model) {
715                 (*(klass->update_model)) (wizard_dialog);
716         }
717 }
718
719 static gboolean
720 invoke_save_vfunc (ModestWizardDialog *wizard_dialog)
721 {
722         ModestWizardDialogClass *klass = MODEST_WIZARD_DIALOG_GET_CLASS (wizard_dialog);
723         
724         /* Call the vfunc, which may be overridden by derived classes: */
725         if (klass->save) {
726                 return (*(klass->save)) (wizard_dialog);
727         } else {
728                 return TRUE;
729         }
730 }
731
732 void 
733 modest_wizard_dialog_set_response_override_handler (ModestWizardDialog *wizard_dialog,
734                                                     ModestWizardDialogResponseOverrideFunc callback)
735 {
736     ModestWizardDialogPrivate *priv = wizard_dialog->priv;
737
738     priv->override_func = callback;
739 }
740
741 void
742 modest_wizard_dialog_update_model (ModestWizardDialog *wizard_dialog)
743 {
744         g_return_if_fail (MODEST_IS_WIZARD_DIALOG (wizard_dialog));
745
746         invoke_update_model_vfunc (wizard_dialog);
747 }
748
749 gboolean
750 modest_wizard_dialog_save (ModestWizardDialog *wizard_dialog)
751 {
752         g_return_val_if_fail (MODEST_IS_WIZARD_DIALOG (wizard_dialog), FALSE);
753
754         return invoke_save_vfunc (wizard_dialog);
755 }