X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Fcontent_view.cc;h=8055e2f2d2fb2f043c147984bf30ecd99dd542ec;hb=796aaab029ebd06a6176383714ef75726b2b9ec2;hp=b7f05020b5dbdd0f13dcd305599a5221c870f3ff;hpb=63bce67bd548f4aff98e2a1963e1fd77a6412a15;p=dcpomatic.git diff --git a/src/wx/content_view.cc b/src/wx/content_view.cc index b7f05020b..8055e2f2d 100644 --- a/src/wx/content_view.cc +++ b/src/wx/content_view.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2018 Carl Hetherington + Copyright (C) 2018-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,6 +18,7 @@ */ + #include "content_view.h" #include "wx_util.h" #include "lib/dcpomatic_assert.h" @@ -32,17 +33,20 @@ #include #include -using std::string; + using std::cout; +using std::dynamic_pointer_cast; using std::list; -using boost::shared_ptr; -using boost::weak_ptr; +using std::make_shared; +using std::shared_ptr; +using std::string; +using std::weak_ptr; using boost::optional; -using boost::dynamic_pointer_cast; +using namespace dcpomatic; -ContentView::ContentView (wxWindow* parent, weak_ptr film) + +ContentView::ContentView (wxWindow* parent) : wxListCtrl (parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_NO_HEADER) - , _film (film) { AppendColumn (wxT(""), wxLIST_FORMAT_LEFT, 80); /* type */ @@ -51,57 +55,56 @@ ContentView::ContentView (wxWindow* parent, weak_ptr film) AppendColumn (wxT(""), wxLIST_FORMAT_LEFT, 580); } + shared_ptr ContentView::selected () const { long int s = GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); if (s == -1) { - return shared_ptr(); + return {}; } DCPOMATIC_ASSERT (s < int(_content.size())); return _content[s]; } + void ContentView::update () { - shared_ptr film = _film.lock (); - if (!film) { - return; - } - using namespace boost::filesystem; DeleteAllItems (); _content.clear (); - optional dir = Config::instance()->player_content_directory(); - if (!dir) { - return; + auto dir = Config::instance()->player_content_directory(); + if (!dir || !boost::filesystem::is_directory(*dir)) { + dir = home_directory (); } wxProgressDialog progress (_("DCP-o-matic"), _("Reading content directory")); - JobManager* jm = JobManager::instance (); + auto jm = JobManager::instance (); - list > jobs; + list> jobs; - for (directory_iterator i = directory_iterator(*dir); i != directory_iterator(); ++i) { + for (auto i: directory_iterator(*dir)) { try { + progress.Pulse (); + shared_ptr 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" || i->path().extension() == ".ecinema") { - content = content_factory(film, *i).front(); + if (is_directory(i) && (is_regular_file(i / "ASSETMAP") || is_regular_file(i / "ASSETMAP.xml"))) { + content.reset (new DCPContent(i)); + } else if (i.path().extension() == ".mp4" || i.path().extension() == ".ecinema") { + content = content_factory(i).front(); } if (content) { - shared_ptr job(new ExamineContentJob(film, content)); + auto job = make_shared(shared_ptr(), content); jm->add (job); jobs.push_back (job); } } catch (boost::filesystem::filesystem_error& e) { /* Never mind */ - } catch (dcp::DCPReadError& e) { + } catch (dcp::ReadError& e) { /* Never mind */ } } @@ -109,24 +112,26 @@ ContentView::update () while (jm->work_to_do()) { if (!progress.Pulse()) { /* user pressed cancel */ - BOOST_FOREACH (shared_ptr i, jm->get()) { + for (auto i: jm->get()) { i->cancel(); } return; } - dcpomatic_sleep (1); + dcpomatic_sleep_seconds (1); } /* Add content from successful jobs and report errors */ - BOOST_FOREACH (shared_ptr i, jobs) { + for (auto i: jobs) { if (i->finished_in_error()) { error_dialog(this, std_to_wx(i->error_summary()) + ".\n", std_to_wx(i->error_details())); } else { add (i->content()); + _content.push_back (i->content()); } } } + void ContentView::add (shared_ptr content) { @@ -135,13 +140,12 @@ ContentView::add (shared_ptr content) wxListItem it; it.SetId(N); it.SetColumn(0); - DCPTime length = content->length_after_trim (); - int h, m, s, f; - length.split (24, h, m, s, f); - it.SetText(wxString::Format("%02d:%02d:%02d", h, m, s)); + auto length = content->approximate_length (); + auto const hmsf = length.split (24); + it.SetText(wxString::Format("%02d:%02d:%02d", hmsf.h, hmsf.m, hmsf.s)); InsertItem(it); - shared_ptr dcp = dynamic_pointer_cast(content); + auto dcp = dynamic_pointer_cast(content); if (dcp && dcp->content_kind()) { it.SetId(N); it.SetColumn(1); @@ -155,20 +159,15 @@ ContentView::add (shared_ptr content) SetItem(it); } + shared_ptr ContentView::get (string digest) const { - BOOST_FOREACH (shared_ptr i, _content) { + for (auto i: _content) { if (i->digest() == digest) { return i; } } - return shared_ptr(); -} - -void -ContentView::set_film (weak_ptr film) -{ - _film = film; + return {}; }