Split VerifyDCPProgressDialog into a panel and a dialog.
[dcpomatic.git] / src / wx / verify_dcp_progress_panel.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 "lib/job.h"
23 #include "verify_dcp_progress_panel.h"
24 #include "wx_util.h"
25
26
27 using std::shared_ptr;
28 using std::string;
29
30
31 auto constexpr max_file_name_length = 80;
32
33
34
35 VerifyDCPProgressPanel::VerifyDCPProgressPanel(wxWindow* parent)
36         : wxPanel(parent, wxID_ANY)
37 {
38         auto overall_sizer = new wxBoxSizer(wxVERTICAL);
39
40         _job_name = new wxStaticText(this, wxID_ANY, wxT(""));
41         overall_sizer->Add(_job_name, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, DCPOMATIC_SIZER_GAP);
42
43         _file_name = new wxStaticText(this, wxID_ANY, wxT(""));
44         wxFont file_name_font(*wxNORMAL_FONT);
45         file_name_font.SetFamily(wxFONTFAMILY_MODERN);
46         file_name_font.SetPointSize(file_name_font.GetPointSize() - 2);
47         _file_name->SetFont(file_name_font);
48
49         int w;
50         int h;
51         _file_name->GetTextExtent(std_to_wx(string(max_file_name_length, 'X')), &w, &h);
52         _file_name->SetMinSize(wxSize(w, -1));
53
54         overall_sizer->Add(_file_name, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, DCPOMATIC_SIZER_GAP);
55
56         _progress = new wxGauge(this, wxID_ANY, 100);
57         overall_sizer->Add(_progress, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_GAP);
58
59         SetSizerAndFit (overall_sizer);
60 }
61
62
63 void
64 VerifyDCPProgressPanel::update(shared_ptr<Job> job)
65 {
66         auto const progress = job->progress();
67         if (progress) {
68                 _progress->SetValue(*progress * 100);
69         } else {
70                 _progress->Pulse();
71         }
72         string const sub = job->sub_name();
73         size_t colon = sub.find(":");
74         if (colon != string::npos) {
75                 _job_name->SetLabel(std_to_wx(sub.substr(0, colon)));
76                 string file_name;
77                 if ((sub.length() - colon - 1) > max_file_name_length) {
78                         file_name = "..." + sub.substr(sub.length() - max_file_name_length + 3);
79                 } else {
80                         file_name = sub.substr(colon + 1);
81                 }
82                 _file_name->SetLabel(std_to_wx(file_name));
83         } else {
84                 _job_name->SetLabel(std_to_wx(sub));
85         }
86 }
87