Public Member Functions

ThreadWithProgressWindow Class Reference

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

Inherits Thread, and Timer.

List of all members.

Public Member Functions

 ThreadWithProgressWindow (const String &windowTitle, bool hasProgressBar, bool hasCancelButton, int timeOutMsWhenCancelling=10000, const String &cancelButtonText="Cancel")
 Creates the thread.
 ~ThreadWithProgressWindow ()
 Destructor.
bool runThread (int threadPriority=5)
 Starts the thread and waits for it to finish.
void setProgress (double newProgress)
 The thread should call this periodically to update the position of the progress bar.
void setStatusMessage (const String &newStatusMessage)
 The thread can call this to change the message that's displayed in the dialog box.
AlertWindowgetAlertWindow () const noexcept
 Returns the AlertWindow that is being used.

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)
        {
        }

        ~MyTask()
        {
        }

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

Constructor & Destructor Documentation

ThreadWithProgressWindow::ThreadWithProgressWindow ( const String windowTitle,
bool  hasProgressBar,
bool  hasCancelButton,
int  timeOutMsWhenCancelling = 10000,
const String cancelButtonText = "Cancel" 
)

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)
ThreadWithProgressWindow::~ThreadWithProgressWindow (  )

Destructor.


Member Function Documentation

bool ThreadWithProgressWindow::runThread ( int  threadPriority = 5 )

Starts the thread and waits for it to finish.

This will start the thread, make the dialog box appear, and wait until either the thread finishes normally, or until the cancel button is pressed.

Before returning, the dialog box will be hidden.

Parameters:
threadPrioritythe priority to use when starting the thread - see Thread::startThread() for values
Returns:
true if the thread finished normally; false if the user pressed cancel
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
void ThreadWithProgressWindow::setStatusMessage ( const String newStatusMessage )

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

AlertWindow* ThreadWithProgressWindow::getAlertWindow (  ) const

Returns the AlertWindow that is being used.


The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines