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 468933ae496169a1601672bb527db6a01bdad4a3..2bc562f57730339bce035be957368f7a29e8d8b2 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 da9c5cb20be0d0aa71186956621fb8fd7fbeba82..5d0af688125ca9d7ab439d3cf8177bf07f0ff3ca 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 e54268805ca9c71d752ecd89026d84cf6ebdc6ca..687033908db186257f93b2d84cf958796b10edf4 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 876d312ae427666c23649aca3db4e5690d0e36f1..1c5022428a332563ee586ca1441cfc64756ae69c 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 3b6be6dcc227625d28574da53b3af4419d893d28..fee4a3c26aab11ac4bf094d5977d6d9c27e18e9a 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 5b2e1870be1d09d706c706f0cd0b14b6a5f024de..572a5be40adf0b20e74fa5c56502ae77f5275225 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 9388112f6e613861a621ab20d86a222982389109..13efb6b1958dd537060b7dafcee37d9a49955525 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) {