More stack-allocated Dialog objects.
authorCarl Hetherington <cth@carlh.net>
Fri, 27 Jan 2023 12:41:49 +0000 (13:41 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 27 Jan 2023 12:41:49 +0000 (13:41 +0100)
src/tools/dcpomatic_editor.cc
src/wx/audio_panel.cc
src/wx/file_picker_ctrl.cc
src/wx/full_config_dialog.cc
src/wx/job_view.cc
src/wx/kdm_output_panel.cc
src/wx/language_tag_dialog.cc
src/wx/nag_dialog.cc
src/wx/templates_dialog.cc
src/wx/text_panel.cc
src/wx/video_panel.cc

index 8e306551f970bc6790606a6795cef8d52f59ba9f..663eb8e3b00a4d2917846471799a911fea7cd226 100644 (file)
@@ -362,12 +362,12 @@ private:
        void file_open ()
        {
                auto d = wxStandardPaths::Get().GetDocumentsDir();
-               auto c = new wxDirDialog (this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
+               wxDirDialog dialog(this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
 
                int r;
                while (true) {
-                       r = c->ShowModal ();
-                       if (r == wxID_OK && c->GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
+                       r = dialog.ShowModal();
+                       if (r == wxID_OK && dialog.GetPath() == wxStandardPaths::Get().GetDocumentsDir()) {
                                error_dialog (this, _("You did not select a folder.  Make sure that you select a folder before clicking Open."));
                        } else {
                                break;
@@ -375,11 +375,9 @@ private:
                }
 
                if (r == wxID_OK) {
-                       boost::filesystem::path const dcp (wx_to_std (c->GetPath ()));
+                       boost::filesystem::path const dcp(wx_to_std(dialog.GetPath()));
                        load_dcp (dcp);
                }
-
-               c->Destroy ();
        }
 
        void file_save ()
@@ -394,9 +392,8 @@ private:
 
        void help_about ()
        {
-               auto d = new AboutDialog (this);
-               d->ShowModal ();
-               d->Destroy ();
+               AboutDialog dialog(this);
+               dialog.ShowModal();
        }
 
        wxPanel* _overall_panel = nullptr;
index 81a445efbce029fa7bf51842bf0ac9eba3d4c8f5..9a90436696485f65a32aa32e4632ce0b099120ed 100644 (file)
@@ -304,18 +304,17 @@ AudioPanel::film_content_changed (int property)
 void
 AudioPanel::gain_calculate_button_clicked ()
 {
-       auto d = new GainCalculatorDialog (this);
-       auto const r = d->ShowModal ();
-       auto c = d->db_change();
+       GainCalculatorDialog dialog(this);
+       auto const r = dialog.ShowModal();
+       auto change = dialog.db_change();
 
-       if (r == wxID_CANCEL || !c) {
-               d->Destroy ();
+       if (r == wxID_CANCEL || !change) {
                return;
        }
 
        auto old_peak_dB = peak ();
        auto old_value = _gain->wrapped()->GetValue();
-       _gain->wrapped()->SetValue(old_value + *c);
+       _gain->wrapped()->SetValue(old_value + *change);
 
        /* This appears to be necessary, as the change is not signalled,
           I think.
@@ -328,8 +327,6 @@ AudioPanel::gain_calculate_button_clicked ()
                _gain->wrapped()->SetValue (old_value);
                _gain->view_changed ();
        }
-
-       d->Destroy ();
 }
 
 
index 284f7bc99336d93dd9ad80a5c6fbc3e4c181d04c..bf4877891a2344860c862f8d77599118e4341842 100644 (file)
@@ -83,12 +83,11 @@ FilePickerCtrl::browse_clicked ()
        if (_warn_overwrite) {
                style |= wxFD_OVERWRITE_PROMPT;
        }
-       wxFileDialog* d = new wxFileDialog (this, _prompt, wxEmptyString, wxEmptyString, _wildcard, style);
-       d->SetPath (_path);
-       if (d->ShowModal () == wxID_OK) {
-               SetPath (d->GetPath ());
+       wxFileDialog dialog(this, _prompt, wxEmptyString, wxEmptyString, _wildcard, style);
+       dialog.SetPath(_path);
+       if (dialog.ShowModal() == wxID_OK) {
+               SetPath(dialog.GetPath());
        }
-       d->Destroy ();
 }
 
 void
index f7ed2b5beef491fb6810a2b1bf043e4a584a023f..7aea87c73ddeb8438150e40e9578ace618e60d7c 100644 (file)
@@ -180,15 +180,14 @@ private:
 
        void export_cinemas_file ()
        {
-               auto d = new wxFileDialog (
+               wxFileDialog dialog(
                        _panel, _("Select Cinemas File"), wxEmptyString, wxEmptyString, wxT("XML files (*.xml)|*.xml"),
                        wxFD_SAVE | wxFD_OVERWRITE_PROMPT
                 );
 
-               if (d->ShowModal () == wxID_OK) {
-                       boost::filesystem::copy_file(Config::instance()->cinemas_file(), wx_to_std(d->GetPath()), boost::filesystem::copy_option::overwrite_if_exists);
+               if (dialog.ShowModal() == wxID_OK) {
+                       boost::filesystem::copy_file(Config::instance()->cinemas_file(), wx_to_std(dialog.GetPath()), boost::filesystem::copy_option::overwrite_if_exists);
                }
-               d->Destroy ();
        }
 
 #ifdef DCPOMATIC_HAVE_EBUR128_PATCHED_FFMPEG
@@ -222,11 +221,10 @@ private:
                }
                bool copy_and_link = true;
                if (boost::filesystem::exists(new_file)) {
-                       auto d = new ConfigMoveDialog (_panel, new_file);
-                       if (d->ShowModal() == wxID_OK) {
+                       ConfigMoveDialog dialog(_panel, new_file);
+                       if (dialog.ShowModal() == wxID_OK) {
                                copy_and_link = false;
                        }
-                       d->Destroy ();
                }
 
                if (copy_and_link) {
@@ -974,31 +972,31 @@ private:
 
        void send_test_email_clicked ()
        {
-               auto dialog = new SendTestEmailDialog(_panel);
-               auto result = dialog->ShowModal();
-               dialog->Destroy();
-               if (result == wxID_OK) {
-                       Emailer emailer(
-                               wx_to_std(dialog->from()),
-                               { wx_to_std(dialog->to()) },
-                               wx_to_std(_("DCP-o-matic test email")),
-                               wx_to_std(_("This is a test email from DCP-o-matic."))
-                               );
-                       auto config = Config::instance();
-                       try {
-                               emailer.send (config->mail_server(), config->mail_port(), config->mail_protocol(), config->mail_user(), config->mail_password());
-                       } catch (NetworkError& e) {
-                               error_dialog (_panel, std_to_wx(e.summary()), std_to_wx(e.detail().get_value_or("")));
-                               return;
-                       } catch (std::exception& e) {
-                               error_dialog (_panel, _("Test email sending failed."), std_to_wx(e.what()));
-                               return;
-                       } catch (...) {
-                               error_dialog (_panel, _("Test email sending failed."));
-                               return;
-                       }
-                       message_dialog (_panel, _("Test email sent."));
+               SendTestEmailDialog dialog(_panel);
+               if (dialog.ShowModal() != wxID_OK) {
+                       return;
+               }
+
+               Emailer emailer(
+                       wx_to_std(dialog.from()),
+                       { wx_to_std(dialog.to()) },
+                       wx_to_std(_("DCP-o-matic test email")),
+                       wx_to_std(_("This is a test email from DCP-o-matic."))
+                       );
+               auto config = Config::instance();
+               try {
+                       emailer.send(config->mail_server(), config->mail_port(), config->mail_protocol(), config->mail_user(), config->mail_password());
+               } catch (NetworkError& e) {
+                       error_dialog(_panel, std_to_wx(e.summary()), std_to_wx(e.detail().get_value_or("")));
+                       return;
+               } catch (std::exception& e) {
+                       error_dialog(_panel, _("Test email sending failed."), std_to_wx(e.what()));
+                       return;
+               } catch (...) {
+                       error_dialog(_panel, _("Test email sending failed."));
+                       return;
                }
+               message_dialog(_panel, _("Test email sent."));
        }
 
        wxTextCtrl* _server;
index 8dbe8765210de29e34f3ed9aa98274ba513e95ed..b98555e8a2b71f519c71c99a7e9a7f12801aa1df 100644 (file)
@@ -156,9 +156,8 @@ JobView::finished ()
        }
 
        if (_job->message()) {
-               auto d = new MessageDialog (_parent, std_to_wx(_job->name()), std_to_wx(_job->message().get()));
-               d->ShowModal ();
-               d->Destroy ();
+               MessageDialog dialog(_parent, std_to_wx(_job->name()), std_to_wx(_job->message().get()));
+               dialog.ShowModal();
        }
 
        if (_job->enable_notify() && _notify->GetValue()) {
index 96b97b1636be1acc06cf933dcc84cbc50531b201..e7374cff924dc582a5aae81da51d0df45b6ea77a 100644 (file)
@@ -197,12 +197,11 @@ KDMOutputPanel::setup_sensitivity ()
 void
 KDMOutputPanel::advanced_clicked ()
 {
-       auto d = new KDMAdvancedDialog (this, _forensic_mark_video, _forensic_mark_audio, _forensic_mark_audio_up_to);
-       d->ShowModal ();
-       _forensic_mark_video = d->forensic_mark_video ();
-       _forensic_mark_audio = d->forensic_mark_audio ();
-       _forensic_mark_audio_up_to = d->forensic_mark_audio_up_to ();
-       d->Destroy ();
+       KDMAdvancedDialog dialog(this, _forensic_mark_video, _forensic_mark_audio, _forensic_mark_audio_up_to);
+       dialog.ShowModal();
+       _forensic_mark_video = dialog.forensic_mark_video();
+       _forensic_mark_audio = dialog.forensic_mark_audio();
+       _forensic_mark_audio_up_to = dialog.forensic_mark_audio_up_to();
 }
 
 
@@ -343,10 +342,9 @@ KDMOutputPanel::directory () const
 void
 KDMOutputPanel::add_email_addresses_clicked ()
 {
-       auto dialog = new ExtraKDMEmailDialog (this, _extra_addresses);
-       if (dialog->ShowModal() == wxID_OK) {
-               _extra_addresses = dialog->get();
+       ExtraKDMEmailDialog dialog(this, _extra_addresses);
+       if (dialog.ShowModal() == wxID_OK) {
+               _extra_addresses = dialog.get();
        }
-       dialog->Destroy();
 }
 
index a3ad847d52b9c98d6bb375d3b69811f15ee47859..b472edab07d1a5fda88d417129b23189ebe5b833 100644 (file)
@@ -75,13 +75,11 @@ LanguageTagDialog::LanguageTagDialog (wxWindow* parent, dcp::LanguageTag tag)
 void
 LanguageTagDialog::add_language ()
 {
-       auto full = new FullLanguageTagDialog (GetParent());
-       auto r = full->ShowModal ();
-       if (r == wxID_OK) {
-               Config::instance()->add_custom_language (full->get());
-               set (full->get());
+       FullLanguageTagDialog full(GetParent());
+       if (full.ShowModal() == wxID_OK) {
+               Config::instance()->add_custom_language(full.get());
+               set(full.get());
        }
-       full->Destroy ();
 }
 
 
index 04c3ce8e90ccae9ed69fc8a63c898a03ff571668..b137b07d18668b11b7647cf991765b44aa126840 100644 (file)
@@ -79,9 +79,6 @@ NagDialog::maybe_nag (wxWindow* parent, Config::Nag nag, wxString message, bool
                return false;
        }
 
-       auto d = new NagDialog (parent, nag, message, can_cancel);
-       int const r = d->ShowModal();
-       d->Destroy ();
-
-       return r == wxID_CANCEL;
+       NagDialog dialog(parent, nag, message, can_cancel);
+       return dialog.ShowModal() == wxID_CANCEL;
 }
index 3336277b6051da1ce1f447e36c063cf36ddaebd3..145e4f2b97119d3557c7805705d3e4ce39265d99 100644 (file)
@@ -130,17 +130,18 @@ TemplatesDialog::rename_clicked ()
        li.m_mask = wxLIST_MASK_TEXT;
        _list->GetItem (li);
 
-       auto d = new RenameTemplateDialog (this);
-       d->set (li.m_text);
-       if (d->ShowModal() == wxID_OK) {
-               if (!d->get().IsEmpty()) {
-                       Config::instance()->rename_template (wx_to_std (li.m_text), wx_to_std (d->get ()));
-                       _list->SetItem (item, 0, d->get());
-               } else {
-                       error_dialog (this, _("Template names must not be empty."));
-               }
+       RenameTemplateDialog dialog(this);
+       dialog.set(li.m_text);
+       if (dialog.ShowModal() != wxID_OK) {
+               return;
+       }
+
+       if (!dialog.get().IsEmpty()) {
+               Config::instance()->rename_template(wx_to_std(li.m_text), wx_to_std(dialog.get()));
+               _list->SetItem(item, 0, dialog.get());
+       } else {
+               error_dialog (this, _("Template names must not be empty."));
        }
-       d->Destroy ();
 }
 
 
index ba6c07e76ca15d556a57a7c96e1445402390398b..630ca6944e3da2ced3b33b502cd0dd96427331c6 100644 (file)
@@ -781,11 +781,10 @@ TextPanel::appearance_dialog_clicked ()
        auto c = _parent->selected_text ();
        DCPOMATIC_ASSERT (c.size() == 1);
 
-       auto d = new SubtitleAppearanceDialog (this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type));
-       if (d->ShowModal () == wxID_OK) {
-               d->apply ();
+       SubtitleAppearanceDialog dialog(this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type));
+       if (dialog.ShowModal() == wxID_OK) {
+               dialog.apply();
        }
-       d->Destroy ();
 }
 
 
index e1770efbe8e44fbfd0540a6ca1548f02e75e6f89..4f7c2db791400d8038efed8ab81499e69d5b6061 100644 (file)
@@ -541,17 +541,16 @@ VideoPanel::edit_colour_conversion_clicked ()
 {
        auto vc = _parent->selected_video ();
 
-       auto d = new ContentColourConversionDialog (this, vc.front()->video->yuv ());
-       d->set (vc.front()->video->colour_conversion().get_value_or (PresetColourConversion::all().front().conversion));
-       if (d->ShowModal() == wxID_OK) {
+       ContentColourConversionDialog dialog(this, vc.front()->video->yuv());
+       dialog.set(vc.front()->video->colour_conversion().get_value_or(PresetColourConversion::all().front().conversion));
+       if (dialog.ShowModal() == wxID_OK) {
                for (auto i: vc) {
-                       i->video->set_colour_conversion (d->get ());
+                       i->video->set_colour_conversion(dialog.get());
                }
        } else {
                /* Reset the colour conversion choice */
                film_content_changed (VideoContentProperty::COLOUR_CONVERSION);
        }
-       d->Destroy ();
 }
 
 
@@ -725,16 +724,17 @@ bool
 VideoPanel::scale_custom_edit_clicked ()
 {
        auto vc = _parent->selected_video().front()->video;
-       auto d = new CustomScaleDialog (this, vc->size(), _parent->film()->frame_size(), vc->custom_ratio(), vc->custom_size());
-       int const r = d->ShowModal ();
-       if (r == wxID_OK) {
-               for (auto i: _parent->selected_video()) {
-                       i->video->set_custom_ratio (d->custom_ratio());
-                       i->video->set_custom_size (d->custom_size());
-               }
+       CustomScaleDialog dialog(this, vc->size(), _parent->film()->frame_size(), vc->custom_ratio(), vc->custom_size());
+       if (dialog.ShowModal() != wxID_OK) {
+               return false;
+       }
+
+       for (auto i: _parent->selected_video()) {
+               i->video->set_custom_ratio(dialog.custom_ratio());
+               i->video->set_custom_size(dialog.custom_size());
        }
-       d->Destroy ();
-       return r == wxID_OK;
+
+       return true;
 }