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 1000 of file ProgressDialog.cpp.

1002{
1003}

◆ ProgressDialog() [2/3]

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

Definition at line 1005 of file ProgressDialog.cpp.

1010{
1011 Create(title, message, flags, sRemainingLabelText);
1012}
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 1014 of file ProgressDialog.cpp.

1019{
1020 Create(title, columns, flags, sRemainingLabelText);
1021}

References Create(), and title.

Here is the call graph for this function:

◆ ~ProgressDialog()

ProgressDialog::~ProgressDialog ( )
virtual

Reimplemented from BasicUI::ProgressDialog.

Definition at line 1026 of file ProgressDialog.cpp.

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

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

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 1125 of file ProgressDialog.cpp.

1127 {
1128
1129 // Assuming that we don't want empty columns, bail out if there is no text.
1130 if (column.empty())
1131 return;
1132
1133 // Join strings
1134 auto sText = column[0];
1135 std::for_each( column.begin() + 1, column.end(),
1136 [&](const TranslatableString &text)
1137 { sText.Join( text, wxT("\n") ); });
1138
1139 // Create a statictext object and add to the sizer
1140 wxStaticText* oText = safenew wxStaticText(this,
1141 wxID_ANY,
1142 sText.Translation(),
1143 wxDefaultPosition,
1144 wxDefaultSize,
1145 wxALIGN_LEFT);
1146 oText->SetName(sText.Translation()); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
1147
1148 // If this is the first column then set the mMessage pointer so non-TimerRecord usages
1149 // will still work correctly in SetMessage()
1150 if (bFirstColumn) {
1151 mMessage = oText;
1152 }
1153
1154 pSizer->Add(oText, 1, wxEXPAND | wxALL, 5);
1155}
#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 1647 of file ProgressDialog.cpp.

1648{
1649 int after;
1650 bool should;
1651 wxString name;
1652
1653 gPrefs->Read(wxT("/GUI/BeepOnCompletion"), &should, false);
1654 gPrefs->Read(wxT("/GUI/BeepAfterDuration"), &after, 60);
1655 gPrefs->Read(wxT("/GUI/BeepFileName"), &name, {});
1656
1657 if (should && wxGetUTCTimeMillis().GetValue() - mStartTime > after * 1000)
1658 {
1659 wxBusyCursor busy;
1660 wxSound s;
1661
1662 if (name.empty())
1663 {
1664#ifdef __WXOSX_COCOA__
1665 // wxSound::Create(size_t,const void*) isn't implemented;
1666 // use the system beep function.
1667 NSBeep();
1668#else
1669 s.Create(sizeof(beep), beep);
1670#endif
1671 }
1672 else
1673 {
1674 s.Create(name);
1675 }
1676
1677 if (s.IsOk())
1678 {
1679 s.Play(wxSOUND_SYNC);
1680 }
1681 }
1682}
wxT("CloseDown"))
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
static const unsigned char beep[]
wxString name
Definition: TagsEditor.cpp:166
wxLongLong_t mStartTime
virtual bool Read(const wxString &key, bool *value) const =0

References beep, gPrefs, mStartTime, name, audacity::BasicSettings::Read(), 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 1686 of file ProgressDialog.cpp.

1688 {
1689
1690 // Check if confirmations are enabled?
1691 // If not then return TRUE
1692 if (m_bConfirmAction == false) {
1693 return true;
1694 }
1695
1696 AudacityMessageDialog dlgMessage(
1697 this,
1698 sPrompt,
1699 sTitle,
1700 wxYES_NO | wxICON_QUESTION | wxNO_DEFAULT | wxSTAY_ON_TOP );
1701 int iAction = dlgMessage.ShowModal();
1702
1703 bool bReturn = (iAction == wxID_YES);
1704 if ((bReturn == false) && (iButtonID > -1)) {
1705 // Set the focus back to the relevant button
1706 FindWindowById(iButtonID, this)->SetFocus();
1707 }
1708
1709 return bReturn;
1710}
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 1176 of file ProgressDialog.cpp.

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

