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