Sort KDM CPL list in reverse timestamp order (#1496).
authorCarl Hetherington <cth@carlh.net>
Mon, 25 Mar 2019 00:30:19 +0000 (00:30 +0000)
committerCarl Hetherington <cth@carlh.net>
Mon, 25 Mar 2019 00:30:19 +0000 (00:30 +0000)
src/lib/film.cc
src/lib/types.cc
src/lib/types.h
src/wx/kdm_cpl_panel.cc

index 76cd8da9645f256708dfaee443c0053dde2d797c..f61d5106f14e42c5a60e71d015ed1221d015c152 100644 (file)
@@ -1038,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
 {
@@ -1063,6 +1072,8 @@ Film::cpls () const
                }
        }
 
+       sort (out.begin(), out.end(), cpl_summary_compare);
+
        return out;
 }
 
index ee36431cf8755d17a42ddb5d8215cd78eaf954a1..a0095cedfdf1e96bdba7f22fd4e86a0b36943ca2 100644 (file)
@@ -208,4 +208,6 @@ CPLSummary::CPLSummary (boost::filesystem::path p)
                        }
                }
        }
+
+       last_write_time = boost::filesystem::last_write_time (p);
 }
index 3c9a8025b1a39a5006982a021ec5502e12f25e72..14840d5a678a1ba9c40d676687c2848501429ad1 100644 (file)
@@ -203,16 +203,20 @@ struct Crop
        void as_xml (xmlpp::Node *) const;
 };
 
+extern bool operator== (Crop const & a, Crop const & b);
+extern bool operator!= (Crop const & a, Crop const & b);
+
 struct CPLSummary
 {
        CPLSummary (boost::filesystem::path p);
 
-       CPLSummary (std::string d, std::string i, std::string a, boost::filesystem::path f, bool e)
+       CPLSummary (std::string d, std::string i, std::string a, boost::filesystem::path f, bool e, time_t t)
                : dcp_directory (d)
                , cpl_id (i)
                , cpl_annotation_text (a)
                , cpl_file (f)
                , encrypted (e)
+               , last_write_time (t)
        {}
 
        std::string dcp_directory;
@@ -221,11 +225,9 @@ struct CPLSummary
        boost::filesystem::path cpl_file;
        /** true if this CPL has any encrypted assets */
        bool encrypted;
+       time_t last_write_time;
 };
 
-extern bool operator== (Crop const & a, Crop const & b);
-extern bool operator!= (Crop const & a, Crop const & b);
-
 enum Resolution {
        RESOLUTION_2K,
        RESOLUTION_4K
index 4151f84a7b252adbb69a4ff123cef3b0bdc900d5..967fb28457e98800aea5997ac3bdcd45b35affde 100644 (file)
@@ -128,6 +128,10 @@ KDMCPLPanel::cpl_browse_clicked ()
                return;
        }
 
+       /* We're ignoring the CPLSummary timestamp stuff here and just putting the new one in at the end
+          of the list, then selecting it.
+       */
+
        try {
                _cpls.push_back (
                        CPLSummary (
@@ -135,7 +139,8 @@ KDMCPLPanel::cpl_browse_clicked ()
                                cpl_document.string_child("Id").substr (9),
                                cpl_document.string_child("ContentTitleText"),
                                cpl_file,
-                               encrypted
+                               encrypted,
+                               0
                                )
                        );
        } catch (cxml::Error) {