From 5feadb30fc839601345c4553c5a954ffc37bc1c7 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 28 Oct 2018 19:44:53 +0000 Subject: [PATCH] Untested loading of playlists into the list view. --- src/lib/config.h | 5 +++-- src/wx/controls.cc | 50 ++++++++++++++++++++++++++++++++++++++++++++-- src/wx/controls.h | 3 +++ 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/lib/config.h b/src/lib/config.h index 23286ddb0..a162750fe 100644 --- a/src/lib/config.h +++ b/src/lib/config.h @@ -78,6 +78,7 @@ public: SOUND_OUTPUT, INTERFACE_COMPLEXITY, PLAYER_CONTENT_DIRECTORY, + PLAYER_PLAYLIST_DIRECTORY, HISTORY, #ifdef DCPOMATIC_VARIANT_SWAROOP PLAYER_BACKGROUND_IMAGE, @@ -964,7 +965,7 @@ public: } void set_player_playlist_directory (boost::filesystem::path p) { - maybe_set (_player_playlist_directory, p); + maybe_set (_player_playlist_directory, p, PLAYER_PLAYLIST_DIRECTORY); } void unset_player_playlist_directory () { @@ -972,7 +973,7 @@ public: return; } _player_playlist_directory = boost::none; - changed (); + changed (PLAYER_PLAYLIST_DIRECTORY); } void set_player_kdm_directory (boost::filesystem::path p) { diff --git a/src/wx/controls.cc b/src/wx/controls.cc index d8df6f2f3..62f75fde3 100644 --- a/src/wx/controls.cc +++ b/src/wx/controls.cc @@ -42,6 +42,7 @@ using std::string; using std::list; using std::make_pair; +using std::exception; using boost::optional; using boost::shared_ptr; using boost::weak_ptr; @@ -200,6 +201,7 @@ Controls::Controls (wxWindow* parent, shared_ptr viewer, bool editor setup_sensitivity (); update_content_directory (); + update_playlist_directory (); JobManager::instance()->ActiveJobsChanged.connect ( bind (&Controls::active_jobs_changed, this, _2) @@ -236,7 +238,9 @@ Controls::save_clicked () ); if (d->ShowModal() == wxID_OK) { - _film->write_metadata(wx_to_std(d->GetPath())); + boost::filesystem::path p(wx_to_std(d->GetPath())); + _film->set_name(p.stem().string()); + _film->write_metadata(p); } d->Destroy (); @@ -266,6 +270,8 @@ Controls::config_changed (int property) { if (property == Config::PLAYER_CONTENT_DIRECTORY) { update_content_directory (); + } else if (property == Config::PLAYER_PLAYLIST_DIRECTORY) { + update_playlist_directory (); } else { setup_sensitivity (); } @@ -581,10 +587,11 @@ void Controls::show_extended_player_controls (bool s) { _content_view->Show (s); + _spl_view->Show (s); if (s) { update_content_directory (); + update_playlist_directory (); } - _spl_view->Show (s); _current_spl_view->Show (s); _log->Show (s); _add_button->Show (s); @@ -624,6 +631,18 @@ Controls::add_content_to_list (shared_ptr content, wxListCtrl* ctrl) ctrl->SetItem(it); } +void +Controls::add_playlist_to_list (shared_ptr film) +{ + int const N = _spl_view->GetItemCount(); + + wxListItem it; + it.SetId(N); + it.SetColumn(0); + it.SetText (std_to_wx(film->name())); + _spl_view->InsertItem (it); +} + void Controls::update_content_directory () { @@ -677,6 +696,33 @@ Controls::update_content_directory () } } +void +Controls::update_playlist_directory () +{ + if (!_spl_view->IsShown()) { + return; + } + + using namespace boost::filesystem; + + _spl_view->DeleteAllItems (); + optional dir = Config::instance()->player_playlist_directory(); + if (!dir) { + return; + } + + for (directory_iterator i = directory_iterator(*dir); i != directory_iterator(); ++i) { + try { + shared_ptr film (new Film(optional())); + film->read_metadata (i->path()); + _playlists.push_back (film); + add_playlist_to_list (film); + } catch (exception& e) { + /* Never mind */ + } + } +} + #ifdef DCPOMATIC_VARIANT_SWAROOP void Controls::pause_clicked () diff --git a/src/wx/controls.h b/src/wx/controls.h index 2c0b84d8d..d916beaf8 100644 --- a/src/wx/controls.h +++ b/src/wx/controls.h @@ -80,6 +80,7 @@ private: void stopped (); void film_changed (); void update_content_directory (); + void update_playlist_directory (); void config_changed (int property); typedef std::pair, boost::filesystem::path> CPL; @@ -93,6 +94,7 @@ private: void save_clicked (); void load_clicked (); void add_content_to_list (boost::shared_ptr content, wxListCtrl* list); + void add_playlist_to_list (boost::shared_ptr film); boost::shared_ptr _film; boost::shared_ptr _viewer; @@ -112,6 +114,7 @@ private: wxButton* _save_button; wxButton* _load_button; std::vector > _content; + std::vector > _playlists; wxSlider* _slider; wxButton* _rewind_button; wxButton* _back_button; -- 2.30.2