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