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