/* This file is part of Cinaest. * * Copyright (C) 2009 Philipp Zabel * * Cinaest is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Cinaest is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Cinaest. If not, see . */ using Gtk; using Hildon; public class MovieListView : PannableArea { public MovieListStore store; TreeView tree; public TreeSortable sorted_store; construct { store = new MovieListStore (); // Add filter wrapper var filtered_store = new TreeModelFilter (store, null); // Add sort wrapper sorted_store = new TreeModelSort.with_model (filtered_store); // Tree View tree = (TreeView) Hildon.gtk_tree_view_new_with_model (UIMode.NORMAL, sorted_store); tree.set_headers_visible (false); add (tree); tree.set_rules_hint (true); // Tree selection object var selection = tree.get_selection (); selection.set_mode (SelectionMode.SINGLE); // Title column with poster var title_column = new TreeViewColumn (); title_column.set_title (_("Movie")); title_column.set_sort_column_id (MovieListStore.Columns.TITLE); title_column.set_reorderable (false); title_column.set_sizing (TreeViewColumnSizing.AUTOSIZE); title_column.set_expand (true); // Add poster icon to column var pixbuf_renderer = new CellRendererPixbuf (); title_column.pack_start (pixbuf_renderer, false); title_column.add_attribute (pixbuf_renderer, "pixbuf", MovieListStore.Columns.POSTER); // Add text to column var renderer = new CellRendererText (); renderer.set ("ellipsize", Pango.EllipsizeMode.END); title_column.pack_start (renderer, true); title_column.add_attribute (renderer, "text", MovieListStore.Columns.TITLE); tree.append_column (title_column); // Sort by title sorted_store.set_sort_column_id (MovieListStore.Columns.TITLE, SortType.ASCENDING); // Year column renderer = new CellRendererText (); var year_column = new TreeViewColumn.with_attributes (_("Year"), renderer, "text", MovieListStore.Columns.YEAR); year_column.set_sort_column_id (MovieListStore.Columns.YEAR); year_column.set_reorderable (false); year_column.set_sort_order (SortType.DESCENDING); tree.append_column (year_column); // Rating column renderer = new CellRendererText (); var rating_column = new TreeViewColumn.with_attributes (_("Rating"), renderer, "text", MovieListStore.Columns.RATING); rating_column.set_sort_column_id (MovieListStore.Columns.RATING); rating_column.set_reorderable (false); rating_column.set_sort_order (SortType.DESCENDING); rating_column.set_cell_data_func (renderer, rating_data_func); rating_column.xalign = (float) 1.0; tree.append_column (rating_column); } private void rating_data_func (CellLayout cell_layout, CellRenderer cell, TreeModel model, TreeIter iter) { int rating; model.get (iter, MovieListStore.Columns.RATING, out rating); ((CellRendererText) cell).text = "%d.%d".printf (rating / 10, rating % 10); } }