2 Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /** @file src/config_dialog.cc
21 * @brief A dialogue to edit DCP-o-matic configuration.
25 #include <boost/lexical_cast.hpp>
26 #include <boost/filesystem.hpp>
27 #include <wx/stdpaths.h>
28 #include <wx/preferences.h>
29 #include <wx/filepicker.h>
30 #include <wx/spinctrl.h>
31 #include <libdcp/colour_matrix.h>
32 #include "lib/config.h"
33 #include "lib/ratio.h"
34 #include "lib/scaler.h"
35 #include "lib/filter.h"
36 #include "lib/dcp_content_type.h"
37 #include "lib/colour_conversion.h"
38 #include "config_dialog.h"
40 #include "editable_list.h"
41 #include "filter_dialog.h"
42 #include "dir_picker_ctrl.h"
43 #include "dci_metadata_dialog.h"
44 #include "preset_colour_conversion_dialog.h"
45 #include "server_dialog.h"
52 using boost::shared_ptr;
53 using boost::lexical_cast;
55 class GeneralPage : public wxStockPreferencesPage
59 : wxStockPreferencesPage (Kind_General)
62 wxWindow* CreateWindow (wxWindow* parent)
64 wxPanel* panel = new wxPanel (parent);
65 wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
68 wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
69 table->AddGrowableCol (1, 1);
70 s->Add (table, 1, wxALL | wxEXPAND, 8);
72 _set_language = new wxCheckBox (panel, wxID_ANY, _("Set language"));
73 table->Add (_set_language, 1);
74 _language = new wxChoice (panel, wxID_ANY);
75 _language->Append (wxT ("English"));
76 _language->Append (wxT ("Français"));
77 _language->Append (wxT ("Italiano"));
78 _language->Append (wxT ("Español"));
79 _language->Append (wxT ("Svenska"));
80 _language->Append (wxT ("Deutsch"));
81 table->Add (_language);
83 wxStaticText* restart = add_label_to_sizer (table, panel, _("(restart DCP-o-matic to see language changes)"), false);
84 wxFont font = restart->GetFont();
85 font.SetStyle (wxFONTSTYLE_ITALIC);
86 font.SetPointSize (font.GetPointSize() - 1);
87 restart->SetFont (font);
90 add_label_to_sizer (table, panel, _("Threads to use for encoding on this host"), true);
91 _num_local_encoding_threads = new wxSpinCtrl (panel);
92 table->Add (_num_local_encoding_threads, 1);
94 add_label_to_sizer (table, panel, _("Outgoing mail server"), true);
95 _mail_server = new wxTextCtrl (panel, wxID_ANY);
96 table->Add (_mail_server, 1, wxEXPAND | wxALL);
98 add_label_to_sizer (table, panel, _("Mail user name"), true);
99 _mail_user = new wxTextCtrl (panel, wxID_ANY);
100 table->Add (_mail_user, 1, wxEXPAND | wxALL);
102 add_label_to_sizer (table, panel, _("Mail password"), true);
103 _mail_password = new wxTextCtrl (panel, wxID_ANY);
104 table->Add (_mail_password, 1, wxEXPAND | wxALL);
106 wxStaticText* plain = add_label_to_sizer (table, panel, _("(password will be stored on disk in plaintext)"), false);
107 plain->SetFont (font);
108 table->AddSpacer (0);
110 add_label_to_sizer (table, panel, _("From address for KDM emails"), true);
111 _kdm_from = new wxTextCtrl (panel, wxID_ANY);
112 table->Add (_kdm_from, 1, wxEXPAND | wxALL);
114 _check_for_updates = new wxCheckBox (panel, wxID_ANY, _("Check for updates on startup"));
115 table->Add (_check_for_updates, 1, wxEXPAND | wxALL);
116 table->AddSpacer (0);
118 _check_for_test_updates = new wxCheckBox (panel, wxID_ANY, _("Check for testing updates as well as stable ones"));
119 table->Add (_check_for_test_updates, 1, wxEXPAND | wxALL);
120 table->AddSpacer (0);
122 Config* config = Config::instance ();
124 _set_language->SetValue (config->language ());
126 if (config->language().get_value_or ("") == "fr") {
127 _language->SetSelection (1);
128 } else if (config->language().get_value_or ("") == "it") {
129 _language->SetSelection (2);
130 } else if (config->language().get_value_or ("") == "es") {
131 _language->SetSelection (3);
132 } else if (config->language().get_value_or ("") == "sv") {
133 _language->SetSelection (4);
134 } else if (config->language().get_value_or ("") == "de") {
135 _language->SetSelection (5);
137 _language->SetSelection (0);
140 setup_language_sensitivity ();
142 _set_language->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&GeneralPage::set_language_changed, this));
143 _language->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&GeneralPage::language_changed, this));
145 _num_local_encoding_threads->SetRange (1, 128);
146 _num_local_encoding_threads->SetValue (config->num_local_encoding_threads ());
147 _num_local_encoding_threads->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&GeneralPage::num_local_encoding_threads_changed, this));
149 _mail_server->SetValue (std_to_wx (config->mail_server ()));
150 _mail_server->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&GeneralPage::mail_server_changed, this));
151 _mail_user->SetValue (std_to_wx (config->mail_user ()));
152 _mail_user->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&GeneralPage::mail_user_changed, this));
153 _mail_password->SetValue (std_to_wx (config->mail_password ()));
154 _mail_password->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&GeneralPage::mail_password_changed, this));
155 _kdm_from->SetValue (std_to_wx (config->kdm_from ()));
156 _kdm_from->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&GeneralPage::kdm_from_changed, this));
157 _check_for_updates->SetValue (config->check_for_updates ());
158 _check_for_updates->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&GeneralPage::check_for_updates_changed, this));
159 _check_for_test_updates->SetValue (config->check_for_test_updates ());
160 _check_for_test_updates->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&GeneralPage::check_for_test_updates_changed, this));
166 void setup_language_sensitivity ()
168 _language->Enable (_set_language->GetValue ());
171 void set_language_changed ()
173 setup_language_sensitivity ();
174 if (_set_language->GetValue ()) {
177 Config::instance()->unset_language ();
181 void language_changed ()
183 switch (_language->GetSelection ()) {
185 Config::instance()->set_language ("en");
188 Config::instance()->set_language ("fr");
191 Config::instance()->set_language ("it");
194 Config::instance()->set_language ("es");
197 Config::instance()->set_language ("sv");
200 Config::instance()->set_language ("de");
205 void mail_server_changed ()
207 Config::instance()->set_mail_server (wx_to_std (_mail_server->GetValue ()));
210 void mail_user_changed ()
212 Config::instance()->set_mail_user (wx_to_std (_mail_user->GetValue ()));
215 void mail_password_changed ()
217 Config::instance()->set_mail_password (wx_to_std (_mail_password->GetValue ()));
220 void kdm_from_changed ()
222 Config::instance()->set_kdm_from (wx_to_std (_kdm_from->GetValue ()));
225 void check_for_updates_changed ()
227 Config::instance()->set_check_for_updates (_check_for_updates->GetValue ());
230 void check_for_test_updates_changed ()
232 Config::instance()->set_check_for_test_updates (_check_for_test_updates->GetValue ());
235 void num_local_encoding_threads_changed ()
237 Config::instance()->set_num_local_encoding_threads (_num_local_encoding_threads->GetValue ());
240 wxCheckBox* _set_language;
242 wxSpinCtrl* _num_local_encoding_threads;
243 wxTextCtrl* _mail_server;
244 wxTextCtrl* _mail_user;
245 wxTextCtrl* _mail_password;
246 wxTextCtrl* _kdm_from;
247 wxCheckBox* _check_for_updates;
248 wxCheckBox* _check_for_test_updates;
251 class DefaultsPage : public wxPreferencesPage
254 wxString GetName () const
256 return _("Defaults");
260 wxBitmap GetLargeIcon () const
262 return wxBitmap ("defaults", wxBITMAP_TYPE_PNG_RESOURCE);
266 wxWindow* CreateWindow (wxWindow* parent)
268 wxPanel* panel = new wxPanel (parent);
269 wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
272 wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
273 table->AddGrowableCol (1, 1);
274 s->Add (table, 1, wxALL | wxEXPAND, 8);
277 add_label_to_sizer (table, panel, _("Default duration of still images"), true);
278 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
279 _still_length = new wxSpinCtrl (panel);
280 s->Add (_still_length);
281 add_label_to_sizer (s, panel, _("s"), false);
285 add_label_to_sizer (table, panel, _("Default directory for new films"), true);
286 #ifdef DCPOMATIC_USE_OWN_DIR_PICKER
287 _directory = new DirPickerCtrl (panel);
289 _directory = new wxDirPickerCtrl (panel, wxDD_DIR_MUST_EXIST);
291 table->Add (_directory, 1, wxEXPAND);
293 add_label_to_sizer (table, panel, _("Default DCI name details"), true);
294 _dci_metadata_button = new wxButton (panel, wxID_ANY, _("Edit..."));
295 table->Add (_dci_metadata_button);
297 add_label_to_sizer (table, panel, _("Default container"), true);
298 _container = new wxChoice (panel, wxID_ANY);
299 table->Add (_container);
301 add_label_to_sizer (table, panel, _("Default content type"), true);
302 _dcp_content_type = new wxChoice (panel, wxID_ANY);
303 table->Add (_dcp_content_type);
306 add_label_to_sizer (table, panel, _("Default JPEG2000 bandwidth"), true);
307 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
308 _j2k_bandwidth = new wxSpinCtrl (panel);
309 s->Add (_j2k_bandwidth);
310 add_label_to_sizer (s, panel, _("Mbit/s"), false);
315 add_label_to_sizer (table, panel, _("Default audio delay"), true);
316 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
317 _audio_delay = new wxSpinCtrl (panel);
318 s->Add (_audio_delay);
319 add_label_to_sizer (s, panel, _("ms"), false);
323 add_label_to_sizer (table, panel, _("Default issuer"), true);
324 _issuer = new wxTextCtrl (panel, wxID_ANY);
325 table->Add (_issuer, 1, wxEXPAND);
327 add_label_to_sizer (table, panel, _("Default creator"), true);
328 _creator = new wxTextCtrl (panel, wxID_ANY);
329 table->Add (_creator, 1, wxEXPAND);
331 Config* config = Config::instance ();
333 _still_length->SetRange (1, 3600);
334 _still_length->SetValue (config->default_still_length ());
335 _still_length->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&DefaultsPage::still_length_changed, this));
337 _directory->SetPath (std_to_wx (config->default_directory_or (wx_to_std (wxStandardPaths::Get().GetDocumentsDir())).string ()));
338 _directory->Bind (wxEVT_COMMAND_DIRPICKER_CHANGED, boost::bind (&DefaultsPage::directory_changed, this));
340 _dci_metadata_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&DefaultsPage::edit_dci_metadata_clicked, this, parent));
342 vector<Ratio const *> ratio = Ratio::all ();
344 for (vector<Ratio const *>::iterator i = ratio.begin(); i != ratio.end(); ++i) {
345 _container->Append (std_to_wx ((*i)->nickname ()));
346 if (*i == config->default_container ()) {
347 _container->SetSelection (n);
352 _container->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DefaultsPage::container_changed, this));
354 vector<DCPContentType const *> const ct = DCPContentType::all ();
356 for (vector<DCPContentType const *>::const_iterator i = ct.begin(); i != ct.end(); ++i) {
357 _dcp_content_type->Append (std_to_wx ((*i)->pretty_name ()));
358 if (*i == config->default_dcp_content_type ()) {
359 _dcp_content_type->SetSelection (n);
364 _dcp_content_type->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DefaultsPage::dcp_content_type_changed, this));
366 _j2k_bandwidth->SetRange (50, 250);
367 _j2k_bandwidth->SetValue (config->default_j2k_bandwidth() / 1000000);
368 _j2k_bandwidth->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&DefaultsPage::j2k_bandwidth_changed, this));
370 _audio_delay->SetRange (-1000, 1000);
371 _audio_delay->SetValue (config->default_audio_delay ());
372 _audio_delay->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&DefaultsPage::audio_delay_changed, this));
374 _issuer->SetValue (std_to_wx (config->dcp_metadata().issuer));
375 _issuer->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&DefaultsPage::issuer_changed, this));
376 _creator->SetValue (std_to_wx (config->dcp_metadata().creator));
377 _creator->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&DefaultsPage::creator_changed, this));
383 void j2k_bandwidth_changed ()
385 Config::instance()->set_default_j2k_bandwidth (_j2k_bandwidth->GetValue() * 1000000);
388 void audio_delay_changed ()
390 Config::instance()->set_default_audio_delay (_audio_delay->GetValue());
393 void directory_changed ()
395 Config::instance()->set_default_directory (wx_to_std (_directory->GetPath ()));
398 void edit_dci_metadata_clicked (wxWindow* parent)
400 DCIMetadataDialog* d = new DCIMetadataDialog (parent, Config::instance()->default_dci_metadata ());
402 Config::instance()->set_default_dci_metadata (d->dci_metadata ());
406 void still_length_changed ()
408 Config::instance()->set_default_still_length (_still_length->GetValue ());
411 void container_changed ()
413 vector<Ratio const *> ratio = Ratio::all ();
414 Config::instance()->set_default_container (ratio[_container->GetSelection()]);
417 void dcp_content_type_changed ()
419 vector<DCPContentType const *> ct = DCPContentType::all ();
420 Config::instance()->set_default_dcp_content_type (ct[_dcp_content_type->GetSelection()]);
423 void issuer_changed ()
425 libdcp::XMLMetadata m = Config::instance()->dcp_metadata ();
426 m.issuer = wx_to_std (_issuer->GetValue ());
427 Config::instance()->set_dcp_metadata (m);
430 void creator_changed ()
432 libdcp::XMLMetadata m = Config::instance()->dcp_metadata ();
433 m.creator = wx_to_std (_creator->GetValue ());
434 Config::instance()->set_dcp_metadata (m);
437 wxSpinCtrl* _j2k_bandwidth;
438 wxSpinCtrl* _audio_delay;
439 wxButton* _dci_metadata_button;
440 wxSpinCtrl* _still_length;
441 #ifdef DCPOMATIC_USE_OWN_DIR_PICKER
442 DirPickerCtrl* _directory;
444 wxDirPickerCtrl* _directory;
446 wxChoice* _container;
447 wxChoice* _dcp_content_type;
449 wxTextCtrl* _creator;
452 class EncodingServersPage : public wxPreferencesPage
455 wxString GetName () const
461 wxBitmap GetLargeIcon () const
463 return wxBitmap ("servers", wxBITMAP_TYPE_PNG_RESOURCE);
467 wxWindow* CreateWindow (wxWindow* parent)
469 wxPanel* panel = new wxPanel (parent);
470 wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
473 _use_any_servers = new wxCheckBox (panel, wxID_ANY, _("Use all servers"));
474 s->Add (_use_any_servers, 0, wxALL, DCPOMATIC_SIZER_X_GAP);
476 vector<string> columns;
477 columns.push_back (wx_to_std (_("IP address / host name")));
478 _servers_list = new EditableList<string, ServerDialog> (
481 boost::bind (&Config::servers, Config::instance()),
482 boost::bind (&Config::set_servers, Config::instance(), _1),
483 boost::bind (&EncodingServersPage::server_column, this, _1)
486 s->Add (_servers_list, 1, wxEXPAND | wxALL, DCPOMATIC_SIZER_X_GAP);
488 _use_any_servers->SetValue (Config::instance()->use_any_servers ());
489 _use_any_servers->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&EncodingServersPage::use_any_servers_changed, this));
496 void use_any_servers_changed ()
498 Config::instance()->set_use_any_servers (_use_any_servers->GetValue ());
501 string server_column (string s)
506 wxCheckBox* _use_any_servers;
507 EditableList<string, ServerDialog>* _servers_list;
510 class ColourConversionsPage : public wxPreferencesPage
512 wxString GetName () const
514 return _("Colour Conversions");
518 wxBitmap GetLargeIcon () const
520 return wxBitmap ("colour_conversions", wxBITMAP_TYPE_PNG_RESOURCE);
523 wxWindow* CreateWindow (wxWindow* parent)
525 vector<string> columns;
526 columns.push_back (wx_to_std (_("Name")));
527 return new EditableList<PresetColourConversion, PresetColourConversionDialog> (
530 boost::bind (&Config::colour_conversions, Config::instance()),
531 boost::bind (&Config::set_colour_conversions, Config::instance(), _1),
532 boost::bind (&ColourConversionsPage::colour_conversion_column, this, _1),
538 string colour_conversion_column (PresetColourConversion c)
544 class TMSPage : public wxPreferencesPage
546 wxString GetName () const
552 wxBitmap GetLargeIcon () const
554 return wxBitmap ("tms", wxBITMAP_TYPE_PNG_RESOURCE);
558 wxWindow* CreateWindow (wxWindow* parent)
560 wxPanel* panel = new wxPanel (parent);
561 wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
564 wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
565 table->AddGrowableCol (1, 1);
566 s->Add (table, 1, wxALL | wxEXPAND, 8);
568 add_label_to_sizer (table, panel, _("IP address"), true);
569 _tms_ip = new wxTextCtrl (panel, wxID_ANY);
570 table->Add (_tms_ip, 1, wxEXPAND);
572 add_label_to_sizer (table, panel, _("Target path"), true);
573 _tms_path = new wxTextCtrl (panel, wxID_ANY);
574 table->Add (_tms_path, 1, wxEXPAND);
576 add_label_to_sizer (table, panel, _("User name"), true);
577 _tms_user = new wxTextCtrl (panel, wxID_ANY);
578 table->Add (_tms_user, 1, wxEXPAND);
580 add_label_to_sizer (table, panel, _("Password"), true);
581 _tms_password = new wxTextCtrl (panel, wxID_ANY);
582 table->Add (_tms_password, 1, wxEXPAND);
584 Config* config = Config::instance ();
586 _tms_ip->SetValue (std_to_wx (config->tms_ip ()));
587 _tms_ip->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&TMSPage::tms_ip_changed, this));
588 _tms_path->SetValue (std_to_wx (config->tms_path ()));
589 _tms_path->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&TMSPage::tms_path_changed, this));
590 _tms_user->SetValue (std_to_wx (config->tms_user ()));
591 _tms_user->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&TMSPage::tms_user_changed, this));
592 _tms_password->SetValue (std_to_wx (config->tms_password ()));
593 _tms_password->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&TMSPage::tms_password_changed, this));
599 void tms_ip_changed ()
601 Config::instance()->set_tms_ip (wx_to_std (_tms_ip->GetValue ()));
604 void tms_path_changed ()
606 Config::instance()->set_tms_path (wx_to_std (_tms_path->GetValue ()));
609 void tms_user_changed ()
611 Config::instance()->set_tms_user (wx_to_std (_tms_user->GetValue ()));
614 void tms_password_changed ()
616 Config::instance()->set_tms_password (wx_to_std (_tms_password->GetValue ()));
620 wxTextCtrl* _tms_path;
621 wxTextCtrl* _tms_user;
622 wxTextCtrl* _tms_password;
625 class KDMEmailPage : public wxPreferencesPage
628 wxString GetName () const
630 return _("KDM Email");
634 wxBitmap GetLargeIcon () const
636 return wxBitmap ("blank", wxBITMAP_TYPE_PNG_RESOURCE);
640 wxWindow* CreateWindow (wxWindow* parent)
642 wxPanel* panel = new wxPanel (parent);
643 wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
646 _kdm_email = new wxTextCtrl (panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
647 s->Add (_kdm_email, 1, wxEXPAND | wxALL, 12);
649 _kdm_email->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&KDMEmailPage::kdm_email_changed, this));
650 _kdm_email->SetValue (wx_to_std (Config::instance()->kdm_email ()));
656 void kdm_email_changed ()
658 Config::instance()->set_kdm_email (wx_to_std (_kdm_email->GetValue ()));
661 wxTextCtrl* _kdm_email;
665 create_config_dialog ()
667 wxPreferencesEditor* e = new wxPreferencesEditor ();
668 e->AddPage (new GeneralPage);
669 e->AddPage (new DefaultsPage);
670 e->AddPage (new EncodingServersPage);
671 e->AddPage (new ColourConversionsPage);
672 e->AddPage (new TMSPage);
673 e->AddPage (new KDMEmailPage);