LMMS
Loading...
Searching...
No Matches
juce::ThreadWithProgressWindow Class Reference

#include <juce_ThreadWithProgressWindow.h>

Inheritance diagram for juce::ThreadWithProgressWindow:
juce::Thread juce::Timer

Public Member Functions

 ThreadWithProgressWindow (const String &windowTitle, bool hasProgressBar, bool hasCancelButton, int timeOutMsWhenCancelling=10000, const String &cancelButtonText=String(), Component *componentToCentreAround=nullptr)
 ~ThreadWithProgressWindow () override
void launchThread (int priority=5)
void setProgress (double newProgress)
void setStatusMessage (const String &newStatusMessage)
AlertWindowgetAlertWindow () const noexcept
virtual void threadComplete (bool userPressedCancel)
Public Member Functions inherited from juce::Thread
 Thread (const String &threadName, size_t threadStackSize=0)
virtual ~Thread ()
virtual void run ()=0
void startThread ()
void startThread (int priority)
bool stopThread (int timeOutMilliseconds)
bool isThreadRunning () const
void signalThreadShouldExit ()
bool threadShouldExit () const
bool waitForThreadToExit (int timeOutMilliseconds) const
void addListener (Listener *)
void removeListener (Listener *)
bool setPriority (int priority)
void setAffinityMask (uint32 affinityMask)
bool wait (int timeOutMilliseconds) const
void notify () const
ThreadID getThreadId () const noexcept
const StringgetThreadName () const noexcept

Private Member Functions

void timerCallback () override
Private Member Functions inherited from juce::Timer
virtual ~Timer ()
void startTimer (int intervalInMilliseconds) noexcept
void startTimerHz (int timerFrequencyHz) noexcept
void stopTimer () noexcept
bool isTimerRunning () const noexcept
int getTimerInterval () const noexcept
 Timer () noexcept
 Timer (const Timer &) noexcept

Private Attributes

double progress
std::unique_ptr< AlertWindowalertWindow
String message
CriticalSection messageLock
const int timeOutMsWhenCancelling
bool wasCancelledByUser

Additional Inherited Members

Public Types inherited from juce::Thread
enum  { realtimeAudioPriority = -1 }
using ThreadID = void*
Static Public Member Functions inherited from juce::Thread
static void launch (std::function< void()> functionToRun)
static bool currentThreadShouldExit ()
static bool setCurrentThreadPriority (int priority)
static void JUCE_CALLTYPE setCurrentThreadAffinityMask (uint32 affinityMask)
static void JUCE_CALLTYPE sleep (int milliseconds)
static void JUCE_CALLTYPE yield ()
static ThreadID JUCE_CALLTYPE getCurrentThreadId ()
static Thread *JUCE_CALLTYPE getCurrentThread ()
static void JUCE_CALLTYPE setCurrentThreadName (const String &newThreadName)
Static Private Member Functions inherited from juce::Timer
static void JUCE_CALLTYPE callAfterDelay (int milliseconds, std::function< void()> functionToCall)
static void JUCE_CALLTYPE callPendingTimersSynchronously ()

Detailed Description

A thread that automatically pops up a modal dialog box with a progress bar and cancel button while it's busy running.

These are handy for performing some sort of task while giving the user feedback about how long there is to go, etc.

E.g.

class MyTask : public ThreadWithProgressWindow
{
public:
MyTask() : ThreadWithProgressWindow ("busy...", true, true)
{
}
void run()
{
for (int i = 0; i < thingsToDo; ++i)
{
// must check this as often as possible, because this is
// how we know if the user's pressed 'cancel'
if (threadShouldExit())
break;
// this will update the progress bar on the dialog box
setProgress (i / (double) thingsToDo);
// ... do the business here...
}
}
};
void doTheTask()
{
MyTask m;
if (m.runThread())
{
// thread finished normally..
}
else
{
// user pressed the cancel button..
}
}
static void run(LV2_Handle instance, uint32_t n_samples)
Definition bindings_test_plugin.c:112
ThreadWithProgressWindow(const String &windowTitle, bool hasProgressBar, bool hasCancelButton, int timeOutMsWhenCancelling=10000, const String &cancelButtonText=String(), Component *componentToCentreAround=nullptr)
Definition juce_ThreadWithProgressWindow.cpp:29
unsigned * m
Definition inflate.c:1559
register unsigned i
Definition inflate.c:1575
#define true
Definition ordinals.h:82
See also
Thread, AlertWindow

