Change bitmap_path to take a full name with extension.
[dcpomatic.git] / src / wx / config_dialog.h
index a72879407af03b9661ad0240fcd762fad14ef537..c767929f75f76fc9558bade2ca846b890e3e3620 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2017 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
 
 */
 
+
 #ifndef DCPOMATIC_CONFIG_DIALOG_H
 #define DCPOMATIC_CONFIG_DIALOG_H
 
-#include "wx_util.h"
+
 #include "editable_list.h"
+#include "make_chain_dialog.h"
+#include "wx_util.h"
 #include "lib/config.h"
-#include "lib/ratio.h"
-#include "lib/filter.h"
+#include "lib/cross.h"
 #include "lib/dcp_content_type.h"
+#include "lib/exceptions.h"
+#include "lib/filter.h"
 #include "lib/log.h"
+#include "lib/ratio.h"
 #include "lib/util.h"
-#include "lib/cross.h"
-#include "lib/exceptions.h"
-#include <dcp/locale_convert.h>
-#include <dcp/exceptions.h>
 #include <dcp/certificate_chain.h>
-#include <wx/stdpaths.h>
+#include <dcp/exceptions.h>
+#include <dcp/locale_convert.h>
+#include <dcp/warnings.h>
+LIBDCP_DISABLE_WARNINGS
+#include <wx/filepicker.h>
 #include <wx/preferences.h>
 #include <wx/spinctrl.h>
-#include <wx/filepicker.h>
+#include <wx/stdpaths.h>
 #include <RtAudio.h>
+LIBDCP_ENABLE_WARNINGS
 #include <boost/filesystem.hpp>
-#include <boost/foreach.hpp>
-#include <iostream>
 
