Audacity 3.2.0
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
cloud::audiocom::ShareAudioDialog Class Referencefinal

#include <ShareAudioDialog.h>

Inheritance diagram for cloud::audiocom::ShareAudioDialog:
[legend]
Collaboration diagram for cloud::audiocom::ShareAudioDialog:
[legend]

Classes

struct  ExportProgressHelper
 
struct  InitialStatePanel
 
struct  ProgressPanel
 
struct  Services
 

Public Member Functions

 ShareAudioDialog (AudacityProject &project, wxWindow *parent=nullptr)
 
 ~ShareAudioDialog () override
 
- 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
 

Private Types

using Clock = std::chrono::steady_clock
 

Private Member Functions

void Populate (ShuttleGui &s)
 
void OnCancel ()
 
void OnContinue ()
 
wxString ExportProject ()
 
void StartUploadProcess ()
 
void HandleUploadSucceeded (const UploadSuccessfulPayload &payload)
 
void HandleUploadFailed (const UploadFailedPayload &payload)
 
void HandleExportFailure ()
 
void ResetProgress ()
 
void UpdateProgress (uint64_t current, uint64_t total)
 

Private Attributes

AudacityProjectmProject
 
struct cloud::audiocom::ShareAudioDialog::InitialStatePanel mInitialStatePanel
 
struct cloud::audiocom::ShareAudioDialog::ProgressPanel mProgressPanel
 
wxButton * mContinueButton { nullptr }
 
wxButton * mCancelButton { nullptr }
 
std::unique_ptr< ServicesmServices
 
std::unique_ptr< BasicUI::ProgressDialogmExportProgressHelper
 
Clock::time_point mStageStartTime
 
Clock::time_point mLastUIUpdateTime
 
int mLastProgressValue { 0 }
 
wxString mFilePath
 
std::function< void()> mContinueAction
 
bool mIsAuthorised { false }
 
bool mInProgress { false }
 

Detailed Description

Definition at line 44 of file ShareAudioDialog.h.

Member Typedef Documentation

◆ Clock

using cloud::audiocom::ShareAudioDialog::Clock = std::chrono::steady_clock
private

Definition at line 120 of file ShareAudioDialog.h.

Constructor & Destructor Documentation

◆ ShareAudioDialog()

cloud::audiocom::ShareAudioDialog::ShareAudioDialog ( AudacityProject project,
wxWindow *  parent = nullptr 
)

Definition at line 167 of file ShareAudioDialog.cpp.

169 parent, wxID_ANY, XO("Share Audio"), wxDefaultPosition, { 480, 250 },
170 wxDEFAULT_DIALOG_STYLE)
171 , mProject(project)
172 , mInitialStatePanel(*this)
173 , mServices(std::make_unique<Services>())
174{
176
177 ShuttleGui s(this, eIsCreating);
178
179 s.StartVerticalLay();
180 {
181 Populate(s);
182 }
183 s.EndVerticalLay();
184
185 Layout();
186 Fit();
187 Centre();
188
189 const auto size = GetSize();
190
191 SetMinSize({ size.x, std::min(250, size.y) });
192 SetMaxSize({ size.x, -1 });
193
194 mContinueAction = [this]()
195 {
196 if (mInitialStatePanel.root->IsShown())
198 };
199
200 Bind(
201 wxEVT_CHAR_HOOK,
202 [this](auto& evt)
203 {
204 if (!IsEscapeKey(evt))
205 {
206 evt.Skip();
207 return;
208 }
209
210 OnCancel();
211 });
212}
int min(int a, int b)
XO("Cut/Copy/Paste")
@ eIsCreating
Definition: ShuttleGui.h:37
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:625
struct cloud::audiocom::ShareAudioDialog::InitialStatePanel mInitialStatePanel
std::function< void()> mContinueAction
std::unique_ptr< Services > mServices
AuthorizationHandler & GetAuthorizationHandler()

◆ ~ShareAudioDialog()

cloud::audiocom::ShareAudioDialog::~ShareAudioDialog ( )
override

Definition at line 214 of file ShareAudioDialog.cpp.

215{
217 // Clean up the temp file when the dialog is closed
218 if (!mFilePath.empty() && wxFileExists(mFilePath))
219 wxRemoveFile(mFilePath);
220}

References cloud::audiocom::GetAuthorizationHandler(), mFilePath, and cloud::audiocom::AuthorizationHandler::PopSuppressDialogs().