1161{
1162 MessageTable columns(1);
1163 columns.back().push_back(message);
1164 auto result = Create(title, columns, flags, sRemainingLabelText);
1165
1166 if (result) {
1167 // Record some values used in case of change of message
1168 // TODO: make the following work in case of message tables
1169 wxClientDC dc(this);
1170 dc.GetMultiLineTextExtent(message.Translation(), &mLastW, &mLastH);
1171 }
1172
1173 return result;
1174}
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 1063 of file ProgressDialog.cpp.

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

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 1615 of file ProgressDialog.cpp.

1616{
1617 if (!ConfirmAction(
1618 XO("Are you sure you wish to cancel?"),
1619 XO("Confirm Cancel"), wxID_CANCEL)) {
1620 return;
1621 }
1622 FindWindowById(wxID_CANCEL, this)->Disable();
1623 mCancel = true;
1624}
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 1638 of file ProgressDialog.cpp.

1639{
1640 if (!ConfirmAction(
1641 XO("Are you sure you wish to close?"), XO("Confirm Close"))) {
1642 return;
1643 }
1644 mCancel = true;
1645}

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

Here is the call graph for this function:

◆ OnStop()

void ProgressDialog::OnStop ( wxCommandEvent &  e)
private

Definition at line 1626 of file ProgressDialog.cpp.

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

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 1528 of file ProgressDialog.cpp.

1531{
1532 return Update(numerator, denominator, message);
1533}
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 1084 of file ProgressDialog.cpp.

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

References mCancel, mElapsedTime, mIsTransparent, mLastUpdate, mLastValue, mPollsCount, mStartTime, mStop, mTotalPollTime, mTotalYieldTime, mYieldsCount, mYieldTimer, and ExportProgressUI::Show().

Referenced by Create().

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

◆ SearchForWindow()

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

Definition at line 1602 of file ProgressDialog.cpp.

1603{
1604 for (auto win : list)
1605 {
1606 if (win == searchfor || SearchForWindow(win->GetChildren(), searchfor))
1607 {
1608 return true;
1609 }
1610 }
1611
1612 return false;
1613}

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 1119 of file ProgressDialog.cpp.

1120{
1121 SetTitle(title);
1122}
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 1554 of file ProgressDialog.cpp.

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

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 1458 of file ProgressDialog.cpp.

1460{
1461 return Update((int)(current * 1000), message);
1462}

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 1538 of file ProgressDialog.cpp.

1540{
1541 if (total != 0)
1542 {
1543 return Update((int)(current * 1000.0 / total), message);
1544 }
1545 else
1546 {
1547 return Update(1000, message);
1548 }
1549}

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 1515 of file ProgressDialog.cpp.

1517{
1518 if (total != 0)
1519 {
1520 return Update((int)(current * ((double)(1000.0 / total))), message);
1521 }
1522 else
1523 {
1524 return Update(1000, message);
1525 }
1526}

References Update().

Here is the call graph for this function:

◆ Update() [4/7]

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

Definition at line 1354 of file ProgressDialog.cpp.

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

References BasicUI::Cancelled, m_bShowElapsedTime, mCancel, mElapsed, mElapsedTime, mGauge, mIsTransparent, mLastUpdate, mLastValue, mPollsCount, mRemaining, mStartTime, mStop, mTotalPollTime, mTotalYieldTime, mYieldsCount, mYieldTimer, SetMessage(), BasicUI::Stopped, 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 1483 of file ProgressDialog.cpp.

1485{
1486 if (total.GetValue() != 0)
1487 {
1488 return Update((int)(current.GetValue() * 1000ll / total.GetValue()), message);
1489 }
1490 else
1491 {
1492 return Update(1000, message);
1493 }
1494}

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 1499 of file ProgressDialog.cpp.

1501{
1502 if (total != 0)
1503 {
1504 return Update((int)(current * 1000ll / total), message);
1505 }
1506 else
1507 {
1508 return Update(1000, message);
1509 }
1510}

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 1467 of file ProgressDialog.cpp.

1469{
1470 if (total != 0)
1471 {
1472 return Update((int)(current * 1000 / total), message);
1473 }
1474 else
1475 {
1476 return Update(1000, message);
1477 }
1478}

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: