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