Audacity 3.2.0
Classes | Functions | Variables
BasicUI Namespace Reference

Classes

struct  ErrorDialogOptions
 Options for variations of error dialogs; the default is for modal dialogs. More...
 
class  GenericProgressDialog
 Abstraction of a progress dialog with undefined time-to-completion estimate. More...
 
struct  MessageBoxOptions
 
struct  Point
 A pair of screen coordinates, x increasing rightward, y downward. More...
 
class  ProgressDialog
 Abstraction of a progress dialog with well defined time-to-completion estimate. More...
 
class  Services
 Abstract class defines a few user interface services, not mentioning particular toolkits. More...
 
class  WindowPlacement
 Subclasses may hold information such as a parent window pointer for a dialog. More...
 

Functions

ServicesGet ()
 Fetch the global instance, or nullptr if none is yet installed. More...
 
ServicesInstall (Services *pInstance)
 Install an implementation; return the previously installed instance. More...
 
Functions that invoke global Services

These dispatch to the global Services, if supplied. If none was supplied, they are mostly no-ops, with exceptions as noted. All should be called on the main thread only, except as noted.

void CallAfter (Action action)
 Schedule an action to be done later, and in the main thread. More...
 
void Yield ()
 Dispatch waiting events, including actions enqueued by CallAfter. More...
 
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. More...
 
MessageBoxResult ShowMessageBox (const TranslatableString &message, MessageBoxOptions options={})
 Show a modal message box with either Ok or Yes and No, and optionally Cancel. More...
 
std::unique_ptr< ProgressDialogMakeProgress (const TranslatableString &title, const TranslatableString &message, unsigned flags=(ProgressShowStop|ProgressShowCancel), const TranslatableString &remainingLabelText={})
 Create and display a progress dialog. More...
 
std::unique_ptr< GenericProgressDialogMakeGenericProgress (const WindowPlacement &placement, const TranslatableString &title, const TranslatableString &message)
 Create and display a progress dialog (return nullptr if Services not installed) More...
 
int ShowMultiDialog (const TranslatableString &message, const TranslatableString &title, const TranslatableStrings &buttons, const ManualPageID &helpPage, const TranslatableString &boxMsg, bool log)
 Display a dialog with radio buttons. More...
 

Variables

static ServicestheInstance = nullptr
 
static std::recursive_mutex sActionsMutex
 
static std::vector< ActionsActions
 

Types used in the Services interface

enum class  ErrorDialogType { ModelessError , ModalError , ModalErrorReport }
 
enum class  Icon {
  None , Warning , Error , Question ,
  Information
}
 
enum class  Button { Default , Ok , YesNo }
 
enum class  MessageBoxResult : int {
  None , Yes , No , Ok ,
  Cancel
}
 
enum  ProgressDialogOptions : unsigned { ProgressShowStop = (1 << 0) , ProgressShowCancel = (1 << 1) , ProgressHideTime = (1 << 2) , ProgressConfirmStopOrCancel = (1 << 3) }
 
enum class  ProgressResult : unsigned { Cancelled = 0 , Success , Failed , Stopped }
 
using Action = std::function< void()>
 
TranslatableString DefaultCaption ()
 "Message", suitably translated More...
 

Typedef Documentation

◆ Action

using BasicUI::Action = typedef std::function<void()>

Definition at line 24 of file BasicUI.h.

Enumeration Type Documentation

◆ Button

enum class BasicUI::Button
strong
Enumerator
Default 

Like Ok, except maybe minor difference of dialog position.

Ok 

One button.

YesNo 

Two buttons.

Definition at line 85 of file BasicUI.h.

85 {
86 Default,
87 Ok,
88 YesNo
89};
@ Default
Like Ok, except maybe minor difference of dialog position.
@ Ok
One button.
@ YesNo
Two buttons.

◆ ErrorDialogType

enum class BasicUI::ErrorDialogType
strong
Enumerator
ModelessError 
ModalError 
ModalErrorReport 

If error reporting is enabled, may give option to send; if not, then like ModalError

Definition at line 40 of file BasicUI.h.

◆ Icon

enum class BasicUI::Icon
strong
Enumerator
None 
Warning 
Error 
Question 
Information 

Definition at line 77 of file BasicUI.h.

◆ MessageBoxResult

enum class BasicUI::MessageBoxResult : int
strong
Enumerator
None 

May be returned if no Services are installed.

Yes 
No 
Ok 
Cancel 

Definition at line 129 of file BasicUI.h.

◆ ProgressDialogOptions

Enumerator
ProgressShowStop 
ProgressShowCancel 
ProgressHideTime 
ProgressConfirmStopOrCancel 

Definition at line 137 of file BasicUI.h.

137 : unsigned {
138 ProgressShowStop = (1 << 0),
139 ProgressShowCancel = (1 << 1),
140 ProgressHideTime = (1 << 2),
142};
@ ProgressHideTime
Definition: BasicUI.h:140
@ ProgressShowCancel
Definition: BasicUI.h:139
@ ProgressConfirmStopOrCancel
Definition: BasicUI.h:141
@ ProgressShowStop
Definition: BasicUI.h:138

