X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fsource-list-view.vala;h=df492e459dd7936a75193e998b3506193c357b35;hb=684bb20c0334dc12ea69d00255574be6363fcbc3;hp=03fc33ef02a32c2ccc11d05059ab2fa7c4872494;hpb=7198676260ca8ca8d65a6cd9bb6cb5b4afb2c4f6;p=cinaest diff --git a/src/source-list-view.vala b/src/source-list-view.vala index 03fc33e..df492e4 100644 --- a/src/source-list-view.vala +++ b/src/source-list-view.vala @@ -22,16 +22,28 @@ using Hildon; public class SourceListView : PannableArea { TreeView tree; ListStore store; + TreeModelFilter filtered_store; + bool filtered; public signal void source_activated (MovieSource source); - public SourceListView (List list) { + public SourceListView (List 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); @@ -53,28 +65,27 @@ public class SourceListView : PannableArea { 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); @@ -89,11 +100,31 @@ public class SourceListView : PannableArea { 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 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); } } @@ -125,6 +156,17 @@ public class SourceListView : PannableArea { } } + 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; @@ -144,10 +186,10 @@ public class SourceListView : PannableArea { 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; } }