IMDb plugin: enable movie source description string for translation
[cinaest] / src / movie-window.vala
index 6e5b060..42d6f74 100644 (file)
@@ -20,24 +20,25 @@ using Gtk;
 using Hildon;
 
 public class MovieWindow : StackableWindow {
-       private Movie movie;
        private MovieMenu menu;
        private Gdk.Pixbuf no_poster;
        private MoviePoster.Factory poster_factory;
+       private HBox landscape;
+       private VBox portrait;
        private Image image;
+       private Label label;
+       private bool portrait_mode;
 
-       public MovieWindow.with_movie (Movie movie_) {
-               movie = movie_;
+       public MovieWindow.with_movie (Movie movie, MovieListStore store) {
                set_title (movie.title);
 
                // View menu
-               menu = new MovieMenu (movie);
+               menu = new MovieMenu (movie, store, this);
 
                set_main_menu (menu);
 
                // Poster
                image = new Image ();
-               image.set_size_request (268, 424);
 
                if (movie.poster != null && movie.poster.pixbuf != null) {
                        image.pixbuf = movie.poster.pixbuf;
@@ -68,19 +69,33 @@ public class MovieWindow : StackableWindow {
                string year = movie.year > 0 ? " (%d)".printf (movie.year) : "";
                string text = "<b>%s</b>%s".printf (genres, year);
 
-               var label = new Label (text);
+               label = new Label (text);
                label.wrap = true;
                label.use_markup = true;
                label.set_alignment (0.0f, 0.0f);
 
-               var hbox = new HBox (false, 0);
-               hbox.pack_start (image, false, true, 0);
-               hbox.pack_start (label, true, true, MARGIN_DOUBLE);
+               landscape = new HBox (false, 0);
+               portrait = new VBox (false, 0);
 
                var vbox = new VBox (false, 0);
-               vbox.pack_start (hbox, true, true, MARGIN_DOUBLE);
+               vbox.pack_start (landscape, true, true, MARGIN_DOUBLE);
+               vbox.pack_start (portrait, true, true, MARGIN_DOUBLE);
 
+               portrait_mode = CinaestProgram.orientation.portrait;
+               if (portrait_mode) {
+                       portrait.pack_start (image, false, false, 0);
+                       portrait.pack_start (label, true, true, MARGIN_DOUBLE);
+               } else {
+                       landscape.pack_start (image, false, true, 0);
+                       landscape.pack_start (label, true, true, MARGIN_DOUBLE);
+               }
+
+               vbox.show_all ();
                add (vbox);
+
+               // Connect signals
+               menu.movie_deleted.connect (() => { destroy (); });
+               Gdk.Screen.get_default ().size_changed.connect (on_orientation_changed);
        }
 
        private void receive_poster (Gdk.Pixbuf pixbuf, Movie movie) {
@@ -99,5 +114,23 @@ public class MovieWindow : StackableWindow {
                        image.pixbuf = movie.poster.pixbuf;
                }
        }
+
+       private void on_orientation_changed (Gdk.Screen screen) {
+               if (CinaestProgram.orientation.portrait == portrait_mode)
+                       return;
+
+               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);
+               } else {
+                       portrait.remove (label);
+                       portrait.remove (image);
+                       landscape.pack_start (image, false, true, 0);
+                       landscape.pack_start (label, true, true, MARGIN_DOUBLE);
+               }
+       }
 }