Movie list store: remove insert call and switch back to integer rating string
[cinaest] / src / movie-list-store.vala
index 852690f..52a3c3d 100644 (file)
@@ -24,6 +24,7 @@ public class MovieListStore : ListStore, TreeModel {
                YEAR,
                RATING,
                POSTER,
+               ICON,
                MOVIE,
                MARKUP,
                N_COLUMNS
@@ -33,6 +34,7 @@ public class MovieListStore : ListStore, TreeModel {
                typeof (int),
                typeof (string),
                typeof (Gdk.Pixbuf),
+               typeof (Gdk.Pixbuf),
                typeof (Movie),
                typeof (string)
        };
@@ -47,6 +49,7 @@ public class MovieListStore : ListStore, TreeModel {
        public bool update_running { get; set; }
        public string year_markup = "<span size=\"small\">[%d]</span>";
        private Cancellable cancellable;
+       public Widget view;
 
        public signal void search_finished (int movies);
 
@@ -78,16 +81,25 @@ public class MovieListStore : ListStore, TreeModel {
                        markup.append_printf (year_markup, movie.year);
                }
 
-               append (out iter1);
-               base.set (iter1, 0, movie,
-                                1, markup.str,
-                                2, (movie.rating >= 0) ? "%d.%d".printf (movie.rating / 10, movie.rating % 10) : null);
+               base.insert_with_values (out iter1, -1,
+                                        0, movie,
+                                        1, markup.str,
+                                        2, rating_string (movie.rating));
 
                movie.notify.connect (this.on_movie_changed);
 
                iter = iter1;
        }
 
+       private string? rating_string (int rating) {
+               if (rating >= 0) {
+                       return "%d.%d".printf (rating / 10,
+                                              rating % 10);
+               } else {
+                       return null;
+               }
+       }
+
        public new bool remove (Movie movie) {
                TreeIter iter;
 
@@ -179,19 +191,23 @@ public class MovieListStore : ListStore, TreeModel {
                if (cancellable.is_cancelled ())
                        return;
 
-               foreach (Movie movie in movies) {
+               view.freeze_child_notify ();
+               foreach (Movie movie in movies)
                        add (movie, out iter);
-                       try {
-                               poster_factory.queue_thumbnail (movie, 64, 64, false, receive_poster_thumbnail);
-                       } catch (Error e) {
-                               warning ("Failed to queue poster request: %s\n", e.message);
-                       }
-               }
+               view.thaw_child_notify ();
        }
 
-       private void receive_poster_thumbnail (Gdk.Pixbuf pixbuf, Movie movie) {
+       private void receive_poster_icon (Gdk.Pixbuf pixbuf, Movie movie) {
                var poster = new Poster ();
-               poster.thumbnail = pixbuf;
+               poster.icon = pixbuf;
+               movie.poster = poster;
+       }
+
+       private void receive_poster_small (Gdk.Pixbuf pixbuf, Movie movie) {
+               var poster = new Poster ();
+               if (movie.poster != null && movie.poster.icon != null)
+                       poster.icon = movie.poster.icon;
+               poster.small = pixbuf;
                movie.poster = poster;
        }
 
@@ -209,13 +225,6 @@ public class MovieListStore : ListStore, TreeModel {
        public virtual void get_value (TreeIter iter, int column, out GLib.Value value) {
                Movie movie;
 
-               // FIXME
-               if (no_poster == null) try {
-                       no_poster = new Gdk.Pixbuf.from_file ("/usr/share/icons/hicolor/64x64/hildon/general_video.png");
-               } catch (Error e) {
-                       critical ("Missing general_video icon: %s\n", e.message);
-               }
-
                return_if_fail (column >= 0 && column < Columns.N_COLUMNS);
 
                // Get the Movie from our parent's storage
@@ -247,10 +256,30 @@ public class MovieListStore : ListStore, TreeModel {
                        break;
 
                case Columns.POSTER:
-                       if ((movie.poster != null) && (movie.poster.thumbnail != null))
-                               value.set_object (movie.poster.thumbnail);
-                       else
+                       if ((movie.poster != null) && (movie.poster.small != null)) {
+                               value.set_object (movie.poster.small);
+                       } else {
+                               // FIXME
+                               if (no_poster == null) try {
+                               //      var no_pic = new Gdk.Pixbuf.from_file ("/usr/share/icons/hicolor/64x64/hildon/imageviewer_no_pic.png");
+                                       var no_pic = new Gdk.Pixbuf.from_file ("/usr/share/icons/hicolor/64x64/hildon/general_no_thumbnail.png");
+                                       no_poster = new Gdk.Pixbuf (Gdk.Colorspace.RGB, true, 8, Poster.SMALL_WIDTH, Poster.SMALL_HEIGHT);
+                                       no_poster.fill (0);
+                                       no_pic.copy_area (0, 0, no_pic.width, no_pic.height, no_poster,
+                                                         (Poster.SMALL_WIDTH - no_pic.width) / 2, (Poster.SMALL_HEIGHT - no_pic.height) / 2);
+                               } catch (Error e) {
+                                       critical ("Missing general_video icon: %s\n", e.message);
+                               }
                                value.set_object (no_poster);
+                       }
+                       break;
+
+               case Columns.ICON:
+                       if ((movie.poster != null) && (movie.poster.icon != null)) {
+                               value.set_object (movie.poster.icon);
+                       } else {
+                               value.set_object (null);
+                       }
                        break;
 
                case Columns.MOVIE: