Movie window: add basic orientation awareness
authorPhilipp Zabel <philipp.zabel@gmail.com>
Tue, 5 Jan 2010 18:37:10 +0000 (19:37 +0100)
committerPhilipp Zabel <philipp.zabel@gmail.com>
Wed, 6 Jan 2010 17:56:35 +0000 (18:56 +0100)
Also remove size request on image, which is needed for portrait mode.

src/main.vala
src/movie-list-window.vala
src/movie-window.vala

index 0b9f0eb..752997c 100644 (file)
@@ -21,7 +21,7 @@ using Hildon;
 public class CinaestProgram : Hildon.Program {
        SourceListWindow window;
        public static List<Plugin> plugins;
-       private Orientation orientation;
+       public static Orientation orientation;
 
        construct {
                Environment.set_application_name ("Cinæst");
index e545244..1bcc7ec 100644 (file)
@@ -207,8 +207,8 @@ public class MovieListWindow : StackableWindow {
 
        private void on_movie_activated (Movie movie) {
                var window = new MovieWindow.with_movie (movie, store);
-               window.show_all ();
 
+               window.show ();
        }
 
        private void on_update_running_changed (GLib.Object source, ParamSpec spec) {
index 1eecbd4..42d6f74 100644 (file)
@@ -23,7 +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 Image image;
+       private Label label;
+       private bool portrait_mode;
 
        public MovieWindow.with_movie (Movie movie, MovieListStore store) {
                set_title (movie.title);
@@ -35,7 +39,6 @@ public class MovieWindow : StackableWindow {
 
                // Poster
                image = new Image ();
-               image.set_size_request (268, 424);
 
                if (movie.poster != null && movie.poster.pixbuf != null) {
                        image.pixbuf = movie.poster.pixbuf;
@@ -66,22 +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) {
@@ -100,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);
+               }
+       }
 }