Movie list view: remove test data
[cinaest] / src / movie-list-view.vala
1 /* This file is part of Cinaest.
2  *
3  * Copyright (C) 2009 Philipp Zabel
4  *
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.
9  *
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.
14  *
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/>.
17  */
18
19 using Gtk;
20 using Hildon;
21
22 public class MovieListView : PannableArea {
23         MovieListStore store;
24         TreeView tree;
25         public TreeSortable sorted_store;
26
27         construct {
28                 store = new MovieListStore ();
29
30                 // Add filter wrapper
31                 var filtered_store = new TreeModelFilter (store, null);
32
33                 // Add sort wrapper
34                 sorted_store = new TreeModelSort.with_model (filtered_store);
35
36                 // Tree View
37                 tree = (TreeView) Hildon.gtk_tree_view_new_with_model (UIMode.NORMAL, sorted_store);
38                 tree.set_headers_visible (false);
39
40                 add (tree);
41
42                 tree.set_rules_hint (true);
43
44                 // Tree selection object
45                 var selection = tree.get_selection ();
46                 selection.set_mode (SelectionMode.SINGLE);
47
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);
55
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);
60
61                 // Add text to column
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);
67
68                 // Sort by title
69                 sorted_store.set_sort_column_id (MovieListStore.Columns.TITLE, SortType.ASCENDING);
70
71                 // Year column
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);
78
79                 // Rating 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);
88         }
89
90         private void rating_data_func (CellLayout cell_layout, CellRenderer cell, TreeModel model, TreeIter iter) {
91                 int rating;
92
93                 model.get (iter, MovieListStore.Columns.RATING, out rating);
94                 ((CellRendererText) cell).text = "%d.%d".printf (rating / 10, rating % 10);
95         }
96 }