Audacity 3.2.0
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
ProgressDialog Class Reference

ProgressDialog Class. More...

#include <ProgressDialog.h>

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

Public Types

using MessageColumn = std::vector< TranslatableString >
 
using MessageTable = std::vector< MessageColumn >
 

Public Member Functions

 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 () override
 Reset the dialog state. More...
 
void SetDialogTitle (const TranslatableString &title) override
 Change the dialog's title. More...
 
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={})
 
ProgressResult Poll (unsigned long long numerator, unsigned long long denominator, const TranslatableString &message={}) override
 Update the bar and poll for clicks. Call only on the main thread. More...
 
void SetMessage (const TranslatableString &message) override
 Change an existing dialog's message. More...
 
- 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
 
virtual ~ProgressDialog ()
 
virtual ProgressResult Poll (unsigned long long numerator, unsigned long long denominator, const TranslatableString &message={})=0
 Update the bar and poll for clicks. Call only on the main thread. More...
 
virtual void SetMessage (const TranslatableString &message)=0
 Change an existing dialog's message. More...
 
virtual void SetDialogTitle (const TranslatableString &title)=0
 Change the dialog's title. More...
 
virtual void Reinit ()=0
 Reset the dialog state. More...
 

Protected Member Functions

 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

wxWindowRef mHadFocus
 
wxStaticText * mElapsed
 
wxStaticText * mRemaining
 
wxGauge * mGauge
 
wxLongLong_t mStartTime
 
wxLongLong_t mLastUpdate
 
wxLongLong_t mYieldTimer
 
wxLongLong_t mElapsedTime {}
 
int mLastValue
 
bool mCancel
 
bool mStop
 
bool mIsTransparent
 
bool m_bShowElapsedTime = true
 
bool m_bConfirmAction = false
 

Private Member Functions

void Init ()
 
bool SearchForWindow (const wxWindowList &list, const wxWindow *searchfor) const
 
void OnCancel (wxCommandEvent &e)
 
void OnStop (wxCommandEvent &e)
 
void OnCloseWindow (wxCloseEvent &e)
 
void Beep () const
 
bool ConfirmAction (const TranslatableString &sPrompt, const TranslatableString &sTitle, int iButtonID=-1)
 
void AddMessageAsColumn (wxBoxSizer *pSizer, const MessageColumn &column, bool bFirstColumn)
 

Private Attributes

wxEventLoopGuarantor mLoop
 
std::unique_ptr< wxWindowDisabler > mDisable
 
wxStaticText * mMessage {}
 
int mLastW { 0 }
 
int mLastH { 0 }
 
std::chrono::nanoseconds mTotalPollTime {}
 
unsigned mPollsCount { 0 }
 
std::chrono::nanoseconds mTotalYieldTime {}
 
unsigned mYieldsCount { 0 }
 

Detailed Description

ProgressDialog Class.

Custom progress dialog with Audacity specific semantics.

Definition at line 50 of file ProgressDialog.h.

Member Typedef Documentation

◆ MessageColumn

Definition at line 63 of file ProgressDialog.h.

◆ MessageTable

Definition at line 64 of file ProgressDialog.h.

Constructor & Destructor Documentation

◆ ProgressDialog() [1/3]

ProgressDialog::ProgressDialog ( )

Methods for ProgressDialog.

Definition at line 996 of file ProgressDialog.cpp.

998{
999}

◆ ProgressDialog() [2/3]

ProgressDialog::ProgressDialog ( const TranslatableString title,
const TranslatableString message = {},
int  flags = pdlgDefaultFlags,
const TranslatableString sRemainingLabelText = {} 
)

Definition at line 1001 of file ProgressDialog.cpp.

1006{
1007 Create(title, message, flags, sRemainingLabelText);
1008}
static const auto title
bool Create(const TranslatableString &title, const TranslatableString &message={}, int flags=pdlgDefaultFlags, const TranslatableString &sRemainingLabelText={})

References Create(), and title.

Here is the call graph for this function:

◆ ProgressDialog() [3/3]

ProgressDialog::ProgressDialog ( const TranslatableString title,
const MessageTable columns,
int  flags = pdlgDefaultFlags,
const TranslatableString sRemainingLabelText = {} 
)
protected

Definition at line 1010 of file ProgressDialog.cpp.

1015{
1016 Create(title, columns, flags, sRemainingLabelText);
1017}

References Create(), and title.

Here is the call graph for this function:

◆ ~ProgressDialog()

ProgressDialog::~ProgressDialog ( )
virtual

Reimplemented from BasicUI::ProgressDialog.

Definition at line 1022 of file ProgressDialog.cpp.

