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...
 
bool OpenInDefaultBrowser (const wxString &url)
 Open an URL in default browser. 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 206 of file BasicUI.cpp.

207{
208 if (auto p = Get())
209 p->DoCallAfter(action);
210 else {
211 // No services yet -- but don't lose the action. Put it in a queue
212 auto guard = std::lock_guard{ sActionsMutex };
213 sActions.emplace_back(std::move(action));
214 }
215}
static std::vector< Action > sActions
Definition: BasicUI.cpp:204
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:194
static std::recursive_mutex sActionsMutex
Definition: BasicUI.cpp:203

References Get(), sActions, and sActionsMutex.

Referenced by AdornedRulerPanel::AdornedRulerPanel(), PrefsListener::Broadcast(), cloud::audiocom::UserService::ClearUserData(), cloud::audiocom::OAuthService::DoAuthorise(), cloud::audiocom::UserService::DownloadAvatar(), 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(), cloud::audiocom::OAuthService::SafePublish(), TrackPanelAx::SetFocus(), and cloud::audiocom::UserService::UpdateUserData().

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 251 of file BasicUI.cpp.

252{
253 return XO("Message");
254}
#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 196 of file BasicUI.cpp.

197{
198 auto result = theInstance;
199 theInstance = pInstance;
200 return result;
201}

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 302 of file BasicUI.h.

305{
306 if (auto p = Get())
307 return p->DoMakeGenericProgress(placement, title, message);
308 else
309 return nullptr;
310}
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 284 of file BasicUI.h.

288 {})
289{
290 if (auto p = Get())
291 return p->DoMakeProgress(title, message, flags, remainingLabelText);
292 else
293 return nullptr;
294}

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

Here is the caller graph for this function:

◆ OpenInDefaultBrowser()

BASIC_UI_API bool BasicUI::OpenInDefaultBrowser ( const wxString &  url)

Open an URL in default browser.

This function may be called in other threads than the main.

Definition at line 238 of file BasicUI.cpp.

239{
240#if HAS_XDG_OPEN_HELPER
241 if (RunXDGOpen(url.ToStdString()))
242 return true;
243#endif
244
245 if(auto p = Get())
246 return p->DoOpenInDefaultBrowser(url);
247
248 return false;
249}

References Get().

Referenced by OpenInDefaultBrowser(), and RealtimeEffectListWindow::RealtimeEffectListWindow().

Here is the call graph for this function:
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 254 of file BasicUI.h.

259 {})
260{
261 if (auto p = Get())
262 p->DoShowErrorDialog(placement, dlogTitle, message, helpPage, options);
263}

Referenced by MessageBoxException::DelayedHandlerAction(), ProjectAudioManager::DoRecord(), ProjectFileManager::DoSave(), MP3ImportFileHandle::ErrorCB(), TempDirectory::FATFilesystemDenied(), UpdateManager::GetUpdates(), cloud::audiocom::ShareAudioDialog::HandleExportFailure(), cloud::audiocom::ShareAudioDialog::HandleUploadFailed(), 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 269 of file BasicUI.h.

270 {})
271{
272 if (auto p = Get())
273 return p->DoMessageBox(message, std::move(options));
274 else
275 return MessageBoxResult::None;
276}

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 322 of file BasicUI.h.

327{
328 if (auto p = Get())
329 return p->DoMultiDialog(message, title, buttons, helpPage, boxMsg, log);
330 else
331 return -1;
332}

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 217 of file BasicUI.cpp.

218{
219 do {
220 // Dispatch anything in the queue, added while there were no Services
221 {
222 auto guard = std::lock_guard{ sActionsMutex };
223 std::vector<Action> actions;
224 actions.swap(sActions);
225 for (auto &action : actions)
226 action();
227 }
228
229 // Dispatch according to Services, if present
230 if (auto p = Get())
231 p->DoYield();
232 }
233 // Re-test for more actions that might have been enqueued by actions just
234 // dispatched
235 while ( !sActions.empty() );
236}

References Get(), sActions, and sActionsMutex.

Referenced by cloud::audiocom::ShareAudioDialog::ExportProgressHelper::Poll(), cloud::audiocom::ShareAudioDialog::ResetProgress(), and NyquistEffect::ShowHostInterface().

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

Variable Documentation

◆ sActions

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

Definition at line 204 of file BasicUI.cpp.

Referenced by CallAfter(), and Yield().

◆ sActionsMutex

std::recursive_mutex BasicUI::sActionsMutex
static

Definition at line 203 of file BasicUI.cpp.

Referenced by CallAfter(), and Yield().

◆ theInstance

Services* BasicUI::theInstance = nullptr
static

Definition at line 192 of file BasicUI.cpp.

Referenced by Get(), and Install().