Here is the call graph for this function:

Member Function Documentation

◆ ExportProject()

wxString cloud::audiocom::ShareAudioDialog::ExportProject ( )
private

Definition at line 312 of file ShareAudioDialog.cpp.

313{
314 mExportProgressHelper = std::make_unique<ExportProgressHelper>(*this);
315
316 auto exporter = CreatePreferredExporter(GetServiceConfig().GetPreferredAudioFormats(), mProject);
317
318 if (!exporter)
319 return {};
320
321 const auto path = GenerateTempPath(exporter->GetFileExtension());
322
323 if (path.empty())
324 return {};
325
326
328 exporter->OnBeforeExport();
329
330 auto cleanupExporter = finally([&]() { exporter->OnAfterExport(); });
331
332 Exporter e { const_cast<AudacityProject&>(mProject) };
333
334 auto& tracks = TrackList::Get(mProject);
335
336 const double t0 = 0.0;
337 const double t1 = tracks.GetEndTime();
338
339 const int nChannels = CalculateChannels(tracks);
340
341 const bool success = e.Process(
342 nChannels, // numChannels,
343 exporter->GetExporterID(), // type,
344 path, // full path,
345 false, // selectedOnly,
346 t0, // t0
347 t1, // t1
348 mExportProgressHelper // progress dialog
349 );
350
351 if (!success && wxFileExists(path))
352 // Try to remove the file if exporting has failed (or was canceled)
353 wxRemoveFile(path);
354
355 return success ? path : wxString {};
356}
static AudioUnitEffectsModule::Factory::SubstituteInUnique< AudioUnitEffect > scope
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
Makes temporary changes to preferences, then rolls them back at destruction.
Definition: Prefs.h:115
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:385
std::unique_ptr< BasicUI::ProgressDialog > mExportProgressHelper
const ServiceConfig & GetServiceConfig()
Returns the instance of the ServiceConfig.
std::unique_ptr< cloud::CloudExporterPlugin > CreatePreferredExporter(const MimeTypesList &mimeTypes, const AudacityProject &project)

References cloud::audiocom::anonymous_namespace{ShareAudioDialog.cpp}::CalculateChannels(), cloud::CreatePreferredExporter(), cloud::audiocom::anonymous_namespace{ShareAudioDialog.cpp}::GenerateTempPath(), TrackList::Get(), cloud::audiocom::GetServiceConfig(), mExportProgressHelper, mProject, and scope.

Referenced by StartUploadProcess().

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

◆ HandleExportFailure()

void cloud::audiocom::ShareAudioDialog::HandleExportFailure ( )
private

Definition at line 492 of file ShareAudioDialog.cpp.

493{
494 EndModal(wxID_ABORT);
495
497 {}, XO("Export error"),
498 XO("We are unable to prepare this file for uploading."), {},
500}
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:259
Options for variations of error dialogs; the default is for modal dialogs.
Definition: BasicUI.h:51

References BasicUI::ModalError, BasicUI::ShowErrorDialog(), and XO().

Referenced by StartUploadProcess().

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

◆ HandleUploadFailed()

void cloud::audiocom::ShareAudioDialog::HandleUploadFailed ( const UploadFailedPayload payload)
private

Definition at line 463 of file ShareAudioDialog.cpp.

464{
465 EndModal(wxID_ABORT);
466
467 TranslatableString message;
468
469 if (payload.status == 401)
470 {
471 message = XO(
472 "We are unable to upload this file. Please try again and make sure to link to your audio.com account before uploading.");
473 }
474 else
475 {
476 auto details = payload.message;
477
478 for (auto& err : payload.additionalErrors)
479 details += " " + err.second;
480
481 message = XO("Error: %s").Format(details);
482 }
483
485 {}, XO("Upload error"),
486 message,
487 {},
489
490}
Holds a msgid for the translation catalog; may also bind format arguments.

References cloud::audiocom::UploadFailedPayload::additionalErrors, cloud::audiocom::UploadFailedPayload::message, BasicUI::ModalError, BasicUI::ShowErrorDialog(), cloud::audiocom::UploadFailedPayload::status, and XO().

Here is the call graph for this function:

◆ HandleUploadSucceeded()

void cloud::audiocom::ShareAudioDialog::HandleUploadSucceeded ( const UploadSuccessfulPayload payload)
private

Definition at line 436 of file ShareAudioDialog.cpp.

