/* This file is part of Cinaest. * * Copyright (C) 2009 Philipp Zabel * * Cinaest is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Cinaest is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Cinaest. If not, see . */ using Hildon; using Osso; public class MovieMenu : AppMenu { private Movie movie; private MovieListStore store; private Gtk.Window parent_window; private List actions; public signal void movie_deleted (); public MovieMenu (Movie _movie, MovieListStore _store, Gtk.Window window) { bool can_rate = false; movie = _movie; store = _store; parent_window = window; foreach (Plugin plugin in CinaestProgram.plugins) { foreach (MovieAction action in plugin.get_actions (movie, window)) { var button = new Gtk.Button.with_label (action.name); button.clicked.connect (action.execute); append (button); actions.append (action); } foreach (MovieSource source in plugin.get_sources ()) { if (source.active && SourceFlags.RATING in source.get_flags ()) can_rate = true; } } if (can_rate) { var button = new Gtk.Button.with_label (_("Rate movie")); button.clicked.connect (on_rate_movie); append (button); } if (store.get_editable ()) { var button = new Gtk.Button.with_label (_("Edit movie")); button.clicked.connect (on_edit_movie); append (button); button = new Gtk.Button.with_label (_("Delete movie")); button.clicked.connect (on_delete_movie); append (button); } show_all (); } private void on_rate_movie () { var dialog = new Gtk.Dialog (); dialog.set_title (_("Rate movie")); var rating = new RatingWidget (); var date = new Hildon.DateButton (SizeType.FINGER_HEIGHT, ButtonArrangement.VERTICAL); date.set_title (_("Watched on")); date.set_alignment (0.0f, 0.5f, 1.0f, 1.0f); var content = (Gtk.VBox) dialog.get_content_area (); content.pack_start (rating, true, false, 0); content.pack_start (date, true, false, 0); dialog.add_button (_("Done"), Gtk.ResponseType.OK); dialog.show_all (); var res = dialog.run (); dialog.destroy (); if (res == Gtk.ResponseType.OK) { movie.julian_date = get_julian_date (date); movie.rating = rating.rating; Banner.show_information (parent_window, null, _("Rated movie '%s': %.1f").printf (movie.title, movie.rating/10.0)); foreach (Plugin plugin in CinaestProgram.plugins) { foreach (MovieSource source in plugin.get_sources ()) { if (source.active && SourceFlags.RATING in source.get_flags ()) source.add_movie (movie); } } } } private uint get_julian_date (DateButton button) { var date = Date (); uint year; uint month; uint day; button.get_date (out year, out month, out day); date.set_dmy ((DateDay) day, (DateMonth) month + DateMonth.JANUARY, (DateYear) year); return date.get_julian (); } private void on_delete_movie () { var dialog = new Note.confirmation (parent_window, _("Delete movie '%s'?").printf (movie.title)); var res = dialog.run (); dialog.destroy (); if (res == Gtk.ResponseType.OK) { store.remove (movie); movie_deleted (); } } private void on_edit_movie () { var dialog = new MovieEditDialog (parent_window, movie); var res = dialog.run (); } }