X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Ftools%2Fdcpomatic.cc;h=6c789632a2dff6e46c73f10fb91be54985dfe2b0;hb=5a5324ed3a381a86dfe0a6e3932c1d58fdcd596f;hp=acdae692dad4a61b7fe0286c24bf5fec920c9741;hpb=3828baf56467224f5d44049bf1e7a7ed11f43a05;p=dcpomatic.git diff --git a/src/tools/dcpomatic.cc b/src/tools/dcpomatic.cc index acdae692d..6c789632a 100644 --- a/src/tools/dcpomatic.cc +++ b/src/tools/dcpomatic.cc @@ -72,6 +72,7 @@ #endif #include #include +#include #include #include #include @@ -92,6 +93,8 @@ using std::list; using std::exception; using boost::shared_ptr; using boost::dynamic_pointer_cast; +using boost::optional; +using boost::make_shared; class FilmChangedDialog : public boost::noncopyable { @@ -104,7 +107,11 @@ public: /// TRANSLATORS: this is the heading for a dialog box, which tells the user that the current /// project (Film) has been changed since it was last saved. _("Film changed"), - wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION + wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxICON_QUESTION + ); + + _dialog->SetYesNoCancelLabels ( + _("Save film and close"), _("Close without saving film"), _("Don't close") ); } @@ -270,7 +277,7 @@ public: void new_film (boost::filesystem::path path) { - shared_ptr film (new Film (path)); + shared_ptr film = make_shared (path); film->write_metadata (); film->set_name (path.filename().generic_string()); set_film (film); @@ -279,9 +286,7 @@ public: void load_film (boost::filesystem::path file) try { - maybe_save_then_delete_film (); - - shared_ptr film (new Film (file)); + shared_ptr film = make_shared (file); list const notes = film->read_metadata (); if (film->state_version() == 4) { @@ -355,8 +360,9 @@ private: return; } - maybe_save_then_delete_film (); - new_film (d->get_path ()); + if (maybe_save_then_delete_film ()) { + new_film (d->get_path ()); + } } d->Destroy (); @@ -381,7 +387,7 @@ private: } } - if (r == wxID_OK) { + if (r == wxID_OK && maybe_save_then_delete_film()) { load_film (wx_to_std (c->GetPath ())); } @@ -397,7 +403,7 @@ private: { vector history = Config::instance()->history (); int n = event.GetId() - ID_file_history; - if (n >= 0 && n < static_cast (history.size ())) { + if (n >= 0 && n < static_cast (history.size ()) && maybe_save_then_delete_film()) { load_film (history[n]); } } @@ -486,14 +492,14 @@ private: ); } else { JobManager::instance()->add ( - shared_ptr (new SendKDMEmailJob ( - _film->name(), - _film->dcp_name(), - d->from(), - d->until(), - CinemaKDMs::collect (screen_kdms), - _film->log() - )) + boost::make_shared ( + _film->name(), + _film->dcp_name(), + d->from(), + d->until(), + CinemaKDMs::collect (screen_kdms), + _film->log() + ) ); } } catch (dcp::NotEncryptedError& e) { @@ -560,20 +566,16 @@ private: return; } + optional kdm; try { - vector dkdms = Config::instance()->dkdms (); - dkdms.push_back ( - _film->make_kdm ( - Config::instance()->decryption_chain()->leaf(), - vector (), - d->cpl (), - dcp::LocalTime ("2012-01-01T01:00:00+00:00"), - dcp::LocalTime ("2112-01-01T01:00:00+00:00"), - dcp::MODIFIED_TRANSITIONAL_1 - ) + kdm = _film->make_kdm ( + Config::instance()->decryption_chain()->leaf(), + vector (), + d->cpl (), + dcp::LocalTime ("2012-01-01T01:00:00+00:00"), + dcp::LocalTime ("2112-01-01T01:00:00+00:00"), + dcp::MODIFIED_TRANSITIONAL_1 ); - - Config::instance()->set_dkdms (dkdms); } catch (dcp::NotEncryptedError& e) { error_dialog (this, _("CPL's content is not encrypted.")); } catch (exception& e) { @@ -582,6 +584,17 @@ private: error_dialog (this, _("An unknown exception occurred.")); } + if (kdm) { + if (d->internal ()) { + vector dkdms = Config::instance()->dkdms (); + dkdms.push_back (kdm.get()); + Config::instance()->set_dkdms (dkdms); + } else { + boost::filesystem::path path = d->directory() / (_film->dcp_name(false) + "_DKDM.xml"); + kdm->as_xml (path); + } + } + d->Destroy (); } @@ -716,21 +729,9 @@ private: if (_film && _film->dirty ()) { - wxMessageDialog* dialog = new wxMessageDialog ( - 0, - wxString::Format (_("Save changes to film \"%s\" before closing?"), std_to_wx (_film->name()).data()), - /// TRANSLATORS: this is the heading for a dialog box, which tells the user that the current - /// project (Film) has been changed since it was last saved. - _("Film changed"), - wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxICON_QUESTION - ); - - dialog->SetYesNoCancelLabels ( - _("Save film and close"), _("Close without saving film"), _("Don't close") - ); - - int const r = dialog->ShowModal (); - dialog->Destroy (); + FilmChangedDialog* dialog = new FilmChangedDialog (_film->name ()); + int const r = dialog->run (); + delete dialog; switch (r) { case wxID_NO: @@ -791,10 +792,13 @@ private: } } - void maybe_save_then_delete_film () + /** @return true if the operation that called this method + * should continue, false to abort it. + */ + bool maybe_save_then_delete_film () { if (!_film) { - return; + return true; } if (_film->dirty ()) { @@ -805,10 +809,13 @@ private: case wxID_YES: _film->write_metadata (); break; + case wxID_CANCEL: + return false; } } _film.reset (); + return true; } void add_item (wxMenu* menu, wxString text, int id, int sens)