From 33f6039f8039e33ca55b3fc542ddaa512f3b9e06 Mon Sep 17 00:00:00 2001 From: Philipp Zabel Date: Tue, 9 Feb 2010 21:42:00 +0100 Subject: [PATCH] Movie menu: add rating button and rating dialog --- src/movie-menu.vala | 50 +++++++++++++++++++++++++++++++++++++++++++++ src/plugin-interface.vala | 1 + 2 files changed, 51 insertions(+) diff --git a/src/movie-menu.vala b/src/movie-menu.vala index 3860527..a3e2544 100644 --- a/src/movie-menu.vala +++ b/src/movie-menu.vala @@ -28,6 +28,7 @@ public class MovieMenu : AppMenu { 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; @@ -38,6 +39,15 @@ public class MovieMenu : AppMenu { 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 (_("Delete movie")); @@ -48,6 +58,46 @@ public class MovieMenu : AppMenu { 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 = 10 * rating.get_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 (); diff --git a/src/plugin-interface.vala b/src/plugin-interface.vala index 0c76178..0252e9a 100644 --- a/src/plugin-interface.vala +++ b/src/plugin-interface.vala @@ -30,6 +30,7 @@ public abstract class Plugin : Object { public enum SourceFlags { EDITABLE = 1, ONLINE = 2, + RATING = 4, } public abstract class MovieSource : Object { -- 1.7.9.5