Add movie action class
[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 Movie movie;
24         private Gdk.Pixbuf no_poster;
25         private MoviePoster.Factory poster_factory;
26         private Image image;
27
28         public MovieWindow.with_movie (Movie movie_) {
29                 movie = movie_;
30                 set_title (movie.title);
31
32                 // Poster
33                 image = new Image ();
34                 image.set_size_request (268, 424);
35
36                 if (movie.poster != null && movie.poster.pixbuf != null) {
37                         image.pixbuf = movie.poster.pixbuf;
38                 } else {
39                         movie.notify.connect (this.on_movie_changed);
40                         if (movie.poster != null && movie.poster.thumbnail != null) {
41                                 // FIXME
42                                 image.pixbuf = movie.poster.thumbnail.scale_simple (244, 400, Gdk.InterpType.BILINEAR);
43                         } else {
44                                 // FIXME
45                                 if (no_poster == null) try {
46                                         no_poster = new Gdk.Pixbuf.from_file ("/usr/share/icons/hicolor/124x124/hildon/general_video.png");
47                                 } catch (Error e) {
48                                         critical ("Missing general_video icon: %s\n", e.message);
49                                 }
50                                 image.pixbuf = no_poster;
51                         }
52                         try {
53                                 poster_factory = MoviePoster.Factory.get_instance ();
54                                 poster_factory.queue (movie, receive_poster);
55                         } catch (Error e) {
56                                 warning ("Failed to queue poster request: %s\n", e.message);
57                         }
58                 }
59
60                 // Text area
61                 string genres = movie.genres.to_string ();
62                 string year = movie.year > 0 ? " (%d)".printf (movie.year) : "";
63                 string text = "<b>%s</b>%s".printf (genres, year);
64
65                 var label = new Label (text);
66                 label.wrap = true;
67                 label.use_markup = true;
68                 label.set_alignment (0.0f, 0.0f);
69
70                 var hbox = new HBox (false, 0);
71                 hbox.pack_start (image, false, true, 0);
72                 hbox.pack_start (label, true, true, MARGIN_DOUBLE);
73
74                 var vbox = new VBox (false, 0);
75                 vbox.pack_start (hbox, true, true, MARGIN_DOUBLE);
76
77                 add (vbox);
78         }
79
80         private void receive_poster (Gdk.Pixbuf pixbuf, Movie movie) {
81                 var poster = new Poster();
82
83                 poster.pixbuf = pixbuf;
84                 if (movie.poster != null)
85                         poster.thumbnail = movie.poster.thumbnail;
86                 movie.poster = poster;
87         }
88
89         private void on_movie_changed (GLib.Object source, GLib.ParamSpec spec) {
90                 var movie = (Movie) source;
91
92                 if ((spec.name == "poster") && (movie.poster != null) && (movie.poster.pixbuf != null)) {
93                         image.pixbuf = movie.poster.pixbuf;
94                 }
95         }
96 }
97