3e71cb11ad75c75345c8e7553cc9a1a6691d3376
[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
22 #ifndef DCPOMATIC_CONFIG_DIALOG_H
23 #define DCPOMATIC_CONFIG_DIALOG_H
24
25
26 #include "editable_list.h"
27 #include "make_chain_dialog.h"
28 #include "wx_util.h"
29 #include "lib/config.h"
30 #include "lib/cross.h"
31 #include "lib/dcp_content_type.h"
32 #include "lib/exceptions.h"
33 #include "lib/filter.h"
34 #include "lib/log.h"
35 #include "lib/ratio.h"
36 #include "lib/util.h"
37 #include <dcp/certificate_chain.h>
38 #include <dcp/exceptions.h>
39 #include <dcp/locale_convert.h>
40 #include <dcp/warnings.h>
41 LIBDCP_DISABLE_WARNINGS
42 #include <wx/filepicker.h>
43 #include <wx/preferences.h>
44 #include <wx/spinctrl.h>
45 #include <wx/stdpaths.h>
46 #include <RtAudio.h>
47 LIBDCP_ENABLE_WARNINGS
48 #include <boost/filesystem.hpp>
49
50
51 class AudioMappingView;
52
53
54 class Page : public wxPreferencesPage
55 {
56 public:
57         Page (wxSize panel_size, int border);
58         virtual ~Page () {}
59
60         wxWindow* CreateWindow (wxWindow* parent) override;
61
62 protected:
63         wxWindow* create_window (wxWindow* parent);
64
65         int _border;
66         wxPanel* _panel;
67
68 private:
69         virtual void config_changed () = 0;
70         virtual void setup () = 0;
71
72         void config_changed_wrapper ();
73         void window_destroyed ();
74
75         wxSize _panel_size;
76         boost::signals2::scoped_connection _config_connection;
77         bool _window_exists;
78 };
79
80
81 class GeneralPage : public Page
82 {
83 public:
84         GeneralPage (wxSize panel_size, int border);
85
86         wxString GetName () const override;
87
88 #ifdef DCPOMATIC_OSX
89         wxBitmap GetLargeIcon () const override
90         {
91                 return wxBitmap(bitmap_path("general"), wxBITMAP_TYPE_PNG);
92         }
93 #endif
94
95 protected:
96         void add_language_controls (wxGridBagSizer* table, int& r);
97         void add_update_controls (wxGridBagSizer* table, int& r);
98         void config_changed () override;
99
100 private:
101         void setup_sensitivity ();
102         void set_language_changed ();
103         void language_changed ();
104         void check_for_updates_changed ();
105         void check_for_test_updates_changed ();
106
107         wxCheckBox* _set_language;
108         wxChoice* _language;
109         wxCheckBox* _check_for_updates;
110         wxCheckBox* _check_for_test_updates;
111 };
112
113
114 class CertificateChainEditor : public wxDialog
115 {
116 public:
117         CertificateChainEditor (
118                 wxWindow* parent,
119                 wxString title,
120                 int border,
121                 std::function<void (std::shared_ptr<dcp::CertificateChain>)> set,
122                 std::function<std::shared_ptr<const dcp::CertificateChain> (void)> get,
123                 std::function<bool (void)> nag_alter
124                 );
125
126         void add_button (wxWindow* button);
127
128 private:
129         void add_certificate ();
130         void remove_certificate ();
131         void export_certificate ();
132         void update_certificate_list ();
133         void remake_certificates ();
134         void update_sensitivity ();
135         void update_private_key ();
136         void import_private_key ();
137         void export_private_key ();
138         void export_chain ();
139
140         wxListCtrl* _certificates;
141         wxButton* _add_certificate;
142         wxButton* _export_certificate;
143         wxButton* _remove_certificate;
144         wxButton* _remake_certificates;
145         wxStaticText* _private_key;
146         wxButton* _import_private_key;
147         wxButton* _export_private_key;
148         wxButton* _export_chain;
149         wxStaticText* _private_key_bad;
150         wxSizer* _sizer;
151         wxBoxSizer* _button_sizer;
152         std::function<void (std::shared_ptr<dcp::CertificateChain>)> _set;
153         std::function<std::shared_ptr<const dcp::CertificateChain> (void)> _get;
154         std::function<bool (void)> _nag_alter;
155 };
156
157 class KeysPage : public Page
158 {
159 public:
160         KeysPage (wxSize panel_size, int border)
161                 : Page (panel_size, border)
162         {}
163
164         wxString GetName () const override;
165
166 #ifdef DCPOMATIC_OSX
167         wxBitmap GetLargeIcon () const override
168         {
169                 return wxBitmap(bitmap_path("keys"), wxBITMAP_TYPE_PNG);
170         }
171 #endif
172
173 private:
174
175         void setup () override;
176
177         void export_decryption_certificate ();
178         void config_changed () override {}
179         bool nag_alter_decryption_chain ();
180         void decryption_advanced ();
181         void signing_advanced ();
182         void export_decryption_chain_and_key ();
183         void import_decryption_chain_and_key ();
184         void remake_signing ();
185 };
186
187
188 class SoundPage : public Page
189 {
190 public:
191         SoundPage (wxSize panel_size, int border)
192                 : Page (panel_size, border)
193         {}
194
195         wxString GetName() const override;
196
197 #ifdef DCPOMATIC_OSX
198         wxBitmap GetLargeIcon () const override
199         {
200                 return wxBitmap(bitmap_path("sound"), wxBITMAP_TYPE_PNG);
201         }
202 #endif
203
204 private:
205
206         void setup () override;
207         void config_changed () override;
208         boost::optional<std::string> get_sound_output ();
209         void sound_changed ();
210         void sound_output_changed ();
211         void setup_sensitivity ();
212         void map_changed (AudioMapping m);
213         void reset_to_default ();
214
215         wxCheckBox* _sound;
216         wxChoice* _sound_output;
217         wxStaticText* _sound_output_details;
218         AudioMappingView* _map;
219         Button* _reset_to_default;
220 };
221
222
223 class LocationsPage : public Page
224 {
225 public:
226         LocationsPage (wxSize panel_size, int border);
227
228         wxString GetName () const override;
229
230 #ifdef DCPOMATIC_OSX
231         wxBitmap GetLargeIcon () const override;
232 #endif
233
234 private:
235         void setup () override;
236         void config_changed () override;
237         void content_directory_changed ();
238         void playlist_directory_changed ();
239         void kdm_directory_changed ();
240
241         wxDirPickerCtrl* _content_directory;
242         wxDirPickerCtrl* _playlist_directory;
243         wxDirPickerCtrl* _kdm_directory;
244 };
245
246 #endif