Italian translation update (via transifex.net, by mij37)
[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 title_label;
31         private Label rating_label;
32         private Label cast_label;
33         private Label plot;
34         private bool portrait_mode;
35
36         public MovieWindow.with_movie (Movie movie, MovieListStore store) {
37                 update_title (movie);
38
39                 // View menu
40                 menu = new MovieMenu (movie, store, this);
41
42                 set_main_menu (menu);
43
44                 // Poster
45                 image = new Image ();
46
47                 title_label = new Label (title_label_markup (movie));
48                 title_label.wrap = true;
49                 title_label.use_markup = true;
50                 title_label.set_alignment (0.0f, 0.0f);
51
52                 var header = new HBox (false, 0);
53                 header.pack_start (title_label, true, true, 0);
54
55                 rating_label = new Label (rating_label_markup (movie));
56                 rating_label.use_markup = true;
57                 rating_label.set_alignment (0.5f, 0.0f);
58                 header.pack_start (rating_label, false, false, MARGIN_DOUBLE);
59
60                 cast_label = new Label (cast_label_markup (movie));
61                 cast_label.wrap = true;
62                 cast_label.use_markup = true;
63                 cast_label.set_alignment (0.0f, 0.0f);
64
65                 plot = new Label (movie.get_plot ());
66                 plot.wrap = true;
67                 plot.set_alignment (0.0f, 0.0f);
68
69                 details = new VBox (false, MARGIN_DOUBLE);
70                 details.pack_start (header, false, false, 0);
71                 details.pack_start (cast_label, false, false, 0);
72                 details.pack_start (plot, false, false, 0);
73
74                 var pannable = new PannableArea ();
75                 var eventbox = new EventBox ();
76                 eventbox.add (details);
77                 eventbox.above_child = true;
78                 pannable.add_with_viewport (eventbox);
79
80                 hbox = new HBox (false, 0);
81                 hbox.pack_start (pannable, true, true, 0);
82
83                 portrait_mode = CinaestProgram.orientation.portrait;
84                 if (portrait_mode) {
85                         details.pack_start (image, false, false, 0);
86                         details.reorder_child (image, 0);
87                         plot.set_size_request (480 - 2 * MARGIN_DOUBLE, -1);
88                 } else {
89                         hbox.pack_start (image, false, false, MARGIN_DOUBLE);
90                         hbox.reorder_child (image, 0);
91                         plot.set_size_request (800 - 288 /* image */ - 3 * MARGIN_DOUBLE, -1);
92                         pannable.set_size_request (-1, 424);
93                 }
94
95                 hbox.show_all ();
96                 add (hbox);
97
98                 // Connect signals
99                 menu.movie_deleted.connect (() => { destroy (); });
100                 Gdk.Screen.get_default ().size_changed.connect (on_orientation_changed);
101                 movie.notify.connect (this.on_movie_changed);
102
103                 if (movie.poster != null && movie.poster.large != null) {
104                         image.pixbuf = movie.poster.large;
105                 } else {
106                         if (movie.poster != null && movie.poster.small != null) {
107                                 // FIXME
108                                 image.pixbuf = movie.poster.small.scale_simple (288, 400, Gdk.InterpType.HYPER);
109                         } else {
110                                 // FIXME
111                                 if (no_poster == null) try {
112                                         no_poster = new Gdk.Pixbuf.from_file ("/usr/share/icons/hicolor/64x64/hildon/general_no_thumbnail.png");
113                                 } catch (Error e) {
114                                         critical ("Missing general_no_thumbnail icon: %s\n", e.message);
115                                 }
116                                 image.pixbuf = no_poster;
117                         }
118                         try {
119                                 poster_factory = MoviePoster.Factory.get_instance ();
120                                 poster_factory.queue (movie, 288, 400, false, receive_poster);
121                         } catch (Error e) {
122                                 warning ("Failed to queue poster request: %s\n", e.message);
123                         }
124                 }
125         }
126
127         private void update_title (Movie movie) {
128                 Gdk.Color color;
129                 this.ensure_style ();
130                 if (this.style.lookup_color ("SecondaryTextColor", out color))
131                         set_markup ("%s <span size=\"small\" fgcolor=\"%s\">(%d)</span>".printf (movie.title, color.to_string (), movie.year));
132                 else
133                         set_markup ("%s <small>(%d)</small>".printf (movie.title, movie.year));
134         }
135
136         private string title_label_markup (Movie movie) {
137                 Gdk.Color color;
138                 this.ensure_style ();
139                 string year = "";
140                 if (this.style.lookup_color ("SecondaryTextColor", out color)) {
141                         if (movie.year > 0)
142                                 year = " <span fgcolor=\"%s\">(%d)</span>".printf (color.to_string (), movie.year);
143                         return "<big><b>%s</b></big>%s\n<span size=\"small\" fgcolor=\"%s\">%s</span>".printf (movie.title, year, color.to_string (), movie.secondary);
144                 } else {
145                         if (movie.year > 0)
146                                 year = " (%d)".printf (movie.year);
147                         return "<big><b>%s</b></big>%s\n<small>%s</small>".printf (movie.title, year, movie.secondary);
148                 }
149         }
150
151         private string rating_label_markup (Movie movie) {
152                 if (movie.rating > 0)
153                         return "<big><b>%d.%d</b></big>".printf (movie.rating / 10, movie.rating % 10);
154                 else
155                         return "";
156         }
157
158         private string cast_label_markup (Movie movie) {
159                 List<Role> cast = movie.get_cast ();
160                 var markup = new StringBuilder ();
161                 Gdk.Color color;
162                 this.ensure_style ();
163
164                 if (this.style.lookup_color ("SecondaryTextColor", out color)) {
165                         foreach (Role role in cast) {
166                                 if (markup.len > 0)
167                                         markup.append (",\n");
168                                 markup.append_printf ("%s <span size=\"small\" fgcolor=\"%s\">(%s)</span>", display_name (role.actor_name), color.to_string (), role.character);
169                         }
170                 } else {
171                         foreach (Role role in cast) {
172                                 if (markup.len > 0)
173                                         markup.append (",\n");
174                                 markup.append_printf ("%s <small>(%s)</small>", display_name (role.actor_name), role.character);
175                         }
176                 }
177
178                 return markup.str;
179         }
180
181         private string display_name (string name) {
182                 string[] parts;
183                 if (name.has_suffix (")"))
184                         parts = name.ndup (name.length - 4).split (", ");
185                 else
186                         parts = name.split (", ");
187                 if (parts.length == 2) {
188                         return parts[1] + " " + parts[0];
189                 } else {
190                         return name;
191                 }
192         }
193
194         private void receive_poster (Gdk.Pixbuf pixbuf, Movie movie) {
195                 var poster = new Poster();
196
197                 poster.large = pixbuf;
198                 if (movie.poster != null) {
199                         poster.icon = movie.poster.icon;
200                         poster.small = movie.poster.small;
201                 }
202                 movie.poster = poster;
203         }
204
205         private void on_movie_changed (GLib.Object source, GLib.ParamSpec spec) {
206                 var movie = (Movie) source;
207
208                 if ((spec.name == "title") || (spec.name == "year")) {
209                         update_title (movie);
210                         title_label.set_markup (title_label_markup (movie));
211                 }
212                 if (spec.name == "rating") {
213                         rating_label.set_markup (rating_label_markup (movie));
214                 }
215                 if ((spec.name == "poster") && (movie.poster != null) && (movie.poster.large != null)) {
216                         image.pixbuf = movie.poster.large;
217                 }
218         }
219
220         private void on_orientation_changed (Gdk.Screen screen) {
221                 if (CinaestProgram.orientation.portrait == portrait_mode)
222                         return;
223
224                 portrait_mode = CinaestProgram.orientation.portrait;
225                 if (portrait_mode) {
226                         hbox.remove (image);
227                         details.pack_start (image, false, false, 0);
228                         details.reorder_child (image, 0);
229                         plot.set_size_request (480 - 2 * MARGIN_DOUBLE, -1);
230                         pannable.set_size_request (-1, -1);
231                 } else {
232                         details.remove (image);
233                         hbox.pack_start (image, false, false, MARGIN_DOUBLE);
234                         hbox.reorder_child (image, 0);
235                         pannable.set_size_request (-1, 424);
236                         plot.set_size_request (800 - 288 /* image */ - 3 * MARGIN_DOUBLE, -1);
237                 }
238         }
239 }
240