Audacity 3.2.0
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
TimerProgressDialog Class Referencefinal

#include <ProgressDialog.h>

Inheritance diagram for TimerProgressDialog:
[legend]
Collaboration diagram for TimerProgressDialog:
[legend]

Public Member Functions

 TimerProgressDialog (const wxLongLong_t duration, const TranslatableString &title, const MessageTable &columns, int flags=pdlgDefaultFlags, const TranslatableString &sRemainingLabelText={})
 
ProgressResult UpdateProgress ()
 
- Public Member Functions inherited from ProgressDialog
 ProgressDialog ()
 Methods for ProgressDialog. More...
 
 ProgressDialog (const TranslatableString &title, const TranslatableString &message={}, int flags=pdlgDefaultFlags, const TranslatableString &sRemainingLabelText={})
 
virtual ~ProgressDialog ()
 
bool Create (const TranslatableString &title, const TranslatableString &message={}, int flags=pdlgDefaultFlags, const TranslatableString &sRemainingLabelText={})
 
void Reinit ()
 
ProgressResult Update (int value, const TranslatableString &message={})
 
ProgressResult Update (double current, const TranslatableString &message={})
 
ProgressResult Update (double current, double total, const TranslatableString &message={})
 
ProgressResult Update (wxULongLong_t current, wxULongLong_t total, const TranslatableString &message={})
 
ProgressResult Update (wxLongLong current, wxLongLong total, const TranslatableString &message={})
 
ProgressResult Update (wxLongLong_t current, wxLongLong_t total, const TranslatableString &message={})
 
ProgressResult Update (int current, int total, const TranslatableString &message={})
 
void SetMessage (const TranslatableString &message)
 
- Public Member Functions inherited from wxDialogWrapper
 wxDialogWrapper ()
 
 wxDialogWrapper (wxWindow *parent, wxWindowID id, const TranslatableString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const TranslatableString &name=XO("Dialog"))
 
bool Create (wxWindow *parent, wxWindowID id, const TranslatableString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE, const TranslatableString &name=XO("Dialog"))
 
void SetTitle (const TranslatableString &title)
 
void SetLabel (const TranslatableString &title)
 
void SetName (const TranslatableString &title)
 
void SetName ()
 
- Public Member Functions inherited from wxTabTraversalWrapper< wxDialog >
 wxTabTraversalWrapper (Args &&... args)
 
 wxTabTraversalWrapper (const wxTabTraversalWrapper &)=delete
 
 wxTabTraversalWrapper (wxTabTraversalWrapper &&)=delete
 
wxTabTraversalWrapperoperator= (const wxTabTraversalWrapper &)=delete
 
wxTabTraversalWrapperoperator= (wxTabTraversalWrapper &&)=delete
 

Protected Member Functions

ProgressResult Update (int value, const TranslatableString &message={})
 
ProgressResult Update (double current, const TranslatableString &message={})
 
ProgressResult Update (double current, double total, const TranslatableString &message={})
 
ProgressResult Update (wxULongLong_t current, wxULongLong_t total, const TranslatableString &message={})
 
ProgressResult Update (wxLongLong current, wxLongLong total, const TranslatableString &message={})
 
ProgressResult Update (wxLongLong_t current, wxLongLong_t total, const TranslatableString &message={})
 
ProgressResult Update (int current, int total, const TranslatableString &message={})
 
- Protected Member Functions inherited from ProgressDialog
 ProgressDialog (const TranslatableString &title, const MessageTable &columns, int flags=pdlgDefaultFlags, const TranslatableString &sRemainingLabelText={})
 
bool Create (const TranslatableString &title, const MessageTable &columns, int flags=pdlgDefaultFlags, const TranslatableString &sRemainingLabelText={})
 

Protected Attributes

wxLongLong_t mDuration
 
- Protected Attributes inherited from ProgressDialog
wxWindowRef mHadFocus
 
wxStaticText * mElapsed
 
wxStaticText * mRemaining
 
wxGauge * mGauge
 
wxLongLong_t mStartTime
 
wxLongLong_t mLastUpdate
 
wxLongLong_t mYieldTimer
 
int mLastValue
 
bool mCancel
 
bool mStop
 
bool mIsTransparent
 
bool m_bShowElapsedTime = true
 
bool m_bConfirmAction = false
 

