2 Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
22 #include "self_dkdm_dialog.h"
24 #include "kdm_output_panel.h"
25 #include "kdm_cpl_panel.h"
26 #include "static_text.h"
28 #include "lib/screen.h"
29 #include "lib/config.h"
30 #include <dcp/warnings.h>
31 #include <libcxml/cxml.h>
32 #ifdef DCPOMATIC_USE_OWN_PICKER
33 #include "dir_picker_ctrl.h"
35 LIBDCP_DISABLE_WARNINGS
36 #include <wx/filepicker.h>
37 LIBDCP_ENABLE_WARNINGS
39 LIBDCP_DISABLE_WARNINGS
40 #include <wx/treectrl.h>
41 #include <wx/listctrl.h>
42 #include <wx/stdpaths.h>
43 LIBDCP_ENABLE_WARNINGS
54 using std::shared_ptr;
58 SelfDKDMDialog::SelfDKDMDialog (wxWindow* parent, std::shared_ptr<const Film> film)
59 : wxDialog (parent, wxID_ANY, _("Make DKDM for DCP-o-matic"))
62 auto vertical = new wxBoxSizer (wxVERTICAL);
64 /* Font for sub-headings */
65 wxFont subheading_font (*wxNORMAL_FONT);
66 subheading_font.SetWeight (wxFONTWEIGHT_BOLD);
68 /* Sub-heading: CPL */
69 auto h = new StaticText (this, _("CPL"));
70 h->SetFont (subheading_font);
72 _cpl = new KDMCPLPanel (this, film->cpls ());
75 /* Sub-heading: output */
76 h = new StaticText (this, _("Output"));
77 h->SetFont (subheading_font);
78 vertical->Add(h, 0, wxTOP, DCPOMATIC_SUBHEADING_TOP_PAD);
80 _internal = new wxRadioButton (this, wxID_ANY, _("Save to KDM Creator tool's list"));
81 vertical->Add (_internal, 0, wxTOP, DCPOMATIC_SIZER_Y_GAP);
83 auto w = new wxBoxSizer (wxHORIZONTAL);
85 _write_to = new wxRadioButton (this, wxID_ANY, _("Write to"));
86 w->Add (_write_to, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, DCPOMATIC_SIZER_GAP);
88 #ifdef DCPOMATIC_USE_OWN_PICKER
89 _folder = new DirPickerCtrl (this);
91 _folder = new wxDirPickerCtrl (this, wxID_ANY, wxEmptyString, wxDirSelectorPromptStr, wxDefaultPosition, wxSize (300, -1));
94 _folder->SetPath (wxStandardPaths::Get().GetDocumentsDir());
96 w->Add (_folder, 1, wxEXPAND);
98 vertical->Add (w, 0, wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
100 /* Make an overall sizer to get a nice border, and put some buttons in */
102 auto overall_sizer = new wxBoxSizer (wxVERTICAL);
103 overall_sizer->Add (vertical, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, DCPOMATIC_DIALOG_BORDER);
105 auto buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL);
107 overall_sizer->Add (buttons, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_Y_GAP);
110 SetSizer (overall_sizer);
111 overall_sizer->Layout ();
112 overall_sizer->SetSizeHints (this);
114 switch (Config::instance()->last_dkdm_write_type().get_value_or(Config::DKDM_WRITE_INTERNAL)) {
115 case Config::DKDM_WRITE_INTERNAL:
116 _internal->SetValue (true);
118 case Config::DKDM_WRITE_FILE:
119 _write_to->SetValue (true);
122 setup_sensitivity ();
124 _internal->Bind (wxEVT_RADIOBUTTON, bind (&SelfDKDMDialog::dkdm_write_type_changed, this));
125 _write_to->Bind (wxEVT_RADIOBUTTON, bind (&SelfDKDMDialog::dkdm_write_type_changed, this));
126 _cpl->Changed.connect(boost::bind(&SelfDKDMDialog::setup_sensitivity, this));
131 SelfDKDMDialog::dkdm_write_type_changed ()
133 setup_sensitivity ();
135 if (_internal->GetValue()) {
136 Config::instance()->set_last_dkdm_write_type(Config::DKDM_WRITE_INTERNAL);
137 } else if (_write_to->GetValue()) {
138 Config::instance()->set_last_dkdm_write_type(Config::DKDM_WRITE_FILE);
144 SelfDKDMDialog::setup_sensitivity ()
146 _folder->Enable (_write_to->GetValue ());
148 auto ok = dynamic_cast<wxButton *>(FindWindowById(wxID_OK, this));
150 ok->Enable (_cpl->has_selected ());
155 boost::filesystem::path
156 SelfDKDMDialog::cpl () const
163 SelfDKDMDialog::internal () const
165 return _internal->GetValue ();
169 boost::filesystem::path
170 SelfDKDMDialog::directory () const
172 return wx_to_std (_folder->GetPath());