-class Page
-{
-public:
-       Page (wxSize panel_size, int border)
-               : _border (border)
-               , _panel (0)
-               , _panel_size (panel_size)
-               , _window_exists (false)
-       {
-               _config_connection = Config::instance()->Changed.connect (boost::bind (&Page::config_changed_wrapper, this));
-       }
 
-       virtual ~Page () {}
+class AudioMappingView;
 
-protected:
-       wxWindow* create_window (wxWindow* parent)
-       {
-               _panel = new wxPanel (parent, wxID_ANY, wxDefaultPosition, _panel_size);
-               wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
-               _panel->SetSizer (s);
 
-               setup ();
-               _window_exists = true;
-               config_changed ();
+class Page : public wxPreferencesPage
+{
+public:
+       Page (wxSize panel_size, int border);
+       virtual ~Page () {}
 
-               _panel->Bind (wxEVT_DESTROY, boost::bind (&Page::window_destroyed, this));
+       wxWindow* CreateWindow (wxWindow* parent) override;
 
-               return _panel;
-       }
+protected:
+       wxWindow* create_window (wxWindow* parent);
 
        int _border;
        wxPanel* _panel;
@@ -80,267 +69,178 @@ private:
        virtual void config_changed () = 0;
        virtual void setup () = 0;
 
-       void config_changed_wrapper ()
-       {
-               if (_window_exists) {
-                       config_changed ();
-               }
-       }
-
-       void window_destroyed ()
-       {
-               _window_exists = false;
-       }
+       void config_changed_wrapper ();
+       void window_destroyed ();
 
        wxSize _panel_size;
        boost::signals2::scoped_connection _config_connection;
        bool _window_exists;
 };
 
-class StockPage : public wxStockPreferencesPage, public Page
+
+class GeneralPage : public Page
 {
 public:
-       StockPage (Kind kind, wxSize panel_size, int border)
-               : wxStockPreferencesPage (kind)
-               , Page (panel_size, border)
-       {}
+       GeneralPage (wxSize panel_size, int border);
 
-       wxWindow* CreateWindow (wxWindow* parent)
+       wxString GetName () const override;
+
+#ifdef DCPOMATIC_OSX
+       wxBitmap GetLargeIcon () const override
        {
-               return create_window (parent);
+               return wxBitmap(bitmap_path("general.png"), wxBITMAP_TYPE_PNG);
        }
+#endif
+
+protected:
+       void add_language_controls (wxGridBagSizer* table, int& r);
+       void add_update_controls (wxGridBagSizer* table, int& r);
+       void config_changed () override;
+
+private:
+       void setup_sensitivity ();
+       void set_language_changed ();
+       void language_changed ();
+       void check_for_updates_changed ();
+       void check_for_test_updates_changed ();
+
+       wxCheckBox* _set_language;
+       wxChoice* _language;
+       wxCheckBox* _check_for_updates;
+       wxCheckBox* _check_for_test_updates;
 };
 
-class StandardPage : public wxPreferencesPage, public Page
+
+class CertificateChainEditor : public wxDialog
 {
 public:
-       StandardPage (wxSize panel_size, int border)
-               : Page (panel_size, border)
-       {}
+       CertificateChainEditor (
+               wxWindow* parent,
+               wxString title,
+               int border,
+               std::function<void (std::shared_ptr<dcp::CertificateChain>)> set,
+               std::function<std::shared_ptr<const dcp::CertificateChain> (void)> get,
+               std::function<bool (void)> nag_alter
+               );
 
-       wxWindow* CreateWindow (wxWindow* parent)
-       {
-               return create_window (parent);
-       }
+       void add_button (wxWindow* button);
+
+private:
+       void add_certificate ();
+       void remove_certificate ();
+       void export_certificate ();
+       void update_certificate_list ();
+       void remake_certificates ();
+       void update_sensitivity ();
+       void update_private_key ();
+       void import_private_key ();
+       void export_private_key ();
+       void export_chain ();
+
+       wxListCtrl* _certificates;
+       wxButton* _add_certificate;
+       wxButton* _export_certificate;
+       wxButton* _remove_certificate;
+       wxButton* _remake_certificates;
+       wxStaticText* _private_key;
+       wxButton* _import_private_key;
+       wxButton* _export_private_key;
+       wxButton* _export_chain;
+       wxStaticText* _private_key_bad;
+       wxSizer* _sizer;
+       wxBoxSizer* _button_sizer;
+       std::function<void (std::shared_ptr<dcp::CertificateChain>)> _set;
+       std::function<std::shared_ptr<const dcp::CertificateChain> (void)> _get;
+       std::function<bool (void)> _nag_alter;
 };
 
-class GeneralPage : public StockPage
+class KeysPage : public Page
 {
 public:
-       GeneralPage (wxSize panel_size, int border)
-               : StockPage (Kind_General, panel_size, border)
+       KeysPage (wxSize panel_size, int border)
+               : Page (panel_size, border)
        {}
 
-protected:
-       void add_language_controls (wxGridBagSizer* table, int& r)
-       {
-               _set_language = new wxCheckBox (_panel, wxID_ANY, _("Set language"));
-               table->Add (_set_language, wxGBPosition (r, 0));
-               _language = new wxChoice (_panel, wxID_ANY);
-               std::vector<std::pair<std::string, std::string> > languages;
-               languages.push_back (std::make_pair ("Čeština", "cs_CZ"));
-               languages.push_back (std::make_pair ("汉语/漢語", "zh_CN"));
-               languages.push_back (std::make_pair ("Dansk", "da_DK"));
-               languages.push_back (std::make_pair ("Deutsch", "de_DE"));
-               languages.push_back (std::make_pair ("English", "en_GB"));
-               languages.push_back (std::make_pair ("Español", "es_ES"));
-               languages.push_back (std::make_pair ("Français", "fr_FR"));
-               languages.push_back (std::make_pair ("Italiano", "it_IT"));
-               languages.push_back (std::make_pair ("Nederlands", "nl_NL"));
-               languages.push_back (std::make_pair ("Русский", "ru_RU"));
-               languages.push_back (std::make_pair ("Polski", "pl_PL"));
-               languages.push_back (std::make_pair ("Português europeu", "pt_PT"));
-               languages.push_back (std::make_pair ("Português do Brasil", "pt_BR"));
-               languages.push_back (std::make_pair ("Svenska", "sv_SE"));
-               languages.push_back (std::make_pair ("Slovenský jazyk", "sk_SK"));
-               languages.push_back (std::make_pair ("українська мова", "uk_UA"));
-               checked_set (_language, languages);
-               table->Add (_language, wxGBPosition (r, 1));
-               ++r;
-
-               wxStaticText* restart = add_label_to_sizer (
-                       table, _panel, _("(restart DCP-o-matic to see language changes)"), false, wxGBPosition (r, 0), wxGBSpan (1, 2)
-                       );
-               wxFont font = restart->GetFont();
-               font.SetStyle (wxFONTSTYLE_ITALIC);
-               font.SetPointSize (font.GetPointSize() - 1);
-               restart->SetFont (font);
-               ++r;
-
-               _set_language->Bind (wxEVT_CHECKBOX, boost::bind (&GeneralPage::set_language_changed, this));
-               _language->Bind     (wxEVT_CHOICE,   boost::bind (&GeneralPage::language_changed,     this));
-       }
+       wxString GetName () const override;
 
-       void add_play_sound_controls (wxGridBagSizer* table, int& r)
+#ifdef DCPOMATIC_OSX
+       wxBitmap GetLargeIcon () const override
        {
-               _sound = new wxCheckBox (_panel, wxID_ANY, _("Play sound via"));
-               table->Add (_sound, wxGBPosition (r, 0));
-                _sound_output = new wxChoice (_panel, wxID_ANY);
-                table->Add (_sound_output, wxGBPosition (r, 1));
-                ++r;
-
-                RtAudio audio (DCPOMATIC_RTAUDIO_API);
-                for (unsigned int i = 0; i < audio.getDeviceCount(); ++i) {
-                        RtAudio::DeviceInfo dev = audio.getDeviceInfo (i);
-                        if (dev.probed && dev.outputChannels > 0) {
-                                _sound_output->Append (std_to_wx (dev.name));
-                        }
-                }
-
-               _sound->Bind        (wxEVT_CHECKBOX, boost::bind (&GeneralPage::sound_changed, this));
-               _sound_output->Bind (wxEVT_CHOICE,   boost::bind (&GeneralPage::sound_output_changed, this));
-       }
-
-       void add_update_controls (wxGridBagSizer* table, int& r)
-       {
-               _check_for_updates = new wxCheckBox (_panel, wxID_ANY, _("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"));
-               table->Add (_check_for_test_updates, wxGBPosition (r, 0), wxGBSpan (1, 2));
-               ++r;
-
-               _check_for_updates->Bind (wxEVT_CHECKBOX, boost::bind (&GeneralPage::check_for_updates_changed, this));
-               _check_for_test_updates->Bind (wxEVT_CHECKBOX, boost::bind (&GeneralPage::check_for_test_updates_changed, this));
-       }
-
-       virtual void config_changed ()
-       {
-               Config* config = Config::instance ();
-
-               checked_set (_set_language, static_cast<bool>(config->language()));
-
-               /* Backwards compatibility of config file */
-
-               std::map<std::string, std::string> compat_map;
-               compat_map["fr"] = "fr_FR";
-               compat_map["it"] = "it_IT";
-               compat_map["es"] = "es_ES";
-               compat_map["sv"] = "sv_SE";
-               compat_map["de"] = "de_DE";
-               compat_map["nl"] = "nl_NL";
-               compat_map["ru"] = "ru_RU";
-               compat_map["pl"] = "pl_PL";
-               compat_map["da"] = "da_DK";
-               compat_map["pt"] = "pt_PT";
-               compat_map["sk"] = "sk_SK";
-               compat_map["cs"] = "cs_CZ";
-               compat_map["uk"] = "uk_UA";
-
-               std::string lang = config->language().get_value_or ("en_GB");
-               if (compat_map.find (lang) != compat_map.end ()) {
-                       lang = compat_map[lang];
-               }
-
-               checked_set (_language, lang);
-
-               checked_set (_check_for_updates, config->check_for_updates ());
-               checked_set (_check_for_test_updates, config->check_for_test_updates ());
-
-               checked_set (_sound, config->sound ());
-
-               boost::optional<std::string> const current_so = get_sound_output ();
-                boost::optional<std::string> configured_so;
-
-                if (config->sound_output()) {
-                        configured_so = config->sound_output().get();
-                } else {
-                        /* No configured output means we should use the default */
-                        RtAudio audio (DCPOMATIC_RTAUDIO_API);
-                       try {
-                               configured_so = audio.getDeviceInfo(audio.getDefaultOutputDevice()).name;
-                       } catch (RtAudioError& e) {
-                               /* Probably no audio devices at all */
-                       }
-                }
-
-                if (configured_so && current_so != configured_so) {
-                        /* Update _sound_output with the configured value */
-                        unsigned int i = 0;
-                        while (i < _sound_output->GetCount()) {
-                                if (_sound_output->GetString(i) == std_to_wx(*configured_so)) {
-                                        _sound_output->SetSelection (i);
-                                        break;
-                                }
-                                ++i;
-                        }
-                }
-
-               setup_sensitivity ();
+               return wxBitmap(bitmap_path("keys.png"), wxBITMAP_TYPE_PNG);
        }
+#endif
 
 private:
-       void setup_sensitivity ()
-       {
-               _language->Enable (_set_language->GetValue ());
-               _check_for_test_updates->Enable (_check_for_updates->GetValue ());
-               _sound_output->Enable (_sound->GetValue ());
-       }
 
-        /** @return Currently-selected preview sound output in the dialogue */
-        boost::optional<std::string> get_sound_output ()
-        {
-                int const sel = _sound_output->GetSelection ();
-                if (sel == wxNOT_FOUND) {
-                        return boost::optional<std::string> ();
-                }
+       void setup () override;
 
-                return wx_to_std (_sound_output->GetString (sel));
-        }
+       void export_decryption_certificate ();
+       void config_changed () override {}
+       bool nag_alter_decryption_chain ();
+       void decryption_advanced ();
+       void signing_advanced ();
+       void export_decryption_chain_and_key ();
+       void import_decryption_chain_and_key ();
+       void remake_signing ();
+};
 
-       void set_language_changed ()
-       {
-               setup_sensitivity ();
-               if (_set_language->GetValue ()) {
-                       language_changed ();
-               } else {
-                       Config::instance()->unset_language ();
-               }
-       }
 
-       void language_changed ()
-       {
-               int const sel = _language->GetSelection ();
-               if (sel != -1) {
-                       Config::instance()->set_language (string_client_data (_language->GetClientObject (sel)));
-               } else {
-                       Config::instance()->unset_language ();
-               }
-       }
+class SoundPage : public Page
+{
+public:
+       SoundPage (wxSize panel_size, int border)
+               : Page (panel_size, border)
+       {}
 
-       void check_for_updates_changed ()
-       {
-               Config::instance()->set_check_for_updates (_check_for_updates->GetValue ());
-       }
+       wxString GetName() const override;
 
-       void check_for_test_updates_changed ()
+#ifdef DCPOMATIC_OSX
+       wxBitmap GetLargeIcon () const override
        {
-               Config::instance()->set_check_for_test_updates (_check_for_test_updates->GetValue ());
+               return wxBitmap(bitmap_path("sound.png"), wxBITMAP_TYPE_PNG);
        }
+#endif
 
-       void sound_changed ()
-       {
-               Config::instance()->set_sound (_sound->GetValue ());
-       }
+private:
 
-        void sound_output_changed ()
-        {
-                RtAudio audio (DCPOMATIC_RTAUDIO_API);
-               boost::optional<std::string> const so = get_sound_output();
-                if (!so || *so == audio.getDeviceInfo(audio.getDefaultOutputDevice()).name) {
-                        Config::instance()->unset_sound_output ();
-                } else {
-                        Config::instance()->set_sound_output (*so);
-                }
-        }
+       void setup () override;
+       void config_changed () override;
+        boost::optional<std::string> get_sound_output ();
+       void sound_changed ();
+       void sound_output_changed ();
+       void setup_sensitivity ();
+       void map_changed (AudioMapping m);
+       void reset_to_default ();
 
-       wxCheckBox* _set_language;
-       wxChoice* _language;
        wxCheckBox* _sound;
        wxChoice* _sound_output;
-       wxCheckBox* _check_for_updates;
-       wxCheckBox* _check_for_test_updates;
+       wxStaticText* _sound_output_details;
+       AudioMappingView* _map;
+       Button* _reset_to_default;
+};
+
+
+class LocationsPage : public Page
+{
+public:
+       LocationsPage (wxSize panel_size, int border);
+
+       wxString GetName () const override;
+
+#ifdef DCPOMATIC_OSX
+       wxBitmap GetLargeIcon () const override;
+#endif
+
+private:
+       void setup () override;
+       void config_changed () override;
+       void content_directory_changed ();
+       void playlist_directory_changed ();
+       void kdm_directory_changed ();
+
+       wxDirPickerCtrl* _content_directory;
+       wxDirPickerCtrl* _playlist_directory;
+       wxDirPickerCtrl* _kdm_directory;
 };
 
 #endif