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 {
25 public TreeSortable sorted_store;
28 store = new MovieListStore ();
30 // FIXME - fill store with test data
32 for (i = 0; i < 10; i++) {
34 m.title = "Test %d".printf (i);
36 m.rating = 10 * (i % 5) + i;
38 store.add (m, out iter);
42 var filtered_store = new TreeModelFilter (store, null);
45 sorted_store = new TreeModelSort.with_model (filtered_store);
48 tree = (TreeView) Hildon.gtk_tree_view_new_with_model (UIMode.NORMAL, sorted_store);
49 tree.set_headers_visible (false);
53 tree.set_rules_hint (true);
55 // Tree selection object
56 var selection = tree.get_selection ();
57 selection.set_mode (SelectionMode.SINGLE);
59 // Title column with poster
60 var title_column = new TreeViewColumn ();
61 title_column.set_title ("Movie");
62 title_column.set_sort_column_id (MovieListStore.Columns.TITLE);
63 title_column.set_reorderable (false);
64 title_column.set_sizing (TreeViewColumnSizing.AUTOSIZE);
65 title_column.set_expand (true);
67 // Add poster icon to column
68 var pixbuf_renderer = new CellRendererPixbuf ();
69 title_column.pack_start (pixbuf_renderer, false);
70 title_column.add_attribute (pixbuf_renderer, "pixbuf", MovieListStore.Columns.POSTER);
73 var renderer = new CellRendererText ();
74 renderer.set ("ellipsize", Pango.EllipsizeMode.END);
75 title_column.pack_start (renderer, true);
76 title_column.add_attribute (renderer, "text", MovieListStore.Columns.TITLE);
77 tree.append_column (title_column);
80 sorted_store.set_sort_column_id (MovieListStore.Columns.TITLE, SortType.ASCENDING);
83 renderer = new CellRendererText ();
84 var year_column = new TreeViewColumn.with_attributes ("Year", renderer, "text", MovieListStore.Columns.YEAR);
85 year_column.set_sort_column_id (MovieListStore.Columns.YEAR);
86 year_column.set_reorderable (false);
87 year_column.set_sort_order (SortType.DESCENDING);
88 tree.append_column (year_column);
91 renderer = new CellRendererText ();
92 var rating_column = new TreeViewColumn.with_attributes ("Rating", renderer, "text", MovieListStore.Columns.RATING);
93 rating_column.set_sort_column_id (MovieListStore.Columns.RATING);
94 rating_column.set_reorderable (false);
95 rating_column.set_sort_order (SortType.DESCENDING);
96 rating_column.set_cell_data_func (renderer, rating_data_func);
97 rating_column.xalign = (float) 1.0;
98 tree.append_column (rating_column);
101 private void rating_data_func (CellLayout cell_layout, CellRenderer cell, TreeModel model, TreeIter iter) {
104 model.get (iter, MovieListStore.Columns.RATING, out rating);
105 ((CellRendererText) cell).text = "%d.%d".printf (rating / 10, rating % 10);