Tidy up handling of content-modified checks when using the dcpomatic_cli.
[dcpomatic.git] / src / lib / util.cc
index 340af1ea839ba8c96c75f39fcc7f671ea254255b..fee4a3c26aab11ac4bf094d5977d6d9c27e18e9a 100644 (file)
@@ -44,6 +44,7 @@
 #include "ffmpeg_image_proxy.h"
 #include "image.h"
 #include "text_decoder.h"
+#include "job_manager.h"
 #include <dcp/locale_convert.h>
 #include <dcp/util.h>
 #include <dcp/raw_convert.h>
@@ -106,6 +107,7 @@ using boost::scoped_array;
 using dcp::Size;
 using dcp::raw_convert;
 using dcp::locale_convert;
+using namespace dcpomatic;
 
 /** Path to our executable, required by the stacktrace stuff and filled
  *  in during App::onInit().
@@ -944,6 +946,61 @@ emit_subtitle_image (ContentTimePeriod period, dcp::SubtitleImage sub, dcp::Size
        decoder->emit_bitmap (period, image, rect);
 }
 
+bool
+show_jobs_on_console (bool progress)
+{
+       bool first = true;
+       bool error = false;
+       while (true) {
+
+               dcpomatic_sleep (5);
+
+               list<shared_ptr<Job> > jobs = JobManager::instance()->get();
+
+               if (!first && progress) {
+                       for (size_t i = 0; i < jobs.size(); ++i) {
+                               cout << "\033[1A\033[2K";
+                       }
+                       cout.flush ();
+               }
+
+               first = false;
+
+               BOOST_FOREACH (shared_ptr<Job> i, jobs) {
+                       if (progress) {
+                               cout << i->name();
+                               if (!i->sub_name().empty()) {
+                                       cout << "; " << i->sub_name();
+                               }
+                               cout << ": ";
+
+                               if (i->progress ()) {
+                                       cout << i->status() << "                            \n";
+                               } else {
+                                       cout << ": Running           \n";
+                               }
+                       }
+
+                       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 (!JobManager::instance()->work_to_do()) {
+                       break;
+               }
+       }
+
+       return error;
+}
+
 #ifdef DCPOMATIC_VARIANT_SWAROOP
 
 /* Make up a key from the machine UUID */