2 * This file is a part of hildon
4 * Copyright (C) 2007 Nokia Corporation, all rights reserved.
6 * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
7 * Author: Xan Lopez <xan.lopez@nokia.com>
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.
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.
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
27 #include "hildon-bread-crumb-trail.h"
28 #include <sys/types.h>
33 #include <hildon/hildon.h>
47 populate_store (GtkListStore *store,
54 struct stat stat_info;
55 GdkPixbuf *pixbuf = NULL;
57 dir = g_dir_open (path, 0, &error);
60 g_debug ("Error populating store: %s", error->message);
65 while ((item = (gchar*)g_dir_read_name (dir)) != NULL)
67 gchar *file_path = g_strconcat (path, "/", item, NULL);
69 if (stat (file_path, &stat_info) == -1)
71 g_debug ("error retrieving stat info for %s", item);
76 gtk_list_store_append (store, &iter);
78 if (S_ISDIR (stat_info.st_mode))
79 pixbuf = gdk_pixbuf_new_from_file ("./gnome-fs-directory.png", NULL);
81 pixbuf = gdk_pixbuf_new_from_file ("./gnome-mime-text.png", NULL);
83 gtk_list_store_set (store, &iter,
86 IS_DIR_COL, S_ISDIR (stat_info.st_mode) ? TRUE : FALSE,
89 g_object_unref (pixbuf);
98 free_id (gpointer data)
100 g_debug ("Freeing ID data");
105 row_activated_cb (GtkTreeView *treeview,
107 GtkTreeViewColumn *column,
108 HildonBreadCrumbTrail *bct)
110 gchar *text = NULL, *new_root;
115 model = gtk_tree_view_get_model (treeview);
116 gtk_tree_model_get_iter (model, &iter, path);
117 gtk_tree_model_get (model, &iter,
122 if (is_dir == FALSE) goto out;
124 g_debug ("Clicked %s", text);
126 new_root = g_strconcat (g_str_equal (current_root, "/")? "" : current_root, "/", text, NULL);
127 gtk_list_store_clear (GTK_LIST_STORE (model));
128 populate_store (GTK_LIST_STORE (model), new_root);
130 hildon_bread_crumb_trail_push_text (bct, text, new_root, (GDestroyNotify)free_id);
134 g_free (current_root);
137 current_root = g_strdup (new_root);
144 crumb_clicked_cb (HildonBreadCrumbTrail *bct, gpointer id)
147 gchar *text = (gchar*)id;
149 g_debug ("item %s clicked", text);
150 model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
151 gtk_list_store_clear (GTK_LIST_STORE (model));
152 populate_store (GTK_LIST_STORE (model), text);
154 g_free (current_root);
155 current_root = g_strdup (text);
158 int main (int argc, char **argv)
161 HildonProgram *program;
164 GtkWidget *window, *scrolled_window, *vbox, *bct;
165 GtkCellRenderer *renderer;
166 GtkTreeViewColumn *column;
168 gtk_init (&argc, &argv);
172 program = hildon_program_get_instance ();
173 window = hildon_window_new ();
174 hildon_program_add_window (program, HILDON_WINDOW (window));
176 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
178 gtk_container_set_border_width (GTK_CONTAINER (window), 2);
179 gtk_window_set_default_size (GTK_WINDOW (window), 400, 600);
180 g_signal_connect (window, "delete-event", gtk_main_quit, NULL);
182 vbox = gtk_vbox_new (FALSE, 3);
183 gtk_container_add (GTK_CONTAINER (window), vbox);
184 gtk_widget_show (vbox);
186 current_root = g_strdup ("/");
188 bct = hildon_bread_crumb_trail_new ();
189 g_signal_connect (bct, "crumb-clicked", G_CALLBACK (crumb_clicked_cb), NULL);
190 gtk_box_pack_start (GTK_BOX (vbox), bct, FALSE, FALSE, 0);
191 gtk_widget_show (bct);
193 hildon_bread_crumb_trail_push_text (HILDON_BREAD_CRUMB_TRAIL (bct), "/",
194 g_strdup ("/"), (GDestroyNotify)free_id);
197 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
198 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
199 GTK_POLICY_AUTOMATIC,
200 GTK_POLICY_AUTOMATIC);
201 store = gtk_list_store_new (N_COLS, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_BOOLEAN);
202 populate_store (store, "/");
203 treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
204 g_signal_connect (treeview, "row-activated", G_CALLBACK (row_activated_cb), bct);
206 renderer = gtk_cell_renderer_pixbuf_new ();
207 column = gtk_tree_view_column_new_with_attributes ("Icon",
211 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
213 renderer = gtk_cell_renderer_text_new ();
214 column = gtk_tree_view_column_new_with_attributes ("Name",
218 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
220 gtk_container_add (GTK_CONTAINER (scrolled_window), treeview);
221 gtk_widget_show (treeview);
222 gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 0);
223 gtk_widget_show (scrolled_window);
225 gtk_widget_show (window);