public class SourceListView : PannableArea {
TreeView tree;
ListStore store;
+ TreeModelFilter filtered_store;
+ bool filtered;
public signal void source_activated (MovieSource source);
- public SourceListView (List<MovieSource> list) {
+ public SourceListView (List<MovieSource> list, bool _filtered, Gtk.Window window) {
+ filtered = _filtered;
+
// Source list
store = new ListStore (3, typeof (string), typeof (string), typeof (MovieSource));
add_sources (list);
- // Tree View
- tree = (TreeView) Hildon.gtk_tree_view_new_with_model (UIMode.NORMAL, store);
+ if (filtered) {
+ // Add filter wrapper
+ filtered_store = new TreeModelFilter (store, null);
+ filtered_store.set_visible_func (filter_visible_func);
+
+ // Tree View
+ tree = (TreeView) Hildon.gtk_tree_view_new_with_model (UIMode.NORMAL, filtered_store);
+ } else {
+ tree = (TreeView) Hildon.gtk_tree_view_new_with_model (UIMode.NORMAL, store);
+ }
tree.set_headers_visible (false);
add (tree);
var vbox_renderer = new CellRendererVBox ();
var renderer = new CellRendererText ();
+ renderer.yalign = 1.0f;
vbox_renderer.append (renderer, true);
vbox_renderer.set_data ("name", renderer);
// Add description
renderer = new CellRendererText ();
- renderer.set ("ellipsize", Pango.EllipsizeMode.END);
+ renderer.yalign = 0;
+ renderer.ellipsize = Pango.EllipsizeMode.END;
Pango.AttrList attr_list = new Pango.AttrList ();
- var style = Gtk.rc_get_style_by_paths (this.get_settings (), "SmallSystemFont", null, typeof (void));
+ var style = Gtk.rc_get_style_by_paths (Gtk.Settings.get_default (), "SmallSystemFont", null, typeof (void));
if (style != null) {
var attr_font_desc = new Pango.AttrFontDesc (style.font_desc.copy ());
attr_list.insert ((owned) attr_font_desc);
- } else {
- Pango.Attribute attr_font_scale = Pango.attr_scale_new (Pango.Scale.SMALL);
- attr_list.insert ((owned) attr_font_scale);
}
Gdk.Color color;
- if (!style.lookup_color ("SecondaryTextColor", out color)) {
- Gdk.Color.parse ("grey", out color);
+ window.ensure_style ();
+ if (window.style.lookup_color ("SecondaryTextColor", out color)) {
+ Pango.Attribute attr_color = Pango.attr_foreground_new (color.red, color.green, color.blue);
+ attr_list.insert ((owned) attr_color);
}
- Pango.Attribute attr_color = Pango.attr_foreground_new (color.red, color.green, color.blue);
- attr_list.insert ((owned) attr_color);
renderer.attributes = attr_list;
vbox_renderer.append (renderer, true);
tree.row_activated.connect (on_row_activated);
}
+ bool filter_visible_func (TreeModel model, TreeIter iter) {
+ MovieSource source = null;
+
+ store.get (iter, 2, out source);
+
+ return source.active;
+ }
+
public void add_sources (List<MovieSource> list) {
foreach (MovieSource source in list) {
TreeIter iter;
- store.append (out iter);
- store.set (iter, 0, source.get_name (), 1, source.get_description (), 2, source);
+
+ store.insert_with_values (out iter, -1, 0, source.get_name (), 1, source.get_description (), 2, source);
+
+ source.notify["active"].connect (this.on_source_changed);
+ }
+ }
+
+ private void on_source_changed (GLib.Object _source, GLib.ParamSpec spec) {
+ var source = (MovieSource) _source;
+ TreeIter iter;
+
+ if (get_iter (source, out iter)) {
+ TreePath path = store.get_path (iter);
+ store.row_changed (path, iter);
}
}
}
}
+ public int length () {
+ TreeIter iter;
+ int len = 0;
+
+ if (store.get_iter_first (out iter)) do {
+ len++;
+ } while (store.iter_next (ref iter));
+
+ return len;
+ }
+
private void on_row_activated (TreeView tree, TreePath path_, TreeViewColumn column) {
TreePath path = path_.copy (); // FIXME - calling model.get_iter with path_ directly causes a C qualifier warning
TreeModel model = tree.model;
model.get (iter, 0, out name, 1, out description);
- renderer = (CellRendererText) cell.get_data ("name");
+ renderer = cell.get_data ("name");
renderer.text = name;
- renderer = (CellRendererText) cell.get_data ("description");
+ renderer = cell.get_data ("description");
renderer.text = description;
}
}