Hand-apply d849d411cff28ef5453085791d0b4d7cd73bd070 from master; replace all assert...
[dcpomatic.git] / src / wx / kdm_dialog.cc
index 8df94de9c5f06a986213d479d56e5463d83df51d..9b1d6bc98ed1e12fdc0811b26f95a4f486ad6c0b 100644 (file)
@@ -161,9 +161,11 @@ KDMDialog::KDMDialog (wxWindow* parent, boost::shared_ptr<const Film> film)
 
        add_label_to_sizer (table, this, _("KDM type"), true);
        _type = new wxChoice (this, wxID_ANY);
-       _type->Append ("Modified Transitional 1");
-       _type->Append ("DCI Any");
-       _type->Append ("DCI Specific");
+       _type->Append ("Modified Transitional 1", ((void *) dcp::MODIFIED_TRANSITIONAL_1));
+       if (!film->interop ()) {
+               _type->Append ("DCI Any", ((void *) dcp::DCI_ANY));
+               _type->Append ("DCI Specific", ((void *) dcp::DCI_SPECIFIC));
+       }
        table->Add (_type, 1, wxEXPAND);
        _type->SetSelection (0);
 
@@ -307,11 +309,11 @@ void
 KDMDialog::add_cinema_clicked ()
 {
        CinemaDialog* d = new CinemaDialog (this, "Add Cinema");
-       d->ShowModal ();
-
-       shared_ptr<Cinema> c (new Cinema (d->name(), d->email()));
-       Config::instance()->add_cinema (c);
-       add_cinema (c);
+       if (d->ShowModal () == wxID_OK) {
+               shared_ptr<Cinema> c (new Cinema (d->name(), d->email()));
+               Config::instance()->add_cinema (c);
+               add_cinema (c);
+       }
 
        d->Destroy ();
 }
@@ -326,13 +328,12 @@ KDMDialog::edit_cinema_clicked ()
        pair<wxTreeItemId, shared_ptr<Cinema> > c = selected_cinemas().front();
        
        CinemaDialog* d = new CinemaDialog (this, "Edit cinema", c.second->name, c.second->email);
-       d->ShowModal ();
-
-       c.second->name = d->name ();
-       c.second->email = d->email ();
-       _targets->SetItemText (c.first, std_to_wx (d->name()));
-
-       Config::instance()->changed ();
+       if (d->ShowModal () == wxID_OK) {
+               c.second->name = d->name ();
+               c.second->email = d->email ();
+               _targets->SetItemText (c.first, std_to_wx (d->name()));
+               Config::instance()->changed ();
+       }
 
        d->Destroy ();  
 }
@@ -383,13 +384,12 @@ KDMDialog::edit_screen_clicked ()
        pair<wxTreeItemId, shared_ptr<Screen> > s = selected_screens().front();
        
        ScreenDialog* d = new ScreenDialog (this, "Edit screen", s.second->name, s.second->certificate);
-       d->ShowModal ();
-
-       s.second->name = d->name ();
-       s.second->certificate = d->certificate ();
-       _targets->SetItemText (s.first, std_to_wx (d->name()));
-
-       Config::instance()->changed ();
+       if (d->ShowModal () == wxID_OK) {
+               s.second->name = d->name ();
+               s.second->certificate = d->certificate ();
+               _targets->SetItemText (s.first, std_to_wx (d->name()));
+               Config::instance()->changed ();
+       }
 
        d->Destroy ();
 }
@@ -472,7 +472,7 @@ boost::filesystem::path
 KDMDialog::cpl () const
 {
        int const item = _cpl->GetSelection ();
-       assert (item >= 0);
+       DCPOMATIC_ASSERT (item >= 0);
        return _cpls[item].cpl_file;
 }
 
@@ -488,19 +488,10 @@ KDMDialog::write_to () const
        return _write_to->GetValue ();
 }
 
-libdcp::KDM::Formulation
+dcp::Formulation
 KDMDialog::formulation () const
 {
-       switch (_type->GetSelection()) {
-       case 0:
-               return libdcp::KDM::MODIFIED_TRANSITIONAL_1;
-       case 1:
-               return libdcp::KDM::DCI_ANY;
-       case 2:
-               return libdcp::KDM::DCI_SPECIFIC;
-       default:
-               assert (false);
-       }
+       return (dcp::Formulation) reinterpret_cast<intptr_t> (_type->GetClientData (_type->GetSelection()));
 }
 
 void
@@ -535,14 +526,17 @@ KDMDialog::update_cpl_summary ()
 void
 KDMDialog::cpl_browse_clicked ()
 {
-       wxFileDialog d (this, _("Select CPL XML file"), wxEmptyString, wxEmptyString, "*.xml");
-       if (d.ShowModal() == wxID_CANCEL) {
+       wxFileDialog* d = new wxFileDialog (this, _("Select CPL XML file"), wxEmptyString, wxEmptyString, "*.xml");
+       if (d->ShowModal() == wxID_CANCEL) {
+               d->Destroy ();
                return;
        }
 
-       boost::filesystem::path cpl_file (wx_to_std (d.GetPath ()));
+       boost::filesystem::path cpl_file (wx_to_std (d->GetPath ()));
        boost::filesystem::path dcp_dir = cpl_file.parent_path ();
 
+       d->Destroy ();
+
        /* XXX: hack alert */
        cxml::Document cpl_document ("CompositionPlaylist");
        cpl_document.read_file (cpl_file);