7fe81de4eb3297a3f1bcef75f17e744d6b614835
[dcpomatic.git] / src / wx / config_dialog.cc
1 /*
2     Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 /** @file src/config_dialog.cc
21  *  @brief A dialogue to edit DCP-o-matic configuration.
22  */
23
24 #include <iostream>
25 #include <boost/lexical_cast.hpp>
26 #include <boost/filesystem.hpp>
27 #include <wx/stdpaths.h>
28 #include <wx/preferences.h>
29 #include <wx/filepicker.h>
30 #include <wx/spinctrl.h>
31 #include <libdcp/colour_matrix.h>
32 #include "lib/config.h"
33 #include "lib/ratio.h"
34 #include "lib/scaler.h"
35 #include "lib/filter.h"
36 #include "lib/dcp_content_type.h"
37 #include "lib/colour_conversion.h"
38 #include "config_dialog.h"
39 #include "wx_util.h"
40 #include "editable_list.h"
41 #include "filter_dialog.h"
42 #include "dir_picker_ctrl.h"
43 #include "dci_metadata_dialog.h"
44 #include "preset_colour_conversion_dialog.h"
45 #include "server_dialog.h"
46
47 using std::vector;
48 using std::string;
49 using std::list;
50 using std::cout;
51 using boost::bind;
52 using boost::shared_ptr;
53 using boost::lexical_cast;
54
55 class GeneralPage : public wxStockPreferencesPage
56 {
57 public:
58         GeneralPage ()
59                 : wxStockPreferencesPage (Kind_General)
60         {}
61
62         wxWindow* CreateWindow (wxWindow* parent)
63         {
64                 wxPanel* panel = new wxPanel (parent);
65                 wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
66                 panel->SetSizer (s);
67
68                 wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
69                 table->AddGrowableCol (1, 1);
70                 s->Add (table, 1, wxALL | wxEXPAND, 8);
71                 
72                 _set_language = new wxCheckBox (panel, wxID_ANY, _("Set language"));
73                 table->Add (_set_language, 1);
74                 _language = new wxChoice (panel, wxID_ANY);
75                 _language->Append (wxT ("English"));
76                 _language->Append (wxT ("Français"));
77                 _language->Append (wxT ("Italiano"));
78                 _language->Append (wxT ("Español"));
79                 _language->Append (wxT ("Svenska"));
80                 _language->Append (wxT ("Deutsch"));
81                 table->Add (_language);
82                 
83                 wxStaticText* restart = add_label_to_sizer (table, panel, _("(restart DCP-o-matic to see language changes)"), false);
84                 wxFont font = restart->GetFont();
85                 font.SetStyle (wxFONTSTYLE_ITALIC);
86                 font.SetPointSize (font.GetPointSize() - 1);
87                 restart->SetFont (font);
88                 table->AddSpacer (0);
89                 
90                 add_label_to_sizer (table, panel, _("Threads to use for encoding on this host"), true);
91                 _num_local_encoding_threads = new wxSpinCtrl (panel);
92                 table->Add (_num_local_encoding_threads, 1);
93                 
94                 add_label_to_sizer (table, panel, _("Outgoing mail server"), true);
95                 _mail_server = new wxTextCtrl (panel, wxID_ANY);
96                 table->Add (_mail_server, 1, wxEXPAND | wxALL);
97                 
98                 add_label_to_sizer (table, panel, _("Mail user name"), true);
99                 _mail_user = new wxTextCtrl (panel, wxID_ANY);
100                 table->Add (_mail_user, 1, wxEXPAND | wxALL);
101                 
102                 add_label_to_sizer (table, panel, _("Mail password"), true);
103                 _mail_password = new wxTextCtrl (panel, wxID_ANY);
104                 table->Add (_mail_password, 1, wxEXPAND | wxALL);
105                 
106                 wxStaticText* plain = add_label_to_sizer (table, panel, _("(password will be stored on disk in plaintext)"), false);
107                 plain->SetFont (font);
108                 table->AddSpacer (0);
109                 
110                 add_label_to_sizer (table, panel, _("From address for KDM emails"), true);
111                 _kdm_from = new wxTextCtrl (panel, wxID_ANY);
112                 table->Add (_kdm_from, 1, wxEXPAND | wxALL);
113                 
114                 _check_for_updates = new wxCheckBox (panel, wxID_ANY, _("Check for updates on startup"));
115                 table->Add (_check_for_updates, 1, wxEXPAND | wxALL);
116                 table->AddSpacer (0);
117                 
118                 _check_for_test_updates = new wxCheckBox (panel, wxID_ANY, _("Check for testing updates as well as stable ones"));
119                 table->Add (_check_for_test_updates, 1, wxEXPAND | wxALL);
120                 table->AddSpacer (0);
121                 
122                 Config* config = Config::instance ();
123                 
124                 _set_language->SetValue (config->language ());
125                 
126                 if (config->language().get_value_or ("") == "fr") {
127                         _language->SetSelection (1);
128                 } else if (config->language().get_value_or ("") == "it") {
129                 _language->SetSelection (2);
130                 } else if (config->language().get_value_or ("") == "es") {
131                         _language->SetSelection (3);
132                 } else if (config->language().get_value_or ("") == "sv") {
133                         _language->SetSelection (4);
134                 } else if (config->language().get_value_or ("") == "de") {
135                         _language->SetSelection (5);
136                 } else {
137                         _language->SetSelection (0);
138                 }
139                 
140                 setup_language_sensitivity ();
141                 
142                 _set_language->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&GeneralPage::set_language_changed, this));
143                 _language->Bind     (wxEVT_COMMAND_CHOICE_SELECTED,  boost::bind (&GeneralPage::language_changed,     this));
144                 
145                 _num_local_encoding_threads->SetRange (1, 128);
146                 _num_local_encoding_threads->SetValue (config->num_local_encoding_threads ());
147                 _num_local_encoding_threads->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&GeneralPage::num_local_encoding_threads_changed, this));
148                 
149                 _mail_server->SetValue (std_to_wx (config->mail_server ()));
150                 _mail_server->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&GeneralPage::mail_server_changed, this));
151                 _mail_user->SetValue (std_to_wx (config->mail_user ()));
152                 _mail_user->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&GeneralPage::mail_user_changed, this));
153                 _mail_password->SetValue (std_to_wx (config->mail_password ()));
154                 _mail_password->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&GeneralPage::mail_password_changed, this));
155                 _kdm_from->SetValue (std_to_wx (config->kdm_from ()));
156                 _kdm_from->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&GeneralPage::kdm_from_changed, this));
157                 _check_for_updates->SetValue (config->check_for_updates ());
158                 _check_for_updates->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&GeneralPage::check_for_updates_changed, this));
159                 _check_for_test_updates->SetValue (config->check_for_test_updates ());
160                 _check_for_test_updates->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&GeneralPage::check_for_test_updates_changed, this));
161                 
162                 return panel;
163         }
164
165 private:        
166         void setup_language_sensitivity ()
167         {
168                 _language->Enable (_set_language->GetValue ());
169         }
170
171         void set_language_changed ()
172         {
173                 setup_language_sensitivity ();
174                 if (_set_language->GetValue ()) {
175                         language_changed ();
176                 } else {
177                         Config::instance()->unset_language ();
178                 }
179         }
180
181         void language_changed ()
182         {
183                 switch (_language->GetSelection ()) {
184                 case 0:
185                         Config::instance()->set_language ("en");
186                         break;
187                 case 1:
188                         Config::instance()->set_language ("fr");
189                         break;
190                 case 2:
191                         Config::instance()->set_language ("it");
192                         break;
193                 case 3:
194                         Config::instance()->set_language ("es");
195                         break;
196                 case 4:
197                         Config::instance()->set_language ("sv");
198                         break;
199                 case 5:
200                         Config::instance()->set_language ("de");
201                         break;
202                 }
203         }
204         
205         void mail_server_changed ()
206         {
207                 Config::instance()->set_mail_server (wx_to_std (_mail_server->GetValue ()));
208         }
209         
210         void mail_user_changed ()
211         {
212                 Config::instance()->set_mail_user (wx_to_std (_mail_user->GetValue ()));
213         }
214         
215         void mail_password_changed ()
216         {
217                 Config::instance()->set_mail_password (wx_to_std (_mail_password->GetValue ()));
218         }
219         
220         void kdm_from_changed ()
221         {
222                 Config::instance()->set_kdm_from (wx_to_std (_kdm_from->GetValue ()));
223         }
224
225         void check_for_updates_changed ()
226         {
227                 Config::instance()->set_check_for_updates (_check_for_updates->GetValue ());
228         }
229         
230         void check_for_test_updates_changed ()
231         {
232                 Config::instance()->set_check_for_test_updates (_check_for_test_updates->GetValue ());
233         }
234
235         void num_local_encoding_threads_changed ()
236         {
237                 Config::instance()->set_num_local_encoding_threads (_num_local_encoding_threads->GetValue ());
238         }
239         
240         wxCheckBox* _set_language;
241         wxChoice* _language;
242         wxSpinCtrl* _num_local_encoding_threads;
243         wxTextCtrl* _mail_server;
244         wxTextCtrl* _mail_user;
245         wxTextCtrl* _mail_password;
246         wxTextCtrl* _kdm_from;
247         wxCheckBox* _check_for_updates;
248         wxCheckBox* _check_for_test_updates;
249 };
250
251 class DefaultsPage : public wxPreferencesPage
252 {
253 public:
254         wxString GetName () const
255         {
256                 return _("Defaults");
257         }
258
259 #ifdef DCPOMATIC_OSX    
260         wxBitmap GetLargeIcon () const
261         {
262                 return wxBitmap ("defaults", wxBITMAP_TYPE_PNG_RESOURCE);
263         }
264 #endif  
265
266         wxWindow* CreateWindow (wxWindow* parent)
267         {
268                 wxPanel* panel = new wxPanel (parent);
269                 wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
270                 panel->SetSizer (s);
271
272                 wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
273                 table->AddGrowableCol (1, 1);
274                 s->Add (table, 1, wxALL | wxEXPAND, 8);
275                 
276                 {
277                         add_label_to_sizer (table, panel, _("Default duration of still images"), true);
278                         wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
279                         _default_still_length = new wxSpinCtrl (panel);
280                         s->Add (_default_still_length);
281                         add_label_to_sizer (s, panel, _("s"), false);
282                         table->Add (s, 1);
283                 }
284                 
285                 add_label_to_sizer (table, panel, _("Default directory for new films"), true);
286 #ifdef DCPOMATIC_USE_OWN_DIR_PICKER
287                 _default_directory = new DirPickerCtrl (panel);
288 #else   
289                 _default_directory = new wxDirPickerCtrl (panel, wxDD_DIR_MUST_EXIST);
290 #endif
291                 table->Add (_default_directory, 1, wxEXPAND);
292                 
293                 add_label_to_sizer (table, panel, _("Default DCI name details"), true);
294                 _default_dci_metadata_button = new wxButton (panel, wxID_ANY, _("Edit..."));
295                 table->Add (_default_dci_metadata_button);
296                 
297                 add_label_to_sizer (table, panel, _("Default container"), true);
298                 _default_container = new wxChoice (panel, wxID_ANY);
299                 table->Add (_default_container);
300                 
301                 add_label_to_sizer (table, panel, _("Default content type"), true);
302                 _default_dcp_content_type = new wxChoice (panel, wxID_ANY);
303                 table->Add (_default_dcp_content_type);
304                 
305                 {
306                         add_label_to_sizer (table, panel, _("Default JPEG2000 bandwidth"), true);
307                         wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
308                         _default_j2k_bandwidth = new wxSpinCtrl (panel);
309                         s->Add (_default_j2k_bandwidth);
310                         add_label_to_sizer (s, panel, _("Mbit/s"), false);
311                         table->Add (s, 1);
312                 }
313                 
314                 {
315                         add_label_to_sizer (table, panel, _("Default audio delay"), true);
316                         wxBoxSizer* s = new wxBoxSizer (wxHORIZONTAL);
317                         _default_audio_delay = new wxSpinCtrl (panel);
318                         s->Add (_default_audio_delay);
319                         add_label_to_sizer (s, panel, _("ms"), false);
320                         table->Add (s, 1);
321                 }
322                 
323                 Config* config = Config::instance ();
324                 
325                 _default_still_length->SetRange (1, 3600);
326                 _default_still_length->SetValue (config->default_still_length ());
327                 _default_still_length->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&DefaultsPage::default_still_length_changed, this));
328                 
329                 _default_directory->SetPath (std_to_wx (config->default_directory_or (wx_to_std (wxStandardPaths::Get().GetDocumentsDir())).string ()));
330                 _default_directory->Bind (wxEVT_COMMAND_DIRPICKER_CHANGED, boost::bind (&DefaultsPage::default_directory_changed, this));
331                 
332                 _default_dci_metadata_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&DefaultsPage::edit_default_dci_metadata_clicked, this, parent));
333                 
334                 vector<Ratio const *> ratio = Ratio::all ();
335                 int n = 0;
336                 for (vector<Ratio const *>::iterator i = ratio.begin(); i != ratio.end(); ++i) {
337                         _default_container->Append (std_to_wx ((*i)->nickname ()));
338                         if (*i == config->default_container ()) {
339                                 _default_container->SetSelection (n);
340                         }
341                         ++n;
342                 }
343                 
344                 _default_container->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DefaultsPage::default_container_changed, this));
345                 
346                 vector<DCPContentType const *> const ct = DCPContentType::all ();
347                 n = 0;
348                 for (vector<DCPContentType const *>::const_iterator i = ct.begin(); i != ct.end(); ++i) {
349                         _default_dcp_content_type->Append (std_to_wx ((*i)->pretty_name ()));
350                         if (*i == config->default_dcp_content_type ()) {
351                                 _default_dcp_content_type->SetSelection (n);
352                         }
353                         ++n;
354                 }
355                 
356                 _default_dcp_content_type->Bind (wxEVT_COMMAND_CHOICE_SELECTED, boost::bind (&DefaultsPage::default_dcp_content_type_changed, this));
357                 
358                 _default_j2k_bandwidth->SetRange (50, 250);
359                 _default_j2k_bandwidth->SetValue (config->default_j2k_bandwidth() / 1000000);
360                 _default_j2k_bandwidth->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&DefaultsPage::default_j2k_bandwidth_changed, this));
361                 
362                 _default_audio_delay->SetRange (-1000, 1000);
363                 _default_audio_delay->SetValue (config->default_audio_delay ());
364                 _default_audio_delay->Bind (wxEVT_COMMAND_SPINCTRL_UPDATED, boost::bind (&DefaultsPage::default_audio_delay_changed, this));
365
366                 return panel;
367         }
368
369 private:
370         void default_j2k_bandwidth_changed ()
371         {
372                 Config::instance()->set_default_j2k_bandwidth (_default_j2k_bandwidth->GetValue() * 1000000);
373         }
374         
375         void default_audio_delay_changed ()
376         {
377                 Config::instance()->set_default_audio_delay (_default_audio_delay->GetValue());
378         }
379
380         void default_directory_changed ()
381         {
382                 Config::instance()->set_default_directory (wx_to_std (_default_directory->GetPath ()));
383         }
384
385         void edit_default_dci_metadata_clicked (wxWindow* parent)
386         {
387                 DCIMetadataDialog* d = new DCIMetadataDialog (parent, Config::instance()->default_dci_metadata ());
388                 d->ShowModal ();
389                 Config::instance()->set_default_dci_metadata (d->dci_metadata ());
390                 d->Destroy ();
391         }
392
393         void default_still_length_changed ()
394         {
395                 Config::instance()->set_default_still_length (_default_still_length->GetValue ());
396         }
397         
398         void default_container_changed ()
399         {
400                 vector<Ratio const *> ratio = Ratio::all ();
401                 Config::instance()->set_default_container (ratio[_default_container->GetSelection()]);
402         }
403         
404         void default_dcp_content_type_changed ()
405         {
406                 vector<DCPContentType const *> ct = DCPContentType::all ();
407                 Config::instance()->set_default_dcp_content_type (ct[_default_dcp_content_type->GetSelection()]);
408         }
409         
410         wxSpinCtrl* _default_j2k_bandwidth;
411         wxSpinCtrl* _default_audio_delay;
412         wxButton* _default_dci_metadata_button;
413         wxSpinCtrl* _default_still_length;
414 #ifdef DCPOMATIC_USE_OWN_DIR_PICKER
415         DirPickerCtrl* _default_directory;
416 #else
417         wxDirPickerCtrl* _default_directory;
418 #endif
419         wxChoice* _default_container;
420         wxChoice* _default_dcp_content_type;
421 };
422
423 class EncodingServersPage : public wxPreferencesPage
424 {
425 public:
426         wxString GetName () const
427         {
428                 return _("Servers");
429         }
430
431 #ifdef DCPOMATIC_OSX    
432         wxBitmap GetLargeIcon () const
433         {
434                 return wxBitmap ("servers", wxBITMAP_TYPE_PNG_RESOURCE);
435         }
436 #endif  
437
438         wxWindow* CreateWindow (wxWindow* parent)
439         {
440                 wxPanel* panel = new wxPanel (parent);
441                 wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
442                 panel->SetSizer (s);
443                 
444                 _use_any_servers = new wxCheckBox (panel, wxID_ANY, _("Use all servers"));
445                 s->Add (_use_any_servers, 0, wxALL, DCPOMATIC_SIZER_X_GAP);
446                 
447                 vector<string> columns;
448                 columns.push_back (wx_to_std (_("IP address / host name")));
449                 _servers_list = new EditableList<string, ServerDialog> (
450                         panel,
451                         columns,
452                         boost::bind (&Config::servers, Config::instance()),
453                         boost::bind (&Config::set_servers, Config::instance(), _1),
454                         boost::bind (&EncodingServersPage::server_column, this, _1)
455                         );
456                 
457                 s->Add (_servers_list, 1, wxEXPAND | wxALL, DCPOMATIC_SIZER_X_GAP);
458                 
459                 _use_any_servers->SetValue (Config::instance()->use_any_servers ());
460                 _use_any_servers->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&EncodingServersPage::use_any_servers_changed, this));
461
462                 return panel;
463         }
464
465 private:        
466
467         void use_any_servers_changed ()
468         {
469                 Config::instance()->set_use_any_servers (_use_any_servers->GetValue ());
470         }
471
472         string server_column (string s)
473         {
474                 return s;
475         }
476
477         wxCheckBox* _use_any_servers;
478         EditableList<string, ServerDialog>* _servers_list;
479 };
480
481 class ColourConversionsPage : public wxPreferencesPage
482 {
483         wxString GetName () const
484         {
485                 return _("Colour Conversions");
486         }
487
488 #ifdef DCPOMATIC_OSX    
489         wxBitmap GetLargeIcon () const
490         {
491                 return wxBitmap ("blank", wxBITMAP_TYPE_PNG_RESOURCE);
492         }
493 #endif  
494         wxWindow* CreateWindow (wxWindow* parent)
495         {
496                 vector<string> columns;
497                 columns.push_back (wx_to_std (_("Name")));
498                 return new EditableList<PresetColourConversion, PresetColourConversionDialog> (
499                         parent,
500                         columns,
501                         boost::bind (&Config::colour_conversions, Config::instance()),
502                         boost::bind (&Config::set_colour_conversions, Config::instance(), _1),
503                         boost::bind (&ColourConversionsPage::colour_conversion_column, this, _1),
504                         300
505                         );
506         }
507
508 private:
509         string colour_conversion_column (PresetColourConversion c)
510         {
511                 return c.name;
512         }
513 };
514
515 class MetadataPage : public wxPreferencesPage
516 {
517         wxString GetName () const
518         {
519                 return _("Metadata");
520         }
521
522 #ifdef DCPOMATIC_OSX    
523         wxBitmap GetLargeIcon () const
524         {
525                 return wxBitmap ("blank", wxBITMAP_TYPE_PNG_RESOURCE);
526         }
527 #endif  
528
529         wxWindow* CreateWindow (wxWindow* parent)
530         {
531                 wxPanel* panel = new wxPanel (parent);
532                 wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
533                 panel->SetSizer (s);
534                 
535                 wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
536                 table->AddGrowableCol (1, 1);
537                 s->Add (table, 1, wxALL | wxEXPAND, 8);
538                 
539                 add_label_to_sizer (table, panel, _("Issuer"), true);
540                 _issuer = new wxTextCtrl (panel, wxID_ANY);
541                 table->Add (_issuer, 1, wxEXPAND);
542                 
543                 add_label_to_sizer (table, panel, _("Creator"), true);
544                 _creator = new wxTextCtrl (panel, wxID_ANY);
545                 table->Add (_creator, 1, wxEXPAND);
546                 
547                 Config* config = Config::instance ();
548                 
549                 _issuer->SetValue (std_to_wx (config->dcp_metadata().issuer));
550                 _issuer->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&MetadataPage::issuer_changed, this));
551                 _creator->SetValue (std_to_wx (config->dcp_metadata().creator));
552                 _creator->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&MetadataPage::creator_changed, this));
553
554                 return panel;
555         }               
556
557 private:
558         wxTextCtrl* _issuer;
559         wxTextCtrl* _creator;
560         
561         void issuer_changed ()
562         {
563                 libdcp::XMLMetadata m = Config::instance()->dcp_metadata ();
564                 m.issuer = wx_to_std (_issuer->GetValue ());
565                 Config::instance()->set_dcp_metadata (m);
566         }
567         
568         void creator_changed ()
569         {
570                 libdcp::XMLMetadata m = Config::instance()->dcp_metadata ();
571                 m.creator = wx_to_std (_creator->GetValue ());
572                 Config::instance()->set_dcp_metadata (m);
573         }
574 };
575
576 class TMSPage : public wxPreferencesPage
577 {
578         wxString GetName () const
579         {
580                 return _("TMS");
581         }
582
583 #ifdef DCPOMATIC_OSX    
584         wxBitmap GetLargeIcon () const
585         {
586                 return wxBitmap ("blank", wxBITMAP_TYPE_PNG_RESOURCE);
587         }
588 #endif  
589
590         wxWindow* CreateWindow (wxWindow* parent)
591         {
592                 wxPanel* panel = new wxPanel (parent);
593                 wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
594                 panel->SetSizer (s);
595
596                 wxFlexGridSizer* table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
597                 table->AddGrowableCol (1, 1);
598                 s->Add (table, 1, wxALL | wxEXPAND, 8);
599                 
600                 add_label_to_sizer (table, panel, _("IP address"), true);
601                 _tms_ip = new wxTextCtrl (panel, wxID_ANY);
602                 table->Add (_tms_ip, 1, wxEXPAND);
603                 
604                 add_label_to_sizer (table, panel, _("Target path"), true);
605                 _tms_path = new wxTextCtrl (panel, wxID_ANY);
606                 table->Add (_tms_path, 1, wxEXPAND);
607                 
608                 add_label_to_sizer (table, panel, _("User name"), true);
609                 _tms_user = new wxTextCtrl (panel, wxID_ANY);
610                 table->Add (_tms_user, 1, wxEXPAND);
611                 
612                 add_label_to_sizer (table, panel, _("Password"), true);
613                 _tms_password = new wxTextCtrl (panel, wxID_ANY);
614                 table->Add (_tms_password, 1, wxEXPAND);
615                 
616                 Config* config = Config::instance ();
617                 
618                 _tms_ip->SetValue (std_to_wx (config->tms_ip ()));
619                 _tms_ip->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&TMSPage::tms_ip_changed, this));
620                 _tms_path->SetValue (std_to_wx (config->tms_path ()));
621                 _tms_path->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&TMSPage::tms_path_changed, this));
622                 _tms_user->SetValue (std_to_wx (config->tms_user ()));
623                 _tms_user->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&TMSPage::tms_user_changed, this));
624                 _tms_password->SetValue (std_to_wx (config->tms_password ()));
625                 _tms_password->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&TMSPage::tms_password_changed, this));
626
627                 return panel;
628         }
629
630 private:
631         void tms_ip_changed ()
632         {
633                 Config::instance()->set_tms_ip (wx_to_std (_tms_ip->GetValue ()));
634         }
635         
636         void tms_path_changed ()
637         {
638                 Config::instance()->set_tms_path (wx_to_std (_tms_path->GetValue ()));
639         }
640         
641         void tms_user_changed ()
642         {
643                 Config::instance()->set_tms_user (wx_to_std (_tms_user->GetValue ()));
644         }
645         
646         void tms_password_changed ()
647         {
648                 Config::instance()->set_tms_password (wx_to_std (_tms_password->GetValue ()));
649         }
650
651         wxTextCtrl* _tms_ip;
652         wxTextCtrl* _tms_path;
653         wxTextCtrl* _tms_user;
654         wxTextCtrl* _tms_password;
655 };
656
657 class KDMEmailPage : public wxPreferencesPage
658 {
659 public:
660         wxString GetName () const
661         {
662                 return _("KDM Email");
663         }
664
665 #ifdef DCPOMATIC_OSX    
666         wxBitmap GetLargeIcon () const
667         {
668                 return wxBitmap ("blank", wxBITMAP_TYPE_PNG_RESOURCE);
669         }
670 #endif  
671
672         wxWindow* CreateWindow (wxWindow* parent)
673         {
674                 wxPanel* panel = new wxPanel (parent);
675                 wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
676                 panel->SetSizer (s);
677                 
678                 _kdm_email = new wxTextCtrl (panel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
679                 s->Add (_kdm_email, 1, wxEXPAND | wxALL, 12);
680                 
681                 _kdm_email->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&KDMEmailPage::kdm_email_changed, this));
682                 _kdm_email->SetValue (wx_to_std (Config::instance()->kdm_email ()));
683
684                 return panel;
685         }
686
687 private:        
688         void kdm_email_changed ()
689         {
690                 Config::instance()->set_kdm_email (wx_to_std (_kdm_email->GetValue ()));
691         }
692
693         wxTextCtrl* _kdm_email;
694 };
695
696 wxPreferencesEditor*
697 create_config_dialog ()
698 {
699         wxPreferencesEditor* e = new wxPreferencesEditor ();
700         e->AddPage (new GeneralPage);
701         e->AddPage (new DefaultsPage);
702         e->AddPage (new EncodingServersPage);
703         e->AddPage (new ColourConversionsPage);
704         e->AddPage (new MetadataPage);
705         e->AddPage (new TMSPage);
706         e->AddPage (new KDMEmailPage);
707         return e;
708 }