Make sure that all timeouts in HildonBanner are removed
[hildon] / examples / hildon-pannable-area-tree-view-example.c
1 /*
2  * This file is a part of hildon examples
3  *
4  * Copyright (C) 2008 Nokia Corporation, all rights reserved.
5  *
6  * Author: Karl Lattimer <karl.lattimer@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                                        <glib.h>
28 #include                                        <gtk/gtk.h>
29 #include                                        <hildon/hildon.h>
30
31 enum { TEXT_COLUMN, N_COLUMNS };
32
33 static void
34 get_sawtooth_label (gchar **label, guint num)
35 {
36   static gchar *sawtooth = NULL;
37   gchar *label_aux, *sawtooth_aux;
38   
39   if (num % 5 != 0) {
40     sawtooth_aux = g_strconcat (" ", sawtooth, NULL);
41     g_free (sawtooth);
42     
43     sawtooth = sawtooth_aux;
44   } else {
45     if (sawtooth)
46       g_free (sawtooth);
47
48     sawtooth = g_strdup (" ");
49   }
50   
51   label_aux = g_strconcat (sawtooth, *label, NULL);
52   g_free (*label);
53   
54   *label = label_aux;
55 }
56
57 int
58 main (int argc, char **argv)
59 {
60     int i;
61     HildonProgram *program;
62     GtkWidget *window, *tv, *panarea;
63     GtkTreeViewColumn *col;
64     GtkCellRenderer *renderer;
65     GtkListStore *store;
66
67     hildon_gtk_init (&argc, &argv);
68
69     program = hildon_program_get_instance ();
70
71     /* Create the main window */
72     window = hildon_window_new ();
73     hildon_program_add_window (program, HILDON_WINDOW (window));
74
75     gtk_container_set_border_width (GTK_CONTAINER (window), 5);
76
77     /* Create a treeview */
78     tv = gtk_tree_view_new ();
79     renderer = gtk_cell_renderer_text_new ();
80     col = gtk_tree_view_column_new_with_attributes ("Title", renderer, "text", TEXT_COLUMN, NULL);
81     gtk_tree_view_append_column (GTK_TREE_VIEW(tv), col);
82
83     /* Add some rows to the treeview */
84     store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING);
85     for (i = 0; i < 100; i++) {
86             GtkTreeIter iter;
87             gchar *label = g_strdup_printf ("Row number %d", i);
88             
89             get_sawtooth_label (&label, i);
90
91             gtk_list_store_append (store, &iter);
92             gtk_list_store_set (store, &iter, TEXT_COLUMN, label, -1);
93             g_free (label);
94     }
95     gtk_tree_view_set_model (GTK_TREE_VIEW (tv), GTK_TREE_MODEL (store));
96     g_object_unref (store);
97
98     /* Put everything in a pannable area */
99     panarea = hildon_pannable_area_new ();
100     gtk_container_add (GTK_CONTAINER (panarea), GTK_WIDGET (tv));
101     gtk_container_add (GTK_CONTAINER (window), panarea);
102
103     g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL);
104
105     gtk_widget_show_all (GTK_WIDGET (window));
106
107     gtk_main ();
108
109     return 0;
110 }