/*
Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
- This program is free software; you can redistribute it and/or modify
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
- This program is distributed in the hope that it will be useful,
+ DCP-o-matic is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
*/
using std::exception;
using boost::shared_ptr;
using boost::dynamic_pointer_cast;
+using boost::optional;
class FilmChangedDialog : public boost::noncopyable
{
/// 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")
);
}
void load_film (boost::filesystem::path file)
try
{
- maybe_save_then_delete_film ();
-
shared_ptr<Film> film (new Film (file));
list<string> const notes = film->read_metadata ();
return;
}
- maybe_save_then_delete_film ();
- new_film (d->get_path ());
+ if (maybe_save_then_delete_film ()) {
+ new_film (d->get_path ());
+ }
}
d->Destroy ();
}
}
- if (r == wxID_OK) {
+ if (r == wxID_OK && maybe_save_then_delete_film()) {
load_film (wx_to_std (c->GetPath ()));
}
{
vector<boost::filesystem::path> history = Config::instance()->history ();
int n = event.GetId() - ID_file_history;
- if (n >= 0 && n < static_cast<int> (history.size ())) {
+ if (n >= 0 && n < static_cast<int> (history.size ()) && maybe_save_then_delete_film()) {
load_film (history[n]);
}
}
return;
}
+ optional<dcp::EncryptedKDM> kdm;
try {
- vector<dcp::EncryptedKDM> dkdms = Config::instance()->dkdms ();
- dkdms.push_back (
- _film->make_kdm (
- Config::instance()->decryption_chain()->leaf(),
- vector<dcp::Certificate> (),
- 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<dcp::Certificate> (),
+ 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) {
error_dialog (this, _("An unknown exception occurred."));
}
+ if (kdm) {
+ if (d->internal ()) {
+ vector<dcp::EncryptedKDM> 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 ();
}
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:
}
}
- 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 ()) {
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)