Add IMDb poster downloader
[cinaest] / src / movie-window.vala
index 42d6f74..82a2511 100644 (file)
@@ -23,10 +23,11 @@ public class MovieWindow : StackableWindow {
        private MovieMenu menu;
        private Gdk.Pixbuf no_poster;
        private MoviePoster.Factory poster_factory;
-       private HBox landscape;
-       private VBox portrait;
+       private HBox hbox;
        private Image image;
-       private Label label;
+       private VBox details;
+       private PannableArea pannable;
+       private Label plot;
        private bool portrait_mode;
 
        public MovieWindow.with_movie (Movie movie, MovieListStore store) {
@@ -40,13 +41,13 @@ public class MovieWindow : StackableWindow {
                // Poster
                image = new Image ();
 
-               if (movie.poster != null && movie.poster.pixbuf != null) {
-                       image.pixbuf = movie.poster.pixbuf;
+               if (movie.poster != null && movie.poster.large != null) {
+                       image.pixbuf = movie.poster.large;
                } else {
                        movie.notify.connect (this.on_movie_changed);
-                       if (movie.poster != null && movie.poster.thumbnail != null) {
+                       if (movie.poster != null && movie.poster.icon != null) {
                                // FIXME
-                               image.pixbuf = movie.poster.thumbnail.scale_simple (244, 400, Gdk.InterpType.BILINEAR);
+                               image.pixbuf = movie.poster.icon.scale_simple (268, 424, Gdk.InterpType.BILINEAR);
                        } else {
                                // FIXME
                                if (no_poster == null) try {
@@ -65,33 +66,54 @@ public class MovieWindow : StackableWindow {
                }
 
                // Text area
-               string genres = movie.genres.to_string ();
                string year = movie.year > 0 ? " (%d)".printf (movie.year) : "";
-               string text = "<b>%s</b>%s".printf (genres, year);
-
-               label = new Label (text);
+               string text = "<big><b>%s</b></big>%s\n<small>%s</small>".printf (movie.title, year, movie.secondary);
+               var label = new Label (text);
                label.wrap = true;
                label.use_markup = true;
                label.set_alignment (0.0f, 0.0f);
 
-               landscape = new HBox (false, 0);
-               portrait = new VBox (false, 0);
+               var header = new HBox (false, 0);
+               header.pack_start (label, true, true, 0);
+               if (movie.rating > 0) {
+                       text = "<big><b>%d.%d</b></big>".printf (movie.rating / 10, movie.rating % 10);
+                       var rating = new Label (text);
+                       rating.use_markup = true;
+                       rating.set_alignment (0.5f, 0.0f);
+                       header.pack_start (rating, false, false, MARGIN_DOUBLE);
+               }
+
+               plot = new Label (movie.get_plot ());
+               plot.wrap = true;
+               plot.set_alignment (0.0f, 0.0f);
 
-               var vbox = new VBox (false, 0);
-               vbox.pack_start (landscape, true, true, MARGIN_DOUBLE);
-               vbox.pack_start (portrait, true, true, MARGIN_DOUBLE);
+               details = new VBox (false, MARGIN_DOUBLE);
+               details.pack_start (header, false, false, 0);
+               details.pack_start (plot, false, false, 0);
+
+               var pannable = new PannableArea ();
+               var eventbox = new EventBox ();
+               eventbox.add (details);
+               eventbox.above_child = true;
+               pannable.add_with_viewport (eventbox);
+
+               hbox = new HBox (false, 0);
+               hbox.pack_start (pannable, true, true, 0);
 
                portrait_mode = CinaestProgram.orientation.portrait;
                if (portrait_mode) {
-                       portrait.pack_start (image, false, false, 0);
-                       portrait.pack_start (label, true, true, MARGIN_DOUBLE);
+                       details.pack_start (image, false, false, 0);
+                       details.reorder_child (image, 0);
+                       plot.set_size_request (480 - 2 * MARGIN_DOUBLE, -1);
                } else {
-                       landscape.pack_start (image, false, true, 0);
-                       landscape.pack_start (label, true, true, MARGIN_DOUBLE);
+                       hbox.pack_start (image, false, false, MARGIN_DOUBLE);
+                       hbox.reorder_child (image, 0);
+                       plot.set_size_request (800 - 268 /* image */ - 3 * MARGIN_DOUBLE, -1);
+                       pannable.set_size_request (-1, 424);
                }
 
-               vbox.show_all ();
-               add (vbox);
+               hbox.show_all ();
+               add (hbox);
 
                // Connect signals
                menu.movie_deleted.connect (() => { destroy (); });
@@ -101,17 +123,19 @@ public class MovieWindow : StackableWindow {
        private void receive_poster (Gdk.Pixbuf pixbuf, Movie movie) {
                var poster = new Poster();
 
-               poster.pixbuf = pixbuf;
-               if (movie.poster != null)
-                       poster.thumbnail = movie.poster.thumbnail;
+               poster.large = pixbuf;
+               if (movie.poster != null) {
+                       poster.icon = movie.poster.icon;
+                       poster.small = movie.poster.small;
+               }
                movie.poster = poster;
        }
 
        private void on_movie_changed (GLib.Object source, GLib.ParamSpec spec) {
                var movie = (Movie) source;
 
-               if ((spec.name == "poster") && (movie.poster != null) && (movie.poster.pixbuf != null)) {
-                       image.pixbuf = movie.poster.pixbuf;
+               if ((spec.name == "poster") && (movie.poster != null) && (movie.poster.large != null)) {
+                       image.pixbuf = movie.poster.large;
                }
        }
 
@@ -121,15 +145,17 @@ public class MovieWindow : StackableWindow {
 
                portrait_mode = CinaestProgram.orientation.portrait;
                if (portrait_mode) {
-                       landscape.remove (label);
-                       landscape.remove (image);
-                       portrait.pack_start (image, false, false, 0);
-                       portrait.pack_start (label, true, true, MARGIN_DOUBLE);
+                       hbox.remove (image);
+                       details.pack_start (image, false, false, 0);
+                       details.reorder_child (image, 0);
+                       plot.set_size_request (480 - 2 * MARGIN_DOUBLE, -1);
+                       pannable.set_size_request (-1, -1);
                } else {
-                       portrait.remove (label);
-                       portrait.remove (image);
-                       landscape.pack_start (image, false, true, 0);
-                       landscape.pack_start (label, true, true, MARGIN_DOUBLE);
+                       details.remove (image);
+                       hbox.pack_start (image, false, false, MARGIN_DOUBLE);
+                       hbox.reorder_child (image, 0);
+                       pannable.set_size_request (-1, 424);
+                       plot.set_size_request (800 - 268 /* image */ - 3 * MARGIN_DOUBLE, -1);
                }
        }
 }