X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=src%2Flib%2Fkdm_with_metadata.cc;h=123649d127c0a00fbf468d765505a17b89794046;hp=2747e414060463804141419526603a7ca4fc1ace;hb=8a8c977c12fc65f1f50ea05099387e0fc8840e7d;hpb=dd9be86db6cde0afa5da0d1d1ac43b42e05dca26 diff --git a/src/lib/kdm_with_metadata.cc b/src/lib/kdm_with_metadata.cc index 2747e4140..123649d12 100644 --- a/src/lib/kdm_with_metadata.cc +++ b/src/lib/kdm_with_metadata.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2016 Carl Hetherington + Copyright (C) 2013-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,40 +18,42 @@ */ -#include "kdm_with_metadata.h" + #include "cinema.h" -#include "screen.h" -#include "util.h" -#include "zipper.h" #include "config.h" +#include "cross.h" #include "dcpomatic_log.h" #include "emailer.h" -#include -#include -#include +#include "kdm_with_metadata.h" +#include "screen.h" +#include "util.h" +#include "zipper.h" +#include #include "i18n.h" -using std::string; + using std::cout; +using std::function; using std::list; using std::shared_ptr; +using std::string; using boost::optional; -using boost::function; + int write_files ( list kdms, boost::filesystem::path directory, dcp::NameFormat name_format, - boost::function confirm_overwrite + std::function confirm_overwrite ) { int written = 0; if (directory == "-") { /* Write KDMs to the stdout */ - BOOST_FOREACH (KDMWithMetadataPtr i, kdms) { + for (auto i: kdms) { cout << i->kdm_as_xml (); ++written; } @@ -64,8 +66,8 @@ write_files ( } /* Write KDMs to the specified directory */ - BOOST_FOREACH (KDMWithMetadataPtr i, kdms) { - boost::filesystem::path out = directory / careful_string_filter(name_format.get(i->name_values(), ".xml")); + for (auto i: kdms) { + auto out = dcp::fix_long_path(directory / careful_string_filter(name_format.get(i->name_values(), ".xml"))); if (!boost::filesystem::exists (out) || confirm_overwrite (out)) { i->kdm_as_xml (out); ++written; @@ -79,9 +81,9 @@ write_files ( optional KDMWithMetadata::get (char k) const { - dcp::NameFormat::Map::const_iterator i = _name_values.find (k); + auto i = _name_values.find (k); if (i == _name_values.end()) { - return optional(); + return {}; } return i->second; @@ -93,8 +95,8 @@ make_zip_file (list kdms, boost::filesystem::path zip_file, { Zipper zipper (zip_file); - BOOST_FOREACH (KDMWithMetadataPtr i, kdms) { - string const name = careful_string_filter(name_format.get(i->name_values(), ".xml")); + for (auto i: kdms) { + auto const name = careful_string_filter(name_format.get(i->name_values(), ".xml")); zipper.add (name, i->kdm_as_xml()); } @@ -105,14 +107,14 @@ make_zip_file (list kdms, boost::filesystem::path zip_file, /** Collect a list of KDMWithMetadatas into a list of lists so that * each list contains the KDMs for one list. */ -list > +list> collect (list kdms) { - list > grouped; + list> grouped; - BOOST_FOREACH (KDMWithMetadataPtr i, kdms) { + for (auto i: kdms) { - list >::iterator j = grouped.begin (); + auto j = grouped.begin (); while (j != grouped.end()) { if (j->front()->group() == i->group()) { @@ -135,7 +137,7 @@ collect (list kdms) /** Write one directory per list into another directory */ int write_directories ( - list > kdms, + list> kdms, boost::filesystem::path directory, dcp::NameFormat container_name_format, dcp::NameFormat filename_format, @@ -144,8 +146,8 @@ write_directories ( { int written = 0; - BOOST_FOREACH (list const & i, kdms) { - boost::filesystem::path path = directory; + for (auto const& i: kdms) { + auto path = directory; path /= container_name_format.get(i.front()->name_values(), "", "s"); if (!boost::filesystem::exists (path) || confirm_overwrite (path)) { boost::filesystem::create_directories (path); @@ -161,7 +163,7 @@ write_directories ( /** Write one ZIP file per cinema into a directory */ int write_zip_files ( - list > kdms, + list> kdms, boost::filesystem::path directory, dcp::NameFormat container_name_format, dcp::NameFormat filename_format, @@ -170,8 +172,8 @@ write_zip_files ( { int written = 0; - BOOST_FOREACH (list const & i, kdms) { - boost::filesystem::path path = directory; + for (auto const& i: kdms) { + auto path = directory; path /= container_name_format.get(i.front()->name_values(), ".zip", "s"); if (!boost::filesystem::exists (path) || confirm_overwrite (path)) { if (boost::filesystem::exists (path)) { @@ -195,45 +197,45 @@ write_zip_files ( * @param cpl_name Name of the CPL that the KDMs are for. */ void -email ( - list > kdms, +send_emails ( + list> kdms, dcp::NameFormat container_name_format, dcp::NameFormat filename_format, string cpl_name ) { - Config* config = Config::instance (); + auto config = Config::instance (); if (config->mail_server().empty()) { throw NetworkError (_("No mail server configured in preferences")); } - BOOST_FOREACH (list const & i, kdms) { + for (auto const& i: kdms) { if (i.front()->emails().empty()) { continue; } - boost::filesystem::path zip_file = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path(); + auto zip_file = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path(); boost::filesystem::create_directories (zip_file); zip_file /= container_name_format.get(i.front()->name_values(), ".zip"); make_zip_file (i, zip_file, filename_format); - string subject = config->kdm_subject(); - boost::algorithm::replace_all (subject, "$CPL_NAME", cpl_name); - boost::algorithm::replace_all (subject, "$START_TIME", i.front()->get('b').get_value_or("")); - boost::algorithm::replace_all (subject, "$END_TIME", i.front()->get('e').get_value_or("")); - boost::algorithm::replace_all (subject, "$CINEMA_NAME", i.front()->get('c').get_value_or("")); + auto substitute_variables = [cpl_name, i](string target) { + boost::algorithm::replace_all (target, "$CPL_NAME", cpl_name); + boost::algorithm::replace_all (target, "$START_TIME", i.front()->get('b').get_value_or("")); + boost::algorithm::replace_all (target, "$END_TIME", i.front()->get('e').get_value_or("")); + boost::algorithm::replace_all (target, "$CINEMA_NAME", i.front()->get('c').get_value_or("")); + boost::algorithm::replace_all (target, "$CINEMA_SHORT_NAME", i.front()->get('c').get_value_or("").substr(0, 14)); + return target; + }; - string body = config->kdm_email().c_str(); - boost::algorithm::replace_all (body, "$CPL_NAME", cpl_name); - boost::algorithm::replace_all (body, "$START_TIME", i.front()->get('b').get_value_or("")); - boost::algorithm::replace_all (body, "$END_TIME", i.front()->get('e').get_value_or("")); - boost::algorithm::replace_all (body, "$CINEMA_NAME", i.front()->get('c').get_value_or("")); + auto subject = substitute_variables(config->kdm_subject()); + auto body = substitute_variables(config->kdm_email()); string screens; - BOOST_FOREACH (KDMWithMetadataPtr j, i) { - optional screen_name = j->get('n'); + for (auto j: i) { + auto screen_name = j->get('s'); if (screen_name) { screens += *screen_name + ", "; } @@ -242,19 +244,17 @@ email ( Emailer email (config->kdm_from(), i.front()->emails(), subject, body); - BOOST_FOREACH (string i, config->kdm_cc()) { + for (auto i: config->kdm_cc()) { email.add_cc (i); } - if (!config->kdm_bcc().empty ()) { - email.add_bcc (config->kdm_bcc ()); + if (!config->kdm_bcc().empty()) { + email.add_bcc (config->kdm_bcc()); } email.add_attachment (zip_file, container_name_format.get(i.front()->name_values(), ".zip"), "application/zip"); - Config* c = Config::instance (); - try { - email.send (c->mail_server(), c->mail_port(), c->mail_protocol(), c->mail_user(), c->mail_password()); + email.send (config->mail_server(), config->mail_port(), config->mail_protocol(), config->mail_user(), config->mail_password()); } catch (...) { boost::filesystem::remove (zip_file); dcpomatic_log->log ("Email content follows", LogEntry::TYPE_DEBUG_EMAIL);