X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Flib%2Fjob.cc;h=912c6a6ef3c961374a81bd4863509a94d0c524f2;hb=a6c4b4fa16d9c6597e362044b875f3d6df80753f;hp=5bed3f0d273c6b5216ce2bb0c67b3b52c3953db2;hpb=1d3085c403f265fb203654d461c0b77974205f2f;p=dcpomatic.git diff --git a/src/lib/job.cc b/src/lib/job.cc index 5bed3f0d2..912c6a6ef 100644 --- a/src/lib/job.cc +++ b/src/lib/job.cc @@ -25,6 +25,7 @@ #include "compose.hpp" +#include "constants.h" #include "cross.h" #include "dcpomatic_log.h" #include "exceptions.h" @@ -235,6 +236,12 @@ Job::run_wrapper () set_progress (1); set_state (FINISHED_ERROR); + } catch (CPLNotFoundError& e) { + + set_error(e.what()); + set_progress(1); + set_state(FINISHED_ERROR); + } catch (std::exception& e) { set_error ( @@ -337,6 +344,10 @@ Job::set_state (State s) { boost::mutex::scoped_lock lm (_state_mutex); + if (_state == s) { + return; + } + _state = s; if (_state == FINISHED_OK || _state == FINISHED_ERROR || _state == FINISHED_CANCELLED) { @@ -347,12 +358,31 @@ Job::set_state (State s) } if (finished) { - emit (boost::bind (boost::ref (Finished))); - FinishedImmediate (); + auto const result = state_to_result(s); + emit(boost::bind(boost::ref(Finished), result)); + FinishedImmediate(result); } } +Job::Result +Job::state_to_result(State state) const +{ + switch (state) { + case FINISHED_OK: + return Result::RESULT_OK; + case FINISHED_ERROR: + return Result::RESULT_ERROR; + case FINISHED_CANCELLED: + return Result::RESULT_CANCELLED; + default: + DCPOMATIC_ASSERT(false); + }; + + DCPOMATIC_ASSERT(false); +} + + /** @return DCPTime (in seconds) that this sub-job has been running */ int Job::elapsed_sub_time () const @@ -507,6 +537,27 @@ Job::status () const int const t = elapsed_sub_time (); int const r = remaining_time (); + auto day_of_week_to_string = [](boost::gregorian::greg_weekday d) -> std::string { + switch (d.as_enum()) { + case boost::date_time::Sunday: + return _("Sunday"); + case boost::date_time::Monday: + return _("Monday"); + case boost::date_time::Tuesday: + return _("Tuesday"); + case boost::date_time::Wednesday: + return _("Wednesday"); + case boost::date_time::Thursday: + return _("Thursday"); + case boost::date_time::Friday: + return _("Friday"); + case boost::date_time::Saturday: + return _("Saturday"); + } + + return d.as_long_string(); + }; + string s; if (!finished () && p) { int pc = lrintf (p.get() * 100); @@ -589,17 +640,13 @@ Job::remaining_time () const void Job::cancel () { - if (!_thread.joinable()) { - return; - } + if (_thread.joinable()) { + resume(); - if (paused_by_user() || paused_by_priority()) { - resume (); + _thread.interrupt (); + _thread.join (); } - _thread.interrupt (); - _thread.join (); - set_state (FINISHED_CANCELLED); } @@ -649,11 +696,11 @@ Job::resume () void -Job::when_finished (boost::signals2::connection& connection, function finished) +Job::when_finished(boost::signals2::connection& connection, function finished) { boost::mutex::scoped_lock lm (_state_mutex); if (_state == FINISHED_OK || _state == FINISHED_ERROR || _state == FINISHED_CANCELLED) { - finished (); + finished(state_to_result(_state)); } else { connection = Finished.connect (finished); }