2007-05-15 Murray Cumming <murrayc@murrayc.com>
[modest] / src / maemo / easysetup / modest-wizard-dialog.c
index 2131caa..cd37041 100644 (file)
@@ -29,6 +29,7 @@
 #include <gtk/gtkhbox.h>
 #include <gtk/gtkvbox.h>
 #include <gtk/gtkbutton.h>
+#include <gtk/gtk.h>
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -269,6 +270,53 @@ init (ModestWizardDialog *wizard_dialog)
             G_CALLBACK (response), NULL);
 }
 
+#if GTK_CHECK_VERSION(2, 10, 0) /* These signals were added in GTK+ 2.10: */
+static void on_notebook_page_added(GtkNotebook *notebook, 
+                                  GtkWidget   *child,
+                                  guint        page_num,
+                                  gpointer     user_data)
+{
+       ModestWizardDialog* dialog = NULL;
+
+       g_return_if_fail (MODEST_IS_WIZARD_DIALOG(user_data));
+       dialog = MODEST_WIZARD_DIALOG(user_data);
+
+       /* The title should show the total number of pages: */
+       create_title (dialog);
+}
+
+static void on_notebook_page_removed(GtkNotebook *notebook, 
+                                    GtkWidget   *child,
+                                    guint        page_num,
+                                    gpointer     user_data)
+{
+       ModestWizardDialog* dialog = NULL;
+
+       g_return_if_fail (MODEST_IS_WIZARD_DIALOG(user_data));
+       dialog = MODEST_WIZARD_DIALOG(user_data);
+
+       /* The title should show the total number of pages: */
+       create_title (dialog);
+}
+#endif /* GTK_CHECK_VERSION */
+
+static void
+connect_to_notebook_signals(ModestWizardDialog* dialog)
+{
+#if GTK_CHECK_VERSION(2, 10, 0) /* These signals were added in GTK+ 2.10: */
+       ModestWizardDialogPrivate *priv = MODEST_WIZARD_DIALOG(dialog)->priv;
+       g_return_if_fail (priv->notebook);
+       
+       /* Connect to the notebook signals,
+        * so we can update the title when necessary: */
+       g_signal_connect (G_OBJECT (priv->notebook), "page-added",
+                     G_CALLBACK (on_notebook_page_added), dialog);
+       g_signal_connect (G_OBJECT (priv->notebook), "page-removed",
+                     G_CALLBACK (on_notebook_page_removed), dialog);
+#endif /* GTK_CHECK_VERSION */
+}
+
+
 static void
 set_property (GObject      *object, 
               guint        property_id,
@@ -328,11 +376,14 @@ set_property (GObject      *object,
              * all that is required to display the dialog correctly */
             gtk_widget_show ( GTK_WIDGET (priv->notebook));
 
-            /* Update dialog title to reflect current page stats etc */        
+            /* Update dialog title to reflect current page stats etc */ 
+            ModestWizardDialog *wizard_dialog = MODEST_WIZARD_DIALOG (object);      
             if (priv->wizard_name && priv->autotitle)
-                create_title (MODEST_WIZARD_DIALOG (object));
+                create_title (wizard_dialog);
+                
+            connect_to_notebook_signals (wizard_dialog);
             
-            } break;
+            }break;
 
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -373,8 +424,14 @@ create_title (ModestWizardDialog *wizard_dialog)
 {
     gint pages, current;
     gchar *str = NULL;
-    ModestWizardDialogPrivate *priv = wizard_dialog->priv;
-    GtkNotebook *notebook = priv->notebook;
+    ModestWizardDialogPrivate *priv = NULL;
+    GtkNotebook *notebook = NULL;
+
+    g_return_if_fail (MODEST_IS_WIZARD_DIALOG(wizard_dialog));
+    g_return_if_fail (wizard_dialog->priv != NULL);
+
+    priv = wizard_dialog->priv;    
+    notebook = priv->notebook;
 
     if (!notebook)
         return;
@@ -502,6 +559,21 @@ modest_wizard_dialog_new (GtkWindow   *parent,
     return widget;
 }
 
+/**
+ * modest_wizard_dialog_force_title_update:
+ * @wizard_dialog: The wizard dialog
+ *
+ * Force the title to be rebuilt, for instance when you have added or 
+ * removed notebook pages. This function is not necessary when using GTK+ 2.10, 
+ * because that has GtkNotebook signals that will be used to update the title 
+ * automatically.
+ */
+void
+modest_wizard_dialog_force_title_update (ModestWizardDialog   *wizard_dialog)
+{
+       create_title (wizard_dialog);
+}
+
 static gboolean
 invoke_before_next_vfunc (ModestWizardDialog *wizard_dialog)
 {