Cleanup: use auto.
[dcpomatic.git] / src / wx / screen_dialog.cc
index af5e25f476ba19d1998f2561b7c909df439e9b51..bc39193fba395d790f11a95594e52c18e745a864 100644 (file)
 
 #include "dcpomatic_button.h"
 #include "download_certificate_dialog.h"
-#include "file_dialog_wrapper.h"
+#include "file_dialog.h"
 #include "screen_dialog.h"
 #include "static_text.h"
 #include "table_dialog.h"
+#include "wx_ptr.h"
 #include "wx_util.h"
 #include "lib/compose.hpp"
+#include "lib/scope_guard.h"
 #include "lib/util.h"
-#include "lib/warnings.h"
+#include <dcp/warnings.h>
 #include <dcp/exceptions.h>
 #include <dcp/certificate_chain.h>
-DCPOMATIC_DISABLE_WARNINGS
+LIBDCP_DISABLE_WARNINGS
 #include <wx/filepicker.h>
 #include <wx/validate.h>
-DCPOMATIC_ENABLE_WARNINGS
-#include <iostream>
+LIBDCP_ENABLE_WARNINGS
 
 
 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
@@ -65,14 +65,16 @@ 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 certficate (%s)"), std_to_wx(e.what())));
-                       }
+               auto dialog = make_wx<FileDialog>(this, _("Trusted Device certificate"), wxEmptyString, wxFD_DEFAULT_STYLE, "SelectCertificatePath");
+               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())));
                }
        }
 
@@ -152,8 +154,8 @@ ScreenDialog::ScreenDialog (
        ++r;
 
        add_label_to_sizer (_sizer, this, _("Filename"), true, wxGBPosition(r, 0));
-       _recipient_file = new wxStaticText (this, wxID_ANY, wxT(""));
        checked_set (_recipient_file, recipient_file.get_value_or(""));
+       _recipient_file = new wxStaticText(this, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(600, -1), wxST_ELLIPSIZE_MIDDLE | wxST_NO_AUTORESIZE);
        _sizer->Add (_recipient_file, wxGBPosition(r, 1), wxDefaultSpan, wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_Y_GAP);
        ++r;
 
@@ -179,7 +181,8 @@ ScreenDialog::ScreenDialog (
                [] (TrustedDevice const& d, int) {
                        return d.thumbprint();
                },
-               false
+               EditableListTitle::INVISIBLE,
+               EditableListButton::NEW | EditableListButton::EDIT | EditableListButton::REMOVE
                );
 
        _sizer->Add (_trusted_device_list, wxGBPosition (r, 0), wxGBSpan (1, 3), wxEXPAND);
@@ -191,7 +194,7 @@ ScreenDialog::ScreenDialog (
 
        overall_sizer->Add (_sizer, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
 
-       wxSizer* buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL);
+       auto buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL);
        if (buttons) {
                overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
        }
@@ -256,11 +259,10 @@ 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 = make_wx<FileDialog>(this, _("Select Certificate File"), wxEmptyString, wxFD_DEFAULT_STYLE , "SelectCertificatePath");
+       if (dialog->show()) {
+               load_recipient(dialog->paths()[0]);
        }
-       d->Destroy ();
 
        setup_sensitivity ();
 }
@@ -269,12 +271,11 @@ ScreenDialog::get_recipient_from_file ()
 void
 ScreenDialog::download_recipient ()
 {
-       auto d = new DownloadCertificateDialog (this);
-       if (d->ShowModal() == wxID_OK) {
-               set_recipient (d->certificate());
-               checked_set (_recipient_file, d->url());
+       auto dialog = make_wx<DownloadCertificateDialog>(this);
+       if (dialog->ShowModal() == wxID_OK) {
+               set_recipient(dialog->certificate());
+               checked_set(_recipient_file, dialog->url());
        }
-       d->Destroy ();
        setup_sensitivity ();
 }