Poster downloading update
[cinaest] / src / movie-list-view.vala
index d469148..c1f3bcd 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 ();
@@ -292,23 +307,33 @@ public class MovieListView : PannableArea {
                for (int i = a; i <= b; i++) {
                        var path = new TreePath.from_indices (i);
                        TreeIter iter;
-                       if (store.get_iter (out iter, path)) {
-                               Movie movie;
-                               store.get (iter, MovieListStore.Columns.MOVIE, out movie);
-                               if (movie != null) {
-                                       if (poster_mode_) {
-                                               if (movie.poster == null || movie.poster.small == null) try {
-                                                       poster_factory.queue_thumbnail (movie, Poster.SMALL_WIDTH, Poster.SMALL_HEIGHT, false, receive_poster_small);
-                                               } catch (Error e) {
-                                                       warning ("Failed to queue poster request: %s\n", e.message);
-                                               }
-                                       } else {
-                                               if (movie.poster == null || movie.poster.icon == null) try {
-                                                       poster_factory.queue_thumbnail (movie, Poster.ICON_WIDTH, Poster.ICON_HEIGHT, false, receive_poster_icon);
-                                               } catch (Error e) {
-                                                       warning ("Failed to queue poster request: %s\n", e.message);
-                                               }
-                                       }
+                       if (!store.get_iter (out iter, path))
+                               continue;
+
+                       Movie movie;
+                       store.get (iter, MovieListStore.Columns.MOVIE, out movie);
+                       if (movie == null)
+                               continue;
+
+                       if (poster_mode_) {
+                               if (movie.poster == null || movie.poster.small == null) try {
+                                       poster_factory.queue (movie,
+                                                             Poster.SMALL_WIDTH,
+                                                             Poster.SMALL_HEIGHT,
+                                                             true,
+                                                             receive_poster_small);
+                               } catch (Error e) {
+                                       warning ("Failed to queue poster request: %s\n", e.message);
+                               }
+                       } else {
+                               if (movie.poster == null || movie.poster.icon == null) try {
+                                       poster_factory.queue (movie,
+                                                             Poster.ICON_WIDTH,
+                                                             Poster.ICON_HEIGHT,
+                                                             true,
+                                                             receive_poster_icon);
+                               } catch (Error e) {
+                                       warning ("Failed to queue poster request: %s\n", e.message);
                                }
                        }
                }
@@ -358,6 +383,7 @@ public class MovieListView : PannableArea {
                else
                        poster = new Poster ();
                poster.small = pixbuf;
+               // Notify store of the poster change
                movie.poster = poster;
        }
 
@@ -368,6 +394,7 @@ public class MovieListView : PannableArea {
                else
                        poster = new Poster ();
                poster.icon = pixbuf;
+               // Notify store of the poster change
                movie.poster = poster;
        }