diff options
| author | Carl Hetherington <cth@carlh.net> | 2023-01-14 22:06:05 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2023-01-14 22:06:05 +0100 |
| commit | 4e4968464eeef1956cb82392e1fc3b27a792ab89 (patch) | |
| tree | 79db245f320df21a075a0fd26de685e02fff6924 /src/tools | |
| parent | 0ecea9f4d1a772e99f396e47364e68abfbfe9f7f (diff) | |
Add wx_ptr and use it instead of ScopeGuard in a lot of places.
Diffstat (limited to 'src/tools')
| -rw-r--r-- | src/tools/dcpomatic.cc | 124 | ||||
| -rw-r--r-- | src/tools/dcpomatic_batch.cc | 13 | ||||
| -rw-r--r-- | src/tools/dcpomatic_kdm.cc | 19 | ||||
| -rw-r--r-- | src/tools/dcpomatic_player.cc | 10 |
4 files changed, 66 insertions, 100 deletions
diff --git a/src/tools/dcpomatic.cc b/src/tools/dcpomatic.cc index 257bb7ab1..546306ac4 100644 --- a/src/tools/dcpomatic.cc +++ b/src/tools/dcpomatic.cc @@ -53,6 +53,7 @@ #include "wx/update_dialog.h" #include "wx/video_waveform_dialog.h" #include "wx/wx_signal_manager.h" +#include "wx/wx_ptr.h" #include "wx/wx_util.h" #include "lib/analytics.h" #include "lib/audio_content.h" @@ -80,7 +81,6 @@ #include "lib/log.h" #include "lib/make_dcp.h" #include "lib/release_notes.h" -#include "lib/scope_guard.h" #include "lib/screen.h" #include "lib/send_kdm_email_job.h" #include "lib/signal_manager.h" @@ -577,8 +577,7 @@ private: void file_new () { - auto d = new FilmNameLocationDialog (this, _("New Film"), true); - ScopeGuard sg = [d]() { d->Destroy(); }; + auto d = make_wx<FilmNameLocationDialog>(this, _("New Film"), true); int const r = d->ShowModal (); if (r != wxID_OK || !d->check_path() || !maybe_save_then_delete_film<FilmChangedClosingDialog>()) { @@ -613,13 +612,12 @@ private: void file_open () { - auto c = new wxDirDialog ( + auto c = make_wx<wxDirDialog>( this, _("Select film to open"), std_to_wx (Config::instance()->default_directory_or (wx_to_std (wxStandardPaths::Get().GetDocumentsDir())).string ()), wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST ); - ScopeGuard sg = [c]() { c->Destroy(); }; int r; while (true) { @@ -643,8 +641,7 @@ private: void file_save_as_template () { - auto d = new SaveTemplateDialog (this); - ScopeGuard sg = [d]() { d->Destroy(); }; + auto d = make_wx<SaveTemplateDialog>(this); if (d->ShowModal() == wxID_OK) { Config::instance()->save_template (_film, d->name ()); } @@ -652,8 +649,7 @@ private: void file_duplicate () { - auto d = new FilmNameLocationDialog (this, _("Duplicate Film"), false); - ScopeGuard sg = [d]() { d->Destroy(); }; + auto d = make_wx<FilmNameLocationDialog>(this, _("Duplicate Film"), false); if (d->ShowModal() == wxID_OK && d->check_path() && maybe_save_film<FilmChangedDuplicatingDialog>()) { shared_ptr<Film> film (new Film (d->path())); @@ -665,11 +661,10 @@ private: void file_duplicate_and_open () { - auto d = new FilmNameLocationDialog (this, _("Duplicate Film"), false); - ScopeGuard sg = [d]() { d->Destroy(); }; + auto d = make_wx<FilmNameLocationDialog>(this, _("Duplicate Film"), false); if (d->ShowModal() == wxID_OK && d->check_path() && maybe_save_film<FilmChangedDuplicatingDialog>()) { - shared_ptr<Film> film (new Film (d->path())); + auto film = make_shared<Film>(d->path()); film->copy_from (_film); film->set_name (d->path().filename().generic_string()); film->write_metadata (); @@ -728,8 +723,7 @@ private: { DCPOMATIC_ASSERT (_clipboard); - auto d = new PasteDialog (this, static_cast<bool>(_clipboard->video), static_cast<bool>(_clipboard->audio), !_clipboard->text.empty()); - ScopeGuard sg = [d]() { d->Destroy(); }; + auto d = make_wx<PasteDialog>(this, static_cast<bool>(_clipboard->video), static_cast<bool>(_clipboard->audio), !_clipboard->text.empty()); if (d->ShowModal() != wxID_OK) { return; } @@ -771,13 +765,12 @@ private: void tools_restore_default_preferences () { - auto d = new wxMessageDialog ( - 0, + auto d = make_wx<wxMessageDialog>( + nullptr, _("Are you sure you want to restore preferences to their defaults? This cannot be undone."), _("Restore default preferences"), wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION ); - ScopeGuard sg = [d]() { d->Destroy(); }; if (d->ShowModal() == wxID_YES) { Config::restore_defaults (); @@ -786,11 +779,10 @@ private: void tools_export_preferences () { - auto dialog = new wxFileDialog ( + auto dialog = make_wx<wxFileDialog>( this, _("Specify ZIP file"), wxEmptyString, wxT("dcpomatic_config.zip"), wxT("ZIP files (*.zip)|*.zip"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); - ScopeGuard sg = [dialog]() { dialog->Destroy(); }; if (dialog->ShowModal() == wxID_OK) { save_all_config_as_zip (wx_to_std(dialog->GetPath())); @@ -816,8 +808,7 @@ private: } if (Config::instance()->show_hints_before_make_dcp()) { - auto hints = new HintsDialog (this, _film, false); - ScopeGuard sg = [hints]() { hints->Destroy(); }; + auto hints = make_wx<HintsDialog>(this, _film, false); if (hints->ShowModal() == wxID_CANCEL) { return; } @@ -929,8 +920,7 @@ private: } if (Config::instance()->show_hints_before_make_dcp()) { - auto hints = new HintsDialog (this, _film, false); - ScopeGuard sg = [hints]() { hints->Destroy(); }; + auto hints = make_wx<HintsDialog>(this, _film, false); if (hints->ShowModal() == wxID_CANCEL) { return; } @@ -968,8 +958,7 @@ private: return; } - auto d = new SelfDKDMDialog (this, _film); - ScopeGuard sg = [d]() { d->Destroy(); }; + auto d = make_wx<SelfDKDMDialog>(this, _film); if (d->ShowModal () != wxID_OK) { return; } @@ -1025,8 +1014,7 @@ private: void jobs_export_video_file () { - auto d = new ExportVideoFileDialog (this, _film->isdcf_name(true)); - ScopeGuard sg = [d]() { d->Destroy(); }; + auto d = make_wx<ExportVideoFileDialog>(this, _film->isdcf_name(true)); if (d->ShowModal() != wxID_OK) { return; } @@ -1053,8 +1041,7 @@ private: void jobs_export_subtitles () { - auto d = new ExportSubtitlesDialog (this, _film->reels().size(), _film->interop()); - ScopeGuard sg = [d]() { d->Destroy(); }; + auto d = make_wx<ExportSubtitlesDialog>(this, _film->reels().size(), _film->interop()); if (d->ShowModal() != wxID_OK) { return; } @@ -1137,44 +1124,43 @@ private: void tools_send_translations () { - auto d = new SendI18NDialog (this); - ScopeGuard sg = [d]() { d->Destroy(); }; - if (d->ShowModal() == wxID_OK) { - string body; - body += d->name() + "\n"; - body += d->language() + "\n"; - body += string(dcpomatic_version) + " " + string(dcpomatic_git_commit) + "\n"; - body += "--\n"; - auto translations = I18NHook::translations (); - for (auto i: translations) { - body += i.first + "\n" + i.second + "\n\n"; - } - list<string> to = { "carl@dcpomatic.com" }; - if (d->email().find("@") == string::npos) { - error_dialog (this, _("You must enter a valid email address when sending translations, " - "otherwise the DCP-o-matic maintainers cannot credit you or contact you with questions.")); - } else { - Emailer emailer (d->email(), to, "DCP-o-matic translations", body); - try { - emailer.send ("main.carlh.net", 2525, EmailProtocol::STARTTLS); - } catch (NetworkError& e) { - error_dialog (this, _("Could not send translations"), std_to_wx(e.what())); - } + auto d = make_wx<SendI18NDialog>(this); + if (d->ShowModal() != wxID_OK) { + return; + } + + string body; + body += d->name() + "\n"; + body += d->language() + "\n"; + body += string(dcpomatic_version) + " " + string(dcpomatic_git_commit) + "\n"; + body += "--\n"; + auto translations = I18NHook::translations (); + for (auto i: translations) { + body += i.first + "\n" + i.second + "\n\n"; + } + list<string> to = { "carl@dcpomatic.com" }; + if (d->email().find("@") == string::npos) { + error_dialog (this, _("You must enter a valid email address when sending translations, " + "otherwise the DCP-o-matic maintainers cannot credit you or contact you with questions.")); + } else { + Emailer emailer (d->email(), to, "DCP-o-matic translations", body); + try { + emailer.send ("main.carlh.net", 2525, EmailProtocol::STARTTLS); + } catch (NetworkError& e) { + error_dialog (this, _("Could not send translations"), std_to_wx(e.what())); } } } void help_about () { - auto d = new AboutDialog (this); - ScopeGuard sg = [d]() { d->Destroy(); }; + auto d = make_wx<AboutDialog>(this); d->ShowModal (); } void help_report_a_problem () { - auto d = new ReportProblemDialog (this, _film); - ScopeGuard sg = [d]() { d->Destroy(); }; + auto d = make_wx<ReportProblemDialog>(this, _film); if (d->ShowModal () == wxID_OK) { d->report (); } @@ -1186,13 +1172,12 @@ private: return true; } - auto d = new wxMessageDialog ( - 0, + auto d = make_wx<wxMessageDialog>( + nullptr, _("There are unfinished jobs; are you sure you want to quit?"), _("Unfinished jobs"), wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION ); - ScopeGuard sg = [d]() { d->Destroy(); }; return d->ShowModal() == wxID_YES; } @@ -1529,8 +1514,7 @@ private: } if (uc->state() == UpdateChecker::State::YES) { - auto dialog = new UpdateDialog (this, uc->stable(), uc->test()); - ScopeGuard sg = [dialog]() { dialog->Destroy(); }; + auto dialog = make_wx<UpdateDialog>(this, uc->stable(), uc->test()); dialog->ShowModal (); } else if (uc->state() == UpdateChecker::State::FAILED) { error_dialog (this, _("The DCP-o-matic download server could not be contacted.")); @@ -1567,8 +1551,7 @@ private: void analytics_message (string title, string html) { - auto d = new HTMLDialog(this, std_to_wx(title), std_to_wx(html)); - ScopeGuard sg = [d]() { d->Destroy(); }; + auto d = make_wx<HTMLDialog>(this, std_to_wx(title), std_to_wx(html)); d->ShowModal(); } @@ -1738,8 +1721,7 @@ private: auto release_notes = find_release_notes(gui_is_dark()); if (release_notes) { - auto notes = new HTMLDialog(nullptr, _("Release notes"), std_to_wx(*release_notes), true); - ScopeGuard sg = [notes]() { notes->Destroy(); }; + auto notes = make_wx<HTMLDialog>(nullptr, _("Release notes"), std_to_wx(*release_notes), true); notes->Centre(); notes->ShowModal(); } @@ -1892,7 +1874,7 @@ private: if (config->nagged(Config::NAG_BAD_SIGNER_CHAIN_UTF8)) { return false; } - auto d = new RecreateChainDialog ( + auto d = make_wx<RecreateChainDialog>( _frame, _("Recreate signing certificates"), _("The certificate chain that DCP-o-matic uses for signing DCPs and KDMs contains a small error\n" "which will prevent DCPs from being validated correctly on some systems. Do you want to re-create\n" @@ -1900,7 +1882,6 @@ private: _("Do nothing"), Config::NAG_BAD_SIGNER_CHAIN_UTF8 ); - ScopeGuard sg = [d]() { d->Destroy(); }; return d->ShowModal() == wxID_OK; } case Config::BAD_SIGNER_VALIDITY_TOO_LONG: @@ -1908,7 +1889,7 @@ private: if (config->nagged(Config::NAG_BAD_SIGNER_CHAIN_VALIDITY)) { return false; } - auto d = new RecreateChainDialog ( + auto d = make_wx<RecreateChainDialog>( _frame, _("Recreate signing certificates"), _("The certificate chain that DCP-o-matic uses for signing DCPs and KDMs has a validity period\n" "that is too long. This will cause problems playing back DCPs on some systems.\n" @@ -1916,19 +1897,17 @@ private: _("Do nothing"), Config::NAG_BAD_SIGNER_CHAIN_VALIDITY ); - ScopeGuard sg = [d]() { d->Destroy(); }; return d->ShowModal() == wxID_OK; } case Config::BAD_SIGNER_INCONSISTENT: { - auto d = new RecreateChainDialog ( + auto d = make_wx<RecreateChainDialog>( _frame, _("Recreate signing certificates"), _("The certificate chain that DCP-o-matic uses for signing DCPs and KDMs is inconsistent and\n" "cannot be used. DCP-o-matic cannot start unless you re-create it. Do you want to re-create\n" "the certificate chain for signing DCPs and KDMs?"), _("Close DCP-o-matic") ); - ScopeGuard sg = [d]() { d->Destroy(); }; if (d->ShowModal() != wxID_OK) { exit (EXIT_FAILURE); } @@ -1936,7 +1915,7 @@ private: } case Config::BAD_DECRYPTION_INCONSISTENT: { - auto d = new RecreateChainDialog ( + auto d = make_wx<RecreateChainDialog>( _frame, _("Recreate KDM decryption chain"), _("The certificate chain that DCP-o-matic uses for decrypting KDMs is inconsistent and\n" "cannot be used. DCP-o-matic cannot start unless you re-create it. Do you want to re-create\n" @@ -1944,7 +1923,6 @@ private: "configuration before continuing."), _("Close DCP-o-matic") ); - ScopeGuard sg = [d]() { d->Destroy(); }; if (d->ShowModal() != wxID_OK) { exit (EXIT_FAILURE); } diff --git a/src/tools/dcpomatic_batch.cc b/src/tools/dcpomatic_batch.cc index 64015a0e3..b73d0a418 100644 --- a/src/tools/dcpomatic_batch.cc +++ b/src/tools/dcpomatic_batch.cc @@ -24,6 +24,7 @@ #include "wx/full_config_dialog.h" #include "wx/job_manager_view.h" #include "wx/servers_list_dialog.h" +#include "wx/wx_ptr.h" #include "wx/wx_signal_manager.h" #include "wx/wx_util.h" #include "lib/compose.hpp" @@ -33,7 +34,6 @@ #include "lib/job.h" #include "lib/job_manager.h" #include "lib/make_dcp.h" -#include "lib/scope_guard.h" #include "lib/transcode_job.h" #include "lib/util.h" #include "lib/version.h" @@ -269,13 +269,12 @@ private: return true; } - auto d = new wxMessageDialog ( - 0, + auto d = make_wx<wxMessageDialog>( + nullptr, _("There are unfinished jobs; are you sure you want to quit?"), _("Unfinished jobs"), wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION ); - ScopeGuard sg = [d]{ d->Destroy(); }; return d->ShowModal() == wxID_YES; } @@ -321,15 +320,13 @@ private: void help_about () { - auto d = new AboutDialog (this); - ScopeGuard sg = [d]() { d->Destroy(); }; + auto d = make_wx<AboutDialog>(this); d->ShowModal (); } void add_film () { - auto dialog = new wxDirDialog(this, _("Select film to open"), wxStandardPaths::Get().GetDocumentsDir(), wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST); - ScopeGuard sg = [dialog]() { dialog->Destroy(); }; + auto dialog = make_wx<wxDirDialog>(this, _("Select film to open"), wxStandardPaths::Get().GetDocumentsDir(), wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST); if (_last_parent) { dialog->SetPath(std_to_wx(_last_parent.get().string())); } diff --git a/src/tools/dcpomatic_kdm.cc b/src/tools/dcpomatic_kdm.cc index 256367977..87a77c626 100644 --- a/src/tools/dcpomatic_kdm.cc +++ b/src/tools/dcpomatic_kdm.cc @@ -33,6 +33,7 @@ #include "wx/report_problem_dialog.h" #include "wx/screens_panel.h" #include "wx/static_text.h" +#include "wx/wx_ptr.h" #include "wx/wx_signal_manager.h" #include "wx/wx_util.h" #include "lib/cinema.h" @@ -47,7 +48,6 @@ #include "lib/file_log.h" #include "lib/job_manager.h" #include "lib/kdm_with_metadata.h" -#include "lib/scope_guard.h" #include "lib/screen.h" #include "lib/send_kdm_email_job.h" #include <dcp/encrypted_kdm.h> @@ -266,15 +266,13 @@ private: void help_about () { - auto d = new AboutDialog (this); - ScopeGuard sg = [d]() { d->Destroy(); }; + auto d = make_wx<AboutDialog>(this); d->ShowModal (); } void help_report_a_problem () { - auto d = new ReportProblemDialog (this, shared_ptr<Film>()); - ScopeGuard sg = [d]() { d->Destroy(); }; + auto d = make_wx<ReportProblemDialog>(this, shared_ptr<Film>()); if (d->ShowModal () == wxID_OK) { d->report (); } @@ -512,10 +510,7 @@ private: void add_dkdm_clicked () { - auto dialog = new FileDialog(this, _("Select DKDM file"), wxT("XML files|*.xml|All files|*.*"), wxFD_MULTIPLE, "AddDKDMPath"); - - ScopeGuard sg = [dialog]() { dialog->Destroy(); }; - + auto dialog = make_wx<FileDialog>(this, _("Select DKDM file"), wxT("XML files|*.xml|All files|*.*"), wxFD_MULTIPLE, "AddDKDMPath"); if (!dialog->show()) { return; } @@ -566,8 +561,7 @@ private: void add_dkdm_folder_clicked () { - auto d = new NewDKDMFolderDialog (this); - ScopeGuard sg = [d]() { d->Destroy(); }; + auto d = make_wx<NewDKDMFolderDialog>(this); if (d->ShowModal() != wxID_OK) { return; } @@ -718,11 +712,10 @@ private: return; } - auto d = new wxFileDialog ( + auto d = make_wx<wxFileDialog>( this, _("Select DKDM File"), wxEmptyString, wxEmptyString, wxT("XML files (*.xml)|*.xml"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT ); - ScopeGuard sg = [d]() { d->Destroy(); }; if (d->ShowModal() == wxID_OK) { dkdm->dkdm().as_xml(wx_to_std(d->GetPath())); diff --git a/src/tools/dcpomatic_player.cc b/src/tools/dcpomatic_player.cc index 1b2b98729..600d1c6b4 100644 --- a/src/tools/dcpomatic_player.cc +++ b/src/tools/dcpomatic_player.cc @@ -32,6 +32,7 @@ #include "wx/update_dialog.h" #include "wx/verify_dcp_dialog.h" #include "wx/verify_dcp_progress_dialog.h" +#include "wx/wx_ptr.h" #include "wx/wx_signal_manager.h" #include "wx/wx_util.h" #include "lib/compose.hpp" @@ -617,8 +618,7 @@ private: d = std_to_wx (Config::instance()->last_player_load_directory()->string()); } - auto c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST); - ScopeGuard sg = [c]() { c->Destroy(); }; + auto c = make_wx<wxDirDialog>(this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST); int r; while (true) { @@ -644,13 +644,12 @@ private: initial_dir = std_to_wx(Config::instance()->last_player_load_directory()->string()); } - auto c = new wxDirDialog ( + auto c = make_wx<wxDirDialog>( this, _("Select DCP to open as OV"), initial_dir, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST ); - ScopeGuard sg = [c]() { c->Destroy(); }; int r; while (true) { @@ -688,8 +687,7 @@ private: void file_add_kdm () { - auto d = new wxFileDialog (this, _("Select KDM")); - ScopeGuard sg = [d]() { d->Destroy(); }; + auto d = make_wx<wxFileDialog>(this, _("Select KDM")); if (d->ShowModal() == wxID_OK) { DCPOMATIC_ASSERT (_film); |
