Audacity 3.2.0
ExportProgressUI.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 ExportProgressUI.cpp
6
7 Vitaly Sverchinsky
8
9**********************************************************************/
10
11#include "ExportProgressUI.h"
12
13#include "Export.h"
14#include "ExportPlugin.h"
15#include "Internat.h"
16#include "BasicUI.h"
17#include "FileException.h"
18
19namespace
20{
22 {
23 std::atomic<bool> mCancelled {false};
24 std::atomic<bool> mStopped {false};
25 std::atomic<double> mProgress {};
26
28
29 std::unique_ptr<BasicUI::ProgressDialog> mProgressDialog;
30 public:
31
32 bool IsCancelled() const override
33 {
34 return mCancelled;
35 }
36
37 bool IsStopped() const override
38 {
39 return mStopped;
40 }
41
43 {
44 mStatus = str;
45 }
46
47 void OnProgress(double progress) override
48 {
49 mProgress = progress;
50 }
51
52 void UpdateUI()
53 {
54 constexpr long long ProgressSteps = 1000ul;
55
56 if(!mProgressDialog)
57 mProgressDialog = BasicUI::MakeProgress(XO("Export"), mStatus);
58 else
59 mProgressDialog->SetMessage(mStatus);
60
61 const auto result = mProgressDialog->Poll(mProgress * ProgressSteps, ProgressSteps);
62
64 {
65 if(!mStopped)
66 mCancelled = true;
67 }
68 else if(result == BasicUI::ProgressResult::Stopped)
69 {
70 if(!mCancelled)
71 mStopped = true;
72 }
73 }
74
75
76 };
77
78}
79
81{
82 assert(exportTask.valid());
83
84 auto f = exportTask.get_future();
85 DialogExportProgressDelegate delegate;
86 std::thread(std::move(exportTask), std::ref(delegate)).detach();
87 auto result = ExportResult::Error;
88 while(f.wait_for(std::chrono::milliseconds(50)) != std::future_status::ready)
89 delegate.UpdateUI();
90
91 ExceptionWrappedCall([&] { result = f.get(); });
92
93 if(result == ExportResult::Error)
94 {
96 {}, XO("Export error"),
97 XO("Export completed with error."), {},
99 }
100
101 return result;
102}
Toolkit-neutral facade for basic user interface services.
#define str(a)
std::packaged_task< ExportResult(ExportProcessorDelegate &)> ExportTask
Definition: ExportTypes.h:31
ExportResult
Definition: ExportTypes.h:24
MessageBoxException for failures of file operations.
XO("Cut/Copy/Paste")
Holds a msgid for the translation catalog; may also bind format arguments.
void ShowErrorDialog(const WindowPlacement &placement, const TranslatableString &dlogTitle, const TranslatableString &message, const ManualPageID &helpPage, const ErrorDialogOptions &options={})
Show an error dialog with a link to the manual for further help.
Definition: BasicUI.h:264
std::unique_ptr< ProgressDialog > MakeProgress(const TranslatableString &title, const TranslatableString &message, unsigned flags=(ProgressShowStop|ProgressShowCancel), const TranslatableString &remainingLabelText={})
Create and display a progress dialog.
Definition: BasicUI.h:294
IMPORT_EXPORT_API ExportResult Show(ExportTask exportTask)
void ExceptionWrappedCall(Callable callable)
Options for variations of error dialogs; the default is for modal dialogs.
Definition: BasicUI.h:52