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 "lib/config.h"
27 #include "lib/server.h"
28 #include "lib/screen.h"
29 #include "lib/format.h"
30 #include "lib/scaler.h"
31 #include "lib/filter.h"
32 #include "config_dialog.h"
34 #include "filter_dialog.h"
35 #include "server_dialog.h"
38 using namespace boost;
40 ConfigDialog::ConfigDialog (wxWindow* parent)
41 : wxDialog (parent, wxID_ANY, _("DVD-o-matic Configuration"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
43 wxFlexGridSizer* table = new wxFlexGridSizer (3, 6, 6);
44 table->AddGrowableCol (1, 1);
46 add_label_to_sizer (table, this, "TMS IP address");
47 _tms_ip = new wxTextCtrl (this, wxID_ANY);
48 table->Add (_tms_ip, 1, wxEXPAND);
51 add_label_to_sizer (table, this, "TMS target path");
52 _tms_path = new wxTextCtrl (this, wxID_ANY);
53 table->Add (_tms_path, 1, wxEXPAND);
56 add_label_to_sizer (table, this, "TMS user name");
57 _tms_user = new wxTextCtrl (this, wxID_ANY);
58 table->Add (_tms_user, 1, wxEXPAND);
61 add_label_to_sizer (table, this, "TMS password");
62 _tms_password = new wxTextCtrl (this, wxID_ANY);
63 table->Add (_tms_password, 1, wxEXPAND);
66 add_label_to_sizer (table, this, "Threads to use for encoding on this host");
67 _num_local_encoding_threads = new wxSpinCtrl (this);
68 table->Add (_num_local_encoding_threads, 1, wxEXPAND);
71 add_label_to_sizer (table, this, "Colour look-up table");
72 _colour_lut = new wxComboBox (this, wxID_ANY);
73 for (int i = 0; i < 2; ++i) {
74 _colour_lut->Append (std_to_wx (colour_lut_index_to_name (i)));
76 _colour_lut->SetSelection (0);
77 table->Add (_colour_lut, 1, wxEXPAND);
80 add_label_to_sizer (table, this, "JPEG2000 bandwidth");
81 _j2k_bandwidth = new wxSpinCtrl (this, wxID_ANY);
82 table->Add (_j2k_bandwidth, 1, wxEXPAND);
83 add_label_to_sizer (table, this, "MBps");
85 add_label_to_sizer (table, this, "Reference scaler for A/B");
86 _reference_scaler = new wxComboBox (this, wxID_ANY);
87 vector<Scaler const *> const sc = Scaler::all ();
88 for (vector<Scaler const *>::const_iterator i = sc.begin(); i != sc.end(); ++i) {
89 _reference_scaler->Append (std_to_wx ((*i)->name ()));
92 table->Add (_reference_scaler, 1, wxEXPAND);
96 add_label_to_sizer (table, this, "Reference filters for A/B");
97 wxSizer* s = new wxBoxSizer (wxHORIZONTAL);
98 _reference_filters = new wxStaticText (this, wxID_ANY, wxT (""));
99 s->Add (_reference_filters, 1, wxEXPAND);
100 _reference_filters_button = new wxButton (this, wxID_ANY, _("Edit..."));
101 s->Add (_reference_filters_button, 0);
102 table->Add (s, 1, wxEXPAND);
103 table->AddSpacer (0);
106 add_label_to_sizer (table, this, "Encoding Servers");
107 _servers = new wxListCtrl (this, wxID_ANY, wxDefaultPosition, wxSize (220, 100), wxLC_REPORT | wxLC_SINGLE_SEL);
110 ip.SetText (_("IP address"));
112 _servers->InsertColumn (0, ip);
114 ip.SetText (_("Threads"));
116 _servers->InsertColumn (1, ip);
117 table->Add (_servers, 1, wxEXPAND | wxALL);
120 wxSizer* s = new wxBoxSizer (wxVERTICAL);
121 _add_server = new wxButton (this, wxID_ANY, _("Add"));
122 s->Add (_add_server);
123 _edit_server = new wxButton (this, wxID_ANY, _("Edit"));
124 s->Add (_edit_server);
125 _remove_server = new wxButton (this, wxID_ANY, _("Remove"));
126 s->Add (_remove_server);
130 Config* config = Config::instance ();
132 _tms_ip->SetValue (std_to_wx (config->tms_ip ()));
133 _tms_ip->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (ConfigDialog::tms_ip_changed), 0, this);
134 _tms_path->SetValue (std_to_wx (config->tms_path ()));
135 _tms_path->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (ConfigDialog::tms_path_changed), 0, this);
136 _tms_user->SetValue (std_to_wx (config->tms_user ()));
137 _tms_user->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (ConfigDialog::tms_user_changed), 0, this);
138 _tms_password->SetValue (std_to_wx (config->tms_password ()));
139 _tms_password->Connect (wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler (ConfigDialog::tms_password_changed), 0, this);
141 _num_local_encoding_threads->SetRange (1, 128);
142 _num_local_encoding_threads->SetValue (config->num_local_encoding_threads ());
143 _num_local_encoding_threads->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (ConfigDialog::num_local_encoding_threads_changed), 0, this);
145 _colour_lut->Connect (wxID_ANY, wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEventHandler (ConfigDialog::colour_lut_changed), 0, this);
147 _j2k_bandwidth->SetRange (50, 250);
148 _j2k_bandwidth->SetValue (rint ((double) config->j2k_bandwidth() / 1e6));
149 _j2k_bandwidth->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (ConfigDialog::j2k_bandwidth_changed), 0, this);
151 _reference_scaler->SetSelection (Scaler::as_index (config->reference_scaler ()));
152 _reference_scaler->Connect (wxID_ANY, wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEventHandler (ConfigDialog::reference_scaler_changed), 0, this);
154 pair<string, string> p = Filter::ffmpeg_strings (config->reference_filters ());
155 _reference_filters->SetLabel (std_to_wx (p.first + " " + p.second));
156 _reference_filters_button->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (ConfigDialog::edit_reference_filters_clicked), 0, this);
158 vector<ServerDescription*> servers = config->servers ();
159 for (vector<ServerDescription*>::iterator i = servers.begin(); i != servers.end(); ++i) {
160 add_server_to_control (*i);
163 _add_server->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (ConfigDialog::add_server_clicked), 0, this);
164 _edit_server->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (ConfigDialog::edit_server_clicked), 0, this);
165 _remove_server->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (ConfigDialog::remove_server_clicked), 0, this);
167 _servers->Connect (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_SELECTED, wxListEventHandler (ConfigDialog::server_selection_changed), 0, this);
168 _servers->Connect (wxID_ANY, wxEVT_COMMAND_LIST_ITEM_DESELECTED, wxListEventHandler (ConfigDialog::server_selection_changed), 0, this);
170 server_selection_changed (ev);
172 wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
173 overall_sizer->Add (table, 1, wxEXPAND | wxALL, 6);
175 wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
177 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
180 SetSizer (overall_sizer);
181 overall_sizer->Layout ();
182 overall_sizer->SetSizeHints (this);
186 ConfigDialog::tms_ip_changed (wxCommandEvent &)
188 Config::instance()->set_tms_ip (wx_to_std (_tms_ip->GetValue ()));
192 ConfigDialog::tms_path_changed (wxCommandEvent &)
194 Config::instance()->set_tms_path (wx_to_std (_tms_path->GetValue ()));
198 ConfigDialog::tms_user_changed (wxCommandEvent &)
200 Config::instance()->set_tms_user (wx_to_std (_tms_user->GetValue ()));
204 ConfigDialog::tms_password_changed (wxCommandEvent &)
206 Config::instance()->set_tms_password (wx_to_std (_tms_password->GetValue ()));
210 ConfigDialog::num_local_encoding_threads_changed (wxCommandEvent &)
212 Config::instance()->set_num_local_encoding_threads (_num_local_encoding_threads->GetValue ());
216 ConfigDialog::colour_lut_changed (wxCommandEvent &)
218 Config::instance()->set_colour_lut_index (_colour_lut->GetSelection ());
222 ConfigDialog::j2k_bandwidth_changed (wxCommandEvent &)
224 Config::instance()->set_j2k_bandwidth (_j2k_bandwidth->GetValue() * 1e6);
228 ConfigDialog::add_server_to_control (ServerDescription* s)
231 int const n = _servers->GetItemCount ();
233 _servers->InsertItem (item);
234 _servers->SetItem (n, 0, std_to_wx (s->host_name ()));
235 _servers->SetItem (n, 1, std_to_wx (boost::lexical_cast<string> (s->threads ())));
239 ConfigDialog::add_server_clicked (wxCommandEvent &)
241 ServerDialog* d = new ServerDialog (this, 0);
243 ServerDescription* s = d->server ();
246 add_server_to_control (s);
247 vector<ServerDescription*> o = Config::instance()->servers ();
249 Config::instance()->set_servers (o);
253 ConfigDialog::edit_server_clicked (wxCommandEvent &)
255 int i = _servers->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
263 _servers->GetItem (item);
265 vector<ServerDescription*> servers = Config::instance()->servers ();
266 assert (i >= 0 && i < int (servers.size ()));
268 ServerDialog* d = new ServerDialog (this, servers[i]);
272 _servers->SetItem (i, 0, std_to_wx (servers[i]->host_name ()));
273 _servers->SetItem (i, 1, std_to_wx (boost::lexical_cast<string> (servers[i]->threads ())));
277 ConfigDialog::remove_server_clicked (wxCommandEvent &)
279 int i = _servers->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
281 _servers->DeleteItem (i);
284 vector<ServerDescription*> o = Config::instance()->servers ();
285 o.erase (o.begin() + i);
286 Config::instance()->set_servers (o);
290 ConfigDialog::server_selection_changed (wxListEvent& ev)
292 int const i = _servers->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
293 _edit_server->Enable (i >= 0);
294 _remove_server->Enable (i >= 0);
298 ConfigDialog::reference_scaler_changed (wxCommandEvent &)
300 int const n = _reference_scaler->GetSelection ();
302 Config::instance()->set_reference_scaler (Scaler::from_index (n));
307 ConfigDialog::edit_reference_filters_clicked (wxCommandEvent &)
309 FilterDialog* d = new FilterDialog (this, Config::instance()->reference_filters ());
310 d->ActiveChanged.connect (sigc::mem_fun (*this, &ConfigDialog::reference_filters_changed));
316 ConfigDialog::reference_filters_changed (vector<Filter const *> f)
318 Config::instance()->set_reference_filters (f);
319 pair<string, string> p = Filter::ffmpeg_strings (Config::instance()->reference_filters ());
320 _reference_filters->SetLabel (std_to_wx (p.first + " " + p.second));