Use wx_ptr more.
authorCarl Hetherington <cth@carlh.net>
Mon, 16 Jan 2023 00:14:37 +0000 (01:14 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 16 Jan 2023 00:15:50 +0000 (01:15 +0100)
13 files changed:
src/tools/dcpomatic.cc
src/tools/dcpomatic_disk.cc
src/tools/dcpomatic_playlist.cc
src/wx/audio_mapping_view.cc
src/wx/audio_panel.cc
src/wx/audio_panel.h
src/wx/content_panel.cc
src/wx/content_panel.h
src/wx/dcp_panel.cc
src/wx/dcp_panel.h
src/wx/dir_picker_ctrl.cc
src/wx/kdm_cpl_panel.cc
src/wx/recipient_dialog.cc

index af4576fd5e2daeee848eebc2ed981e00e185c136..4ac804cc9f3dbddfef6474f1491fbdfcc1d7e1d6 100644 (file)
@@ -145,7 +145,7 @@ class FilmChangedClosingDialog
 public:
        explicit FilmChangedClosingDialog (string name)
        {
-               _dialog = new wxMessageDialog (
+               _dialog.reset(
                        nullptr,
                        wxString::Format(_("Save changes to film \"%s\" before closing?"), std_to_wx (name).data()),
                        /// TRANSLATORS: this is the heading for a dialog box, which tells the user that the current
@@ -159,21 +159,13 @@ public:
                        );
        }
 
-       ~FilmChangedClosingDialog ()
-       {
-               _dialog->Destroy ();
-       }
-
-       FilmChangedClosingDialog (FilmChangedClosingDialog const&) = delete;
-       FilmChangedClosingDialog& operator= (FilmChangedClosingDialog const&) = delete;
-
        int run ()
        {
                return _dialog->ShowModal ();
        }
 
 private:
-       wxMessageDialog* _dialog;
+       wx_ptr<wxMessageDialog> _dialog;
 };
 
 
@@ -182,7 +174,7 @@ class FilmChangedDuplicatingDialog
 public:
        explicit FilmChangedDuplicatingDialog (string name)
        {
-               _dialog = new wxMessageDialog (
+               _dialog.reset(
                        nullptr,
                        wxString::Format(_("Save changes to film \"%s\" before duplicating?"), std_to_wx (name).data()),
                        /// TRANSLATORS: this is the heading for a dialog box, which tells the user that the current
@@ -196,21 +188,13 @@ public:
                        );
        }
 
-       ~FilmChangedDuplicatingDialog ()
-       {
-               _dialog->Destroy ();
-       }
-
-       FilmChangedDuplicatingDialog (FilmChangedDuplicatingDialog const&) = delete;
-       FilmChangedDuplicatingDialog& operator= (FilmChangedDuplicatingDialog const&) = delete;
-
        int run ()
        {
                return _dialog->ShowModal ();
        }
 
 private:
-       wxMessageDialog* _dialog;
+       wx_ptr<wxMessageDialog> _dialog;
 };
 
 
@@ -532,10 +516,7 @@ public:
                _film_viewer.set_film(_film);
                _film_editor->set_film(_film);
                _controls->set_film (_film);
-               if (_video_waveform_dialog) {
-                       _video_waveform_dialog->Destroy ();
-                       _video_waveform_dialog = nullptr;
-               }
+               _video_waveform_dialog.reset();
                set_menu_sensitivity ();
                if (_film && _film->directory()) {
                        Config::instance()->add_to_history (_film->directory().get());
@@ -853,12 +834,7 @@ private:
                        return;
                }
 
-               if (_kdm_dialog) {
-                       _kdm_dialog->Destroy ();
-                       _kdm_dialog = 0;
-               }
-
-               _kdm_dialog = new KDMDialog (this, _film);
+               _kdm_dialog.reset(this, _film);
                _kdm_dialog->Show ();
        }
 
@@ -868,12 +844,7 @@ private:
                        return;
                }
 
-               if (_dkdm_dialog) {
-                       _dkdm_dialog->Destroy ();
-                       _dkdm_dialog = nullptr;
-               }
-
-               _dkdm_dialog = new DKDMDialog (this, _film);
+               _dkdm_dialog.reset(this, _film);
                _dkdm_dialog->Show ();
        }
 
