Task Class

(KDUpdater::Task)

The Task class is the base class for all tasks in KDUpdater. More...

Header: #include <Task>

Public Types

enum Capability { NoCapability, Pausable, Stoppable }

Public Functions

bool autoDelete() const
int capabilities() const
int error() const
QString errorString() const
bool isFinished() const
bool isPaused() const
bool isRunning() const
bool isStopped() const
QString name() const
int progressPercent() const
QString progressText() const
void setAutoDelete(bool autoDelete)

Public Slots

void pause()
void resume()
void run()
void stop()

Signals

void error(int code, const QString &errorText)
void finished()
void paused()
void progressText(const QString &progressText)
void progressValue(int percent)
void resumed()
void started()
void stopped()

Static Public Members

const QMetaObject staticMetaObject

Protected Functions

virtual bool doPause() = 0
virtual bool doResume() = 0
virtual void doRun() = 0
virtual bool doStop() = 0

Detailed Description

The Task class is the base class for all tasks in KDUpdater.

This class is the base class for all task classes in KDUpdater. Task is an activity that occupies certain amount of execution time. It can be started, stopped (or canceled), paused and resumed. Tasks can report progress and error messages which an application can show in any sort of UI. The KDUpdater::Task class provides a common interface for dealing with all kinds of tasks in KDUpdater.

User should be careful of these points:

  • Task classes can be started only once.
  • Instances of this class cannot be created. Only instances of the subclasses can.

Member Type Documentation

enum Task::Capability

This enum value sets the capabilities of the task.

ConstantValueDescription
KDUpdater::Task::NoCapability0The task has no capabilities, so it cannot be paused or stopped.
KDUpdater::Task::Pausable1The task can be paused.
KDUpdater::Task::Stoppable2The task can be stopped.

Member Function Documentation

bool Task::autoDelete() const

Returns true if the task will be automatically deleted.

See also setAutoDelete().

int Task::capabilities() const

Returns the capabilities of the task. It is a combination of one or more Task::Capability flags.

[pure virtual protected] bool Task::doPause()

[pure virtual protected] bool Task::doResume()

[pure virtual protected] void Task::doRun()

[pure virtual protected] bool Task::doStop()

int Task::error() const

Returns the last reported error code.

[signal] void Task::error(int code, const QString &errorText)

Note: Signal error is overloaded in this class. To connect to this signal by using the function pointer syntax, Qt provides a convenient helper for obtaining the function pointer as shown in this example:

 connect(task, QOverload<int, const QString &>::of(&Task::error),
     [=](int code, const QString &errorText){ /* ... */ });

QString Task::errorString() const

Returns the last reported error message text.

[signal] void Task::finished()

bool Task::isFinished() const

Returns whether the task has finished or not.

Note: Stopped (or canceled) tasks are not finished tasks.

bool Task::isPaused() const

Returns whether the task is paused or not.

bool Task::isRunning() const

Returns whether the task has started and is running.

bool Task::isStopped() const

Returns whether the task is stopped or not.

Note: Finished tasks are not stopped classes.

QString Task::name() const

Returns the name of the task.

[slot] void Task::pause()

Pauses the task, provided the task has the Task::Pausable capability.

[signal] void Task::paused()

int Task::progressPercent() const

Returns the progress in percentage made by this task.

QString Task::progressText() const

Returns a string that describes the progress made by this task as a string.

[signal] void Task::progressText(const QString &progressText)

Note: Signal progressText is overloaded in this class. To connect to this signal by using the function pointer syntax, Qt provides a convenient helper for obtaining the function pointer as shown in this example:

 connect(task, QOverload<const QString &>::of(&Task::progressText),
     [=](const QString &progressText){ /* ... */ });

[signal] void Task::progressValue(int percent)

[slot] void Task::resume()

Resumes the task if it was paused.

[signal] void Task::resumed()

[slot] void Task::run()

Starts the task.

void Task::setAutoDelete(bool autoDelete)

Automatically deletes the task if autoDelete is true.

See also autoDelete().

[signal] void Task::started()

[slot] void Task::stop()

Stops the task, provided the task has the Task::Stoppable capability.

Note: Once the task is stopped, it cannot be restarted.

[signal] void Task::stopped()