summaryrefslogtreecommitdiff
path: root/src/wx
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2023-01-13 13:57:28 +0100
committerCarl Hetherington <cth@carlh.net>2023-01-14 00:42:39 +0100
commitb7e65adf286ce20918797a06a910ededf8f07b7b (patch)
tree5ae7d4b521cedc75feef7b1a03b86b2e058795ad /src/wx
parente002d31ac51e80bb1d008c198b864dfcb2b30cb3 (diff)
Use more ScopeGuards.
Diffstat (limited to 'src/wx')
-rw-r--r--src/wx/config_dialog.cc167
-rw-r--r--src/wx/content_panel.cc9
-rw-r--r--src/wx/controls.cc7
-rw-r--r--src/wx/editable_list.h6
-rw-r--r--src/wx/language_tag_widget.cc3
-rw-r--r--src/wx/screen_dialog.cc10
-rw-r--r--src/wx/text_panel.cc3
7 files changed, 105 insertions, 100 deletions
diff --git a/src/wx/config_dialog.cc b/src/wx/config_dialog.cc
index 6403d7e12..bf7e295ee 100644
--- a/src/wx/config_dialog.cc
+++ b/src/wx/config_dialog.cc
@@ -368,6 +368,7 @@ void
CertificateChainEditor::add_certificate ()
{
auto d = new wxFileDialog (this, _("Select Certificate File"));
+ ScopeGuard sg = [d]() { d->Destroy(); };
if (d->ShowModal() == wxID_OK) {
try {
@@ -377,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;
}
@@ -406,8 +406,6 @@ CertificateChainEditor::add_certificate ()
}
}
- d->Destroy ();
-
update_sensitivity ();
}
@@ -456,26 +454,28 @@ CertificateChainEditor::export_certificate ()
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) {
++j;
}
- if (d->ShowModal () == wxID_OK) {
- 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);
- }
+ if (d->ShowModal() != wxID_OK) {
+ return;
+ }
- string const s = j->certificate (true);
- f.checked_write(s.c_str(), s.length());
+ 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
@@ -485,22 +485,23 @@ CertificateChainEditor::export_chain ()
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) {
- 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);
- }
+ if (d->ShowModal() != wxID_OK) {
+ return;
+ }
- auto const s = _get()->chain();
- f.checked_write (s.c_str(), s.length());
+ 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
@@ -546,14 +547,13 @@ CertificateChainEditor::remake_certificates ()
}
auto d = new MakeChainDialog (this, _get());
+ ScopeGuard sg = [d]() { d->Destroy(); };
if (d->ShowModal () == wxID_OK) {
_set (d->get());
update_certificate_list ();
update_private_key ();
}
-
- d->Destroy ();
}
void
@@ -575,6 +575,7 @@ void
CertificateChainEditor::import_private_key ()
{
auto d = new wxFileDialog (this, _("Select Key File"));
+ ScopeGuard sg = [d]() { d->Destroy(); };
if (d->ShowModal() == wxID_OK) {
try {
@@ -596,8 +597,6 @@ CertificateChainEditor::import_private_key ()
}
}
- d->Destroy ();
-
update_sensitivity ();
}
@@ -613,6 +612,7 @@ CertificateChainEditor::export_private_key ()
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()));
@@ -627,7 +627,6 @@ CertificateChainEditor::export_private_key ()
auto const s = _get()->key().get ();
f.checked_write(s.c_str(), s.length());
}
- d->Destroy ();
}
wxString
@@ -732,22 +731,23 @@ KeysPage::export_decryption_chain_and_key ()
_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) {
- boost::filesystem::path path (wx_to_std(d->GetPath()));
- dcp::File f(path, "w");
- if (!f) {
- throw OpenFileError (path, errno, OpenFileError::WRITE);
- }
+ if (d->ShowModal() != wxID_OK) {
+ return;
+ }
- 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());
+ 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
@@ -765,38 +765,40 @@ KeysPage::import_decryption_chain_and_key ()
auto d = new wxFileDialog (
_panel, _("Select File To Import"), wxEmptyString, wxEmptyString, wxT ("DOM files (*.dom)|*.dom")
);
+ ScopeGuard sg = [d]() { d->Destroy(); };
- if (d->ShowModal () == wxID_OK) {
- auto new_chain = make_shared<dcp::CertificateChain>();
+ if (d->ShowModal() != wxID_OK) {
+ return;
+ }
- dcp::File f(wx_to_std(d->GetPath()), "r");
- if (!f) {
- throw OpenFileError (f.path(), errno, OpenFileError::WRITE);
- }
+ auto new_chain = make_shared<dcp::CertificateChain>();
- 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 = "";
- }
- }
+ 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
@@ -827,22 +829,23 @@ KeysPage::export_decryption_certificate ()
_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) {
- 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);
- }
+ if (d->ShowModal() != wxID_OK) {
+ return;
+ }
- auto const s = Config::instance()->decryption_chain()->leaf().certificate (true);
- f.checked_write(s.c_str(), s.length());
+ 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
diff --git a/src/wx/content_panel.cc b/src/wx/content_panel.cc
index e035d1795..c18520c30 100644
--- a/src/wx/content_panel.cc
+++ b/src/wx/content_panel.cc
@@ -654,15 +654,12 @@ ContentPanel::add_folder(boost::filesystem::path folder)
auto ic = dynamic_pointer_cast<ImageContent> (i);
if (ic) {
auto e = new ImageSequenceDialog (_splitter);
- int const r = e->ShowModal();
- auto const frame_rate = e->frame_rate ();
- e->Destroy ();
+ ScopeGuard sg = [e]() { e->Destroy(); };
- if (r != wxID_OK) {
+ if (e->ShowModal() != wxID_OK) {
return;
}
-
- ic->set_video_frame_rate(_film, frame_rate);
+ ic->set_video_frame_rate(_film, e->frame_rate());
}
_film->examine_and_add_content (i);
diff --git a/src/wx/controls.cc b/src/wx/controls.cc
index f16b494c9..804b59dae 100644
--- a/src/wx/controls.cc
+++ b/src/wx/controls.cc
@@ -36,6 +36,7 @@
#include "lib/job.h"
#include "lib/job_manager.h"
#include "lib/player_video.h"
+#include "lib/scope_guard.h"
#include <dcp/cpl.h>
#include <dcp/dcp.h>
#include <dcp/reel.h>
@@ -381,10 +382,11 @@ void
Controls::timecode_clicked ()
{
auto dialog = new PlayheadToTimecodeDialog(this, _viewer.position(), _film->video_frame_rate());
+ ScopeGuard sg = [dialog]() { dialog->Destroy(); };
+
if (dialog->ShowModal() == wxID_OK) {
_viewer.seek(dialog->get(), true);
}
- dialog->Destroy ();
}
@@ -392,10 +394,11 @@ void
Controls::frame_number_clicked ()
{
auto dialog = new PlayheadToFrameDialog(this, _viewer.position(), _film->video_frame_rate());
+ ScopeGuard sg = [dialog]() { dialog->Destroy(); };
+
if (dialog->ShowModal() == wxID_OK) {
_viewer.seek(dialog->get(), true);
}
- dialog->Destroy ();
}
diff --git a/src/wx/editable_list.h b/src/wx/editable_list.h
index 902d1ccbb..f3a0dd957 100644
--- a/src/wx/editable_list.h
+++ b/src/wx/editable_list.h
@@ -25,6 +25,7 @@
#include "dcpomatic_button.h"
#include "wx_util.h"
+#include "lib/scope_guard.h"
#include <dcp/warnings.h>
LIBDCP_DISABLE_WARNINGS
#include <wx/listctrl.h>
@@ -233,6 +234,7 @@ private:
void add_clicked ()
{
S* dialog = new S (this);
+ ScopeGuard sg = [dialog]() { dialog->Destroy(); };
if (dialog->ShowModal() == wxID_OK) {
auto const v = dialog->get ();
@@ -244,8 +246,6 @@ private:
_set (all);
}
}
-
- dialog->Destroy ();
}
void edit_clicked ()
@@ -259,6 +259,7 @@ private:
DCPOMATIC_ASSERT (item >= 0 && item < int (all.size ()));
S* dialog = new S (this);
+ ScopeGuard sg = [dialog]() { dialog->Destroy(); };
dialog->set (all[item]);
if (dialog->ShowModal() == wxID_OK) {
auto const v = dialog->get ();
@@ -269,7 +270,6 @@ private:
all[item] = v.get ();
}
- dialog->Destroy ();
for (size_t i = 0; i < _columns.size(); ++i) {
_list->SetItem (item, i, std_to_wx (_column (all[item], i)));
diff --git a/src/wx/language_tag_widget.cc b/src/wx/language_tag_widget.cc
index 37b7f6209..f28046bd9 100644
--- a/src/wx/language_tag_widget.cc
+++ b/src/wx/language_tag_widget.cc
@@ -23,6 +23,7 @@
#include "language_tag_dialog.h"
#include "language_tag_widget.h"
#include "wx_util.h"
+#include "lib/scope_guard.h"
#include <dcp/warnings.h>
LIBDCP_DISABLE_WARNINGS
#include <wx/wx.h>
@@ -66,11 +67,11 @@ void
LanguageTagWidget::edit ()
{
auto d = new LanguageTagDialog(_parent, _tag.get_value_or(dcp::LanguageTag("en")));
+ ScopeGuard sg = [d]() { d->Destroy(); };
if (d->ShowModal() == wxID_OK) {
set(d->get());
Changed(d->get());
}
- d->Destroy ();
}
diff --git a/src/wx/screen_dialog.cc b/src/wx/screen_dialog.cc
index 1f1fc2fad..6d7fb4f03 100644
--- a/src/wx/screen_dialog.cc
+++ b/src/wx/screen_dialog.cc
@@ -272,12 +272,12 @@ ScreenDialog::get_recipient_from_file ()
void
ScreenDialog::download_recipient ()
{
- auto d = new DownloadCertificateDialog (this);
- if (d->ShowModal() == wxID_OK) {
- set_recipient (d->certificate());
- checked_set (_recipient_file, d->url());
+ auto dialog = new DownloadCertificateDialog (this);
+ ScopeGuard sg = [dialog]() { dialog->Destroy(); };
+ if (dialog->ShowModal() == wxID_OK) {
+ set_recipient(dialog->certificate());
+ checked_set(_recipient_file, dialog->url());
}
- d->Destroy ();
setup_sensitivity ();
}
diff --git a/src/wx/text_panel.cc b/src/wx/text_panel.cc
index 7e6557ba9..8e7d4434e 100644
--- a/src/wx/text_panel.cc
+++ b/src/wx/text_panel.cc
@@ -41,6 +41,7 @@
#include "lib/ffmpeg_content.h"
#include "lib/ffmpeg_subtitle_stream.h"
#include "lib/job_manager.h"
+#include "lib/scope_guard.h"
#include "lib/string_text_file_content.h"
#include "lib/string_text_file_decoder.h"
#include "lib/subtitle_analysis.h"
@@ -370,10 +371,10 @@ TextPanel::dcp_track_changed ()
if (_dcp_track->GetSelection() == int(_dcp_track->GetCount()) - 1) {
auto d = new DCPTextTrackDialog (this);
+ ScopeGuard sg = [d]() { d->Destroy(); };
if (d->ShowModal() == wxID_OK) {
track = d->get();
}
- d->Destroy ();
} else {
/* Find the DCPTextTrack that was selected */
for (auto i: _parent->film()->closed_caption_tracks()) {