1023{
1024 // Delete the window disabler before hiding the dialog to allow
1025 // focus to return to the original window.
1026 mDisable.reset();
1027
1028 if (IsShown())
1029 {
1030 Show(false);
1031
1032 Beep();
1033 }
1034
1035#if defined(__WXGTK__)
1036 // Under GTK, when applying any effect that prompts the user, it's more than
1037 // like that FindFocus() will return NULL. So, make sure something has focus.
1038 if (GetParent()) {
1039 GetParent()->SetFocus();
1040 }
1041#endif
1042
1043 // Restore saved focus, but only if the window still exists.
1044 //
1045 // PRL: I'm conservatively preserving the old existence test, but I think
1046 // it's redundant now that we use wxWindowRef to avoid a dangling pointer
1047 if (mHadFocus && SearchForWindow(wxTopLevelWindows, mHadFocus)) {
1048 mHadFocus->SetFocus();
1049 }
1050
1051 using namespace std::chrono;
1052 wxLogInfo(
1053 "Operation '%s' took %f seconds. Poll was called %d times and took %f seconds. Yield was called %d times and took %f seconds.",
1054 GetTitle(), mElapsedTime / 1000.0,
1055 mPollsCount, duration_cast<duration<double>>(mTotalPollTime).count(),
1056 mYieldsCount, duration_cast<duration<double>>(mTotalYieldTime).count());
1057}
std::unique_ptr< wxWindowDisabler > mDisable
std::chrono::nanoseconds mTotalPollTime
void Beep() const
bool SearchForWindow(const wxWindowList &list, const wxWindow *searchfor) const
wxLongLong_t mElapsedTime
std::chrono::nanoseconds mTotalYieldTime
unsigned mPollsCount
unsigned mYieldsCount
wxWindowRef mHadFocus

References Beep(), mDisable, mElapsedTime, mHadFocus, mPollsCount, mTotalPollTime, mTotalYieldTime, mYieldsCount, and SearchForWindow().

Here is the call graph for this function:

Member Function Documentation

◆ AddMessageAsColumn()

void ProgressDialog::AddMessageAsColumn ( wxBoxSizer *  pSizer,
const MessageColumn column,
bool  bFirstColumn 
)
private

Definition at line 1121 of file ProgressDialog.cpp.

1123 {
1124
1125 // Assuming that we don't want empty columns, bail out if there is no text.
1126 if (column.empty())
1127 return;
1128
1129 // Join strings
1130 auto sText = column[0];
1131 std::for_each( column.begin() + 1, column.end(),
1132 [&](const TranslatableString &text)
1133 { sText.Join( text, wxT("\n") ); });
1134
1135 // Create a statictext object and add to the sizer
1136 wxStaticText* oText = safenew wxStaticText(this,
1137 wxID_ANY,
1138 sText.Translation(),
1139 wxDefaultPosition,
1140 wxDefaultSize,
1141 wxALIGN_LEFT);
1142 oText->SetName(sText.Translation()); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
1143
1144 // If this is the first column then set the mMessage pointer so non-TimerRecord usages
1145 // will still work correctly in SetMessage()
1146 if (bFirstColumn) {
1147 mMessage = oText;
1148 }
1149
1150 pSizer->Add(oText, 1, wxEXPAND | wxALL, 5);
1151}
#define safenew
Definition: MemoryX.h:10
wxStaticText * mMessage
Holds a msgid for the translation catalog; may also bind format arguments.
wxWeakRef< wxTextCtrl > sText
Definition: LogWindow.cpp:44

References mMessage, safenew, and anonymous_namespace{LogWindow.cpp}::sText.

Referenced by Create().

Here is the caller graph for this function:

◆ Beep()

void ProgressDialog::Beep ( ) const
private

Definition at line 1643 of file ProgressDialog.cpp.

1644{
1645 int after;
1646 bool should;
1647 wxString name;
1648
1649 gPrefs->Read(wxT("/GUI/BeepOnCompletion"), &should, false);
1650 gPrefs->Read(wxT("/GUI/BeepAfterDuration"), &after, 60);
1651 gPrefs->Read(wxT("/GUI/BeepFileName"), &name, wxEmptyString);
1652
1653 if (should && wxGetUTCTimeMillis().GetValue() - mStartTime > after * 1000)
1654 {
1655 wxBusyCursor busy;
1656 wxSound s;
1657
1658 if (name.empty())
1659 {
1660 s.Create(sizeof(beep), beep);
1661 }
1662 else
1663 {
1664 s.Create(name);
1665 }
1666
1667 if (s.IsOk())
1668 {
1669 s.Play(wxSOUND_SYNC);
1670 }
1671 }
1672}
wxT("CloseDown"))
const TranslatableString name
Definition: Distortion.cpp:76
FileConfig * gPrefs
Definition: Prefs.cpp:70
static const unsigned char beep[]
wxLongLong_t mStartTime

