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 61234ff..56b76d3 100644 (file)
@@ -29,6 +29,7 @@
 #include "log.h"
 #include "zipper.h"
 #include "dcpomatic_log.h"
+#include "kdm_with_metadata.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 boost::optional;
 
 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['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());
@@ -72,14 +73,14 @@ CinemaKDMs::collect (list<KDMWithMetadataPtr> screen_kdms)
                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 ()) {
-                       if ((*i)->screen->cinema == ck.cinema) {
+                       if ((*i)->cinema() == ck.cinema) {
                                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) {
-                       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));
 
index 674554f..012172a 100644 (file)
@@ -28,6 +28,7 @@ using std::string;
 using std::cout;
 using std::list;
 using boost::shared_ptr;
+using boost::optional;
 
 int
 write_files (
@@ -56,8 +57,6 @@ write_files (
 
        /* 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)) {
@@ -68,3 +67,15 @@ write_files (
 
        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 19af035..ee84d9e 100644 (file)
 #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:
-       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 () {}
@@ -46,7 +44,19 @@ public:
        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:
-       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)
        {}
 
@@ -87,8 +97,8 @@ 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)
        {}
 
index efc09c8..bda944d 100644 (file)
@@ -326,10 +326,14 @@ private:
                                                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(
-                                                       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);
                                        }
 
+                                       dcp::NameFormat::Map name_values;
+                                       name_values['c'] = i->cinema->name;
+                                       name_values['s'] = i->name;
+
                                        /* 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
index a1003ec..dd7fc82 100644 (file)
@@ -244,7 +244,11 @@ from_film (
                                                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;
                        }
 
+                       dcp::NameFormat::Map name_values;
+                       name_values['c'] = i->cinema->name;
+                       name_values['s'] = i->name;
+
                        screen_kdms.push_back (
                                KDMWithMetadataPtr(
                                        new DCPKDMWithMetadata(
-                                               i,
+                                               name_values,
+                                               i->cinema,
                                                kdm_from_dkdm(
                                                        dkdm,
                                                        i->recipient.get(),
index b067ff0..f041c16 100644 (file)
@@ -175,7 +175,13 @@ KDMDialog::make_clicked ()
                                                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)));
                        }
                }