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 {
26 public signal void source_activated (MovieSource source);
28 public SourceListView (List<MovieSource> list) {
30 store = new ListStore (3, typeof (string), typeof (string), typeof (MovieSource));
34 tree = (TreeView) Hildon.gtk_tree_view_new_with_model (UIMode.NORMAL, store);
35 tree.set_headers_visible (false);
39 tree.set_rules_hint (true);
41 // Tree selection object
42 var selection = tree.get_selection ();
43 selection.set_mode (SelectionMode.SINGLE);
46 var title_column = new TreeViewColumn ();
47 title_column.set_title (_("Source"));
48 title_column.set_reorderable (false);
49 title_column.set_sizing (TreeViewColumnSizing.AUTOSIZE);
50 title_column.set_expand (true);
53 var vbox_renderer = new CellRendererVBox ();
55 var renderer = new CellRendererText ();
56 vbox_renderer.append (renderer, true);
57 vbox_renderer.set_data ("name", renderer);
60 renderer = new CellRendererText ();
61 renderer.set ("ellipsize", Pango.EllipsizeMode.END);
63 Pango.AttrList attr_list = new Pango.AttrList ();
64 var style = Gtk.rc_get_style_by_paths (this.get_settings (), "SmallSystemFont", null, typeof (void));
66 var attr_font_desc = new Pango.AttrFontDesc (style.font_desc.copy ());
67 attr_list.insert ((owned) attr_font_desc);
69 Pango.Attribute attr_font_scale = Pango.attr_scale_new (Pango.Scale.SMALL);
70 attr_list.insert ((owned) attr_font_scale);
73 if (!style.lookup_color ("SecondaryTextColor", out color)) {
74 Gdk.Color.parse ("grey", out color);
76 Pango.Attribute attr_color = Pango.attr_foreground_new (color.red, color.green, color.blue);
77 attr_list.insert ((owned) attr_color);
78 renderer.attributes = attr_list;
80 vbox_renderer.append (renderer, true);
81 vbox_renderer.set_data ("description", renderer);
83 title_column.pack_start (vbox_renderer, true);
84 title_column.set_cell_data_func (vbox_renderer, vbox_data_func);
86 tree.append_column (title_column);
89 tree.row_activated.connect (on_row_activated);
92 public void add_sources (List<MovieSource> list) {
93 foreach (MovieSource source in list) {
95 store.append (out iter);
96 store.set (iter, 0, source.get_name (), 1, source.get_description (), 2, source);
100 public bool get_iter (MovieSource source, out Gtk.TreeIter iter) {
101 if (store.get_iter_first (out iter)) do {
102 MovieSource s = null;
103 store.get (iter, 2, out s);
107 } while (store.iter_next (ref iter));
112 public unowned TreeSelection get_selection () {
113 return tree.get_selection ();
116 public void set_hildon_ui_mode (UIMode mode) {
117 var selection = tree.get_selection ();
119 if (mode == UIMode.NORMAL) {
120 selection.set_mode (SelectionMode.NONE);
122 Hildon.gtk_tree_view_set_ui_mode (tree, mode);
123 if (mode == UIMode.EDIT) {
124 selection.set_mode (SelectionMode.MULTIPLE);
128 private void on_row_activated (TreeView tree, TreePath path_, TreeViewColumn column) {
129 TreePath path = path_.copy (); // FIXME - calling model.get_iter with path_ directly causes a C qualifier warning
130 TreeModel model = tree.model;
133 if (model.get_iter (out iter, path)) {
135 model.get (iter, 2, out source);
136 source_activated (source);
140 private void vbox_data_func (CellLayout cell_layout, CellRenderer cell, TreeModel model, TreeIter iter) {
141 CellRendererText renderer;
145 model.get (iter, 0, out name, 1, out description);
147 renderer = (CellRendererText) cell.get_data ("name");
148 renderer.text = name;
150 renderer = (CellRendererText) cell.get_data ("description");
151 renderer.text = description;