From 9262839360779de83b711f86151fcf56b86c3989 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 5 May 2020 00:35:13 +0200 Subject: [PATCH] Replace CinemaKDMs class with a list --- src/lib/cinema_kdms.cc | 53 +++++++++++++++-------------------- src/lib/cinema_kdms.h | 17 ++++------- src/lib/send_kdm_email_job.cc | 2 +- src/lib/send_kdm_email_job.h | 6 ++-- src/wx/kdm_output_panel.cc | 10 +++---- 5 files changed, 37 insertions(+), 51 deletions(-) diff --git a/src/lib/cinema_kdms.cc b/src/lib/cinema_kdms.cc index d96a95d7f..94e83f807 100644 --- a/src/lib/cinema_kdms.cc +++ b/src/lib/cinema_kdms.cc @@ -43,13 +43,11 @@ using boost::function; using boost::optional; void -make_zip_file (CinemaKDMs kdms, boost::filesystem::path zip_file, dcp::NameFormat name_format, dcp::NameFormat::Map name_values) +make_zip_file (list kdms, boost::filesystem::path zip_file, dcp::NameFormat name_format, dcp::NameFormat::Map name_values) { Zipper zipper (zip_file); - name_values['c'] = kdms.cinema->name; - - BOOST_FOREACH (KDMWithMetadataPtr i, kdms.screen_kdms) { + BOOST_FOREACH (KDMWithMetadataPtr i, kdms) { name_values['i'] = i->kdm_id (); string const name = careful_string_filter(name_format.get(name_values, ".xml")); zipper.add (name, i->kdm_as_xml()); @@ -58,30 +56,29 @@ make_zip_file (CinemaKDMs kdms, boost::filesystem::path zip_file, dcp::NameForma zipper.close (); } -/** Collect a list of KDMWithMetadatas into a list of CinemaKDMs so that each +/** Collect a list of KDMWithMetadatas into a list of list so that each * CinemaKDM contains the KDMs for its cinema. */ -list +list > collect (list screen_kdms) { - list cinema_kdms; + list > cinema_kdms; while (!screen_kdms.empty ()) { /* Get all the screens from a single cinema */ - CinemaKDMs ck; + list ck; list::iterator i = screen_kdms.begin (); - ck.cinema = (*i)->cinema(); - ck.screen_kdms.push_back (*i); + ck.push_back (*i); list::iterator j = i; ++i; screen_kdms.remove (*j); while (i != screen_kdms.end ()) { - if ((*i)->cinema() == ck.cinema) { - ck.screen_kdms.push_back (*i); + if ((*i)->cinema() == ck.front()->cinema()) { + ck.push_back (*i); list::iterator j = i; ++i; screen_kdms.remove (*j); @@ -99,7 +96,7 @@ collect (list screen_kdms) /** Write one directory per cinema into another directory */ int write_directories ( - list cinema_kdms, + list > cinema_kdms, boost::filesystem::path directory, dcp::NameFormat container_name_format, dcp::NameFormat filename_format, @@ -112,15 +109,14 @@ write_directories ( int written = 0; - BOOST_FOREACH (CinemaKDMs const & i, cinema_kdms) { + BOOST_FOREACH (list const & i, cinema_kdms) { boost::filesystem::path path = directory; - name_values['c'] = i.cinema->name; path /= container_name_format.get(name_values, ""); if (!boost::filesystem::exists (path) || confirm_overwrite (path)) { boost::filesystem::create_directories (path); - write_files (i.screen_kdms, path, filename_format, name_values, confirm_overwrite); + write_files (i, path, filename_format, name_values, confirm_overwrite); } - written += i.screen_kdms.size(); + written += i.size(); } return written; @@ -129,7 +125,7 @@ write_directories ( /** Write one ZIP file per cinema into a directory */ int write_zip_files ( - list cinema_kdms, + list > cinema_kdms, boost::filesystem::path directory, dcp::NameFormat container_name_format, dcp::NameFormat filename_format, @@ -142,9 +138,8 @@ write_zip_files ( int written = 0; - BOOST_FOREACH (CinemaKDMs const & i, cinema_kdms) { + BOOST_FOREACH (list const & i, cinema_kdms) { boost::filesystem::path path = directory; - name_values['c'] = i.cinema->name; path /= container_name_format.get(name_values, ".zip"); if (!boost::filesystem::exists (path) || confirm_overwrite (path)) { if (boost::filesystem::exists (path)) { @@ -152,7 +147,7 @@ write_zip_files ( boost::filesystem::remove (path); } make_zip_file (i, path, filename_format, name_values); - written += i.screen_kdms.size(); + written += i.size(); } } @@ -168,7 +163,7 @@ write_zip_files ( */ void email ( - list cinema_kdms, + list > cinema_kdms, dcp::NameFormat container_name_format, dcp::NameFormat filename_format, dcp::NameFormat::Map name_values, @@ -184,14 +179,12 @@ email ( /* No specific screen */ name_values['s'] = ""; - BOOST_FOREACH (CinemaKDMs const & i, cinema_kdms) { + BOOST_FOREACH (list const & i, cinema_kdms) { - if (i.cinema->emails.empty()) { + if (i.front()->cinema()->emails.empty()) { continue; } - name_values['c'] = i.cinema->name; - boost::filesystem::path zip_file = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path(); boost::filesystem::create_directories (zip_file); zip_file /= container_name_format.get(name_values, ".zip"); @@ -201,16 +194,16 @@ email ( boost::algorithm::replace_all (subject, "$CPL_NAME", cpl_name); boost::algorithm::replace_all (subject, "$START_TIME", name_values['b']); boost::algorithm::replace_all (subject, "$END_TIME", name_values['e']); - boost::algorithm::replace_all (subject, "$CINEMA_NAME", i.cinema->name); + boost::algorithm::replace_all (subject, "$CINEMA_NAME", i.front()->cinema()->name); string body = config->kdm_email().c_str(); boost::algorithm::replace_all (body, "$CPL_NAME", cpl_name); boost::algorithm::replace_all (body, "$START_TIME", name_values['b']); boost::algorithm::replace_all (body, "$END_TIME", name_values['e']); - boost::algorithm::replace_all (body, "$CINEMA_NAME", i.cinema->name); + boost::algorithm::replace_all (body, "$CINEMA_NAME", i.front()->cinema()->name); string screens; - BOOST_FOREACH (KDMWithMetadataPtr j, i.screen_kdms) { + BOOST_FOREACH (KDMWithMetadataPtr j, i) { optional screen_name = j->get('n'); if (screen_name) { screens += *screen_name + ", "; @@ -218,7 +211,7 @@ email ( } boost::algorithm::replace_all (body, "$SCREENS", screens.substr (0, screens.length() - 2)); - Emailer email (config->kdm_from(), i.cinema->emails, subject, body); + Emailer email (config->kdm_from(), i.front()->cinema()->emails, subject, body); BOOST_FOREACH (string i, config->kdm_cc()) { email.add_cc (i); diff --git a/src/lib/cinema_kdms.h b/src/lib/cinema_kdms.h index 592bec923..0a5749ee8 100644 --- a/src/lib/cinema_kdms.h +++ b/src/lib/cinema_kdms.h @@ -24,19 +24,12 @@ class Cinema; class Job; class Log; -class CinemaKDMs -{ -public: - boost::shared_ptr cinema; - std::list screen_kdms; -}; +void make_zip_file (std::list kdms, boost::filesystem::path zip_file, dcp::NameFormat name_format, dcp::NameFormat::Map name_values); -void make_zip_file (CinemaKDMs kdms, boost::filesystem::path zip_file, dcp::NameFormat name_format, dcp::NameFormat::Map name_values); - -std::list collect (std::list kdms); +std::list > collect (std::list kdms); int write_directories ( - std::list cinema_kdms, + std::list > cinema_kdms, boost::filesystem::path directory, dcp::NameFormat container_name_format, dcp::NameFormat filename_format, @@ -45,7 +38,7 @@ int write_directories ( ); int write_zip_files ( - std::list cinema_kdms, + std::list > cinema_kdms, boost::filesystem::path directory, dcp::NameFormat container_name_format, dcp::NameFormat filename_format, @@ -54,7 +47,7 @@ int write_zip_files ( ); void email ( - std::list cinema_kdms, + std::list > cinema_kdms, dcp::NameFormat container_name_format, dcp::NameFormat filename_format, dcp::NameFormat::Map name_values, diff --git a/src/lib/send_kdm_email_job.cc b/src/lib/send_kdm_email_job.cc index 10a571ead..e9bad4c20 100644 --- a/src/lib/send_kdm_email_job.cc +++ b/src/lib/send_kdm_email_job.cc @@ -37,7 +37,7 @@ using boost::shared_ptr; * @param cpl_name Name of the CPL that the KDMs are for. */ SendKDMEmailJob::SendKDMEmailJob ( - list cinema_kdms, + list > cinema_kdms, dcp::NameFormat container_name_format, dcp::NameFormat filename_format, dcp::NameFormat::Map name_values, diff --git a/src/lib/send_kdm_email_job.h b/src/lib/send_kdm_email_job.h index a7196fe15..7a70d555c 100644 --- a/src/lib/send_kdm_email_job.h +++ b/src/lib/send_kdm_email_job.h @@ -19,6 +19,7 @@ */ #include "job.h" +#include "kdm_with_metadata.h" #include #include #include @@ -27,14 +28,13 @@ namespace dcpomatic { class Screen; } -class CinemaKDMs; class Log; class SendKDMEmailJob : public Job { public: SendKDMEmailJob ( - std::list cinema_kdms, + std::list > cinema_kdms, dcp::NameFormat container_name_format, dcp::NameFormat filename_format, dcp::NameFormat::Map name_values, @@ -51,5 +51,5 @@ private: dcp::NameFormat _filename_format; dcp::NameFormat::Map _name_values; std::string _cpl_name; - std::list _cinema_kdms; + std::list > _cinema_kdms; }; diff --git a/src/wx/kdm_output_panel.cc b/src/wx/kdm_output_panel.cc index fe87dfccd..c2884008f 100644 --- a/src/wx/kdm_output_panel.cc +++ b/src/wx/kdm_output_panel.cc @@ -186,7 +186,7 @@ KDMOutputPanel::make ( list screen_kdms, string name, KDMTimingPanel* timing, function confirm_overwrite ) { - list const cinema_kdms = collect (screen_kdms); + list > const cinema_kdms = collect (screen_kdms); /* Decide whether to proceed */ @@ -200,8 +200,8 @@ KDMOutputPanel::make ( } bool cinemas_with_no_email = false; - BOOST_FOREACH (CinemaKDMs i, cinema_kdms) { - if (i.cinema->emails.empty ()) { + BOOST_FOREACH (list i, cinema_kdms) { + if (i.front()->cinema()->emails.empty ()) { cinemas_with_no_email = true; } } @@ -215,8 +215,8 @@ KDMOutputPanel::make ( if (proceed && Config::instance()->confirm_kdm_email ()) { list emails; - BOOST_FOREACH (CinemaKDMs i, cinema_kdms) { - BOOST_FOREACH (string j, i.cinema->emails) { + BOOST_FOREACH (list const& i, cinema_kdms) { + BOOST_FOREACH (string j, i.front()->cinema()->emails) { emails.push_back (j); } } -- 2.30.2