Factor out hints code into its own method.
[dcpomatic.git] / src / wx / hints_dialog.cc
1 /*
2     Copyright (C) 2012-2016 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 <wx/richtext/richtextctrl.h>
26 #include <boost/foreach.hpp>
27
28 using std::max;
29 using std::vector;
30 using std::string;
31 using boost::shared_ptr;
32 using boost::optional;
33 using boost::dynamic_pointer_cast;
34
35 HintsDialog::HintsDialog (wxWindow* parent, boost::weak_ptr<Film> film)
36         : wxDialog (parent, wxID_ANY, _("Hints"))
37         , _film (film)
38 {
39         wxBoxSizer* sizer = new wxBoxSizer (wxVERTICAL);
40         _text = new wxRichTextCtrl (this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize (400, 300), wxRE_READONLY);
41         sizer->Add (_text, 1, wxEXPAND | wxALL, 6);
42
43         wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
44         if (buttons) {
45                 sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
46         }
47
48         SetSizer (sizer);
49         sizer->Layout ();
50         sizer->SetSizeHints (this);
51
52         _text->GetCaret()->Hide ();
53
54         boost::shared_ptr<Film> locked_film = _film.lock ();
55         if (locked_film) {
56                 _film_changed_connection = locked_film->Changed.connect (boost::bind (&HintsDialog::film_changed, this));
57                 _film_content_changed_connection = locked_film->ContentChanged.connect (boost::bind (&HintsDialog::film_changed, this));
58         }
59
60         film_changed ();
61 }
62
63 void
64 HintsDialog::film_changed ()
65 {
66         _text->Clear ();
67
68         boost::shared_ptr<Film> film = _film.lock ();
69         if (!film) {
70                 return;
71         }
72
73         vector<string> hints = get_hints (film);
74
75         if (hints.empty ()) {
76                 _text->WriteText (_("There are no hints: everything looks good!"));
77         } else {
78                 _text->BeginStandardBullet (N_("standard/circle"), 1, 50);
79                 BOOST_FOREACH (string i, hints) {
80                         _text->WriteText (std_to_wx (i));
81                         _text->Newline ();
82                 }
83                 _text->EndSymbolBullet ();
84         }
85 }