From d9e6b138e84e7a8504075b8581cca4d0fabfbc40 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sat, 30 Nov 2019 22:34:19 +0100 Subject: [PATCH] Try to improve the checking for overwrite of export files a little on Linux; I think we need to do it ourselves rather than relying on wxFileDialog. --- src/tools/dcpomatic.cc | 12 ++++++++++++ src/wx/export_dialog.cc | 7 ++++++- src/wx/file_picker_ctrl.cc | 9 +++++++-- src/wx/file_picker_ctrl.h | 3 ++- src/wx/full_config_dialog.cc | 4 ++-- src/wx/player_config_dialog.cc | 6 +++--- 6 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/tools/dcpomatic.cc b/src/tools/dcpomatic.cc index ae80a42da..4ddedab41 100644 --- a/src/tools/dcpomatic.cc +++ b/src/tools/dcpomatic.cc @@ -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 job (new TranscodeJob (_film)); if (d->format() == EXPORT_FORMAT_SUBTITLES_DCP) { job->set_encoder ( diff --git a/src/wx/export_dialog.cc b/src/wx/export_dialog.cc index 65ce14092..5fc4036fe 100644 --- a/src/wx/export_dialog.cc +++ b/src/wx/export_dialog.cc @@ -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); diff --git a/src/wx/file_picker_ctrl.cc b/src/wx/file_picker_ctrl.cc index 47b5dbca0..47211a269 100644 --- a/src/wx/file_picker_ctrl.cc +++ b/src/wx/file_picker_ctrl.cc @@ -29,11 +29,12 @@ 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 ()); diff --git a/src/wx/file_picker_ctrl.h b/src/wx/file_picker_ctrl.h index d0c4d56c8..b30288fa7 100644 --- a/src/wx/file_picker_ctrl.h +++ b/src/wx/file_picker_ctrl.h @@ -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; }; diff --git a/src/wx/full_config_dialog.cc b/src/wx/full_config_dialog.cc index f6dd783bd..1c5a9e3f6 100644 --- a/src/wx/full_config_dialog.cc +++ b/src/wx/full_config_dialog.cc @@ -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)); diff --git a/src/wx/player_config_dialog.cc b/src/wx/player_config_dialog.cc index c1765eccb..34eee2871 100644 --- a/src/wx/player_config_dialog.cc +++ b/src/wx/player_config_dialog.cc @@ -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 -- 2.30.2