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 DVD-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, _("DVD-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 DVD-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 Config* config = Config::instance ();
140 _set_language->SetValue (config->language ());
142 if (config->language().get_value_or ("") == "fr") {
143 _language->SetSelection (1);
144 } else if (config->language().get_value_or ("") == "it") {
145 _language->SetSelection (2);
146 } else if (config->language().get_value_or ("") == "es") {
147 _language->SetSelection (3);
148 } else if (config->language().get_value_or ("") == "sv") {
149 _language->SetSelection (4);
151 _language->SetSelection (0);
154 setup_language_sensitivity ();
156 _set_language->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (ConfigDialog::set_language_changed), 0, this);
157 _language->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (ConfigDialog::language_changed), 0, this);
159 _num_local_encoding_threads->SetRange (1, 128);
160 _num_local_encoding_threads->SetValue (config->num_local_encoding_threads ());
161 _num_local_encoding_threads->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (ConfigDialog::num_local_encoding_threads_changed), 0, this);
163 _default_still_length->SetRange (1, 3600);
164 _default_still_length->SetValue (config->default_still_length ());
165 _default_still_length->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (ConfigDialog::default_still_length_changed), 0, this);
167 _default_directory->SetPath (std_to_wx (config->default_directory_or (wx_to_std (wxStandardPaths::Get().GetDocumentsDir()))));
168 _default_directory->Connect (wxID_ANY, wxEVT_COMMAND_DIRPICKER_CHANGED, wxCommandEventHandler (ConfigDialog::default_directory_changed), 0, this);
170 _default_dci_metadata_button->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (ConfigDialog::edit_default_dci_metadata_clicked), 0, this);
172 vector<Ratio const *> ratio = Ratio::all ();
174 for (vector<Ratio const *>::iterator i = ratio.begin(); i != ratio.end(); ++i) {
175 _default_container->Append (std_to_wx ((*i)->nickname ()));
176 if (*i == config->default_container ()) {
177 _default_container->SetSelection (n);
182 _default_container->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (ConfigDialog::default_container_changed), 0, this);
184 vector<DCPContentType const *> const ct = DCPContentType::all ();
186 for (vector<DCPContentType const *>::const_iterator i = ct.begin(); i != ct.end(); ++i) {
187 _default_dcp_content_type->Append (std_to_wx ((*i)->pretty_name ()));
188 if (*i == config->default_dcp_content_type ()) {
189 _default_dcp_content_type->SetSelection (n);
194 _default_dcp_content_type->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (ConfigDialog::default_dcp_content_type_changed), 0, this);
198 ConfigDialog::make_tms_panel ()
200 _tms_panel = new wxPanel (_notebook);
201 wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
202 _tms_panel->SetSizer (s);
204 wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
205 table->AddGrowableCol (1, 1);
206 s->Add (table, 1, wxALL | wxEXPAND, 8);
208 add_label_to_sizer (table, _tms_panel, _("IP address"), true);
209 _tms_ip = new wxTextCtrl (_tms_panel, wxID_ANY);
210 table->Add (_tms_ip, 1, wxEXPAND);
212 add_label_to_sizer (table, _tms_panel, _("Target path"), true);
213 _tms_path = new wxTextCtrl (_tms_panel, wxID_ANY);
214 table->Add (_tms_path, 1, wxEXPAND);
216 add_label_to_sizer (table, _tms_panel, _("User name"), true);
217 _tms_user = new wxTextCtrl (_tms_panel, wxID_ANY);
218 table->Add (_tms_user, 1, wxEXPAND);
220 add_label_to_sizer (table, _tms_panel, _("Password"), true);
221 _tms_password = new wxTextCtrl (_tms_panel, wxID_ANY);
222 table->Add (_tms_password, 1, wxEXPAND);
224 Config* config = Config::instance ();
226 _tms_ip->SetValue (std_to_wx (config->tms_ip ()));
227 _tms_ip->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (ConfigDialog::tms_ip_changed), 0, this);
228 _tms_path->SetValue (std_to_wx (config->tms_path ()));
229 _tms_path->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (ConfigDialog::tms_path_changed), 0, this);
230 _tms_user->SetValue (std_to_wx (config->tms_user ()));
231 _tms_user->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (ConfigDialog::tms_user_changed), 0, this);
232 _tms_password->SetValue (std_to_wx (config->tms_password ()));
233 _tms_password->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (ConfigDialog::tms_password_changed), 0, this);
237 ConfigDialog::make_metadata_panel ()
239 _metadata_panel = new wxPanel (_notebook);
240 wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
241 _metadata_panel->SetSizer (s);
243 wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
244 table->AddGrowableCol (1, 1);
245 s->Add (table, 1, wxALL | wxEXPAND, 8);
247 add_label_to_sizer (table, _metadata_panel, _("Issuer"), true);
248 _issuer = new wxTextCtrl (_metadata_panel, wxID_ANY);
249 table->Add (_issuer, 1, wxEXPAND);
251 add_label_to_sizer (table, _metadata_panel, _("Creator"), true);
252 _creator = new wxTextCtrl (_metadata_panel, wxID_ANY);
253 table->Add (_creator, 1, wxEXPAND);
255 Config* config = Config::instance ();
257 _issuer->SetValue (std_to_wx (config->dcp_metadata().issuer));
258 _issuer->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (ConfigDialog::issuer_changed), 0, this);
259 _creator->SetValue (std_to_wx (config->dcp_metadata().creator));
260 _creator->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (ConfigDialog::creator_changed), 0, this);
264 ConfigDialog::make_servers_panel ()
266 _servers_panel = new wxPanel (_notebook);
267 wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
268 _servers_panel->SetSizer (s);
270 wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
271 table->AddGrowableCol (0, 1);
272 s->Add (table, 1, wxALL | wxEXPAND, 8);
274 Config* config = Config::instance ();
276 _servers = new wxListCtrl (_servers_panel, wxID_ANY, wxDefaultPosition, wxSize (220, 100), wxLC_REPORT | wxLC_SINGLE_SEL);
279 ip.SetText (_("IP address"));
281 _servers->InsertColumn (0, ip);
283 ip.SetText (_("Threads"));
285 _servers->InsertColumn (1, ip);
286 table->Add (_servers, 1, wxEXPAND | wxALL);
289 wxSizer* s = new wxBoxSizer (wxVERTICAL);
290 _add_server = new wxButton (_servers_panel, wxID_ANY, _("Add"));
291 s->Add (_add_server, 0, wxTOP | wxBOTTOM, 2);
292 _edit_server = new wxButton (_servers_panel, wxID_ANY, _("Edit"));
293 s->Add (_edit_server, 0, wxTOP | wxBOTTOM, 2);
294 _remove_server = new wxButton (_servers_panel, wxID_ANY, _("Remove"));
295 s->Add (_remove_server, 0, wxTOP | wxBOTTOM, 2);
299 vector<ServerDescription*> servers = config->servers ();
300 for (vector<ServerDescription*>::iterator i = servers.begin(); i != servers.end(); ++i) {
301 add_server_to_control (*i);
304 _add_server->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (ConfigDialog::add_server_clicked), 0, this);
305 _edit_server->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (ConfigDialog::edit_server_clicked), 0, this);
306 _remove_server->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (ConfigDialog::remove_server_clicked), 0, this);
308 _servers->Connect (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler (ConfigDialog::server_selection_changed), 0, this);
309 _servers->Connect (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_DESELECTED, wxListEventHandler (ConfigDialog::server_selection_changed), 0, this);
311 server_selection_changed (ev);
315 ConfigDialog::language_changed (wxCommandEvent &)
317 switch (_language->GetSelection ()) {
319 Config::instance()->set_language ("en");
322 Config::instance()->set_language ("fr");
325 Config::instance()->set_language ("it");
328 Config::instance()->set_language ("es");
331 Config::instance()->set_language ("sv");
337 ConfigDialog::tms_ip_changed (wxCommandEvent &)
339 Config::instance()->set_tms_ip (wx_to_std (_tms_ip->GetValue ()));
343 ConfigDialog::tms_path_changed (wxCommandEvent &)
345 Config::instance()->set_tms_path (wx_to_std (_tms_path->GetValue ()));
349 ConfigDialog::tms_user_changed (wxCommandEvent &)
351 Config::instance()->set_tms_user (wx_to_std (_tms_user->GetValue ()));
355 ConfigDialog::tms_password_changed (wxCommandEvent &)
357 Config::instance()->set_tms_password (wx_to_std (_tms_password->GetValue ()));
361 ConfigDialog::num_local_encoding_threads_changed (wxCommandEvent &)
363 Config::instance()->set_num_local_encoding_threads (_num_local_encoding_threads->GetValue ());
367 ConfigDialog::default_directory_changed (wxCommandEvent &)
369 Config::instance()->set_default_directory (wx_to_std (_default_directory->GetPath ()));
373 ConfigDialog::add_server_to_control (ServerDescription* s)
376 int const n = _servers->GetItemCount ();
378 _servers->InsertItem (item);
379 _servers->SetItem (n, 0, std_to_wx (s->host_name ()));
380 _servers->SetItem (n, 1, std_to_wx (boost::lexical_cast<string> (s->threads ())));
384 ConfigDialog::add_server_clicked (wxCommandEvent &)
386 ServerDialog* d = new ServerDialog (this, 0);
388 ServerDescription* s = d->server ();
391 add_server_to_control (s);
392 vector<ServerDescription*> o = Config::instance()->servers ();
394 Config::instance()->set_servers (o);
398 ConfigDialog::edit_server_clicked (wxCommandEvent &)
400 int i = _servers->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
408 _servers->GetItem (item);
410 vector<ServerDescription*> servers = Config::instance()->servers ();
411 assert (i >= 0 && i < int (servers.size ()));
413 ServerDialog* d = new ServerDialog (this, servers[i]);
417 _servers->SetItem (i, 0, std_to_wx (servers[i]->host_name ()));
418 _servers->SetItem (i, 1, std_to_wx (boost::lexical_cast<string> (servers[i]->threads ())));
422 ConfigDialog::remove_server_clicked (wxCommandEvent &)
424 int i = _servers->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
426 _servers->DeleteItem (i);
429 vector<ServerDescription*> o = Config::instance()->servers ();
430 o.erase (o.begin() + i);
431 Config::instance()->set_servers (o);
435 ConfigDialog::server_selection_changed (wxListEvent &)
437 int const i = _servers->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
438 _edit_server->Enable (i >= 0);
439 _remove_server->Enable (i >= 0);
443 ConfigDialog::edit_default_dci_metadata_clicked (wxCommandEvent &)
445 DCIMetadataDialog* d = new DCIMetadataDialog (this, Config::instance()->default_dci_metadata ());
447 Config::instance()->set_default_dci_metadata (d->dci_metadata ());
452 ConfigDialog::set_language_changed (wxCommandEvent& ev)
454 setup_language_sensitivity ();
455 if (_set_language->GetValue ()) {
456 language_changed (ev);
458 Config::instance()->unset_language ();
463 ConfigDialog::setup_language_sensitivity ()
465 _language->Enable (_set_language->GetValue ());
469 ConfigDialog::default_still_length_changed (wxCommandEvent &)
471 Config::instance()->set_default_still_length (_default_still_length->GetValue ());
475 ConfigDialog::default_container_changed (wxCommandEvent &)
477 vector<Ratio const *> ratio = Ratio::all ();
478 Config::instance()->set_default_container (ratio[_default_container->GetSelection()]);
482 ConfigDialog::default_dcp_content_type_changed (wxCommandEvent &)
484 vector<DCPContentType const *> ct = DCPContentType::all ();
485 Config::instance()->set_default_dcp_content_type (ct[_default_dcp_content_type->GetSelection()]);
489 ConfigDialog::issuer_changed (wxCommandEvent &)
491 libdcp::XMLMetadata m = Config::instance()->dcp_metadata ();
492 m.issuer = wx_to_std (_issuer->GetValue ());
493 Config::instance()->set_dcp_metadata (m);
497 ConfigDialog::creator_changed (wxCommandEvent &)
499 libdcp::XMLMetadata m = Config::instance()->dcp_metadata ();
500 m.creator = wx_to_std (_creator->GetValue ());
501 Config::instance()->set_dcp_metadata (m);