Merge branch 'master' of /home/carl/git/dvdomatic
[dcpomatic.git] / src / lib / job.cc
index 399b235d9bee7d0264d19da544c4a20f283966d8..22754eb909659ffd8693b48c77a9c184b6c40f9b 100644 (file)
@@ -22,6 +22,8 @@
  */
 
 #include <boost/thread.hpp>
+#include <boost/filesystem.hpp>
+#include <libdcp/exceptions.h>
 #include "job.h"
 #include "util.h"
 
@@ -62,6 +64,14 @@ Job::run_wrapper ()
 
                run ();
 
+       } catch (libdcp::FileError& e) {
+               
+               set_progress (1);
+               set_state (FINISHED_ERROR);
+               stringstream s;
+               s << e.what() << "(" << filesystem::path (e.filename()).leaf() << ")";
+               set_error (s.str ());
+               
        } catch (std::exception& e) {
 
                set_progress (1);
@@ -213,7 +223,7 @@ Job::set_error (string e)
        _error = e;
 }
 
-/** Set that this job's progress will always be unknown */
+/** Say that this job's progress will always be unknown */
 void
 Job::set_progress_unknown ()
 {
@@ -221,16 +231,18 @@ Job::set_progress_unknown ()
        _progress_unknown = true;
 }
 
+/** @return Human-readable status of this job */
 string
 Job::status () const
 {
        float const p = overall_progress ();
        int const t = elapsed_time ();
+       int const r = remaining_time ();
        
        stringstream s;
-       if (!finished () && p >= 0 && t > 10) {
-               s << rint (p * 100) << "%; about " << seconds_to_approximate_hms (t / p - t) << " remaining";
-       } else if (!finished () && t <= 10) {
+       if (!finished () && p >= 0 && t > 10 && r > 0) {
+               s << rint (p * 100) << "%; " << seconds_to_approximate_hms (r) << " remaining";
+       } else if (!finished () && (t <= 10 || r == 0)) {
                s << rint (p * 100) << "%";
        } else if (finished_ok ()) {
                s << "OK (ran for " << seconds_to_hms (t) << ")";
@@ -240,3 +252,10 @@ Job::status () const
 
        return s.str ();
 }
+
+/** @return An estimate of the remaining time for this job, in seconds */
+int
+Job::remaining_time () const
+{
+       return elapsed_time() / overall_progress() - elapsed_time();
+}