Replace CinemaKDMs class with a list<KDMWithMetadata>
authorCarl Hetherington <cth@carlh.net>
Mon, 4 May 2020 22:35:13 +0000 (00:35 +0200)
committerCarl Hetherington <cth@carlh.net>
Wed, 6 May 2020 18:15:30 +0000 (20:15 +0200)
src/lib/cinema_kdms.cc
src/lib/cinema_kdms.h
src/lib/send_kdm_email_job.cc
src/lib/send_kdm_email_job.h
src/wx/kdm_output_panel.cc

index d96a95d..94e83f8 100644 (file)
@@ -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<KDMWithMetadataPtr> 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<KDMWithMetadata> so that each
  *  CinemaKDM contains the KDMs for its cinema.
  */
-list<CinemaKDMs>
+list<list<KDMWithMetadataPtr> >
 collect (list<KDMWithMetadataPtr> screen_kdms)
 {
-       list<CinemaKDMs> cinema_kdms;
+       list<list<KDMWithMetadataPtr> > cinema_kdms;
 
        while (!screen_kdms.empty ()) {
 
                /* Get all the screens from a single cinema */
 
-               CinemaKDMs ck;
+               list<KDMWithMetadataPtr> ck;
 
                list<KDMWithMetadataPtr>::iterator i = screen_kdms.begin ();
-               ck.cinema = (*i)->cinema();
-               ck.screen_kdms.push_back (*i);
+               ck.push_back (*i);
                list<KDMWithMetadataPtr>::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<KDMWithMetadataPtr>::iterator j = i;
                                ++i;
                                screen_kdms.remove (*j);
@@ -99,7 +96,7 @@ collect (list<KDMWithMetadataPtr> screen_kdms)
 /** Write one directory per cinema into another directory */
 int
 write_directories (
-       list<CinemaKDMs> cinema_kdms,
+       list<list<KDMWithMetadataPtr> > 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<KDMWithMetadataPtr> 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<CinemaKDMs> cinema_kdms,
+       list<list<KDMWithMetadataPtr> > 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<KDMWithMetadataPtr> 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<CinemaKDMs> cinema_kdms,
+       list<list<KDMWithMetadataPtr> > 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<KDMWithMetadataPtr> 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<string> 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);
index 592bec9..0a5749e 100644 (file)
@@ -24,19 +24,12 @@ class Cinema;
 class Job;
 class Log;
 
-class CinemaKDMs
-{
-public:
-       boost::shared_ptr<Cinema> cinema;
-       std::list<KDMWithMetadataPtr > screen_kdms;
-};
+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 (CinemaKDMs kdms, boost::filesystem::path zip_file, dcp::NameFormat name_format, dcp::NameFormat::Map name_values);
-
-std::list<CinemaKDMs> collect (std::list<KDMWithMetadataPtr > kdms);
+std::list<std::list<KDMWithMetadataPtr> > collect (std::list<KDMWithMetadataPtr> kdms);
 
 int write_directories (
-               std::list<CinemaKDMs> cinema_kdms,
+               std::list<std::list<KDMWithMetadataPtr> > 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<CinemaKDMs> cinema_kdms,
+               std::list<std::list<KDMWithMetadataPtr> > 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<CinemaKDMs> cinema_kdms,
+               std::list<std::list<KDMWithMetadataPtr> > cinema_kdms,
                dcp::NameFormat container_name_format,
                dcp::NameFormat filename_format,
                dcp::NameFormat::Map name_values,
index 10a571e..e9bad4c 100644 (file)
@@ -37,7 +37,7 @@ using boost::shared_ptr;
  *  @param cpl_name Name of the CPL that the KDMs are for.
  */
 SendKDMEmailJob::SendKDMEmailJob (
-       list<CinemaKDMs> cinema_kdms,
+       list<list<KDMWithMetadataPtr> > cinema_kdms,
        dcp::NameFormat container_name_format,
        dcp::NameFormat filename_format,
        dcp::NameFormat::Map name_values,
index a7196fe..7a70d55 100644 (file)
@@ -19,6 +19,7 @@
 */
 
 #include "job.h"
+#include "kdm_with_metadata.h"
 #include <dcp/types.h>
 #include <dcp/name_format.h>
 #include <boost/filesystem.hpp>
@@ -27,14 +28,13 @@ namespace dcpomatic {
        class Screen;
 }
 
-class CinemaKDMs;
 class Log;
 
 class SendKDMEmailJob : public Job
 {
 public:
        SendKDMEmailJob (
-               std::list<CinemaKDMs> cinema_kdms,
+               std::list<std::list<KDMWithMetadataPtr> > 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<CinemaKDMs> _cinema_kdms;
+       std::list<std::list<KDMWithMetadataPtr> > _cinema_kdms;
 };
index fe87dfc..c288400 100644 (file)
@@ -186,7 +186,7 @@ KDMOutputPanel::make (
        list<KDMWithMetadataPtr> screen_kdms, string name, KDMTimingPanel* timing, function<bool (boost::filesystem::path)> confirm_overwrite
        )
 {
-       list<CinemaKDMs> const cinema_kdms = collect (screen_kdms);
+       list<list<KDMWithMetadataPtr> > 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<KDMWithMetadataPtr> 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<string> emails;
-                       BOOST_FOREACH (CinemaKDMs i, cinema_kdms) {
-                               BOOST_FOREACH (string j, i.cinema->emails) {
+                       BOOST_FOREACH (list<KDMWithMetadataPtr> const& i, cinema_kdms) {
+                               BOOST_FOREACH (string j, i.front()->cinema()->emails) {
                                        emails.push_back (j);
                                }
                        }