/*
- Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
#include "log.h"
#include "compose.hpp"
#include <dcp/exceptions.h>
+#include <sub/exceptions.h>
#include <boost/thread.hpp>
#include <boost/filesystem.hpp>
+#include <boost/foreach.hpp>
#include <iostream>
#include "i18n.h"
using boost::optional;
using boost::function;
-#define LOG_ERROR_NC(...) _film->log()->log (__VA_ARGS__, LogEntry::TYPE_ERROR);
-#define LOG_GENERAL(...) _film->log()->log (String::compose (__VA_ARGS__), LogEntry::TYPE_GENERAL);
+#define LOG_ERROR_NC(...) if (_film) { _film->log()->log (__VA_ARGS__, LogEntry::TYPE_ERROR); }
+#define LOG_GENERAL(...) if (_film) { _film->log()->log (String::compose (__VA_ARGS__), LogEntry::TYPE_GENERAL); }
/** @param film Associated film, or 0 */
Job::Job (shared_ptr<const Film> film)
set_state (FINISHED_CANCELLED);
+ } catch (sub::SubripError& e) {
+
+ string extra = "Error is near:\n";
+ BOOST_FOREACH (string i, e.context()) {
+ extra += i + "\n";
+ }
+
+ set_error (e.what (), extra);
+ set_progress (1);
+ set_state (FINISHED_ERROR);
+
} catch (std::bad_alloc& e) {
set_error (_("Out of memory"), _("There was not enough memory to do this. If you are running a 32-bit operating system try reducing the number of encoding threads in the General tab of Preferences."));
return time (0) - _sub_start_time;
}
+/** Check to see if this job has been interrupted or paused */
+void
+Job::check_for_interruption_or_pause ()
+{
+ boost::this_thread::interruption_point ();
+
+ boost::mutex::scoped_lock lm (_state_mutex);
+ while (_state == PAUSED) {
+ emit (boost::bind (boost::ref (Progress)));
+ _pause_changed.wait (lm);
+ }
+}
+
/** Set the progress of the current part of the job.
* @param p Progress (from 0 to 1)
*/
void
Job::set_progress (float p, bool force)
{
+ check_for_interruption_or_pause ();
+
if (!force) {
/* Check for excessively frequent progress reporting */
boost::mutex::scoped_lock lm (_progress_mutex);
void
Job::set_progress_common (optional<float> p)
{
- boost::mutex::scoped_lock lm (_progress_mutex);
- _progress = p;
- boost::this_thread::interruption_point ();
-
- boost::mutex::scoped_lock lm2 (_state_mutex);
- while (_state == PAUSED) {
- _pause_changed.wait (lm2);
+ {
+ boost::mutex::scoped_lock lm (_progress_mutex);
+ _progress = p;
}
- lm.unlock ();
- lm2.unlock ();
-
emit (boost::bind (boost::ref (Progress)));
}
void
Job::set_progress_unknown ()
{
+ check_for_interruption_or_pause ();
set_progress_common (optional<float> ());
}
int const t = elapsed_sub_time ();
int const r = remaining_time ();
- locked_stringstream s;
+ string s;
if (!finished () && p) {
int pc = lrintf (p.get() * 100);
if (pc == 100) {
pc = 99;
}
- s << pc << N_("%");
+ char buffer[64];
+ snprintf (buffer, sizeof(buffer), "%d%%", pc);
+ s += buffer;
if (t > 10 && r > 0) {
/// TRANSLATORS: remaining here follows an amount of time that is remaining
/// on an operation.
- s << "; " << seconds_to_approximate_hms (r) << " " << _("remaining");
+ s += "; " + seconds_to_approximate_hms (r) + " " + _("remaining");
}
} else if (finished_ok ()) {
- s << String::compose (_("OK (ran for %1)"), seconds_to_hms (_ran_for));
+ s = String::compose (_("OK (ran for %1)"), seconds_to_hms (_ran_for));
} else if (finished_in_error ()) {
- s << String::compose (_("Error: %1"), error_summary ());
+ s = String::compose (_("Error: %1"), error_summary ());
} else if (finished_cancelled ()) {
- s << _("Cancelled");
+ s = _("Cancelled");
}
- return s.str ();
+ return s;
}
string