Tidy up handling of content-modified checks when using the dcpomatic_cli.
authorCarl Hetherington <cth@carlh.net>
Tue, 23 Jul 2019 13:26:02 +0000 (14:26 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 23 Jul 2019 13:26:02 +0000 (14:26 +0100)
src/lib/check_content_change_job.cc
src/lib/check_content_change_job.h
src/lib/film.cc
src/lib/film.h
src/lib/util.cc
src/tools/dcpomatic.cc
src/tools/dcpomatic_cli.cc

index 468933a..2bc562f 100644 (file)
@@ -33,9 +33,11 @@ using std::list;
 using std::cout;
 using boost::shared_ptr;
 
-CheckContentChangeJob::CheckContentChangeJob (shared_ptr<const Film> film, shared_ptr<Job> following)
+/** @param gui true if we are running this job from the GUI, false if it's the CLI */
+CheckContentChangeJob::CheckContentChangeJob (shared_ptr<const Film> film, shared_ptr<Job> following, bool gui)
        : Job (film)
        , _following (following)
+       , _gui (gui)
 {
 
 }
@@ -79,18 +81,28 @@ CheckContentChangeJob::run ()
                JobManager::instance()->add(shared_ptr<Job>(new ExamineContentJob(_film, i)));
        }
 
-       set_progress (1);
-       set_state (FINISHED_OK);
-
        if (!changed.empty()) {
-               string m = _("Some files have been changed since they were added to the project.\n\nThese files will now be re-examined, so you may need to check their settings.");
-               if (_following) {
-                       /* I'm assuming that _following is a make DCP job */
-                       m += "  ";
-                       m += _("Choose 'Make DCP' again when you have done this.");
+               if (_gui) {
+                       string m = _("Some files have been changed since they were added to the project.\n\nThese files will now be re-examined, so you may need to check their settings.");
+                       if (_following) {
+                               /* I'm assuming that _following is a make DCP job */
+                               m += "  ";
+                               m += _("Choose 'Make DCP' again when you have done this.");
+                       }
+                       set_message (m);
+               } else {
+                       set_progress (1);
+                       set_state (FINISHED_ERROR);
+                       set_error (
+                               _("Some files have been changed since they were added to the project.  Open the project in DCP-o-matic, check the settings, then save it before trying again."),
+                               ""
+                               );
+                       return;
                }
-               set_message (m);
        } else if (_following) {
                JobManager::instance()->add (_following);
        }
+
+       set_progress (1);
+       set_state (FINISHED_OK);
 }
index da9c5cb..5d0af68 100644 (file)
@@ -27,7 +27,7 @@
 class CheckContentChangeJob : public Job
 {
 public:
-       CheckContentChangeJob (boost::shared_ptr<const Film>, boost::shared_ptr<Job> following = boost::shared_ptr<Job>());
+       CheckContentChangeJob (boost::shared_ptr<const Film>, boost::shared_ptr<Job> following = boost::shared_ptr<Job>(), bool gui = false);
 
        std::string name () const;
        std::string json_name () const;
@@ -35,4 +35,5 @@ public:
 
 private:
        boost::shared_ptr<Job> _following;
+       bool _gui;
 };
index e542688..6870339 100644 (file)
@@ -299,7 +299,7 @@ Film::audio_analysis_path (shared_ptr<const Playlist> playlist) const
 
 /** Add suitable Jobs to the JobManager to create a DCP for this Film */
 void
-Film::make_dcp ()
+Film::make_dcp (bool gui)
 {
        if (dcp_name().find ("/") != string::npos) {
                throw BadSettingError (_("name"), _("Cannot contain slashes"));
@@ -353,7 +353,7 @@ Film::make_dcp ()
 
        shared_ptr<TranscodeJob> tj (new TranscodeJob (shared_from_this()));
        tj->set_encoder (shared_ptr<Encoder> (new DCPEncoder (shared_from_this(), tj)));
-       shared_ptr<CheckContentChangeJob> cc (new CheckContentChangeJob (shared_from_this(), tj));
+       shared_ptr<CheckContentChangeJob> cc (new CheckContentChangeJob(shared_from_this(), tj, gui));
        JobManager::instance()->add (cc);
 }
 
index 876d312..1c50224 100644 (file)
@@ -82,7 +82,7 @@ public:
        boost::filesystem::path audio_analysis_path (boost::shared_ptr<const Playlist>) const;
 
        void send_dcp_to_tms ();
-       void make_dcp ();
+       void make_dcp (bool gui = false);
 
        /** @return Logger.
         *  It is safe to call this from any thread.
index 3b6be6d..fee4a3c 100644 (file)
@@ -949,10 +949,9 @@ emit_subtitle_image (ContentTimePeriod period, dcp::SubtitleImage sub, dcp::Size
 bool
 show_jobs_on_console (bool progress)
 {
-       bool should_stop = false;
        bool first = true;
        bool error = false;
-       while (!should_stop) {
+       while (true) {
 
                dcpomatic_sleep (5);
 
@@ -967,9 +966,6 @@ show_jobs_on_console (bool progress)
 
                first = false;
 
-               int unfinished = 0;
-               int finished_in_error = 0;
-
                BOOST_FOREACH (shared_ptr<Job> i, jobs) {
                        if (progress) {
                                cout << i->name();
@@ -985,25 +981,20 @@ show_jobs_on_console (bool progress)
                                }
                        }
 
-                       if (!i->finished ()) {
-                               ++unfinished;
-                       }
-
-                       if (i->finished_in_error ()) {
-                               ++finished_in_error;
-                               error = true;
-                       }
-
-                       if (!progress && i->finished_in_error ()) {
+                       if (!progress && i->finished_in_error()) {
                                /* We won't see this error if we haven't been showing progress,
                                   so show it now.
                                */
                                cout << i->status() << "\n";
                        }
+
+                       if (i->finished_in_error()) {
+                               error = true;
+                       }
                }
 
-               if (unfinished == 0 || finished_in_error != 0) {
-                       should_stop = true;
+               if (!JobManager::instance()->work_to_do()) {
+                       break;
                }
        }
 
index 5b2e187..572a5be 100644 (file)
@@ -757,7 +757,7 @@ private:
                           a long time, and crashes/power failures are moderately likely.
                        */
                        _film->write_metadata ();
-                       _film->make_dcp ();
+                       _film->make_dcp (true);
                } catch (BadSettingError& e) {
                        error_dialog (this, wxString::Format (_("Bad setting for %s."), std_to_wx(e.setting()).data()), std_to_wx(e.what()));
                } catch (std::exception& e) {
index 9388112..13efb6b 100644 (file)
@@ -349,7 +349,7 @@ main (int argc, char* argv[])
                cout << "\nMaking DCP for " << film->name() << "\n";
        }
 
-       film->make_dcp ();
+       film->make_dcp (false);
        bool const error = show_jobs_on_console (progress);
 
        if (keep_going) {