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