Cleanup: extract sorted_cinemas().
[dcpomatic.git] / src / wx / screens_panel.h
1 /*
2     Copyright (C) 2015-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 "lib/collator.h"
23 #include "lib/config.h"
24 #include <dcp/warnings.h>
25 LIBDCP_DISABLE_WARNINGS
26 #include <wx/srchctrl.h>
27 #include <wx/treelist.h>
28 #include <wx/wx.h>
29 LIBDCP_ENABLE_WARNINGS
30 #include <boost/signals2.hpp>
31 #include <list>
32 #include <map>
33 #include <set>
34
35
36 namespace dcpomatic {
37         class Screen;
38 }
39
40
41 class Cinema;
42
43
44 class ScreensPanel : public wxPanel
45 {
46 public:
47         explicit ScreensPanel (wxWindow* parent);
48         ~ScreensPanel ();
49
50         std::vector<std::shared_ptr<dcpomatic::Screen>> screens () const;
51         void setup_sensitivity ();
52
53         boost::signals2::signal<void ()> ScreensChanged;
54
55 private:
56         void add_cinemas ();
57         boost::optional<wxTreeListItem> add_cinema (std::shared_ptr<Cinema>, wxTreeListItem previous);
58         boost::optional<wxTreeListItem> add_screen (std::shared_ptr<Cinema>, std::shared_ptr<dcpomatic::Screen>);
59         void add_cinema_clicked ();
60         void edit_cinema_clicked ();
61         void remove_cinema_clicked ();
62         void add_screen_clicked ();
63         void edit_screen_clicked ();
64         void remove_screen_clicked ();
65         void selection_changed_shim (wxTreeListEvent &);
66         void selection_changed ();
67         void search_changed ();
68         void checkbox_changed (wxTreeListEvent& ev);
69         std::shared_ptr<Cinema> cinema_for_operation () const;
70         void set_screen_checked (wxTreeListItem item, bool checked);
71         void setup_cinema_checked_state (wxTreeListItem screen);
72         void check_all ();
73         void uncheck_all ();
74         bool notify_cinemas_changed();
75         void clear_and_re_add();
76         void config_changed(Config::Property);
77         void convert_to_lower(std::string& s);
78         bool matches_search(std::shared_ptr<const Cinema> cinema, std::string lower_case_search);
79         std::list<std::shared_ptr<Cinema>> sorted_cinemas() const;
80
81         std::shared_ptr<Cinema> item_to_cinema (wxTreeListItem item) const;
82         std::shared_ptr<dcpomatic::Screen> item_to_screen (wxTreeListItem item) const;
83         boost::optional<wxTreeListItem> cinema_to_item (std::shared_ptr<Cinema> cinema) const;
84         boost::optional<wxTreeListItem> screen_to_item (std::shared_ptr<dcpomatic::Screen> screen) const;
85
86         wxSearchCtrl* _search;
87         wxTreeListCtrl* _targets;
88         wxButton* _add_cinema;
89         wxButton* _edit_cinema;
90         wxButton* _remove_cinema;
91         wxButton* _add_screen;
92         wxButton* _edit_screen;
93         wxButton* _remove_screen;
94         wxButton* _check_all;
95         wxButton* _uncheck_all;
96
97         /* We want to be able to search (and so remove selected things from the view)
98          * but not deselect them, so we maintain lists of selected cinemas and screens.
99          */
100         std::vector<std::shared_ptr<Cinema>> _selected_cinemas;
101         std::vector<std::shared_ptr<dcpomatic::Screen>> _selected_screens;
102         /* Likewise with checked screens, except that we can work out which cinemas
103          * are checked from which screens are checked, so we don't need to store the
104          * cinemas.
105          */
106         std::set<std::shared_ptr<dcpomatic::Screen>> _checked_screens;
107
108         std::map<wxTreeListItem, std::shared_ptr<Cinema>> _item_to_cinema;
109         std::map<wxTreeListItem, std::shared_ptr<dcpomatic::Screen>> _item_to_screen;
110         std::map<std::shared_ptr<Cinema>, wxTreeListItem> _cinema_to_item;
111         std::map<std::shared_ptr<dcpomatic::Screen>, wxTreeListItem> _screen_to_item;
112
113         bool _ignore_selection_change = false;
114         bool _ignore_check_change = false;
115
116         Collator _collator;
117
118         boost::signals2::scoped_connection _config_connection;
119         bool _ignore_cinemas_changed = false;
120 };