#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"
#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"
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>()) {
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) {
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 ());
}
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()));
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 ();
{
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;
}
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 ();
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()));
}
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;
}
}
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;
}
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;
}
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;
}
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;
}
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 ();
}
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;
}
}
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."));
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();
}
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();
}
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"
_("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:
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"
_("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);
}
}
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"
"configuration before continuing."),
_("Close DCP-o-matic")
);
- ScopeGuard sg = [d]() { d->Destroy(); };
if (d->ShowModal() != wxID_OK) {
exit (EXIT_FAILURE);
}
#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"
#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"
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;
}
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()));
}
#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"
#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>
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 ();
}
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;
}
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;
}
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()));
#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"
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) {
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) {
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);
#include "dcpomatic_button.h"
#include "nag_dialog.h"
#include "static_text.h"
+#include "wx_ptr.h"
#include "lib/constants.h"
#include <dcp/file.h>
#include <dcp/raw_convert.h>
void
CertificateChainEditor::add_certificate ()
{
- auto d = new wxFileDialog (this, _("Select Certificate File"));
- ScopeGuard sg = [d]() { d->Destroy(); };
+ auto d = make_wx<wxFileDialog>(this, _("Select Certificate File"));
if (d->ShowModal() == wxID_OK) {
try {
default_name = "intermediate.pem";
}
- auto d = new wxFileDialog(
+ auto d = make_wx<wxFileDialog>(
this, _("Select Certificate File"), wxEmptyString, default_name, wxT ("PEM files (*.pem)|*.pem"),
wxFD_SAVE | wxFD_OVERWRITE_PROMPT
);
- ScopeGuard sg = [d]() { d->Destroy(); };
auto j = all.begin ();
for (int k = 0; k < i; ++k) {
void
CertificateChainEditor::export_chain ()
{
- auto d = new wxFileDialog (
+ auto d = make_wx<wxFileDialog>(
this, _("Select Chain File"), wxEmptyString, wxT("certificate_chain.pem"), wxT("PEM files (*.pem)|*.pem"),
wxFD_SAVE | wxFD_OVERWRITE_PROMPT
);
- ScopeGuard sg = [d]() { d->Destroy(); };
if (d->ShowModal() != wxID_OK) {
return;
return;
}
- auto d = new MakeChainDialog (this, _get());
- ScopeGuard sg = [d]() { d->Destroy(); };
+ auto d = make_wx<MakeChainDialog>(this, _get());
if (d->ShowModal () == wxID_OK) {
_set (d->get());
void
CertificateChainEditor::import_private_key ()
{
- auto d = new wxFileDialog (this, _("Select Key File"));
- ScopeGuard sg = [d]() { d->Destroy(); };
+ auto d = make_wx<wxFileDialog>(this, _("Select Key File"));
if (d->ShowModal() == wxID_OK) {
try {
return;
}
- auto d = new wxFileDialog (
+ auto d = make_wx<wxFileDialog>(
this, _("Select Key File"), wxEmptyString, wxT("private_key.pem"), wxT("PEM files (*.pem)|*.pem"),
wxFD_SAVE | wxFD_OVERWRITE_PROMPT
);
- ScopeGuard sg = [d]() { d->Destroy(); };
if (d->ShowModal () == wxID_OK) {
boost::filesystem::path path (wx_to_std(d->GetPath()));
void
KeysPage::export_decryption_chain_and_key ()
{
- auto d = new wxFileDialog (
+ auto d = make_wx<wxFileDialog>(
_panel, _("Select Export File"), wxEmptyString, wxEmptyString, wxT ("DOM files (*.dom)|*.dom"),
wxFD_SAVE | wxFD_OVERWRITE_PROMPT
);
- ScopeGuard sg = [d]() { d->Destroy(); };
if (d->ShowModal() != wxID_OK) {
return;
return;
}
- auto d = new wxFileDialog (
+ auto d = make_wx<wxFileDialog>(
_panel, _("Select File To Import"), wxEmptyString, wxEmptyString, wxT ("DOM files (*.dom)|*.dom")
);
- ScopeGuard sg = [d]() { d->Destroy(); };
if (d->ShowModal() != wxID_OK) {
return;
}
default_name += wxT("_kdm_decryption_cert.pem");
- auto d = new wxFileDialog (
+ auto d = make_wx<wxFileDialog>(
_panel, _("Select Certificate File"), wxEmptyString, default_name, wxT("PEM files (*.pem)|*.pem"),
wxFD_SAVE | wxFD_OVERWRITE_PROMPT
);
- ScopeGuard sg = [d]() { d->Destroy(); };
if (d->ShowModal() != wxID_OK) {
return;
#include "filter_dialog.h"
#include "language_tag_widget.h"
#include "static_text.h"
+#include "wx_ptr.h"
#include "wx_util.h"
#include "lib/content.h"
#include "lib/dcp_content.h"
#include "lib/filter.h"
#include "lib/ffmpeg_content.h"
#include "lib/image_content.h"
-#include "lib/scope_guard.h"
#include "lib/video_content.h"
#include <dcp/warnings.h>
LIBDCP_DISABLE_WARNINGS
return;
}
- auto dialog = new FilterDialog(this, _filters_list);
- ScopeGuard sg = [dialog]() { dialog->Destroy(); };
-
+ auto dialog = make_wx<FilterDialog>(this, _filters_list);
dialog->ActiveChanged.connect(bind(&ContentAdvancedDialog::filters_changed, this, _1));
dialog->ShowModal();
}
#include "repeat_dialog.h"
#include "timeline_video_content_view.h"
#include "timeline_audio_content_view.h"
+#include "wx_ptr.h"
#include "wx_util.h"
#include "lib/audio_content.h"
#include "lib/config.h"
#include "lib/image_content.h"
#include "lib/job_manager.h"
#include "lib/playlist.h"
-#include "lib/scope_guard.h"
#include "lib/video_content.h"
#include <dcp/cpl.h>
#include <dcp/decrypted_kdm.h>
DCPOMATIC_ASSERT(!_content.empty());
auto content = _content.front();
- auto dialog = new ContentAdvancedDialog(_parent, content);
- ScopeGuard sg = [dialog]() { dialog->Destroy(); };
+ auto dialog = make_wx<ContentAdvancedDialog>(_parent, content);
if (dialog->ShowModal() == wxID_CANCEL) {
return;
#include "timeline_dialog.h"
#include "timing_panel.h"
#include "video_panel.h"
+#include "wx_ptr.h"
#include "wx_util.h"
#include "lib/audio_content.h"
#include "lib/case_insensitive_sorter.h"
#include "lib/image_content.h"
#include "lib/log.h"
#include "lib/playlist.h"
-#include "lib/scope_guard.h"
#include "lib/string_text_file.h"
#include "lib/string_text_file_content.h"
#include "lib/text_content.h"
/* The wxFD_CHANGE_DIR here prevents a `could not set working directory' error 123 on Windows when using
non-Latin filenames or paths.
*/
- auto dialog = new FileDialog(
+ auto dialog = make_wx<FileDialog>(
_splitter,
_("Choose a file or files"),
wxT("All files|*.*|Subtitle files|*.srt;*.xml|Audio files|*.wav;*.w64;*.flac;*.aif;*.aiff"),
add_files_override_path()
);
- ScopeGuard sg = [dialog]() { dialog->Destroy(); };
-
if (dialog->show()) {
add_files(dialog->paths());
}
void
ContentPanel::add_folder_clicked ()
{
- auto d = new DirDialog(_splitter, _("Choose a folder"), wxDD_DIR_MUST_EXIST, "AddFilesPath", add_files_override_path());
- ScopeGuard sg = [d]() { d->Destroy(); };
+ auto d = make_wx<DirDialog>(_splitter, _("Choose a folder"), wxDD_DIR_MUST_EXIST, "AddFilesPath", add_files_override_path());
if (d->show()) {
add_folder(d->path());
}
for (auto i: content) {
auto ic = dynamic_pointer_cast<ImageContent> (i);
if (ic) {
- auto e = new ImageSequenceDialog (_splitter);
- ScopeGuard sg = [e]() { e->Destroy(); };
+ auto e = make_wx<ImageSequenceDialog>(_splitter);
if (e->ShowModal() != wxID_OK) {
return;
void
ContentPanel::add_dcp_clicked ()
{
- auto d = new DirDialog(_splitter, _("Choose a DCP folder"), wxDD_DIR_MUST_EXIST, "AddFilesPath", add_files_override_path());
- ScopeGuard sg = [d]() { d->Destroy(); };
+ auto d = make_wx<DirDialog>(_splitter, _("Choose a DCP folder"), wxDD_DIR_MUST_EXIST, "AddFilesPath", add_files_override_path());
if (d->show()) {
add_dcp(d->path());
}
#include "playhead_to_frame_dialog.h"
#include "playhead_to_timecode_dialog.h"
#include "static_text.h"
+#include "wx_ptr.h"
#include "wx_util.h"
#include "lib/content_factory.h"
#include "lib/cross.h"
void
Controls::timecode_clicked ()
{
- auto dialog = new PlayheadToTimecodeDialog(this, _viewer.position(), _film->video_frame_rate());
- ScopeGuard sg = [dialog]() { dialog->Destroy(); };
+ auto dialog = make_wx<PlayheadToTimecodeDialog>(this, _viewer.position(), _film->video_frame_rate());
if (dialog->ShowModal() == wxID_OK) {
_viewer.seek(dialog->get(), true);
void
Controls::frame_number_clicked ()
{
- auto dialog = new PlayheadToFrameDialog(this, _viewer.position(), _film->video_frame_rate());
- ScopeGuard sg = [dialog]() { dialog->Destroy(); };
+ auto dialog = make_wx<PlayheadToFrameDialog>(this, _viewer.position(), _film->video_frame_rate());
if (dialog->ShowModal() == wxID_OK) {
_viewer.seek(dialog->get(), true);
#include "dcpomatic_button.h"
+#include "wx_ptr.h"
#include "wx_util.h"
-#include "lib/scope_guard.h"
#include <dcp/warnings.h>
LIBDCP_DISABLE_WARNINGS
#include <wx/listctrl.h>
void add_clicked ()
{
- S* dialog = new S (this);
- ScopeGuard sg = [dialog]() { dialog->Destroy(); };
+ auto dialog = make_wx<S>(this);
if (dialog->ShowModal() == wxID_OK) {
auto const v = dialog->get ();
std::vector<T> all = _get ();
DCPOMATIC_ASSERT (item >= 0 && item < int (all.size ()));
- S* dialog = new S (this);
- ScopeGuard sg = [dialog]() { dialog->Destroy(); };
+ auto dialog = make_wx<S>(this);
dialog->set (all[item]);
if (dialog->ShowModal() == wxID_OK) {
auto const v = dialog->get ();
#include "dcpomatic_button.h"
#include "fonts_dialog.h"
#include "system_font_dialog.h"
+#include "wx_ptr.h"
#include "wx_util.h"
#include "lib/content.h"
#include "lib/font.h"
default_dir = "/System/Library/Fonts";
#endif
- auto d = new wxFileDialog (this, _("Choose a font file"), default_dir, wxT(""), wxT("*.ttf;*.otf;*.ttc"), wxFD_CHANGE_DIR);
- ScopeGuard sg = [d]() { d->Destroy(); };
+ auto d = make_wx<wxFileDialog>(this, _("Choose a font file"), default_dir, wxT(""), wxT("*.ttf;*.otf;*.ttc"), wxFD_CHANGE_DIR);
if (d->ShowModal() != wxID_OK) {
return;
return;
}
- auto dialog = new SystemFontDialog(this);
- ScopeGuard sg = [dialog]() { dialog->Destroy(); };
+ auto dialog = make_wx<SystemFontDialog>(this);
if (dialog->ShowModal() == wxID_OK) {
auto font_file = dialog->get_font();
if (font_file) {
#include "dcpomatic_button.h"
#include "language_tag_dialog.h"
#include "language_tag_widget.h"
+#include "wx_ptr.h"
#include "wx_util.h"
#include "lib/scope_guard.h"
#include <dcp/warnings.h>
void
LanguageTagWidget::edit ()
{
- auto d = new LanguageTagDialog(_parent, _tag.get_value_or(dcp::LanguageTag("en")));
- ScopeGuard sg = [d]() { d->Destroy(); };
+ auto d = make_wx<LanguageTagDialog>(_parent, _tag.get_value_or(dcp::LanguageTag("en")));
if (d->ShowModal() == wxID_OK) {
set(d->get());
Changed(d->get());
#include "full_language_tag_dialog.h"
#include "region_subtag_dialog.h"
#include "region_subtag_widget.h"
+#include "wx_ptr.h"
#include "wx_util.h"
#include "lib/scope_guard.h"
#include <dcp/warnings.h>
void
RegionSubtagWidget::edit()
{
- auto d = new RegionSubtagDialog(_parent, _tag.get_value_or(dcp::LanguageTag::RegionSubtag("US")));
- ScopeGuard sg = [d]() { d->Destroy(); };
+ auto d = make_wx<RegionSubtagDialog>(_parent, _tag.get_value_or(dcp::LanguageTag::RegionSubtag("US")));
if (d->ShowModal() == wxID_OK) {
set(d->get());
#include "screen_dialog.h"
#include "static_text.h"
#include "table_dialog.h"
+#include "wx_ptr.h"
#include "wx_util.h"
#include "lib/compose.hpp"
#include "lib/scope_guard.h"
void load_certificate ()
{
- auto dialog = new FileDialog(this, _("Trusted Device certificate"), wxEmptyString, wxFD_DEFAULT_STYLE, "SelectCertificatePath");
- ScopeGuard sg = [dialog]() { dialog->Destroy(); };
+ auto dialog = make_wx<FileDialog>(this, _("Trusted Device certificate"), wxEmptyString, wxFD_DEFAULT_STYLE, "SelectCertificatePath");
if (!dialog->show()) {
return;
}
void
ScreenDialog::get_recipient_from_file ()
{
- auto dialog = new FileDialog(this, _("Select Certificate File"), wxEmptyString, wxFD_DEFAULT_STYLE , "SelectCertificatePath");
- ScopeGuard sg = [dialog]() { dialog->Destroy(); };
+ auto dialog = make_wx<FileDialog>(this, _("Select Certificate File"), wxEmptyString, wxFD_DEFAULT_STYLE , "SelectCertificatePath");
if (dialog->show()) {
load_recipient(dialog->paths()[0]);
}
void
ScreenDialog::download_recipient ()
{
- auto dialog = new DownloadCertificateDialog (this);
- ScopeGuard sg = [dialog]() { dialog->Destroy(); };
+ auto dialog = make_wx<DownloadCertificateDialog>(this);
if (dialog->ShowModal() == wxID_OK) {
set_recipient(dialog->certificate());
checked_set(_recipient_file, dialog->url());
#include "dcpomatic_button.h"
#include "screen_dialog.h"
#include "screens_panel.h"
+#include "wx_ptr.h"
#include "wx_util.h"
#include "lib/cinema.h"
#include "lib/config.h"
void
ScreensPanel::add_cinema_clicked ()
{
- auto dialog = new CinemaDialog (GetParent(), _("Add Cinema"));
- ScopeGuard sg = [dialog]() { dialog->Destroy(); };
+ auto dialog = make_wx<CinemaDialog>(GetParent(), _("Add Cinema"));
if (dialog->ShowModal() == wxID_OK) {
auto cinema = make_shared<Cinema>(dialog->name(), dialog->emails(), dialog->notes(), dialog->utc_offset_hour(), dialog->utc_offset_minute());
return;
}
- auto dialog = new CinemaDialog(
+ auto dialog = make_wx<CinemaDialog>(
GetParent(), _("Edit cinema"), cinema->name, cinema->emails, cinema->notes, cinema->utc_offset_hour(), cinema->utc_offset_minute()
);
- ScopeGuard sg = [dialog]() { dialog->Destroy(); };
if (dialog->ShowModal() == wxID_OK) {
cinema->name = dialog->name();
return;
}
- auto dialog = new ScreenDialog(GetParent(), _("Add Screen"));
- ScopeGuard sg = [dialog]() { dialog->Destroy(); };
+ auto dialog = make_wx<ScreenDialog>(GetParent(), _("Add Screen"));
if (dialog->ShowModal () != wxID_OK) {
return;
auto edit_screen = _selected_screens[0];
- auto dialog = new ScreenDialog(
+ auto dialog = make_wx<ScreenDialog>(
GetParent(), _("Edit screen"),
edit_screen->name,
edit_screen->notes,
edit_screen->recipient_file,
edit_screen->trusted_devices
);
- ScopeGuard sg = [dialog]() { dialog->Destroy(); };
if (dialog->ShowModal() != wxID_OK) {
return;
#include "subtitle_appearance_dialog.h"
#include "text_panel.h"
#include "text_view.h"
+#include "wx_ptr.h"
#include "wx_util.h"
#include "lib/analyse_subtitles_job.h"
#include "lib/dcp_content.h"
optional<DCPTextTrack> track;
if (_dcp_track->GetSelection() == int(_dcp_track->GetCount()) - 1) {
- auto d = new DCPTextTrackDialog (this);
- ScopeGuard sg = [d]() { d->Destroy(); };
+ auto d = make_wx<DCPTextTrackDialog>(this);
if (d->ShowModal() == wxID_OK) {
track = d->get();
}
#include "static_text.h"
#include "timecode.h"
#include "timing_panel.h"
+#include "wx_ptr.h"
#include "wx_util.h"
#include "lib/audio_content.h"
#include "lib/content.h"
}
}
- auto d = new MoveToDialog(this, position, _parent->film());
- ScopeGuard sg = [d]() { d->Destroy(); };
+ auto d = make_wx<MoveToDialog>(this, position, _parent->film());
if (d->ShowModal() == wxID_OK) {
for (auto i: _parent->selected()) {
--- /dev/null
+/*
+ Copyright (C) 2023 Carl Hetherington <cth@carlh.net>
+
+ 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.
+
+ 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 DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
+#ifndef DCPOMATIC_WX_PTR_H
+#define DCPOMATIC_WX_PTR_H
+
+
+#include <utility>
+
+
+template <class T>
+class wx_ptr
+{
+public:
+ explicit wx_ptr(T* wx)
+ : _wx(wx)
+ {}
+
+ wx_ptr(wx_ptr&) = delete;
+ wx_ptr& operator=(wx_ptr&) = delete;
+
+ wx_ptr(wx_ptr&& other)
+ {
+ _wx = other._wx;
+ other._wx = nullptr;
+ }
+
+ wx_ptr& operator=(wx_ptr&& other)
+ {
+ if (this != &other) {
+ _wx = other._wx;
+ other._wx = nullptr;
+ }
+ return *this;
+ }
+
+ ~wx_ptr()
+ {
+ if (_wx) {
+ _wx->Destroy();
+ }
+ }
+
+ T* operator->() {
+ return _wx;
+ }
+
+private:
+ T* _wx;
+};
+
+
+
+template <class T, typename... Args>
+wx_ptr<T>
+make_wx(Args... args)
+{
+ return wx_ptr<T>(new T(std::forward<Args>(args)...));
+}
+
+
+#endif
#include "password_entry.h"
#include "region_subtag_widget.h"
#include "static_text.h"
+#include "wx_ptr.h"
#include "wx_util.h"
#include "lib/config.h"
#include "lib/cross.h"
#include "lib/job.h"
#include "lib/job_manager.h"
-#include "lib/scope_guard.h"
#include "lib/util.h"
#include "lib/version.h"
#include <dcp/locale_convert.h>
void
error_dialog (wxWindow* parent, wxString m, optional<wxString> e)
{
- auto d = new wxMessageDialog (parent, m, _("DCP-o-matic"), wxOK | wxICON_ERROR);
- ScopeGuard sg = [d]() { d->Destroy(); };
+ auto d = make_wx<wxMessageDialog>(parent, m, _("DCP-o-matic"), wxOK | wxICON_ERROR);
if (e) {
wxString em = *e;
em[0] = wxToupper (em[0]);
void
message_dialog (wxWindow* parent, wxString m)
{
- auto d = new wxMessageDialog (parent, m, _("DCP-o-matic"), wxOK | wxICON_INFORMATION);
- ScopeGuard sg = [d]() { d->Destroy(); };
+ auto d = make_wx<wxMessageDialog>(parent, m, _("DCP-o-matic"), wxOK | wxICON_INFORMATION);
d->ShowModal ();
}
bool
confirm_dialog (wxWindow* parent, wxString m)
{
- auto d = new wxMessageDialog (parent, m, _("DCP-o-matic"), wxYES_NO | wxICON_QUESTION);
- ScopeGuard sg = [d]() { d->Destroy(); };
+ auto d = make_wx<wxMessageDialog>(parent, m, _("DCP-o-matic"), wxYES_NO | wxICON_QUESTION);
return d->ShowModal() == wxID_YES;
}