References beep, TranslatableString::empty(), gPrefs, mStartTime, name, and wxT().

Referenced by ~ProgressDialog().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ConfirmAction()

bool ProgressDialog::ConfirmAction ( const TranslatableString sPrompt,
const TranslatableString sTitle,
int  iButtonID = -1 
)
private

Definition at line 1676 of file ProgressDialog.cpp.

1678 {
1679
1680 // Check if confirmations are enabled?
1681 // If not then return TRUE
1682 if (m_bConfirmAction == false) {
1683 return true;
1684 }
1685
1686 AudacityMessageDialog dlgMessage(
1687 this,
1688 sPrompt,
1689 sTitle,
1690 wxYES_NO | wxICON_QUESTION | wxNO_DEFAULT | wxSTAY_ON_TOP );
1691 int iAction = dlgMessage.ShowModal();
1692
1693 bool bReturn = (iAction == wxID_YES);
1694 if ((bReturn == false) && (iButtonID > -1)) {
1695 // Set the focus back to the relevant button
1696 FindWindowById(iButtonID, this)->SetFocus();
1697 }
1698
1699 return bReturn;
1700}
Wrap wxMessageDialog so that caption IS translatable.

References m_bConfirmAction.

Referenced by OnCancel(), OnCloseWindow(), and OnStop().

Here is the caller graph for this function:

◆ Create() [1/2]

bool ProgressDialog::Create ( const TranslatableString title,
const MessageTable columns,
int  flags = pdlgDefaultFlags,
const TranslatableString sRemainingLabelText = {} 
)
protected

Definition at line 1172 of file ProgressDialog.cpp.

