Split VerifyDCPProgressDialog into a panel and a dialog.
authorCarl Hetherington <cth@carlh.net>
Tue, 9 Apr 2024 19:11:32 +0000 (21:11 +0200)
committerCarl Hetherington <cth@carlh.net>
Mon, 15 Apr 2024 22:39:05 +0000 (00:39 +0200)
src/wx/verify_dcp_progress_dialog.cc
src/wx/verify_dcp_progress_dialog.h
src/wx/verify_dcp_progress_panel.cc [new file with mode: 0644]
src/wx/verify_dcp_progress_panel.h [new file with mode: 0644]

index 6c941c98d333c450426bfef6d8de37a0814af474..5e3a7be627b3711146a52cac22cda2a50a5899fb 100644 (file)
@@ -20,6 +20,7 @@
 
 
 #include "verify_dcp_progress_dialog.h"
+#include "verify_dcp_progress_panel.h"
 #include "wx_util.h"
 #include "lib/cross.h"
 #include "lib/job.h"
@@ -36,36 +37,17 @@ using std::shared_ptr;
 using boost::optional;
 
 
-static int const max_file_name_length = 80;
-
-
 VerifyDCPProgressDialog::VerifyDCPProgressDialog (wxWindow* parent, wxString title)
        : wxDialog (parent, wxID_ANY, title)
