Build fixes for Boost >= 1.73
[dcpomatic.git] / src / wx / kdm_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 "kdm_dialog.h"
22 #include "wx_util.h"
23 #include "screens_panel.h"
24 #include "kdm_timing_panel.h"
25 #include "kdm_output_panel.h"
26 #include "kdm_cpl_panel.h"
27 #include "confirm_kdm_email_dialog.h"
28 #include "static_text.h"
29 #include "dcpomatic_button.h"
30 #include "lib/film.h"
31 #include "lib/screen.h"
32 #include "lib/screen_kdm.h"
33 #include "lib/job_manager.h"
34 #include "lib/cinema_kdms.h"
35 #include "lib/config.h"
36 #include "lib/cinema.h"
37 #include <libcxml/cxml.h>
38 #include <dcp/exceptions.h>
39 #include <wx/treectrl.h>
40 #include <wx/listctrl.h>
41 #include <iostream>
42
43 using std::string;
44 using std::exception;
45 using std::map;
46 using std::list;
47 using std::pair;
48 using std::cout;
49 using std::vector;
50 using std::make_pair;
51 using std::runtime_error;
52 using boost::shared_ptr;
53 using boost::bind;
54 #if BOOST_VERSION >= 106100
55 using namespace boost::placeholders;
56 #endif
57
58 KDMDialog::KDMDialog (wxWindow* parent, shared_ptr<const Film> film)
59         : wxDialog (parent, wxID_ANY, _("Make KDMs"))
60         , _film (film)
61 {
62         /* Main sizers */
63         wxBoxSizer* horizontal = new wxBoxSizer (wxHORIZONTAL);
64         wxBoxSizer* left = new wxBoxSizer (wxVERTICAL);
65         wxBoxSizer* right = new wxBoxSizer (wxVERTICAL);
66
67         horizontal->Add (left, 1, wxEXPAND | wxRIGHT, DCPOMATIC_SIZER_X_GAP * 4);
68         horizontal->Add (right, 1, wxEXPAND);
69
70         /* Font for sub-headings */
71         wxFont subheading_font (*wxNORMAL_FONT);
72         subheading_font.SetWeight (wxFONTWEIGHT_BOLD);
73
74         /* Sub-heading: Screens */
75         wxStaticText* h = new StaticText (this, _("Screens"));
76         h->SetFont (subheading_font);
77         left->Add (h, 0, wxALIGN_CENTER_VERTICAL | wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
78         _screens = new ScreensPanel (this);
79         left->Add (_screens, 1, wxEXPAND | wxBOTTOM, DCPOMATIC_SIZER_Y_GAP);
80
81         /* Sub-heading: Timing */
82         /// TRANSLATORS: translate the word "Timing" here; do not include the "KDM|" prefix
83         h = new StaticText (this, S_("KDM|Timing"));
84         h->SetFont (subheading_font);
85         right->Add (h, 0, wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_Y_GAP * 2);
86         _timing = new KDMTimingPanel (this);
87         right->Add (_timing);
88
89         /* Sub-heading: CPL */
90         h = new StaticText (this, _("CPL"));
91         h->SetFont (subheading_font);
92         right->Add (h, 0, wxALIGN_CENTER_VERTICAL, DCPOMATIC_SIZER_Y_GAP * 2);
93
94         vector<CPLSummary> cpls;
95         BOOST_FOREACH (CPLSummary const & i, film->cpls()) {
96                 if (i.encrypted) {
97                         cpls.push_back (i);
98                 }
99         }
100
101         _cpl = new KDMCPLPanel (this, cpls);
102         right->Add (_cpl, 0, wxEXPAND);
103
104         /* Sub-heading: Output */
105         h = new StaticText (this, _("Output"));
106         h->SetFont (subheading_font);
107         right->Add (h, 0, wxALIGN_CENTER_VERTICAL | wxTOP, DCPOMATIC_SIZER_Y_GAP * 2);
108         _output = new KDMOutputPanel (this, film->interop ());
109         right->Add (_output, 0, wxEXPAND | wxTOP, DCPOMATIC_SIZER_GAP);
110
111         _make = new Button (this, _("Make KDMs"));
112         right->Add (_make, 0, wxTOP | wxBOTTOM, DCPOMATIC_SIZER_GAP);
113
114         /* Make an overall sizer to get a nice border */
115
116         wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
117         overall_sizer->Add (horizontal, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, DCPOMATIC_DIALOG_BORDER);
118
119         /* Bind */
120
121         _screens->ScreensChanged.connect (boost::bind (&KDMDialog::setup_sensitivity, this));
122         _timing->TimingChanged.connect (boost::bind (&KDMDialog::setup_sensitivity, this));
123         _make->Bind (wxEVT_BUTTON, boost::bind (&KDMDialog::make_clicked, this));
124
125         setup_sensitivity ();
126
127         SetSizer (overall_sizer);
128         overall_sizer->Layout ();
129         overall_sizer->SetSizeHints (this);
130 }
131
132 void
133 KDMDialog::setup_sensitivity ()
134 {
135         _screens->setup_sensitivity ();
136         _output->setup_sensitivity ();
137         _make->Enable (!_screens->screens().empty() && _timing->valid() && _cpl->has_selected());
138 }
139
140 bool
141 KDMDialog::confirm_overwrite (boost::filesystem::path path)
142 {
143         return confirm_dialog (
144                 this,
145                 wxString::Format (_("File %s already exists.  Do you want to overwrite it?"), std_to_wx(path.string()).data())
146                 );
147 }
148
149 void
150 KDMDialog::make_clicked ()
151 {
152         shared_ptr<const Film> film = _film.lock ();
153         DCPOMATIC_ASSERT (film);
154
155         list<ScreenKDM> screen_kdms;
156         try {
157
158                 screen_kdms = film->make_kdms (
159                         _screens->screens(), _cpl->cpl(), _timing->from(), _timing->until(), _output->formulation(),
160                         !_output->forensic_mark_video(), _output->forensic_mark_audio() ? boost::optional<int>() : 0
161                         );
162
163         } catch (runtime_error& e) {
164                 error_dialog (this, std_to_wx(e.what()));
165                 return;
166         }
167
168         pair<shared_ptr<Job>, int> result = _output->make (screen_kdms, film->name(), _timing, bind (&KDMDialog::confirm_overwrite, this, _1));
169         if (result.first) {
170                 JobManager::instance()->add (result.first);
171         }
172
173         if (result.second > 0) {
174                 /* XXX: proper plural form support in wxWidgets? */
175                 wxString s = result.second == 1 ? _("%d KDM written to %s") : _("%d KDMs written to %s");
176                 message_dialog (
177                         this,
178                         wxString::Format (s, result.second, std_to_wx(_output->directory().string()).data())
179                         );
180         }
181 }