swaroop: new slightly-hacky way to make background image appear on stop.
[dcpomatic.git] / src / wx / controls.cc
index 9540b85868be470b7839505faaa4cc1f2a56c234..cf805e8f78cf9171562b30f04fe43cc44db9db05 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;
@@ -87,7 +88,11 @@ Controls::Controls (wxWindow* parent, shared_ptr<FilmViewer> viewer, bool editor
 
        _v_sizer->Add (view_options, 0, wxALL, DCPOMATIC_SIZER_GAP);
 
-       wxBoxSizer* e_sizer = new wxBoxSizer (wxHORIZONTAL);
+       wxBoxSizer* left_sizer = new wxBoxSizer (wxVERTICAL);
+
+       _spl_view = new wxListCtrl (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_NO_HEADER);
+       _spl_view->AppendColumn (wxT(""), wxLIST_FORMAT_LEFT, 740);
+       left_sizer->Add (_spl_view, 1, wxALL | wxEXPAND, DCPOMATIC_SIZER_GAP);
 
        _content_view = new wxListCtrl (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_NO_HEADER);
        /* time */
@@ -96,13 +101,16 @@ Controls::Controls (wxWindow* parent, shared_ptr<FilmViewer> viewer, bool editor
        _content_view->AppendColumn (wxT(""), wxLIST_FORMAT_LEFT, 80);
        /* annotation text */
        _content_view->AppendColumn (wxT(""), wxLIST_FORMAT_LEFT, 580);
-       e_sizer->Add (_content_view, 1, wxALL | wxEXPAND, DCPOMATIC_SIZER_GAP);
+       left_sizer->Add (_content_view, 1, wxALL | wxEXPAND, DCPOMATIC_SIZER_GAP);
 
-       _spl_view = new wxListCtrl (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_NO_HEADER);
-       _spl_view->AppendColumn (wxT(""), wxLIST_FORMAT_LEFT, 80);
-       _spl_view->AppendColumn (wxT(""), wxLIST_FORMAT_LEFT, 80);
-       _spl_view->AppendColumn (wxT(""), wxLIST_FORMAT_LEFT, 580);
-       e_sizer->Add (_spl_view, 1, wxALL | wxEXPAND, DCPOMATIC_SIZER_GAP);
+       wxBoxSizer* e_sizer = new wxBoxSizer (wxHORIZONTAL);
+       e_sizer->Add (left_sizer, 1, wxALL | wxEXPAND, DCPOMATIC_SIZER_GAP);
+
+       _current_spl_view = new wxListCtrl (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_NO_HEADER);
+       _current_spl_view->AppendColumn (wxT(""), wxLIST_FORMAT_LEFT, 80);
+       _current_spl_view->AppendColumn (wxT(""), wxLIST_FORMAT_LEFT, 80);
+       _current_spl_view->AppendColumn (wxT(""), wxLIST_FORMAT_LEFT, 580);
+       e_sizer->Add (_current_spl_view, 1, wxALL | wxEXPAND, DCPOMATIC_SIZER_GAP);
 
        wxBoxSizer* buttons_sizer = new wxBoxSizer (wxVERTICAL);
        _add_button = new wxButton(this, wxID_ANY, _("Add"));
@@ -120,6 +128,7 @@ Controls::Controls (wxWindow* parent, shared_ptr<FilmViewer> viewer, bool editor
 
        _content_view->Show (false);
        _spl_view->Show (false);
+       _current_spl_view->Show (false);
        _add_button->Show (false);
        _save_button->Show (false);
        _load_button->Show (false);
@@ -192,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)
@@ -204,18 +214,14 @@ Controls::Controls (wxWindow* parent, shared_ptr<FilmViewer> viewer, bool editor
 void
 Controls::add_clicked ()
 {
-       shared_ptr<Content> sel = selected_content ();
+       shared_ptr<Content> sel = selected_content()->clone();
        DCPOMATIC_ASSERT (sel);
        _film->examine_and_add_content (sel);
        bool const ok = display_progress (_("DCP-o-matic"), _("Loading DCP"));
        if (!ok || !report_errors_from_last_job(this)) {
                return;
        }
-       if (_film->content().size() == 1) {
-               /* Put 1 frame of black at the start so when we seek to 0 we don't see anything */
-               sel->set_position (DCPTime::from_frames(1, _film->video_frame_rate()));
-       }
-       add_content_to_list (sel, _spl_view);
+       add_content_to_list (sel, _current_spl_view);
        setup_sensitivity ();
 }
 
@@ -228,7 +234,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 ();
@@ -243,10 +251,10 @@ Controls::load_clicked ()
 
        if (d->ShowModal() == wxID_OK) {
                _film->read_metadata (boost::filesystem::path(wx_to_std(d->GetPath())));
-               _spl_view->DeleteAllItems ();
+               _current_spl_view->DeleteAllItems ();
                BOOST_FOREACH (shared_ptr<Content> i, _film->content()) {
                        shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent>(i);
-                       add_content_to_list (dcp, _spl_view);
+                       add_content_to_list (dcp, _current_spl_view);
                }
        }
 
@@ -258,6 +266,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 ();
        }
@@ -573,10 +583,12 @@ 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);
        _save_button->Show (s);
@@ -615,6 +627,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 ()
 {
@@ -639,7 +663,7 @@ Controls::update_content_directory ()
                        shared_ptr<Content> content;
                        if (is_directory(*i) && (is_regular_file(*i / "ASSETMAP") || is_regular_file(*i / "ASSETMAP.xml"))) {
                                content.reset (new DCPContent(_film, *i));
-                       } else if (i->path().extension() == ".mp4") {
+                       } else if (i->path().extension() == ".mp4" || i->path().extension() == ".ecinema") {
                                content = content_factory(_film, *i).front();
                        }
 
@@ -668,6 +692,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 ()