@@ -1074,7 +1045,7 @@ private:
        void view_video_waveform ()
        {
                if (!_video_waveform_dialog) {
-                       _video_waveform_dialog = new VideoWaveformDialog (this, _film, _film_viewer);
+                       _video_waveform_dialog.reset(this, _film, _film_viewer);
                }
 
                _video_waveform_dialog->Show ();
@@ -1110,7 +1081,7 @@ private:
        void tools_manage_templates ()
        {
                if (!_templates_dialog) {
-                       _templates_dialog = new TemplatesDialog (this);
+                       _templates_dialog.reset(this);
                }
 
                _templates_dialog->Show ();
@@ -1575,14 +1546,14 @@ private:
        wxPanel* _right_panel;
        FilmViewer _film_viewer;
        StandardControls* _controls;
-       VideoWaveformDialog* _video_waveform_dialog = nullptr;
+       wx_ptr<VideoWaveformDialog> _video_waveform_dialog;
        SystemInformationDialog* _system_information_dialog = nullptr;
        HintsDialog* _hints_dialog = nullptr;
        ServersListDialog* _servers_list_dialog = nullptr;
        wxPreferencesEditor* _config_dialog = nullptr;
-       KDMDialog* _kdm_dialog = nullptr;
-       DKDMDialog* _dkdm_dialog = nullptr;
-       TemplatesDialog* _templates_dialog = nullptr;
+       wx_ptr<KDMDialog> _kdm_dialog;
+       wx_ptr<DKDMDialog> _dkdm_dialog;
+       wx_ptr<TemplatesDialog> _templates_dialog;
        wxMenu* _file_menu = nullptr;
        shared_ptr<Film> _film;
        int _history_items = 0;
index d3235c1bbc1d7c2ad7db1e189b574f6083d816bc..a6ae58c8d704f00c70a4d9f8a7d0f121ea829fba 100644 (file)
@@ -249,16 +249,14 @@ 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
                        );
 
-               bool const r = d->ShowModal() == wxID_YES;
-               d->Destroy ();
-               return r;
+               return d->ShowModal() == wxID_YES;
        }
 
 
