Remove Screen pointer from KDMWithMetadata, preferring to
authorCarl Hetherington <cth@carlh.net>
Mon, 4 May 2020 21:30:23 +0000 (23:30 +0200)
committerCarl Hetherington <cth@carlh.net>
Wed, 6 May 2020 18:15:16 +0000 (20:15 +0200)
add metadata to a dcp::NameFormat::Map earlier in the
call stack.

src/lib/cinema_kdms.cc
src/lib/kdm_with_metadata.cc
src/lib/kdm_with_metadata.h
src/tools/dcpomatic_kdm.cc
src/tools/dcpomatic_kdm_cli.cc
src/wx/kdm_dialog.cc

index 61234ff3fd6af6b5df8299903ae45b46cfd7223a..56b76d3f9ecdb5e9264647c7ce638e28384645ea 100644 (file)
@@ -29,6 +29,7 @@
 #include "log.h"
 #include "zipper.h"
 #include "dcpomatic_log.h"
 #include "log.h"
 #include "zipper.h"
 #include "dcpomatic_log.h"
+#include "kdm_with_metadata.h"
 #include <boost/foreach.hpp>
 
 #include "i18n.h"
 #include <boost/foreach.hpp>
 
 #include "i18n.h"
@@ -39,6 +40,7 @@ using std::string;
 using std::runtime_error;
 using boost::shared_ptr;
 using boost::function;
 using std::runtime_error;
 using boost::shared_ptr;
 using boost::function;
+using boost::optional;
 
 void
 CinemaKDMs::make_zip_file (boost::filesystem::path zip_file, dcp::NameFormat name_format, dcp::NameFormat::Map name_values) const
 
 void
 CinemaKDMs::make_zip_file (boost::filesystem::path zip_file, dcp::NameFormat name_format, dcp::NameFormat::Map name_values) const
