Add movie window
authorPhilipp Zabel <philipp.zabel@gmail.com>
Wed, 4 Nov 2009 14:42:49 +0000 (15:42 +0100)
committerPhilipp Zabel <philipp.zabel@gmail.com>
Thu, 12 Nov 2009 18:23:24 +0000 (19:23 +0100)
A stacked window to display detail movie information and operate on a
single movie.

Makefile.am
src/movie-list-window.vala
src/movie-window.vala [new file with mode: 0644]

index 054d7f2..e79c281 100644 (file)
@@ -36,6 +36,7 @@ cinaest_SOURCES = \
         src/movie-list-store.c \
         src/movie-list-view.c \
         src/movie-list-window.c \
+        src/movie-window.c \
         src/plugin-interface.c \
        src/plugin-registrar.c \
        src/poster/movie-poster-factory.c \
@@ -52,6 +53,7 @@ cinaest_VALASOURCES = \
         src/movie-list-store.vala \
         src/movie-list-view.vala \
         src/movie-list-window.vala \
+        src/movie-window.vala \
         src/plugin-interface.vala \
        src/plugin-registrar.vala \
        src/poster/movie-poster-factory.vala \
index 3a20f51..f122222 100644 (file)
@@ -73,6 +73,7 @@ public class MovieListWindow : StackableWindow {
                search_field.changed.connect (on_search_field_changed);
                close_button.clicked.connect (on_close_button_clicked);
                key_press_event.connect (on_key_press_event);
+               movie_list.movie_activated.connect (on_movie_activated);
 
                store.notify["update-running"].connect (on_update_running_changed);
 
@@ -138,6 +139,12 @@ public class MovieListWindow : StackableWindow {
                return false;
        }
 
+       private void on_movie_activated (Movie movie) {
+               var window = new MovieWindow.with_movie (movie);
+               window.show_all ();
+
+       }
+
        private void on_update_running_changed (GLib.Object source, ParamSpec spec) {
                TreeIter iter;
 
diff --git a/src/movie-window.vala b/src/movie-window.vala
new file mode 100644 (file)
index 0000000..92ff56e
--- /dev/null
@@ -0,0 +1,97 @@
+/* This file is part of Cinaest.
+ *
+ * Copyright (C) 2009 Philipp Zabel
+ *
+ * Cinaest is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Cinaest is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Cinaest. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+using Gtk;
+using Hildon;
+
+public class MovieWindow : StackableWindow {
+       private Movie movie;
+       private Gdk.Pixbuf no_poster;
+       private MoviePoster.Factory poster_factory;
+       private Image image;
+
+       public MovieWindow.with_movie (Movie movie_) {
+               movie = movie_;
+               set_title (movie.title);
+
+               // Poster
+               image = new Image ();
+               image.set_size_request (268, 424);
+
+               if (movie.poster != null && movie.poster.pixbuf != null) {
+                       image.pixbuf = movie.poster.pixbuf;
+               } else {
+                       movie.notify.connect (this.on_movie_changed);
+                       if (movie.poster != null && movie.poster.thumbnail != null) {
+                               // FIXME
+                               image.pixbuf = movie.poster.thumbnail.scale_simple (244, 400, Gdk.InterpType.BILINEAR);
+                       } else {
+                               // FIXME
+                               if (no_poster == null) try {
+                                       no_poster = new Gdk.Pixbuf.from_file ("/usr/share/icons/hicolor/124x124/hildon/general_video.png");
+                               } catch (Error e) {
+                                       critical ("Missing general_video icon: %s\n", e.message);
+                               }
+                               image.pixbuf = no_poster;
+                       }
+                       try {
+                               poster_factory = MoviePoster.Factory.get_instance ();
+                               poster_factory.queue (movie, receive_poster);
+                       } catch (Error e) {
+                               warning ("Failed to queue poster request: %s\n", e.message);
+                       }
+               }
+
+               // 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);
+
+               var 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);
+
+               var vbox = new VBox (false, 0);
+               vbox.pack_start (hbox, true, true, MARGIN_DOUBLE);
+
+               add (vbox);
+       }
+
+       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;
+               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;
+               }
+       }
+}
+