Use dcp_name (probably ISDCF name) for CPL_NAME in KDM emails (#2787).
[dcpomatic.git] / src / wx / kdm_dialog.cc
index c44321ac55c0a931b21b633e6a5894adc9b1f19f..5ab13b4ce7410905f41b5581e9290bbdd57446a8 100644 (file)
 */
 
 
+#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 "wx_util.h"
-#include "screens_panel.h"
-#include "kdm_timing_panel.h"
 #include "kdm_output_panel.h"
-#include "kdm_cpl_panel.h"
-#include "confirm_kdm_email_dialog.h"
+#include "kdm_timing_panel.h"
+#include "screens_panel.h"
 #include "static_text.h"
-#include "dcpomatic_button.h"
+#include "wx_util.h"
+#include "lib/cinema.h"
+#include "lib/config.h"
 #include "lib/film.h"
-#include "lib/screen.h"
-#include "lib/kdm_with_metadata.h"
 #include "lib/job_manager.h"
-#include "lib/config.h"
-#include "lib/cinema.h"
+#include "lib/kdm_with_metadata.h"
+#include "lib/kdm_util.h"
+#include "lib/screen.h"
 #include <libcxml/cxml.h>
+#include <dcp/cpl.h>
 #include <dcp/exceptions.h>
-#include <wx/treectrl.h>
+#include <dcp/warnings.h>
+LIBDCP_DISABLE_WARNINGS
 #include <wx/listctrl.h>
-#include <iostream>
+#include <wx/treectrl.h>
+LIBDCP_ENABLE_WARNINGS
 
 
-using std::string;
 using std::exception;
-using std::map;
 using std::list;
-using std::pair;
-using std::cout;
-using std::vector;
 using std::make_pair;
+using std::map;
+using std::pair;
 using std::runtime_error;
 using std::shared_ptr;
+using std::string;
+using std::vector;
 using boost::bind;
 using boost::optional;
 #if BOOST_VERSION >= 106100
@@ -107,8 +111,8 @@ KDMDialog::KDMDialog (wxWindow* parent, shared_ptr<const Film> film)
        /* Sub-heading: Output */
        h = new StaticText (this, _("Output"));
        h->SetFont (subheading_font);
-       right->Add (h, 0, wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
-       _output = new KDMOutputPanel (this, film->interop ());
+       right->Add(h, 0, wxTOP, DCPOMATIC_SUBHEADING_TOP_PAD);
+       _output = new KDMOutputPanel (this);
        right->Add (_output, 0, wxEXPAND | wxTOP, DCPOMATIC_SIZER_GAP);
 
        _make = new Button (this, _("Make KDMs"));
@@ -124,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);
@@ -133,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 ()
 {
@@ -170,17 +190,36 @@ KDMDialog::make_clicked ()
                        for_audio = _output->forensic_mark_audio_up_to();
                }
 
+               vector<KDMCertificatePeriod> period_checks;
+
+               std::function<dcp::DecryptedKDM (dcp::LocalTime, dcp::LocalTime)> make_kdm = [film, this](dcp::LocalTime begin, dcp::LocalTime end) {
+                       return film->make_kdm(_cpl->cpl(), begin, end);
+               };
+
                for (auto i: _screens->screens()) {
-                       auto p = kdm_for_screen (film, _cpl->cpl(), i, _timing->from(), _timing->until(), _output->formulation(), !_output->forensic_mark_video(), for_audio);
+                       auto p = kdm_for_screen(make_kdm, i, _timing->from(), _timing->until(), _output->formulation(), !_output->forensic_mark_video(), for_audio, period_checks);
                        if (p) {
                                kdms.push_back (p);
                        }
                }
+
+               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) {
                if (e.starts_too_early()) {
                        error_dialog (this, _("The KDM start period is before (or close to) the start of the signing certificate's validity period.  Use a later start time for this KDM."));
                } else {
-                       error_dialog (this, _("The KDM end period is after (or close to) the end of the signing certficates' validity period.  Either use an earlier end time for this KDM or re-create your signing certificates in the DCP-o-matic preferences window."));
+                       error_dialog (this, _("The KDM end period is after (or close to) the end of the signing certificates' validity period.  Either use an earlier end time for this KDM or re-create your signing certificates in the DCP-o-matic preferences window."));
                }
                return;
        } catch (runtime_error& e) {
@@ -188,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);
        }