438{
440 mProgressPanel.title->SetLabel(XO("Upload complete!").Translation());
441 mProgressPanel.info->Show();
442
443 mProgressPanel.info->SetLabel(
444 "By pressing continue, you will be taken to audio.com and given a shareable link.");
445 mProgressPanel.info->Wrap(mProgressPanel.root->GetSize().GetWidth());
446
447 mContinueAction = [this, slug = std::string(payload.audioSlug)]()
448 {
449 EndModal(wxID_CLOSE);
450 auto url = wxString::Format(
451 "https://audio.com/%s/%s/edit", GetUserService().GetUserSlug(),
453
455 };
456
457 mContinueButton->Show();
458
459 Layout();
460 Fit();
461}
struct cloud::audiocom::ShareAudioDialog::ProgressPanel mProgressPanel
bool OpenInDefaultBrowser(const wxString &url)
Open an URL in default browser.
Definition: BasicUI.cpp:240
wxString ToWXString(const std::string &str)
UserService & GetUserService()

References cloud::audiocom::UploadSuccessfulPayload::audioSlug, cloud::audiocom::GetUserService(), BasicUI::OpenInDefaultBrowser(), audacity::ToWXString(), and XO().

Here is the call graph for this function:

◆ OnCancel()

void cloud::audiocom::ShareAudioDialog::OnCancel ( )
private

Definition at line 252 of file ShareAudioDialog.cpp.

253{
254 const auto hasExportStarted = mExportProgressHelper != nullptr;
255 const auto hasUploadStarted = !!mServices->uploadPromise;
256
257 if (mInProgress)
258 {
259 AudacityMessageDialog dlgMessage(
260 this, XO("Are you sure you want to cancel?"), XO("Cancel upload to Audio.com"),
261 wxYES_NO | wxICON_QUESTION | wxNO_DEFAULT | wxSTAY_ON_TOP);
262
263 const auto result = dlgMessage.ShowModal();
264
265 if (result != wxID_YES)
266 return;
267
268 // If export has started, notify it that it should be canceled
269 if (mExportProgressHelper != nullptr)
270 static_cast<ExportProgressHelper&>(*mExportProgressHelper).Cancel();
271 }
272
273
274 // If upload was started - ask it to discard the result.
275 // The result should be discarded even after the upload has finished
276 if (mServices->uploadPromise)
277 mServices->uploadPromise->DiscardResult();
278
279 EndModal(wxID_CANCEL);
280}
Wrap wxMessageDialog so that caption IS translatable.

References cloud::audiocom::ShareAudioDialog::ExportProgressHelper::Cancel(), mExportProgressHelper, mInProgress, mServices, and XO().

Referenced by Populate().

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

◆ OnContinue()

void cloud::audiocom::ShareAudioDialog::OnContinue ( )
private

Definition at line 282 of file ShareAudioDialog.cpp.

283{
285}

References mContinueAction.

Referenced by Populate().

Here is the caller graph for this function:

◆ Populate()

void cloud::audiocom::ShareAudioDialog::Populate ( ShuttleGui s)
private

Definition at line 222 of file ShareAudioDialog.cpp.

223{
226
227 s.StartHorizontalLay(wxEXPAND, 0);
228 {
230 {
231 s.SetBorder(2);
232 s.StartHorizontalLay(wxEXPAND, 0);
233 {
234 s.AddSpace(0, 0, 1);
235
236 mCancelButton = s.AddButton(XXO("&Cancel"));
237 mCancelButton->Bind(wxEVT_BUTTON, [this](auto) { OnCancel(); });
238
239 s.AddSpace(4, 0, 0);
240
241 mContinueButton = s.AddButton(XXO("C&ontinue"));
242 mContinueButton->Bind(wxEVT_BUTTON, [this](auto) { OnContinue(); });
244 }
246 }
248 }
250}
XXO("&Cut/Copy/Paste Toolbar")
void SetBorder(int Border)
Definition: ShuttleGui.h:484
void EndInvisiblePanel()
wxPanel * StartInvisiblePanel(int border=0)
wxButton * AddButton(const TranslatableString &Text, int PositionFlags=wxALIGN_CENTRE, bool setDefault=false)
Definition: ShuttleGui.cpp:359
void EndHorizontalLay()
void StartHorizontalLay(int PositionFlags=wxALIGN_CENTRE, int iProp=1)
wxSizerItem * AddSpace(int width, int height, int prop=0)

References ShuttleGuiBase::AddButton(), ShuttleGui::AddSpace(), ShuttleGuiBase::EndHorizontalLay(), ShuttleGuiBase::EndInvisiblePanel(), mCancelButton, mContinueButton, mInitialStatePanel, mIsAuthorised, mProgressPanel, OnCancel(), OnContinue(), cloud::audiocom::ShareAudioDialog::InitialStatePanel::PopulateInitialStatePanel(), cloud::audiocom::ShareAudioDialog::ProgressPanel::PopulateProgressPanel(), ShuttleGuiBase::SetBorder(), ShuttleGuiBase::StartHorizontalLay(), ShuttleGuiBase::StartInvisiblePanel(), and XXO().

Here is the call graph for this function:

◆ ResetProgress()

void cloud::audiocom::ShareAudioDialog::ResetProgress ( )
private

Definition at line 502 of file ShareAudioDialog.cpp.

503{
504 mStageStartTime = Clock::now();
506
507 mProgressPanel.elapsedTime->SetLabel(" 00:00:00");
508 mProgressPanel.remainingTime->SetLabel(" 00:00:00");
509 mProgressPanel.progress->SetValue(0);
510
512
514}
void Yield()
Dispatch waiting events, including actions enqueued by CallAfter.
Definition: BasicUI.cpp:219

References BasicUI::Yield().

Referenced by StartUploadProcess().

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

◆ StartUploadProcess()

void cloud::audiocom::ShareAudioDialog::StartUploadProcess ( )
private

Definition at line 358 of file ShareAudioDialog.cpp.

359{
360 mInProgress = true;
361
362 mInitialStatePanel.root->Hide();
363 mProgressPanel.root->Show();
364
365 mProgressPanel.info->Hide();
366
367 mContinueButton->Hide();
368
369 Layout();
370 Fit();
371
373
375
376 if (mFilePath.empty())
377 {
378 if (!static_cast<ExportProgressHelper&>(*mExportProgressHelper)
379 .WasCancelled())
380 {
382 }
383
384 return;
385 }
386
387 mProgressPanel.title->SetLabel(XO("Uploading audio...").Translation());
389
390 mServices->uploadPromise = mServices->uploadService.Upload(
391 mFilePath,
393 false,
394 [this](const auto& result)
395 {
396 CallAfter(
397 [this, result]()
398 {
399 mInProgress = false;
400
401 if (result.result == UploadOperationCompleted::Result::Success)
402 {
403 // Success indicates that UploadSuccessfulPayload is in the payload
404 assert(std::holds_alternative<UploadSuccessfulPayload>(result.payload));
405
406 if (
407 auto payload =
408 std::get_if<UploadSuccessfulPayload>(&result.payload))
409 HandleUploadSucceeded(*payload);
410 else
411 HandleUploadSucceeded({});
412
413 }
414 else if (
415 result.result != UploadOperationCompleted::Result::Aborted)
416 {
417 if (
418 auto payload =
419 std::get_if<UploadFailedPayload>(&result.payload))
420 HandleUploadFailed(*payload);
421 else
422 HandleUploadFailed({});
423 }
424 });
425 },
426 [this](auto current, auto total)
427 {
428 CallAfter(
429 [this, current, total]()
430 {
431 UpdateProgress(current, total);
432 });
433 });
434}
const wxString & GetProjectName() const
Definition: Project.cpp:100
void UpdateProgress(uint64_t current, uint64_t total)
void CallAfter(Action action)
Schedule an action to be done later, and in the main thread.
Definition: BasicUI.cpp:208

References ExportProject(), AudacityProject::GetProjectName(), HandleExportFailure(), cloud::audiocom::ShareAudioDialog::ProgressPanel::info, mContinueButton, mExportProgressHelper, mFilePath, mInitialStatePanel, mInProgress, mProgressPanel, mProject, mServices, ResetProgress(), cloud::audiocom::ShareAudioDialog::InitialStatePanel::root, cloud::audiocom::ShareAudioDialog::ProgressPanel::root, cloud::audiocom::ShareAudioDialog::ProgressPanel::title, and XO().

Here is the call graph for this function:

◆ UpdateProgress()

void cloud::audiocom::ShareAudioDialog::UpdateProgress ( uint64_t  current,
uint64_t  total 
)
private

Definition at line 528 of file ShareAudioDialog.cpp.

529{
530 using namespace std::chrono;
531
532 const auto now = Clock::now();
533
534 if (current == 0)
535 return;
536
537 if (current > total)
538 current = total;
539
540 if (mLastProgressValue != current)
541 {
542 constexpr int scale = 10000;
543
544 mLastProgressValue = static_cast<int>(current);
545
546 mProgressPanel.progress->SetRange(scale);
547 mProgressPanel.progress->SetValue((current * scale) / total);
548
549 if (current == total && mServices->uploadPromise)
550 {
552 mProgressPanel.title->SetLabel(XO("Finalizing upload...").Translation());
553 }
554 }
555
556 const auto elapsedSinceUIUpdate = now - mLastUIUpdateTime;
557
558 constexpr auto uiUpdateTimeout = 500ms;
559
560 if (elapsedSinceUIUpdate < uiUpdateTimeout && current < total)
561 return;
562
563 mLastUIUpdateTime = now;
564
565 const auto elapsed = duration_cast<milliseconds>(now - mStageStartTime);
566
568
569 const auto estimate = elapsed * total / current;
570 const auto remains = estimate - elapsed;
571
574 std::chrono::duration_cast<std::chrono::milliseconds>(remains));
575}
void SetTimeLabel(wxStaticText *label, std::chrono::milliseconds time)

