BOOST_FOREACH.
[dcpomatic.git] / src / wx / verify_dcp_dialog.cc
1 /*
2     Copyright (C) 2018 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 #include "verify_dcp_dialog.h"
22 #include "wx_util.h"
23 #include "lib/verify_dcp_job.h"
24 #include "lib/warnings.h"
25 #include <dcp/verify.h>
26 DCPOMATIC_DISABLE_WARNINGS
27 #include <wx/richtext/richtextctrl.h>
28 DCPOMATIC_ENABLE_WARNINGS
29
30 using std::list;
31 using std::shared_ptr;
32
33 VerifyDCPDialog::VerifyDCPDialog (wxWindow* parent, shared_ptr<VerifyDCPJob> job)
34         : wxDialog (parent, wxID_ANY, _("DCP verification"))
35 {
36         wxBoxSizer* sizer = new wxBoxSizer (wxVERTICAL);
37         _text = new wxRichTextCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (400, 300), wxRE_READONLY);
38         sizer->Add (_text, 1, wxEXPAND | wxALL, 6);
39
40         wxStdDialogButtonSizer* buttons = CreateStdDialogButtonSizer (0);
41         sizer->Add (CreateSeparatedSizer(buttons), wxSizerFlags().Expand().DoubleBorder());
42         buttons->SetAffirmativeButton (new wxButton (this, wxID_OK));
43         buttons->Realize ();
44
45         SetSizer (sizer);
46         sizer->Layout ();
47         sizer->SetSizeHints (this);
48
49         _text->GetCaret()->Hide ();
50
51         if (job->finished_ok() && job->notes().empty()) {
52                 _text->BeginStandardBullet (N_("standard/circle"), 1, 50);
53                 _text->WriteText (_("DCP validates OK."));
54                 _text->EndStandardBullet ();
55                 return;
56         }
57
58         /* We might have an error that did not come from dcp::verify; report it if so */
59         if (job->finished_in_error() && job->error_summary() != "") {
60                 _text->BeginSymbolBullet (N_("!"), 1, 50);
61                 _text->WriteText(std_to_wx(job->error_summary()));
62                 _text->Newline();
63         }
64
65         for (auto i: job->notes()) {
66                 switch (i.type()) {
67                 case dcp::VerificationNote::VERIFY_WARNING:
68                         _text->BeginStandardBullet (N_("standard/diamond"), 1, 50);
69                         break;
70                 case dcp::VerificationNote::VERIFY_ERROR:
71                         _text->BeginSymbolBullet (N_("!"), 1, 50);
72                         break;
73                 }
74
75                 wxString text;
76                 switch (i.code()) {
77                 case dcp::VerificationNote::GENERAL_READ:
78                         text = std_to_wx(*i.note());
79                         break;
80                 case dcp::VerificationNote::CPL_HASH_INCORRECT:
81                         text = _("The hash of the CPL in the PKL does not agree with the CPL file.  This probably means that the CPL file is corrupt.");
82                         break;
83                 case dcp::VerificationNote::INVALID_PICTURE_FRAME_RATE:
84                         text = _("The picture in a reel has an invalid frame rate");
85                         break;
86                 case dcp::VerificationNote::PICTURE_HASH_INCORRECT:
87                         text = wxString::Format(
88                                 _("The hash of the picture asset %s does not agree with the PKL file.  This probably means that the asset file is corrupt."),
89                                 std_to_wx(i.file()->filename().string())
90                                 );
91                         break;
92                 case dcp::VerificationNote::PKL_CPL_PICTURE_HASHES_DISAGREE:
93                         text = _("The PKL and CPL hashes disagree for a picture asset.");
94                         break;
95                 case dcp::VerificationNote::SOUND_HASH_INCORRECT:
96                         text = wxString::Format(
97                                 _("The hash of the sound asset %s does not agree with the PKL file.  This probably means that the asset file is corrupt."),
98                                 std_to_wx(i.file()->filename().string())
99                                 );
100                         break;
101                 case dcp::VerificationNote::PKL_CPL_SOUND_HASHES_DISAGREE:
102                         text = _("The PKL and CPL hashes disagree for a sound asset.");
103                         break;
104                 case dcp::VerificationNote::EMPTY_ASSET_PATH:
105                         text = _("An asset has an empty path in the ASSETMAP.");
106                         break;
107                 case dcp::VerificationNote::MISSING_ASSET:
108                         text = _("An asset is missing.");
109                         break;
110                 case dcp::VerificationNote::MISMATCHED_STANDARD:
111                         text = _("Parts of the DCP are written according to the Interop standard and parts according to SMPTE.");
112                         break;
113                 case dcp::VerificationNote::XML_VALIDATION_ERROR:
114                         if (i.line()) {
115                                 text = wxString::Format(
116                                         _("The XML in %s is malformed on line %" PRIu64 "."),
117                                         std_to_wx(i.file()->filename().string()),
118                                         i.line().get()
119                                         );
120                         } else {
121                                 text = wxString::Format(
122                                         _("The XML in %s is malformed."),
123                                         std_to_wx(i.file()->filename().string())
124                                         );
125                         }
126                         break;
127                 case dcp::VerificationNote::MISSING_ASSETMAP:
128                         text = _("No ASSETMAP or ASSETMAP.xml file was found.");
129                         break;
130                 case dcp::VerificationNote::INTRINSIC_DURATION_TOO_SMALL:
131                         text = _("An asset has an instrinsic duration of less than 1 second, which is invalid.");
132                         break;
133                 case dcp::VerificationNote::DURATION_TOO_SMALL:
134                         text = _("An asset has a duration of less than 1 second, which is invalid.");
135                         break;
136                 case dcp::VerificationNote::PICTURE_FRAME_TOO_LARGE:
137                         text = _("At least one frame of the video data is over the limit of 250Mbit/s.");
138                         break;
139                 case dcp::VerificationNote::PICTURE_FRAME_NEARLY_TOO_LARGE:
140                         text = _("At least one frame of the video data is close to the limit of 250MBit/s.");
141                         break;
142                 case dcp::VerificationNote::EXTERNAL_ASSET:
143                         text = _("This DCP refers to at least one asset in another DCP, so it is a \"version file\" (VF)");
144                         break;
145                 }
146
147                 _text->WriteText (text);
148                 _text->Newline ();
149
150                 switch (i.type()) {
151                 case dcp::VerificationNote::VERIFY_WARNING:
152                         _text->EndStandardBullet ();
153                         break;
154                 case dcp::VerificationNote::VERIFY_ERROR:
155                         _text->EndSymbolBullet ();
156                         break;
157                 }
158         }
159 }