Also use FileDialog for adding certificates to screens.
authorCarl Hetherington <cth@carlh.net>
Tue, 3 Jan 2023 19:56:54 +0000 (20:56 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 4 Jan 2023 09:25:10 +0000 (10:25 +0100)
src/lib/config.cc
src/wx/screen_dialog.cc

index 30e80b938658719b4e46ea05f04a57a84bcef268..5db5cf35fe3145f14bf1653bc2c416e0d63491b8 100644 (file)
@@ -188,6 +188,7 @@ Config::set_defaults ()
        _initial_paths.clear();
        _initial_paths["AddFilesPath"] = boost::none;
        _initial_paths["AddDKDMPath"] = boost::none;
+       _initial_paths["SelectCertificatePath"] = boost::none;
        _use_isdcf_name_by_default = true;
        _write_kdms_to_disk = true;
        _email_kdms = false;
index 716f9e9eb3db91dbdb16546a19447e0084e0558f..1f1fc2fad7ae746170dad7d2088c776e6a2d78fc 100644 (file)
 
 #include "dcpomatic_button.h"
 #include "download_certificate_dialog.h"
+#include "file_dialog.h"
 #include "screen_dialog.h"
 #include "static_text.h"
 #include "table_dialog.h"
 #include "wx_util.h"
 #include "lib/compose.hpp"
+#include "lib/scope_guard.h"
 #include "lib/util.h"
 #include <dcp/warnings.h>
 #include <dcp/exceptions.h>
@@ -34,14 +36,12 @@ LIBDCP_DISABLE_WARNINGS
 #include <wx/filepicker.h>
 #include <wx/validate.h>
 LIBDCP_ENABLE_WARNINGS
-#include <iostream>
 
 
 using std::string;
-using std::cout;
 using std::vector;
-using boost::optional;
 using boost::bind;
+using boost::optional;
 #if BOOST_VERSION >= 106100
 using namespace boost::placeholders;
 #endif
@@ -64,14 +64,17 @@ public:
 
        void load_certificate ()
        {
-               auto d = new wxFileDialog (this, _("Trusted Device certificate"));
-               if (d->ShowModal() == wxID_OK) {
-                       try {
-                               _certificate = dcp::Certificate(dcp::file_to_string(wx_to_std(d->GetPath())));
-                               _thumbprint->SetValue (std_to_wx(_certificate->thumbprint()));
-                       } catch (dcp::MiscError& e) {
-                               error_dialog(this, wxString::Format(_("Could not load certificate (%s)"), std_to_wx(e.what())));
-                       }
+               auto dialog = new FileDialog(this, _("Trusted Device certificate"), wxEmptyString, wxFD_DEFAULT_STYLE, "SelectCertificatePath");
+               ScopeGuard sg = [dialog]() { dialog->Destroy(); };
+               if (!dialog->show()) {
+                       return;
+               }
+
+               try {
+                       _certificate = dcp::Certificate(dcp::file_to_string(dialog->paths()[0]));
+                       _thumbprint->SetValue (std_to_wx(_certificate->thumbprint()));
+               } catch (dcp::MiscError& e) {
+                       error_dialog(this, wxString::Format(_("Could not load certificate (%s)"), std_to_wx(e.what())));
                }
        }
 
@@ -256,11 +259,11 @@ ScreenDialog::load_recipient (boost::filesystem::path file)
 void
 ScreenDialog::get_recipient_from_file ()
 {
-       auto d = new wxFileDialog (this, _("Select Certificate File"));
-       if (d->ShowModal() == wxID_OK) {
-               load_recipient (boost::filesystem::path(wx_to_std(d->GetPath())));
+       auto dialog = new FileDialog(this, _("Select Certificate File"), wxEmptyString, wxFD_DEFAULT_STYLE , "SelectCertificatePath");
+       ScopeGuard sg = [dialog]() { dialog->Destroy(); };
+       if (dialog->show()) {
+               load_recipient(dialog->paths()[0]);
        }
-       d->Destroy ();
 
        setup_sensitivity ();
 }