Improve ratings dialog to allow only valid values (#2199).
[dcpomatic.git] / src / wx / rating_dialog.h
1 /*
2     Copyright (C) 2019-2022 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
22 #include <dcp/rating.h>
23 #include <wx/wx.h>
24 #include <boost/signals2.hpp>
25
26
27 class wxChoice;
28 class wxListView;
29 class wxNotebook;
30 class wxSearchCtrl;
31
32
33 class RatingDialogPage : public wxPanel
34 {
35 public:
36         RatingDialogPage (wxNotebook* notebook);
37         virtual dcp::Rating get () const = 0;
38         virtual bool set (dcp::Rating rating) = 0;
39
40         /** Emitted when the page has been changed, the parameter being true if OK
41          *  should now be enabled in the main dialogue.
42          */
43         boost::signals2::signal<void (bool)> Changed;
44 };
45
46
47 class StandardRatingDialogPage : public RatingDialogPage
48 {
49 public:
50         StandardRatingDialogPage (wxNotebook* notebook);
51
52         dcp::Rating get () const override;
53         bool set (dcp::Rating rating) override;
54
55 private:
56         void search_changed ();
57         void found_systems_view_selection_changed ();
58         void update_found_system_selection ();
59
60         wxSearchCtrl* _search;
61         wxListView* _found_systems_view;
62         boost::optional<dcp::RatingSystem> _selected_system;
63         wxChoice* _rating;
64         std::vector<dcp::RatingSystem> _found_systems;
65 };
66
67
68 class CustomRatingDialogPage : public RatingDialogPage
69 {
70 public:
71         CustomRatingDialogPage (wxNotebook* notebook);
72
73         dcp::Rating get () const override;
74         bool set (dcp::Rating rating) override;
75
76 private:
77         void changed ();
78
79         wxTextCtrl* _agency;
80         wxTextCtrl* _rating;
81 };
82
83
84 class RatingDialog : public wxDialog
85 {
86 public:
87         RatingDialog (wxWindow* parent);
88
89         void set (dcp::Rating r);
90         dcp::Rating get () const;
91
92 private:
93         void setup_sensitivity (bool ok_valid);
94         void page_changed ();
95
96         wxNotebook* _notebook;
97
98         StandardRatingDialogPage* _standard_page;
99         CustomRatingDialogPage* _custom_page;
100         RatingDialogPage* _active_page;
101 };
102