1176{
1177 Init();
1178
1179 wxWindow *parent =
1180#if defined(__WXMAC__)
1181 // Bug 2703: In release builds, the progress dialog will fall behind
1182 // the top level dialog (like effects dialogs). This does not happen
1183 // in debug builds and I was not able to track down the reason. So,
1184 // this is a workaround and should be reviewed as some point, like
1185 // when upgrading to the next WX version.
1186 GetParentForModalDialog(mHadFocus, 0);
1187#else
1188 GetParentForModalDialog(nullptr, 0);
1189#endif
1190
1191 // Set this boolean to indicate if we are using the "Elapsed" labels
1193 // Set this boolean to indicate if we confirm the Cancel/Stop actions
1195
1196 const long dialogStyle = (flags & pdlgHideCancelButton) != 0 &&
1197 (flags & pdlgHideStopButton) != 0 ?
1198 wxCAPTION : wxDEFAULT_DIALOG_STYLE;
1199
1200 bool success = wxDialogWrapper::Create(parent,
1201 wxID_ANY,
1202 title,
1203 wxDefaultPosition,
1204 wxDefaultSize,
1205 dialogStyle |
1206 wxFRAME_FLOAT_ON_PARENT);
1207 if (!success)
1208 {
1209 return false;
1210 }
1211
1212 SetName(); // This was added for NVDA screen reader and may now be redundant.
1213 SetExtraStyle(GetExtraStyle() | wxWS_EX_TRANSIENT); // Ancient code. Is it still required?
1214
1215 {
1216 wxWindow *window;
1217
1218 // There may be more than one column, so create a BoxSizer container
1219 auto uColSizer = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
1220 auto colSizer = uColSizer.get();
1221
1222 // TODO: this setting-up of a grid of text in a sizer might be worth
1223 // extracting as a utility for building other dialogs.
1224 {
1225 bool bFirstCol = true;
1226 for (const auto &column : columns) {
1227 AddMessageAsColumn(colSizer, column, bFirstCol);
1228 bFirstCol = false;
1229 }
1230 }
1231
1232 // and put message column(s) into a main vertical sizer.
1233 auto vertSizer = std::make_unique<wxBoxSizer>(wxVERTICAL);
1234 vertSizer->Add(uColSizer.release(), 1, wxEXPAND | wxALL, 10);
1235
1236 mGauge = safenew wxGauge(this,
1237 wxID_ANY,
1238 1000,
1239 wxDefaultPosition,
1240 wxDefaultSize,
1241 wxGA_HORIZONTAL);
1242 vertSizer->Add(mGauge, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 10);
1243
1244 {
1245 auto uGridSizer = std::make_unique<wxFlexGridSizer>(2, 2, 10, 10);
1246 // Only one row if we are not going to show the elapsed time
1247 if (m_bShowElapsedTime == false) {
1248 uGridSizer = std::make_unique<wxFlexGridSizer>(1, 2, 10, 10);
1249 }
1250 auto gridSizer = uGridSizer.get();
1251
1252 if (m_bShowElapsedTime) {
1253 window = safenew wxStaticText(this,
1254 wxID_ANY,
1255 _("Elapsed Time:"),
1256 wxDefaultPosition,
1257 wxDefaultSize,
1258 wxALIGN_RIGHT);
1259
1260 window->SetName(window->GetLabel()); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
1261 gridSizer->Add(window, 0, wxALIGN_RIGHT);
1262
1263 mElapsed = safenew wxStaticText(this,
1264 wxID_ANY,
1265 wxT("00:00:00"),
1266 wxDefaultPosition,
1267 wxDefaultSize,
1268 wxALIGN_LEFT);
1269
1270 mElapsed->SetName(mElapsed->GetLabel()); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
1271 gridSizer->Add(mElapsed, 0, wxALIGN_LEFT);
1272 }
1273
1274 // Customised "Remaining" label text
1275 auto sRemainingText = sRemainingLabelText;
1276 if (sRemainingText.empty()) {
1277 sRemainingText = XO("Remaining Time:");
1278 }
1279
1280 window = safenew wxStaticText(this,
1281 wxID_ANY,
1282 sRemainingText.Translation(),
1283 wxDefaultPosition,
1284 wxDefaultSize,
1285 wxALIGN_RIGHT);
1286 window->SetName(window->GetLabel()); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
1287 gridSizer->Add(window, 0, wxALIGN_RIGHT);
1288
1289 mRemaining = safenew wxStaticText(this,
1290 wxID_ANY,
1291 wxT("00:00:00"),
1292 wxDefaultPosition,
1293 wxDefaultSize,
1294 wxALIGN_LEFT);
1295 mRemaining->SetName(mRemaining->GetLabel()); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
1296 gridSizer->Add(mRemaining, 0, wxALIGN_LEFT);
1297
1298 vertSizer->Add(uGridSizer.release(), 0, wxALIGN_CENTER | wxLEFT | wxRIGHT | wxBOTTOM, 10);
1299 }
1300
1301 {
1302 auto uButtonBar = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
1303 auto buttonBarSizer = uButtonBar.get();
1304
1305 if (!(flags & pdlgHideStopButton)) {
1306 window = safenew wxButton(this, wxID_OK, _("Stop"));
1307 buttonBarSizer->Add(window, 0, wxRIGHT, 10);
1308 }
1309 if (!(flags & pdlgHideCancelButton)) {
1310 window = safenew wxButton(this, wxID_CANCEL, _("Cancel"));
1311 buttonBarSizer->Add(window, 0, wxRIGHT, 10);
1312 }
1313 vertSizer->Add(uButtonBar.release(), 0, wxALIGN_RIGHT | wxRIGHT | wxBOTTOM, 10);
1314 }
1315
1316 SetSizerAndFit(vertSizer.release());
1317 }
1318 Layout();
1319
1320 // Center progress bar on Parent if it is nice and wide, otherwise Center on screen.
1321 int parentWidth = -1, parentHeight=-1;
1322 if( GetParent() ) GetParent()->GetSize( &parentWidth, &parentHeight );
1323 if (parentWidth > 400)
1324 CenterOnParent();
1325 else
1326 CenterOnScreen();
1327
1328 Reinit();
1329
1330 // Even though we won't necessarily show the dialog due to the 500ms
1331 // delay, we MUST disable other windows/menus anyway since we run the risk
1332 // of allowing other tasks to run before this one is complete.
1333 //
1334 // Reviewed this code per Proposed Features #1, at
1335 // http://wiki.audacityteam.org/wiki/Proposal_Timer_Record_Improvements.
1336 // Note that this causes a problem for Timer Record wait dialog
1337 // (see TimerRecordDialog::RunWaitDialog()), because it makes it
1338 // impossible to do any editing, even in other open projects,
1339 // while waiting for Timer Record to start -- and then also
1340 // while it's recording, it has a ProgressDialog, so really,
1341 // no editing in any project until Timer Record finishes.
1342 mDisable = std::make_unique<wxWindowDisabler>(this);
1343
1344 return true;
1345}
XO("Cut/Copy/Paste")
#define _(s)
Definition: Internat.h:73
@ pdlgConfirmStopCancel
@ pdlgHideStopButton
@ pdlgHideElapsedTime
@ pdlgHideCancelButton
wxStaticText * mElapsed
wxGauge * mGauge
void AddMessageAsColumn(wxBoxSizer *pSizer, const MessageColumn &column, bool bFirstColumn)
void Reinit() override
Reset the dialog state.
wxStaticText * mRemaining
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"))

References _, AddMessageAsColumn(), wxDialogWrapper::Create(), Init(), m_bConfirmAction, m_bShowElapsedTime, mDisable, mElapsed, mGauge, mHadFocus, mRemaining, pdlgConfirmStopCancel, pdlgHideCancelButton, pdlgHideElapsedTime, pdlgHideStopButton, Reinit(), safenew, wxDialogWrapper::SetName(), title, wxT(), and XO().

