Tidy up test film naming.
[dcpomatic.git] / src / lib / job.cc
index 22754eb909659ffd8693b48c77a9c184b6c40f9b..68cdce3cd3a961ed1e3e272280d2ce3c62ac4fa6 100644 (file)
@@ -31,16 +31,16 @@ using namespace std;
 using namespace boost;
 
 /** @param s FilmState for the film that we are operating on.
- *  @param o Options.
  *  @param l A log that we can write to.
  */
-Job::Job (shared_ptr<const FilmState> s, shared_ptr<const Options> o, Log* l)
+Job::Job (shared_ptr<const FilmState> s, Log* l, shared_ptr<Job> req)
        : _fs (s)
-       , _opt (o)
        , _log (l)
+       , _required (req)
        , _state (NEW)
        , _start_time (0)
        , _progress_unknown (false)
+       , _ran_for (0)
 {
        assert (_log);
        
@@ -68,9 +68,7 @@ Job::run_wrapper ()
                
                set_progress (1);
                set_state (FINISHED_ERROR);
-               stringstream s;
-               s << e.what() << "(" << filesystem::path (e.filename()).leaf() << ")";
-               set_error (s.str ());
+               set_error (String::compose ("%1 (%2)", e.what(), filesystem::path (e.filename()).leaf()));
                
        } catch (std::exception& e) {
 
@@ -81,6 +79,13 @@ Job::run_wrapper ()
        }
 }
 
+bool
+Job::is_new () const
+{
+       boost::mutex::scoped_lock lm (_state_mutex);
+       return _state == NEW;
+}
+
 /** @return true if the job is running */
 bool
 Job::running () const
@@ -121,6 +126,10 @@ Job::set_state (State s)
 {
        boost::mutex::scoped_lock lm (_state_mutex);
        _state = s;
+
+       if (_state == FINISHED_OK || _state == FINISHED_ERROR) {
+               _ran_for = elapsed_time ();
+       }
 }
 
 /** A hack to work around our lack of cross-thread
@@ -152,6 +161,7 @@ void
 Job::set_progress (float p)
 {
        boost::mutex::scoped_lock lm (_progress_mutex);
+       _progress_unknown = false;
        _stack.back().normalised = p;
 }
 
@@ -223,7 +233,7 @@ Job::set_error (string e)
        _error = e;
 }
 
-/** Say that this job's progress will always be unknown */
+/** Say that this job's progress will be unknown until further notice */
 void
 Job::set_progress_unknown ()
 {
@@ -245,7 +255,7 @@ Job::status () const
        } else if (!finished () && (t <= 10 || r == 0)) {
                s << rint (p * 100) << "%";
        } else if (finished_ok ()) {
-               s << "OK (ran for " << seconds_to_hms (t) << ")";
+               s << "OK (ran for " << seconds_to_hms (_ran_for) << ")";
        } else if (finished_in_error ()) {
                s << "Error (" << error() << ")";
        }