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 SourceListView : PannableArea {
25 public signal void source_activated (MovieSource source);
27 public SourceListView (List<MovieSource> list) {
29 var store = new ListStore (3, typeof (string), typeof (string), typeof (MovieSource));
30 foreach (MovieSource source in list) {
32 store.append (out iter);
33 store.set (iter, 0, source.get_name (), 1, source.get_description (), 2, source);
37 tree = (TreeView) Hildon.gtk_tree_view_new_with_model (UIMode.NORMAL, 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);
49 var title_column = new TreeViewColumn ();
50 title_column.set_title (_("Source"));
51 title_column.set_reorderable (false);
52 title_column.set_sizing (TreeViewColumnSizing.AUTOSIZE);
53 title_column.set_expand (true);
56 var vbox_renderer = new CellRendererVBox ();
58 var renderer = new CellRendererText ();
59 vbox_renderer.append (renderer, true);
60 vbox_renderer.set_data ("name", renderer);
63 renderer = new CellRendererText ();
64 renderer.set ("ellipsize", Pango.EllipsizeMode.END);
66 Pango.AttrList attr_list = new Pango.AttrList ();
67 var style = Gtk.rc_get_style_by_paths (this.get_settings (), "SmallSystemFont", null, typeof (void));
69 Pango.Attribute attr_font_desc = Pango.attr_font_desc_new (style.font_desc.copy ());
70 attr_list.insert ((owned) attr_font_desc);
72 Pango.Attribute attr_font_scale = Pango.attr_scale_new (Pango.Scale.SMALL);
73 attr_list.insert ((owned) attr_font_scale);
76 if (!style.lookup_color ("SecondaryTextColor", out color)) {
77 Gdk.Color.parse ("grey", out color);
79 Pango.Attribute attr_color = Pango.attr_foreground_new (color.red, color.green, color.blue);
80 attr_list.insert ((owned) attr_color);
81 renderer.attributes = attr_list;
83 vbox_renderer.append (renderer, true);
84 vbox_renderer.set_data ("description", renderer);
86 title_column.pack_start (vbox_renderer, true);
87 title_column.set_cell_data_func (vbox_renderer, vbox_data_func);
89 tree.append_column (title_column);
92 tree.row_activated.connect (on_row_activated);
95 private void on_row_activated (TreeView tree, TreePath path_, TreeViewColumn column) {
96 TreePath path = path_.copy (); // FIXME - calling model.get_iter with path_ directly causes a C qualifier warning
97 TreeModel model = tree.model;
100 if (model.get_iter (out iter, path)) {
102 model.get (iter, 2, out source);
103 source_activated (source);
107 private void vbox_data_func (CellLayout cell_layout, CellRenderer cell, TreeModel model, TreeIter iter) {
108 CellRendererText renderer;
112 model.get (iter, 0, out name, 1, out description);
114 renderer = (CellRendererText) cell.get_data ("name");
115 renderer.text = name;
117 renderer = (CellRendererText) cell.get_data ("description");
118 renderer.text = description;