71ea089dd4e30574aeff1eff05912ba29a6348ce
[dcpomatic.git] / src / wx / self_dkdm_dialog.cc
1 /*
2     Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
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.
10
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.
15
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/>.
18
19 */
20
21 #include "self_dkdm_dialog.h"
22 #include "wx_util.h"
23 #include "kdm_output_panel.h"
24 #include "kdm_cpl_panel.h"
25 #include "static_text.h"
26 #include "lib/film.h"
27 #include "lib/screen.h"
28 #include "lib/config.h"
29 #include "lib/warnings.h"
30 #include <libcxml/cxml.h>
31 #ifdef DCPOMATIC_USE_OWN_PICKER
32 #include "dir_picker_ctrl.h"
33 #else
34 DCPOMATIC_DISABLE_WARNINGS
35 #include <wx/filepicker.h>
36 DCPOMATIC_ENABLE_WARNINGS
37 #endif
38 DCPOMATIC_DISABLE_WARNINGS
39 #include <wx/treectrl.h>
40 #include <wx/listctrl.h>
41 #include <wx/stdpaths.h>
42 DCPOMATIC_ENABLE_WARNINGS
43 #include <iostream>
44
45 using std::string;
46 using std::map;
47 using std::list;
48 using std::pair;
49 using std::cout;
50 using std::vector;
51 using std::make_pair;
52 using std::shared_ptr;
53 using boost::bind;
54
55 SelfDKDMDialog::SelfDKDMDialog (wxWindow* parent, std::shared_ptr<const Film> film)
56         : wxDialog (parent, wxID_ANY, _("Make DKDM for DCP-o-matic"))
57 {
58         /* Main sizer */
59         wxBoxSizer* vertical = new wxBoxSizer (wxVERTICAL);
60
61         /* Font for sub-headings */
62         wxFont subheading_font (*wxNORMAL_FONT);
63         subheading_font.SetWeight (wxFONTWEIGHT_BOLD);
64
65         /* Sub-heading: CPL */
66         wxStaticText* h = new StaticText (this, _("CPL"));
67         h->SetFont (subheading_font);
68         vertical->Add (h);
69         _cpl = new KDMCPLPanel (this, film->cpls ());
70         vertical->Add (_cpl);
71
72         /* Sub-heading: output */
73         h = new StaticText (this, _("Output"));
74         h->SetFont (subheading_font);
75         vertical->Add (h, 0, wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
76
77         _internal = new wxRadioButton (this, wxID_ANY, _("Save to KDM Creator tool's list"));
78         vertical->Add (_internal, 0, wxTOP, DCPOMATIC_SIZER_Y_GAP);
79
80         wxBoxSizer* w = new wxBoxSizer (wxHORIZONTAL);
81
82         _write_to = new wxRadioButton (this, wxID_ANY, _("Write to"));
83         w->Add (_write_to, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, DCPOMATIC_SIZER_GAP);
84
85 #ifdef DCPOMATIC_USE_OWN_PICKER
86         _folder = new DirPickerCtrl (this);
87 #else
88         _folder = new wxDirPickerCtrl (this, wxID_ANY, wxEmptyString, wxDirSelectorPromptStr, wxDefaultPosition, wxSize (300, -1));
89 #endif
90
91         _folder->SetPath (wxStandardPaths::Get().GetDocumentsDir());
92
93         w->Add (_folder, 1, wxEXPAND);
94
95         vertical->Add (w, 0, wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
96
97         /* Make an overall sizer to get a nice border, and put some buttons in */
98
99         wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
100         overall_sizer->Add (vertical, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, DCPOMATIC_DIALOG_BORDER);
101
102         wxSizer* buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL);
103         if (buttons) {
104                 overall_sizer->Add (buttons, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_Y_GAP);
105         }
106
107         SetSizer (overall_sizer);
108         overall_sizer->Layout ();
109         overall_sizer->SetSizeHints (this);
110
111         switch (Config::instance()->last_dkdm_write_type().get_value_or(Config::DKDM_WRITE_INTERNAL)) {
112         case Config::DKDM_WRITE_INTERNAL:
113                 _internal->SetValue (true);
114                 break;
115         case Config::DKDM_WRITE_FILE:
116                 _write_to->SetValue (true);
117                 break;
118         }
119         setup_sensitivity ();
120
121         _internal->Bind (wxEVT_RADIOBUTTON, bind (&SelfDKDMDialog::dkdm_write_type_changed, this));
122         _write_to->Bind (wxEVT_RADIOBUTTON, bind (&SelfDKDMDialog::dkdm_write_type_changed, this));
123 }
124
125 void
126 SelfDKDMDialog::dkdm_write_type_changed ()
127 {
128         setup_sensitivity ();
129
130         if (_internal->GetValue ()) {
131                 Config::instance()->set_last_dkdm_write_type (Config::DKDM_WRITE_INTERNAL);
132         } else if (_write_to->GetValue ()) {
133                 Config::instance()->set_last_dkdm_write_type (Config::DKDM_WRITE_FILE);
134         }
135 }
136
137 void
138 SelfDKDMDialog::setup_sensitivity ()
139 {
140         _folder->Enable (_write_to->GetValue ());
141
142         wxButton* ok = dynamic_cast<wxButton *> (FindWindowById (wxID_OK, this));
143         if (ok) {
144                 ok->Enable (_cpl->has_selected ());
145         }
146 }
147
148 boost::filesystem::path
149 SelfDKDMDialog::cpl () const
150 {
151         return _cpl->cpl ();
152 }
153
154 bool
155 SelfDKDMDialog::internal () const
156 {
157         return _internal->GetValue ();
158 }
159
160 boost::filesystem::path
161 SelfDKDMDialog::directory () const
162 {
163         return wx_to_std (_folder->GetPath ());
164 }