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