Try to improve the checking for overwrite of export files a little
authorCarl Hetherington <cth@carlh.net>
Sat, 30 Nov 2019 21:34:19 +0000 (22:34 +0100)
committerCarl Hetherington <cth@carlh.net>
Sat, 30 Nov 2019 21:34:19 +0000 (22:34 +0100)
on Linux; I think we need to do it ourselves rather than relying
on wxFileDialog.

src/tools/dcpomatic.cc
src/wx/export_dialog.cc
src/wx/file_picker_ctrl.cc
src/wx/file_picker_ctrl.h
src/wx/full_config_dialog.cc
src/wx/player_config_dialog.cc

index ae80a42da97c7e482d2bd926cdf3f63cc594f2af..4ddedab41651e374a7f5b3f025ecbc759ca397c6 100644 (file)
@@ -913,6 +913,18 @@ private:
        {
                ExportDialog* d = new ExportDialog (this, _film->isdcf_name(true));
                if (d->ShowModal() == wxID_OK) {
+                       if (boost::filesystem::exists(d->path())) {
+                               bool ok = confirm_dialog(
+                                               this,
+                                               wxString::Format (_("File %s already exists.  Do you want to overwrite it?"), std_to_wx(d->path().string()).data())
+                                               );
+
+                               if (!ok) {
+                                       d->Destroy ();
+                                       return;
+                               }
+                       }
+
                        shared_ptr<TranscodeJob> job (new TranscodeJob (_film));
                        if (d->format() == EXPORT_FORMAT_SUBTITLES_DCP) {
                                job->set_encoder (
index 65ce14092683b0a1496cbde9d384fdc9dbbf2d69..5fc4036feddfce2df9b14bb97692dee26a5cf7a7 100644 (file)
@@ -78,7 +78,12 @@ ExportDialog::ExportDialog (wxWindow* parent, string name)
        _x264_crf_label[1]->SetFont(font);
 
        add (_("Output file"), true);
-       _file = new FilePickerCtrl (this, _("Select output file"), format_filters[0], false);
+       /* Don't warn overwrite here, because on Linux (at least) if we specify a filename like foo
+          the wxFileDialog will check that foo exists, but we will add an extension so we actually
+          need to check if foo.mov (or similar) exists.  I can't find a way to make wxWidgets do this,
+          so disable its check and the caller will have to do it themselves.
+       */
+       _file = new FilePickerCtrl (this, _("Select output file"), format_filters[0], false, false);
        _file->SetPath (_initial_name);
        add (_file);
 
index 47b5dbca06a7e8ade9bb710d7de8076a2312c508..47211a269149b83815922b53e5a0005822e04bd2 100644 (file)
 using namespace std;
 using namespace boost;
 
-FilePickerCtrl::FilePickerCtrl (wxWindow* parent, wxString prompt, wxString wildcard, bool open)
+FilePickerCtrl::FilePickerCtrl (wxWindow* parent, wxString prompt, wxString wildcard, bool open, bool warn_overwrite)
        : wxPanel (parent)
        , _prompt (prompt)
        , _wildcard (wildcard)
        , _open (open)
+       , _warn_overwrite (warn_overwrite)
 {
        _sizer = new wxBoxSizer (wxHORIZONTAL);
 
@@ -72,7 +73,11 @@ FilePickerCtrl::GetPath () const
 void
 FilePickerCtrl::browse_clicked ()
 {
-       wxFileDialog* d = new wxFileDialog (this, _prompt, wxEmptyString, wxEmptyString, _wildcard, _open ? wxFD_OPEN : wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
+       long style = _open ? wxFD_OPEN : wxFD_SAVE;
+       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 ());
index d0c4d56c86f789ff50a8edb3856a1d370e1d8e16..b30288fa74826ec7d90994b037d1157d78fbfc0a 100644 (file)
@@ -23,7 +23,7 @@
 class FilePickerCtrl : public wxPanel
 {
 public:
-       FilePickerCtrl (wxWindow* parent, wxString prompt, wxString wildcard, bool open);
+       FilePickerCtrl (wxWindow* parent, wxString prompt, wxString wildcard, bool open, bool warn_overwrite);
 
        wxString GetPath () const;
        void SetPath (wxString);
@@ -38,4 +38,5 @@ private:
        wxString _prompt;
        wxString _wildcard;
        bool _open;
+       bool _warn_overwrite;
 };
index f6dd783bd9f5baaff64d40107c93cdd0a48b2426..1c5a9e3f668f3cb604683f54cd916a783f31e4d0 100644 (file)
@@ -105,12 +105,12 @@ private:
                ++r;
 
                add_label_to_sizer (table, _panel, _("Configuration file"), true, wxGBPosition (r, 0));
-               _config_file = new FilePickerCtrl (_panel, _("Select configuration file"), "*.xml", true);
+               _config_file = new FilePickerCtrl (_panel, _("Select configuration file"), "*.xml", true, true);
                table->Add (_config_file, wxGBPosition (r, 1));
                ++r;
 
                add_label_to_sizer (table, _panel, _("Cinema and screen database file"), true, wxGBPosition (r, 0));
-               _cinemas_file = new FilePickerCtrl (_panel, _("Select cinema and screen database file"), "*.xml", true);
+               _cinemas_file = new FilePickerCtrl (_panel, _("Select cinema and screen database file"), "*.xml", true, true);
                table->Add (_cinemas_file, wxGBPosition (r, 1));
                Button* export_cinemas = new Button (_panel, _("Export..."));
                table->Add (export_cinemas, wxGBPosition (r, 2));
index c1765eccb703d27de4f2954b2d8c484841d3d658..34eee2871cbca4d74d984ee468c17bf664e37ab6 100644 (file)
@@ -121,12 +121,12 @@ private:
                ++r;
 
                add_label_to_sizer (table, _panel, _("Activity log file"), true, wxGBPosition (r, 0));
-               _activity_log_file = new FilePickerCtrl (_panel, _("Select activity log file"), "*", true);
+               _activity_log_file = new FilePickerCtrl (_panel, _("Select activity log file"), "*", true, true);
                table->Add (_activity_log_file, wxGBPosition(r, 1));
                ++r;
 
                add_label_to_sizer (table, _panel, _("Debug log file"), true, wxGBPosition (r, 0));
-               _debug_log_file = new FilePickerCtrl (_panel, _("Select debug log file"), "*", true);
+               _debug_log_file = new FilePickerCtrl (_panel, _("Select debug log file"), "*", true, true);
                table->Add (_debug_log_file, wxGBPosition(r, 1));
                ++r;
 
@@ -137,7 +137,7 @@ private:
                ++r;
 
                add_label_to_sizer (table, _panel, _("Lock file"), true, wxGBPosition(r, 0));
-               _lock_file = new FilePickerCtrl (_panel, _("Select lock file"), "*", true);
+               _lock_file = new FilePickerCtrl (_panel, _("Select lock file"), "*", true, true);
                table->Add (_lock_file, wxGBPosition (r, 1));
                ++r;
 #endif