Now the wizard dialog response override returns a boolean (to stop
[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 #if MODEST_HILDON_API == 0
59 #include <hildon-widgets/hildon-defines.h>
60 #else
61 #include <hildon/hildon-defines.h>
62 #endif /*MODEST_HILDON_API == 0*/
63 #endif /*!MODEST_TOOLKIT_GTK*/
64
65 #include "modest-wizard-dialog.h"
66 #include "modest-debug.h"
67 #include "modest-text-utils.h"
68
69 static GtkDialogClass *parent_class;
70
71 static void class_init              (ModestWizardDialogClass   *wizard_dialog_class);
72
73 static void init                    (ModestWizardDialog        *wizard_dialog);
74
75 static void create_title            (ModestWizardDialog        *wizard_dialog);
76
77 static void set_property            (GObject                   *object,
78                                      guint                     property_id,
79                                      const GValue              *value,
80                                      GParamSpec                *pspec);
81
82 static void get_property            (GObject                   *object,
83                                      guint                     property_id,
84                                      GValue                    *value,
85                                      GParamSpec                *pspec);
86
87 static void finalize                (GObject                   *object);
88
89 static void response                (ModestWizardDialog        *wizard, 
90                                      gint                      response_id,
91                                      gpointer                  unused);
92
93 static void make_buttons_sensitive  (ModestWizardDialog *wizard_dialog,
94                                      gboolean           previous,
95                                      gboolean           finish,
96                                      gboolean next);
97
98 static gboolean invoke_before_next_vfunc (ModestWizardDialog *wizard_dialog);
99 static void invoke_enable_buttons_vfunc (ModestWizardDialog *wizard_dialog);
100
101 enum {
102     PROP_ZERO,
103     PROP_WIZARD_NAME,
104     PROP_WIZARD_NOTEBOOK,
105     PROP_WIZARD_AUTOTITLE
106 };
107
108 struct _ModestWizardDialogPrivate {
109     gchar       *wizard_name;
110     GtkNotebook *notebook;
111     GtkBox      *box;
112     GtkWidget   *image;
113     gboolean    autotitle;
114
115     ModestWizardDialogResponseOverrideFunc override_func;
116 };
117
118
119 GType
120 modest_wizard_dialog_get_type (void)
121 {
122     static GType wizard_dialog_type = 0;
123
124     if (!wizard_dialog_type) {
125
126         static const GTypeInfo wizard_dialog_info = {
127             sizeof (ModestWizardDialogClass),
128             NULL,       /* base_init      */
129             NULL,       /* base_finalize  */
130             (GClassInitFunc) class_init,
131             NULL,       /* class_finalize */
132             NULL,       /* class_data     */
133             sizeof (ModestWizardDialog),
134             0,          /* n_preallocs    */
135             (GInstanceInitFunc) init,
136         };
137
138         wizard_dialog_type = g_type_register_static (GTK_TYPE_DIALOG,
139                                                      "ModestWizardDialog",
140                                                      &wizard_dialog_info,
141                                                      0);
142     }
143
144     return wizard_dialog_type;
145 }
146
147 static void
148 class_init (ModestWizardDialogClass *wizard_dialog_class)
149 {
150     GObjectClass *object_class = G_OBJECT_CLASS (wizard_dialog_class);
151
152     parent_class = g_type_class_peek_parent (wizard_dialog_class);
153
154     g_type_class_add_private (wizard_dialog_class,
155                               sizeof(ModestWizardDialogPrivate));
156
157     /* Override virtual methods */
158     object_class->set_property = set_property;
159     object_class->get_property = get_property;
160     object_class->finalize     = finalize;
161
162     /**
163      * ModestWizardDialog:wizard-name:
164      *
165      * The name of the wizard.
166      */
167     g_object_class_install_property (object_class, PROP_WIZARD_NAME,
168             g_param_spec_string 
169             ("wizard-name",
170              "Wizard Name",
171              "The name of the ModestWizardDialog",
172              NULL,
173              G_PARAM_READWRITE));
174
175     /**
176      * ModestWizardDialog:wizard-notebook:
177      *
178      * The notebook object, which is used by the ModestWizardDialog.
179      */
180     g_object_class_install_property(object_class, PROP_WIZARD_NOTEBOOK,
181             g_param_spec_object 
182             ("wizard-notebook",
183              "Wizard Notebook",
184              "GtkNotebook object to be used in the "
185              "ModestWizardDialog",
186              GTK_TYPE_NOTEBOOK, G_PARAM_READWRITE));
187
188     /**
189      * ModestWizardDialog:autotitle
190      *
191      * If the wizard should automatically try to change the window title when changing steps. 
192      * Set to FALSE if you'd like to override the default behaviour. 
193      *
194      * Since: 0.14.5 
195      */
196     g_object_class_install_property(object_class, PROP_WIZARD_AUTOTITLE,
197             g_param_spec_boolean 
198             ("autotitle",
199              "AutoTitle",
200              "If the wizard should autotitle itself",
201              TRUE, 
202              G_PARAM_READWRITE));
203 }
204
205 static void 
206 finalize (GObject *object)
207 {
208     ModestWizardDialog *dialog = MODEST_WIZARD_DIALOG (object);
209     g_return_if_fail (dialog != NULL);
210
211     if (dialog->priv->wizard_name != NULL)
212         g_free (MODEST_WIZARD_DIALOG (object)->priv->wizard_name);
213     
214     if (G_OBJECT_CLASS (parent_class)->finalize)
215         G_OBJECT_CLASS (parent_class)->finalize(object);
216 }
217
218 /* Disable or enable the Previous, Next and Finish buttons */
219 static void
220 make_buttons_sensitive (ModestWizardDialog *wizard_dialog,
221                         gboolean previous,
222                         gboolean finish,
223                         gboolean next)
224 {
225     gtk_dialog_set_response_sensitive (GTK_DIALOG (wizard_dialog),
226                                        MODEST_WIZARD_DIALOG_PREVIOUS,
227                                        previous);
228
229     gtk_dialog_set_response_sensitive (GTK_DIALOG (wizard_dialog),
230                                        MODEST_WIZARD_DIALOG_FINISH,
231                                        finish);
232
233     gtk_dialog_set_response_sensitive (GTK_DIALOG (wizard_dialog),
234                                        MODEST_WIZARD_DIALOG_NEXT,
235                                        next);
236 }
237
238 static void 
239 init (ModestWizardDialog *wizard_dialog)
240 {
241     /* Initialize private structure for faster member access */
242     ModestWizardDialogPrivate *priv =
243         G_TYPE_INSTANCE_GET_PRIVATE (wizard_dialog,
244                 MODEST_TYPE_WIZARD_DIALOG,
245                 ModestWizardDialogPrivate);
246
247     GtkDialog *dialog = GTK_DIALOG (wizard_dialog);
248
249     /* Init internal widgets */
250     GtkWidget *vbox = gtk_vbox_new (FALSE, 0);
251     gtk_dialog_set_has_separator (dialog, FALSE);
252     wizard_dialog->priv = priv;
253     priv->override_func = NULL;
254     priv->box = GTK_BOX (gtk_hbox_new (FALSE, 0));
255 #ifdef MODEST_TOOLKIT_HILDON2
256     priv->image = NULL;
257 #else
258 #ifdef MODEST_TOOLKIT_GTK
259     priv->image = gtk_image_new_from_stock (GTK_STOCK_PREFERENCES, GTK_ICON_SIZE_DIALOG);
260 #else /*MODEST_TOOLKIT_GTK*/
261 #if MODEST_HILDON_API == 0
262     priv->image = gtk_image_new_from_icon_name ("qgn_widg_wizard",
263                                                 HILDON_ICON_SIZE_WIDG_WIZARD);
264 #else       
265     static int icon_size = 0;
266     if (!icon_size)
267             icon_size = gtk_icon_size_register("modest_wizard", 50, 50);
268     priv->image = gtk_image_new_from_icon_name ("qgn_widg_wizard",
269                                                 icon_size);
270 #endif /*MODEST_HILDON_API == 0*/
271 #endif /*!MODEST_TOOLKIT_GTK*/
272 #endif /*MODEST_TOOLKIT_HILDON2 */
273     /* Default values for user provided properties */
274     priv->notebook = NULL;
275     priv->wizard_name = NULL;
276     priv->autotitle = TRUE;
277
278     /* Build wizard layout */
279     gtk_box_pack_start_defaults (GTK_BOX (dialog->vbox), GTK_WIDGET (priv->box));
280     gtk_box_pack_start_defaults (GTK_BOX (priv->box), GTK_WIDGET (vbox));
281     if (priv->image)
282       gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (priv->image), FALSE, FALSE, 0);
283
284     /* Add response buttons: finish, previous, next, cancel */
285 #ifdef MODEST_TOOLKIT_HILDON1
286     gtk_dialog_add_button (dialog, _HL("ecdg_bd_wizard_finish"), MODEST_WIZARD_DIALOG_FINISH);
287     gtk_dialog_add_button (dialog, _HL("ecdg_bd_wizard_previous"), MODEST_WIZARD_DIALOG_PREVIOUS);
288     gtk_dialog_add_button (dialog, _HL("ecdg_bd_wizard_next"), MODEST_WIZARD_DIALOG_NEXT);
289     gtk_dialog_add_button (dialog, _HL("ecdg_bd_wizard_cancel"), MODEST_WIZARD_DIALOG_CANCEL);
290 #endif
291 #ifdef MODEST_TOOLKIT_HILDON2
292     gtk_dialog_add_button (dialog, _HL("wdgt_bd_finish"), MODEST_WIZARD_DIALOG_FINISH);
293     gtk_dialog_add_button (dialog, _HL("wdgt_bd_previous"), MODEST_WIZARD_DIALOG_PREVIOUS);
294     gtk_dialog_add_button (dialog, _HL("wdgt_bd_next"), MODEST_WIZARD_DIALOG_NEXT);
295 #endif
296 #ifdef MODEST_TOOLKIT_GTK
297     gtk_dialog_add_button (dialog, GTK_STOCK_SAVE, MODEST_WIZARD_DIALOG_FINISH);
298     gtk_dialog_add_button (dialog, GTK_STOCK_GO_BACK, MODEST_WIZARD_DIALOG_PREVIOUS);
299     gtk_dialog_add_button (dialog, GTK_STOCK_GO_FORWARD, MODEST_WIZARD_DIALOG_NEXT);
300     gtk_dialog_add_button (dialog, GTK_STOCK_CANCEL, MODEST_WIZARD_DIALOG_CANCEL);
301 #endif
302
303     /* Set initial button states: previous and finish buttons are disabled */
304     make_buttons_sensitive (wizard_dialog, FALSE, FALSE, TRUE);
305
306     /* Show all the internal widgets */
307     gtk_widget_show_all (GTK_WIDGET (dialog->vbox));
308
309     /* connect to dialog's response signal */
310     g_signal_connect (G_OBJECT (dialog), "response",
311             G_CALLBACK (response), NULL);
312 }
313
314 #if GTK_CHECK_VERSION(2, 10, 0) /* These signals were added in GTK+ 2.10: */
315 static void on_notebook_page_added(GtkNotebook *notebook, 
316                                    GtkWidget   *child,
317                                    guint        page_num,
318                                    gpointer     user_data)
319 {
320         ModestWizardDialog* dialog = NULL;
321
322         g_return_if_fail (MODEST_IS_WIZARD_DIALOG(user_data));
323         dialog = MODEST_WIZARD_DIALOG(user_data);
324
325         /* The title should show the total number of pages: */
326         create_title (dialog);
327 }
328
329 static void on_notebook_page_removed(GtkNotebook *notebook, 
330                                      GtkWidget   *child,
331                                      guint        page_num,
332                                      gpointer     user_data)
333 {
334         ModestWizardDialog* dialog = NULL;
335
336         g_return_if_fail (MODEST_IS_WIZARD_DIALOG(user_data));
337         dialog = MODEST_WIZARD_DIALOG(user_data);
338
339         /* The title should show the total number of pages: */
340         create_title (dialog);
341 }
342 #endif /* GTK_CHECK_VERSION */
343
344 static void
345 connect_to_notebook_signals(ModestWizardDialog* dialog)
346 {
347 #if GTK_CHECK_VERSION(2, 10, 0) /* These signals were added in GTK+ 2.10: */
348         ModestWizardDialogPrivate *priv = MODEST_WIZARD_DIALOG(dialog)->priv;
349         g_return_if_fail (priv->notebook);
350         
351         /* Connect to the notebook signals,
352          * so we can update the title when necessary: */
353         g_signal_connect (G_OBJECT (priv->notebook), "page-added",
354                       G_CALLBACK (on_notebook_page_added), dialog);
355         g_signal_connect (G_OBJECT (priv->notebook), "page-removed",
356                       G_CALLBACK (on_notebook_page_removed), dialog);
357 #endif /* GTK_CHECK_VERSION */
358 }
359
360
361 static void
362 set_property (GObject      *object, 
363               guint        property_id,
364               const GValue *value, 
365               GParamSpec   *pspec)
366 {
367     ModestWizardDialogPrivate *priv = MODEST_WIZARD_DIALOG(object)->priv;
368
369     switch (property_id) {
370
371         case PROP_WIZARD_AUTOTITLE:
372
373             priv->autotitle = g_value_get_boolean (value);
374
375             if (priv->autotitle && 
376                 priv->wizard_name && 
377                 priv->notebook)
378                 create_title (MODEST_WIZARD_DIALOG (object));
379             else if (priv->wizard_name)
380                 gtk_window_set_title (GTK_WINDOW (object), priv->wizard_name);
381             
382             break;
383
384         case PROP_WIZARD_NAME: 
385
386             /* Set new wizard name. This name will appear in titlebar */
387             if (priv->wizard_name)
388                 g_free (priv->wizard_name);
389
390             gchar *str = (gchar *) g_value_get_string (value);
391             g_return_if_fail (str != NULL);
392
393             priv->wizard_name = g_strdup (str);
394
395             /* We need notebook in order to create title, since page information
396                is used in title generation */
397             
398             if (priv->notebook && priv->autotitle)
399                 create_title (MODEST_WIZARD_DIALOG (object));
400     
401             break;
402
403         case PROP_WIZARD_NOTEBOOK: {
404
405             GtkNotebook *book = GTK_NOTEBOOK (g_value_get_object (value));
406             g_return_if_fail (book != NULL);
407
408             priv->notebook = book;
409
410             /* Set the default properties for the notebook (disable tabs,
411              * and remove borders) to make it look like a nice wizard widget */
412             gtk_notebook_set_show_tabs (priv->notebook, FALSE);
413             gtk_notebook_set_show_border (priv->notebook, FALSE);
414             gtk_box_pack_start_defaults (GTK_BOX( priv->box), GTK_WIDGET (priv->notebook));
415
416             /* Show the notebook so that a gtk_widget_show on the dialog is
417              * all that is required to display the dialog correctly */
418             gtk_widget_show ( GTK_WIDGET (priv->notebook));
419
420             /* Update dialog title to reflect current page stats etc */ 
421             ModestWizardDialog *wizard_dialog = MODEST_WIZARD_DIALOG (object);      
422             if (priv->wizard_name && priv->autotitle)
423                 create_title (wizard_dialog);
424                 
425             connect_to_notebook_signals (wizard_dialog);
426             
427             }break;
428
429         default:
430             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
431             break;
432     }
433 }
434
435 static void
436 get_property (GObject      *object,
437               guint        property_id,
438               GValue       *value,
439               GParamSpec   *pspec)
440 {
441     ModestWizardDialogPrivate *priv = MODEST_WIZARD_DIALOG (object)->priv;
442
443     switch (property_id) {
444
445         case PROP_WIZARD_NAME:
446             g_value_set_string (value, priv->wizard_name);
447             break;
448
449         case PROP_WIZARD_NOTEBOOK:
450             g_value_set_object (value, priv->notebook);
451             break;
452
453         default:
454             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
455             break;
456     }
457 }
458
459 /*
460  * Creates the title of the dialog taking into account the current 
461  * page of the notebook.
462  */
463 static void
464 create_title (ModestWizardDialog *wizard_dialog)
465 {
466     gchar *str = NULL;
467     ModestWizardDialogPrivate *priv = NULL;
468     GtkNotebook *notebook = NULL;
469
470     g_return_if_fail (MODEST_IS_WIZARD_DIALOG(wizard_dialog));
471     g_return_if_fail (wizard_dialog->priv != NULL);
472
473     priv = wizard_dialog->priv;    
474     notebook = priv->notebook;
475
476     if (!notebook)
477         return;
478
479     /* Get page information, we'll need that when creating title */
480     gint pages = gtk_notebook_get_n_pages (notebook);
481     if (pages == 0)
482       return;
483         
484     gint current = gtk_notebook_get_current_page (priv->notebook);
485     if (current < 0)
486         current = 0;
487
488     /* the welcome title on the initial page */
489     /* This is the standard wizard title, with, e.g., 1/4 at the end,
490          * but the Modest UI spec does not want this. */
491         /*
492     if (current == 0) {
493         str = g_strdup_printf (_HL("ecdg_ti_wizard_welcome"), 
494                 priv->wizard_name, pages);
495     } else {
496     */
497         const gchar *steps = gtk_notebook_get_tab_label_text (notebook,
498                 gtk_notebook_get_nth_page (notebook, current));
499                 
500                 /* This is the standard wizard title, with, e.g., 1/4 at the end,
501                  * but the Modest UI spec does not want this.
502                  */
503                 /*
504         str = g_strdup_printf (_HL("ecdg_ti_wizard_step"), 
505                 priv->wizard_name, current + 1, pages, steps);
506         */
507
508         str = g_strdup_printf ((steps&&*steps)?_HL("%s: %s"):_HL("%s"), 
509                 priv->wizard_name, steps);
510     /* } */
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 void 
709 modest_wizard_dialog_set_response_override_handler (ModestWizardDialog *wizard_dialog,
710                                                     ModestWizardDialogResponseOverrideFunc callback)
711 {
712     ModestWizardDialogPrivate *priv = wizard_dialog->priv;
713
714     priv->override_func = callback;
715 }