2008-12-05 Claudio Saavedra <csaavedra@igalia.com>
authorClaudio Saavedra <csaavedra@igalia.com>
Fri, 5 Dec 2008 11:12:27 +0000 (11:12 +0000)
committerClaudio Saavedra <csaavedra@igalia.com>
Fri, 5 Dec 2008 11:12:27 +0000 (11:12 +0000)
* examples/hildon-wizard-dialog-example.c: (on_page_switch),
(some_page_func), (main): Update the example to use a
HildonWizardDialogPageFunc function.

* src/hildon-wizard-dialog-private.h: Add private data for
the HildonWizardDialogPageFunc function usage.

* src/hildon-wizard-dialog.c: (hildon_wizard_dialog_class_init),
(destroy), (hildon_wizard_dialog_init), (response),
(hildon_wizard_dialog_set_forward_page_func):
* src/hildon-wizard-dialog.h: Add a HildonWizardDialogPageFunc function,
that applications can use to stop a HildonWizardDialog to jump to
the next page.

Fixes: NB#94214 (No way to stop HildonWizardDialog from going to
next page)

ChangeLog
examples/hildon-wizard-dialog-example.c
src/hildon-wizard-dialog-private.h
src/hildon-wizard-dialog.c
src/hildon-wizard-dialog.h

index c07c5c2..9eb17db 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2008-12-05  Claudio Saavedra  <csaavedra@igalia.com>
+
+       * examples/hildon-wizard-dialog-example.c: (on_page_switch),
+       (some_page_func), (main): Update the example to use a
+       HildonWizardDialogPageFunc function.
+
+       * src/hildon-wizard-dialog-private.h: Add private data for
+       the HildonWizardDialogPageFunc function usage.
+
+       * src/hildon-wizard-dialog.c: (hildon_wizard_dialog_class_init),
+       (destroy), (hildon_wizard_dialog_init), (response),
+       (hildon_wizard_dialog_set_forward_page_func):
+       * src/hildon-wizard-dialog.h: Add a HildonWizardDialogPageFunc function,
+       that applications can use to stop a HildonWizardDialog to jump to
+       the next page.
+
+       Fixes: NB#94214 (No way to stop HildonWizardDialog from going to
+       next page)
+
 2008-12-04  Alberto Garcia  <agarcia@igalia.com>
 
        * src/hildon-program.h
index 51f3817..90f4f08 100644 (file)
@@ -24,6 +24,7 @@
 
 #include                                        <stdio.h>
 #include                                        <stdlib.h>
+#include                                        <string.h>
 #include                                        <glib.h>
 #include                                        <gtk/gtk.h>
 #include                                        "hildon.h"
@@ -43,11 +44,28 @@ on_page_switch (GtkNotebook *notebook,
     g_debug ("Page %d", num);
 
     if (num == 1) {
-        g_debug ("Making next insensitive! %d", num);
-        gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), HILDON_WIZARD_DIALOG_NEXT, FALSE);
+    /*     g_debug ("Making next insensitive! %d", num); */
+    /*     gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), HILDON_WIZARD_DIALOG_NEXT, FALSE); */
     }
-    
+
+    return TRUE;
+}
+
+static gboolean
+some_page_func (GtkNotebook *nb,
+                gint current,
+                gpointer userdata)
+{
+  HildonEntry *entry;
+
+  /* Validate data only for the third page. */
+  switch (current) {
+  case 2:
+    entry = HILDON_ENTRY (gtk_notebook_get_nth_page (nb, current));
+    return (strlen (hildon_entry_get_text (entry)) != 0);
+  default:
     return TRUE;
+  }
 }
 
 int
@@ -58,14 +76,19 @@ main (int argc, char **argv)
     GtkWidget *notebook = gtk_notebook_new ();
     GtkWidget *label_1 = gtk_label_new ("Page 1");
     GtkWidget *label_2 = gtk_label_new ("Page 2");
