Movie list window: open the movie detail window on the current window stack
[cinaest] / src / movie-list-window.vala
index 0765af1..fb08efb 100644 (file)
@@ -34,6 +34,7 @@ public class MovieListWindow : StackableWindow {
        private Alignment alignment;
        private int count;
        private MovieSource source;
+       private bool portrait_mode;
 
        public MovieListWindow (MovieSource source_) {
                source = source_;
@@ -68,7 +69,7 @@ public class MovieListWindow : StackableWindow {
 
                // Movie list - connected to menu for sorting
                movie_list = new MovieListView (this, source.get_name () == _("Watched movies"));
-               menu.sortable = movie_list.store;
+               menu.store = movie_list.store;
                store = movie_list.store;
                store.source = source;
 
@@ -84,8 +85,11 @@ public class MovieListWindow : StackableWindow {
 
                alignment = new Alignment (0.0f, 0.0f, 1.0f, 1.0f);
                alignment.top_padding = MARGIN_HALF;
-               alignment.left_padding = MARGIN_DOUBLE;
-               alignment.right_padding = MARGIN_DOUBLE;
+
+               // Reduced padding in portrait mode to fit 3 posters in width
+               int padding = portrait_mode ? MARGIN_DEFAULT : MARGIN_DOUBLE;
+               alignment.left_padding = padding;
+               alignment.right_padding = padding;
 
                alignment.add (vbox);
                add (alignment);
@@ -103,6 +107,7 @@ public class MovieListWindow : StackableWindow {
                movie_list.movie_activated.connect (on_movie_activated);
                store.row_deleted.connect (on_row_deleted);
                store.row_inserted.connect (on_row_inserted);
+               Gdk.Screen.get_default ().size_changed.connect (on_orientation_changed);
                store.search_finished.connect (on_search_finished);
 
                store.notify["update-running"].connect (on_update_running_changed);
@@ -173,7 +178,10 @@ public class MovieListWindow : StackableWindow {
                        return;
                }
 
-               var dialog = new Note.confirmation (this, _("Delete %d movies?").printf (count));
+               var dialog = new Note.confirmation (this, 
+                                                   ngettext ("Delete %d movie?",
+                                                             "Delete %d movies?",
+                                                             count).printf (count));
                var res = dialog.run ();
 
                if (res == Gtk.ResponseType.OK) {
@@ -236,11 +244,45 @@ public class MovieListWindow : StackableWindow {
                return false;
        }
 
+       private void on_orientation_changed (Gdk.Screen screen) {
+               if (CinaestProgram.orientation.portrait == portrait_mode)
+                       return;
+
+               portrait_mode = CinaestProgram.orientation.portrait;
+
+               // Reduced padding in portrait mode to fit 3 posters in width
+               int padding = portrait_mode ? MARGIN_DEFAULT : MARGIN_DOUBLE;
+               alignment.left_padding = padding;
+
+               // Make space for the pannable area's scroll position indicator
+               if (count > movies_per_screen ())
+                       padding -= MARGIN_DEFAULT;
+               alignment.right_padding = padding;
+       }
+
        private void on_search_finished (int movies) {
-               if (movies > 6)
-                       alignment.right_padding = MARGIN_DEFAULT;
-               else
-                       alignment.right_padding = MARGIN_DOUBLE;
+               int padding = portrait_mode ? MARGIN_DEFAULT : MARGIN_DOUBLE;
+
+               // Make space for the pannable area's scroll position indicator
+               if (count > movies_per_screen ())
+                       padding -= MARGIN_DEFAULT;
+               alignment.right_padding = padding;
+       }
+
+       private int movies_per_screen () {
+               if (portrait_mode) {
+                       // 3x3 full posters or 10 full list items,
+                       // 10 full list items in list mode without search bar
+                       return (search_bar_visible || movie_list.poster_mode) ? 9 : 10;
+               } else {
+                       if (search_bar_visible) {
+                               // 5x1 full posters or 5 list items
+                               return 5;
+                       } else {
+                               // 5x2 posters or 6 list items
+                               return movie_list.poster_mode ? 10 : 6;
+                       }
+               }
        }
 
        private void on_movie_activated (Movie movie) {
@@ -249,7 +291,7 @@ public class MovieListWindow : StackableWindow {
 
                movie_window = new MovieWindow.with_movie (movie, store);
                movie_window.destroy.connect (() => { movie_window = null; });
-               movie_window.show ();
+               get_stack ().push_1 (movie_window);
        }
 
        private void on_row_deleted (TreePath path) {