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