/* Copyright (C) 2012 Carl Hetherington This program 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. This program 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 this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ /** @file src/config_dialog.cc * @brief A dialogue to edit DVD-o-matic configuration. */ #include #include #include #include #include "lib/config.h" #include "lib/server.h" #include "lib/format.h" #include "lib/scaler.h" #include "lib/filter.h" #include "config_dialog.h" #include "wx_util.h" #include "filter_dialog.h" #include "server_dialog.h" #include "dir_picker_ctrl.h" #include "dci_metadata_dialog.h" using namespace std; using boost::bind; ConfigDialog::ConfigDialog (wxWindow* parent) : wxDialog (parent, wxID_ANY, _("DVD-o-matic Preferences"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) { wxFlexGridSizer* table = new wxFlexGridSizer (3, 6, 6); table->AddGrowableCol (1, 1); _set_language = new wxCheckBox (this, wxID_ANY, _("Set language")); table->Add (_set_language, 1, wxEXPAND); _language = new wxChoice (this, wxID_ANY); _language->Append (wxT ("English")); _language->Append (wxT ("Français")); _language->Append (wxT ("Italiano")); _language->Append (wxT ("Español")); table->Add (_language, 1, wxEXPAND); table->AddSpacer (0); table->AddSpacer (0); wxStaticText* restart = add_label_to_sizer (table, this, _("(restart DVD-o-matic to see language changes)")); wxFont font = restart->GetFont(); font.SetStyle (wxFONTSTYLE_ITALIC); font.SetPointSize (font.GetPointSize() - 1); restart->SetFont (font); table->AddSpacer (0); add_label_to_sizer (table, this, _("TMS IP address")); _tms_ip = new wxTextCtrl (this, wxID_ANY); table->Add (_tms_ip, 1, wxEXPAND); table->AddSpacer (0); add_label_to_sizer (table, this, _("TMS target path")); _tms_path = new wxTextCtrl (this, wxID_ANY); table->Add (_tms_path, 1, wxEXPAND); table->AddSpacer (0); add_label_to_sizer (table, this, _("TMS user name")); _tms_user = new wxTextCtrl (this, wxID_ANY); table->Add (_tms_user, 1, wxEXPAND); table->AddSpacer (0); add_label_to_sizer (table, this, _("TMS password")); _tms_password = new wxTextCtrl (this, wxID_ANY); table->Add (_tms_password, 1, wxEXPAND); table->AddSpacer (0); add_label_to_sizer (table, this, _("Threads to use for encoding on this host")); _num_local_encoding_threads = new wxSpinCtrl (this); table->Add (_num_local_encoding_threads, 1, wxEXPAND); table->AddSpacer (0); add_label_to_sizer (table, this, _("Default directory for new films")); #ifdef __WXMSW__ _default_directory = new DirPickerCtrl (this); #else _default_directory = new wxDirPickerCtrl (this, wxDD_DIR_MUST_EXIST); #endif table->Add (_default_directory, 1, wxEXPAND); table->AddSpacer (0); add_label_to_sizer (table, this, _("Default DCI name details")); _default_dci_metadata_button = new wxButton (this, wxID_ANY, _("Edit...")); table->Add (_default_dci_metadata_button); table->AddSpacer (1); add_label_to_sizer (table, this, _("Reference scaler for A/B")); _reference_scaler = new wxChoice (this, wxID_ANY); vector const sc = Scaler::all (); for (vector::const_iterator i = sc.begin(); i != sc.end(); ++i) { _reference_scaler->Append (std_to_wx ((*i)->name ())); } table->Add (_reference_scaler, 1, wxEXPAND); table->AddSpacer (0); { add_label_to_sizer (table, this, _("Reference filters for A/B")); wxSizer* s = new wxBoxSizer (wxHORIZONTAL); _reference_filters = new wxStaticText (this, wxID_ANY, wxT ("")); s->Add (_reference_filters, 1, wxEXPAND); _reference_filters_button = new wxButton (this, wxID_ANY, _("Edit...")); s->Add (_reference_filters_button, 0); table->Add (s, 1, wxEXPAND); table->AddSpacer (0); } add_label_to_sizer (table, this, _("Encoding Servers")); _servers = new wxListCtrl (this, wxID_ANY, wxDefaultPosition, wxSize (220, 100), wxLC_REPORT | wxLC_SINGLE_SEL); wxListItem ip; ip.SetId (0); ip.SetText (_("IP address")); ip.SetWidth (120); _servers->InsertColumn (0, ip); ip.SetId (1); ip.SetText (_("Threads")); ip.SetWidth (80); _servers->InsertColumn (1, ip); table->Add (_servers, 1, wxEXPAND | wxALL); { wxSizer* s = new wxBoxSizer (wxVERTICAL); _add_server = new wxButton (this, wxID_ANY, _("Add")); s->Add (_add_server); _edit_server = new wxButton (this, wxID_ANY, _("Edit")); s->Add (_edit_server); _remove_server = new wxButton (this, wxID_ANY, _("Remove")); s->Add (_remove_server); table->Add (s, 0); } Config* config = Config::instance (); _set_language->SetValue (config->language ()); if (config->language().get_value_or ("") == "fr") { _language->SetSelection (1); } else if (config->language().get_value_or ("") == "it") { _language->SetSelection (2); } else if (config->language().get_value_or ("") == "es") { _language->SetSelection (3); } else { _language->SetSelection (0); } setup_language_sensitivity (); _set_language->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (ConfigDialog::set_language_changed), 0, this); _language->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (ConfigDialog::language_changed), 0, this); _tms_ip->SetValue (std_to_wx (config->tms_ip ())); _tms_ip->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (ConfigDialog::tms_ip_changed), 0, this); _tms_path->SetValue (std_to_wx (config->tms_path ())); _tms_path->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (ConfigDialog::tms_path_changed), 0, this); _tms_user->SetValue (std_to_wx (config->tms_user ())); _tms_user->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (ConfigDialog::tms_user_changed), 0, this); _tms_password->SetValue (std_to_wx (config->tms_password ())); _tms_password->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (ConfigDialog::tms_password_changed), 0, this); _num_local_encoding_threads->SetRange (1, 128); _num_local_encoding_threads->SetValue (config->num_local_encoding_threads ()); _num_local_encoding_threads->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (ConfigDialog::num_local_encoding_threads_changed), 0, this); _default_directory->SetPath (std_to_wx (config->default_directory_or (wx_to_std (wxStandardPaths::Get().GetDocumentsDir())))); _default_directory->Connect (wxID_ANY, wxEVT_COMMAND_DIRPICKER_CHANGED, wxCommandEventHandler (ConfigDialog::default_directory_changed), 0, this); _default_dci_metadata_button->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (ConfigDialog::edit_default_dci_metadata_clicked), 0, this); _reference_scaler->SetSelection (Scaler::as_index (config->reference_scaler ())); _reference_scaler->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (ConfigDialog::reference_scaler_changed), 0, this); pair p = Filter::ffmpeg_strings (config->reference_filters ()); _reference_filters->SetLabel (std_to_wx (p.first) + N_(" ") + std_to_wx (p.second)); _reference_filters_button->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (ConfigDialog::edit_reference_filters_clicked), 0, this); vector servers = config->servers (); for (vector::iterator i = servers.begin(); i != servers.end(); ++i) { add_server_to_control (*i); } _add_server->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (ConfigDialog::add_server_clicked), 0, this); _edit_server->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (ConfigDialog::edit_server_clicked), 0, this); _remove_server->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (ConfigDialog::remove_server_clicked), 0, this); _servers->Connect (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler (ConfigDialog::server_selection_changed), 0, this); _servers->Connect (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_DESELECTED, wxListEventHandler (ConfigDialog::server_selection_changed), 0, this); wxListEvent ev; server_selection_changed (ev); wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL); overall_sizer->Add (table, 1, wxEXPAND | wxALL, 6); wxSizer* buttons = CreateSeparatedButtonSizer (wxOK); if (buttons) { overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder()); } SetSizer (overall_sizer); overall_sizer->Layout (); overall_sizer->SetSizeHints (this); } void ConfigDialog::language_changed (wxCommandEvent &) { switch (_language->GetSelection ()) { case 0: Config::instance()->set_language (""); break; case 1: Config::instance()->set_language ("fr"); break; case 2: Config::instance()->set_language ("it"); break; case 3: Config::instance()->set_language ("es"); break; } } void ConfigDialog::tms_ip_changed (wxCommandEvent &) { Config::instance()->set_tms_ip (wx_to_std (_tms_ip->GetValue ())); } void ConfigDialog::tms_path_changed (wxCommandEvent &) { Config::instance()->set_tms_path (wx_to_std (_tms_path->GetValue ())); } void ConfigDialog::tms_user_changed (wxCommandEvent &) { Config::instance()->set_tms_user (wx_to_std (_tms_user->GetValue ())); } void ConfigDialog::tms_password_changed (wxCommandEvent &) { Config::instance()->set_tms_password (wx_to_std (_tms_password->GetValue ())); } void ConfigDialog::num_local_encoding_threads_changed (wxCommandEvent &) { Config::instance()->set_num_local_encoding_threads (_num_local_encoding_threads->GetValue ()); } void ConfigDialog::default_directory_changed (wxCommandEvent &) { Config::instance()->set_default_directory (wx_to_std (_default_directory->GetPath ())); } void ConfigDialog::add_server_to_control (ServerDescription* s) { wxListItem item; int const n = _servers->GetItemCount (); item.SetId (n); _servers->InsertItem (item); _servers->SetItem (n, 0, std_to_wx (s->host_name ())); _servers->SetItem (n, 1, std_to_wx (boost::lexical_cast (s->threads ()))); } void ConfigDialog::add_server_clicked (wxCommandEvent &) { ServerDialog* d = new ServerDialog (this, 0); d->ShowModal (); ServerDescription* s = d->server (); d->Destroy (); add_server_to_control (s); vector o = Config::instance()->servers (); o.push_back (s); Config::instance()->set_servers (o); } void ConfigDialog::edit_server_clicked (wxCommandEvent &) { int i = _servers->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if (i == -1) { return; } wxListItem item; item.SetId (i); item.SetColumn (0); _servers->GetItem (item); vector servers = Config::instance()->servers (); assert (i >= 0 && i < int (servers.size ())); ServerDialog* d = new ServerDialog (this, servers[i]); d->ShowModal (); d->Destroy (); _servers->SetItem (i, 0, std_to_wx (servers[i]->host_name ())); _servers->SetItem (i, 1, std_to_wx (boost::lexical_cast (servers[i]->threads ()))); } void ConfigDialog::remove_server_clicked (wxCommandEvent &) { int i = _servers->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if (i >= 0) { _servers->DeleteItem (i); } vector o = Config::instance()->servers (); o.erase (o.begin() + i); Config::instance()->set_servers (o); } void ConfigDialog::server_selection_changed (wxListEvent &) { int const i = _servers->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); _edit_server->Enable (i >= 0); _remove_server->Enable (i >= 0); } void ConfigDialog::reference_scaler_changed (wxCommandEvent &) { int const n = _reference_scaler->GetSelection (); if (n >= 0) { Config::instance()->set_reference_scaler (Scaler::from_index (n)); } } void ConfigDialog::edit_reference_filters_clicked (wxCommandEvent &) { FilterDialog* d = new FilterDialog (this, Config::instance()->reference_filters ()); d->ActiveChanged.connect (boost::bind (&ConfigDialog::reference_filters_changed, this, _1)); d->ShowModal (); d->Destroy (); } void ConfigDialog::reference_filters_changed (vector f) { Config::instance()->set_reference_filters (f); pair p = Filter::ffmpeg_strings (Config::instance()->reference_filters ()); _reference_filters->SetLabel (std_to_wx (p.first) + N_(" ") + std_to_wx (p.second)); } void ConfigDialog::edit_default_dci_metadata_clicked (wxCommandEvent &) { DCIMetadataDialog* d = new DCIMetadataDialog (this, Config::instance()->default_dci_metadata ()); d->ShowModal (); Config::instance()->set_default_dci_metadata (d->dci_metadata ()); d->Destroy (); } void ConfigDialog::set_language_changed (wxCommandEvent& ev) { setup_language_sensitivity (); if (_set_language->GetValue ()) { language_changed (ev); } else { Config::instance()->unset_language (); } } void ConfigDialog::setup_language_sensitivity () { _language->Enable (_set_language->GetValue ()); }