Hide warnings triggered by Ubuntu 20.04's gcc.
[dcpomatic.git] / src / wx / hints_dialog.cc
1 /*
2     Copyright (C) 2012-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 "hints_dialog.h"
22 #include "wx_util.h"
23 #include "static_text.h"
24 #include "check_box.h"
25 #include "lib/film.h"
26 #include "lib/hints.h"
27 #include "lib/config.h"
28 #include "lib/warnings.h"
29 DCPOMATIC_DISABLE_WARNINGS
30 #include <wx/richtext/richtextctrl.h>
31 DCPOMATIC_ENABLE_WARNINGS
32 #include <boost/foreach.hpp>
33
34 using std::max;
35 using std::vector;
36 using std::string;
37 using std::cout;
38 using boost::shared_ptr;
39 using boost::optional;
40 using boost::bind;
41 using boost::dynamic_pointer_cast;
42
43 HintsDialog::HintsDialog (wxWindow* parent, boost::weak_ptr<Film> film, bool ok)
44         : wxDialog (parent, wxID_ANY, _("Hints"))
45         , _film (film)
46         , _hints (0)
47         , _finished (false)
48 {
49         wxBoxSizer* sizer = new wxBoxSizer (wxVERTICAL);
50
51         _gauge = new wxGauge (this, wxID_ANY, 100);
52         sizer->Add (_gauge, 0, wxALL | wxEXPAND, DCPOMATIC_SIZER_GAP);
53         _gauge_message = new StaticText (this, wxT(""));
54         sizer->Add (_gauge_message, 0, wxALL | wxEXPAND, DCPOMATIC_SIZER_GAP);
55
56         _text = new wxRichTextCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (400, 300), wxRE_READONLY);
57         sizer->Add (_text, 1, wxEXPAND | wxALL, 6);
58
59         if (!ok) {
60                 wxCheckBox* b = new CheckBox (this, _("Don't show hints again"));
61                 sizer->Add (b, 0, wxALL, 6);
62                 b->Bind (wxEVT_CHECKBOX, bind (&HintsDialog::shut_up, this, _1));
63         }
64
65         wxStdDialogButtonSizer* buttons = CreateStdDialogButtonSizer (0);
66         sizer->Add (CreateSeparatedSizer(buttons), wxSizerFlags().Expand().DoubleBorder());
67         if (ok) {
68                 buttons->SetAffirmativeButton (new wxButton (this, wxID_OK));
69         } else {
70                 buttons->SetAffirmativeButton (new wxButton (this, wxID_OK, _("Make DCP")));
71                 buttons->SetNegativeButton (new wxButton (this, wxID_CANCEL, _("Go back")));
72         }
73
74         buttons->Realize ();
75
76         SetSizer (sizer);
77         sizer->Layout ();
78         sizer->SetSizeHints (this);
79
80         _text->GetCaret()->Hide ();
81
82         boost::shared_ptr<Film> locked_film = _film.lock ();
83         if (locked_film) {
84                 _film_change_connection = locked_film->Change.connect (boost::bind (&HintsDialog::film_change, this, _1));
85                 _film_content_change_connection = locked_film->ContentChange.connect (boost::bind (&HintsDialog::film_content_change, this, _1));
86         }
87
88         film_change (CHANGE_TYPE_DONE);
89 }
90
91 void
92 HintsDialog::film_change (ChangeType type)
93 {
94         if (type != CHANGE_TYPE_DONE) {
95                 return;
96         }
97
98         _text->Clear ();
99         _current.clear ();
100
101         boost::shared_ptr<Film> film = _film.lock ();
102         if (!film) {
103                 return;
104         }
105
106         _gauge->Show ();
107         _gauge_message->Show ();
108         Layout ();
109         _gauge->SetValue (0);
110         update ();
111         _finished = false;
112
113         _hints.reset (new Hints (_film));
114         _hints->Hint.connect (bind (&HintsDialog::hint, this, _1));
115         _hints->Progress.connect (bind (&HintsDialog::progress, this, _1));
116         _hints->Pulse.connect (bind (&HintsDialog::pulse, this));
117         _hints->Finished.connect (bind (&HintsDialog::finished, this));
118         _hints->start ();
119 }
120
121 void
122 HintsDialog::film_content_change (ChangeType type)
123 {
124         film_change (type);
125 }
126
127 void
128 HintsDialog::update ()
129 {
130         _text->Clear ();
131         if (_current.empty ()) {
132                 if (_finished) {
133                         _text->WriteText (_("There are no hints: everything looks good!"));
134                 } else {
135                         _text->WriteText (_("There are no hints yet: project check in progress."));
136                 }
137         } else {
138                 _text->BeginStandardBullet (N_("standard/circle"), 1, 50);
139                 BOOST_FOREACH (string i, _current) {
140                         _text->WriteText (std_to_wx (i));
141                         _text->Newline ();
142                 }
143                 _text->EndSymbolBullet ();
144         }
145 }
146
147 void
148 HintsDialog::hint (string text)
149 {
150         _current.push_back (text);
151         update ();
152 }
153
154 void
155 HintsDialog::shut_up (wxCommandEvent& ev)
156 {
157         Config::instance()->set_show_hints_before_make_dcp (!ev.IsChecked());
158 }
159
160 void
161 HintsDialog::pulse ()
162 {
163         _gauge->Pulse ();
164 }
165
166 void
167 HintsDialog::finished ()
168 {
169         try {
170                 _hints->rethrow ();
171         } catch (std::exception& e) {
172                 error_dialog (this, wxString::Format(_("A problem occurred when looking for hints (%s)"), std_to_wx(e.what())));
173         }
174
175         _finished = true;
176         update ();
177         _gauge->Hide ();
178         _gauge_message->Hide ();
179         Layout ();
180 }
181
182 void
183 HintsDialog::progress (string m)
184 {
185         _gauge_message->SetLabel (std_to_wx(m));
186 }