Movie poster factory: return a "no poster" pixmap if the poster download failed
authorPhilipp Zabel <philipp.zabel@gmail.com>
Wed, 4 Aug 2010 22:27:52 +0000 (00:27 +0200)
committerPhilipp Zabel <philipp.zabel@gmail.com>
Thu, 5 Aug 2010 19:05:00 +0000 (21:05 +0200)
src/poster/movie-poster-factory.vala

index df8f1c3..35c4ba2 100644 (file)
@@ -29,6 +29,8 @@ namespace MoviePoster {
                internal bool download_posters;
                private GConf.Client gc;
                private uint cxnid;
+               private Gdk.Pixbuf poster_failed;
+               private Gdk.Pixbuf icon_failed;
 
                construct {
                        try {
@@ -143,7 +145,32 @@ namespace MoviePoster {
                        if (request == null)
                                return;
                        requests.remove (request);
-               //      request.callback (pixbuf, request.movie);
+                       request.callback (failed_poster (request.width, request.height), request.movie);
+               }
+
+               private Gdk.Pixbuf failed_poster (int width, int height) {
+                       if (width == Poster.ICON_WIDTH && height == Poster.ICON_HEIGHT) {
+                               if (icon_failed == null) {
+                                       // An empty icon for the list view
+                                       icon_failed = new Gdk.Pixbuf (Gdk.Colorspace.RGB, true, 8, Poster.ICON_WIDTH, Poster.ICON_HEIGHT);
+                                       icon_failed.fill (0);
+                               }
+                               return icon_failed;
+                       }
+                       if (width == Poster.SMALL_WIDTH && height == Poster.SMALL_HEIGHT) {
+                               if (poster_failed == null) try {
+                                       // Broken image icon for the poster view
+                                       var no_pic = new Gdk.Pixbuf.from_file ("/usr/share/icons/hicolor/64x64/hildon/imageviewer_no_pic.png");
+                                       poster_failed = new Gdk.Pixbuf (Gdk.Colorspace.RGB, true, 8, Poster.SMALL_WIDTH, Poster.SMALL_HEIGHT);
+                                       poster_failed.fill (0);
+                                       no_pic.copy_area (0, 0, no_pic.width, no_pic.height, poster_failed,
+                                                         (Poster.SMALL_WIDTH - no_pic.width) / 2, (Poster.SMALL_HEIGHT - no_pic.height) / 2);
+                               } catch (Error e) {
+                                       critical ("Missing imageviewer_no_pic icon: %s\n", e.message);
+                               }
+                               return poster_failed;
+                       }
+                       return null;
                }
 
                public void join () {