Audacity 3.2.0
ProgressDialog.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 ProgressDialog.h
6
7 Copyright
8 Leland Lucius
9 Vaughan Johnson
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15
16*************************************************************************/
17
18#ifndef __AUDACITY_WIDGETS_PROGRESSDIALOG__
19#define __AUDACITY_WIDGETS_PROGRESSDIALOG__
20
21#include <chrono>
22
23#include <vector>
24#include <wx/defs.h>
25#include <wx/evtloop.h> // member variable
26
27#include "wxPanelWrapper.h" // to inherit
28
29#include "BasicUI.h" // For ProgressResult
31
32class wxGauge;
33class wxStaticText;
34
36{
37 pdlgEmptyFlags = 0x00000000,
38 pdlgHideStopButton = 0x00000001,
40 pdlgHideElapsedTime = 0x00000004,
42
44};
45
49
50class WX_INIT_API ProgressDialog /* not final */ :
51 public wxDialogWrapper,
53{
54public:
56
57 // Display a simple message.
59 const TranslatableString & message = {},
60 int flags = pdlgDefaultFlags,
61 const TranslatableString & sRemainingLabelText = {});
62
63 using MessageColumn = std::vector< TranslatableString >;
64 using MessageTable = std::vector< MessageColumn >;
65
66protected:
67 // Display a table of messages.
68 // Each member of the table is a column of messages.
69 // Each member of a column is a string that should have no newlines,
70 // and each column should have the same number of elements, to make
71 // proper correspondences, but this is not checked.
73 const MessageTable & columns,
74 int flags = pdlgDefaultFlags,
75 const TranslatableString & sRemainingLabelText = {});
76
77public:
78 virtual ~ProgressDialog();
79
80 bool Create(const TranslatableString & title,
81 const TranslatableString & message = {},
82 int flags = pdlgDefaultFlags,
83 const TranslatableString & sRemainingLabelText = {});
84
85 void Reinit() override;
86
87 void SetDialogTitle(const TranslatableString& title) override;
88
89protected:
90 bool Create(const TranslatableString & title,
91 const MessageTable & columns,
92 int flags = pdlgDefaultFlags,
93 const TranslatableString & sRemainingLabelText = {});
94
95public:
96 ProgressResult Update(int value, const TranslatableString & message = {});
97 ProgressResult Update(double current, const TranslatableString & message = {});
98 ProgressResult Update(double current, double total, const TranslatableString & message = {});
99 ProgressResult Update(wxULongLong_t current, wxULongLong_t total, const TranslatableString & message = {});
100 ProgressResult Update(wxLongLong current, wxLongLong total, const TranslatableString & message = {});
101 ProgressResult Update(wxLongLong_t current, wxLongLong_t total, const TranslatableString & message = {});
102 ProgressResult Update(int current, int total, const TranslatableString & message = {});
103
105 unsigned long long numerator, unsigned long long denominator,
106 const TranslatableString& message = {}) override;
107
108 void SetMessage(const TranslatableString & message) override;
109
110protected:
111 wxWindowRef mHadFocus;
112
113 wxStaticText *mElapsed;
114 wxStaticText *mRemaining;
115 wxGauge *mGauge;
116
117 wxLongLong_t mStartTime;
118 wxLongLong_t mLastUpdate;
119 wxLongLong_t mYieldTimer;
120 wxLongLong_t mElapsedTime {};
121 int mLastValue; // gauge value, range = [0,1000]
122
124 bool mStop;
125
127
128 // MY: Booleans to hold the flag values
129 bool m_bShowElapsedTime = true;
130 bool m_bConfirmAction = false;
131
132private:
133 void Init();
134 bool SearchForWindow(const wxWindowList & list, const wxWindow *searchfor) const;
135 void OnCancel(wxCommandEvent & e);
136 void OnStop(wxCommandEvent & e);
137 void OnCloseWindow(wxCloseEvent & e);
138 void Beep() const;
139
140 bool ConfirmAction(const TranslatableString & sPrompt,
141 const TranslatableString & sTitle,
142 int iButtonID = -1);
143
144 void AddMessageAsColumn(wxBoxSizer * pSizer,
145 const MessageColumn &column, bool bFirstColumn);
146
147private:
148 // This guarantees we have an active event loop...possible during OnInit()
149 wxEventLoopGuarantor mLoop;
150
151 std::unique_ptr<wxWindowDisabler> mDisable;
152
153 wxStaticText *mMessage{} ;
154 int mLastW{ 0 };
155 int mLastH{ 0 };
156
157 std::chrono::nanoseconds mTotalPollTime {};
158 unsigned mPollsCount { 0 };
159 std::chrono::nanoseconds mTotalYieldTime {};
160 unsigned mYieldsCount { 0 };
161
162 DECLARE_EVENT_TABLE()
163};
164
165class WX_INIT_API TimerProgressDialog final : public ProgressDialog
166{
167public:
168 TimerProgressDialog(const wxLongLong_t duration,
170 const MessageTable & columns,
171 int flags = pdlgDefaultFlags,
172 const TranslatableString & sRemainingLabelText = {});
173
174 // Oh no, there is an inherited nullary "Update" in wxDialog!
175 // Choose another name then...
176 ProgressResult UpdateProgress();
177
178protected:
179 wxLongLong_t mDuration;
180
181 // Disallow direct use of the inherited overloads of Update because it
182 // doesn't support changes of message
184};
185
186#endif
Toolkit-neutral facade for basic user interface services.
static const auto title
ProgressDialogFlags
@ pdlgConfirmStopCancel
@ pdlgHideStopButton
@ pdlgHideElapsedTime
@ pdlgEmptyFlags
@ pdlgHideCancelButton
@ pdlgDefaultFlags
Abstraction of a progress dialog with well defined time-to-completion estimate.
Definition: BasicUI.h:164
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.
virtual void SetMessage(const TranslatableString &message)=0
Change an existing dialog's message.
virtual void SetDialogTitle(const TranslatableString &title)=0
Change the dialog's title.
virtual void Reinit()=0
Reset the dialog state.
ProgressDialog Class.
std::unique_ptr< wxWindowDisabler > mDisable
wxStaticText * mElapsed
wxGauge * mGauge
wxStaticText * mRemaining
wxLongLong_t mStartTime
wxLongLong_t mLastUpdate
std::vector< MessageColumn > MessageTable
wxLongLong_t mYieldTimer
std::vector< TranslatableString > MessageColumn
wxEventLoopGuarantor mLoop
ProgressResult Update(int value, const TranslatableString &message={})
wxWindowRef mHadFocus
wxLongLong_t mDuration
Holds a msgid for the translation catalog; may also bind format arguments.
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"))
ProgressResult
Definition: BasicUI.h:155
void OnCloseWindow(wxCloseEvent &e)
void OnStop(const CommandContext &context)