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) {
+ 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);
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);
}
}