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);
Pango.AttrList attr_list = new Pango.AttrList ();
var style = Gtk.rc_get_style_by_paths (this.get_settings (), "SmallSystemFont", null, typeof (void));
if (style != null) {
- Pango.Attribute attr_font_desc = Pango.attr_font_desc_new (style.font_desc.copy ());
+ 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);
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 bool get_iter (MovieSource source, out Gtk.TreeIter iter) {
+ if (store.get_iter_first (out iter)) do {
+ MovieSource s = null;
+ store.get (iter, 2, out s);
+ if (s == source) {
+ return true;
+ }
+ } while (store.iter_next (ref iter));
+
+ return false;
+ }
+
+ public unowned TreeSelection get_selection () {
+ return tree.get_selection ();
+ }
+
+ public void set_hildon_ui_mode (UIMode mode) {
+ var selection = tree.get_selection ();
+
+ if (mode == UIMode.NORMAL) {
+ selection.set_mode (SelectionMode.NONE);
+ }
+ Hildon.gtk_tree_view_set_ui_mode (tree, mode);
+ if (mode == UIMode.EDIT) {
+ selection.set_mode (SelectionMode.MULTIPLE);
}
}