Additional Inherited Members

- Public Types inherited from ProgressDialog
using MessageColumn = std::vector< TranslatableString >
 
using MessageTable = std::vector< MessageColumn >
 

Detailed Description

Definition at line 151 of file ProgressDialog.h.

Constructor & Destructor Documentation

◆ TimerProgressDialog()

TimerProgressDialog::TimerProgressDialog ( const wxLongLong_t  duration,
const TranslatableString title,
const MessageTable columns,
int  flags = pdlgDefaultFlags,
const TranslatableString sRemainingLabelText = {} 
)

Definition at line 1660 of file ProgressDialog.cpp.

1665: ProgressDialog(title, columns, flags, sRemainingLabelText)
1666{
1667 mDuration = duration;
1668}
static const auto title
ProgressDialog()
Methods for ProgressDialog.
wxLongLong_t mDuration

References mDuration.

Member Function Documentation

◆ Update() [1/7]

ProgressResult ProgressDialog::Update ( double  current,
const TranslatableString message = {} 
)
protected

Definition at line 93 of file ProgressDialog.cpp.

1423{
1424 return Update((int)(current * 1000), message);
1425}
ProgressResult Update(int value, const TranslatableString &message={})

◆ Update() [2/7]

ProgressResult ProgressDialog::Update ( double  current,
double  total,
const TranslatableString message = {} 
)
protected

Definition at line 94 of file ProgressDialog.cpp.

1496{
1497 if (total != 0)
1498 {
1499 return Update((int)(current * 1000.0 / total), message);
1500 }
1501 else
1502 {
1503 return Update(1000, message);
1504 }
1505}

◆ Update() [3/7]

ProgressResult ProgressDialog::Update ( int  current,
int  total,
const TranslatableString message = {} 
)
protected

Definition at line 98 of file ProgressDialog.cpp.

1480{
1481 if (total != 0)
1482 {
1483 return Update((int)(current * ((double)(1000.0 / total))), message);
1484 }
1485 else
1486 {
1487 return Update(1000, message);
1488 }
1489}

◆ Update() [4/7]

ProgressResult ProgressDialog::Update ( int  value,
const TranslatableString message = {} 
)
protected

Definition at line 92 of file ProgressDialog.cpp.

1329{
1330 if (mCancel)
1331 {
1332 // for compatibility with old Update, that returned false on cancel
1334 }
1335 else if (mStop)
1336 {
1337 return ProgressResult::Stopped;
1338 }
1339
1340 wxLongLong_t now = wxGetUTCTimeMillis().GetValue();
1341 wxLongLong_t elapsed = now - mStartTime;
1342
1343 if (elapsed < 500)
1344 {
1346 }
1347
1348 if (mIsTransparent)
1349 {
1350 SetTransparent(255);
1351 mIsTransparent = false;
1352 }
1353
1354 if (value <= 0)
1355 {
1356 value = 1;
1357 }
1358
1359 if (value > 1000)
1360 {
1361 value = 1000;
1362 }
1363
1364 wxLongLong_t estimate = elapsed * 1000ll / value;
1365 wxLongLong_t remains = (estimate + mStartTime) - now;
1366
1367 SetMessage(message);
1368
1369 if (value != mLastValue)
1370 {
1371 mGauge->SetValue(value);
1372 mGauge->Update();
1373 mLastValue = value;
1374 }
1375
1376 // Only update if a full second has passed or track progress is complete
1377 if ((now - mLastUpdate > 1000) || (value == 1000))
1378 {
1379 if (m_bShowElapsedTime) {
1380 wxTimeSpan tsElapsed(0, 0, 0, elapsed);
1381 mElapsed->SetLabel(tsElapsed.Format(wxT("%H:%M:%S")));
1382 mElapsed->SetName(mElapsed->GetLabel()); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
1383 mElapsed->Update();
1384 }
1385
1386 wxTimeSpan tsRemains(0, 0, 0, remains);
1387 mRemaining->SetLabel(tsRemains.Format(wxT("%H:%M:%S")));
1388 mRemaining->SetName(mRemaining->GetLabel()); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
1389 mRemaining->Update();
1390
1391 mLastUpdate = now;
1392 }
1393
1394 wxDialogWrapper::Update();
1395
1396 // Copied from wx 3.0.2 generic progress dialog
1397 //
1398 // we have to yield because not only we want to update the display but
1399 // also to process the clicks on the cancel and skip buttons
1400 // NOTE: using YieldFor() this call shouldn't give re-entrancy problems
1401 // for event handlers not interested to UI/user-input events.
1402 //
1403 // LL: Added timer category to prevent extreme delays when processing effects
1404 // (and probably other things). I do not yet know why this happens and
1405 // I'm not too keen on having timer events processed here, but you do
1406 // what you have to do.
1407
1408 // Nyquist effects call Update on every callback, but YieldFor is
1409 // quite slow on Linux / Mac, so don't call too frequently. (bug 1575)
1410 if ((now - mYieldTimer > 50) || (value == 1000)) {
1411 wxEventLoopBase::GetActive()->YieldFor(wxEVT_CATEGORY_UI | wxEVT_CATEGORY_USER_INPUT | wxEVT_CATEGORY_TIMER);
1412 mYieldTimer = now;
1413 }
1414
1416}
wxStaticText * mElapsed
wxGauge * mGauge
void SetMessage(const TranslatableString &message)
wxStaticText * mRemaining
wxLongLong_t mStartTime
wxLongLong_t mLastUpdate
wxLongLong_t mYieldTimer

