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