@@ -311,22 +309,20 @@ private:
 
                if (!have_writer) {
 #if defined(DCPOMATIC_WINDOWS)
-                       auto m = new MessageDialog (
+                       auto m = make_wx<MessageDialog>(
                                this,
                                _("DCP-o-matic Disk Writer"),
                                _("Do you see a 'User Account Control' dialogue asking about dcpomatic2_disk_writer.exe?  If so, click 'Yes', then try again.")
                                );
                        m->ShowModal ();
-                       m->Destroy ();
                        return;
 #elif defined(DCPOMATIC_OSX)
-                       auto m = new MessageDialog (
+                       auto m = make_wx<MessageDialog>(
                                this,
                                _("DCP-o-matic Disk Writer"),
                                _("Did you install the DCP-o-matic Disk Writer.pkg from the .dmg?  Please check and try again.")
                                );
                        m->ShowModal ();
-                       m->Destroy ();
                        return;
 #else
                        LOG_DISK_NC ("Failed to ping writer");
@@ -336,9 +332,8 @@ private:
 
                auto const& drive = _drives[_drive->GetSelection()];
                if (drive.mounted()) {
-                       auto d = new TryUnmountDialog(this, drive.description());
+                       auto d = make_wx<TryUnmountDialog>(this, drive.description());
                        int const r = d->ShowModal ();
-                       d->Destroy ();
                        if (r != wxID_OK) {
                                return;
                        }
@@ -355,13 +350,12 @@ private:
                        /* The reply may have to wait for the user to authenticate, so let's wait a while */
                        auto reply = _nanomsg.receive (30000);
                        if (!reply || *reply != DISK_WRITER_OK) {
-                               auto * m = new MessageDialog (
+                               auto m = make_wx<MessageDialog>(
                                                this,
                                                _("DCP-o-matic Disk Writer"),
                                                wxString::Format(_("The drive %s could not be unmounted.\nClose any application that is using it, then try again."), std_to_wx(drive.description()))
                                                );
                                m->ShowModal ();
-                               m->Destroy ();
                                return;
                        }
                }
index 2bca4106b2f158adcf007973157e4798c582252f..4dc8aef2817fef78f2fc65f20f4d287067a961b6 100644 (file)
@@ -551,9 +551,8 @@ private:
 
        void help_about ()
        {
-               auto d = new AboutDialog (this);
+               auto d = make_wx<AboutDialog>(this);
                d->ShowModal ();
-               d->Destroy ();
        }
 
        void edit_preferences ()
index 8818deb63737ad54b9492bf450701d0b7b2db636..9c14f61e78f421bc54f867247daf62a2fd6ee27f 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "audio_gain_dialog.h"
 #include "audio_mapping_view.h"
+#include "wx_ptr.h"
 #include "wx_util.h"
 #include "lib/audio_mapping.h"
 #include "lib/maths_util.h"
@@ -550,13 +551,11 @@ AudioMappingView::set_gain_from_menu (double linear)
 void
 AudioMappingView::edit ()
 {
-       auto dialog = new AudioGainDialog (this, _menu_input, _menu_output, _map.get(_menu_input, _menu_output));
+       auto dialog = make_wx<AudioGainDialog>(this, _menu_input, _menu_output, _map.get(_menu_input, _menu_output));
        if (dialog->ShowModal() == wxID_OK) {
                _map.set (_menu_input, _menu_output, dialog->value ());
                map_values_changed ();
        }
-
-       dialog->Destroy ();
 }
 
 void
index f84c9d67f82b7902df5389eb8edc89e4f74c51be..81a445efbce029fa7bf51842bf0ac9eba3d4c8f5 100644 (file)
@@ -195,14 +195,6 @@ AudioPanel::add_to_grid ()
 }
 
 
-AudioPanel::~AudioPanel ()
-{
-       if (_audio_dialog) {
-               _audio_dialog->Destroy ();
-               _audio_dialog = nullptr;
-       }
-}
-
 void
 AudioPanel::film_changed (Film::Property property)
 {
@@ -424,17 +416,14 @@ AudioPanel::setup_sensitivity ()
 void
 AudioPanel::show_clicked ()
 {
-       if (_audio_dialog) {
-               _audio_dialog->Destroy ();
-               _audio_dialog = nullptr;
-       }
+       _audio_dialog.reset();
 
        auto ac = _parent->selected_audio ();
        if (ac.size() != 1) {
                return;
        }
 
-       _audio_dialog = new AudioDialog (this, _parent->film(), _parent->film_viewer(), ac.front());
+       _audio_dialog.reset(this, _parent->film(), _parent->film_viewer(), ac.front());
        _audio_dialog->Show ();
 }
 
@@ -533,10 +522,7 @@ void
 AudioPanel::set_film (shared_ptr<Film>)
 {
        /* We are changing film, so destroy any audio dialog for the old one */
-       if (_audio_dialog) {
-               _audio_dialog->Destroy ();
-               _audio_dialog = nullptr;
-       }
+       _audio_dialog.reset();
 }
 
 
index bd6e0163d5f24e736e93e3323c82e54ca2aa657d..5f03de42404811a37b210e685632abf0e044ffac 100644 (file)
@@ -39,7 +39,6 @@ class AudioPanel : public ContentSubPanel
 {
 public:
        explicit AudioPanel (ContentPanel *);
-       ~AudioPanel ();
 
        void create () override;
        void film_changed (Film::Property) override;
@@ -80,7 +79,7 @@ private:
        CheckBox* _use_same_fades_as_video;
        AudioMappingView* _mapping;
        wxStaticText* _description;
-       AudioDialog* _audio_dialog = nullptr;
+       wx_ptr<AudioDialog> _audio_dialog;
 
        boost::signals2::scoped_connection _mapping_connection;
        boost::signals2::scoped_connection _active_jobs_connection;
index 71f32068a7e87836f47f905ccd75f2b183d8f158..456dbcb56db8f1980f890dbfba07408ff482996c 100644 (file)
@@ -709,12 +709,7 @@ ContentPanel::timeline_clicked ()
                return;
        }
 
-       if (_timeline_dialog) {
-               _timeline_dialog->Destroy ();
-               _timeline_dialog = nullptr;
-       }
-
-       _timeline_dialog = new TimelineDialog (this, _film, _film_viewer);
+       _timeline_dialog.reset(this, _film, _film_viewer);
        _timeline_dialog->set_selection (selected());
        _timeline_dialog->Show ();
 }
index 8f25353b3c4167eec241dfa42d7f7a4979983d4b..88686067221253ea674bf66ef611727cbc101706 100644 (file)
@@ -133,7 +133,7 @@ private:
        EnumIndexedVector<TextPanel*, TextType> _text_panel;
        TimingPanel* _timing_panel;
        ContentMenu* _menu;
-       TimelineDialog* _timeline_dialog = nullptr;
+       wx_ptr<TimelineDialog> _timeline_dialog;
        wxNotebook* _parent;
        wxWindow* _last_selected_tab = nullptr;
 
index d8aa3ac460986acb4e096cdd2b73ac2c31531184..1b97a023d263b327202ffb69d8a6e45446b024e0 100644 (file)
@@ -327,12 +327,7 @@ DCPPanel::standard_changed ()
 void
 DCPPanel::markers_clicked ()
 {
-       if (_markers_dialog) {
-               _markers_dialog->Destroy ();
-               _markers_dialog = nullptr;
-       }
-
-       _markers_dialog = new MarkersDialog (_panel, _film, _viewer);
+       _markers_dialog.reset(_panel, _film, _viewer);
        _markers_dialog->Show();
 }
 
@@ -341,21 +336,11 @@ void
 DCPPanel::metadata_clicked ()
 {
        if (_film->interop()) {
-               if (_interop_metadata_dialog) {
-                       _interop_metadata_dialog->Destroy ();
-                       _interop_metadata_dialog = nullptr;
-               }
-
-               _interop_metadata_dialog = new InteropMetadataDialog (_panel, _film);
+               _interop_metadata_dialog.reset(_panel, _film);
                _interop_metadata_dialog->setup ();
                _interop_metadata_dialog->Show ();
        } else {
-               if (_smpte_metadata_dialog) {
-                       _smpte_metadata_dialog->Destroy ();
-                       _smpte_metadata_dialog = nullptr;
-               }
-
-               _smpte_metadata_dialog = new SMPTEMetadataDialog (_panel, _film);
+               _smpte_metadata_dialog.reset(_panel, _film);
                _smpte_metadata_dialog->setup ();
                _smpte_metadata_dialog->Show ();
        }
@@ -586,22 +571,10 @@ void
 DCPPanel::set_film (shared_ptr<Film> film)
 {
        /* We are changing film, so destroy any dialogs for the old one */
-       if (_audio_dialog) {
-               _audio_dialog->Destroy ();
-               _audio_dialog = nullptr;
-       }
-       if (_markers_dialog) {
-               _markers_dialog->Destroy ();
-               _markers_dialog = nullptr;
-       }
-       if (_interop_metadata_dialog) {
-               _interop_metadata_dialog->Destroy ();
-               _interop_metadata_dialog = nullptr;
-       }
-       if (_smpte_metadata_dialog) {
-               _smpte_metadata_dialog->Destroy ();
-               _smpte_metadata_dialog = nullptr;
-       }
+       _audio_dialog.reset();
+       _markers_dialog.reset();
+       _interop_metadata_dialog.reset();
+       _smpte_metadata_dialog.reset();
 
        _film = film;
 
@@ -979,13 +952,8 @@ DCPPanel::show_audio_clicked ()
                return;
        }
 
-       if (_audio_dialog) {
-               _audio_dialog->Destroy ();
-               _audio_dialog = nullptr;
-       }
-
-       auto d = new AudioDialog (_panel, _film, _viewer);
-       d->Show ();
+       _audio_dialog.reset(_panel, _film, _viewer);
+       _audio_dialog->Show();
 }
 
 
@@ -1039,11 +1007,10 @@ void
 DCPPanel::edit_audio_language_clicked ()
 {
        DCPOMATIC_ASSERT (_film->audio_language());
-       auto d = new LanguageTagDialog (_panel, *_film->audio_language());
+       auto d = make_wx<LanguageTagDialog>(_panel, *_film->audio_language());
        if (d->ShowModal() == wxID_OK) {
               _film->set_audio_language(d->get());
        }
-       d->Destroy ();
 }
 
 
index 7d7f0bd798d95164d0406c696f711e3d6bd0da9b..cd39f2d1ef11b5de46cbbea78b9524a50fb76e64 100644 (file)
@@ -19,6 +19,7 @@
 */
 
 
+#include "wx_ptr.h"
 #include "lib/config.h"
 #include "lib/film.h"
 
@@ -159,10 +160,10 @@ private:
        wxButton* _metadata;
        wxSizer* _audio_panel_sizer;
 
-       AudioDialog* _audio_dialog = nullptr;
-       MarkersDialog* _markers_dialog = nullptr;
-       InteropMetadataDialog* _interop_metadata_dialog = nullptr;
-       SMPTEMetadataDialog* _smpte_metadata_dialog = nullptr;
+       wx_ptr<AudioDialog> _audio_dialog;
+       wx_ptr<MarkersDialog> _markers_dialog;
+       wx_ptr<InteropMetadataDialog> _interop_metadata_dialog;
+       wx_ptr<SMPTEMetadataDialog> _smpte_metadata_dialog;
 
        std::shared_ptr<Film> _film;
        FilmViewer& _viewer;
index 6c8fdd1fc3e6b48c82505c7e4278b7c428156466..34e54532e10f7bc60e3904603661abce093014aa 100644 (file)
@@ -22,6 +22,7 @@
 #include "dcpomatic_button.h"
 #include "dir_picker_ctrl.h"
 #include "static_text.h"
+#include "wx_ptr.h"
 #include "wx_util.h"
 #include <dcp/warnings.h>
 LIBDCP_DISABLE_WARNINGS
@@ -83,9 +84,8 @@ DirPickerCtrl::GetPath () const
 void
 DirPickerCtrl::browse_clicked ()
 {
-       wxDirDialog* d = new wxDirDialog (this);
+       auto d = make_wx<wxDirDialog>(this);
        if (d->ShowModal () == wxID_OK) {
                SetPath (d->GetPath ());
        }
-       d->Destroy ();
 }
index b1bbc1cf01d6d711aef38f0665f6a146474d3be3..1ddaa90cf5097159251bec6f4e56caf05efd5091 100644 (file)
@@ -101,17 +101,14 @@ KDMCPLPanel::update_cpl_summary ()
 void
 KDMCPLPanel::cpl_browse_clicked ()
 {
-       wxFileDialog* d = new wxFileDialog (this, _("Select CPL XML file"), wxEmptyString, wxEmptyString, "*.xml");
+       auto d = make_wx<wxFileDialog>(this, _("Select CPL XML file"), wxEmptyString, wxEmptyString, "*.xml");
        if (d->ShowModal() == wxID_CANCEL) {
-               d->Destroy ();
                return;
        }
 
        boost::filesystem::path cpl_file (wx_to_std (d->GetPath ()));
        boost::filesystem::path dcp_dir = cpl_file.parent_path ();
 
-       d->Destroy ();
-
        try {
                /* XXX: hack alert */
                cxml::Document cpl_document ("CompositionPlaylist");
index 688dcafbdc15d304f3a3568938201ba656ada735..b685f884aab55fe5f993715ed0cafd0529893f2e 100644 (file)
@@ -188,11 +188,10 @@ RecipientDialog::load_recipient (boost::filesystem::path file)
 void
 RecipientDialog::get_recipient_from_file ()
 {
-       auto d = new wxFileDialog (this, _("Select Certificate File"));
+       auto d = make_wx<wxFileDialog>(this, _("Select Certificate File"));
        if (d->ShowModal () == wxID_OK) {
                load_recipient (boost::filesystem::path (wx_to_std (d->GetPath ())));
        }
-       d->Destroy ();
 
        setup_sensitivity ();
 }