summaryrefslogtreecommitdiff
path: root/src/wx/verify_dcp_dialog.cc
blob: c25899e2d9276ae9dec9e90acab80cb589611144 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
    Copyright (C) 2020 Carl Hetherington <cth@carlh.net>

    This file is part of DCP-o-matic.

    DCP-o-matic is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    DCP-o-matic is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.

*/


#include "check_box.h"
#include "dcpomatic_button.h"
#include "verify_dcp_dialog.h"
#include "verify_dcp_progress_panel.h"
#include "verify_dcp_result_panel.h"
#include "wx_util.h"
#include "lib/cross.h"
#include "lib/job_manager.h"
#include "lib/verify_dcp_job.h"
#include <dcp/warnings.h>
LIBDCP_DISABLE_WARNINGS
#include <wx/evtloop.h>
LIBDCP_ENABLE_WARNINGS
#include <string>


using std::shared_ptr;
using std::string;
using std::vector;
using boost::optional;


VerifyDCPDialog::VerifyDCPDialog(
	wxWindow* parent,
	wxString title,
	vector<boost::filesystem::path> dcp_directories,
	vector<boost::filesystem::path> kdms
	)
	: wxDialog (parent, wxID_ANY, title)
	, _progress_panel(new VerifyDCPProgressPanel(this))
	, _result_panel(new VerifyDCPResultPanel(this))
	, _cancel_pending(false)
	, _dcp_directories(std::move(dcp_directories))
{
	setup();

	if (auto key = Config::instance()->decryption_chain()->key()) {
		for (auto const& kdm: kdms) {
			_kdms.push_back(dcp::DecryptedKDM{dcp::EncryptedKDM(dcp::file_to_string(kdm)), *key});
		}
	}
}


VerifyDCPDialog::VerifyDCPDialog(
	wxWindow* parent,
	wxString title,
	vector<boost::filesystem::path> dcp_directories,
	vector<dcp::EncryptedKDM> const& kdms
	)
	: wxDialog (parent, wxID_ANY, title)
	, _progress_panel(new VerifyDCPProgressPanel(this))
	, _result_panel(new VerifyDCPResultPanel(this))
	, _cancel_pending(false)
	, _dcp_directories(std::move(dcp_directories))
{
	setup();

	if (auto key = Config::instance()->decryption_chain()->key()) {
		for (auto const& kdm: kdms) {
			_kdms.push_back(dcp::DecryptedKDM{kdm, *key});
		}
	}
}


void
VerifyDCPDialog::setup()
{
	auto overall_sizer = new wxBoxSizer (wxVERTICAL);

	auto options_sizer = new wxBoxSizer(wxVERTICAL);
	_check_picture_details = new CheckBox(this, _("Verify picture asset details"));
	_check_picture_details->set(true);
	_check_picture_details->SetToolTip(
		_("Tick to check details of the picture asset, such as frame sizes and JPEG2000 bitstream validity.  "
		  "These checks are quite time-consuming.")
	);
	options_sizer->Add(_check_picture_details, 0, wxBOTTOM, DCPOMATIC_SIZER_GAP);
	overall_sizer->Add(options_sizer, 0, wxALL, DCPOMATIC_SIZER_GAP);

	auto buttons = new wxBoxSizer(wxHORIZONTAL);
	_cancel = new Button(this, _("Cancel"));
	buttons->Add(_cancel, 0, wxLEFT, DCPOMATIC_SIZER_GAP);
	_verify = new Button(this, _("Verify"));
	buttons->Add(_verify, 0, wxLEFT, DCPOMATIC_SIZER_GAP);
	overall_sizer->Add(buttons, 0, wxALL | wxALIGN_CENTER, DCPOMATIC_SIZER_GAP);

	overall_sizer->Add(_progress_panel, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_GAP);
	overall_sizer->Add(_result_panel, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_GAP);

	SetSizerAndFit(overall_sizer);

	_verify->bind(&VerifyDCPDialog::verify_clicked, this);
	_cancel->bind(&VerifyDCPDialog::cancel_clicked, this);

	_cancel->Enable(false);
}


void
VerifyDCPDialog::cancel_clicked()
{
	_cancel_pending = true;
}


void
VerifyDCPDialog::verify_clicked()
{
	_cancel->Enable(true);
	_verify->Enable(false);

	dcp::VerificationOptions options;
	options.check_picture_details = _check_picture_details->get();
	auto job = std::make_shared<VerifyDCPJob>(_dcp_directories, _kdms, options);

	auto jm = JobManager::instance();
	jm->add(job);

	while (jm->work_to_do() && !_cancel_pending) {
		wxEventLoopBase::GetActive()->YieldFor(wxEVT_CATEGORY_UI | wxEVT_CATEGORY_USER_INPUT);
		dcpomatic_sleep_milliseconds(250);
		_progress_panel->update(job);
	}

	if (_cancel_pending) {
		jm->cancel_all_jobs();
		EndModal(0);
	} else {
		_progress_panel->clear();
		_result_panel->add({ job });
		_cancel->Enable(false);
		_verify->Enable(false);
		_check_picture_details->Enable(false);
	}
}