Remove some now-pointless passing of name_values.
authorCarl Hetherington <cth@carlh.net>
Tue, 5 May 2020 18:03:55 +0000 (20:03 +0200)
committerCarl Hetherington <cth@carlh.net>
Wed, 6 May 2020 18:15:49 +0000 (20:15 +0200)
src/lib/kdm_with_metadata.cc
src/lib/kdm_with_metadata.h
src/lib/send_kdm_email_job.cc
src/lib/send_kdm_email_job.h
src/tools/dcpomatic_kdm_cli.cc
src/wx/kdm_output_panel.cc

index bf24f709d69a72cf19ef099f02a9afc9d1281f45..f8718386f555c073971a5e0840c15d947c514742 100644 (file)
@@ -44,7 +44,6 @@ write_files (
        list<KDMWithMetadataPtr> kdms,
        boost::filesystem::path directory,
        dcp::NameFormat name_format,
-       dcp::NameFormat::Map name_values,
        boost::function<bool (boost::filesystem::path)> confirm_overwrite
        )
 {
@@ -66,7 +65,7 @@ write_files (
 
        /* Write KDMs to the specified directory */
        BOOST_FOREACH (KDMWithMetadataPtr i, kdms) {
-               boost::filesystem::path out = directory / careful_string_filter(name_format.get(name_values, ".xml"));
+               boost::filesystem::path out = 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;
@@ -90,12 +89,12 @@ KDMWithMetadata::get (char k) const
 
 
 void
-make_zip_file (list<KDMWithMetadataPtr> kdms, boost::filesystem::path zip_file, dcp::NameFormat name_format, dcp::NameFormat::Map name_values)
+make_zip_file (list<KDMWithMetadataPtr> kdms, boost::filesystem::path zip_file, dcp::NameFormat name_format)
 {
        Zipper zipper (zip_file);
 
        BOOST_FOREACH (KDMWithMetadataPtr i, kdms) {
-               string const name = careful_string_filter(name_format.get(name_values, ".xml"));
+               string const name = careful_string_filter(name_format.get(i->name_values(), ".xml"));
                zipper.add (name, i->kdm_as_xml());
        }
 
@@ -140,21 +139,17 @@ write_directories (
        boost::filesystem::path directory,
        dcp::NameFormat container_name_format,
        dcp::NameFormat filename_format,
-       dcp::NameFormat::Map name_values,
        function<bool (boost::filesystem::path)> confirm_overwrite
        )
 {
-       /* No specific screen */
-       name_values['s'] = "";
-
        int written = 0;
 
        BOOST_FOREACH (list<KDMWithMetadataPtr> const & i, cinema_kdms) {
                boost::filesystem::path path = directory;
-               path /= container_name_format.get(name_values, "");
+               path /= container_name_format.get(i.front()->name_values(), "");
                if (!boost::filesystem::exists (path) || confirm_overwrite (path)) {
                        boost::filesystem::create_directories (path);
-                       write_files (i, path, filename_format, name_values, confirm_overwrite);
+                       write_files (i, path, filename_format, confirm_overwrite);
                }
                written += i.size();
        }
@@ -170,24 +165,20 @@ write_zip_files (
        boost::filesystem::path directory,
        dcp::NameFormat container_name_format,
        dcp::NameFormat filename_format,
-       dcp::NameFormat::Map name_values,
        function<bool (boost::filesystem::path)> confirm_overwrite
        )
 {
-       /* No specific screen */
-       name_values['s'] = "";
-
        int written = 0;
 
        BOOST_FOREACH (list<KDMWithMetadataPtr> const & i, cinema_kdms) {
                boost::filesystem::path path = directory;
-               path /= container_name_format.get(name_values, ".zip");
+               path /= container_name_format.get(i.front()->name_values(), ".zip");
                if (!boost::filesystem::exists (path) || confirm_overwrite (path)) {
                        if (boost::filesystem::exists (path)) {
                                /* Creating a new zip file over an existing one is an error */
                                boost::filesystem::remove (path);
                        }
-                       make_zip_file (i, path, filename_format, name_values);
+                       make_zip_file (i, path, filename_format);
                        written += i.size();
                }
        }
@@ -208,7 +199,6 @@ email (
        list<list<KDMWithMetadataPtr> > cinema_kdms,
        dcp::NameFormat container_name_format,
        dcp::NameFormat filename_format,
-       dcp::NameFormat::Map name_values,
        string cpl_name
        )
 {
@@ -218,9 +208,6 @@ email (
                throw NetworkError (_("No mail server configured in preferences"));
        }
 
-       /* No specific screen */
-       name_values['s'] = "";
-
        BOOST_FOREACH (list<KDMWithMetadataPtr> const & i, cinema_kdms) {
 
                if (i.front()->cinema()->emails.empty()) {
@@ -229,19 +216,19 @@ email (
 
                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");
-               make_zip_file (i, zip_file, filename_format, name_values);
+               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", name_values['b']);
-               boost::algorithm::replace_all (subject, "$END_TIME", name_values['e']);
+               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()->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, "$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()->cinema()->name);
 
                string screens;
@@ -262,7 +249,7 @@ email (
                        email.add_bcc (config->kdm_bcc ());
                }
 
-               email.add_attachment (zip_file, container_name_format.get(name_values, ".zip"), "application/zip");
+               email.add_attachment (zip_file, container_name_format.get(i.front()->name_values(), ".zip"), "application/zip");
 
                Config* c = Config::instance ();
 
index 8710460ede626804471e46d5848784bec39f2310..7309ee2d6b3c58504e144adf24ac87a32aa98fa8 100644 (file)
@@ -64,12 +64,11 @@ typedef boost::shared_ptr<KDMWithMetadata> KDMWithMetadataPtr;
 
 int write_files (
        std::list<KDMWithMetadataPtr> screen_kdms, boost::filesystem::path directory,
-       dcp::NameFormat name_format, dcp::NameFormat::Map name_values,
-       boost::function<bool (boost::filesystem::path)> confirm_overwrite
+       dcp::NameFormat name_format, boost::function<bool (boost::filesystem::path)> confirm_overwrite
        );
 
 
-void make_zip_file (std::list<KDMWithMetadataPtr> kdms, boost::filesystem::path zip_file, dcp::NameFormat name_format, dcp::NameFormat::Map name_values);
+void make_zip_file (std::list<KDMWithMetadataPtr> kdms, boost::filesystem::path zip_file, dcp::NameFormat name_format);
 
 
 std::list<std::list<KDMWithMetadataPtr> > collect (std::list<KDMWithMetadataPtr> kdms);
@@ -80,7 +79,6 @@ int write_directories (
                boost::filesystem::path directory,
                dcp::NameFormat container_name_format,
                dcp::NameFormat filename_format,
-               dcp::NameFormat::Map name_values,
                boost::function<bool (boost::filesystem::path)> confirm_overwrite
                );
 
@@ -90,7 +88,6 @@ int write_zip_files (
                boost::filesystem::path directory,
                dcp::NameFormat container_name_format,
                dcp::NameFormat filename_format,
-               dcp::NameFormat::Map name_values,
                boost::function<bool (boost::filesystem::path)> confirm_overwrite
                );
 
@@ -99,7 +96,6 @@ void email (
                std::list<std::list<KDMWithMetadataPtr> > cinema_kdms,
                dcp::NameFormat container_name_format,
                dcp::NameFormat filename_format,
-               dcp::NameFormat::Map name_values,
                std::string cpl_name
                );
 
index 7b4d349f3d7ca767c799f02d9be8feb335dacbcd..18f686717d451c582c59e54136bf56829f66e788 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2013-2020 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
 using std::string;
 using std::list;
 using boost::shared_ptr;
+using boost::optional;
 
-/** @param cinema_kdms KDMs to email.
+/** @param kdms KDMs to email.
  *  @param container_name_format Format to ues for folders / ZIP files.
  *  @param filename_format Format to use for filenames.
  *  @param name_values Values to substitute into \p container_name_format and \p filename_format.
  *  @param cpl_name Name of the CPL that the KDMs are for.
  */
 SendKDMEmailJob::SendKDMEmailJob (
-       list<list<KDMWithMetadataPtr> > cinema_kdms,
+       list<list<KDMWithMetadataPtr> > kdms,
        dcp::NameFormat container_name_format,
        dcp::NameFormat filename_format,
-       dcp::NameFormat::Map name_values,
        string cpl_name
        )
        : Job (shared_ptr<Film>())
        , _container_name_format (container_name_format)
        , _filename_format (filename_format)
-       , _name_values (name_values)
        , _cpl_name (cpl_name)
-       , _cinema_kdms (cinema_kdms)
+       , _kdms (kdms)
 {
 
 }
@@ -61,12 +60,12 @@ SendKDMEmailJob::~SendKDMEmailJob ()
 string
 SendKDMEmailJob::name () const
 {
-       dcp::NameFormat::Map::const_iterator i = _name_values.find ('f');
-       if (i == _name_values.end() || i->second.empty ()) {
+       optional<string> f = _kdms.front().front()->get('f');
+       if (!f || f->empty()) {
                return _("Email KDMs");
        }
 
-       return String::compose (_("Email KDMs for %1"), i->second);
+       return String::compose (_("Email KDMs for %2"), *f);
 }
 
 string
@@ -79,7 +78,7 @@ void
 SendKDMEmailJob::run ()
 {
        set_progress_unknown ();
-       email (_cinema_kdms, _container_name_format, _filename_format, _name_values, _cpl_name);
+       email (_kdms, _container_name_format, _filename_format, _cpl_name);
        set_progress (1);
        set_state (FINISHED_OK);
 }
index 7a70d555c01ea5c17aa83070c34bb159c8fcbfa6..452c76cee9060880c99ca6564cd1da564dd162ab 100644 (file)
@@ -34,10 +34,9 @@ class SendKDMEmailJob : public Job
 {
 public:
        SendKDMEmailJob (
-               std::list<std::list<KDMWithMetadataPtr> > cinema_kdms,
+               std::list<std::list<KDMWithMetadataPtr> > kdms,
                dcp::NameFormat container_name_format,
                dcp::NameFormat filename_format,
-               dcp::NameFormat::Map name_values,
                std::string cpl_name
                );
        ~SendKDMEmailJob ();
@@ -49,7 +48,6 @@ public:
 private:
        dcp::NameFormat _container_name_format;
        dcp::NameFormat _filename_format;
-       dcp::NameFormat::Map _name_values;
        std::string _cpl_name;
-       std::list<std::list<KDMWithMetadataPtr> > _cinema_kdms;
+       std::list<std::list<KDMWithMetadataPtr> > _kdms;
 };
index 6bcad22f6eb68d441911867a52953d56595ca39d..78b4201c673c97e2d61c11dd00f97ee3b6cc0ecb 100644 (file)
@@ -134,7 +134,6 @@ write_files (
        boost::filesystem::path output,
        dcp::NameFormat container_name_format,
        dcp::NameFormat filename_format,
-       dcp::NameFormat::Map values,
        bool verbose
        )
 {
@@ -144,7 +143,6 @@ write_files (
                        output,
                        container_name_format,
                        filename_format,
-                       values,
                        bind (&always_overwrite)
                        );
 
@@ -153,7 +151,7 @@ write_files (
                }
        } else {
                int const N = write_files (
-                       kdms, output, filename_format, values,
+                       kdms, output, filename_format,
                        bind (&always_overwrite)
                        );
 
@@ -256,7 +254,7 @@ from_film (
                        }
                }
 
-               write_files (kdms, zip, output, container_name_format, filename_format, values, verbose);
+               write_files (kdms, zip, output, container_name_format, filename_format, verbose);
        } catch (FileError& e) {
                cerr << program_name << ": " << e.what() << " (" << e.file().string() << ")\n";
                exit (EXIT_FAILURE);
@@ -380,7 +378,7 @@ from_dkdm (
 
                        kdms.push_back (KDMWithMetadataPtr(new DCPKDMWithMetadata(name_values, i->cinema, kdm)));
                }
-               write_files (kdms, zip, output, container_name_format, filename_format, values, verbose);
+               write_files (kdms, zip, output, container_name_format, filename_format, verbose);
        } catch (FileError& e) {
                cerr << program_name << ": " << e.what() << " (" << e.file().string() << ")\n";
                exit (EXIT_FAILURE);
index 0a70ff125bdb10e9b0a01e22f319a81abfcd81a2..f37865b94c76baaa578aceba8e9b8f965c84ecc8 100644 (file)
@@ -239,7 +239,6 @@ KDMOutputPanel::make (
        shared_ptr<Job> job;
 
        try {
-               dcp::NameFormat::Map name_values;
 
                if (_write_to->GetValue()) {
                        if (_write_flat->GetValue()) {
@@ -247,7 +246,6 @@ KDMOutputPanel::make (
                                        kdms,
                                        directory(),
                                        _filename_format->get(),
-                                       name_values,
                                        confirm_overwrite
                                        );
                        } else if (_write_folder->GetValue()) {
@@ -256,7 +254,6 @@ KDMOutputPanel::make (
                                        directory(),
                                        _container_name_format->get(),
                                        _filename_format->get(),
-                                       name_values,
                                        confirm_overwrite
                                        );
                        } else if (_write_zip->GetValue()) {
@@ -265,7 +262,6 @@ KDMOutputPanel::make (
                                        directory(),
                                        _container_name_format->get(),
                                        _filename_format->get(),
-                                       name_values,
                                        confirm_overwrite
                                        );
                        }
@@ -277,7 +273,6 @@ KDMOutputPanel::make (
                                        cinema_kdms,
                                        _container_name_format->get(),
                                        _filename_format->get(),
-                                       name_values,
                                        name
                                        )
                                );