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 (_("Edit movie"));
54 button.clicked.connect (on_edit_movie);
56 button = new Gtk.Button.with_label (_("Delete movie"));
57 button.clicked.connect (on_delete_movie);
64 private void on_rate_movie () {
65 var dialog = new Gtk.Dialog ();
66 dialog.set_title (_("Rate movie"));
68 var rating = new RatingWidget ();
69 var date = new Hildon.DateButton (SizeType.FINGER_HEIGHT, ButtonArrangement.VERTICAL);
70 date.set_title (_("Watched on"));
71 date.set_alignment (0.0f, 0.5f, 1.0f, 1.0f);
73 var content = (Gtk.VBox) dialog.get_content_area ();
74 content.pack_start (rating, true, false, 0);
75 content.pack_start (date, true, false, 0);
77 dialog.add_button (_("Done"), Gtk.ResponseType.OK);
79 var res = dialog.run ();
81 if (res == Gtk.ResponseType.OK) {
82 movie.julian_date = get_julian_date (date);
83 movie.rating = rating.rating;
84 Banner.show_information (parent_window, null, _("Rated movie '%s': %.1f").printf (movie.title, movie.rating/10.0));
85 foreach (Plugin plugin in CinaestProgram.plugins) {
86 foreach (MovieSource source in plugin.get_sources ()) {
87 if (source.active && SourceFlags.RATING in source.get_flags ())
88 source.add_movie (movie);
94 private uint get_julian_date (DateButton button) {
99 button.get_date (out year, out month, out day);
100 date.set_dmy ((DateDay) day, (DateMonth) month + DateMonth.JANUARY, (DateYear) year);
101 return date.get_julian ();
104 private void on_delete_movie () {
105 var dialog = new Note.confirmation (parent_window, _("Delete movie '%s'?").printf (movie.title));
106 var res = dialog.run ();
109 if (res == Gtk.ResponseType.OK) {
110 store.remove (movie);
115 private void on_edit_movie () {
116 var dialog = new MovieEditDialog (parent_window, movie);
117 var res = dialog.run ();