+       , _panel(new VerifyDCPProgressPanel(this))
        , _cancel (false)
 {
-       wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
-
-       _job_name = new wxStaticText (this, wxID_ANY, wxT(""));
-       overall_sizer->Add (_job_name, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, DCPOMATIC_SIZER_GAP);
-
-       _file_name = new wxStaticText (this, wxID_ANY, wxT(""));
-       wxFont file_name_font (*wxNORMAL_FONT);
-       file_name_font.SetFamily (wxFONTFAMILY_MODERN);
-       file_name_font.SetPointSize (file_name_font.GetPointSize() - 2);
-       _file_name->SetFont (file_name_font);
-
-       int w;
-       int h;
-       _file_name->GetTextExtent (std_to_wx(string(max_file_name_length, 'X')), &w, &h);
-       _file_name->SetMinSize (wxSize(w, -1));
+       auto overall_sizer = new wxBoxSizer (wxVERTICAL);
 
-       overall_sizer->Add (_file_name, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, DCPOMATIC_SIZER_GAP);
+       overall_sizer->Add(_panel, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_GAP);
 
-       _progress = new wxGauge (this, wxID_ANY, 100);
-       overall_sizer->Add (_progress, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_GAP);
-
-       wxButton* cancel = new wxButton (this, wxID_ANY, _("Cancel"));
-       wxSizer* buttons = new wxBoxSizer (wxHORIZONTAL);
+       auto cancel = new wxButton(this, wxID_ANY, _("Cancel"));
+       auto buttons = new wxBoxSizer(wxHORIZONTAL);
        buttons->AddStretchSpacer ();
        buttons->Add (cancel, 0);
        overall_sizer->Add (buttons, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_GAP);
@@ -94,26 +76,8 @@ VerifyDCPProgressDialog::run (shared_ptr<Job> job)
        while (jm->work_to_do()) {
                wxEventLoopBase::GetActive()->YieldFor(wxEVT_CATEGORY_UI | wxEVT_CATEGORY_USER_INPUT);
                dcpomatic_sleep_seconds (1);
-               optional<float> const progress = job->progress ();
-               if (progress) {
-                       _progress->SetValue (*progress * 100);
-               } else {
-                       _progress->Pulse ();
-               }
-               string const sub = job->sub_name ();
-               size_t colon = sub.find (":");
-               if (colon != string::npos) {
-                       _job_name->SetLabel (std_to_wx(sub.substr(0, colon)));
-                       string file_name;
-                       if ((sub.length() - colon - 1) > max_file_name_length) {
-                               file_name = "..." + sub.substr(sub.length() - max_file_name_length + 3);
-                       } else {
-                               file_name = sub.substr(colon + 1);
-                       }
-                       _file_name->SetLabel (std_to_wx(file_name));
-               } else {
-                       _job_name->SetLabel (std_to_wx(sub));
-               }
+
+               _panel->update(job);
 
                if (_cancel) {
                        break;
index 190c302ea45fb25ebf24d8fc06fc18da37ea0043..1ae3336e89c83ff1b74133fd5346989902301af1 100644 (file)
@@ -25,10 +25,9 @@ LIBDCP_DISABLE_WARNINGS
 LIBDCP_ENABLE_WARNINGS
 #include <memory>
 
-class Job;
 
-class wxGauge;
-class wxStaticText;
+class Job;
+class VerifyDCPProgressPanel;
 
 
 class VerifyDCPProgressDialog : public wxDialog
@@ -41,9 +40,7 @@ public:
 private:
        void cancel ();
 
-       wxStaticText* _job_name;
-       wxStaticText* _file_name;
-       wxGauge* _progress;
+       VerifyDCPProgressPanel* _panel;
        bool _cancel;
 };
 
diff --git a/src/wx/verify_dcp_progress_panel.cc b/src/wx/verify_dcp_progress_panel.cc
new file mode 100644 (file)
index 0000000..4c4ce68
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+    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 "lib/job.h"
+#include "verify_dcp_progress_panel.h"
+#include "wx_util.h"
+
+
+using std::shared_ptr;
+using std::string;
+
+
+auto constexpr max_file_name_length = 80;
+
+
+
+VerifyDCPProgressPanel::VerifyDCPProgressPanel(wxWindow* parent)
+       : wxPanel(parent, wxID_ANY)
+{
+       auto overall_sizer = new wxBoxSizer(wxVERTICAL);
+
+       _job_name = new wxStaticText(this, wxID_ANY, wxT(""));
+       overall_sizer->Add(_job_name, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, DCPOMATIC_SIZER_GAP);
+
+       _file_name = new wxStaticText(this, wxID_ANY, wxT(""));
+       wxFont file_name_font(*wxNORMAL_FONT);
+       file_name_font.SetFamily(wxFONTFAMILY_MODERN);
+       file_name_font.SetPointSize(file_name_font.GetPointSize() - 2);
+       _file_name->SetFont(file_name_font);
+
+       int w;
+       int h;
+       _file_name->GetTextExtent(std_to_wx(string(max_file_name_length, 'X')), &w, &h);
+       _file_name->SetMinSize(wxSize(w, -1));
+
+       overall_sizer->Add(_file_name, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, DCPOMATIC_SIZER_GAP);
+
+       _progress = new wxGauge(this, wxID_ANY, 100);
+       overall_sizer->Add(_progress, 0, wxEXPAND | wxALL, DCPOMATIC_SIZER_GAP);
+
+       SetSizerAndFit (overall_sizer);
+}
+
+
+void
+VerifyDCPProgressPanel::update(shared_ptr<Job> job)
+{
+       auto const progress = job->progress();
+       if (progress) {
+               _progress->SetValue(*progress * 100);
+       } else {
+               _progress->Pulse();
+       }
+       string const sub = job->sub_name();
+       size_t colon = sub.find(":");
+       if (colon != string::npos) {
+               _job_name->SetLabel(std_to_wx(sub.substr(0, colon)));
+               string file_name;
+               if ((sub.length() - colon - 1) > max_file_name_length) {
+                       file_name = "..." + sub.substr(sub.length() - max_file_name_length + 3);
+               } else {
+                       file_name = sub.substr(colon + 1);
+               }
+               _file_name->SetLabel(std_to_wx(file_name));
+       } else {
+               _job_name->SetLabel(std_to_wx(sub));
+       }
+}
+
diff --git a/src/wx/verify_dcp_progress_panel.h b/src/wx/verify_dcp_progress_panel.h
new file mode 100644 (file)
index 0000000..e39713d
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+    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 <wx/wx.h>
+#include <memory>
+
+
+class Job;
+
+
+class VerifyDCPProgressPanel : public wxPanel
+{
+public:
+       VerifyDCPProgressPanel(wxWindow* parent);
+
+       void update(std::shared_ptr<Job> job);
+
+private:
+       wxStaticText* _job_name;
+       wxStaticText* _file_name;
+       wxGauge* _progress;
+};
+