1 /* This file is part of Cinaest.
3 * Copyright (C) 2009 Philipp Zabel
5 * Cinaest is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * Cinaest is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with Cinaest. If not, see <http://www.gnu.org/licenses/>.
22 public class MovieListView : PannableArea {
23 private enum Columns {
32 public TreeSortable sorted_store;
35 store = new ListStore (3, typeof (string), typeof (int), typeof (int));
37 // FIXME - fill store with test data
39 for (i = 0; i < 10; i++) {
42 store.append (out iter);
43 store.set_value (iter, Columns.TITLE, "Test %d".printf (i));
44 store.set_value (iter, Columns.YEAR, 2000 - i);
45 store.set_value (iter, Columns.RATING, 10 * (i % 5) + i);
49 var filtered_store = new TreeModelFilter (store, null);
52 sorted_store = new TreeModelSort.with_model (filtered_store);
55 tree = (TreeView) Hildon.gtk_tree_view_new_with_model (UIMode.NORMAL, sorted_store);
56 tree.set_headers_visible (false);
60 tree.set_rules_hint (true);
62 // Tree selection object
63 var selection = tree.get_selection ();
64 selection.set_mode (SelectionMode.SINGLE);
67 var title_column = new TreeViewColumn ();
68 title_column.set_title ("Movie");
69 title_column.set_sort_column_id (Columns.TITLE);
70 title_column.set_reorderable (false);
71 title_column.set_sizing (TreeViewColumnSizing.AUTOSIZE);
72 title_column.set_expand (true);
75 var renderer = new CellRendererText ();
76 renderer.set ("ellipsize", Pango.EllipsizeMode.END);
77 title_column.pack_start (renderer, true);
78 title_column.add_attribute (renderer, "text", Columns.TITLE);
79 tree.append_column (title_column);
82 sorted_store.set_sort_column_id (Columns.TITLE, SortType.ASCENDING);
85 renderer = new CellRendererText ();
86 var year_column = new TreeViewColumn.with_attributes ("Year", renderer, "text", Columns.YEAR);
87 year_column.set_sort_column_id (Columns.YEAR);
88 year_column.set_reorderable (false);
89 year_column.set_sort_order (SortType.DESCENDING);
90 tree.append_column (year_column);
93 renderer = new CellRendererText ();
94 var rating_column = new TreeViewColumn.with_attributes ("Rating", renderer, "text", Columns.RATING);
95 rating_column.set_sort_column_id (Columns.RATING);
96 rating_column.set_reorderable (false);
97 rating_column.set_sort_order (SortType.DESCENDING);
98 rating_column.set_cell_data_func (renderer, rating_data_func);
99 rating_column.xalign = (float) 1.0;
100 tree.append_column (rating_column);
103 private void rating_data_func (CellLayout cell_layout, CellRenderer cell, TreeModel model, TreeIter iter) {
106 model.get (iter, MovieListStore.Columns.RATING, out rating);
107 ((CellRendererText) cell).text = "%d.%d".printf (rating / 10, rating % 10);