1 /* This file is part of Cinaest.
3 * Copyright (C) 2009 Philipp Zabel
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.
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.
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/>.
22 public class MovieMenu : AppMenu {
24 private MovieListStore store;
25 private Gtk.Window parent_window;
26 private List<MovieAction> actions;
28 public signal void movie_deleted ();
30 public MovieMenu (Movie _movie, MovieListStore _store, Gtk.Window window) {
31 bool can_rate = false;
34 parent_window = window;
35 foreach (Plugin plugin in CinaestProgram.plugins) {
36 foreach (MovieAction action in plugin.get_actions (movie, window)) {
37 var button = new Gtk.Button.with_label (action.name);
38 button.clicked.connect (action.execute);
40 actions.append (action);
42 foreach (MovieSource source in plugin.get_sources ()) {
43 if (source.active && SourceFlags.RATING in source.get_flags ())
48 var button = new Gtk.Button.with_label (_("Rate movie"));
49 button.clicked.connect (on_rate_movie);
52 if (store.get_editable ()) {
53 var button = new Gtk.Button.with_label (_("Delete movie"));
54 button.clicked.connect (on_delete_movie);
61 private void on_rate_movie () {
62 var dialog = new Gtk.Dialog ();
63 dialog.set_title (_("Rate movie"));
65 var rating = new RatingWidget ();
66 var date = new Hildon.DateButton (SizeType.FINGER_HEIGHT, ButtonArrangement.VERTICAL);
67 date.set_title (_("Watched on"));
68 date.set_alignment (0.0f, 0.5f, 1.0f, 1.0f);
70 var content = (Gtk.VBox) dialog.get_content_area ();
71 content.pack_start (rating, true, false, 0);
72 content.pack_start (date, true, false, 0);
74 dialog.add_button (_("Done"), Gtk.ResponseType.OK);
76 var res = dialog.run ();
78 if (res == Gtk.ResponseType.OK) {
79 movie.julian_date = get_julian_date (date);
80 movie.rating = 10 * rating.get_rating ();
81 Banner.show_information (parent_window, null, _("Rated movie '%s': %.1f").printf (movie.title, movie.rating/10.0));
82 foreach (Plugin plugin in CinaestProgram.plugins) {
83 foreach (MovieSource source in plugin.get_sources ()) {
84 if (source.active && SourceFlags.RATING in source.get_flags ())
85 source.add_movie (movie);
91 private uint get_julian_date (DateButton button) {
96 button.get_date (out year, out month, out day);
97 date.set_dmy ((DateDay) day, (DateMonth) month + DateMonth.JANUARY, (DateYear) year);
98 return date.get_julian ();
101 private void on_delete_movie () {
102 var dialog = new Note.confirmation (parent_window, _("Delete movie '%s'?").printf (movie.title));
103 var res = dialog.run ();
106 if (res == Gtk.ResponseType.OK) {
107 store.remove (movie);