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, DCPOMATIC_DIALOG_BORDER);
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 (2, 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);
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);
95 wxStaticText* restart = add_label_to_sizer (table, _misc_panel, _("(restart DCP-o-matic to see language changes)"), false);
96 wxFont font = restart->GetFont();
97 font.SetStyle (wxFONTSTYLE_ITALIC);
98 font.SetPointSize (font.GetPointSize() - 1);
99 restart->SetFont (font);
100 table->AddSpacer (0);
102 add_label_to_sizer (table, _misc_panel, _("Threads to use for encoding on this host"), true);
103 _num_local_encoding_threads = new wxSpinCtrl (_misc_panel);
104 table->Add (_num_local_encoding_threads, 1);
107 add_label_to_sizer (table, _misc_panel, _("Default duration of still images"), true);
108 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
109 _default_still_length = new wxSpinCtrl (_misc_panel);
110 s->Add (_default_still_length);
111 add_label_to_sizer (s, _misc_panel, _("s"), false);
115 add_label_to_sizer (table, _misc_panel, _("Default directory for new films"), true);
116 #ifdef DCPOMATIC_USE_OWN_DIR_PICKER
117 _default_directory = new DirPickerCtrl (_misc_panel);
119 _default_directory = new wxDirPickerCtrl (_misc_panel, wxDD_DIR_MUST_EXIST);
121 table->Add (_default_directory, 1, wxEXPAND);
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);
127 add_label_to_sizer (table, _misc_panel, _("Default container"), true);
128 _default_container = new wxChoice (_misc_panel, wxID_ANY);
129 table->Add (_default_container);
131 add_label_to_sizer (table, _misc_panel, _("Default content type"), true);
132 _default_dcp_content_type = new wxChoice (_misc_panel, wxID_ANY);
133 table->Add (_default_dcp_content_type);
136 add_label_to_sizer (table, _misc_panel, _("Default JPEG2000 bandwidth"), true);
137 wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
138 _default_j2k_bandwidth = new wxSpinCtrl (_misc_panel);
139 s->Add (_default_j2k_bandwidth);
140 add_label_to_sizer (s, _misc_panel, _("MBps"), false);
144 Config* config = Config::instance ();
146 _set_language->SetValue (config->language ());
148 if (config->language().get_value_or ("") == "fr") {
149 _language->SetSelection (1);
150 } else if (config->language().get_value_or ("") == "it") {
151 _language->SetSelection (2);
152 } else if (config->language().get_value_or ("") == "es") {
153 _language->SetSelection (3);
154 } else if (config->language().get_value_or ("") == "sv") {
155 _language->SetSelection (4);
157 _language->SetSelection (0);
160 setup_language_sensitivity ();
162 _set_language->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (ConfigDialog::set_language_changed), 0, this);
163 _language->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (ConfigDialog::language_changed), 0, this);
165 _num_local_encoding_threads->SetRange (1, 128);
166 _num_local_encoding_threads->SetValue (config->num_local_encoding_threads ());
167 _num_local_encoding_threads->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (ConfigDialog::num_local_encoding_threads_changed), 0, this);
169 _default_still_length->SetRange (1, 3600);
170 _default_still_length->SetValue (config->default_still_length ());
171 _default_still_length->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (ConfigDialog::default_still_length_changed), 0, this);
173 _default_directory->SetPath (std_to_wx (config->default_directory_or (wx_to_std (wxStandardPaths::Get().GetDocumentsDir()))));
174 _default_directory->Connect (wxID_ANY, wxEVT_COMMAND_DIRPICKER_CHANGED, wxCommandEventHandler (ConfigDialog::default_directory_changed), 0, this);
176 _default_dci_metadata_button->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (ConfigDialog::edit_default_dci_metadata_clicked), 0, this);
178 vector<Ratio const *> ratio = Ratio::all ();
180 for (vector<Ratio const *>::iterator i = ratio.begin(); i != ratio.end(); ++i) {
181 _default_container->Append (std_to_wx ((*i)->nickname ()));
182 if (*i == config->default_container ()) {
183 _default_container->SetSelection (n);
188 _default_container->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (ConfigDialog::default_container_changed), 0, this);
190 vector<DCPContentType const *> const ct = DCPContentType::all ();
192 for (vector<DCPContentType const *>::const_iterator i = ct.begin(); i != ct.end(); ++i) {
193 _default_dcp_content_type->Append (std_to_wx ((*i)->pretty_name ()));
194 if (*i == config->default_dcp_content_type ()) {
195 _default_dcp_content_type->SetSelection (n);
200 _default_dcp_content_type->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (ConfigDialog::default_dcp_content_type_changed), 0, this);
202 _default_j2k_bandwidth->SetRange (50, 250);
203 _default_j2k_bandwidth->SetValue (config->default_j2k_bandwidth() / 1e6);
204 _default_j2k_bandwidth->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (ConfigDialog::default_j2k_bandwidth_changed), 0, this);
208 ConfigDialog::make_tms_panel ()
210 _tms_panel = new wxPanel (_notebook);
211 wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
212 _tms_panel->SetSizer (s);
214 wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
215 table->AddGrowableCol (1, 1);
216 s->Add (table, 1, wxALL | wxEXPAND, 8);
218 add_label_to_sizer (table, _tms_panel, _("IP address"), true);
219 _tms_ip = new wxTextCtrl (_tms_panel, wxID_ANY);
220 table->Add (_tms_ip, 1, wxEXPAND);
222 add_label_to_sizer (table, _tms_panel, _("Target path"), true);
223 _tms_path = new wxTextCtrl (_tms_panel, wxID_ANY);
224 table->Add (_tms_path, 1, wxEXPAND);
226 add_label_to_sizer (table, _tms_panel, _("User name"), true);
227 _tms_user = new wxTextCtrl (_tms_panel, wxID_ANY);
228 table->Add (_tms_user, 1, wxEXPAND);
230 add_label_to_sizer (table, _tms_panel, _("Password"), true);
231 _tms_password = new wxTextCtrl (_tms_panel, wxID_ANY);
232 table->Add (_tms_password, 1, wxEXPAND);
234 Config* config = Config::instance ();
236 _tms_ip->SetValue (std_to_wx (config->tms_ip ()));
237 _tms_ip->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (ConfigDialog::tms_ip_changed), 0, this);
238 _tms_path->SetValue (std_to_wx (config->tms_path ()));
239 _tms_path->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (ConfigDialog::tms_path_changed), 0, this);
240 _tms_user->SetValue (std_to_wx (config->tms_user ()));
241 _tms_user->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (ConfigDialog::tms_user_changed), 0, this);
242 _tms_password->SetValue (std_to_wx (config->tms_password ()));
243 _tms_password->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (ConfigDialog::tms_password_changed), 0, this);
247 ConfigDialog::make_metadata_panel ()
249 _metadata_panel = new wxPanel (_notebook);
250 wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
251 _metadata_panel->SetSizer (s);
253 wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
254 table->AddGrowableCol (1, 1);
255 s->Add (table, 1, wxALL | wxEXPAND, 8);
257 add_label_to_sizer (table, _metadata_panel, _("Issuer"), true);
258 _issuer = new wxTextCtrl (_metadata_panel, wxID_ANY);
259 table->Add (_issuer, 1, wxEXPAND);
261 add_label_to_sizer (table, _metadata_panel, _("Creator"), true);
262 _creator = new wxTextCtrl (_metadata_panel, wxID_ANY);
263 table->Add (_creator, 1, wxEXPAND);
265 Config* config = Config::instance ();
267 _issuer->SetValue (std_to_wx (config->dcp_metadata().issuer));
268 _issuer->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (ConfigDialog::issuer_changed), 0, this);
269 _creator->SetValue (std_to_wx (config->dcp_metadata().creator));
270 _creator->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (ConfigDialog::creator_changed), 0, this);
274 ConfigDialog::make_servers_panel ()
276 _servers_panel = new wxPanel (_notebook);
277 wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
278 _servers_panel->SetSizer (s);
280 wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
281 table->AddGrowableCol (0, 1);
282 s->Add (table, 1, wxALL | wxEXPAND, 8);
284 Config* config = Config::instance ();
286 _servers = new wxListCtrl (_servers_panel, wxID_ANY, wxDefaultPosition, wxSize (220, 100), wxLC_REPORT | wxLC_SINGLE_SEL);
289 ip.SetText (_("IP address"));
291 _servers->InsertColumn (0, ip);
293 ip.SetText (_("Threads"));
295 _servers->InsertColumn (1, ip);
296 table->Add (_servers, 1, wxEXPAND | wxALL);
299 wxSizer* s = new wxBoxSizer (wxVERTICAL);
300 _add_server = new wxButton (_servers_panel, wxID_ANY, _("Add"));
301 s->Add (_add_server, 0, wxTOP | wxBOTTOM, 2);
302 _edit_server = new wxButton (_servers_panel, wxID_ANY, _("Edit"));
303 s->Add (_edit_server, 0, wxTOP | wxBOTTOM, 2);
304 _remove_server = new wxButton (_servers_panel, wxID_ANY, _("Remove"));
305 s->Add (_remove_server, 0, wxTOP | wxBOTTOM, 2);
309 vector<ServerDescription*> servers = config->servers ();
310 for (vector<ServerDescription*>::iterator i = servers.begin(); i != servers.end(); ++i) {
311 add_server_to_control (*i);
314 _add_server->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (ConfigDialog::add_server_clicked), 0, this);
315 _edit_server->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (ConfigDialog::edit_server_clicked), 0, this);
316 _remove_server->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (ConfigDialog::remove_server_clicked), 0, this);
318 _servers->Connect (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler (ConfigDialog::server_selection_changed), 0, this);
319 _servers->Connect (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_DESELECTED, wxListEventHandler (ConfigDialog::server_selection_changed), 0, this);
321 server_selection_changed (ev);
325 ConfigDialog::language_changed (wxCommandEvent &)
327 switch (_language->GetSelection ()) {
329 Config::instance()->set_language ("en");
332 Config::instance()->set_language ("fr");
335 Config::instance()->set_language ("it");
338 Config::instance()->set_language ("es");
341 Config::instance()->set_language ("sv");
347 ConfigDialog::tms_ip_changed (wxCommandEvent &)
349 Config::instance()->set_tms_ip (wx_to_std (_tms_ip->GetValue ()));
353 ConfigDialog::tms_path_changed (wxCommandEvent &)
355 Config::instance()->set_tms_path (wx_to_std (_tms_path->GetValue ()));
359 ConfigDialog::tms_user_changed (wxCommandEvent &)
361 Config::instance()->set_tms_user (wx_to_std (_tms_user->GetValue ()));
365 ConfigDialog::tms_password_changed (wxCommandEvent &)
367 Config::instance()->set_tms_password (wx_to_std (_tms_password->GetValue ()));
371 ConfigDialog::num_local_encoding_threads_changed (wxCommandEvent &)
373 Config::instance()->set_num_local_encoding_threads (_num_local_encoding_threads->GetValue ());
377 ConfigDialog::default_directory_changed (wxCommandEvent &)
379 Config::instance()->set_default_directory (wx_to_std (_default_directory->GetPath ()));
383 ConfigDialog::add_server_to_control (ServerDescription* s)
386 int const n = _servers->GetItemCount ();
388 _servers->InsertItem (item);
389 _servers->SetItem (n, 0, std_to_wx (s->host_name ()));
390 _servers->SetItem (n, 1, std_to_wx (boost::lexical_cast<string> (s->threads ())));
394 ConfigDialog::add_server_clicked (wxCommandEvent &)
396 ServerDialog* d = new ServerDialog (this, 0);
398 ServerDescription* s = d->server ();
401 add_server_to_control (s);
402 vector<ServerDescription*> o = Config::instance()->servers ();
404 Config::instance()->set_servers (o);
408 ConfigDialog::edit_server_clicked (wxCommandEvent &)
410 int i = _servers->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
418 _servers->GetItem (item);
420 vector<ServerDescription*> servers = Config::instance()->servers ();
421 assert (i >= 0 && i < int (servers.size ()));
423 ServerDialog* d = new ServerDialog (this, servers[i]);
427 _servers->SetItem (i, 0, std_to_wx (servers[i]->host_name ()));
428 _servers->SetItem (i, 1, std_to_wx (boost::lexical_cast<string> (servers[i]->threads ())));
432 ConfigDialog::remove_server_clicked (wxCommandEvent &)
434 int i = _servers->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
436 _servers->DeleteItem (i);
439 vector<ServerDescription*> o = Config::instance()->servers ();
440 o.erase (o.begin() + i);
441 Config::instance()->set_servers (o);
445 ConfigDialog::server_selection_changed (wxListEvent &)
447 int const i = _servers->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
448 _edit_server->Enable (i >= 0);
449 _remove_server->Enable (i >= 0);
453 ConfigDialog::edit_default_dci_metadata_clicked (wxCommandEvent &)
455 DCIMetadataDialog* d = new DCIMetadataDialog (this, Config::instance()->default_dci_metadata ());
457 Config::instance()->set_default_dci_metadata (d->dci_metadata ());
462 ConfigDialog::set_language_changed (wxCommandEvent& ev)
464 setup_language_sensitivity ();
465 if (_set_language->GetValue ()) {
466 language_changed (ev);
468 Config::instance()->unset_language ();
473 ConfigDialog::setup_language_sensitivity ()
475 _language->Enable (_set_language->GetValue ());
479 ConfigDialog::default_still_length_changed (wxCommandEvent &)
481 Config::instance()->set_default_still_length (_default_still_length->GetValue ());
485 ConfigDialog::default_container_changed (wxCommandEvent &)
487 vector<Ratio const *> ratio = Ratio::all ();
488 Config::instance()->set_default_container (ratio[_default_container->GetSelection()]);
492 ConfigDialog::default_dcp_content_type_changed (wxCommandEvent &)
494 vector<DCPContentType const *> ct = DCPContentType::all ();
495 Config::instance()->set_default_dcp_content_type (ct[_default_dcp_content_type->GetSelection()]);
499 ConfigDialog::issuer_changed (wxCommandEvent &)
501 libdcp::XMLMetadata m = Config::instance()->dcp_metadata ();
502 m.issuer = wx_to_std (_issuer->GetValue ());
503 Config::instance()->set_dcp_metadata (m);
507 ConfigDialog::creator_changed (wxCommandEvent &)
509 libdcp::XMLMetadata m = Config::instance()->dcp_metadata ();
510 m.creator = wx_to_std (_creator->GetValue ());
511 Config::instance()->set_dcp_metadata (m);
515 ConfigDialog::default_j2k_bandwidth_changed (wxCommandEvent &)
517 Config::instance()->set_default_j2k_bandwidth (_default_j2k_bandwidth->GetValue() * 1e6);