Movie menu: add rating button and rating dialog
authorPhilipp Zabel <philipp.zabel@gmail.com>
Tue, 9 Feb 2010 20:42:00 +0000 (21:42 +0100)
committerPhilipp Zabel <philipp.zabel@gmail.com>
Tue, 9 Feb 2010 20:42:00 +0000 (21:42 +0100)
src/movie-menu.vala
src/plugin-interface.vala

index 3860527..a3e2544 100644 (file)
@@ -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 ();
index 0c76178..0252e9a 100644 (file)
@@ -30,6 +30,7 @@ public abstract class Plugin : Object {
 public enum SourceFlags {
        EDITABLE = 1,
        ONLINE = 2,
+       RATING = 4,
 }
 
 public abstract class MovieSource : Object {