-    GtkWidget *label_3 = gtk_label_new ("Page 3");
+    GtkWidget *entry_3 = hildon_entry_new (HILDON_SIZE_AUTO);
+    hildon_entry_set_placeholder (HILDON_ENTRY (entry_3), " Write something to continue");
+    GtkWidget *label_4 = gtk_label_new ("Page 4");
 
     gtk_notebook_append_page (GTK_NOTEBOOK (notebook), label_1, NULL);
     gtk_notebook_append_page (GTK_NOTEBOOK (notebook), label_2, NULL);
-    gtk_notebook_append_page (GTK_NOTEBOOK (notebook), label_3, NULL);
+    gtk_notebook_append_page (GTK_NOTEBOOK (notebook), entry_3, NULL);
+    gtk_notebook_append_page (GTK_NOTEBOOK (notebook), label_4, NULL);
 
     GtkWidget *dialog = hildon_wizard_dialog_new (NULL, "Wizard", GTK_NOTEBOOK (notebook));
     g_signal_connect (G_OBJECT (notebook), "switch-page", G_CALLBACK (on_page_switch), dialog);
+    hildon_wizard_dialog_set_forward_page_func (HILDON_WIZARD_DIALOG (dialog),
+                                                some_page_func, NULL, NULL);
 
     gtk_widget_show_all (dialog);
     gtk_dialog_run (GTK_DIALOG (dialog));
index 97bec46..22437a5 100644 (file)
@@ -40,6 +40,10 @@ struct                                          _HildonWizardDialogPrivate
     gchar *wizard_name;
     GtkNotebook *notebook;
     gboolean autotitle;
+
+    HildonWizardDialogPageFunc forward_function;
+    gpointer forward_function_data;
+    GDestroyNotify forward_data_destroy;
 };
 
 G_END_DECLS
