0aef80510d40be80bd1f3cde9f7cec15fece5c95
[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 HBox hbox;
27         private Image image;
28         private VBox details;
29         private PannableArea pannable;
30         private Label plot;
31         private bool portrait_mode;
32
33         public MovieWindow.with_movie (Movie movie, MovieListStore store) {
34                 set_title (movie.title);
35
36                 // View menu
37                 menu = new MovieMenu (movie, store, this);
38
39                 set_main_menu (menu);
40
41                 // Poster
42                 image = new Image ();
43
44                 if (movie.poster != null && movie.poster.pixbuf != null) {
45                         image.pixbuf = movie.poster.pixbuf;
46                 } else {
47                         movie.notify.connect (this.on_movie_changed);
48                         if (movie.poster != null && movie.poster.thumbnail != null) {
49                                 // FIXME
50                                 image.pixbuf = movie.poster.thumbnail.scale_simple (268, 424, Gdk.InterpType.BILINEAR);
51                         } else {
52                                 // FIXME
53                                 if (no_poster == null) try {
54                                         no_poster = new Gdk.Pixbuf.from_file ("/usr/share/icons/hicolor/124x124/hildon/general_video.png");
55                                 } catch (Error e) {
56                                         critical ("Missing general_video icon: %s\n", e.message);
57                                 }
58                                 image.pixbuf = no_poster;
59                         }
60                         try {
61                                 poster_factory = MoviePoster.Factory.get_instance ();
62                                 poster_factory.queue (movie, receive_poster);
63                         } catch (Error e) {
64                                 warning ("Failed to queue poster request: %s\n", e.message);
65                         }
66                 }
67
68                 // Text area
69                 string year = movie.year > 0 ? " (%d)".printf (movie.year) : "";
70                 string text = "<big><b>%s</b></big>%s\n<small>%s</small>".printf (movie.title, year, movie.secondary);
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 header = new HBox (false, 0);
77                 header.pack_start (label, true, true, 0);
78                 if (movie.rating > 0) {
79                         text = "<big><b>%d.%d</b></big>".printf (movie.rating / 10, movie.rating % 10);
80                         var rating = new Label (text);
81                         rating.use_markup = true;
82                         rating.set_alignment (0.5f, 0.0f);
83                         header.pack_start (rating, false, false, MARGIN_DOUBLE);
84                 }
85
86                 plot = new Label (movie.get_plot ());
87                 plot.wrap = true;
88                 plot.set_alignment (0.0f, 0.0f);
89
90                 details = new VBox (false, MARGIN_DOUBLE);
91                 details.pack_start (header, false, false, 0);
92                 details.pack_start (plot, false, false, 0);
93
94                 var pannable = new PannableArea ();
95                 var eventbox = new EventBox ();
96                 eventbox.add (details);
97                 eventbox.above_child = true;
98                 pannable.add_with_viewport (eventbox);
99
100                 hbox = new HBox (false, 0);
101                 hbox.pack_start (pannable, true, true, 0);
102
103                 portrait_mode = CinaestProgram.orientation.portrait;
104                 if (portrait_mode) {
105                         details.pack_start (image, false, false, 0);
106                         details.reorder_child (image, 0);
107                         plot.set_size_request (480 - 2 * MARGIN_DOUBLE, -1);
108                 } else {
109                         hbox.pack_start (image, false, false, MARGIN_DOUBLE);
110                         hbox.reorder_child (image, 0);
111                         plot.set_size_request (800 - 268 /* image */ - 3 * MARGIN_DOUBLE, -1);
112                         pannable.set_size_request (-1, 424);
113                 }
114
115                 hbox.show_all ();
116                 add (hbox);
117
118                 // Connect signals
119                 menu.movie_deleted.connect (() => { destroy (); });
120                 Gdk.Screen.get_default ().size_changed.connect (on_orientation_changed);
121         }
122
123         private void receive_poster (Gdk.Pixbuf pixbuf, Movie movie) {
124                 var poster = new Poster();
125
126                 poster.pixbuf = pixbuf;
127                 if (movie.poster != null)
128                         poster.thumbnail = movie.poster.thumbnail;
129                 movie.poster = poster;
130         }
131
132         private void on_movie_changed (GLib.Object source, GLib.ParamSpec spec) {
133                 var movie = (Movie) source;
134
135                 if ((spec.name == "poster") && (movie.poster != null) && (movie.poster.pixbuf != null)) {
136                         image.pixbuf = movie.poster.pixbuf;
137                 }
138         }
139
140         private void on_orientation_changed (Gdk.Screen screen) {
141                 if (CinaestProgram.orientation.portrait == portrait_mode)
142                         return;
143
144                 portrait_mode = CinaestProgram.orientation.portrait;
145                 if (portrait_mode) {
146                         hbox.remove (image);
147                         details.pack_start (image, false, false, 0);
148                         details.reorder_child (image, 0);
149                         plot.set_size_request (480 - 2 * MARGIN_DOUBLE, -1);
150                         pannable.set_size_request (-1, -1);
151                 } else {
152                         details.remove (image);
153                         hbox.pack_start (image, false, false, MARGIN_DOUBLE);
154                         hbox.reorder_child (image, 0);
155                         pannable.set_size_request (-1, 424);
156                         plot.set_size_request (800 - 268 /* image */ - 3 * MARGIN_DOUBLE, -1);
157                 }
158         }
159 }
160