From 74873babf8ed3ffb3dd79858328d5b3f142479a3 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 25 Mar 2019 00:30:19 +0000 Subject: [PATCH] Sort KDM CPL list in reverse timestamp order (#1496). --- src/lib/film.cc | 13 ++++++++++++- src/lib/types.cc | 2 ++ src/lib/types.h | 10 ++++++---- src/wx/kdm_cpl_panel.cc | 7 ++++++- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/lib/film.cc b/src/lib/film.cc index 76cd8da96..f61d5106f 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -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 Film::cpls () const { @@ -1063,6 +1072,8 @@ Film::cpls () const } } + sort (out.begin(), out.end(), cpl_summary_compare); + return out; } diff --git a/src/lib/types.cc b/src/lib/types.cc index ee36431cf..a0095cedf 100644 --- a/src/lib/types.cc +++ b/src/lib/types.cc @@ -208,4 +208,6 @@ CPLSummary::CPLSummary (boost::filesystem::path p) } } } + + last_write_time = boost::filesystem::last_write_time (p); } diff --git a/src/lib/types.h b/src/lib/types.h index 3c9a8025b..14840d5a6 100644 --- a/src/lib/types.h +++ b/src/lib/types.h @@ -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 diff --git a/src/wx/kdm_cpl_panel.cc b/src/wx/kdm_cpl_panel.cc index 4151f84a7..967fb2845 100644 --- a/src/wx/kdm_cpl_panel.cc +++ b/src/wx/kdm_cpl_panel.cc @@ -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) { -- 2.30.2