Here is the call graph for this function:

◆ Create() [2/2]

bool ProgressDialog::Create ( const TranslatableString title,
const TranslatableString message = {},
int  flags = pdlgDefaultFlags,
const TranslatableString sRemainingLabelText = {} 
)

Definition at line 1153 of file ProgressDialog.cpp.

1157{
1158 MessageTable columns(1);
1159 columns.back().push_back(message);
1160 auto result = Create(title, columns, flags, sRemainingLabelText);
1161
1162 if (result) {
1163 // Record some values used in case of change of message
1164 // TODO: make the following work in case of message tables
1165 wxClientDC dc(this);
1166 dc.GetMultiLineTextExtent(message.Translation(), &mLastW, &mLastH);
1167 }
1168
1169 return result;
1170}
std::vector< MessageColumn > MessageTable
wxString Translation() const

References Create(), mLastH, mLastW, title, and TranslatableString::Translation().

Referenced by Create(), and ProgressDialog().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Init()

void ProgressDialog::Init ( )
private

Definition at line 1059 of file ProgressDialog.cpp.

1060{
1061 // There's a problem where the focus is not returned to the window that had
1062 // it before creating this object. The reason is because the focus events
1063 // that are sent to the parent window after the wxWindowDisabler are created
1064 // are tossed and focus will not get restored to the parent once the disabler
1065 // is deleted. (See bug #1173 for more info)
1066 //
1067 // So, we capture and restore the focus ourselves.
1069
1070#if defined(__WXGTK__)
1071 // Under GTK, when applying any effect that prompts the user, it's more than
1072 // likely that FindFocus() will return NULL. So, make sure something has focus.
1073 if (GetParent())
1074 {
1075 GetParent()->SetFocus();
1076 }
1077#endif
1078}
std::unique_ptr< WindowPlacement > FindFocus()
Find the window that is accepting keyboard input, if any.
Definition: BasicUI.h:343

References BasicUI::FindFocus(), and mHadFocus.

Referenced by Create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnCancel()

void ProgressDialog::OnCancel ( wxCommandEvent &  e)
private

Definition at line 1611 of file ProgressDialog.cpp.

1612{
1613 if (!ConfirmAction(
1614 XO("Are you sure you wish to cancel?"),
1615 XO("Confirm Cancel"), wxID_CANCEL)) {
1616 return;
1617 }
1618 FindWindowById(wxID_CANCEL, this)->Disable();
1619 mCancel = true;
1620}
bool ConfirmAction(const TranslatableString &sPrompt, const TranslatableString &sTitle, int iButtonID=-1)

References ConfirmAction(), mCancel, and XO().

Here is the call graph for this function:

◆ OnCloseWindow()

void ProgressDialog::OnCloseWindow ( wxCloseEvent &  e)
private

Definition at line 1634 of file ProgressDialog.cpp.

1635{
1636 if (!ConfirmAction(
1637 XO("Are you sure you wish to close?"), XO("Confirm Close"))) {
1638 return;
1639 }
1640 mCancel = true;
1641}

References ConfirmAction(), mCancel, and XO().

Here is the call graph for this function:

◆ OnStop()

void ProgressDialog::OnStop ( wxCommandEvent &  e)
private

Definition at line 1622 of file ProgressDialog.cpp.

1623{
1624 if (!ConfirmAction(
1625 XO("Are you sure you wish to stop?"),
1626 XO("Confirm Stop"), wxID_OK)) {
1627 return;
1628 }
1629 FindWindowById(wxID_OK, this)->Disable();
1630 mCancel = false;
1631 mStop = true;
1632}

References ConfirmAction(), mCancel, mStop, and XO().

Here is the call graph for this function:

◆ Poll()

ProgressResult ProgressDialog::Poll ( unsigned long long  numerator,
unsigned long long  denominator,
const TranslatableString message = {} 
)
overridevirtual

Update the bar and poll for clicks. Call only on the main thread.

Implements BasicUI::ProgressDialog.

Definition at line 1524 of file ProgressDialog.cpp.

1527{
1528 return Update(numerator, denominator, message);
1529}
ProgressResult Update(int value, const TranslatableString &message={})

References Update().

Here is the call graph for this function:

◆ Reinit()

void ProgressDialog::Reinit ( )
overridevirtual

Reset the dialog state.

Implements BasicUI::ProgressDialog.

Definition at line 1080 of file ProgressDialog.cpp.