References cloud::audiocom::anonymous_namespace{ShareAudioDialog.cpp}::SetTimeLabel(), and XO().

Referenced by cloud::audiocom::ShareAudioDialog::ExportProgressHelper::Poll().

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

Member Data Documentation

◆ mCancelButton

wxButton* cloud::audiocom::ShareAudioDialog::mCancelButton { nullptr }
private

Definition at line 112 of file ShareAudioDialog.h.

Referenced by Populate().

◆ mContinueAction

std::function<void()> cloud::audiocom::ShareAudioDialog::mContinueAction
private

Definition at line 128 of file ShareAudioDialog.h.

Referenced by OnContinue().

◆ mContinueButton

wxButton* cloud::audiocom::ShareAudioDialog::mContinueButton { nullptr }
private

Definition at line 111 of file ShareAudioDialog.h.

Referenced by Populate(), and StartUploadProcess().

◆ mExportProgressHelper

std::unique_ptr<BasicUI::ProgressDialog> cloud::audiocom::ShareAudioDialog::mExportProgressHelper
private

Definition at line 118 of file ShareAudioDialog.h.

Referenced by ExportProject(), OnCancel(), and StartUploadProcess().

◆ mFilePath

wxString cloud::audiocom::ShareAudioDialog::mFilePath
private

