2 Copyright (C) 2012 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/notebook.h>
29 #include "lib/config.h"
30 #include "lib/server.h"
31 #include "lib/ratio.h"
32 #include "lib/scaler.h"
33 #include "lib/filter.h"
34 #include "lib/dcp_content_type.h"
35 #include "config_dialog.h"
37 #include "filter_dialog.h"
38 #include "server_dialog.h"
39 #include "dir_picker_ctrl.h"
40 #include "dci_metadata_dialog.h"
45 ConfigDialog::ConfigDialog (wxWindow* parent)
46 : wxDialog (parent, wxID_ANY, _("DCP-o-matic Preferences"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
48 wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
49 _notebook = new wxNotebook (this, wxID_ANY);
50 s->Add (_notebook, 1);
53 _notebook->AddPage (_misc_panel, _("Miscellaneous"), true);
54 make_servers_panel ();
55 _notebook->AddPage (_servers_panel, _("Encoding servers"), false);
56 make_metadata_panel ();
57 _notebook->AddPage (_metadata_panel, _("Metadata"), false);
59 _notebook->AddPage (_tms_panel, _("TMS"), false);
61 wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
62 overall_sizer->Add (s, 1, wxEXPAND | wxALL, 6);
64 wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
66 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
69 SetSizer (overall_sizer);
70 overall_sizer->Layout ();
71 overall_sizer->SetSizeHints (this);
75 ConfigDialog::make_misc_panel ()
77 _misc_panel = new wxPanel (_notebook);
78 wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
79 _misc_panel->SetSizer (s);
81 wxFlexGridSizer* table = new wxFlexGridSizer (3, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
82 table->AddGrowableCol (1, 1);
83 s->Add (table, 1, wxALL | wxEXPAND, 8);
85 _set_language = new wxCheckBox (_misc_panel, wxID_ANY, _("Set language"));
86 table->Add (_set_language, 1, wxEXPAND);
87 _language = new wxChoice (_misc_panel, wxID_ANY);
88 _language->Append (wxT ("English"));
89 _language->Append (wxT ("Français"));
90 _language->Append (wxT ("Italiano"));
91 _language->Append (wxT ("Español"));
92 _language->Append (wxT ("Svenska"));
93 table->Add (_language, 1, wxEXPAND);
96 wxStaticText* restart = add_label_to_sizer (table, _misc_panel, _("(restart DCP-o-matic to see language changes)"), false);
97 wxFont font = restart->GetFont();
98 font.SetStyle (wxFONTSTYLE_ITALIC);
99 font.SetPointSize (font.GetPointSize() - 1);
100 restart->SetFont (font);
101 table->AddSpacer (0);
102 table->AddSpacer (0);
104 add_label_to_sizer (table, _misc_panel, _("Threads to use for encoding on this host"), true);
105 _num_local_encoding_threads = new wxSpinCtrl (_misc_panel);
106 table->Add (_num_local_encoding_threads, 1);
107 table->AddSpacer (0);
109 add_label_to_sizer (table, _misc_panel, _("Default duration of still images"), true);
110 _default_still_length = new wxSpinCtrl (_misc_panel);
111 table->Add (_default_still_length, 1, wxEXPAND);
112 add_label_to_sizer (table, _misc_panel, _("s"), false);
114 add_label_to_sizer (table, _misc_panel, _("Default directory for new films"), true);
115 #ifdef DCPOMATIC_USE_OWN_DIR_PICKER
116 _default_directory = new DirPickerCtrl (_misc_panel);
118 _default_directory = new wxDirPickerCtrl (_misc_panel, wxDD_DIR_MUST_EXIST);
120 table->Add (_default_directory, 1, wxEXPAND);
121 table->AddSpacer (0);
123 add_label_to_sizer (table, _misc_panel, _("Default DCI name details"), true);
124 _default_dci_metadata_button = new wxButton (_misc_panel, wxID_ANY, _("Edit..."));
125 table->Add (_default_dci_metadata_button);
126 table->AddSpacer (1);
128 add_label_to_sizer (table, _misc_panel, _("Default container"), true);
129 _default_container = new wxChoice (_misc_panel, wxID_ANY);
130 table->Add (_default_container);
131 table->AddSpacer (1);
133 add_label_to_sizer (table, _misc_panel, _("Default content type"), true);
134 _default_dcp_content_type = new wxChoice (_misc_panel, wxID_ANY);
135 table->Add (_default_dcp_content_type);
136 table->AddSpacer (1);
138 add_label_to_sizer (table, _misc_panel, _("Default JPEG2000 bandwidth"), true);
139 _default_j2k_bandwidth = new wxSpinCtrl (_misc_panel);
140 table->Add (_default_j2k_bandwidth, 1);
141 add_label_to_sizer (table, _misc_panel, _("MBps"), false);
143 Config* config = Config::instance ();
145 _set_language->SetValue (config->language ());
147 if (config->language().get_value_or ("") == "fr") {
148 _language->SetSelection (1);
149 } else if (config->language().get_value_or ("") == "it") {
150 _language->SetSelection (2);
151 } else if (config->language().get_value_or ("") == "es") {
152 _language->SetSelection (3);
153 } else if (config->language().get_value_or ("") == "sv") {
154 _language->SetSelection (4);
156 _language->SetSelection (0);
159 setup_language_sensitivity ();
161 _set_language->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (ConfigDialog::set_language_changed), 0, this);
162 _language->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (ConfigDialog::language_changed), 0, this);
164 _num_local_encoding_threads->SetRange (1, 128);
165 _num_local_encoding_threads->SetValue (config->num_local_encoding_threads ());
166 _num_local_encoding_threads->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (ConfigDialog::num_local_encoding_threads_changed), 0, this);
168 _default_still_length->SetRange (1, 3600);
169 _default_still_length->SetValue (config->default_still_length ());
170 _default_still_length->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (ConfigDialog::default_still_length_changed), 0, this);
172 _default_directory->SetPath (std_to_wx (config->default_directory_or (wx_to_std (wxStandardPaths::Get().GetDocumentsDir()))));
173 _default_directory->Connect (wxID_ANY, wxEVT_COMMAND_DIRPICKER_CHANGED, wxCommandEventHandler (ConfigDialog::default_directory_changed), 0, this);
175 _default_dci_metadata_button->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (ConfigDialog::edit_default_dci_metadata_clicked), 0, this);
177 vector<Ratio const *> ratio = Ratio::all ();
179 for (vector<Ratio const *>::iterator i = ratio.begin(); i != ratio.end(); ++i) {
180 _default_container->Append (std_to_wx ((*i)->nickname ()));
181 if (*i == config->default_container ()) {
182 _default_container->SetSelection (n);
187 _default_container->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (ConfigDialog::default_container_changed), 0, this);
189 vector<DCPContentType const *> const ct = DCPContentType::all ();
191 for (vector<DCPContentType const *>::const_iterator i = ct.begin(); i != ct.end(); ++i) {
192 _default_dcp_content_type->Append (std_to_wx ((*i)->pretty_name ()));
193 if (*i == config->default_dcp_content_type ()) {
194 _default_dcp_content_type->SetSelection (n);
199 _default_dcp_content_type->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (ConfigDialog::default_dcp_content_type_changed), 0, this);
201 _default_j2k_bandwidth->SetRange (50, 250);
202 _default_j2k_bandwidth->SetValue (config->default_j2k_bandwidth() / 1e6);
203 _default_j2k_bandwidth->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (ConfigDialog::default_j2k_bandwidth_changed), 0, this);
207 ConfigDialog::make_tms_panel ()
209 _tms_panel = new wxPanel (_notebook);
210 wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
211 _tms_panel->SetSizer (s);
213 wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
214 table->AddGrowableCol (1, 1);
215 s->Add (table, 1, wxALL | wxEXPAND, 8);
217 add_label_to_sizer (table, _tms_panel, _("IP address"), true);
218 _tms_ip = new wxTextCtrl (_tms_panel, wxID_ANY);
219 table->Add (_tms_ip, 1, wxEXPAND);
221 add_label_to_sizer (table, _tms_panel, _("Target path"), true);
222 _tms_path = new wxTextCtrl (_tms_panel, wxID_ANY);
223 table->Add (_tms_path, 1, wxEXPAND);
225 add_label_to_sizer (table, _tms_panel, _("User name"), true);
226 _tms_user = new wxTextCtrl (_tms_panel, wxID_ANY);
227 table->Add (_tms_user, 1, wxEXPAND);
229 add_label_to_sizer (table, _tms_panel, _("Password"), true);
230 _tms_password = new wxTextCtrl (_tms_panel, wxID_ANY);
231 table->Add (_tms_password, 1, wxEXPAND);
233 Config* config = Config::instance ();
235 _tms_ip->SetValue (std_to_wx (config->tms_ip ()));
236 _tms_ip->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (ConfigDialog::tms_ip_changed), 0, this);
237 _tms_path->SetValue (std_to_wx (config->tms_path ()));
238 _tms_path->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (ConfigDialog::tms_path_changed), 0, this);
239 _tms_user->SetValue (std_to_wx (config->tms_user ()));
240 _tms_user->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (ConfigDialog::tms_user_changed), 0, this);
241 _tms_password->SetValue (std_to_wx (config->tms_password ()));
242 _tms_password->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (ConfigDialog::tms_password_changed), 0, this);
246 ConfigDialog::make_metadata_panel ()
248 _metadata_panel = new wxPanel (_notebook);
249 wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
250 _metadata_panel->SetSizer (s);
252 wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
253 table->AddGrowableCol (1, 1);
254 s->Add (table, 1, wxALL | wxEXPAND, 8);
256 add_label_to_sizer (table, _metadata_panel, _("Issuer"), true);
257 _issuer = new wxTextCtrl (_metadata_panel, wxID_ANY);
258 table->Add (_issuer, 1, wxEXPAND);
260 add_label_to_sizer (table, _metadata_panel, _("Creator"), true);
261 _creator = new wxTextCtrl (_metadata_panel, wxID_ANY);
262 table->Add (_creator, 1, wxEXPAND);
264 Config* config = Config::instance ();
266 _issuer->SetValue (std_to_wx (config->dcp_metadata().issuer));
267 _issuer->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (ConfigDialog::issuer_changed), 0, this);
268 _creator->SetValue (std_to_wx (config->dcp_metadata().creator));
269 _creator->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (ConfigDialog::creator_changed), 0, this);
273 ConfigDialog::make_servers_panel ()
275 _servers_panel = new wxPanel (_notebook);
276 wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
277 _servers_panel->SetSizer (s);
279 wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
280 table->AddGrowableCol (0, 1);
281 s->Add (table, 1, wxALL | wxEXPAND, 8);
283 Config* config = Config::instance ();
285 _servers = new wxListCtrl (_servers_panel, wxID_ANY, wxDefaultPosition, wxSize (220, 100), wxLC_REPORT | wxLC_SINGLE_SEL);
288 ip.SetText (_("IP address"));
290 _servers->InsertColumn (0, ip);
292 ip.SetText (_("Threads"));
294 _servers->InsertColumn (1, ip);
295 table->Add (_servers, 1, wxEXPAND | wxALL);
298 wxSizer* s = new wxBoxSizer (wxVERTICAL);
299 _add_server = new wxButton (_servers_panel, wxID_ANY, _("Add"));
300 s->Add (_add_server, 0, wxTOP | wxBOTTOM, 2);
301 _edit_server = new wxButton (_servers_panel, wxID_ANY, _("Edit"));
302 s->Add (_edit_server, 0, wxTOP | wxBOTTOM, 2);
303 _remove_server = new wxButton (_servers_panel, wxID_ANY, _("Remove"));
304 s->Add (_remove_server, 0, wxTOP | wxBOTTOM, 2);
308 vector<ServerDescription*> servers = config->servers ();
309 for (vector<ServerDescription*>::iterator i = servers.begin(); i != servers.end(); ++i) {
310 add_server_to_control (*i);
313 _add_server->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (ConfigDialog::add_server_clicked), 0, this);
314 _edit_server->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (ConfigDialog::edit_server_clicked), 0, this);
315 _remove_server->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (ConfigDialog::remove_server_clicked), 0, this);
317 _servers->Connect (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler (ConfigDialog::server_selection_changed), 0, this);
318 _servers->Connect (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_DESELECTED, wxListEventHandler (ConfigDialog::server_selection_changed), 0, this);
320 server_selection_changed (ev);
324 ConfigDialog::language_changed (wxCommandEvent &)
326 switch (_language->GetSelection ()) {
328 Config::instance()->set_language ("en");
331 Config::instance()->set_language ("fr");
334 Config::instance()->set_language ("it");
337 Config::instance()->set_language ("es");
340 Config::instance()->set_language ("sv");
346 ConfigDialog::tms_ip_changed (wxCommandEvent &)
348 Config::instance()->set_tms_ip (wx_to_std (_tms_ip->GetValue ()));
352 ConfigDialog::tms_path_changed (wxCommandEvent &)
354 Config::instance()->set_tms_path (wx_to_std (_tms_path->GetValue ()));
358 ConfigDialog::tms_user_changed (wxCommandEvent &)
360 Config::instance()->set_tms_user (wx_to_std (_tms_user->GetValue ()));
364 ConfigDialog::tms_password_changed (wxCommandEvent &)
366 Config::instance()->set_tms_password (wx_to_std (_tms_password->GetValue ()));
370 ConfigDialog::num_local_encoding_threads_changed (wxCommandEvent &)
372 Config::instance()->set_num_local_encoding_threads (_num_local_encoding_threads->GetValue ());
376 ConfigDialog::default_directory_changed (wxCommandEvent &)
378 Config::instance()->set_default_directory (wx_to_std (_default_directory->GetPath ()));
382 ConfigDialog::add_server_to_control (ServerDescription* s)
385 int const n = _servers->GetItemCount ();
387 _servers->InsertItem (item);
388 _servers->SetItem (n, 0, std_to_wx (s->host_name ()));
389 _servers->SetItem (n, 1, std_to_wx (boost::lexical_cast<string> (s->threads ())));
393 ConfigDialog::add_server_clicked (wxCommandEvent &)
395 ServerDialog* d = new ServerDialog (this, 0);
397 ServerDescription* s = d->server ();
400 add_server_to_control (s);
401 vector<ServerDescription*> o = Config::instance()->servers ();
403 Config::instance()->set_servers (o);
407 ConfigDialog::edit_server_clicked (wxCommandEvent &)
409 int i = _servers->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
417 _servers->GetItem (item);
419 vector<ServerDescription*> servers = Config::instance()->servers ();
420 assert (i >= 0 && i < int (servers.size ()));
422 ServerDialog* d = new ServerDialog (this, servers[i]);
426 _servers->SetItem (i, 0, std_to_wx (servers[i]->host_name ()));
427 _servers->SetItem (i, 1, std_to_wx (boost::lexical_cast<string> (servers[i]->threads ())));
431 ConfigDialog::remove_server_clicked (wxCommandEvent &)
433 int i = _servers->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
435 _servers->DeleteItem (i);
438 vector<ServerDescription*> o = Config::instance()->servers ();
439 o.erase (o.begin() + i);
440 Config::instance()->set_servers (o);
444 ConfigDialog::server_selection_changed (wxListEvent &)
446 int const i = _servers->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
447 _edit_server->Enable (i >= 0);
448 _remove_server->Enable (i >= 0);
452 ConfigDialog::edit_default_dci_metadata_clicked (wxCommandEvent &)
454 DCIMetadataDialog* d = new DCIMetadataDialog (this, Config::instance()->default_dci_metadata ());
456 Config::instance()->set_default_dci_metadata (d->dci_metadata ());
461 ConfigDialog::set_language_changed (wxCommandEvent& ev)
463 setup_language_sensitivity ();
464 if (_set_language->GetValue ()) {
465 language_changed (ev);
467 Config::instance()->unset_language ();
472 ConfigDialog::setup_language_sensitivity ()
474 _language->Enable (_set_language->GetValue ());
478 ConfigDialog::default_still_length_changed (wxCommandEvent &)
480 Config::instance()->set_default_still_length (_default_still_length->GetValue ());
484 ConfigDialog::default_container_changed (wxCommandEvent &)
486 vector<Ratio const *> ratio = Ratio::all ();
487 Config::instance()->set_default_container (ratio[_default_container->GetSelection()]);
491 ConfigDialog::default_dcp_content_type_changed (wxCommandEvent &)
493 vector<DCPContentType const *> ct = DCPContentType::all ();
494 Config::instance()->set_default_dcp_content_type (ct[_default_dcp_content_type->GetSelection()]);
498 ConfigDialog::issuer_changed (wxCommandEvent &)
500 libdcp::XMLMetadata m = Config::instance()->dcp_metadata ();
501 m.issuer = wx_to_std (_issuer->GetValue ());
502 Config::instance()->set_dcp_metadata (m);
506 ConfigDialog::creator_changed (wxCommandEvent &)
508 libdcp::XMLMetadata m = Config::instance()->dcp_metadata ();
509 m.creator = wx_to_std (_creator->GetValue ());
510 Config::instance()->set_dcp_metadata (m);
514 ConfigDialog::default_j2k_bandwidth_changed (wxCommandEvent &)
516 Config::instance()->set_default_j2k_bandwidth (_default_j2k_bandwidth->GetValue() * 1e6);