1081{
1082 mLastValue = 0;
1083
1084 mStartTime = wxGetUTCTimeMillis().GetValue();
1087 mElapsedTime = 0;
1088 mCancel = false;
1089 mStop = false;
1090
1091 // Because wxGTK is very sensitive about maintaining focus when
1092 // this window is not shown, we always show it. But, since we
1093 // want a 500ms delay before it's actually visible for those
1094 // quick tasks, we show it as transparent. If the initial
1095 // delay is exceeded, then we reset the dialog to full opacity.
1096 SetTransparent(0);
1097 mIsTransparent = true;
1098
1099 auto button = FindWindowById(wxID_CANCEL, this);
1100 if (button)
1101 button->Enable();
1102 button = FindWindowById(wxID_OK, this);
1103 if (button)
1104 button->Enable();
1105
1106 wxDialogWrapper::Show(true);
1107 wxDialogWrapper::Raise();
1108
1109 mTotalPollTime = {};
1110 mPollsCount = {};
1111 mTotalYieldTime = {};
1112 mYieldsCount = {};
1113}
wxLongLong_t mLastUpdate
wxLongLong_t mYieldTimer

References mCancel, mElapsedTime, mIsTransparent, mLastUpdate, mLastValue, mPollsCount, mStartTime, mStop, mTotalPollTime, mTotalYieldTime, mYieldsCount, and mYieldTimer.

Referenced by Create().

Here is the caller graph for this function:

◆ SearchForWindow()

bool ProgressDialog::SearchForWindow ( const wxWindowList &  list,
const wxWindow *  searchfor 
) const
private

Definition at line 1598 of file ProgressDialog.cpp.

1599{
1600 for (auto win : list)
1601 {
1602 if (win == searchfor || SearchForWindow(win->GetChildren(), searchfor))
1603 {
1604 return true;
1605 }
1606 }
1607
1608 return false;
1609}

References SearchForWindow().

Referenced by SearchForWindow(), and ~ProgressDialog().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetDialogTitle()

void ProgressDialog::SetDialogTitle ( const TranslatableString title)
overridevirtual

Change the dialog's title.

Implements BasicUI::ProgressDialog.

Definition at line 1115 of file ProgressDialog.cpp.

1116{
1117 SetTitle(title);
1118}
void SetTitle(const TranslatableString &title)

References wxDialogWrapper::SetTitle(), and title.

Here is the call graph for this function:

◆ SetMessage()

void ProgressDialog::SetMessage ( const TranslatableString message)
overridevirtual

Change an existing dialog's message.

Implements BasicUI::ProgressDialog.

Definition at line 1550 of file ProgressDialog.cpp.

1551{
1552 if (!message.empty())
1553 {
1554 mMessage->SetLabel(message.Translation());
1555
1556 int w, h;
1557 wxClientDC dc(mMessage);
1558 dc.GetMultiLineTextExtent(message.Translation(), &w, &h);
1559
1560 auto sizeUpdated = false;
1561 const auto currentSize = GetClientSize();
1562 auto ds = currentSize;
1563
1564 // TODO: make the following work in case of message tables
1565 if (w > mLastW)
1566 {
1567 ds.x += (w - mLastW);
1568 sizeUpdated = true;
1569 mLastW = w;
1570 }
1571
1572 if (h > mLastH)
1573 {
1574 ds.y += (h - mLastH);
1575 sizeUpdated = true;
1576 mLastH = h;
1577 }
1578
1579 if (sizeUpdated)
1580 {
1581#if defined(__WXMAC__)
1582 wxSize sz = mMessage->GetSize();
1583 mMessage->SetMinSize(wxSize(wxMax(sz.x, mLastW), wxMax(sz.y, mLastH)));
1584#endif
1585 // No need to adjust for the margin here since we only add
1586 // to the existing dimensions.
1587 ds.x = wxMax(wxMax(ds.x, mLastW), wxMax(ds.y, mLastH));
1588 SetClientSize(ds);
1589 SetPosition(GetPosition() - (ds - currentSize) / 2);
1590 wxDialogWrapper::Update();
1591 }
1592 }
1593}

References TranslatableString::empty(), mLastH, mLastW, mMessage, and TranslatableString::Translation().

Referenced by Update().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Update() [1/7]

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

Definition at line 1454 of file ProgressDialog.cpp.

1456{
1457 return Update((int)(current * 1000), message);
1458}

References Update().

Here is the call graph for this function:

◆ Update() [2/7]

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

Definition at line 1534 of file ProgressDialog.cpp.

1536{
1537 if (total != 0)
1538 {
1539 return Update((int)(current * 1000.0 / total), message);
1540 }
1541 else
1542 {
1543 return Update(1000, message);
1544 }
1545}

References Update().

Here is the call graph for this function:

◆ Update() [3/7]

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

Definition at line 1511 of file ProgressDialog.cpp.

1513{
1514 if (total != 0)
1515 {
1516 return Update((int)(current * ((double)(1000.0 / total))), message);
1517 }
1518 else
1519 {
1520 return Update(1000, message);
1521 }
1522}