◆ ProgressResult

enum class BasicUI::ProgressResult : unsigned
strong
Enumerator
Cancelled 
Success 
Failed 
Stopped 

Definition at line 144 of file BasicUI.h.

145{
146 Cancelled = 0, //<! User says that whatever is happening is undesirable and shouldn't have happened at all
147 Success, //<! User says nothing, everything works fine, continue doing whatever we're doing
148 Failed, //<! Something has gone wrong, we should stop and cancel everything we did
149 Stopped //<! Nothing is wrong, but user says we should stop now and leave things as they are now
150};

Function Documentation

◆ CallAfter()

BASIC_UI_API void BasicUI::CallAfter ( Action  action)

Schedule an action to be done later, and in the main thread.

This function may be called in other threads than the main. If no Services are yet installed, the action is not lost, but may be dispatched by Yield(). The action may itself invoke CallAfter to enqueue other actions.

Definition at line 38 of file BasicUI.cpp.

39{
40 if (auto p = Get())
41 p->DoCallAfter(action);
42 else {
43 // No services yet -- but don't lose the action. Put it in a queue
44 auto guard = std::lock_guard{ sActionsMutex };
45 sActions.emplace_back(std::move(action));
46 }
47}
static std::vector< Action > sActions
Definition: BasicUI.cpp:36
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:26
static std::recursive_mutex sActionsMutex
Definition: BasicUI.cpp:35

References Get(), sActions, and sActionsMutex.

Referenced by AdornedRulerPanel::AdornedRulerPanel(), PrefsListener::Broadcast(), AudacityException::EnqueueAction(), UndoManager::EnqueueMessage(), Journal::Events::FailedEventSerialization(), AsyncPluginValidator::Impl::HandleInternalError(), ProjectWindow::HandleResize(), AsyncPluginValidator::Impl::HandleResult(), AudacityApp::InitPart2(), NotifyingSelectedRegion::Notify(), TrackPanel::OnAudioIO(), AudacityApp::OnExceptionInMainLoop(), App::OnInit(), AudacityApp::OnInit(), AudacityApp::OnInit0(), AdornedRulerPanel::OnLeave(), TrackPanel::OnMouseEvent(), IncompatiblePluginsDialog::OnPluginManagerClicked(), ErrorReportDialog::OnSend(), TrackList::QueueEvent(), ProjectWindow::RedrawProject(), AdornedRulerPanel::Refresh(), TrackPanel::Refresh(), and TrackPanelAx::SetFocus().

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

◆ DefaultCaption()

BASIC_UI_API TranslatableString BasicUI::DefaultCaption ( )

"Message", suitably translated

Definition at line 70 of file BasicUI.cpp.

71{
72 return XO("Message");
73}
#define XO(s)
Definition: Internat.h:31

References XO.

Referenced by MessageBoxException::DelayedHandlerAction(), and MP3ImportFileHandle::ErrorCB().

Here is the caller graph for this function:

◆ Get()

BASIC_UI_API Services * BasicUI::Get ( )

◆ Install()

BASIC_UI_API Services * BasicUI::Install ( Services pInstance)

Install an implementation; return the previously installed instance.

Definition at line 28 of file BasicUI.cpp.

29{
30 auto result = theInstance;
31 theInstance = pInstance;
32 return result;
33}

References theInstance.

Referenced by AudacityApp::OnInit0().

Here is the caller graph for this function:

◆ MakeGenericProgress()

std::unique_ptr< GenericProgressDialog > BasicUI::MakeGenericProgress ( const WindowPlacement placement,
const TranslatableString title,
const TranslatableString message 
)
inline

Create and display a progress dialog (return nullptr if Services not installed)

This function makes a "generic" progress dialog, for the case when time to completion cannot be estimated, but some indication of progress is still given

Definition at line 289 of file BasicUI.h.

292{
293 if (auto p = Get())
294 return p->DoMakeGenericProgress(placement, title, message);
295 else
296 return nullptr;
297}
static const auto title

References Get(), and title.

Referenced by DBConnection::Close(), ProjectFileIO::RenameOrWarn(), and ProjectFileIO::SaveProject().

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

◆ MakeProgress()

std::unique_ptr< ProgressDialog > BasicUI::MakeProgress ( const TranslatableString title,
const TranslatableString message,
unsigned  flags = (ProgressShowStop | ProgressShowCancel),
const TranslatableString remainingLabelText = {} 
)
inline

Create and display a progress dialog.

Parameters
flagsbitwise OR of values in ProgressDialogOptions
remainingLabelTextif not empty substitutes for "Remaining Time:"
Returns
nullptr if Services not installed

Definition at line 271 of file BasicUI.h.

275 {})
276{
277 if (auto p = Get())
278 return p->DoMakeProgress(title, message, flags, remainingLabelText);
279 else
280 return nullptr;
281}

Referenced by EffectBase::DoEffect(), UpdateManager::GetUpdates(), MixAndRender(), SqliteSampleBlockFactory::OnBeginPurge(), TrackActions::Handler::OnResample(), EffectBase::Preview(), and PluginStartupRegistration::Run().

