Separate Controls into standard/swaroop.
[dcpomatic.git] / src / wx / content_view.cc
index e1503e790f15d67161e11fb73c59881f8b8f4af3..51473cb8652d030e6060bdbb12402583add3b0ea 100644 (file)
@@ -34,6 +34,7 @@
 
 using std::string;
 using std::cout;
+using std::list;
 using boost::shared_ptr;
 using boost::weak_ptr;
 using boost::optional;
@@ -82,6 +83,8 @@ ContentView::update ()
        wxProgressDialog progress (_("DCP-o-matic"), _("Reading content directory"));
        JobManager* jm = JobManager::instance ();
 
+       list<shared_ptr<ExamineContentJob> > jobs;
+
        for (directory_iterator i = directory_iterator(*dir); i != directory_iterator(); ++i) {
                try {
                        shared_ptr<Content> content;
@@ -92,21 +95,9 @@ ContentView::update ()
                        }
 
                        if (content) {
-                               jm->add (shared_ptr<Job>(new ExamineContentJob(film, content)));
-                               while (jm->work_to_do()) {
-                                       if (!progress.Pulse()) {
-                                               /* user pressed cancel */
-                                               BOOST_FOREACH (shared_ptr<Job> i, jm->get()) {
-                                                       i->cancel();
-                                               }
-                                               return;
-                                       }
-                                       dcpomatic_sleep (1);
-                               }
-                               if (report_errors_from_last_job (this)) {
-                                       add (content);
-                                       _content.push_back (content);
-                               }
+                               shared_ptr<ExamineContentJob> job(new ExamineContentJob(film, content));
+                               jm->add (job);
+                               jobs.push_back (job);
                        }
                } catch (boost::filesystem::filesystem_error& e) {
                        /* Never mind */
@@ -114,6 +105,27 @@ ContentView::update ()
                        /* Never mind */
                }
        }
+
+       while (jm->work_to_do()) {
+               if (!progress.Pulse()) {
+                       /* user pressed cancel */
+                       BOOST_FOREACH (shared_ptr<Job> i, jm->get()) {
+                               i->cancel();
+                       }
+                       return;
+               }
+               dcpomatic_sleep (1);
+       }
+
+       /* Add content from successful jobs and report errors */
+       BOOST_FOREACH (shared_ptr<ExamineContentJob> 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
@@ -159,5 +171,10 @@ ContentView::get (string digest) const
 void
 ContentView::set_film (weak_ptr<Film> film)
 {
+       if (_film.lock() == film.lock()) {
+               return;
+       }
+
        _film = film;
+       update ();
 }