Movie list view: disconnect model from unused view, workaround for switching
authorPhilipp Zabel <philipp.zabel@gmail.com>
Thu, 5 Aug 2010 18:26:58 +0000 (20:26 +0200)
committerPhilipp Zabel <philipp.zabel@gmail.com>
Thu, 5 Aug 2010 19:27:00 +0000 (21:27 +0200)
Connect the model only to the visible view for performance reasons.
Jumping to 0, 0 and manually checking the first few posters is a workaround
for posters not being displayed until the user scrolls after switching to
the poster grid mode.

src/movie-list-view.vala

index d469148..0b695cf 100644 (file)
@@ -30,6 +30,8 @@ public class MovieListView : PannableArea {
        private CellRendererText rating_renderer;
        private CellRendererText date_renderer;
        private MoviePoster.Factory poster_factory;
+       private int last_a = -1;
+       private int last_b = -1;
 
        private bool poster_mode_;
        public bool poster_mode {
@@ -39,12 +41,27 @@ public class MovieListView : PannableArea {
                set {
                        if (value & !poster_mode_) {
                                remove (tree);
+                               tree.set_model (null);
+                               icons.set_model (store);
+                               store.view = (Widget) icons;
                                add (icons);
                        } else if (!value & poster_mode_) {
                                remove (icons);
+                               icons.set_model (null);
+                               tree.set_model (store);
+                               store.view = (Widget) tree;
                                add (tree);
                        }
-                       poster_mode_ = value;
+                       if (value != poster_mode_) {
+                               poster_mode_ = value;
+                               last_a = -1;
+                               last_b = -1;
+
+                               // FIXME - just calling on_adjustment_value_changed () here doesn't work
+                               // because icons.get_visible_range () returns wrong paths.
+                               check_posters (0, 10);
+                               jump_to (0, 0);
+                       }
                }
        }
 
@@ -138,7 +155,7 @@ public class MovieListView : PannableArea {
        }
 
        private Gtk.IconView create_iconview () {
-               var iconview = (Gtk.IconView) Hildon.gtk_icon_view_new_with_model (Hildon.UIMode.NORMAL, store);
+               var iconview = (Gtk.IconView) Hildon.gtk_icon_view_new (Hildon.UIMode.NORMAL);
                iconview.set_column_spacing (0);
                iconview.set_pixbuf_column (MovieListStore.Columns.POSTER);
                iconview.margin = 0;
@@ -247,8 +264,6 @@ public class MovieListView : PannableArea {
 
        // TODO: after scrolling down 80% of the list, load more
        //       results if available.
-       int last_a = 0;
-       int last_b = 0;
        private void on_adjustment_value_changed () {
                if (more_movies_available) {
                        var vadj = get_vadjustment ();