Adding example for hildon note. Fixing buggy code in hildon-note new object creation.
[hildon] / examples / hildon-note / hildon-note-example.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <glib.h>
4 #include <gtk/gtk.h>
5 #include "hildon-widgets/hildon-window.h"
6 #include "hildon-widgets/hildon-program.h"
7 #include "hildon-widgets/hildon-note.h"
8
9 static gboolean
10 on_information_clicked (GtkWidget *widget)
11 {
12     HildonNote* note = HILDON_NOTE (hildon_note_new_information (NULL, 
13             "This is a really really really long text that should " 
14             "get wrapped but never truncated because truncating stuff "
15             "automatically is really really bad! Blah blah blah!"));
16
17     gtk_dialog_run (GTK_DIALOG (note));
18     gtk_object_destroy (GTK_OBJECT (note));
19     
20     return TRUE;
21 }
22
23 static gboolean
24 on_confirmation_clicked (GtkWidget *widget)
25 {
26     HildonNote* note = HILDON_NOTE (hildon_note_new_confirmation (NULL, 
27             "Do you want to confirm?!"));
28
29     gtk_dialog_run (GTK_DIALOG (note));
30     gtk_object_destroy (GTK_OBJECT (note));
31     
32     return TRUE;
33 }
34
35 static gboolean
36 on_progress_clicked (GtkWidget *widget)
37 {
38     GtkProgressBar *bar = GTK_PROGRESS_BAR (gtk_progress_bar_new ());
39     HildonNote *note = HILDON_NOTE (hildon_note_new_cancel_with_progress_bar (NULL, 
40                 "Do you want to foo bar?", bar));
41
42     gtk_dialog_run (GTK_DIALOG (note));
43     gtk_object_destroy (GTK_OBJECT (note));
44
45     return TRUE;
46 }
47
48 int
49 main (int argc, char **args)
50 {
51     gtk_init (&argc, &args);
52     
53     HildonProgram *program = hildon_program_get_instance ();
54
55     GtkWidget *window = hildon_window_new ();
56     hildon_program_add_window (program, HILDON_WINDOW (window));    
57
58     gtk_container_set_border_width (GTK_CONTAINER (window), 6);
59
60     GtkVBox *vbox = GTK_VBOX (gtk_vbox_new (6, FALSE));
61     GtkButton *button1 = GTK_BUTTON (gtk_button_new_with_label ("Information note"));
62     g_signal_connect (G_OBJECT (button1), "clicked", G_CALLBACK (on_information_clicked), NULL);
63
64     GtkButton *button2 = GTK_BUTTON (gtk_button_new_with_label ("Confirmation note"));
65     g_signal_connect (G_OBJECT (button2), "clicked", G_CALLBACK (on_confirmation_clicked), NULL);
66
67     GtkButton *button3 = GTK_BUTTON (gtk_button_new_with_label ("Progress note"));
68     g_signal_connect (G_OBJECT (button3), "clicked", G_CALLBACK (on_progress_clicked), NULL);
69
70     g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL);
71
72     gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (button1), TRUE, TRUE, 0);
73     gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (button2), TRUE, TRUE, 0);
74     gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (button3), TRUE, TRUE, 0);
75
76     gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (vbox));
77
78     gtk_widget_show_all (GTK_WIDGET (window));
79     
80     gtk_main ();
81
82     return 0;
83 }
84
85