swaroop: better handling of missing content in SPLs.
authorCarl Hetherington <cth@carlh.net>
Sat, 8 Dec 2018 22:17:35 +0000 (22:17 +0000)
committerCarl Hetherington <cth@carlh.net>
Sat, 8 Dec 2018 22:17:35 +0000 (22:17 +0000)
src/lib/spl.cc
src/lib/spl.h
src/tools/dcpomatic_playlist.cc
src/wx/swaroop_controls.cc

index 74538aa990d9007e9728100cded052043d6a3804..2cba229c10962f4ee4c3ccb48f8db26c58ce392c 100644 (file)
 using std::cout;
 using boost::shared_ptr;
 
-bool
+void
 SPL::read (boost::filesystem::path path, ContentStore* store)
 {
        _spl.clear ();
+       _missing = false;
        cxml::Document doc ("SPL");
        doc.read_file (path);
-       bool missing = false;
        BOOST_FOREACH (cxml::ConstNodePtr i, doc.node_children("Entry")) {
                shared_ptr<Content> c = store->get(i->string_child("Digest"));
                if (c) {
                        add (SPLEntry(c, i));
                } else {
-                       missing = true;
+                       _missing = true;
                }
        }
 
        _name = path.filename().string();
-       return missing;
 }
 
 void
index a0b754f04acd72b3f3229dd6fc41e8ee06d1d2a3..b94c0857197f63791e34cfc795e2b1b5c5ee32e0 100644 (file)
@@ -28,6 +28,10 @@ class ContentStore;
 class SPL
 {
 public:
+       SPL ()
+               : _missing (false)
+       {}
+
        void add (SPLEntry e) {
                _spl.push_back (e);
        }
@@ -48,16 +52,22 @@ public:
                return _spl[index];
        }
 
-       bool read (boost::filesystem::path path, ContentStore* store);
+       void read (boost::filesystem::path path, ContentStore* store);
        void write (boost::filesystem::path path) const;
 
        std::string name () const {
                return _name;
        }
 
+       bool missing () const {
+               return _missing;
+       }
+
 private:
        std::string _name;
        std::vector<SPLEntry> _spl;
+       /** true if any content was missing when read() was last called on this SPL */
+       bool _missing;
 };
 
 #endif
index bac47d6dbae3ee02067c1e69b7f6375f98fd2ffc..ad54e364817352a92ec4d5ab9fa5eacfd8493dbf 100644 (file)
@@ -295,7 +295,8 @@ private:
                wxFileDialog* d = new wxFileDialog (this, _("Select playlist file"), default_dir, wxEmptyString, wxT("XML files (*.xml)|*.xml"));
                if (d->ShowModal() == wxID_OK) {
                        _list->DeleteAllItems ();
-                       if (!_playlist.read (wx_to_std(d->GetPath()), _content_dialog)) {
+                       _playlist.read (wx_to_std(d->GetPath()), _content_dialog);
+                       if (!_playlist.missing()) {
                                BOOST_FOREACH (SPLEntry i, _playlist.get()) {
                                        add (i);
                                }
index 2f51fed3f3833d840005f2120fb2159f351d4f19..99a19f5de7fd17ace10440a3b239e5c00cd8548f 100644 (file)
@@ -214,7 +214,11 @@ SwaroopControls::add_playlist_to_list (SPL spl)
        wxListItem it;
        it.SetId(N);
        it.SetColumn(0);
-       it.SetText (std_to_wx(spl.name()));
+       string t = spl.name();
+       if (spl.missing()) {
+               t += " (content missing)";
+       }
+       it.SetText (std_to_wx(t));
        _spl_view->InsertItem (it);
 }
 
@@ -248,17 +252,36 @@ SwaroopControls::update_playlist_directory ()
 void
 SwaroopControls::spl_selection_changed ()
 {
-       _current_spl_view->DeleteAllItems ();
-
        long int selected = _spl_view->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
        if (selected == -1) {
+               _current_spl_view->DeleteAllItems ();
+               _selected_playlist = boost::none;
+               return;
+       }
+
+       if (_playlists[selected].missing()) {
+               error_dialog (this, "This playlist cannot be loaded as some content is missing.");
                _selected_playlist = boost::none;
+               _spl_view->SetItemState (selected, 0, wxLIST_STATE_SELECTED);
                return;
        }
 
-       wxProgressDialog progress (_("DCP-o-matic"), _("Loading playlist"));
+       wxProgressDialog* progress = new wxProgressDialog (_("DCP-o-matic"), _("Loading playlist"));
 
        shared_ptr<Film> film (new Film(optional<boost::filesystem::path>()));
+       BOOST_FOREACH (SPLEntry i, _playlists[selected].get()) {
+               film->add_content (i.content);
+               if (!progress->Pulse()) {
+                       /* user pressed cancel */
+                       _selected_playlist = boost::none;
+                       _spl_view->SetItemState (selected, 0, wxLIST_STATE_SELECTED);
+                       progress->Destroy ();
+                       return;
+               }
+       }
+
+       progress->Destroy ();
+       _current_spl_view->DeleteAllItems ();
 
        int N = 0;
        BOOST_FOREACH (SPLEntry i, _playlists[selected].get()) {
@@ -267,12 +290,7 @@ SwaroopControls::spl_selection_changed ()
                it.SetColumn (0);
                it.SetText (std_to_wx(i.name));
                _current_spl_view->InsertItem (it);
-               film->add_content (i.content);
                ++N;
-               if (!progress.Pulse()) {
-                       /* user pressed cancel */
-                       return;
-               }
        }
 
        _selected_playlist = selected;