openshot-audio  0.1.6
Public Member Functions | List of all members
ThreadWithProgressWindow Class Reference

#include <juce_ThreadWithProgressWindow.h>

Inheritance diagram for ThreadWithProgressWindow:
Thread Timer

Public Member Functions

 ThreadWithProgressWindow (const String &windowTitle, bool hasProgressBar, bool hasCancelButton, int timeOutMsWhenCancelling=10000, const String &cancelButtonText=String(), Component *componentToCentreAround=nullptr)
 
 ~ThreadWithProgressWindow ()
 
void launchThread (int threadPriority=5)
 
void setProgress (double newProgress)
 
void setStatusMessage (const String &newStatusMessage)
 
AlertWindowgetAlertWindow () const noexcept
 
virtual void threadComplete (bool userPressedCancel)
 
- Public Member Functions inherited from Thread
 Thread (const String &threadName)
 
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
 
bool setPriority (int priority)
 
void setAffinityMask (uint32 affinityMask)
 
bool wait (int timeOutMilliseconds) const
 
void notify () const
 
ThreadID getThreadId () const noexcept
 
const StringgetThreadName () const
 

Additional Inherited Members

- Public Types inherited from Thread
typedef void * ThreadID
 
- Static Public Member Functions inherited from Thread
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)
 

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'
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..
}
}
See also
Thread, AlertWindow

Constructor & Destructor Documentation

◆ ThreadWithProgressWindow()

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()

ThreadWithProgressWindow::~ThreadWithProgressWindow ( )

Destructor.

Member Function Documentation

◆ getAlertWindow()

AlertWindow* ThreadWithProgressWindow::getAlertWindow ( ) const
inlinenoexcept

Returns the AlertWindow that is being used.

◆ launchThread()

void ThreadWithProgressWindow::launchThread ( int  threadPriority = 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
threadPrioritythe priority to use when starting the thread - see Thread::startThread() for values

◆ setProgress()

void 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 ThreadWithProgressWindow::setStatusMessage ( const String newStatusMessage)

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

◆ threadComplete()

void 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.


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