Untested loading of playlists into the list view.
authorCarl Hetherington <cth@carlh.net>
Sun, 28 Oct 2018 19:44:53 +0000 (19:44 +0000)
committerCarl Hetherington <cth@carlh.net>
Sun, 28 Oct 2018 19:44:53 +0000 (19:44 +0000)
src/lib/config.h
src/wx/controls.cc
src/wx/controls.h

index 23286dd..a162750 100644 (file)
@@ -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) {
index d8df6f2..62f75fd 100644 (file)
@@ -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<FilmViewer> 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> content, wxListCtrl* ctrl)
        ctrl->SetItem(it);
 }
 
+void
+Controls::add_playlist_to_list (shared_ptr<Film> 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<path> dir = Config::instance()->player_playlist_directory();
+       if (!dir) {
+               return;
+       }
+
+       for (directory_iterator i = directory_iterator(*dir); i != directory_iterator(); ++i) {
+               try {
+                       shared_ptr<Film> film (new Film(optional<path>()));
+                       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 ()
index 2c0b84d..d916bea 100644 (file)
@@ -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::shared_ptr<dcp::CPL>, boost::filesystem::path> CPL;
@@ -93,6 +94,7 @@ private:
        void save_clicked ();
        void load_clicked ();
        void add_content_to_list (boost::shared_ptr<Content> content, wxListCtrl* list);
+       void add_playlist_to_list (boost::shared_ptr<Film> film);
 
        boost::shared_ptr<Film> _film;
        boost::shared_ptr<FilmViewer> _viewer;
@@ -112,6 +114,7 @@ private:
        wxButton* _save_button;
        wxButton* _load_button;
        std::vector<boost::shared_ptr<Content> > _content;
+       std::vector<boost::shared_ptr<Film> > _playlists;
        wxSlider* _slider;
        wxButton* _rewind_button;
        wxButton* _back_button;