Use dcp_name (probably ISDCF name) for CPL_NAME in KDM emails (#2787).
[dcpomatic.git] / src / wx / kdm_dialog.cc
index bec880852748c052c4de42eea3a40d457659fe2a..5ab13b4ce7410905f41b5581e9290bbdd57446a8 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "confirm_kdm_email_dialog.h"
 #include "dcpomatic_button.h"
+#include "invalid_certificate_period_dialog.h"
 #include "kdm_cpl_panel.h"
 #include "kdm_dialog.h"
 #include "kdm_output_panel.h"
@@ -36,6 +37,7 @@
 #include "lib/kdm_util.h"
 #include "lib/screen.h"
 #include <libcxml/cxml.h>
+#include <dcp/cpl.h>
 #include <dcp/exceptions.h>
 #include <dcp/warnings.h>
 LIBDCP_DISABLE_WARNINGS
@@ -126,7 +128,9 @@ KDMDialog::KDMDialog (wxWindow* parent, shared_ptr<const Film> film)
        _screens->ScreensChanged.connect (boost::bind (&KDMDialog::setup_sensitivity, this));
        _timing->TimingChanged.connect (boost::bind (&KDMDialog::setup_sensitivity, this));
        _make->Bind (wxEVT_BUTTON, boost::bind (&KDMDialog::make_clicked, this));
+       _cpl->Changed.connect(boost::bind(&KDMDialog::cpl_changed, this));
 
+       cpl_changed();
        setup_sensitivity ();
 
        SetSizer (overall_sizer);
@@ -135,6 +139,20 @@ KDMDialog::KDMDialog (wxWindow* parent, shared_ptr<const Film> film)
 }
 
 
+void
+KDMDialog::cpl_changed()
+{
+       try {
+               dcp::CPL cpl(_cpl->cpl());
+               if (auto text = cpl.annotation_text()) {
+                       _output->set_annotation_text(*text);
+               }
+       } catch (...) {}
+
+       setup_sensitivity();
+}
+
+
 void
 KDMDialog::setup_sensitivity ()
 {
@@ -185,19 +203,16 @@ KDMDialog::make_clicked ()
                        }
                }
 
-               if (find(period_checks.begin(), period_checks.end(), KDMCertificatePeriod::KDM_OUTSIDE_CERTIFICATE) != period_checks.end()) {
-                       error_dialog(
-                               this,
-                               _("Some KDMs would have validity periods which are completely outside the recipient certificate periods.  Such KDMs are very unlikely to work, so will not be created.")
-                               );
-                       return;
-               }
-
-               if (find(period_checks.begin(), period_checks.end(), KDMCertificatePeriod::KDM_OVERLAPS_CERTIFICATE) != period_checks.end()) {
-                       message_dialog(
-                               this,
-                               _("For some of these KDMs the recipient certificate's validity period will not cover the whole of the KDM validity period.  This might cause problems with the KDMs.")
-                               );
+               if (
+                       find_if(
+                               period_checks.begin(),
+                               period_checks.end(),
+                               [](KDMCertificatePeriod const& p) { return p.overlap != KDMCertificateOverlap::KDM_WITHIN_CERTIFICATE; }
+                              ) != period_checks.end()) {
+                       InvalidCertificatePeriodDialog dialog(this, period_checks);
+                       if (dialog.ShowModal() == wxID_CANCEL) {
+                               return;
+                       }
                }
 
        } catch (dcp::BadKDMDateError& e) {
@@ -212,7 +227,7 @@ KDMDialog::make_clicked ()
                return;
        }
 
-       auto result = _output->make (kdms, film->name(), bind (&KDMDialog::confirm_overwrite, this, _1));
+       auto result = _output->make(kdms, film->dcp_name(), bind (&KDMDialog::confirm_overwrite, this, _1));
        if (result.first) {
                JobManager::instance()->add (result.first);
        }