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