Definition at line 126 of file ShareAudioDialog.h.

Referenced by StartUploadProcess(), and ~ShareAudioDialog().

◆ mInitialStatePanel

struct cloud::audiocom::ShareAudioDialog::InitialStatePanel cloud::audiocom::ShareAudioDialog::mInitialStatePanel
private

Referenced by Populate(), and StartUploadProcess().

◆ mInProgress

bool cloud::audiocom::ShareAudioDialog::mInProgress { false }
private

Definition at line 131 of file ShareAudioDialog.h.

Referenced by OnCancel(), and StartUploadProcess().

◆ mIsAuthorised

bool cloud::audiocom::ShareAudioDialog::mIsAuthorised { false }
private

Definition at line 130 of file ShareAudioDialog.h.

Referenced by Populate().

◆ mLastProgressValue

int cloud::audiocom::ShareAudioDialog::mLastProgressValue { 0 }
private

Definition at line 124 of file ShareAudioDialog.h.

◆ mLastUIUpdateTime

Clock::time_point cloud::audiocom::ShareAudioDialog::mLastUIUpdateTime
private

Definition at line 123 of file ShareAudioDialog.h.

◆ mProgressPanel

struct cloud::audiocom::ShareAudioDialog::ProgressPanel cloud::audiocom::ShareAudioDialog::mProgressPanel
private

Referenced by Populate(), and StartUploadProcess().

◆ mProject

AudacityProject& cloud::audiocom::ShareAudioDialog::mProject
private

Definition at line 67 of file ShareAudioDialog.h.

Referenced by ExportProject(), and StartUploadProcess().

◆ mServices

std::unique_ptr<Services> cloud::audiocom::ShareAudioDialog::mServices
private

Definition at line 115 of file ShareAudioDialog.h.

Referenced by OnCancel(), and StartUploadProcess().

◆ mStageStartTime

Clock::time_point cloud::audiocom::ShareAudioDialog::mStageStartTime
private

Definition at line 122 of file ShareAudioDialog.h.


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