Move locale_convert into libdcp.
[dcpomatic.git] / src / wx / config_dialog.cc
index a33099a42424934f9744fbfc723314ef1df72bb7..cb9f4669b8c7a0cfa7057b2606e7a73c9f10d969 100644 (file)
 #include "lib/dcp_content_type.h"
 #include "lib/log.h"
 #include "lib/util.h"
-#include "lib/raw_convert.h"
 #include "lib/cross.h"
 #include "lib/exceptions.h"
+#include <dcp/locale_convert.h>
 #include <dcp/exceptions.h>
 #include <dcp/certificate_chain.h>
-#include <dcp/raw_convert.h>
 #include <wx/stdpaths.h>
 #include <wx/preferences.h>
 #include <wx/spinctrl.h>
@@ -64,6 +63,7 @@ using boost::bind;
 using boost::shared_ptr;
 using boost::function;
 using boost::optional;
+using dcp::locale_convert;
 
 class Page
 {
@@ -517,7 +517,7 @@ private:
                _directory->SetPath (std_to_wx (config->default_directory_or (wx_to_std (wxStandardPaths::Get().GetDocumentsDir())).string ()));
                checked_set (_j2k_bandwidth, config->default_j2k_bandwidth() / 1000000);
                _j2k_bandwidth->SetRange (50, config->maximum_j2k_bandwidth() / 1000000);
-               checked_set (_dcp_audio_channels, raw_convert<string> (config->default_dcp_audio_channels()));
+               checked_set (_dcp_audio_channels, locale_convert<string> (config->default_dcp_audio_channels()));
                checked_set (_audio_delay, config->default_audio_delay ());
                checked_set (_standard, config->default_interop() ? 1 : 0);
        }
@@ -536,7 +536,9 @@ private:
        {
                int const s = _dcp_audio_channels->GetSelection ();
                if (s != wxNOT_FOUND) {
-                       Config::instance()->set_default_dcp_audio_channels (dcp::raw_convert<int> (string_client_data (_dcp_audio_channels->GetClientObject (s))));
+                       Config::instance()->set_default_dcp_audio_channels (
+                               locale_convert<int> (string_client_data (_dcp_audio_channels->GetClientObject (s)))
+                               );
                }
        }
 
@@ -732,7 +734,7 @@ public:
                ++r;
 
                _button_sizer = new wxBoxSizer (wxHORIZONTAL);
-               _remake_certificates = new wxButton (this, wxID_ANY, _("Re-make certificates and key..."));
+               _remake_certificates = new wxButton (this, wxID_ANY, _("Re-make certificates\nand key..."));
                _button_sizer->Add (_remake_certificates, 1, wxRIGHT, border);
                table->Add (_button_sizer, wxGBPosition (r, 0), wxGBSpan (1, 4));
                ++r;
@@ -760,7 +762,7 @@ public:
 
        void add_button (wxWindow* button)
        {
-               _button_sizer->Add (button);
+               _button_sizer->Add (button, 0, wxLEFT | wxRIGHT, DCPOMATIC_SIZER_X_GAP);
                _sizer->Layout ();
        }
 
@@ -1039,10 +1041,13 @@ private:
 
                _panel->GetSizer()->Add (_decryption);
 
-               _export_decryption_certificate = new wxButton (_decryption, wxID_ANY, _("Export DCP decryption certificate..."));
+               _export_decryption_certificate = new wxButton (_decryption, wxID_ANY, _("Export DCP decryption\ncertificate..."));
                _decryption->add_button (_export_decryption_certificate);
+               _export_decryption_chain = new wxButton (_decryption, wxID_ANY, _("Export DCP decryption\nchain..."));
+               _decryption->add_button (_export_decryption_chain);
 
                _export_decryption_certificate->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&KeysPage::export_decryption_certificate, this));
+               _export_decryption_chain->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&KeysPage::export_decryption_chain, this));
        }
 
        void export_decryption_certificate ()
@@ -1065,6 +1070,26 @@ private:
                d->Destroy ();
        }
 
+       void export_decryption_chain ()
+       {
+               wxFileDialog* d = new wxFileDialog (
+                       _panel, _("Select Chain File"), wxEmptyString, wxEmptyString, wxT ("PEM files (*.pem)|*.pem"),
+                       wxFD_SAVE | wxFD_OVERWRITE_PROMPT
+                       );
+
+               if (d->ShowModal () == wxID_OK) {
+                       FILE* f = fopen_boost (wx_to_std (d->GetPath ()), "w");
+                       if (!f) {
+                               throw OpenFileError (wx_to_std (d->GetPath ()));
+                       }
+
+                       string const s = Config::instance()->decryption_chain()->chain();
+                       fwrite (s.c_str(), 1, s.length(), f);
+                       fclose (f);
+               }
+               d->Destroy ();
+       }
+
        void config_changed ()
        {
                _signer->config_changed ();
@@ -1074,6 +1099,7 @@ private:
        CertificateChainEditor* _signer;
        CertificateChainEditor* _decryption;
        wxButton* _export_decryption_certificate;
+       wxButton* _export_decryption_chain;
 };
 
 class TMSPage : public StandardPage