Sort KDM CPL list in reverse timestamp order (#1496).
[dcpomatic.git] / src / lib / film.cc
index f4745d0995597d2e17a91fee185a26d187d8f2bf..f61d5106f14e42c5a60e71d015ed1221d015c152 100644 (file)
@@ -92,6 +92,7 @@ using std::runtime_error;
 using std::copy;
 using std::back_inserter;
 using std::map;
+using std::exception;
 using boost::shared_ptr;
 using boost::weak_ptr;
 using boost::dynamic_pointer_cast;
@@ -454,6 +455,16 @@ Film::read_metadata (optional<boost::filesystem::path> path)
        _state_version = f.number_child<int> ("Version");
        if (_state_version > current_state_version) {
                throw runtime_error (_("This film was created with a newer version of DCP-o-matic, and it cannot be loaded into this version.  Sorry!"));
+       } else if (_state_version < current_state_version) {
+               /* This is an older version; save a copy (if we haven't already) */
+               boost::filesystem::path const older = path->parent_path() / String::compose("metadata.%1.xml", _state_version);
+               if (!boost::filesystem::is_regular_file(older)) {
+                       try {
+                               boost::filesystem::copy_file(*path, older);
+                       } catch (...) {
+                               /* Never mind; at least we tried */
+                       }
+               }
        }
 
        _name = f.string_child ("Name");
@@ -1027,7 +1038,16 @@ Film::j2c_path (int reel, Frame frame, Eyes eyes, bool tmp) const
        return file (p);
 }
 
-/** Find all the DCPs in our directory that can be dcp::DCP::read() and return details of their CPLs */
+static
+bool
+cpl_summary_compare (CPLSummary const & a, CPLSummary const & b)
+{
+       return a.last_write_time > b.last_write_time;
+}
+
+/** Find all the DCPs in our directory that can be dcp::DCP::read() and return details of their CPLs.
+ *  The list will be returned in reverse order of timestamp (i.e. most recent first).
+ */
 vector<CPLSummary>
 Film::cpls () const
 {
@@ -1045,23 +1065,15 @@ Film::cpls () const
                        ) {
 
                        try {
-                               dcp::DCP dcp (*i);
-                               dcp.read ();
-                               DCPOMATIC_ASSERT (dcp.cpls().front()->file());
-                               out.push_back (
-                                       CPLSummary (
-                                               i->path().leaf().string(),
-                                               dcp.cpls().front()->id(),
-                                               dcp.cpls().front()->annotation_text(),
-                                               dcp.cpls().front()->file().get()
-                                               )
-                                       );
+                               out.push_back (CPLSummary(*i));
                        } catch (...) {
 
                        }
                }
        }
 
+       sort (out.begin(), out.end(), cpl_summary_compare);
+
        return out;
 }
 
@@ -1220,6 +1232,31 @@ Film::playlist_change (ChangeType type)
 {
        signal_change (type, CONTENT);
        signal_change (type, NAME);
+
+       if (type == CHANGE_TYPE_DONE) {
+               /* Check that this change hasn't made our settings inconsistent */
+               bool change_made = false;
+               BOOST_FOREACH (shared_ptr<Content> i, content()) {
+                       shared_ptr<DCPContent> d = dynamic_pointer_cast<DCPContent>(i);
+                       if (!d) {
+                               continue;
+                       }
+
+                       string why_not;
+                       if (d->reference_video() && !d->can_reference_video(shared_from_this(), why_not)) {
+                               d->set_reference_video(false);
+                               change_made = true;
+                       }
+                       if (d->reference_audio() && !d->can_reference_audio(shared_from_this(), why_not)) {
+                               d->set_reference_audio(false);
+                               change_made = true;
+                       }
+               }
+
+               if (change_made) {
+                       Message (_("DCP-o-matic had to change your settings for referring to DCPs as OV.  Please review those settings to make sure they are what you want."));
+               }
+       }
 }
 
 void