2 Copyright (C) 2020 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
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.
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.
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/>.
22 #include "verify_dcp_progress_dialog.h"
24 #include "lib/cross.h"
26 #include "lib/job_manager.h"
27 #include <dcp/warnings.h>
28 LIBDCP_DISABLE_WARNINGS
29 #include <wx/evtloop.h>
30 LIBDCP_ENABLE_WARNINGS
35 using std::shared_ptr;
36 using boost::optional;
39 static int const max_file_name_length = 80;
42 VerifyDCPProgressDialog::VerifyDCPProgressDialog (wxWindow* parent, wxString title)
43 : wxDialog (parent, wxID_ANY, title)
46 wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
48 _job_name = new wxStaticText (this, wxID_ANY, wxT(""));
49 overall_sizer->Add (_job_name, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, DCPOMATIC_SIZER_GAP);
51 _file_name = new wxStaticText (this, wxID_ANY, wxT(""));
52 wxFont file_name_font (*wxNORMAL_FONT);
53 file_name_font.SetFamily (wxFONTFAMILY_MODERN);
54 file_name_font.SetPointSize (file_name_font.GetPointSize() - 2);
55 _file_name->SetFont (file_name_font);
59 _file_name->GetTextExtent (std_to_wx(string(max_file_name_length, 'X')), &w, &h);
60 _file_name->SetMinSize (wxSize(w, -1));
62 overall_sizer->Add (_file_name, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, DCPOMATIC_SIZER_GAP);
64 _progress = new wxGauge (this, wxID_ANY, 100);
65 overall_sizer->Add (_progress, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_GAP);
67 wxButton* cancel = new wxButton (this, wxID_ANY, _("Cancel"));
68 wxSizer* buttons = new wxBoxSizer (wxHORIZONTAL);
69 buttons->AddStretchSpacer ();
70 buttons->Add (cancel, 0);
71 overall_sizer->Add (buttons, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_GAP);
73 SetSizerAndFit (overall_sizer);
75 cancel->Bind (wxEVT_BUTTON, boost::bind(&VerifyDCPProgressDialog::cancel, this));
80 VerifyDCPProgressDialog::cancel ()
87 VerifyDCPProgressDialog::run (shared_ptr<Job> job)
91 JobManager* jm = JobManager::instance ();
94 while (jm->work_to_do()) {
95 wxEventLoopBase::GetActive()->YieldFor(wxEVT_CATEGORY_UI | wxEVT_CATEGORY_USER_INPUT);
96 dcpomatic_sleep_seconds (1);
97 optional<float> const progress = job->progress ();
99 _progress->SetValue (*progress * 100);
103 string const sub = job->sub_name ();
104 size_t colon = sub.find (":");
105 if (colon != string::npos) {
106 _job_name->SetLabel (std_to_wx(sub.substr(0, colon)));
108 if ((sub.length() - colon - 1) > max_file_name_length) {
109 file_name = "..." + sub.substr(sub.length() - max_file_name_length + 3);
111 file_name = sub.substr(colon + 1);
113 _file_name->SetLabel (std_to_wx(file_name));
115 _job_name->SetLabel (std_to_wx(sub));