2 Copyright (C) 2018 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
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.
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.
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/>.
21 #include "../wx/wx_util.h"
22 #include "../wx/wx_signal_manager.h"
23 #include "../lib/util.h"
24 #include "../lib/config.h"
25 #include "../lib/cross.h"
27 #include <wx/listctrl.h>
28 #include <wx/imaglist.h>
32 using boost::optional;
39 dcp::ContentKind kind;
47 bool disable_timeline;
52 class DOMFrame : public wxFrame
55 explicit DOMFrame (wxString const & title)
56 : wxFrame (0, -1, title)
58 /* Use a panel as the only child of the Frame so that we avoid
59 the dark-grey background on Windows.
61 wxPanel* overall_panel = new wxPanel (this, wxID_ANY);
62 wxBoxSizer* main_sizer = new wxBoxSizer (wxHORIZONTAL);
64 _list = new wxListCtrl (
65 overall_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_SINGLE_SEL
68 _list->AppendColumn (_("Name"), wxLIST_FORMAT_LEFT, 400);
69 _list->AppendColumn (_("CPL"), wxLIST_FORMAT_LEFT, 400);
70 _list->AppendColumn (_("Type"), wxLIST_FORMAT_CENTRE, 75);
71 _list->AppendColumn (_("Format"), wxLIST_FORMAT_CENTRE, 75);
72 _list->AppendColumn (_("Encrypted"), wxLIST_FORMAT_CENTRE, 90);
73 _list->AppendColumn (_("Skippable"), wxLIST_FORMAT_CENTRE, 90);
74 _list->AppendColumn (_("Disable timeline"), wxLIST_FORMAT_CENTRE, 125);
75 _list->AppendColumn (_("Stop after play"), wxLIST_FORMAT_CENTRE, 125);
77 wxImageList* images = new wxImageList (16, 16);
81 tick_icon.LoadFile ("tick.png", wxBITMAP_TYPE_PNG_RESOURCE);
82 no_tick_icon.LoadFile ("no_tick.png", wxBITMAP_TYPE_PNG_RESOURCE);
84 boost::filesystem::path tick_path = shared_path() / "tick.png";
85 tick_icon.LoadFile (std_to_wx(tick_path.string()));
86 boost::filesystem::path no_tick_path = shared_path() / "no_tick.png";
87 no_tick_icon.LoadFile (std_to_wx(no_tick_path.string()));
89 images->Add (tick_icon);
90 images->Add (no_tick_icon);
92 _list->SetImageList (images, wxIMAGE_LIST_SMALL);
94 main_sizer->Add (_list, 1, wxEXPAND | wxALL, DCPOMATIC_SIZER_GAP);
96 wxBoxSizer* button_sizer = new wxBoxSizer (wxVERTICAL);
97 _up = new wxButton (overall_panel, wxID_ANY, _("Up"));
98 _down = new wxButton (overall_panel, wxID_ANY, _("Down"));
99 _add = new wxButton (overall_panel, wxID_ANY, _("Add"));
100 _remove = new wxButton (overall_panel, wxID_ANY, _("Remove"));
101 _save = new wxButton (overall_panel, wxID_ANY, _("Save playlist"));
102 _load = new wxButton (overall_panel, wxID_ANY, _("Load playlist"));
103 button_sizer->Add (_up, 0, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
104 button_sizer->Add (_down, 0, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
105 button_sizer->Add (_add, 0, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
106 button_sizer->Add (_remove, 0, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
107 button_sizer->Add (_save, 0, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
108 button_sizer->Add (_load, 0, wxEXPAND | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP);
110 main_sizer->Add (button_sizer, 0, wxALL, DCPOMATIC_SIZER_GAP);
111 overall_panel->SetSizer (main_sizer);
113 _list->Bind (wxEVT_LEFT_DOWN, bind(&DOMFrame::list_left_click, this, _1));
118 pe.kind = dcp::FEATURE;
119 pe.type = PlaylistEntry::ECINEMA;
121 pe.disable_timeline = false;
122 pe.stop_after_play = true;
125 setup_sensitivity ();
130 void add (PlaylistEntry e)
134 long const N = _list->InsertItem (item);
136 _playlist.push_back (e);
139 void set_item (long N, PlaylistEntry e)
141 _list->SetItem (N, 0, std_to_wx(e.name));
142 _list->SetItem (N, 1, std_to_wx(e.cpl_id));
143 _list->SetItem (N, 2, std_to_wx(dcp::content_kind_to_string(e.kind)));
144 _list->SetItem (N, 3, e.type == PlaylistEntry::DCP ? _("DCP") : _("E-cinema"));
145 _list->SetItem (N, 4, e.encrypted ? _("Y") : _("N"));
146 _list->SetItem (N, COLUMN_SKIPPABLE, wxEmptyString, e.skippable ? 0 : 1);
147 _list->SetItem (N, COLUMN_DISABLE_TIMELINE, wxEmptyString, e.disable_timeline ? 0 : 1);
148 _list->SetItem (N, COLUMN_STOP_AFTER_PLAY, wxEmptyString, e.stop_after_play ? 0 : 1);
151 void setup_sensitivity ()
153 int const selected = _list->GetSelectedItemCount ();
154 _up->Enable (selected > 0);
155 _down->Enable (selected > 0);
156 _remove->Enable (selected > 0);
159 void list_left_click (wxMouseEvent& ev)
162 long item = _list->HitTest (ev.GetPosition(), flags, 0);
163 int x = ev.GetPosition().x;
164 optional<int> column;
165 for (int i = 0; i < _list->GetColumnCount(); ++i) {
166 x -= _list->GetColumnWidth (i);
173 if (item != -1 && column) {
175 case COLUMN_SKIPPABLE:
176 _playlist[item].skippable = !_playlist[item].skippable;
178 case COLUMN_DISABLE_TIMELINE:
179 _playlist[item].disable_timeline = !_playlist[item].disable_timeline;
181 case COLUMN_STOP_AFTER_PLAY:
182 _playlist[item].stop_after_play = !_playlist[item].stop_after_play;
187 set_item (item, _playlist[item]);
200 std::vector<PlaylistEntry> _playlist;
203 COLUMN_SKIPPABLE = 5,
204 COLUMN_DISABLE_TIMELINE = 6,
205 COLUMN_STOP_AFTER_PLAY = 7
210 * @brief The magic App class for wxWidgets.
212 class App : public wxApp
225 SetAppName (_("DCP-o-matic KDM Creator"));
227 if (!wxApp::OnInit()) {
231 #ifdef DCPOMATIC_LINUX
232 unsetenv ("UBUNTU_MENUPROXY");
236 ProcessSerialNumber serial;
237 GetCurrentProcess (&serial);
238 TransformProcessType (&serial, kProcessTransformToForegroundApplication);
241 dcpomatic_setup_path_encoding ();
243 /* Enable i18n; this will create a Config object
244 to look for a force-configured language. This Config
245 object will be wrong, however, because dcpomatic_setup
246 hasn't yet been called and there aren't any filters etc.
249 dcpomatic_setup_i18n ();
251 /* Set things up, including filters etc.
252 which will now be internationalised correctly.
256 /* Force the configuration to be re-loaded correctly next
261 _frame = new DOMFrame (_("DCP-o-matic KDM Creator"));
262 SetTopWindow (_frame);
266 signal_manager = new wxSignalManager (this);
267 Bind (wxEVT_IDLE, boost::bind (&App::idle, this));
273 error_dialog (0, _("DCP-o-matic could not start"), std_to_wx(e.what()));
277 /* An unhandled exception has occurred inside the main event loop */
278 bool OnExceptionInMainLoop ()
282 } catch (FileError& e) {
286 _("An exception occurred: %s (%s)\n\n") + REPORT_PROBLEM,
287 std_to_wx (e.what()),
288 std_to_wx (e.file().string().c_str ())
291 } catch (exception& e) {
295 _("An exception occurred: %s.\n\n") + " " + REPORT_PROBLEM,
296 std_to_wx (e.what ())
300 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
303 /* This will terminate the program */
307 void OnUnhandledException ()
309 error_dialog (0, _("An unknown exception occurred.") + " " + REPORT_PROBLEM);
314 signal_manager->ui_idle ();