Movie list window: optionally open with initial title and year filter
authorPhilipp Zabel <philipp.zabel@gmail.com>
Thu, 19 Aug 2010 17:10:48 +0000 (19:10 +0200)
committerPhilipp Zabel <philipp.zabel@gmail.com>
Thu, 19 Aug 2010 17:10:48 +0000 (19:10 +0200)
If there is a single match, directly open the movie detail window.

src/movie-list-window.vala

index fb08efb..07914e5 100644 (file)
@@ -35,11 +35,14 @@ public class MovieListWindow : StackableWindow {
        private int count;
        private MovieSource source;
        private bool portrait_mode;
+       private bool auto_open_movie_window;
 
-       public MovieListWindow (MovieSource source_) {
+       public MovieListWindow (MovieSource source_, string? title = null, int year = 0) {
                source = source_;
                set_title (source.get_name ());
 
+               auto_open_movie_window = (title != null);
+
                // View menu
                menu = new MovieListMenu (this);
                menu.source = source;
@@ -122,7 +125,11 @@ public class MovieListWindow : StackableWindow {
 
                filter = new MovieFilter ();
                menu.filter = filter;
-               filter.title = "";
+               filter.title = (title != null) ? title : "";
+               if (year != 0) {
+                       filter.year_min = year;
+                       filter.year_max = year;
+               }
                if (SourceFlags.NOEMPTY in source.get_flags ()) {
                        no_movies.hide ();
                        search_bar_visible = true;
@@ -267,6 +274,15 @@ public class MovieListWindow : StackableWindow {
                if (count > movies_per_screen ())
                        padding -= MARGIN_DEFAULT;
                alignment.right_padding = padding;
+
+               if (count == 1 && auto_open_movie_window) {
+                       TreeIter iter;
+                       if (store.get_iter_first (out iter)) {
+                               Movie movie;
+                               store.get (iter, MovieListStore.Columns.MOVIE, out movie);
+                               on_movie_activated (movie);
+                       }
+               }
        }
 
        private int movies_per_screen () {