X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Fcontent_view.cc;h=67a9a3fa53c90b4faa1395ef5200c1701bdba14f;hb=dd9be86db6cde0afa5da0d1d1ac43b42e05dca26;hp=4eab80339ec09fcbf509c2d2a77d0231122810e3;hpb=a3f6e20d055cdf1697eab011622dc569010ad617;p=dcpomatic.git diff --git a/src/wx/content_view.cc b/src/wx/content_view.cc index 4eab80339..67a9a3fa5 100644 --- a/src/wx/content_view.cc +++ b/src/wx/content_view.cc @@ -32,14 +32,17 @@ #include #include -using boost::shared_ptr; -using boost::weak_ptr; +using std::string; +using std::cout; +using std::list; +using std::shared_ptr; +using std::weak_ptr; using boost::optional; -using boost::dynamic_pointer_cast; +using std::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 */ @@ -63,59 +66,63 @@ ContentView::selected () const void ContentView::update () { - if (!IsShown()) { - return; - } - - 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; + if (!dir || !boost::filesystem::is_directory(*dir)) { + dir = home_directory (); } wxProgressDialog progress (_("DCP-o-matic"), _("Reading content directory")); JobManager* jm = JobManager::instance (); + list > jobs; + for (directory_iterator i = directory_iterator(*dir); i != directory_iterator(); ++i) { 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)); + content.reset (new DCPContent(*i)); } else if (i->path().extension() == ".mp4" || i->path().extension() == ".ecinema") { - content = content_factory(film, *i).front(); + content = content_factory(*i).front(); } if (content) { - jm->add (shared_ptr(new ExamineContentJob(film, content))); - while (jm->work_to_do()) { - if (!progress.Pulse()) { - /* user pressed cancel */ - BOOST_FOREACH (shared_ptr i, jm->get()) { - i->cancel(); - } - return; - } - dcpomatic_sleep (1); - } - if (report_errors_from_last_job (this)) { - add (content); - _content.push_back (content); - } + shared_ptr job(new ExamineContentJob(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 */ } } + + while (jm->work_to_do()) { + if (!progress.Pulse()) { + /* user pressed cancel */ + BOOST_FOREACH (shared_ptr i, jm->get()) { + i->cancel(); + } + return; + } + dcpomatic_sleep_seconds (1); + } + + /* Add content from successful jobs and report errors */ + BOOST_FOREACH (shared_ptr 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 @@ -126,7 +133,7 @@ ContentView::add (shared_ptr content) wxListItem it; it.SetId(N); it.SetColumn(0); - DCPTime length = content->length_after_trim (); + DCPTime length = content->approximate_length (); int h, m, s, f; length.split (24, h, m, s, f); it.SetText(wxString::Format("%02d:%02d:%02d", h, m, s)); @@ -145,3 +152,15 @@ ContentView::add (shared_ptr content) it.SetText(std_to_wx(content->summary())); SetItem(it); } + +shared_ptr +ContentView::get (string digest) const +{ + BOOST_FOREACH (shared_ptr i, _content) { + if (i->digest() == digest) { + return i; + } + } + + return shared_ptr(); +}