@tags{GUI}

Constructor & Destructor Documentation

◆ ThreadWithProgressWindow()

juce::ThreadWithProgressWindow::ThreadWithProgressWindow ( const String & windowTitle,
bool hasProgressBar,
bool hasCancelButton,
int timeOutMsWhenCancelling = 10000,
const String & cancelButtonText = String(),
Component * componentToCentreAround = nullptr )

Creates the thread.

Initially, the dialog box won't be visible, it'll only appear when the runThread() method is called.

Parameters
windowTitlethe title to go at the top of the dialog box
hasProgressBarwhether the dialog box should have a progress bar (see setProgress() )
hasCancelButtonwhether the dialog box should have a cancel button
timeOutMsWhenCancellingwhen 'cancel' is pressed, this is how long to wait for the thread to stop before killing it forcibly (see Thread::stopThread() )
cancelButtonTextthe text that should be shown in the cancel button (if it has one). Leave this empty for the default "Cancel"
componentToCentreAroundif this is non-null, the window will be positioned so that it's centred around this component.

◆ ~ThreadWithProgressWindow()

juce::ThreadWithProgressWindow::~ThreadWithProgressWindow ( )
override

Destructor.

Member Function Documentation

◆ getAlertWindow()

AlertWindow * juce::ThreadWithProgressWindow::getAlertWindow ( ) const
inlinenoexcept

Returns the AlertWindow that is being used.

◆ launchThread()

void juce::ThreadWithProgressWindow::launchThread ( int priority = 5)

Starts the thread and returns.

This will start the thread and make the dialog box appear in a modal state. When the thread finishes normally, or the cancel button is pressed, the window will be hidden and the threadComplete() method will be called.

Parameters
prioritythe priority to use when starting the thread - see Thread::startThread() for values

◆ setProgress()

void juce::ThreadWithProgressWindow::setProgress ( double newProgress)

The thread should call this periodically to update the position of the progress bar.

Parameters
newProgressthe progress, from 0.0 to 1.0
See also
setStatusMessage

◆ setStatusMessage()

void juce::ThreadWithProgressWindow::setStatusMessage ( const String & newStatusMessage)

The thread can call this to change the message that's displayed in the dialog box.

◆ threadComplete()

void juce::ThreadWithProgressWindow::threadComplete ( bool userPressedCancel)
virtual

This method is called (on the message thread) when the operation has finished. You may choose to use this callback to delete the ThreadWithProgressWindow object.

◆ timerCallback()

void juce::ThreadWithProgressWindow::timerCallback ( )
overrideprivatevirtual

The user-defined callback routine that actually gets called periodically.

It's perfectly ok to call startTimer() or stopTimer() from within this callback to change the subsequent intervals.

Implements juce::Timer.

Member Data Documentation

◆ alertWindow

std::unique_ptr<AlertWindow> juce::ThreadWithProgressWindow::alertWindow
private

◆ message

String juce::ThreadWithProgressWindow::message
private

◆ messageLock

CriticalSection juce::ThreadWithProgressWindow::messageLock
private

◆ progress

double juce::ThreadWithProgressWindow::progress
private

◆ timeOutMsWhenCancelling

const int juce::ThreadWithProgressWindow::timeOutMsWhenCancelling
private

◆ wasCancelledByUser

bool juce::ThreadWithProgressWindow::wasCancelledByUser
private

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