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 "swaroop_controls.h"
22 #include "film_viewer.h"
24 #include "content_view.h"
25 #include "lib/player_video.h"
26 #include "lib/dcp_content.h"
27 #include <wx/listctrl.h>
32 using boost::shared_ptr;
33 using boost::dynamic_pointer_cast;
34 using boost::optional;
36 SwaroopControls::SwaroopControls (wxWindow* parent, shared_ptr<FilmViewer> viewer)
37 : Controls (parent, viewer, false)
38 , _play_button (new wxButton(this, wxID_ANY, _("Play")))
39 , _pause_button (new wxButton(this, wxID_ANY, _("Pause")))
40 , _stop_button (new wxButton(this, wxID_ANY, _("Stop")))
42 _button_sizer->Add (_play_button, 0, wxEXPAND);
43 _button_sizer->Add (_pause_button, 0, wxEXPAND);
44 _button_sizer->Add (_stop_button, 0, wxEXPAND);
46 _spl_view = new wxListCtrl (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_NO_HEADER);
47 _spl_view->AppendColumn (wxT(""), wxLIST_FORMAT_LEFT, 740);
49 wxBoxSizer* left_sizer = new wxBoxSizer (wxVERTICAL);
50 wxBoxSizer* e_sizer = new wxBoxSizer (wxHORIZONTAL);
52 left_sizer->Add (_spl_view, 1, wxALL | wxEXPAND, DCPOMATIC_SIZER_GAP);
54 _content_view = new ContentView (this, _film);
55 left_sizer->Add (_content_view, 1, wxALL | wxEXPAND, DCPOMATIC_SIZER_GAP);
57 _current_spl_view = new wxListCtrl (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_NO_HEADER);
58 _current_spl_view->AppendColumn (wxT(""), wxLIST_FORMAT_LEFT, 500);
59 _current_spl_view->AppendColumn (wxT(""), wxLIST_FORMAT_LEFT, 80);
60 e_sizer->Add (left_sizer, 0, wxALL | wxEXPAND, DCPOMATIC_SIZER_GAP);
61 e_sizer->Add (_current_spl_view, 1, wxALL | wxEXPAND, DCPOMATIC_SIZER_GAP);
63 _v_sizer->Add (e_sizer, 1, wxEXPAND);
65 _log = new wxTextCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(-1, 200), wxTE_READONLY | wxTE_MULTILINE);
66 _v_sizer->Add (_log, 0, wxALL | wxEXPAND, DCPOMATIC_SIZER_GAP);
68 _play_button->Bind (wxEVT_BUTTON, boost::bind(&SwaroopControls::play_clicked, this));
69 _pause_button->Bind (wxEVT_BUTTON, boost::bind(&SwaroopControls::pause_clicked, this));
70 _stop_button->Bind (wxEVT_BUTTON, boost::bind(&SwaroopControls::stop_clicked, this));
71 _spl_view->Bind (wxEVT_LIST_ITEM_SELECTED, boost::bind(&SwaroopControls::spl_selection_changed, this));
72 _spl_view->Bind (wxEVT_LIST_ITEM_DESELECTED, boost::bind(&SwaroopControls::spl_selection_changed, this));
73 _viewer->ImageChanged.connect (boost::bind(&SwaroopControls::image_changed, this, _1));
75 _content_view->update ();
76 update_playlist_directory ();
80 SwaroopControls::started ()
83 _play_button->Enable (false);
84 _pause_button->Enable (true);
88 SwaroopControls::stopped ()
91 _play_button->Enable (true);
92 _pause_button->Enable (false);
96 SwaroopControls::play_clicked ()
102 SwaroopControls::setup_sensitivity ()
104 Controls::setup_sensitivity ();
105 bool const active_job = _active_job && *_active_job != "examine_content";
106 bool const c = _film && !_film->content().empty() && !active_job;
107 _play_button->Enable (c && !_viewer->playing());
108 _pause_button->Enable (c && (!_current_kind || _current_kind != dcp::ADVERTISEMENT) && _viewer->playing());
109 _stop_button->Enable (c && (!_current_kind || _current_kind != dcp::ADVERTISEMENT));
110 _slider->Enable (c && (!_current_kind || _current_kind != dcp::ADVERTISEMENT));
114 SwaroopControls::pause_clicked ()
120 SwaroopControls::stop_clicked ()
123 _viewer->seek (DCPTime(), true);
127 SwaroopControls::log (wxString s)
130 gettimeofday (&time, 0);
132 time_t const sec = time.tv_sec;
133 struct tm* t = localtime (&sec);
134 strftime (buffer, 64, "%c", t);
135 wxString ts = std_to_wx(string(buffer)) + N_(": ");
136 _log->SetValue(_log->GetValue() + ts + s + "\n");
140 SwaroopControls::image_changed (boost::weak_ptr<PlayerVideo> weak_pv)
142 shared_ptr<PlayerVideo> pv = weak_pv.lock ();
147 shared_ptr<Content> c = pv->content().lock();
152 shared_ptr<DCPContent> dc = dynamic_pointer_cast<DCPContent> (c);
157 if (!_current_kind || *_current_kind != dc->content_kind()) {
158 _current_kind = dc->content_kind ();
159 setup_sensitivity ();
164 SwaroopControls::add_playlist_to_list (SPL spl)
166 int const N = _spl_view->GetItemCount();
171 it.SetText (std_to_wx(spl.name()));
172 _spl_view->InsertItem (it);
176 SwaroopControls::update_playlist_directory ()
178 using namespace boost::filesystem;
180 _spl_view->DeleteAllItems ();
181 optional<path> dir = Config::instance()->player_playlist_directory();
188 for (directory_iterator i = directory_iterator(*dir); i != directory_iterator(); ++i) {
190 if (is_regular_file(i->path()) && i->path().extension() == ".xml") {
192 spl.read (i->path(), _content_view);
193 _playlists.push_back (spl);
194 add_playlist_to_list (spl);
196 } catch (exception& e) {
203 SwaroopControls::spl_selection_changed ()
205 long int selected = _spl_view->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
206 if (selected == -1) {
207 _current_spl_view->DeleteAllItems ();
211 shared_ptr<Film> film (new Film(optional<boost::filesystem::path>()));
214 BOOST_FOREACH (SPLEntry i, _playlists[selected].get()) {
218 it.SetText (std_to_wx(i.name));
219 _current_spl_view->InsertItem (it);
220 film->add_content (i.content);
228 SwaroopControls::config_changed (int property)
230 Controls::config_changed (property);
232 if (property == Config::PLAYER_CONTENT_DIRECTORY) {
233 _content_view->update ();
234 } else if (property == Config::PLAYER_PLAYLIST_DIRECTORY) {
235 update_playlist_directory ();
240 SwaroopControls::set_film (shared_ptr<Film> film)
242 Controls::set_film (film);
244 _content_view->set_film (film);
245 update_playlist_directory ();
247 setup_sensitivity ();