References Update().

Here is the call graph for this function:

◆ Update() [4/7]

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

Definition at line 1350 of file ProgressDialog.cpp.

1352{
1353 using namespace std::chrono;
1354 auto updatePollTime = finally([this, pollStart = high_resolution_clock::now()] {
1355 mTotalPollTime += high_resolution_clock::now() - pollStart;
1356 });
1357
1358 mPollsCount++;
1359
1360 if (mCancel)
1361 {
1362 // for compatibility with old Update, that returned false on cancel
1364 }
1365 else if (mStop)
1366 {
1367 return ProgressResult::Stopped;
1368 }
1369
1370 wxLongLong_t now = wxGetUTCTimeMillis().GetValue();
1371 mElapsedTime = now - mStartTime;
1372
1373 if (mElapsedTime < 500)
1374 {
1376 }
1377
1378 if (mIsTransparent)
1379 {
1380 SetTransparent(255);
1381 mIsTransparent = false;
1382 }
1383
1384 if (value <= 0)
1385 {
1386 value = 1;
1387 }
1388
1389 if (value > 1000)
1390 {
1391 value = 1000;
1392 }
1393
1394 wxLongLong_t estimate = mElapsedTime * 1000ll / value;
1395 wxLongLong_t remains = (estimate + mStartTime) - now;
1396
1397 SetMessage(message);
1398
1399 if (value != mLastValue)
1400 {
1401 mGauge->SetValue(value);
1402 mGauge->Update();
1403 mLastValue = value;
1404 }
1405
1406 // Only update if a full second has passed or track progress is complete
1407 if ((now - mLastUpdate > 1000) || (value == 1000))
1408 {
1409 if (m_bShowElapsedTime) {
1410 wxTimeSpan tsElapsed(0, 0, 0, mElapsedTime);
1411 mElapsed->SetLabel(tsElapsed.Format(wxT("%H:%M:%S")));
1412 mElapsed->SetName(mElapsed->GetLabel()); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
1413 mElapsed->Update();
1414 }
1415
1416 wxTimeSpan tsRemains(0, 0, 0, remains);
1417 mRemaining->SetLabel(tsRemains.Format(wxT("%H:%M:%S")));
1418 mRemaining->SetName(mRemaining->GetLabel()); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
1419 mRemaining->Update();
1420
1421 mLastUpdate = now;
1422 }
1423
1424 wxDialogWrapper::Update();
1425
1426 // Copied from wx 3.0.2 generic progress dialog
1427 //
1428 // we have to yield because not only we want to update the display but
1429 // also to process the clicks on the cancel and skip buttons
1430 // NOTE: using YieldFor() this call shouldn't give re-entrancy problems
1431 // for event handlers not interested to UI/user-input events.
1432 //
1433 // LL: Added timer category to prevent extreme delays when processing effects
1434 // (and probably other things). I do not yet know why this happens and
1435 // I'm not too keen on having timer events processed here, but you do
1436 // what you have to do.
1437
1438 // Nyquist effects call Update on every callback, but YieldFor is
1439 // quite slow on Linux / Mac, so don't call too frequently. (bug 1575)
1440 if ((now - mYieldTimer > 50) || (value == 1000)) {
1441 const auto yieldStart = high_resolution_clock::now();
1442 mYieldsCount++;
1443 wxEventLoopBase::GetActive()->YieldFor(wxEVT_CATEGORY_UI | wxEVT_CATEGORY_USER_INPUT | wxEVT_CATEGORY_TIMER);
1444 mTotalYieldTime += high_resolution_clock::now() - yieldStart;
1445 mYieldTimer = now;
1446 }
1447
1449}
void SetMessage(const TranslatableString &message) override
Change an existing dialog's message.

References RefreshCode::Cancelled, m_bShowElapsedTime, mCancel, mElapsed, mElapsedTime, mGauge, mIsTransparent, mLastUpdate, mLastValue, mPollsCount, mRemaining, mStartTime, mStop, mTotalPollTime, mTotalYieldTime, mYieldsCount, mYieldTimer, SetMessage(), BasicUI::Success, and wxT().

Referenced by ImportRaw(), TransportUtilities::PlayCurrentRegionAndWait(), TransportUtilities::PlayPlayRegionAndWait(), Poll(), TransportUtilities::RecordAndWait(), RemoveDependencies(), and Update().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Update() [5/7]

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

Definition at line 1479 of file ProgressDialog.cpp.

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

References Update().

Here is the call graph for this function:

◆ Update() [6/7]

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

Definition at line 1495 of file ProgressDialog.cpp.

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

References Update().

Here is the call graph for this function:

◆ Update() [7/7]

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

Definition at line 1463 of file ProgressDialog.cpp.

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

