Basics of in-place i18n with support for wxStaticText and wxCheckBox.
[dcpomatic.git] / src / wx / config_dialog.cc
index 2f396ded0e969cb3675ac50ace51066675a936b8..1066a88b031ab5511e667329402459c492dc14c8 100644 (file)
@@ -19,6 +19,8 @@
 */
 
 #include "config_dialog.h"
+#include "static_text.h"
+#include "check_box.h"
 #include "nag_dialog.h"
 
 using std::string;
@@ -112,7 +114,7 @@ GeneralPage::GeneralPage (wxSize panel_size, int border)
 void
 GeneralPage::add_language_controls (wxGridBagSizer* table, int& r)
 {
-       _set_language = new wxCheckBox (_panel, wxID_ANY, _("Set language"));
+       _set_language = new CheckBox (_panel, _("Set language"));
        table->Add (_set_language, wxGBPosition (r, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
        _language = new wxChoice (_panel, wxID_ANY);
        vector<pair<string, string> > languages;
@@ -152,7 +154,7 @@ GeneralPage::add_language_controls (wxGridBagSizer* table, int& r)
 void
 GeneralPage::add_play_sound_controls (wxGridBagSizer* table, int& r)
 {
-       _sound = new wxCheckBox (_panel, wxID_ANY, _("Play sound via"));
+       _sound = new CheckBox (_panel, _("Play sound via"));
        table->Add (_sound, wxGBPosition (r, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
        _sound_output = new wxChoice (_panel, wxID_ANY);
        table->Add (_sound_output, wxGBPosition (r, 1));
@@ -173,11 +175,11 @@ GeneralPage::add_play_sound_controls (wxGridBagSizer* table, int& r)
 void
 GeneralPage::add_update_controls (wxGridBagSizer* table, int& r)
 {
-       _check_for_updates = new wxCheckBox (_panel, wxID_ANY, _("Check for updates on startup"));
+       _check_for_updates = new CheckBox (_panel, _("Check for updates on startup"));
        table->Add (_check_for_updates, wxGBPosition (r, 0), wxGBSpan (1, 2));
        ++r;
 
-       _check_for_test_updates = new wxCheckBox (_panel, wxID_ANY, _("Check for testing updates on startup"));
+       _check_for_test_updates = new CheckBox (_panel, _("Check for testing updates on startup"));
        table->Add (_check_for_test_updates, wxGBPosition (r, 0), wxGBSpan (1, 2));
        ++r;
 
@@ -342,7 +344,7 @@ CertificateChainEditor::CertificateChainEditor (
        _sizer = new wxBoxSizer (wxVERTICAL);
 
        {
-               wxStaticText* m = new wxStaticText (this, wxID_ANY, title);
+               wxStaticText* m = new StaticText (this, title);
                m->SetFont (subheading_font);
                _sizer->Add (m, 0, wxALL, border);
        }
@@ -391,7 +393,7 @@ CertificateChainEditor::CertificateChainEditor (
        int r = 0;
 
        add_label_to_sizer (table, this, _("Leaf private key"), true, wxGBPosition (r, 0));
-       _private_key = new wxStaticText (this, wxID_ANY, wxT (""));
+       _private_key = new StaticText (this, wxT(""));
        wxFont font = _private_key->GetFont ();
        font.SetFamily (wxFONTFAMILY_TELETYPE);
        _private_key->SetFont (font);
@@ -408,7 +410,7 @@ CertificateChainEditor::CertificateChainEditor (
        table->Add (_button_sizer, wxGBPosition (r, 0), wxGBSpan (1, 4));
        ++r;
 
-       _private_key_bad = new wxStaticText (this, wxID_ANY, _("Leaf private key does not match leaf certificate!"));
+       _private_key_bad = new StaticText (this, _("Leaf private key does not match leaf certificate!"));
        font = *wxSMALL_FONT;
        font.SetWeight (wxFONTWEIGHT_BOLD);
        _private_key_bad->SetFont (font);
@@ -515,7 +517,8 @@ CertificateChainEditor::export_certificate ()
        }
 
        wxFileDialog* d = new wxFileDialog (
-               this, _("Select Certificate File"), wxEmptyString, wxEmptyString, wxT ("PEM files (*.pem)|*.pem"), wxFD_SAVE
+               this, _("Select Certificate File"), wxEmptyString, wxEmptyString, wxT ("PEM files (*.pem)|*.pem"),
+               wxFD_SAVE | wxFD_OVERWRITE_PROMPT
                );
 
        dcp::CertificateChain::List all = _get()->root_to_leaf ();
@@ -525,17 +528,15 @@ CertificateChainEditor::export_certificate ()
        }
 
        if (d->ShowModal () == wxID_OK) {
-               optional<boost::filesystem::path> path = path_from_file_dialog (d, "pem");
-               if (path) {
-                       FILE* f = fopen_boost (*path, "w");
-                       if (!f) {
-                               throw OpenFileError (*path, errno, false);
-                       }
-
-                       string const s = j->certificate (true);
-                       fwrite (s.c_str(), 1, s.length(), f);
-                       fclose (f);
+               boost::filesystem::path path (wx_to_std(d->GetPath()));
+               FILE* f = fopen_boost (path, "w");
+               if (!f) {
+                       throw OpenFileError (path, errno, false);
                }
+
+               string const s = j->certificate (true);
+               fwrite (s.c_str(), 1, s.length(), f);
+               fclose (f);
        }
        d->Destroy ();
 }
@@ -695,21 +696,20 @@ CertificateChainEditor::export_private_key ()
        }
 
        wxFileDialog* d = new wxFileDialog (
-               this, _("Select Key File"), wxEmptyString, wxEmptyString, wxT ("PEM files (*.pem)|*.pem"), wxFD_SAVE
+               this, _("Select Key File"), wxEmptyString, wxEmptyString, wxT ("PEM files (*.pem)|*.pem"),
+               wxFD_SAVE | wxFD_OVERWRITE_PROMPT
                );
 
        if (d->ShowModal () == wxID_OK) {
-               optional<boost::filesystem::path> path = path_from_file_dialog (d, "pem");
-               if (path) {
-                       FILE* f = fopen_boost (*path, "w");
-                       if (!f) {
-                               throw OpenFileError (*path, errno, false);
-                       }
-
-                       string const s = _get()->key().get ();
-                       fwrite (s.c_str(), 1, s.length(), f);
-                       fclose (f);
+               boost::filesystem::path path (wx_to_std(d->GetPath()));
+               FILE* f = fopen_boost (path, "w");
+               if (!f) {
+                       throw OpenFileError (path, errno, false);
                }
+
+               string const s = _get()->key().get ();
+               fwrite (s.c_str(), 1, s.length(), f);
+               fclose (f);
        }
        d->Destroy ();
 }
@@ -729,7 +729,7 @@ KeysPage::setup ()
        wxSizer* sizer = _panel->GetSizer();
 
        {
-               wxStaticText* m = new wxStaticText (_panel, wxID_ANY, _("Decrypting KDMs"));
+               wxStaticText* m = new StaticText (_panel, _("Decrypting KDMs"));
                m->SetFont (subheading_font);
                sizer->Add (m, 0, wxALL, _border);
        }
@@ -752,7 +752,7 @@ KeysPage::setup ()
        decryption_advanced->Bind (wxEVT_BUTTON, bind (&KeysPage::decryption_advanced, this));
 
        {
-               wxStaticText* m = new wxStaticText (_panel, wxID_ANY, _("Signing DCPs and KDMs"));
+               wxStaticText* m = new StaticText (_panel, _("Signing DCPs and KDMs"));
                m->SetFont (subheading_font);
                sizer->Add (m, 0, wxALL, _border);
        }
@@ -792,24 +792,23 @@ void
 KeysPage::export_decryption_chain_and_key ()
 {
        wxFileDialog* d = new wxFileDialog (
-               _panel, _("Select Export File"), wxEmptyString, wxEmptyString, wxT ("DOM files (*.dom)|*.dom"), wxFD_SAVE
+               _panel, _("Select Export File"), wxEmptyString, wxEmptyString, wxT ("DOM files (*.dom)|*.dom"),
+               wxFD_SAVE | wxFD_OVERWRITE_PROMPT
                );
 
        if (d->ShowModal () == wxID_OK) {
-               optional<boost::filesystem::path> path = path_from_file_dialog (d, "dom");
-               if (path) {
-                       FILE* f = fopen_boost (*path, "w");
-                       if (!f) {
-                               throw OpenFileError (wx_to_std (d->GetPath ()), errno, false);
-                       }
-
-                       string const chain = Config::instance()->decryption_chain()->chain();
-                       fwrite (chain.c_str(), 1, chain.length(), f);
-                       optional<string> const key = Config::instance()->decryption_chain()->key();
-                       DCPOMATIC_ASSERT (key);
-                       fwrite (key->c_str(), 1, key->length(), f);
-                       fclose (f);
+               boost::filesystem::path path (wx_to_std(d->GetPath()));
+               FILE* f = fopen_boost (path, "w");
+               if (!f) {
+                       throw OpenFileError (path, errno, false);
                }
+
+               string const chain = Config::instance()->decryption_chain()->chain();
+               fwrite (chain.c_str(), 1, chain.length(), f);
+               optional<string> const key = Config::instance()->decryption_chain()->key();
+               DCPOMATIC_ASSERT (key);
+               fwrite (key->c_str(), 1, key->length(), f);
+               fclose (f);
        }
        d->Destroy ();
 
@@ -871,21 +870,20 @@ void
 KeysPage::export_decryption_chain ()
 {
        wxFileDialog* d = new wxFileDialog (
-               _panel, _("Select Chain File"), wxEmptyString, _("dcpomatic_kdm_decryption_chain.pem"), wxT ("PEM files (*.pem)|*.pem"), wxFD_SAVE
+               _panel, _("Select Chain File"), wxEmptyString, _("dcpomatic_kdm_decryption_chain.pem"), wxT ("PEM files (*.pem)|*.pem"),
+               wxFD_SAVE | wxFD_OVERWRITE_PROMPT
                );
 
        if (d->ShowModal () == wxID_OK) {
-               optional<boost::filesystem::path> path = path_from_file_dialog (d, "pem");
-               if (path) {
-                       FILE* f = fopen_boost (*path, "w");
-                       if (!f) {
-                               throw OpenFileError (*path, errno, false);
-                       }
-
-                       string const s = Config::instance()->decryption_chain()->chain();
-                       fwrite (s.c_str(), 1, s.length(), f);
-                       fclose (f);
+               boost::filesystem::path path (wx_to_std(d->GetPath()));
+               FILE* f = fopen_boost (path, "w");
+               if (!f) {
+                       throw OpenFileError (path, errno, false);
                }
+
+               string const s = Config::instance()->decryption_chain()->chain();
+               fwrite (s.c_str(), 1, s.length(), f);
+               fclose (f);
        }
        d->Destroy ();
 }
@@ -894,21 +892,20 @@ void
 KeysPage::export_decryption_certificate ()
 {
        wxFileDialog* d = new wxFileDialog (
-               _panel, _("Select Certificate File"), wxEmptyString, _("dcpomatic_kdm_decryption_cert.pem"), wxT ("PEM files (*.pem)|*.pem"), wxFD_SAVE
+               _panel, _("Select Certificate File"), wxEmptyString, _("dcpomatic_kdm_decryption_cert.pem"), wxT ("PEM files (*.pem)|*.pem"),
+               wxFD_SAVE | wxFD_OVERWRITE_PROMPT
                );
 
        if (d->ShowModal () == wxID_OK) {
-               optional<boost::filesystem::path> path = path_from_file_dialog (d, "pem");
-               if (path) {
-                       FILE* f = fopen_boost (*path, "w");
-                       if (!f) {
-                               throw OpenFileError (*path, errno, false);
-                       }
-
-                       string const s = Config::instance()->decryption_chain()->leaf().certificate (true);
-                       fwrite (s.c_str(), 1, s.length(), f);
-                       fclose (f);
+               boost::filesystem::path path (wx_to_std(d->GetPath()));
+               FILE* f = fopen_boost (path, "w");
+               if (!f) {
+                       throw OpenFileError (path, errno, false);
                }
+
+               string const s = Config::instance()->decryption_chain()->leaf().certificate (true);
+               fwrite (s.c_str(), 1, s.length(), f);
+               fclose (f);
        }
 
        d->Destroy ();