Merge remote-tracking branch 'origin/main' into v2.17.x
[dcpomatic.git] / src / wx / verify_dcp_progress_dialog.cc
1 /*
2     Copyright (C) 2020 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
22 #include "verify_dcp_progress_dialog.h"
23 #include "verify_dcp_progress_panel.h"
24 #include "wx_util.h"
25 #include "lib/cross.h"
26 #include "lib/job.h"
27 #include "lib/job_manager.h"
28 #include <dcp/warnings.h>
29 LIBDCP_DISABLE_WARNINGS
30 #include <wx/evtloop.h>
31 LIBDCP_ENABLE_WARNINGS
32 #include <string>
33
34
35 using std::string;
36 using std::shared_ptr;
37 using boost::optional;
38
39
40 VerifyDCPProgressDialog::VerifyDCPProgressDialog (wxWindow* parent, wxString title)
41         : wxDialog (parent, wxID_ANY, title)
42         , _panel(new VerifyDCPProgressPanel(this))
43         , _cancel (false)
44 {
45         auto overall_sizer = new wxBoxSizer (wxVERTICAL);
46
47         overall_sizer->Add(_panel, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_GAP);
48
49         auto cancel = new wxButton(this, wxID_ANY, _("Cancel"));
50         auto buttons = new wxBoxSizer(wxHORIZONTAL);
51         buttons->AddStretchSpacer ();
52         buttons->Add (cancel, 0);
53         overall_sizer->Add (buttons, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_GAP);
54
55         SetSizerAndFit (overall_sizer);
56
57         cancel->Bind (wxEVT_BUTTON, boost::bind(&VerifyDCPProgressDialog::cancel, this));
58 }
59
60
61 void
62 VerifyDCPProgressDialog::cancel ()
63 {
64         _cancel = true;
65 }
66
67
68 bool
69 VerifyDCPProgressDialog::run (shared_ptr<Job> job)
70 {
71         Show ();
72
73         JobManager* jm = JobManager::instance ();
74         jm->add (job);
75
76         while (jm->work_to_do()) {
77                 wxEventLoopBase::GetActive()->YieldFor(wxEVT_CATEGORY_UI | wxEVT_CATEGORY_USER_INPUT);
78                 dcpomatic_sleep_seconds (1);
79
80                 _panel->update(job);
81
82                 if (_cancel) {
83                         break;
84                 }
85         }
86
87         return !_cancel;
88 }