Release 2.1.96-6
[hildon] / examples / hildon-wizard-dialog-example.c
1 /*
2  * This file is a part of hildon examples
3  *
4  * Copyright (C) 2005, 2006, 2007, 2009 Nokia Corporation, all rights reserved.
5  *
6  * Author: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation; version 2.1 of
11  * the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  *
23  */
24
25 #include                                        <stdio.h>
26 #include                                        <stdlib.h>
27 #include                                        <string.h>
28 #include                                        <glib.h>
29 #include                                        <gtk/gtk.h>
30 #include                                        <hildon/hildon.h>
31
32 gboolean
33 on_page_switch (GtkNotebook *notebook, 
34                 GtkNotebookPage *page, 
35                 guint num,
36                 HildonWizardDialog *dialog);
37
38 gboolean
39 on_page_switch (GtkNotebook *notebook, 
40                 GtkNotebookPage *page, 
41                 guint num,
42                 HildonWizardDialog *dialog)
43 {
44     g_debug ("Page %d", num);
45
46     if (num == 1) {
47     /*     g_debug ("Making next insensitive! %d", num); */
48     /*     gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), HILDON_WIZARD_DIALOG_NEXT, FALSE); */
49     }
50
51     return TRUE;
52 }
53
54 static gboolean
55 some_page_func (GtkNotebook *nb,
56                 gint current,
57                 gpointer userdata)
58 {
59   GtkEntry *entry;
60
61   /* Validate data only for the third page. */
62   switch (current) {
63   case 2:
64     entry = GTK_ENTRY (gtk_notebook_get_nth_page (nb, current));
65     return (strlen (gtk_entry_get_text (entry)) != 0);
66   default:
67     return TRUE;
68   }
69 }
70
71 int
72 main (int argc, char **argv)
73 {
74     hildon_gtk_init (&argc, &argv);
75
76     GtkWidget *notebook = gtk_notebook_new ();
77     GtkWidget *label_1 = gtk_label_new ("Page 1");
78     GtkWidget *label_2 = gtk_label_new ("Page 2");
79     GtkWidget *entry_3 = hildon_entry_new (HILDON_SIZE_AUTO);
80     hildon_gtk_entry_set_placeholder_text (GTK_ENTRY (entry_3), " Write something to continue");
81     GtkWidget *label_4 = gtk_label_new ("Page 4");
82
83     gtk_notebook_append_page (GTK_NOTEBOOK (notebook), label_1, NULL);
84     gtk_notebook_append_page (GTK_NOTEBOOK (notebook), label_2, NULL);
85     gtk_notebook_append_page (GTK_NOTEBOOK (notebook), entry_3, NULL);
86     gtk_notebook_append_page (GTK_NOTEBOOK (notebook), label_4, NULL);
87
88     GtkWidget *dialog = hildon_wizard_dialog_new (NULL, "Wizard", GTK_NOTEBOOK (notebook));
89     g_signal_connect (G_OBJECT (notebook), "switch-page", G_CALLBACK (on_page_switch), dialog);
90     hildon_wizard_dialog_set_forward_page_func (HILDON_WIZARD_DIALOG (dialog),
91                                                 some_page_func, NULL, NULL);
92
93     gtk_widget_show_all (dialog);
94     gtk_dialog_run (GTK_DIALOG (dialog));
95     
96     return 0;
97 }
98
99