X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Fconfig_dialog.cc;h=c9ce97367643d1477d6721836ffd9ffa591fb637;hb=eae7b9001d7978d206626995e94c3bb6311cee77;hp=f91ebe670244d9de702534459cc59bb99cd2dd84;hpb=bdf29b6d0a2cdb392a9d4fd1c214ff108ec84c90;p=dcpomatic.git diff --git a/src/wx/config_dialog.cc b/src/wx/config_dialog.cc index f91ebe670..c9ce97367 100644 --- a/src/wx/config_dialog.cc +++ b/src/wx/config_dialog.cc @@ -18,29 +18,34 @@ */ -#include "config_dialog.h" -#include "static_text.h" + +#include "audio_mapping_view.h" #include "check_box.h" -#include "nag_dialog.h" +#include "config_dialog.h" #include "dcpomatic_button.h" -#include "audio_mapping_view.h" +#include "nag_dialog.h" +#include "static_text.h" +#include "wx_ptr.h" +#include "lib/constants.h" +#include #include -#include -using std::string; -using std::vector; -using std::pair; + +using std::function; using std::make_pair; -using std::map; using std::make_shared; +using std::map; +using std::pair; +using std::shared_ptr; +using std::string; +using std::vector; using boost::bind; using boost::optional; -using std::shared_ptr; -using std::function; #if BOOST_VERSION >= 106100 using namespace boost::placeholders; #endif + static bool do_nothing () @@ -131,9 +136,11 @@ GeneralPage::add_language_controls (wxGridBagSizer* table, int& r) languages.push_back (make_pair("Português europeu", "pt_PT")); languages.push_back (make_pair("Português do Brasil", "pt_BR")); languages.push_back (make_pair("Svenska", "sv_SE")); + languages.push_back (make_pair("Slovenščina", "sl_SI")); languages.push_back (make_pair("Slovenský jazyk", "sk_SK")); // languages.push_back (make_pair("Türkçe", "tr_TR")); languages.push_back (make_pair("українська мова", "uk_UA")); + languages.push_back (make_pair("Magyar nyelv", "hu_HU")); checked_set (_language, languages); table->Add (_language, wxGBPosition (r, 1)); ++r; @@ -147,7 +154,7 @@ GeneralPage::add_language_controls (wxGridBagSizer* table, int& r) restart->SetFont (font); ++r; - _set_language->Bind (wxEVT_CHECKBOX, bind (&GeneralPage::set_language_changed, this)); + _set_language->bind(&GeneralPage::set_language_changed, this); _language->Bind (wxEVT_CHOICE, bind (&GeneralPage::language_changed, this)); } @@ -162,8 +169,8 @@ GeneralPage::add_update_controls (wxGridBagSizer* table, int& r) table->Add (_check_for_test_updates, wxGBPosition (r, 0), wxGBSpan (1, 2)); ++r; - _check_for_updates->Bind (wxEVT_CHECKBOX, bind (&GeneralPage::check_for_updates_changed, this)); - _check_for_test_updates->Bind (wxEVT_CHECKBOX, bind (&GeneralPage::check_for_test_updates_changed, this)); + _check_for_updates->bind(&GeneralPage::check_for_updates_changed, this); + _check_for_test_updates->bind(&GeneralPage::check_for_test_updates_changed, this); } void @@ -361,7 +368,7 @@ CertificateChainEditor::add_button (wxWindow* button) void CertificateChainEditor::add_certificate () { - auto d = new wxFileDialog (this, _("Select Certificate File")); + auto d = make_wx(this, _("Select Certificate File")); if (d->ShowModal() == wxID_OK) { try { @@ -371,7 +378,6 @@ CertificateChainEditor::add_certificate () extra = c.read_string (dcp::file_to_string (wx_to_std (d->GetPath ()))); } catch (boost::filesystem::filesystem_error& e) { error_dialog (this, _("Could not import certificate (%s)"), d->GetPath()); - d->Destroy (); return; } @@ -400,8 +406,6 @@ CertificateChainEditor::add_certificate () } } - d->Destroy (); - update_sensitivity (); } @@ -446,7 +450,7 @@ CertificateChainEditor::export_certificate () default_name = "intermediate.pem"; } - auto d = new wxFileDialog( + auto d = make_wx( this, _("Select Certificate File"), wxEmptyString, default_name, wxT ("PEM files (*.pem)|*.pem"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); @@ -456,47 +460,46 @@ CertificateChainEditor::export_certificate () ++j; } - if (d->ShowModal () == wxID_OK) { - boost::filesystem::path path (wx_to_std(d->GetPath())); - if (path.extension() != ".pem") { - path += ".pem"; - } - auto f = fopen_boost (path, "w"); - if (!f) { - throw OpenFileError (path, errno, OpenFileError::WRITE); - } + if (d->ShowModal() != wxID_OK) { + return; + } - string const s = j->certificate (true); - checked_fwrite (s.c_str(), s.length(), f, path); - fclose (f); + boost::filesystem::path path(wx_to_std(d->GetPath())); + if (path.extension() != ".pem") { + path += ".pem"; } - d->Destroy (); + dcp::File f(path, "w"); + if (!f) { + throw OpenFileError(path, errno, OpenFileError::WRITE); + } + + string const s = j->certificate(true); + f.checked_write(s.c_str(), s.length()); } void CertificateChainEditor::export_chain () { - auto d = new wxFileDialog ( + auto d = make_wx( this, _("Select Chain File"), wxEmptyString, wxT("certificate_chain.pem"), wxT("PEM files (*.pem)|*.pem"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); - if (d->ShowModal () == wxID_OK) { - boost::filesystem::path path (wx_to_std(d->GetPath())); - if (path.extension() != ".pem") { - path += ".pem"; - } - auto f = fopen_boost (path, "w"); - if (!f) { - throw OpenFileError (path, errno, OpenFileError::WRITE); - } + if (d->ShowModal() != wxID_OK) { + return; + } - auto const s = _get()->chain(); - checked_fwrite (s.c_str(), s.length(), f, path); - fclose (f); + boost::filesystem::path path(wx_to_std(d->GetPath())); + if (path.extension() != ".pem") { + path += ".pem"; + } + dcp::File f(path, "w"); + if (!f) { + throw OpenFileError(path, errno, OpenFileError::WRITE); } - d->Destroy (); + auto const s = _get()->chain(); + f.checked_write(s.c_str(), s.length()); } void @@ -541,15 +544,13 @@ CertificateChainEditor::remake_certificates () return; } - auto d = new MakeChainDialog (this, _get()); + auto d = make_wx(this, _get()); if (d->ShowModal () == wxID_OK) { _set (d->get()); update_certificate_list (); update_private_key (); } - - d->Destroy (); } void @@ -570,7 +571,7 @@ CertificateChainEditor::update_private_key () void CertificateChainEditor::import_private_key () { - auto d = new wxFileDialog (this, _("Select Key File")); + auto d = make_wx(this, _("Select Key File")); if (d->ShowModal() == wxID_OK) { try { @@ -592,8 +593,6 @@ CertificateChainEditor::import_private_key () } } - d->Destroy (); - update_sensitivity (); } @@ -605,7 +604,7 @@ CertificateChainEditor::export_private_key () return; } - auto d = new wxFileDialog ( + auto d = make_wx( this, _("Select Key File"), wxEmptyString, wxT("private_key.pem"), wxT("PEM files (*.pem)|*.pem"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); @@ -615,16 +614,14 @@ CertificateChainEditor::export_private_key () if (path.extension() != ".pem") { path += ".pem"; } - auto f = fopen_boost (path, "w"); + dcp::File f(path, "w"); if (!f) { throw OpenFileError (path, errno, OpenFileError::WRITE); } auto const s = _get()->key().get (); - checked_fwrite (s.c_str(), s.length(), f, path); - fclose (f); + f.checked_write(s.c_str(), s.length()); } - d->Destroy (); } wxString @@ -725,27 +722,26 @@ KeysPage::signing_advanced () void KeysPage::export_decryption_chain_and_key () { - auto d = new wxFileDialog ( + auto d = make_wx( _panel, _("Select Export File"), wxEmptyString, wxEmptyString, wxT ("DOM files (*.dom)|*.dom"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); - if (d->ShowModal () == wxID_OK) { - boost::filesystem::path path (wx_to_std(d->GetPath())); - auto f = fopen_boost (path, "w"); - if (!f) { - throw OpenFileError (path, errno, OpenFileError::WRITE); - } + if (d->ShowModal() != wxID_OK) { + return; + } - auto const chain = Config::instance()->decryption_chain()->chain(); - checked_fwrite (chain.c_str(), chain.length(), f, path); - optional const key = Config::instance()->decryption_chain()->key(); - DCPOMATIC_ASSERT (key); - checked_fwrite (key->c_str(), key->length(), f, path); - fclose (f); + boost::filesystem::path path(wx_to_std(d->GetPath())); + dcp::File f(path, "w"); + if (!f) { + throw OpenFileError(path, errno, OpenFileError::WRITE); } - d->Destroy (); + auto const chain = Config::instance()->decryption_chain()->chain(); + f.checked_write(chain.c_str(), chain.length()); + auto const key = Config::instance()->decryption_chain()->key(); + DCPOMATIC_ASSERT(key); + f.checked_write(key->c_str(), key->length()); } void @@ -760,42 +756,42 @@ KeysPage::import_decryption_chain_and_key () return; } - auto d = new wxFileDialog ( + auto d = make_wx( _panel, _("Select File To Import"), wxEmptyString, wxEmptyString, wxT ("DOM files (*.dom)|*.dom") ); - if (d->ShowModal () == wxID_OK) { - auto new_chain = make_shared(); + if (d->ShowModal() != wxID_OK) { + return; + } - FILE* f = fopen_boost (wx_to_std (d->GetPath ()), "r"); - if (!f) { - throw OpenFileError (wx_to_std (d->GetPath ()), errno, OpenFileError::WRITE); - } + auto new_chain = make_shared(); - string current; - while (!feof (f)) { - char buffer[128]; - if (fgets (buffer, 128, f) == 0) { - break; - } - current += buffer; - if (strncmp (buffer, "-----END CERTIFICATE-----", 25) == 0) { - new_chain->add (dcp::Certificate (current)); - current = ""; - } else if (strncmp (buffer, "-----END RSA PRIVATE KEY-----", 29) == 0) { - new_chain->set_key (current); - current = ""; - } - } - fclose (f); + dcp::File f(wx_to_std(d->GetPath()), "r"); + if (!f) { + throw OpenFileError(f.path(), errno, OpenFileError::WRITE); + } - if (new_chain->chain_valid() && new_chain->private_key_valid()) { - Config::instance()->set_decryption_chain (new_chain); - } else { - error_dialog (_panel, _("Invalid DCP-o-matic export file")); + string current; + while (!f.eof()) { + char buffer[128]; + if (f.gets(buffer, 128) == 0) { + break; + } + current += buffer; + if (strncmp (buffer, "-----END CERTIFICATE-----", 25) == 0) { + new_chain->add(dcp::Certificate(current)); + current = ""; + } else if (strncmp (buffer, "-----END RSA PRIVATE KEY-----", 29) == 0) { + new_chain->set_key(current); + current = ""; } } - d->Destroy (); + + if (new_chain->chain_valid() && new_chain->private_key_valid()) { + Config::instance()->set_decryption_chain(new_chain); + } else { + error_dialog(_panel, _("Invalid DCP-o-matic export file")); + } } bool @@ -822,27 +818,26 @@ KeysPage::export_decryption_certificate () } default_name += wxT("_kdm_decryption_cert.pem"); - auto d = new wxFileDialog ( + auto d = make_wx( _panel, _("Select Certificate File"), wxEmptyString, default_name, wxT("PEM files (*.pem)|*.pem"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); - if (d->ShowModal () == wxID_OK) { - boost::filesystem::path path (wx_to_std(d->GetPath())); - if (path.extension() != ".pem") { - path += ".pem"; - } - auto f = fopen_boost (path, "w"); - if (!f) { - throw OpenFileError (path, errno, OpenFileError::WRITE); - } + if (d->ShowModal() != wxID_OK) { + return; + } - auto const s = Config::instance()->decryption_chain()->leaf().certificate (true); - checked_fwrite (s.c_str(), s.length(), f, path); - fclose (f); + boost::filesystem::path path(wx_to_std(d->GetPath())); + if (path.extension() != ".pem") { + path += ".pem"; + } + dcp::File f(path, "w"); + if (!f) { + throw OpenFileError(path, errno, OpenFileError::WRITE); } - d->Destroy (); + auto const s = Config::instance()->decryption_chain()->leaf().certificate (true); + f.checked_write(s.c_str(), s.length()); } wxString @@ -871,7 +866,6 @@ SoundPage::setup () add_label_to_sizer (table, _panel, _("Mapping"), true, wxGBPosition(r, 0)); _map = new AudioMappingView (_panel, _("DCP"), _("DCP"), _("Output"), _("output")); - _map->SetSize (-1, 400); table->Add (_map, wxGBPosition(r, 1), wxDefaultSpan, wxEXPAND); ++r; @@ -896,7 +890,7 @@ SoundPage::setup () } } - _sound->Bind (wxEVT_CHECKBOX, bind(&SoundPage::sound_changed, this)); + _sound->bind(&SoundPage::sound_changed, this); _sound_output->Bind (wxEVT_CHOICE, bind(&SoundPage::sound_output_changed, this)); _map->Changed.connect (bind(&SoundPage::map_changed, this, _1)); _reset_to_default->Bind (wxEVT_BUTTON, bind(&SoundPage::reset_to_default, this)); @@ -1055,7 +1049,7 @@ LocationsPage::GetName () const wxBitmap LocationsPage::GetLargeIcon () const { - return wxBitmap(bitmap_path("locations"), wxBITMAP_TYPE_PNG); + return wxBitmap(icon_path("locations"), wxBITMAP_TYPE_PNG); } #endif