◆ Update() [5/7]

ProgressResult ProgressDialog::Update ( wxLongLong  current,
wxLongLong  total,
const TranslatableString message = {} 
)
protected

Definition at line 96 of file ProgressDialog.cpp.

1448{
1449 if (total.GetValue() != 0)
1450 {
1451 return Update((int)(current.GetValue() * 1000ll / total.GetValue()), message);
1452 }
1453 else
1454 {
1455 return Update(1000, message);
1456 }
1457}

◆ Update() [6/7]

ProgressResult ProgressDialog::Update ( wxLongLong_t  current,
wxLongLong_t  total,
const TranslatableString message = {} 
)
protected

Definition at line 97 of file ProgressDialog.cpp.

1464{
1465 if (total != 0)
1466 {
1467 return Update((int)(current * 1000ll / total), message);
1468 }
1469 else
1470 {
1471 return Update(1000, message);
1472 }
1473}

◆ Update() [7/7]

ProgressResult ProgressDialog::Update ( wxULongLong_t  current,
wxULongLong_t  total,
const TranslatableString message = {} 
)
protected

Definition at line 95 of file ProgressDialog.cpp.

1432{
1433 if (total != 0)
1434 {
1435 return Update((int)(current * 1000 / total), message);
1436 }
1437 else
1438 {
1439 return Update(1000, message);
1440 }
1441}

◆ UpdateProgress()

ProgressResult TimerProgressDialog::UpdateProgress ( )

Definition at line 1670 of file ProgressDialog.cpp.

