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 "AudacityMessageBox.h"
18#include "FileException.h"
19
20namespace
21{
23 {
24 std::atomic<bool> mCancelled {false};
25 std::atomic<bool> mStopped {false};
26 std::atomic<double> mProgress {};
27
29
30 std::unique_ptr<BasicUI::ProgressDialog> mProgressDialog;
31 public:
32
33 bool IsCancelled() const override
34 {
35 return mCancelled;
36 }
37
38 bool IsStopped() const override
39 {
40 return mStopped;
41 }
42
44 {
45 mStatus = str;
46 }
47
48 void OnProgress(double progress) override
49 {
50 mProgress = progress;
51 }
52
53 void UpdateUI()
54 {
55 constexpr long long ProgressSteps = 1000ul;
56
57 if(!mProgressDialog)
58 mProgressDialog = BasicUI::MakeProgress(XO("Export"), mStatus);
59 else
60 mProgressDialog->SetMessage(mStatus);
61
62 const auto result = mProgressDialog->Poll(mProgress * ProgressSteps, ProgressSteps);
63
65 {
66 if(!mStopped)
67 mCancelled = true;
68 }
69 else if(result == BasicUI::ProgressResult::Stopped)
70 {
71 if(!mCancelled)
72 mStopped = true;
73 }
74 }
75
76
77 };
78
79}
80
82{
83 assert(exportTask.valid());
84
85 auto f = exportTask.get_future();
86 DialogExportProgressDelegate delegate;
87 std::thread(std::move(exportTask), std::ref(delegate)).detach();
88 auto result = ExportResult::Error;
89 while(f.wait_for(std::chrono::milliseconds(50)) != std::future_status::ready)
90 delegate.UpdateUI();
91
92 ExceptionWrappedCall([&] { result = f.get(); });
93
94 if(result == ExportResult::Error)
95 {
97 {}, XO("Export error"),
98 XO("Export completed with error."), {},
100 }
101
102 return result;
103}
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:262
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:292
ExportResult Show(ExportTask exportTask)
void ExceptionWrappedCall(Callable callable)
Options for variations of error dialogs; the default is for modal dialogs.
Definition: BasicUI.h:52