Use wx_ptr for the splash screen.
[dcpomatic.git] / src / tools / dcpomatic_player.cc
index 7a2ae67f4bec8ab1b5e45bf4adb4ab4b6cd1c12d..1808e86fe4d3da7fb450b12c2a7ec0a74166627c 100644 (file)
@@ -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"
@@ -56,6 +57,7 @@
 #include "lib/player.h"
 #include "lib/player_video.h"
 #include "lib/ratio.h"
+#include "lib/scope_guard.h"
 #include "lib/scoped_temporary.h"
 #include "lib/server.h"
 #include "lib/text_content.h"
@@ -616,7 +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);
+               auto c = make_wx<wxDirDialog>(this, _("Select DCP to open"), d, wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST);
 
                int r;
                while (true) {
@@ -633,16 +635,19 @@ private:
                        load_dcp (dcp);
                        Config::instance()->set_last_player_load_directory (dcp.parent_path());
                }
-
-               c->Destroy ();
        }
 
        void file_add_ov ()
        {
-               auto c = new wxDirDialog (
+               auto initial_dir = wxStandardPaths::Get().GetDocumentsDir();
+               if (Config::instance()->last_player_load_directory()) {
+                       initial_dir = std_to_wx(Config::instance()->last_player_load_directory()->string());
+               }
+
+               auto c = make_wx<wxDirDialog>(
                        this,
                        _("Select DCP to open as OV"),
-                       wxStandardPaths::Get().GetDocumentsDir(),
+                       initial_dir,
                        wxDEFAULT_DIALOG_STYLE | wxDD_DIR_MUST_EXIST
                        );
 
@@ -677,13 +682,12 @@ private:
                        }
                }
 
-               c->Destroy ();
                _info->triggered_update ();
        }
 
        void file_add_kdm ()
        {
-               auto d = new wxFileDialog (this, _("Select KDM"));
+               auto d = make_wx<wxFileDialog>(this, _("Select KDM"));
 
                if (d->ShowModal() == wxID_OK) {
                        DCPOMATIC_ASSERT (_film);
@@ -698,12 +702,10 @@ private:
                                }
                        } catch (exception& e) {
                                error_dialog (this, wxString::Format (_("Could not load KDM.")), std_to_wx(e.what()));
-                               d->Destroy ();
                                return;
                        }
                }
 
-               d->Destroy ();
                _info->triggered_update ();
        }
 
@@ -896,16 +898,14 @@ private:
                DCPOMATIC_ASSERT (dcp);
 
                auto job = make_shared<VerifyDCPJob>(dcp->directories());
-               auto progress = new VerifyDCPProgressDialog(this, _("DCP-o-matic Player"));
+               auto progress = make_wx<VerifyDCPProgressDialog>(this, _("DCP-o-matic Player"));
                bool const completed = progress->run (job);
-               progress->Destroy ();
                if (!completed) {
                        return;
                }
 
-               auto d = new VerifyDCPDialog (this, job);
+               auto d = make_wx<VerifyDCPDialog>(this, job);
                d->ShowModal ();
-               d->Destroy ();
        }
 
        void tools_check_for_updates ()
@@ -916,9 +916,8 @@ private:
 
        void tools_timing ()
        {
-               auto d = new TimerDisplay(this, _viewer.state_timer(), _viewer.gets());
+               auto d = make_wx<TimerDisplay>(this, _viewer.state_timer(), _viewer.gets());
                d->ShowModal ();
-               d->Destroy ();
        }
 
        void tools_system_information ()
@@ -932,18 +931,16 @@ private:
 
        void help_about ()
        {
-               auto d = new AboutDialog (this);
+               auto d = make_wx<AboutDialog>(this);
                d->ShowModal ();
-               d->Destroy ();
        }
 
        void help_report_a_problem ()
        {
-               auto d = new ReportProblemDialog (this);
+               auto d = make_wx<ReportProblemDialog>(this);
                if (d->ShowModal () == wxID_OK) {
                        d->report ();
                }
-               d->Destroy ();
        }
 
        void update_checker_state_changed ()
@@ -962,9 +959,8 @@ private:
                }
 
                if (uc->state() == UpdateChecker::State::YES) {
-                       auto dialog = new UpdateDialog (this, uc->stable (), uc->test ());
+                       auto dialog = make_wx<UpdateDialog>(this, uc->stable (), uc->test ());
                        dialog->ShowModal ();
-                       dialog->Destroy ();
                } else if (uc->state() == UpdateChecker::State::FAILED) {
                        error_dialog (this, _("The DCP-o-matic download server could not be contacted."));
                } else {
@@ -1166,7 +1162,7 @@ private:
 
        bool OnInit () override
        {
-               wxSplashScreen* splash = nullptr;
+               wx_ptr<wxSplashScreen> splash;
                try {
                        wxInitAllImageHandlers ();