Make sure that all timeouts in HildonBanner are removed
[hildon] / examples / hildon-touch-selector-normal-mode-example.c
1 /*
2  * This file is a part of hildon examples
3  *
4  * Copyright (C) 2009 Nokia Corporation, all rights reserved.
5  *
6  * Author: Alejandro Pinheiro <apinheiro@igalia.com>
7  * Based on hildon-touch-selector-example.c
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; version 2.1 of
12  * the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22  * 02110-1301 USA
23  *
24  */
25
26 #include                                        <glib.h>
27 #include                                        <gtk/gtk.h>
28 #include                                        <hildon/hildon.h>
29
30 static GtkWidget *create_selector ();
31 static GtkWidget *get_visible_content (GtkWidget * window);
32
33 static GtkWindow *parent_window = NULL;
34
35 static GtkWidget *label = NULL;
36
37 static void
38 value_changed (HildonPickerButton * button,
39                gpointer user_data)
40 {
41   HildonTouchSelector *selector;
42   gchar *aux_string = NULL;
43   GtkTreePath *path = NULL;
44   GtkTreeModel *model = NULL;
45   GtkTreeIter iter;
46
47   selector = hildon_picker_button_get_selector (button);
48   model = hildon_touch_selector_get_model (selector, 0);
49   path = hildon_touch_selector_get_last_activated_row (selector, 0);
50
51   if (path != NULL) {
52     gtk_tree_model_get_iter (model, &iter, path);
53     gtk_tree_model_get (model, &iter, 0, &aux_string, -1);
54
55     gtk_label_set_text (GTK_LABEL (label), aux_string);
56   }
57
58   gtk_tree_path_free (path);
59 }
60
61 static GtkWidget *
62 create_selector ()
63 {
64   GtkWidget *selector = NULL;
65   GSList *icon_list = NULL;
66   GtkListStore *store_icons = NULL;
67   GSList *item = NULL;
68   GtkCellRenderer *renderer = NULL;
69   HildonTouchSelectorColumn *column = NULL;
70
71   selector = hildon_touch_selector_new ();
72
73   icon_list = gtk_stock_list_ids ();
74
75   store_icons = gtk_list_store_new (1, G_TYPE_STRING);
76   for (item = icon_list; item; item = g_slist_next (item)) {
77     GtkTreeIter iter;
78     gchar *label = item->data;
79
80     gtk_list_store_append (store_icons, &iter);
81     gtk_list_store_set (store_icons, &iter, 0, label, -1);
82     g_free (label);
83   }
84   g_slist_free (icon_list);
85
86   renderer = gtk_cell_renderer_pixbuf_new ();
87   gtk_cell_renderer_set_fixed_size (renderer, -1, 100);
88
89   column = hildon_touch_selector_append_column (HILDON_TOUCH_SELECTOR (selector),
90                                                 GTK_TREE_MODEL (store_icons),
91                                                 renderer, "stock-id", 0, NULL);
92   g_object_set (G_OBJECT (column), "text-column", 0, NULL);
93
94   hildon_touch_selector_set_hildon_ui_mode (HILDON_TOUCH_SELECTOR (selector),
95                                             HILDON_UI_MODE_NORMAL);
96
97
98   return selector;
99 }
100
101 static GtkWidget *
102 get_visible_content (GtkWidget * window)
103 {
104   GtkWidget *result = NULL;
105   GtkWidget *button = NULL;
106   GtkWidget *selector;
107
108   label = gtk_label_new ("Here we are going to put the selection");
109
110   button = hildon_picker_button_new (HILDON_SIZE_AUTO, HILDON_BUTTON_ARRANGEMENT_VERTICAL);
111   hildon_button_set_title (HILDON_BUTTON (button), "Click me..");
112   selector = create_selector ();
113   hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button),
114                                      HILDON_TOUCH_SELECTOR (selector));
115
116   g_signal_connect (G_OBJECT (button), "value-changed",
117                     G_CALLBACK (value_changed), window);
118
119   result = gtk_vbox_new (FALSE, 6);
120
121   gtk_container_add (GTK_CONTAINER (result), button);
122   gtk_container_add (GTK_CONTAINER (result), label);
123
124   return result;
125 }
126
127 int
128 main (int argc, char **argv)
129 {
130   HildonProgram *program = NULL;
131   GtkWidget *window = NULL;
132
133   hildon_gtk_init (&argc, &argv);
134
135   program = hildon_program_get_instance ();
136   g_set_application_name
137     ("hildon-touch-selector normal mode example");
138
139   window = hildon_stackable_window_new ();
140   parent_window = GTK_WINDOW (window);
141   hildon_program_add_window (program, HILDON_WINDOW (window));
142
143   gtk_container_set_border_width (GTK_CONTAINER (window), 6);
144
145   GtkWidget *vbox = get_visible_content (window);
146
147   gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (vbox));
148
149   g_signal_connect (G_OBJECT (window), "destroy",
150                     G_CALLBACK (gtk_main_quit), NULL);
151   gtk_widget_show_all (GTK_WIDGET (window));
152
153   gtk_main ();
154
155   return 0;
156 }