References Update().

Here is the call graph for this function:

Member Data Documentation

◆ m_bConfirmAction

bool ProgressDialog::m_bConfirmAction = false
protected

Definition at line 130 of file ProgressDialog.h.

Referenced by ConfirmAction(), and Create().

◆ m_bShowElapsedTime

bool ProgressDialog::m_bShowElapsedTime = true
protected

Definition at line 129 of file ProgressDialog.h.

Referenced by Create(), Update(), and TimerProgressDialog::UpdateProgress().

◆ mCancel

bool ProgressDialog::mCancel
protected

◆ mDisable

std::unique_ptr<wxWindowDisabler> ProgressDialog::mDisable
private

Definition at line 151 of file ProgressDialog.h.

Referenced by Create(), and ~ProgressDialog().

◆ mElapsed

wxStaticText* ProgressDialog::mElapsed
protected

Definition at line 113 of file ProgressDialog.h.

Referenced by Create(), Update(), and TimerProgressDialog::UpdateProgress().

◆ mElapsedTime

wxLongLong_t ProgressDialog::mElapsedTime {}
protected

Definition at line 120 of file ProgressDialog.h.

Referenced by Reinit(), Update(), and ~ProgressDialog().

◆ mGauge

wxGauge* ProgressDialog::mGauge
protected

Definition at line 115 of file ProgressDialog.h.

Referenced by Create(), Update(), and TimerProgressDialog::UpdateProgress().

◆ mHadFocus

wxWindowRef ProgressDialog::mHadFocus
protected

Definition at line 111 of file ProgressDialog.h.

Referenced by Create(), Init(), and ~ProgressDialog().

◆ mIsTransparent

bool ProgressDialog::mIsTransparent
protected

Definition at line 126 of file ProgressDialog.h.

Referenced by Reinit(), Update(), and TimerProgressDialog::UpdateProgress().

◆ mLastH

int ProgressDialog::mLastH { 0 }
private

Definition at line 155 of file ProgressDialog.h.

Referenced by Create(), and SetMessage().

◆ mLastUpdate

wxLongLong_t ProgressDialog::mLastUpdate
protected

Definition at line 118 of file ProgressDialog.h.

Referenced by Reinit(), Update(), and TimerProgressDialog::UpdateProgress().

◆ mLastValue

int ProgressDialog::mLastValue
protected

Definition at line 121 of file ProgressDialog.h.

Referenced by Reinit(), Update(), and TimerProgressDialog::UpdateProgress().

◆ mLastW

int ProgressDialog::mLastW { 0 }
private

Definition at line 154 of file ProgressDialog.h.

Referenced by Create(), and SetMessage().

◆ mLoop

wxEventLoopGuarantor ProgressDialog::mLoop
private

Definition at line 149 of file ProgressDialog.h.

◆ mMessage

wxStaticText* ProgressDialog::mMessage {}
private

Definition at line 153 of file ProgressDialog.h.

Referenced by AddMessageAsColumn(), and SetMessage().

◆ mPollsCount

unsigned ProgressDialog::mPollsCount { 0 }
private

Definition at line 158 of file ProgressDialog.h.

Referenced by Reinit(), Update(), and ~ProgressDialog().

◆ mRemaining

wxStaticText* ProgressDialog::mRemaining
protected

Definition at line 114 of file ProgressDialog.h.

Referenced by Create(), Update(), and TimerProgressDialog::UpdateProgress().

◆ mStartTime

wxLongLong_t ProgressDialog::mStartTime
protected

Definition at line 117 of file ProgressDialog.h.

Referenced by Beep(), Reinit(), Update(), and TimerProgressDialog::UpdateProgress().

◆ mStop

bool ProgressDialog::mStop
protected

Definition at line 124 of file ProgressDialog.h.

Referenced by OnStop(), Reinit(), Update(), and TimerProgressDialog::UpdateProgress().

◆ mTotalPollTime

std::chrono::nanoseconds ProgressDialog::mTotalPollTime {}
private

Definition at line 157 of file ProgressDialog.h.

Referenced by Reinit(), Update(), and ~ProgressDialog().

◆ mTotalYieldTime

std::chrono::nanoseconds ProgressDialog::mTotalYieldTime {}
private

Definition at line 159 of file ProgressDialog.h.

Referenced by Reinit(), Update(), and ~ProgressDialog().

◆ mYieldsCount

unsigned ProgressDialog::mYieldsCount { 0 }
private

Definition at line 160 of file ProgressDialog.h.

Referenced by Reinit(), Update(), and ~ProgressDialog().

◆ mYieldTimer

wxLongLong_t ProgressDialog::mYieldTimer
protected

Definition at line 119 of file ProgressDialog.h.

Referenced by Reinit(), and Update().


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