Here is the caller graph for this function:

◆ ShowErrorDialog()

void BasicUI::ShowErrorDialog ( const WindowPlacement placement,
const TranslatableString dlogTitle,
const TranslatableString message,
const ManualPageID helpPage,
const ErrorDialogOptions options = {} 
)
inline

Show an error dialog with a link to the manual for further help.

Parameters
placementhow to parent the dialog
dlogTitleText for title bar
messageThe main message text
helpPageIdentifies manual page (and maybe an anchor)

Definition at line 241 of file BasicUI.h.

246 {})
247{
248 if (auto p = Get())
249 p->DoShowErrorDialog(placement, dlogTitle, message, helpPage, options);
250}

Referenced by MessageBoxException::DelayedHandlerAction(), ProjectAudioManager::DoRecord(), ProjectFileManager::DoSave(), MP3ImportFileHandle::ErrorCB(), TempDirectory::FATFilesystemDenied(), UpdateManager::GetUpdates(), ProjectFileManager::Import(), ProjectAudioManager::PlayPlayRegion(), EffectBase::Preview(), ProjectFileIO::ProjectFileIO(), ExportPCM::ReportTooBigError(), ProjectFileManager::SaveCopy(), ShowDiskFullExportErrorDialog(), ProjectFileIO::ShowError(), ShowExportErrorDialog(), AudioIO::StartMonitoring(), MenuManager::TellUserWhyDisallowed(), and TempDirectory::TempDir().

Here is the caller graph for this function:

◆ ShowMessageBox()

MessageBoxResult BasicUI::ShowMessageBox ( const TranslatableString message,
MessageBoxOptions  options = {} 
)
inline

Show a modal message box with either Ok or Yes and No, and optionally Cancel.

Returns
indicates which button was pressed

Definition at line 256 of file BasicUI.h.

257 {})
258{
259 if (auto p = Get())
260 return p->DoMessageBox(message, std::move(options));
261 else
262 return MessageBoxResult::None;
263}

Referenced by anonymous_namespace{Registry.cpp}::BadPath(), ConfirmSave(), CreateDirectory(), ThemeBase::CreateImageCache(), ThemeBase::CreateOneImageCache(), MessageBoxException::DelayedHandlerAction(), DoMessageBox(), PluginManager::DropFile(), VST3Effect::ExportPresets(), Journal::Events::FailedEventSerialization(), ThemeBase::LoadOneThemeComponents(), VST3Effect::LoadPreset(), anonymous_namespace{MIDIPlay.h}::MIDIPlay::MIDIPlay(), ThemeBase::ReadImageCache(), and Sequence::WriteXML().

Here is the caller graph for this function:

◆ ShowMultiDialog()

int BasicUI::ShowMultiDialog ( const TranslatableString message,
const TranslatableString title,
const TranslatableStrings buttons,
const ManualPageID helpPage,
const TranslatableString boxMsg,
bool  log 
)
inline

Display a dialog with radio buttons.

Returns
zero-based index of the chosen button, or -1 if Services not installed.
Parameters
messagemain message in the dialog
titledialog title
buttonslabels for individual radio buttons
boxMsglabel for the group of buttons
helpPageidentifies a manual page
logwhether to add a "Show Log for Details" push button

Definition at line 309 of file BasicUI.h.

314{
315 if (auto p = Get())
316 return p->DoMultiDialog(message, title, buttons, helpPage, boxMsg, log);
317 else
318 return -1;
319}

References Get(), and title.

Referenced by ModuleManager::TryLoadModules().

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

◆ Yield()

BASIC_UI_API void BasicUI::Yield ( )

Dispatch waiting events, including actions enqueued by CallAfter.

This function must be called by the main thread. Actions enqueued by CallAfter before Services were installed will be dispatched in the sequence they were enqueued, unless an exception thrown by one of them stops the dispatching.

Definition at line 49 of file BasicUI.cpp.

50{
51 do {
52 // Dispatch anything in the queue, added while there were no Services
53 {
54 auto guard = std::lock_guard{ sActionsMutex };
55 std::vector<Action> actions;
56 actions.swap(sActions);
57 for (auto &action : actions)
58 action();
59 }
60
61 // Dispatch according to Services, if present
62 if (auto p = Get())
63 p->DoYield();
64 }
65 // Re-test for more actions that might have been enqueued by actions just
66 // dispatched
67 while ( !sActions.empty() );
68}

References Get(), sActions, and sActionsMutex.

Here is the call graph for this function:

Variable Documentation

◆ sActions

std::vector<Action> BasicUI::sActions
static

Definition at line 36 of file BasicUI.cpp.

Referenced by CallAfter(), and Yield().

◆ sActionsMutex

std::recursive_mutex BasicUI::sActionsMutex
static

Definition at line 35 of file BasicUI.cpp.

Referenced by CallAfter(), and Yield().

◆ theInstance

Services* BasicUI::theInstance = nullptr
static

Definition at line 24 of file BasicUI.cpp.

Referenced by Get(), and Install().