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 ();
31 var filtered_store = new TreeModelFilter (store, null);
34 sorted_store = new TreeModelSort.with_model (filtered_store);
37 tree = (TreeView) Hildon.gtk_tree_view_new_with_model (UIMode.NORMAL, sorted_store);
38 tree.set_headers_visible (false);
42 tree.set_rules_hint (true);
44 // Tree selection object
45 var selection = tree.get_selection ();
46 selection.set_mode (SelectionMode.SINGLE);
48 // Title column with poster
49 var title_column = new TreeViewColumn ();
50 title_column.set_title ("Movie");
51 title_column.set_sort_column_id (MovieListStore.Columns.TITLE);
52 title_column.set_reorderable (false);
53 title_column.set_sizing (TreeViewColumnSizing.AUTOSIZE);
54 title_column.set_expand (true);
56 // Add poster icon to column
57 var pixbuf_renderer = new CellRendererPixbuf ();
58 title_column.pack_start (pixbuf_renderer, false);
59 title_column.add_attribute (pixbuf_renderer, "pixbuf", MovieListStore.Columns.POSTER);
62 var renderer = new CellRendererText ();
63 renderer.set ("ellipsize", Pango.EllipsizeMode.END);
64 title_column.pack_start (renderer, true);
65 title_column.add_attribute (renderer, "text", MovieListStore.Columns.TITLE);
66 tree.append_column (title_column);
69 sorted_store.set_sort_column_id (MovieListStore.Columns.TITLE, SortType.ASCENDING);
72 renderer = new CellRendererText ();
73 var year_column = new TreeViewColumn.with_attributes ("Year", renderer, "text", MovieListStore.Columns.YEAR);
74 year_column.set_sort_column_id (MovieListStore.Columns.YEAR);
75 year_column.set_reorderable (false);
76 year_column.set_sort_order (SortType.DESCENDING);
77 tree.append_column (year_column);
80 renderer = new CellRendererText ();
81 var rating_column = new TreeViewColumn.with_attributes ("Rating", renderer, "text", MovieListStore.Columns.RATING);
82 rating_column.set_sort_column_id (MovieListStore.Columns.RATING);
83 rating_column.set_reorderable (false);
84 rating_column.set_sort_order (SortType.DESCENDING);
85 rating_column.set_cell_data_func (renderer, rating_data_func);
86 rating_column.xalign = (float) 1.0;
87 tree.append_column (rating_column);
90 private void rating_data_func (CellLayout cell_layout, CellRenderer cell, TreeModel model, TreeIter iter) {
93 model.get (iter, MovieListStore.Columns.RATING, out rating);
94 ((CellRendererText) cell).text = "%d.%d".printf (rating / 10, rating % 10);