Movie window: construct with movie list store
[cinaest] / src / movie-window.vala
1 /* This file is part of Cinaest.
2  *
3  * Copyright (C) 2009 Philipp Zabel
4  *
5  * Cinaest is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * Cinaest is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with Cinaest. If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 using Gtk;
20 using Hildon;
21
22 public class MovieWindow : StackableWindow {
23         private MovieMenu menu;
24         private Gdk.Pixbuf no_poster;
25         private MoviePoster.Factory poster_factory;
26         private Image image;
27
28         public MovieWindow.with_movie (Movie movie, MovieListStore store) {
29                 set_title (movie.title);
30
31                 // View menu
32                 menu = new MovieMenu (movie);
33
34                 set_main_menu (menu);
35
36                 // Poster
37                 image = new Image ();
38                 image.set_size_request (268, 424);
39
40                 if (movie.poster != null && movie.poster.pixbuf != null) {
41                         image.pixbuf = movie.poster.pixbuf;
42                 } else {
43                         movie.notify.connect (this.on_movie_changed);
44                         if (movie.poster != null && movie.poster.thumbnail != null) {
45                                 // FIXME
46                                 image.pixbuf = movie.poster.thumbnail.scale_simple (244, 400, Gdk.InterpType.BILINEAR);
47                         } else {
48                                 // FIXME
49                                 if (no_poster == null) try {
50                                         no_poster = new Gdk.Pixbuf.from_file ("/usr/share/icons/hicolor/124x124/hildon/general_video.png");
51                                 } catch (Error e) {
52                                         critical ("Missing general_video icon: %s\n", e.message);
53                                 }
54                                 image.pixbuf = no_poster;
55                         }
56                         try {
57                                 poster_factory = MoviePoster.Factory.get_instance ();
58                                 poster_factory.queue (movie, receive_poster);
59                         } catch (Error e) {
60                                 warning ("Failed to queue poster request: %s\n", e.message);
61                         }
62                 }
63
64                 // Text area
65                 string genres = movie.genres.to_string ();
66                 string year = movie.year > 0 ? " (%d)".printf (movie.year) : "";
67                 string text = "<b>%s</b>%s".printf (genres, year);
68
69                 var label = new Label (text);
70                 label.wrap = true;
71                 label.use_markup = true;
72                 label.set_alignment (0.0f, 0.0f);
73
74                 var hbox = new HBox (false, 0);
75                 hbox.pack_start (image, false, true, 0);
76                 hbox.pack_start (label, true, true, MARGIN_DOUBLE);
77
78                 var vbox = new VBox (false, 0);
79                 vbox.pack_start (hbox, true, true, MARGIN_DOUBLE);
80
81                 add (vbox);
82         }
83
84         private void receive_poster (Gdk.Pixbuf pixbuf, Movie movie) {
85                 var poster = new Poster();
86
87                 poster.pixbuf = pixbuf;
88                 if (movie.poster != null)
89                         poster.thumbnail = movie.poster.thumbnail;
90                 movie.poster = poster;
91         }
92
93         private void on_movie_changed (GLib.Object source, GLib.ParamSpec spec) {
94                 var movie = (Movie) source;
95
96                 if ((spec.name == "poster") && (movie.poster != null) && (movie.poster.pixbuf != null)) {
97                         image.pixbuf = movie.poster.pixbuf;
98                 }
99         }
100 }
101