Merge master.
[dcpomatic.git] / src / lib / job.cc
index 812380594ec0ea247661951d93909773fbce2201..080d1eaf6018a5588c9d9f0c31a63c894585a4a1 100644 (file)
@@ -26,6 +26,8 @@
 #include <libdcp/exceptions.h>
 #include "job.h"
 #include "util.h"
+#include "cross.h"
+#include "ui_signaller.h"
 
 #include "i18n.h"
 
@@ -34,7 +36,7 @@ using std::list;
 using std::stringstream;
 using boost::shared_ptr;
 
-Job::Job (shared_ptr<Film> f)
+Job::Job (shared_ptr<const Film> f)
        : _film (f)
        , _thread (0)
        , _state (NEW)
@@ -153,6 +155,13 @@ Job::finished_cancelled () const
        return _state == FINISHED_CANCELLED;
 }
 
+bool
+Job::paused () const
+{
+       boost::mutex::scoped_lock lm (_state_mutex);
+       return _state == PAUSED;
+}
+       
 /** Set the state of this job.
  *  @param s New state.
  */
@@ -162,8 +171,11 @@ Job::set_state (State s)
        boost::mutex::scoped_lock lm (_state_mutex);
        _state = s;
 
-       if (_state == FINISHED_OK || _state == FINISHED_ERROR) {
+       if (_state == FINISHED_OK || _state == FINISHED_ERROR || _state == FINISHED_CANCELLED) {
                _ran_for = elapsed_time ();
+               if (ui_signaller) {
+                       ui_signaller->emit (boost::bind (boost::ref (Finished)));
+               }
        }
 }
 
@@ -188,6 +200,10 @@ Job::set_progress (float p)
        _progress_unknown = false;
        _stack.back().normalised = p;
        boost::this_thread::interruption_point ();
+
+       if (paused ()) {
+               dcpomatic_sleep (1);
+       }
 }
 
 /** @return fractional overall progress, or -1 if not known */
@@ -324,3 +340,19 @@ Job::cancel ()
        _thread->interrupt ();
        _thread->join ();
 }
+
+void
+Job::pause ()
+{
+       if (running ()) {
+               set_state (PAUSED);
+       }
+}
+
+void
+Job::resume ()
+{
+       if (paused ()) {
+               set_state (RUNNING);
+       }
+}