Merge branch 'v2.15.x' of ssh://main.carlh.net/home/carl/git/dcpomatic into v2.15.x
[dcpomatic.git] / src / wx / config_dialog.h
1 /*
2     Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #ifndef DCPOMATIC_CONFIG_DIALOG_H
22 #define DCPOMATIC_CONFIG_DIALOG_H
23
24 #include "wx_util.h"
25 #include "editable_list.h"
26 #include "make_chain_dialog.h"
27 #include "lib/config.h"
28 #include "lib/ratio.h"
29 #include "lib/filter.h"
30 #include "lib/dcp_content_type.h"
31 #include "lib/log.h"
32 #include "lib/util.h"
33 #include "lib/cross.h"
34 #include "lib/exceptions.h"
35 #include <dcp/locale_convert.h>
36 #include <dcp/exceptions.h>
37 #include <dcp/certificate_chain.h>
38 #include <wx/stdpaths.h>
39 #include <wx/preferences.h>
40 #include <wx/spinctrl.h>
41 #include <wx/filepicker.h>
42 #include <RtAudio.h>
43 #include <boost/filesystem.hpp>
44 #include <boost/foreach.hpp>
45 #include <iostream>
46
47 class Page
48 {
49 public:
50         Page (wxSize panel_size, int border);
51         virtual ~Page () {}
52
53 protected:
54         wxWindow* create_window (wxWindow* parent);
55
56         int _border;
57         wxPanel* _panel;
58
59 private:
60         virtual void config_changed () = 0;
61         virtual void setup () = 0;
62
63         void config_changed_wrapper ();
64         void window_destroyed ();
65
66         wxSize _panel_size;
67         boost::signals2::scoped_connection _config_connection;
68         bool _window_exists;
69 };
70
71 class StockPage : public wxStockPreferencesPage, public Page
72 {
73 public:
74         StockPage (Kind kind, wxSize panel_size, int border);
75         wxWindow* CreateWindow (wxWindow* parent);
76 };
77
78 class StandardPage : public wxPreferencesPage, public Page
79 {
80 public:
81         StandardPage (wxSize panel_size, int border);
82         wxWindow* CreateWindow (wxWindow* parent);
83 };
84
85 class GeneralPage : public StockPage
86 {
87 public:
88         GeneralPage (wxSize panel_size, int border);
89
90 protected:
91         void add_language_controls (wxGridBagSizer* table, int& r);
92         void add_play_sound_controls (wxGridBagSizer* table, int& r);
93         void add_update_controls (wxGridBagSizer* table, int& r);
94         virtual void config_changed ();
95
96 private:
97         void setup_sensitivity ();
98         boost::optional<std::string> get_sound_output ();
99         void set_language_changed ();
100         void language_changed ();
101         void check_for_updates_changed ();
102         void check_for_test_updates_changed ();
103         void sound_changed ();
104         void sound_output_changed ();
105
106         wxCheckBox* _set_language;
107         wxChoice* _language;
108         wxCheckBox* _sound;
109         wxChoice* _sound_output;
110         wxStaticText* _sound_output_details;
111         wxCheckBox* _check_for_updates;
112         wxCheckBox* _check_for_test_updates;
113 };
114
115 class CertificateChainEditor : public wxDialog
116 {
117 public:
118         CertificateChainEditor (
119                 wxWindow* parent,
120                 wxString title,
121                 int border,
122                 boost::function<void (boost::shared_ptr<dcp::CertificateChain>)> set,
123                 boost::function<boost::shared_ptr<const dcp::CertificateChain> (void)> get,
124                 boost::function<bool (void)> nag_alter
125                 );
126
127         void add_button (wxWindow* button);
128
129 private:
130         void add_certificate ();
131         void remove_certificate ();
132         void export_certificate ();
133         void update_certificate_list ();
134         void remake_certificates ();
135         void update_sensitivity ();
136         void update_private_key ();
137         void import_private_key ();
138         void export_private_key ();
139         void export_chain ();
140
141         wxListCtrl* _certificates;
142         wxButton* _add_certificate;
143         wxButton* _export_certificate;
144         wxButton* _remove_certificate;
145         wxButton* _remake_certificates;
146         wxStaticText* _private_key;
147         wxButton* _import_private_key;
148         wxButton* _export_private_key;
149         wxButton* _export_chain;
150         wxStaticText* _private_key_bad;
151         wxSizer* _sizer;
152         wxBoxSizer* _button_sizer;
153         boost::function<void (boost::shared_ptr<dcp::CertificateChain>)> _set;
154         boost::function<boost::shared_ptr<const dcp::CertificateChain> (void)> _get;
155         boost::function<bool (void)> _nag_alter;
156 };
157
158 class KeysPage : public StandardPage
159 {
160 public:
161         KeysPage (wxSize panel_size, int border)
162                 : StandardPage (panel_size, border)
163         {}
164
165         wxString GetName () const;
166
167 #ifdef DCPOMATIC_OSX
168         wxBitmap GetLargeIcon () const
169         {
170                 return wxBitmap ("keys", wxBITMAP_TYPE_PNG_RESOURCE);
171         }
172 #endif
173
174 private:
175
176         void setup ();
177
178         void export_decryption_certificate ();
179         void config_changed () {}
180         bool nag_alter_decryption_chain ();
181         void decryption_advanced ();
182         void signing_advanced ();
183         void export_decryption_chain_and_key ();
184         void import_decryption_chain_and_key ();
185 };
186
187
188 #endif