@@ -48,7 +50,6 @@ CinemaKDMs::make_zip_file (boost::filesystem::path zip_file, dcp::NameFormat nam
        name_values['c'] = cinema->name;
 
        BOOST_FOREACH (KDMWithMetadataPtr i, screen_kdms) {
        name_values['c'] = cinema->name;
 
        BOOST_FOREACH (KDMWithMetadataPtr i, screen_kdms) {
-               name_values['s'] = i->screen->name;
                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());
                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());
@@ -72,14 +73,14 @@ CinemaKDMs::collect (list<KDMWithMetadataPtr> screen_kdms)
                CinemaKDMs ck;
 
                list<KDMWithMetadataPtr>::iterator i = screen_kdms.begin ();
                CinemaKDMs ck;
 
                list<KDMWithMetadataPtr>::iterator i = screen_kdms.begin ();
-               ck.cinema = (*i)->screen->cinema;
+               ck.cinema = (*i)->cinema();
                ck.screen_kdms.push_back (*i);
                list<KDMWithMetadataPtr>::iterator j = i;
                ++i;
                screen_kdms.remove (*j);
 
                while (i != screen_kdms.end ()) {
                ck.screen_kdms.push_back (*i);
                list<KDMWithMetadataPtr>::iterator j = i;
                ++i;
                screen_kdms.remove (*j);
 
                while (i != screen_kdms.end ()) {
-                       if ((*i)->screen->cinema == ck.cinema) {
+                       if ((*i)->cinema() == ck.cinema) {
                                ck.screen_kdms.push_back (*i);
                                list<KDMWithMetadataPtr>::iterator j = i;
                                ++i;
                                ck.screen_kdms.push_back (*i);
                                list<KDMWithMetadataPtr>::iterator j = i;
                                ++i;
@@ -210,7 +211,10 @@ CinemaKDMs::email (
 
                string screens;
                BOOST_FOREACH (KDMWithMetadataPtr j, i.screen_kdms) {
 
                string screens;
                BOOST_FOREACH (KDMWithMetadataPtr j, i.screen_kdms) {
-                       screens += j->screen->name + ", ";
+                       optional<string> screen_name = j->get('n');
+                       if (screen_name) {
+                               screens += *screen_name + ", ";
+                       }
                }
                boost::algorithm::replace_all (body, "$SCREENS", screens.substr (0, screens.length() - 2));
 
                }
                boost::algorithm::replace_all (body, "$SCREENS", screens.substr (0, screens.length() - 2));
 
index 674554f7ea13e5dd309d8f46a79a48e6cb9c7922..012172a8ed6bd8b1433081b01bd2f8b6d31dc47c 100644 (file)
@@ -28,6 +28,7 @@ using std::string;
 using std::cout;
 using std::list;
 using boost::shared_ptr;
 using std::cout;
 using std::list;
 using boost::shared_ptr;
+using boost::optional;
 
 int
 write_files (
 
 int
 write_files (
@@ -56,8 +57,6 @@ write_files (
 
        /* Write KDMs to the specified directory */
        BOOST_FOREACH (KDMWithMetadataPtr i, screen_kdms) {
 
        /* Write KDMs to the specified directory */
        BOOST_FOREACH (KDMWithMetadataPtr i, screen_kdms) {
-               name_values['c'] = i->screen->cinema ? i->screen->cinema->name : "";
-               name_values['s'] = i->screen->name;
                name_values['i'] = i->kdm_id ();
                boost::filesystem::path out = directory / careful_string_filter(name_format.get(name_values, ".xml"));
                if (!boost::filesystem::exists (out) || confirm_overwrite (out)) {
                name_values['i'] = i->kdm_id ();
                boost::filesystem::path out = directory / careful_string_filter(name_format.get(name_values, ".xml"));
                if (!boost::filesystem::exists (out) || confirm_overwrite (out)) {
@@ -68,3 +67,15 @@ write_files (
 
        return written;
 }
 
        return written;
 }
+
+
+optional<string>
+KDMWithMetadata::get (char k) const
+{
+       dcp::NameFormat::Map::const_iterator i = _name_values.find (k);
+       if (i == _name_values.end()) {
+               return optional<string>();
+       }
+
+       return i->second;
+}
index 19af0356f80d39c8e584611deb70dcde8cfa6049..ee84d9eb4842699d2dcc5085184ee6609713aa84 100644 (file)
 #include <dcp/name_format.h>
 #include <boost/shared_ptr.hpp>
 
 #include <dcp/name_format.h>
 #include <boost/shared_ptr.hpp>
 
-namespace dcpomatic {
-       class Screen;
-}
+class Cinema;
 
 
-/** Simple class to collect a screen and an encrypted KDM */
 class KDMWithMetadata
 {
 public:
 class KDMWithMetadata
 {
 public:
-       KDMWithMetadata (boost::shared_ptr<dcpomatic::Screen> s)
-               : screen (s)
+       KDMWithMetadata (dcp::NameFormat::Map const& name_values, boost::shared_ptr<Cinema> cinema)
+               : _name_values (name_values)
+               , _cinema (cinema)
        {}
 
        virtual ~KDMWithMetadata () {}
        {}
 
        virtual ~KDMWithMetadata () {}
@@ -46,7 +44,19 @@ public:
        virtual void kdm_as_xml (boost::filesystem::path out) const = 0;
        virtual std::string kdm_id () const = 0;
 
        virtual void kdm_as_xml (boost::filesystem::path out) const = 0;
        virtual std::string kdm_id () const = 0;
 
-       boost::shared_ptr<dcpomatic::Screen> screen;
+       dcp::NameFormat::Map const& name_values () const {
+               return _name_values;
+       }
+
+       boost::optional<std::string> get (char k) const;
+
+       boost::shared_ptr<Cinema> cinema () const {
+               return _cinema;
+       }
+
+private:
+       dcp::NameFormat::Map _name_values;
+       boost::shared_ptr<Cinema> _cinema;
 };
 
 
 };
 
 
@@ -63,8 +73,8 @@ int write_files (
 class DCPKDMWithMetadata : public KDMWithMetadata
 {
 public:
 class DCPKDMWithMetadata : public KDMWithMetadata
 {
 public:
-       DCPKDMWithMetadata (boost::shared_ptr<dcpomatic::Screen> s, dcp::EncryptedKDM k)
-               : KDMWithMetadata (s)
+       DCPKDMWithMetadata (dcp::NameFormat::Map const& name_values, boost::shared_ptr<Cinema> cinema, dcp::EncryptedKDM k)
+               : KDMWithMetadata (name_values, cinema)
                , kdm (k)
        {}
 
                , kdm (k)
        {}
 
@@ -87,8 +97,8 @@ public:
 class ECinemaKDMWithMetadata : public KDMWithMetadata
 {
 public:
 class ECinemaKDMWithMetadata : public KDMWithMetadata
 {
 public:
-       ECinemaKDMWithMetadata (boost::shared_ptr<dcpomatic::Screen> s, EncryptedECinemaKDM k)
-               : KDMWithMetadata (s)
+       ECinemaKDMWithMetadata (dcp::NameValues::Map const& name_values, boost::shared_ptr<Cinema> cinema, EncryptedECinemaKDM k)
+               : KDMWithMetadata (name_values, cinema)
                , kdm (k)
        {}
 
                , kdm (k)
        {}
 
index efc09c818b42303b63d82b0c36d167c69de0af49..bda944d83c485590904cd4e5c1daa46282175a85 100644 (file)
@@ -326,10 +326,14 @@ private:
                                                dcp::LocalTime (_timing->until(), i->cinema->utc_offset_hour(), i->cinema->utc_offset_minute())
                                                );
 
                                                dcp::LocalTime (_timing->until(), i->cinema->utc_offset_hour(), i->cinema->utc_offset_minute())
                                                );
 
+                                       dcp::NameFormat::Map name_values;
+                                       name_values['c'] = i->cinema->name;
+                                       name_values['s'] = i->name;
+
                                        /* Encrypt */
                                        screen_kdms.push_back (
                                                KDMWithMetadataPtr(
                                        /* Encrypt */
                                        screen_kdms.push_back (
                                                KDMWithMetadataPtr(
-                                                       new ECinemaKDMWithMetadata(i, kdm.encrypt(i->recipient.get()))
+                                                       new ECinemaKDMWithMetadata(name_values, i->cinema, kdm.encrypt(i->recipient.get()))
                                                        )
                                                );
                                }
                                                        )
                                                );
                                }
@@ -369,11 +373,16 @@ private:
                                                kdm.add_key (j);
                                        }
 
                                                kdm.add_key (j);
                                        }
 
+                                       dcp::NameFormat::Map name_values;
+                                       name_values['c'] = i->cinema->name;
+                                       name_values['s'] = i->name;
+
                                        /* Encrypt */
                                        screen_kdms.push_back (
                                                KDMWithMetadataPtr(
                                                        new DCPKDMWithMetadata(
                                        /* Encrypt */
                                        screen_kdms.push_back (
                                                KDMWithMetadataPtr(
                                                        new DCPKDMWithMetadata(
-                                                               i,
+                                                               name_values,
+                                                               i->cinema,
                                                                kdm.encrypt(
                                                                        signer, i->recipient.get(), i->trusted_device_thumbprints(), _output->formulation(),
                                                                        !_output->forensic_mark_video(), _output->forensic_mark_audio() ? boost::optional<int>() : 0
                                                                kdm.encrypt(
                                                                        signer, i->recipient.get(), i->trusted_device_thumbprints(), _output->formulation(),
                                                                        !_output->forensic_mark_video(), _output->forensic_mark_audio() ? boost::optional<int>() : 0
index a1003eceb27b4bcb885af7a4e785d3fa09e5f677..dd7fc82e3e92cada7037e52be7e264d8fe59c004 100644 (file)
@@ -244,7 +244,11 @@ from_film (
                                                disable_forensic_marking_audio
                                                );
 
                                                disable_forensic_marking_audio
                                                );
 
-                               kdms.push_back (KDMWithMetadataPtr(new DCPKDMWithMetadata(i, kdm)));
+                               dcp::NameFormat::Map name_values;
+                               name_values['c'] = i->cinema->name;
+                               name_values['s'] = i->name;
+
+                               kdms.push_back (KDMWithMetadataPtr(new DCPKDMWithMetadata(name_values, i->cinema, kdm)));
                        }
                }
 
                        }
                }
 
@@ -351,10 +355,15 @@ from_dkdm (
                                continue;
                        }
 
                                continue;
                        }
 
+                       dcp::NameFormat::Map name_values;
+                       name_values['c'] = i->cinema->name;
+                       name_values['s'] = i->name;
+
                        screen_kdms.push_back (
                                KDMWithMetadataPtr(
                                        new DCPKDMWithMetadata(
                        screen_kdms.push_back (
                                KDMWithMetadataPtr(
                                        new DCPKDMWithMetadata(
-                                               i,
+                                               name_values,
+                                               i->cinema,
                                                kdm_from_dkdm(
                                                        dkdm,
                                                        i->recipient.get(),
                                                kdm_from_dkdm(
                                                        dkdm,
                                                        i->recipient.get(),
index b067ff04afd36ce132196853cc3f30e28dbba2c0..f041c16c52febf299d9e500ba6471235732c70e6 100644 (file)
@@ -175,7 +175,13 @@ KDMDialog::make_clicked ()
                                                for_audio
                                                );
 
                                                for_audio
                                                );
 
-                               screen_kdms.push_back (KDMWithMetadataPtr(new DCPKDMWithMetadata(i, kdm)));
+                               dcp::NameFormat::Map name_values;
+                               if (i->cinema) {
+                                       name_values['c'] = i->cinema->name;
+                               }
+                               name_values['s'] = i->name;
+
+                               screen_kdms.push_back (KDMWithMetadataPtr(new DCPKDMWithMetadata(name_values, i->cinema, kdm)));
                        }
                }
 
                        }
                }