index fb89af8..78e250c 100644 (file)
@@ -80,6 +80,9 @@ hildon_wizard_dialog_get_property               (GObject *object,
 static void 
 finalize                                        (GObject *object);
 
+static void
+destroy                                         (GObject *object);
+
 static void 
 response                                        (HildonWizardDialog *wizard, 
                                                  gint response_id,
@@ -138,7 +141,7 @@ static void
 hildon_wizard_dialog_class_init                 (HildonWizardDialogClass *wizard_dialog_class)
 {
     GObjectClass *object_class = G_OBJECT_CLASS (wizard_dialog_class);
-
+    GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (wizard_dialog_class);
     parent_class = g_type_class_peek_parent (wizard_dialog_class);
 
     g_type_class_add_private (wizard_dialog_class, sizeof (HildonWizardDialogPrivate));
@@ -147,6 +150,7 @@ hildon_wizard_dialog_class_init                 (HildonWizardDialogClass *wizard
     object_class->set_property = hildon_wizard_dialog_set_property;
     object_class->get_property = hildon_wizard_dialog_get_property;
     object_class->finalize     = finalize;
+    gtk_object_class->destroy  = destroy;
 
     /**
      * HildonWizardDialog:wizard-name:
@@ -205,6 +209,25 @@ finalize                                        (GObject *object)
         G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
+static void
+destroy                                         (GObject *object)
+{
+    HildonWizardDialogPrivate *priv = HILDON_WIZARD_DIALOG_GET_PRIVATE (object);
+
+    g_assert (priv);
+
+    if (priv->forward_function)
+    {
+      if (priv->forward_function_data &&
+         priv->forward_data_destroy)
+       priv->forward_data_destroy (priv->forward_function_data);
+
+      priv->forward_function = NULL;
+      priv->forward_function_data = NULL;
+      priv->forward_data_destroy = NULL;
+    }
+}
+
 /* Disable or enable the Previous, Next and Finish buttons */
 static void
 make_buttons_sensitive                          (HildonWizardDialog *wizard_dialog,
@@ -242,6 +265,10 @@ hildon_wizard_dialog_init                       (HildonWizardDialog *wizard_dial
     priv->wizard_name = NULL;
     priv->autotitle = TRUE;
 
+    priv->forward_function = NULL;
+    priv->forward_function_data = NULL;
+    priv->forward_data_destroy = NULL;
+
     /* Add response buttons: finish, previous, next */
     gtk_dialog_add_button (dialog, _("wdgt_bd_finish"), HILDON_WIZARD_DIALOG_FINISH);
     gtk_dialog_add_button (dialog, _("wdgt_bd_previous"), HILDON_WIZARD_DIALOG_PREVIOUS);
@@ -426,15 +453,19 @@ response                                        (HildonWizardDialog *wizard_dial
             break;
 
         case HILDON_WIZARD_DIALOG_NEXT:
-            ++current;
-            is_last = (current == last);
-            is_first = (current == 0);
-            make_buttons_sensitive (wizard_dialog,
-                                    !is_first, !is_first, !is_last);
-            gtk_notebook_next_page (notebook); /* go to next page */
+
+            if (priv->forward_function &&
+                (*priv->forward_function) (priv->notebook, current, priv->forward_function_data)) {
+              ++current;
+              is_last = (current == last);
+              is_first = (current == 0);
+              make_buttons_sensitive (wizard_dialog,
+                                      !is_first, !is_first, !is_last);
+              gtk_notebook_next_page (notebook); /* go to next page */
+            }
             break;
 
-        case HILDON_WIZARD_DIALOG_FINISH:      
+        case HILDON_WIZARD_DIALOG_FINISH:
             return;
 
     }
@@ -481,3 +512,36 @@ hildon_wizard_dialog_new                        (GtkWindow *parent,
     return widget;
 }
 
+/**
+ * hildon_wizard_dialog_set_forward_page_func:
+ * @dialog: a #HildonWizardDialog
+ * @page_func: the #HildonWizardDialogPageFunc
+ * @data: user data for @page_func
+ * @destroy: destroy notifier for @data
+ *
+ * Sets the page forwarding function to be @page_func. This function
+ * will be used to determine whether it is possible to go to the next page
+ * when the user presses the forward button. Setting @page_func to %NULL
+ * wil make the wizard to simply go always to the next page.
+ *
+ * Since: 2.2
+ **/
+void
+hildon_wizard_dialog_set_forward_page_func      (HildonWizardDialog *wizard_dialog,
+                                                 HildonWizardDialogPageFunc page_func,
+                                                 gpointer data,
+                                                 GDestroyNotify destroy)
+{
+  g_return_if_fail (HILDON_IS_WIZARD_DIALOG (wizard_dialog));
+
+  HildonWizardDialogPrivate *priv = HILDON_WIZARD_DIALOG_GET_PRIVATE (wizard_dialog);
+
+  if (priv->forward_data_destroy &&
+      priv->forward_function_data) {
+    (*priv->forward_data_destroy) (priv->forward_function_data);
+  }
+
+  priv->forward_function = page_func;
+  priv->forward_function_data = data;
+  priv->forward_data_destroy = destroy;
+}
index 67f08f5..444e744 100644 (file)
@@ -73,6 +73,8 @@ struct                                          _HildonWizardDialogClass
     GtkDialogClass parent_class;
 };
 
+typedef gboolean (*HildonWizardDialogPageFunc) (GtkNotebook *notebook, gint current_page, gpointer data);
+
 GType G_GNUC_CONST
 hildon_wizard_dialog_get_type                   (void);
 
@@ -81,6 +83,12 @@ hildon_wizard_dialog_new                        (GtkWindow *parent,
                                                  const char *wizard_name,
                                                  GtkNotebook *notebook);
 
+void
+hildon_wizard_dialog_set_forward_page_func      (HildonWizardDialog *dialog,
+                                                 HildonWizardDialogPageFunc pagefunc,
+                                                 gpointer data,
+                                                 GDestroyNotify destroy);
+
 G_END_DECLS
 
 #endif                                          /* __HILDON_WIZARD_DIALOG_H__ */