No-op: remove all trailing whitespace.
[dcpomatic.git] / src / lib / job.cc
index 68aa6230abf150574c85a1b36084775b73c087f2..71e4c34464be7db3eec2db19dbd8b0c5fa31a454 100644 (file)
@@ -27,7 +27,6 @@
 #include "job.h"
 #include "util.h"
 #include "cross.h"
-#include "ui_signaller.h"
 #include "exceptions.h"
 #include "film.h"
 #include "log.h"
@@ -42,8 +41,8 @@ using boost::optional;
 
 #define LOG_ERROR_NC(...) _film->log()->log (__VA_ARGS__, Log::TYPE_ERROR);
 
-Job::Job (shared_ptr<const Film> f)
-       : _film (f)
+Job::Job (shared_ptr<const Film> film)
+       : _film (film)
        , _thread (0)
        , _state (NEW)
        , _start_time (0)
@@ -87,7 +86,7 @@ Job::run_wrapper ()
                set_error (e.what(), m);
                set_progress (1);
                set_state (FINISHED_ERROR);
-               
+
        } catch (OpenFileError& e) {
 
                set_error (
@@ -107,7 +106,7 @@ Job::run_wrapper ()
                set_error (_("Out of memory"), _("There was not enough memory to do this."));
                set_progress (1);
                set_state (FINISHED_ERROR);
-               
+
        } catch (std::exception& e) {
 
                set_error (
@@ -117,7 +116,7 @@ Job::run_wrapper ()
 
                set_progress (1);
                set_state (FINISHED_ERROR);
-               
+
        } catch (...) {
 
                set_error (
@@ -183,7 +182,7 @@ Job::paused () const
        boost::mutex::scoped_lock lm (_state_mutex);
        return _state == PAUSED;
 }
-       
+
 /** Set the state of this job.
  *  @param s New state.
  */
@@ -203,9 +202,9 @@ Job::set_state (State s)
                }
        }
 
-       if (finished && ui_signaller) {
-               ui_signaller->emit (boost::bind (boost::ref (Finished)));
-       }       
+       if (finished) {
+               emit (boost::bind (boost::ref (Finished)));
+       }
 }
 
 /** @return DCPTime (in seconds) that this sub-job has been running */
@@ -215,7 +214,7 @@ Job::elapsed_time () const
        if (_start_time == 0) {
                return 0;
        }
-       
+
        return time (0) - _start_time;
 }
 
@@ -239,9 +238,10 @@ Job::set_progress (float p, bool force)
                _pause_changed.wait (lm2);
        }
 
-       if (ui_signaller) {
-               ui_signaller->emit (boost::bind (boost::ref (Progress)));
-       }
+       lm.unlock ();
+       lm2.unlock ();
+
+       emit (boost::bind (boost::ref (Progress)));
 }
 
 /** @return fractional progress of the current sub-job, if known */
@@ -259,7 +259,7 @@ Job::sub (string n)
                boost::mutex::scoped_lock lm (_progress_mutex);
                _sub_name = n;
        }
-       
+
        set_progress (0, true);
 }
 
@@ -286,7 +286,7 @@ Job::set_error (string s, string d)
 {
        LOG_ERROR_NC (s);
        LOG_ERROR_NC (d);
-       
+
        _film->log()->log (String::compose ("Error in job: %1 (%2)", s, d), Log::TYPE_ERROR);
        boost::mutex::scoped_lock lm (_state_mutex);
        _error_summary = s;
@@ -301,9 +301,7 @@ Job::set_progress_unknown ()
        _progress.reset ();
        lm.unlock ();
 
-       if (ui_signaller) {
-               ui_signaller->emit (boost::bind (boost::ref (Progress)));
-       }
+       emit (boost::bind (boost::ref (Progress)));
 }
 
 /** @return Human-readable status of this job */
@@ -321,9 +319,9 @@ Job::status () const
                        /* 100% makes it sound like we've finished when we haven't */
                        pc = 99;
                }
-               
+
                s << pc << N_("%");
-               
+
                if (t > 10 && r > 0) {
                        /// TRANSLATORS: remaining here follows an amount of time that is remaining
                        /// on an operation.
@@ -332,11 +330,7 @@ Job::status () const
        } else if (finished_ok ()) {
                s << String::compose (_("OK (ran for %1)"), seconds_to_hms (_ran_for));
        } else if (finished_in_error ()) {
-               string es = error_summary ();
-               if (es.length() > 25) {
-                       es = es.substr (0, 25) + "...";
-               }
-               s << String::compose (_("Error (%1)"), es);
+               s << String::compose (_("Error (%1)"), error_summary ());
        } else if (finished_cancelled ()) {
                s << _("Cancelled");
        }
@@ -344,6 +338,29 @@ Job::status () const
        return s.str ();
 }
 
+string
+Job::json_status () const
+{
+       boost::mutex::scoped_lock lm (_state_mutex);
+
+       switch (_state) {
+       case NEW:
+               return N_("new");
+       case RUNNING:
+               return N_("running");
+       case PAUSED:
+               return N_("paused");
+       case FINISHED_OK:
+               return N_("finished_ok");
+       case FINISHED_ERROR:
+               return N_("finished_error");
+       case FINISHED_CANCELLED:
+               return N_("finished_cancelled");
+       }
+
+       return "";
+}
+
 /** @return An estimate of the remaining time for this sub-job, in seconds */
 int
 Job::remaining_time () const
@@ -351,7 +368,7 @@ Job::remaining_time () const
        if (progress().get_value_or(0) == 0) {
                return elapsed_time ();
        }
-       
+
        return elapsed_time() / progress().get() - elapsed_time();
 }
 
@@ -362,6 +379,10 @@ Job::cancel ()
                return;
        }
 
+       if (paused ()) {
+               resume ();
+       }
+
        _thread->interrupt ();
        _thread->join ();
 }