1671{
1672 if (mCancel)
1673 {
1674 // for compatibility with old Update, that returned false on cancel
1676 }
1677 else if (mStop)
1678 {
1679 return ProgressResult::Stopped;
1680 }
1681
1682 wxLongLong_t now = wxGetUTCTimeMillis().GetValue();
1683 wxLongLong_t elapsed = now - mStartTime;
1684
1685 if (elapsed < 500)
1686 {
1688 }
1689
1690 if (mIsTransparent)
1691 {
1692 SetTransparent(255);
1693 mIsTransparent = false;
1694 }
1695
1696 wxLongLong_t remains = mStartTime + mDuration - now;
1697
1698 int nGaugeValue = (1000 * elapsed) / mDuration; // range = [0,1000]
1699 // Running in TimerRecordDialog::RunWaitDialog(), for some unknown reason,
1700 // nGaugeValue here is often a little over 1000.
1701 // From testing, it's never shown bigger than 1009, but
1702 // give it a little extra, to 1010.
1703 // wxASSERT((nGaugeValue >= 0) && (nGaugeValue <= 1000)); // This ought to work.
1704 // wxASSERT((nGaugeValue >= 0) && (nGaugeValue <= 1010));
1705 //
1706 // stf. Update was being called after wxMilliSleep(<ms>), which could be up to <ms>
1707 // beyond the completion time. My guess is that the microsleep in RunWaitDialog was originally 10 ms
1708 // (same as other uses of Update) but was updated to kTimerInterval = 50 ms, thus triggering
1709 // the Assert (Bug 1367). By calling Update() before sleeping then I think nGaugeValue <= 1000 should work.
1710 wxASSERT((nGaugeValue >= 0) && (nGaugeValue <= 1000));
1711
1712 if (nGaugeValue != mLastValue)
1713 {
1714 mGauge->SetValue(nGaugeValue);
1715 mGauge->Update();
1716 mLastValue = nGaugeValue;
1717 }
1718
1719 // Only update if a full second has passed.
1720 if (now - mLastUpdate > 1000)
1721 {
1722 // Bug 1952:
1723 // wxTimeSpan will assert on ridiculously large values.
1724 // We silently wrap the displayed range at one day.
1725 // You'll only see the remaining hours, mins and secs.
1726 // With a + sign, if the time was wrapped.
1727 const wxLongLong_t wrapTime = 24 * 60 * 60 * 1000;
1728 if (m_bShowElapsedTime) {
1729 wxTimeSpan tsElapsed(0, 0, 0, elapsed % wrapTime);
1730 mElapsed->SetLabel(tsElapsed.Format(wxT("%H:%M:%S")) + ((elapsed >= wrapTime) ? " +":""));
1731 mElapsed->Update();
1732 }
1733
1734 wxTimeSpan tsRemains(0, 0, 0, remains % wrapTime);
1735 mRemaining->SetLabel(tsRemains.Format(wxT("%H:%M:%S")) + ((remains >= wrapTime) ? " +":""));
1736 mRemaining->Update();
1737
1738 mLastUpdate = now;
1739 }
1740
1741 // Copied from wx 3.0.2 generic progress dialog
1742 //
1743 // we have to yield because not only we want to update the display but
1744 // also to process the clicks on the cancel and skip buttons
1745 // NOTE: using YieldFor() this call shouldn't give re-entrancy problems
1746 // for event handlers not interested to UI/user-input events.
1747 //
1748 // LL: Added timer category to prevent extreme delays when processing effects
1749 // (and probably other things). I do not yet know why this happens and
1750 // I'm not too keen on having timer events processed here, but you do
1751 // what you have to do.
1752 // JKC: Added thread category, since blocking a thread message could cause things
1753 // to gum up.
1754 // See http://trac.wxwidgets.org/ticket/14027 for discussion of why
1755 // YieldFor is flaky.
1756 // Conclusion... use wxEVT_CATEGORY_ALL since with the list below, we
1757 // are pretty much there already.
1758 // wxEVT_CATEGORY_UI |
1759 // wxEVT_CATEGORY_USER_INPUT |
1760 // wxEVT_CATEGORY_TIMER |
1761 // wxEVT_CATEGORY_THREAD
1762
1763 wxEventLoopBase::GetActive()->YieldFor(wxEVT_CATEGORY_ALL );
1764 // JKC: Yielding twice, because e.g. a timer can build up a lot of events, and we
1765 // really want to make sure they are worked through.
1766 wxEventLoopBase::GetActive()->YieldFor(wxEVT_CATEGORY_ALL );
1767
1768 // MY: Added this after the YieldFor to check we haven't changed the outcome based on buttons pressed...
1769 auto iReturn = ProgressResult::Success;
1770 if (mCancel)
1771 {
1772 iReturn = ProgressResult::Cancelled;
1773 }
1774 else if (mStop)
1775 {
1776 iReturn = ProgressResult::Stopped;
1777 }
1778 return iReturn;
1779}

References RefreshCode::Cancelled, ProgressDialog::m_bShowElapsedTime, ProgressDialog::mCancel, mDuration, ProgressDialog::mElapsed, ProgressDialog::mGauge, ProgressDialog::mIsTransparent, ProgressDialog::mLastUpdate, ProgressDialog::mLastValue, ProgressDialog::mRemaining, ProgressDialog::mStartTime, ProgressDialog::mStop, and BasicUI::Success.

Referenced by TimerRecordDialog::PreActionDelay(), TimerRecordDialog::RunWaitDialog(), and TimerRecordDialog::WaitForStart().

Here is the caller graph for this function:

Member Data Documentation

◆ mDuration

wxLongLong_t TimerProgressDialog::mDuration
protected

Definition at line 165 of file ProgressDialog.h.

Referenced by TimerProgressDialog(), and UpdateProgress().


The documentation for this class was generated from the following files: