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