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