+void wxGenericProgressDialog::UpdateTimeEstimates(int value,
+ unsigned long &elapsedTime,
+ unsigned long &estimatedTime,
+ unsigned long &remainingTime)
+{
+ unsigned long elapsed = wxGetCurrentTime() - m_timeStart;
+ if ( value != 0 && (m_last_timeupdate < elapsed || value == m_maximum) )
+ {
+ m_last_timeupdate = elapsed;
+ unsigned long estimated = m_break +
+ (unsigned long)(( (double) (elapsed-m_break) * m_maximum ) / ((double)value)) ;
+ if ( estimated > m_display_estimated
+ && m_ctdelay >= 0
+ )
+ {
+ ++m_ctdelay;
+ }
+ else if ( estimated < m_display_estimated
+ && m_ctdelay <= 0
+ )
+ {
+ --m_ctdelay;
+ }
+ else
+ {
+ m_ctdelay = 0;
+ }
+ if ( m_ctdelay >= m_delay // enough confirmations for a higher value
+ || m_ctdelay <= (m_delay*-1) // enough confirmations for a lower value
+ || value == m_maximum // to stay consistent
+ || elapsed > m_display_estimated // to stay consistent
+ || ( elapsed > 0 && elapsed < 4 ) // additional updates in the beginning
+ )
+ {
+ m_display_estimated = estimated;
+ m_ctdelay = 0;
+ }
+ }
+
+ if ( value != 0 )
+ {
+ long display_remaining = m_display_estimated - elapsed;
+ if ( display_remaining < 0 )
+ {
+ display_remaining = 0;
+ }
+
+ estimatedTime = m_display_estimated;
+ remainingTime = display_remaining;
+ }
+
+ elapsedTime = elapsed;
+}
+
+// static
+wxString wxGenericProgressDialog::GetFormattedTime(unsigned long timeInSec)
+{
+ wxString timeAsHMS;
+
+ if ( timeInSec == (unsigned long)-1 )
+ {
+ timeAsHMS = _("Unknown");
+ }
+ else
+ {
+ unsigned hours = timeInSec / 3600;
+ unsigned minutes = (timeInSec % 3600) / 60;
+ unsigned seconds = timeInSec % 60;
+ timeAsHMS.Printf("%u:%02u:%02u", hours, minutes, seconds);
+ }
+
+ return timeAsHMS;
+}
+