Fix job pausing to actually work, and always add Pause buttons to JobManagerViews...
[dcpomatic.git] / src / lib / job.cc
index 66fa3755dfb69d3c751a15cde8c868d083927339..52276c0eab3d69ae834f08bd80d8522715c66cd7 100644 (file)
 #include "cross.h"
 #include "ui_signaller.h"
 #include "exceptions.h"
+#include "safe_stringstream.h"
 
 #include "i18n.h"
 
 using std::string;
 using std::list;
 using std::cout;
-using std::stringstream;
 using boost::shared_ptr;
 
 Job::Job (shared_ptr<const Film> f)
@@ -108,7 +108,7 @@ Job::run_wrapper ()
 
                set_error (
                        e.what (),
-                       _("It is not known what caused this error.  The best idea is to report the problem to the DCP-o-matic mailing list (carl@dcpomatic.com)")
+                       _("It is not known what caused this error.  Please report the problem to the DCP-o-matic author (carl@dcpomatic.com).")
                        );
 
                set_progress (1);
@@ -118,7 +118,7 @@ Job::run_wrapper ()
 
                set_error (
                        _("Unknown error"),
-                       _("It is not known what caused this error.  The best idea is to report the problem to the DCP-o-matic mailing list (carl@dcpomatic.com)")
+                       _("It is not known what caused this error.  Please report the problem to the DCP-o-matic author (carl@dcpomatic.com).")
                        );
 
                set_progress (1);
@@ -187,7 +187,7 @@ void
 Job::set_state (State s)
 {
        bool finished = false;
-       
+
        {
                boost::mutex::scoped_lock lm (_state_mutex);
                _state = s;
@@ -201,7 +201,7 @@ Job::set_state (State s)
 
        if (finished && ui_signaller) {
                ui_signaller->emit (boost::bind (boost::ref (Finished)));
-       }
+       }       
 }
 
 /** @return Time (in seconds) that this sub-job has been running */
@@ -230,8 +230,9 @@ Job::set_progress (float p, bool force)
        _progress = p;
        boost::this_thread::interruption_point ();
 
-       if (paused ()) {
-               dcpomatic_sleep (1);
+       boost::mutex::scoped_lock lm2 (_state_mutex);
+       while (_state == PAUSED) {
+               _pause_changed.wait (lm2);
        }
 
        if (ui_signaller) {
@@ -239,7 +240,7 @@ Job::set_progress (float p, bool force)
        }
 }
 
-/** @return fractional progress of this sub-job, or -1 if not known */
+/** @return fractional progress of the current sub-job, or -1 if not known */
 float
 Job::progress () const
 {
@@ -306,7 +307,7 @@ Job::status () const
                pc = 99;
        }
 
-       stringstream s;
+       SafeStringStream s;
        if (!finished ()) {
                s << pc << N_("%");
                if (p >= 0 && t > 10 && r > 0) {
@@ -348,6 +349,7 @@ Job::pause ()
 {
        if (running ()) {
                set_state (PAUSED);
+               _pause_changed.notify_all ();
        }
 }
 
@@ -356,5 +358,6 @@ Job::resume ()
 {
        if (paused ()) {
                set_state (RUNNING);
+               _pause_changed.notify_all ();
        }
 }