1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
|
/*
Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
DCP-o-matic is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
DCP-o-matic is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
*/
#include "audio_backend.h"
#include "audio_mapping_view.h"
#include "certificate_chain_editor.h"
#include "check_box.h"
#include "config_dialog.h"
#include "config_move_dialog.h"
#include "dcpomatic_button.h"
#include "file_picker_ctrl.h"
#include "nag_dialog.h"
#include "static_text.h"
#include "wx_variant.h"
#include "lib/constants.h"
#include "lib/util.h"
#include <dcp/file.h>
#include <dcp/filesystem.h>
#include <fmt/format.h>
using std::function;
using std::make_pair;
using std::make_shared;
using std::map;
using std::pair;
using std::shared_ptr;
using std::string;
using std::vector;
using boost::bind;
using boost::optional;
#if BOOST_VERSION >= 106100
using namespace boost::placeholders;
#endif
using namespace dcpomatic::preferences;
Page::Page(wxSize panel_size, int border)
: _border(border)
, _panel(nullptr)
, _panel_size(panel_size)
, _window_exists(false)
{
_config_connection = Config::instance()->Changed.connect(bind(&Page::config_changed_wrapper, this));
}
wxWindow*
Page::CreateWindow(wxWindow* parent)
{
return create_window(parent);
}
wxWindow*
Page::create_window(wxWindow* parent)
{
_panel = new wxPanel(parent, wxID_ANY, wxDefaultPosition, _panel_size);
auto s = new wxBoxSizer(wxVERTICAL);
_panel->SetSizer(s);
setup();
_window_exists = true;
config_changed();
_panel->Bind(wxEVT_DESTROY, bind(&Page::window_destroyed, this));
return _panel;
}
void
Page::config_changed_wrapper()
{
if (_window_exists) {
config_changed();
}
}
void
Page::window_destroyed()
{
_window_exists = false;
}
GeneralPage::GeneralPage(wxSize panel_size, int border)
: Page(panel_size, border)
{
}
wxString
GeneralPage::GetName() const
{
return _("General");
}
void
GeneralPage::add_language_controls(wxGridBagSizer* table, int& r)
{
_set_language = new CheckBox(_panel, _("Set language"));
table->Add(_set_language, wxGBPosition(r, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
_language = new wxChoice(_panel, wxID_ANY);
vector<pair<string, string>> languages;
languages.push_back(make_pair("Čeština", "cs_CZ"));
languages.push_back(make_pair("汉语/漢語", "zh_CN"));
languages.push_back(make_pair("Dansk", "da_DK"));
languages.push_back(make_pair("Deutsch", "de_DE"));
languages.push_back(make_pair("English", "en_GB"));
languages.push_back(make_pair("Español", "es_ES"));
languages.push_back(make_pair("فارسی", "fa_IR"));
languages.push_back(make_pair("Français", "fr_FR"));
languages.push_back(make_pair("Italiano", "it_IT"));
languages.push_back(make_pair("Nederlands", "nl_NL"));
languages.push_back(make_pair("Русский", "ru_RU"));
languages.push_back(make_pair("Polski", "pl_PL"));
languages.push_back(make_pair("Português europeu", "pt_PT"));
languages.push_back(make_pair("Português do Brasil", "pt_BR"));
languages.push_back(make_pair("Svenska", "sv_SE"));
languages.push_back(make_pair("Slovenščina", "sl_SI"));
languages.push_back(make_pair("Slovenský jazyk", "sk_SK"));
// languages.push_back(make_pair("Türkçe", "tr_TR"));
languages.push_back(make_pair("українська мова", "uk_UA"));
languages.push_back(make_pair("Magyar nyelv", "hu_HU"));
checked_set(_language, languages);
table->Add(_language, wxGBPosition(r, 1));
++r;
auto restart = add_label_to_sizer(
table, _panel, variant::wx::insert_dcpomatic(_("(restart %s to see language changes)")), false, wxGBPosition(r, 0), wxGBSpan(1, 2)
);
wxFont font = restart->GetFont();
font.SetStyle(wxFONTSTYLE_ITALIC);
font.SetPointSize(font.GetPointSize() - 1);
restart->SetFont(font);
++r;
_set_language->bind(&GeneralPage::set_language_changed, this);
_language->Bind(wxEVT_CHOICE, bind(&GeneralPage::language_changed, this));
}
void
GeneralPage::add_config_file_controls(wxGridBagSizer* table, int& r)
{
add_label_to_sizer(table, _panel, _("Configuration file"), true, wxGBPosition(r, 0));
_config_file = new FilePickerCtrl(_panel, _("Select configuration file"), char_to_wx("*.xml"), true, false, "ConfigFilePath");
table->Add(_config_file, wxGBPosition(r, 1));
++r;
add_label_to_sizer(table, _panel, _("Cinema and screen database file"), true, wxGBPosition(r, 0));
_cinemas_file = new FilePickerCtrl(_panel, _("Select cinema and screen database file"), char_to_wx("*.sqlite3"), true, false, "CinemaDatabasePath");
table->Add(_cinemas_file, wxGBPosition(r, 1));
auto export_cinemas = new Button(_panel, _("Export..."));
table->Add(export_cinemas, wxGBPosition(r, 2));
++r;
export_cinemas->Bind(wxEVT_BUTTON, boost::bind(&GeneralPage::export_cinemas_file, this));
_config_file->Bind (wxEVT_FILEPICKER_CHANGED, boost::bind(&GeneralPage::config_file_changed, this));
_cinemas_file->Bind(wxEVT_FILEPICKER_CHANGED, boost::bind(&GeneralPage::cinemas_file_changed, this));
}
void
GeneralPage::config_file_changed()
{
auto config = Config::instance();
auto const new_file = _config_file->path();
if (!new_file || *new_file == config->config_read_file()) {
return;
}
bool copy_and_link = true;
if (dcp::filesystem::exists(*new_file)) {
ConfigMoveDialog dialog(_panel, *new_file);
if (dialog.ShowModal() == wxID_OK) {
copy_and_link = false;
}
}
if (copy_and_link) {
config->write();
if (new_file != config->config_read_file()) {
config->copy_and_link(*new_file);
}
} else {
config->link(*new_file);
}
}
void
GeneralPage::cinemas_file_changed()
{
if (auto path = _cinemas_file->path()) {
Config::instance()->set_cinemas_file(*path);
}
}
void
GeneralPage::export_cinemas_file()
{
wxFileDialog dialog(
_panel, _("Select Cinemas File"), wxEmptyString, wxEmptyString, char_to_wx("SQLite files (*.sqlite3)|*.sqlite3"),
wxFD_SAVE | wxFD_OVERWRITE_PROMPT
);
if (dialog.ShowModal() == wxID_OK) {
dcp::filesystem::copy_file(Config::instance()->cinemas_file(), wx_to_std(dialog.GetPath()), dcp::filesystem::CopyOptions::OVERWRITE_EXISTING);
}
}
void
GeneralPage::add_update_controls(wxGridBagSizer* table, int& r)
{
_check_for_updates = new CheckBox(_panel, _("Check for updates on startup"));
table->Add(_check_for_updates, wxGBPosition(r, 0), wxGBSpan(1, 2));
++r;
_check_for_test_updates = new CheckBox(_panel, _("Check for testing updates on startup"));
table->Add(_check_for_test_updates, wxGBPosition(r, 0), wxGBSpan(1, 2));
++r;
_check_for_updates->bind(&GeneralPage::check_for_updates_changed, this);
_check_for_test_updates->bind(&GeneralPage::check_for_test_updates_changed, this);
}
void
GeneralPage::config_changed()
{
auto config = Config::instance();
checked_set(_set_language, static_cast<bool>(config->language()));
/* Backwards compatibility of config file */
map<string, string> compat_map;
compat_map["fr"] = "fr_FR";
compat_map["it"] = "it_IT";
compat_map["es"] = "es_ES";
compat_map["sv"] = "sv_SE";
compat_map["de"] = "de_DE";
compat_map["nl"] = "nl_NL";
compat_map["ru"] = "ru_RU";
compat_map["pl"] = "pl_PL";
compat_map["da"] = "da_DK";
compat_map["pt"] = "pt_PT";
compat_map["sk"] = "sk_SK";
compat_map["cs"] = "cs_CZ";
compat_map["uk"] = "uk_UA";
auto lang = config->language().get_value_or("en_GB");
if (compat_map.find(lang) != compat_map.end()) {
lang = compat_map[lang];
}
checked_set(_language, lang);
checked_set(_config_file, config->config_read_file());
checked_set(_cinemas_file, config->cinemas_file());
checked_set(_check_for_updates, config->check_for_updates());
checked_set(_check_for_test_updates, config->check_for_test_updates());
setup_sensitivity();
}
void
GeneralPage::setup_sensitivity()
{
_language->Enable(_set_language->GetValue());
_check_for_test_updates->Enable(_check_for_updates->GetValue());
}
void
GeneralPage::set_language_changed()
{
setup_sensitivity();
if (_set_language->GetValue()) {
language_changed();
} else {
Config::instance()->unset_language();
}
}
void
GeneralPage::language_changed()
{
int const sel = _language->GetSelection();
if (sel != -1) {
Config::instance()->set_language(string_client_data(_language->GetClientObject(sel)));
} else {
Config::instance()->unset_language();
}
}
void
GeneralPage::check_for_updates_changed()
{
Config::instance()->set_check_for_updates(_check_for_updates->GetValue());
}
void
GeneralPage::check_for_test_updates_changed()
{
Config::instance()->set_check_for_test_updates(_check_for_test_updates->GetValue());
}
wxString
SoundPage::GetName() const
{
return _("Sound");
}
void
SoundPage::setup()
{
auto table = new wxGridBagSizer(DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
_panel->GetSizer()->Add(table, 1, wxALL | wxEXPAND, _border);
int r = 0;
_sound = new CheckBox(_panel, _("Play sound via"));
table->Add(_sound, wxGBPosition(r, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
wxBoxSizer* s = new wxBoxSizer(wxHORIZONTAL);
_sound_output = new wxChoice(_panel, wxID_ANY);
s->Add(_sound_output, 0);
_sound_output_details = new wxStaticText(_panel, wxID_ANY, {});
s->Add(_sound_output_details, 1, wxALIGN_CENTER_VERTICAL | wxLEFT, DCPOMATIC_SIZER_X_GAP);
table->Add(s, wxGBPosition(r, 1));
++r;
add_label_to_sizer(table, _panel, _("Mapping"), true, wxGBPosition(r, 0));
_map = new AudioMappingView(_panel, _("DCP"), _("DCP"), _("Output"), _("output"));
table->Add(_map, wxGBPosition(r, 1), wxDefaultSpan, wxEXPAND);
++r;
_reset_to_default = new Button(_panel, _("Reset to default"));
table->Add(_reset_to_default, wxGBPosition(r, 1));
++r;
wxFont font = _sound_output_details->GetFont();
font.SetStyle(wxFONTSTYLE_ITALIC);
font.SetPointSize(font.GetPointSize() - 1);
_sound_output_details->SetFont(font);
for (auto name: AudioBackend::instance()->output_device_names()) {
_sound_output->Append(std_to_wx(name));
}
_sound->bind(&SoundPage::sound_changed, this);
_sound_output->Bind(wxEVT_CHOICE, bind(&SoundPage::sound_output_changed, this));
_map->Changed.connect(bind(&SoundPage::map_changed, this, _1));
_reset_to_default->Bind(wxEVT_BUTTON, bind(&SoundPage::reset_to_default, this));
}
void
SoundPage::reset_to_default()
{
Config::instance()->set_audio_mapping_to_default();
}
void
SoundPage::map_changed(AudioMapping m)
{
Config::instance()->set_audio_mapping(m);
}
void
SoundPage::sound_changed()
{
Config::instance()->set_sound(_sound->GetValue());
}
void
SoundPage::sound_output_changed()
{
auto const so = get_sound_output();
auto default_device = AudioBackend::instance()->default_device_name();
if (!so || so == default_device) {
Config::instance()->unset_sound_output();
} else {
Config::instance()->set_sound_output(*so);
}
}
void
SoundPage::config_changed()
{
auto config = Config::instance();
checked_set(_sound, config->sound());
auto const current_so = get_sound_output();
optional<string> configured_so;
auto& audio = AudioBackend::instance()->rtaudio();
if (config->sound_output()) {
configured_so = config->sound_output().get();
} else {
/* No configured output means we should use the default */
configured_so = AudioBackend::instance()->default_device_name();
}
if (configured_so && current_so != configured_so) {
/* Update _sound_output with the configured value */
unsigned int i = 0;
while (i < _sound_output->GetCount()) {
if (_sound_output->GetString(i) == std_to_wx(*configured_so)) {
_sound_output->SetSelection(i);
break;
}
++i;
}
}
map<int, wxString> apis;
apis[RtAudio::MACOSX_CORE] = _("CoreAudio");
apis[RtAudio::WINDOWS_ASIO] = _("ASIO");
apis[RtAudio::WINDOWS_DS] = _("Direct Sound");
apis[RtAudio::WINDOWS_WASAPI] = _("WASAPI");
apis[RtAudio::UNIX_JACK] = _("JACK");
apis[RtAudio::LINUX_ALSA] = _("ALSA");
apis[RtAudio::LINUX_PULSE] = _("PulseAudio");
apis[RtAudio::LINUX_OSS] = _("OSS");
apis[RtAudio::RTAUDIO_DUMMY] = _("Dummy");
int const channels = configured_so ? AudioBackend::instance()->device_output_channels(*configured_so).get_value_or(0) : 0;
_sound_output_details->SetLabel(
wxString::Format(_("%d channels on %s"), channels, apis[audio.getCurrentApi()])
);
_map->set(Config::instance()->audio_mapping(channels));
vector<NamedChannel> input;
for (int i = 0; i < MAX_DCP_AUDIO_CHANNELS; ++i) {
input.push_back(NamedChannel(short_audio_channel_name(i), i));
}
_map->set_input_channels(input);
vector<NamedChannel> output;
for (int i = 0; i < channels; ++i) {
output.push_back(NamedChannel(fmt::to_string(i), i));
}
_map->set_output_channels(output);
setup_sensitivity();
}
void
SoundPage::setup_sensitivity()
{
_sound_output->Enable(_sound->GetValue());
}
/** @return Currently-selected preview sound output in the dialogue */
optional<string>
SoundPage::get_sound_output()
{
int const sel = _sound_output->GetSelection();
if (sel == wxNOT_FOUND) {
return {};
}
return wx_to_std(_sound_output->GetString(sel));
}
LocationsPage::LocationsPage(wxSize panel_size, int border)
: Page(panel_size, border)
{
}
wxString
LocationsPage::GetName() const
{
return _("Locations");
}
#ifdef DCPOMATIC_OSX
wxBitmap
LocationsPage::GetLargeIcon() const
{
return wxBitmap(icon_path("locations"), wxBITMAP_TYPE_PNG);
}
#endif
void
LocationsPage::setup()
{
int r = 0;
auto table = new wxGridBagSizer(DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
_panel->GetSizer()->Add(table, 1, wxALL | wxEXPAND, _border);
add_label_to_sizer(table, _panel, _("Content directory"), true, wxGBPosition(r, 0));
_content_directory = new wxDirPickerCtrl(_panel, wxID_ANY, wxEmptyString, char_to_wx(wxDirSelectorPromptStr), wxDefaultPosition, wxSize(300, -1));
table->Add(_content_directory, wxGBPosition(r, 1));
++r;
add_label_to_sizer(table, _panel, _("Playlist directory"), true, wxGBPosition(r, 0));
_playlist_directory = new wxDirPickerCtrl(_panel, wxID_ANY, wxEmptyString, char_to_wx(wxDirSelectorPromptStr), wxDefaultPosition, wxSize(300, -1));
table->Add(_playlist_directory, wxGBPosition(r, 1));
++r;
add_label_to_sizer(table, _panel, _("KDM directory"), true, wxGBPosition(r, 0));
_kdm_directory = new wxDirPickerCtrl(_panel, wxID_ANY, wxEmptyString, char_to_wx(wxDirSelectorPromptStr), wxDefaultPosition, wxSize(300, -1));
table->Add(_kdm_directory, wxGBPosition(r, 1));
++r;
_content_directory->Bind(wxEVT_DIRPICKER_CHANGED, bind(&LocationsPage::content_directory_changed, this));
_playlist_directory->Bind(wxEVT_DIRPICKER_CHANGED, bind(&LocationsPage::playlist_directory_changed, this));
_kdm_directory->Bind(wxEVT_DIRPICKER_CHANGED, bind(&LocationsPage::kdm_directory_changed, this));
}
void
LocationsPage::config_changed()
{
auto config = Config::instance();
if (config->player_content_directory()) {
checked_set(_content_directory, *config->player_content_directory());
}
if (config->player_playlist_directory()) {
checked_set(_playlist_directory, *config->player_playlist_directory());
}
if (config->player_kdm_directory()) {
checked_set(_kdm_directory, *config->player_kdm_directory());
}
}
void
LocationsPage::content_directory_changed()
{
Config::instance()->set_player_content_directory(wx_to_std(_content_directory->GetPath()));
}
void
LocationsPage::playlist_directory_changed()
{
Config::instance()->set_player_playlist_directory(wx_to_std(_playlist_directory->GetPath()));
}
void
LocationsPage::kdm_directory_changed()
{
Config::instance()->set_player_kdm_directory(wx_to_std(_kdm_directory->GetPath()));
}
|