Remove all use of stringstream in an attempt to fix
[dcpomatic.git] / src / lib / job.cc
index 0699c532c0fa4c69582bf954efa194b9b1ebcce4..6e2bc9f53bed706910be46e5414efd9e253c43fa 100644 (file)
@@ -52,6 +52,7 @@ Job::Job (shared_ptr<const Film> film)
        , _thread (0)
        , _state (NEW)
        , _start_time (0)
+       , _sub_start_time (0)
        , _progress (0)
        , _ran_for (0)
 {
@@ -81,6 +82,7 @@ Job::start ()
 {
        set_state (RUNNING);
        _start_time = time (0);
+       _sub_start_time = time (0);
        _thread = new boost::thread (boost::bind (&Job::run_wrapper, this));
 }
 
@@ -242,7 +244,7 @@ Job::set_state (State s)
                _state = s;
 
                if (_state == FINISHED_OK || _state == FINISHED_ERROR || _state == FINISHED_CANCELLED) {
-                       _ran_for = elapsed_time ();
+                       _ran_for = time(0) - _start_time;
                        finished = true;
                        _sub_name.clear ();
                }
@@ -255,13 +257,13 @@ Job::set_state (State s)
 
 /** @return DCPTime (in seconds) that this sub-job has been running */
 int
-Job::elapsed_time () const
+Job::elapsed_sub_time () const
 {
-       if (_start_time == 0) {
+       if (_sub_start_time == 0) {
                return 0;
        }
 
-       return time (0) - _start_time;
+       return time (0) - _sub_start_time;
 }
 
 /** Set the progress of the current part of the job.
@@ -324,6 +326,7 @@ Job::sub (string n)
        }
 
        set_progress (0, true);
+       _sub_start_time = time (0);
 }
 
 string
@@ -370,10 +373,10 @@ string
 Job::status () const
 {
        optional<float> p = progress ();
-       int const t = elapsed_time ();
+       int const t = elapsed_sub_time ();
        int const r = remaining_time ();
 
-       SafeStringStream s;
+       string s;
        if (!finished () && p) {
                int pc = lrintf (p.get() * 100);
                if (pc == 100) {
@@ -381,22 +384,24 @@ Job::status () const
                        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
@@ -427,10 +432,10 @@ int
 Job::remaining_time () const
 {
        if (progress().get_value_or(0) == 0) {
-               return elapsed_time ();
+               return elapsed_sub_time ();
        }
 
-       return elapsed_time() / progress().get() - elapsed_time();
+       return elapsed_sub_time() / progress().get() - elapsed_sub_time();
 }
 
 void