Movie list menu: store the movie source
[cinaest] / src / plugins / catalog-plugin.vala
index 550a810..831914c 100644 (file)
@@ -55,6 +55,9 @@ class CatalogPlugin : Plugin {
                source = new CatalogSource ("Loaned", _("Loaned movies"), _("Movies loaned to friends"), sqlite, !("Loaned" in hidden_sources));
                sources.append (source);
 
+               source = new WatchedSource (sqlite, !("Watched" in hidden_sources));
+               sources.append (source);
+
                source = new CatalogSource ("Watchlist", _("Watchlist"), _("Movies of interest"), sqlite, !("Watchlist" in hidden_sources));
                sources.append (source);
 
@@ -81,13 +84,13 @@ class CatalogPlugin : Plugin {
                int i = 0;
                var available_sources = new List<MovieSource> ();
                foreach (CatalogSource s in sources) {
-                       if (!s.contains (movie)) {
+                       if (!s.contains (movie) && s.table != "Watched") {
                                available_sources.append ((MovieSource) s);
                                i++;
                        }
                }
 
-               var source_list = new SourceListView (available_sources, true);
+               var source_list = new SourceListView (available_sources, true, window);
 
                var content = (VBox) dialog.get_content_area ();
                content.pack_start (source_list, true, true, 0);
@@ -102,10 +105,37 @@ class CatalogPlugin : Plugin {
                int res = dialog.run ();
                if (res >= 0) {
                        var source = sources.nth_data (res);
-                       source.add_movie (movie);
 
-                       var banner = (Banner) Banner.show_information_with_markup (window, null, _("'%s' added to list '%s'").printf (movie.title, source.get_name ()));
-                       banner.set_timeout (1500);
+                       if (source.table == "Loaned") {
+                               var dialog = new Gtk.Dialog ();
+                               dialog.set_title (_("Add to loaned movies"));
+
+                               var contact = new Hildon.Entry (SizeType.FINGER_HEIGHT);
+                               contact.set_placeholder ("Contact");
+                               var date = new Hildon.DateButton (SizeType.FINGER_HEIGHT, ButtonArrangement.VERTICAL);
+                               date.set_title (_("Loaned on"));
+                               date.set_alignment (0.0f, 0.5f, 1.0f, 1.0f);
+
+                               content = (Gtk.VBox) dialog.get_content_area ();
+                               content.pack_start (contact, true, false, 0);
+                               content.pack_start (date, true, false, 0);
+
+                               dialog.add_button (_("Done"), Gtk.ResponseType.OK);
+                               dialog.show_all ();
+                               res = dialog.run ();
+                               dialog.destroy ();
+                               if (res == Gtk.ResponseType.OK) {
+                                       source.add_movie (movie);
+
+                                       var banner = (Banner) Banner.show_information_with_markup (window, null, _("'%s' added to list of loaned movies").printf (movie.title, source.get_name ()));
+                                       banner.set_timeout (1500);
+                               }
+                       } else {
+                               source.add_movie (movie);
+
+                               var banner = (Banner) Banner.show_information_with_markup (window, null, _("'%s' added to list '%s'").printf (movie.title, source.get_name ()));
+                               banner.set_timeout (1500);
+                       }
                }
                dialog.destroy ();
                dialog = null;
@@ -147,7 +177,7 @@ class CatalogPlugin : Plugin {
                dialog.set_transient_for (window);
                dialog.set_title (_("Select active movie lists"));
 
-               var source_list = new SourceListView (sources, false);
+               var source_list = new SourceListView (sources, false, window);
                source_list.set_hildon_ui_mode (UIMode.EDIT);
 
                var selection = source_list.get_selection ();
@@ -243,9 +273,9 @@ class CatalogPlugin : Plugin {
 
 class CatalogSource : MovieSource {
        internal string table;
-       private string name;
-       private string description;
-       private CatalogSqlite sqlite;
+       internal string name;
+       internal string description;
+       internal CatalogSqlite sqlite;
 
        public CatalogSource (string _table, string _name, string _description, CatalogSqlite _sqlite, bool _active) {
                GLib.Object (active: _active);
@@ -282,13 +312,32 @@ class CatalogSource : MovieSource {
                return description;
        }
 
-       public override bool get_editable () {
-               return true;
+       public override SourceFlags get_flags () {
+               return SourceFlags.EDITABLE;
+       }
+}
+
+class WatchedSource : CatalogSource {
+       public WatchedSource (CatalogSqlite _sqlite, bool _active) {
+               GLib.Object (active: _active);
+               table = "Watched";
+               name = _("Watched movies");
+               description = _("Watched / rated movies");
+               sqlite = _sqlite;
+       }
+
+       public override async int get_movies (MovieFilter filter, MovieSource.ReceiveMovieFunction callback, int limit, Cancellable? cancellable) {
+               int n = yield sqlite.query (table, filter, callback, limit, cancellable);
+               return n;
+       }
+
+       public override SourceFlags get_flags () {
+               return SourceFlags.EDITABLE | SourceFlags.RATING;
        }
 }
 
 [ModuleInit]
-public Type register_plugin () {
+public Type register_plugin (TypeModule module) {
        // types are registered automatically
        return typeof (CatalogPlugin);
 }