libschauer  0.0.1
Qt based library to access the Docker HTTP API.
Public Types | Properties | Public Member Functions | Public Slots | Signals | Protected Member Functions | List of all members
Schauer::SJob Class Referenceabstract

Base class for all jobs. More...

#include <sjob.h>

Inheritance diagram for Schauer::SJob:
Inheritance graph
[legend]

Public Types

enum  { NoError = 0, KilledJobError = 1, UserDefinedError = 100 }
 Error codes. More...
 
enum  Capability { NoCapabilities = 0x0000, Killable = 0x0001, Suspendable = 0x0002 }
 Job capabilities. More...
 
enum  Unit { Bytes = 0, Files, Directories, Items }
 Describes the unit used in the methods that handle reporting the job progress info. More...
 

Properties

Schauer::SJob::Capabilities capabilities
 Capabilities of this job. More...
 
int error
 Error code. More...
 
QString errorString
 Human-readable error message. More...
 
QString errorText
 Additional error text. More...
 
ulong percent
 Overall progress of the job. More...
 

Public Member Functions

 SJob (QObject *parent=nullptr)
 Stores a combination of Capability values. More...
 
 ~SJob () override
 Desconstructs the SJob obejct. More...
 
Capabilities capabilities () const
 Returns the capabilities of this job. More...
 
int error () const
 Returns the error code, if there has been an error. More...
 
virtual QString errorString () const
 A human-readable error message. More...
 
QString errorText () const
 Returns the error text if there has been an error. More...
 
bool exec ()
 Executes the job synchronously. More...
 
bool isAutoDelete () const
 Returns true if this job automatically deletes itself once the job is finished. More...
 
bool isFinishedNotificationHidden () const
 
bool isSuspended () const
 Returns true if the job was suspended with the suspend() call. More...
 
unsigned long percent () const
 Returns the overall progress of this job. More...
 
Q_SCRIPTABLE qulonglong processedAmount (Unit unit) const
 Returns the processed amount of a given unit for this job. More...
 
void setAutoDelete (bool autodelete)
 Sets the auto-delete property of the job. More...
 
void setFinishedNotificationHidden (bool hide=true)
 
virtual Q_SCRIPTABLE void start ()=0
 Starts the job asynchronously. More...
 
Q_SCRIPTABLE qulonglong totalAmount (Unit unit) const
 Returns the total amount of a given unit for this job. More...
 

Public Slots

bool kill (Schauer::SJob::KillVerbosity verbosity=Quietly)
 Aborts this job. More...
 
bool resume ()
 Resumes this job. More...
 
bool suspend ()
 Suspends this job. More...
 

Signals

void description (Schauer::SJob *job, const QString &title, const QPair< QString, QString > &field1=QPair< QString, QString >(), const QPair< QString, QString > &field2=QPair< QString, QString >())
 Emitted to display general description of this job. More...
 
void finished (Schauer::SJob *job)
 Emitted when the job is finished, in any case. More...
 
void infoMessage (Schauer::SJob *job, const QString &plain, const QString &rich=QString())
 Emitted to display state information about this job. More...
 
void percent (Schauer::SJob *job, unsigned long percent)
 Progress signal showing the overall progress of the job This is valid for any kind of job, and allows using a a progress bar very easily. More...
 
void percentChanged (Schauer::SJob *job, unsigned long percent)
 Progress signal showing the overall progress of the job This is valid for any kind of job, and allows using a a progress bar very easily. More...
 
void processedAmount (Schauer::SJob *job, SJob::Unit unit, qulonglong amount)
 Regularly emitted to show the progress of this job by giving the current amount. More...
 
void processedAmountChanged (Schauer::SJob *job, SJob::Unit unit, qulonglong amount)
 Regularly emitted to show the progress of this job by giving the current amount. More...
 
void processedSize (Schauer::SJob *job, qulonglong size)
 Regularly emitted to show the progress of this job (current data size in bytes for transfers, entries listed, etc.). More...
 
void result (Schauer::SJob *job)
 Emitted when the job is finished (except when killed with SJob::Quietly). More...
 
void resumed (Schauer::SJob *job)
 Emitted when the job is resumed. More...
 
void speed (Schauer::SJob *job, unsigned long speed)
 Emitted to display information about the speed of this job. More...
 
void suspended (Schauer::SJob *job)
 Emitted when the job is suspended. More...
 
void totalAmount (Schauer::SJob *job, SJob::Unit unit, qulonglong amount)
 Emitted when we know the amount the job will have to process. More...
 
void totalAmountChanged (Schauer::SJob *job, SJob::Unit unit, qulonglong amount)
 Emitted when we know the amount the job will have to process. More...
 
void totalSize (Schauer::SJob *job, qulonglong size)
 Emitted when we know the size of this job (data size in bytes for transfers, number of entries for listings, etc). More...
 
void warning (Schauer::SJob *job, const QString &plain, const QString &rich=QString())
 Emitted to display a warning about this job. More...
 

Protected Member Functions

virtual bool doKill ()
 Aborts this job quietly. More...
 
virtual bool doResume ()
 Resumes this job. More...
 
virtual bool doSuspend ()
 Suspends this job. More...
 
void emitPercent (qulonglong processedAmount, qulonglong totalAmount)
 Utility function for inherited jobs. More...
 
void emitResult ()
 Utility function to emit the result signal, and suicide this job. More...
 
void emitSpeed (unsigned long speed)
 Utility function for inherited jobs. More...
 
bool isFinished () const
 Returns true if the job has been finished and has emitted the finished() signal. More...
 
void setCapabilities (Capabilities capabilities)
 Sets the capabilities for this job. More...
 
void setError (int errorCode)
 Sets the error code. More...
 
void setErrorText (const QString &errorText)
 Sets the error text. More...
 
void setPercent (unsigned long percentage)
 Sets the overall progress of the job. More...
 
void setProcessedAmount (Unit unit, qulonglong amount)
 Sets the processed size. More...
 
void setProgressUnit (Unit unit)
 Sets the unit that will be used internally to calculate the progress percentage. More...
 
void setTotalAmount (Unit unit, qulonglong amount)
 Sets the total size. More...
 

Detailed Description

Base class for all jobs.

This is a reimplementation of KJob from KDE Frameworks’ KCoreAddons, it is meant for platforms and systems where KJob is not available. If KCoreAddons are available, you should build libschauer with cmake -DWITH_KDE to use the original KJob implementation.

Todo:
Hide deprecated stuff behind preprocessor macro.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Error codes.

Enumerator
NoError 

Indicates there is no error.

KilledJobError 

Indicates the job was killed.

UserDefinedError 

Subclasses should define error codes starting at this value.

◆ Capability

Job capabilities.

Enumerator
NoCapabilities 

None of the capabilities exist.

Killable 

The job can be killed.

Suspendable 

The job can be suspended.

◆ Unit

Describes the unit used in the methods that handle reporting the job progress info.

See also
totalAmount()
Enumerator
Bytes 

Directory and file sizes in bytes.

Files 

The number of files handled by the job.

Directories 

The number of directories handled by the job.

Items 

The number of items (e.g. both directories and files) handled by the job.

Property Documentation

◆ capabilities

SJob::Capabilities SJob::capabilities
read

Capabilities of this job.

Access functions

◆ error

int SJob::error
read

Error code.

This property holds the error code after finishing the job. If no error has occured, the error code will be 0.

Access functions
Notifier signal
See also
SJob::errorString, SJob::errorText

◆ errorString

QString SJob::errorString
read

Human-readable error message.

This property holds a translated, human-readable description of the error.

Access functions
Notifier signal
See also
SJob::error, SJob::errorText

◆ errorText

QString SJob::errorText
read

Additional error text.

This property holds additional error text, usually some extra data associated with the error, such as a URL.

Access functions
Notifier signal
See also
SJob::error, SJob::errorString

◆ percent

unsigned long SJob::percent
read

Overall progress of the job.

Access functions
Notifier signal

Constructor & Destructor Documentation

◆ SJob()

SJob::SJob ( QObject parent = nullptr)
explicit

Stores a combination of Capability values.

Constructs a new SJob object with the given parent.

◆ ~SJob()

SJob::~SJob ( )
override

Desconstructs the SJob obejct.

Member Function Documentation

◆ capabilities()

Capabilities Schauer::SJob::capabilities ( ) const

Returns the capabilities of this job.

See also
setCapabilities()

◆ description

void Schauer::SJob::description ( Schauer::SJob job,
const QString title,
const QPair< QString, QString > &  field1 = QPairQStringQString >(),
const QPair< QString, QString > &  field2 = QPairQStringQString >() 
)
signal

Emitted to display general description of this job.

A description has a title and tow optional fields which can be used to complete the description.

Examples of titles are “Copying“, “Creating resource”, etc. The fields of the description can be “Source“ with an URL and “Destination“ with an URL for a “Copying“ description.

Parameters
jobthe job that emitted the signal
titlethe general description of the job
field1first field (localized name and value)
field2second field (localized name and value)

◆ doKill()

bool SJob::doKill ( )
protectedvirtual

Aborts this job quietly.

This simply kills the job, no error reporting or job deletion should be involved. The default implementation does nothing and returns false.

See also
kill()
Returns
true if the operation is supported and succeedd, false otherwise.

◆ doResume()

bool SJob::doResume ( )
protectedvirtual

Resumes this job.

The default implementation does nothing and returns false.

See also
resume(), resumed()
Returns
true if the operation is supported and succeeded, false otherwise.

◆ doSuspend()

bool SJob::doSuspend ( )
protectedvirtual

Suspends this job.

The default implementation does nothing and returns false.

See also
suspend(), suspended()
Returns
true if the operation is supported and succeeded, false otherwise.

◆ emitPercent()

void SJob::emitPercent ( qulonglong  processedAmount,
qulonglong  totalAmount 
)
protected

Utility function for inherited jobs.

Emits the percent signal if bigger than previous value, after calculating it from the parameters.

See also
percent()
Parameters
processedAmountthe processed amount
totalAmountthe total amount

◆ emitResult()

void SJob::emitResult ( )
protected

Utility function to emit the result signal, and suicide this job.

It first notifies the observers to hide the progress for this job using the finished() signal.

Note
Deletes this job using deleteLater().
See also
result(), finished()

◆ emitSpeed()

void SJob::emitSpeed ( unsigned long  speed)
protected

Utility function for inherited jobs.

Emits the speed signal and starts the timer for removing that info

Parameters
speedthe speed in bytes/s

◆ error()

int Schauer::SJob::error ( ) const

Returns the error code, if there has been an error.

Only call this method from the slot connected to result(). If there has been no error, 0 will be returned.

◆ errorString()

virtual QString Schauer::SJob::errorString ( ) const
virtual

A human-readable error message.

This provides a translated, human-readable description of the error. Only call if error is not 0.

Subclasses should implement this to create a translated error message from the error code and error text. For example:

if (error() == ReadFailed) {
tr("Could not read \"%1\"", errorText());
}

Reimplemented in Schauer::Job.

◆ errorText()

QString Schauer::SJob::errorText ( ) const

Returns the error text if there has been an error.

Only call if error is not 0.

This is usually some extra data associated with the error, such as a URL. Use errorString() to get a human-readable, translated message.

◆ exec()

bool SJob::exec ( )

Executes the job synchronously.

This will start a nested QEventLoop internally. Nested event loop can be dangerous and can have unintended side effects, you should avoid calling exec() whenever you can and use the asynchronous interface of SJob instead.

Should you indeed call this method, you need to make sure that all callers are reentrant, so that events delivered by the inner event loop don't cause non-reentrant functions to be called, which usually wreaks havoc.

Note that the event loop started by this method does not process user input events, which means your user interface will effectively be blocked. Other events like paint or network events are still being processed. The advantage of not processing user input events is that the chance of accidental reentrance is greatly reduced. Still you should avoid calling this function.

Returns if the job has been executed without eror, false otherwise.

◆ finished

void Schauer::SJob::finished ( Schauer::SJob job)
signal

Emitted when the job is finished, in any case.

It is used to notify observers that the job is terminated and that progress can be hidden.

Note
This is a private signal, it can’t be emitted directly by subclasses of SJob, use emitResult() instead.

In general, to be notified of a job’s completion, client code should connect to result() rather than finished(), so that kill(Quietly) is indeed quiet. However if you store a list of jobs and they might get killed silently, then you must connect to this instead of result(), to avoid dangling pointers in your list.

See also
result()
Parameters
jobthe job that emitted this signal

◆ infoMessage

void Schauer::SJob::infoMessage ( Schauer::SJob job,
const QString plain,
const QString rich = QString() 
)
signal

Emitted to display state information about this job.

Examples of message are “Resolving host”, “Connecting to host...”, etc.

Parameters
jobthe job that emitted this signal
plainthe info message
richthe rich text version of the message, or QString() if none is available

◆ isAutoDelete()

bool SJob::isAutoDelete ( ) const

Returns true if this job automatically deletes itself once the job is finished.

See also
setAutoDelete()

◆ isFinished()

bool SJob::isFinished ( ) const
protected

Returns true if the job has been finished and has emitted the finished() signal.

◆ isFinishedNotificationHidden()

bool SJob::isFinishedNotificationHidden ( ) const

Whether to not show a finished notification when a job's finished signal is emitted.

See also
setFinishedNotificationHidden()

◆ isSuspended()

bool SJob::isSuspended ( ) const

Returns true if the job was suspended with the suspend() call.

See also
suspend(), resume()

◆ kill

bool SJob::kill ( Schauer::SJob::KillVerbosity  verbosity = Quietly)
slot

Aborts this job.

This kills and deletes the job.

Parameters
verbosityif equals to EmitResult, job will emit signal result() and ask uiserver to close the progress window. verbosity is set to EmitResult for subjobs. Whether applications should call with Quietly or EmitResult depends on whether they rely on result being emitted or not. Please notice that if verbosity is set to Quietly, signal result will NOT be emitted.
Returns
true if the operation is supported and succeeded, false otherwise

◆ percent() [1/2]

unsigned long Schauer::SJob::percent ( ) const

Returns the overall progress of this job.

◆ percent [2/2]

void Schauer::SJob::percent ( Schauer::SJob job,
unsigned long  percent 
)
signal

Progress signal showing the overall progress of the job This is valid for any kind of job, and allows using a a progress bar very easily.

Note
This is a private signal, it shouldn’t be emitted directly by subclasses of SJob, use emitPercent(), setPercent(), setTotalAmount() or setProcessedAmount() instead.
Parameters
jobthe job that emitted this signal
percentthe percentage
Deprecated:
use the SJob::percentChanged(Schauer::SJob *job, unsigned long percent) signal

◆ percentChanged

void Schauer::SJob::percentChanged ( Schauer::SJob job,
unsigned long  percent 
)
signal

Progress signal showing the overall progress of the job This is valid for any kind of job, and allows using a a progress bar very easily.

Note
This is a private signal, it shouldn’t be emitted directly by subclasses of SJob, use emitPercent(), setPercent(), setTotalAmount() or setProcessedAmount() instead.
Parameters
jobthe job that emitted this signal
percentthe percentage

◆ processedAmount() [1/2]

qulonglong SJob::processedAmount ( Unit  unit) const

Returns the processed amount of a given unit for this job.

Parameters
unitthe unit of the requested amount

◆ processedAmount [2/2]

void Schauer::SJob::processedAmount ( Schauer::SJob job,
SJob::Unit  unit,
qulonglong  amount 
)
signal

Regularly emitted to show the progress of this job by giving the current amount.

The unit of this amount is sent too. It can be emitted several times if the job manages several different units.

Note
This is a private signal, it shouldn’t be emitted directly by subclasses of SJob, use setProcessedAmount() instead.
Parameters
jobthe job that emitted this signal
unitthe unit of the processed amount
amountthe processed amount
Deprecated:
use the SJob::processedAmountChanged(Schauer::SJob *job, SJob::Unit unit, qulonglong amount) signal

◆ processedAmountChanged

void Schauer::SJob::processedAmountChanged ( Schauer::SJob job,
SJob::Unit  unit,
qulonglong  amount 
)
signal

Regularly emitted to show the progress of this job by giving the current amount.

The unit of this amount is sent too. It can be emitted several times if the job manages several different units.

Note
This is a private signal, it shouldn’t be emitted directly by subclasses of SJob, use setProcessedAmount() instead.
Parameters
jobthe job that emitted this signal
unitthe unit of the processed amount
amountthe processed amount

◆ processedSize

void Schauer::SJob::processedSize ( Schauer::SJob job,
qulonglong  size 
)
signal

Regularly emitted to show the progress of this job (current data size in bytes for transfers, entries listed, etc.).

Note
This is a private signal, it shouldn’t be emitted directly by subclasses of SJob, use setProcessedAmount() instead.
Parameters
jobthe job that emitted this signal
sizethe processed size

◆ result

void Schauer::SJob::result ( Schauer::SJob job)
signal

Emitted when the job is finished (except when killed with SJob::Quietly).

Use error() to know if the job was finished with error.

Note
This is a private signal, it can’t be emitted directly by subclasses of SJob, use emitResult() instead.

Please connect to this signal instead of finished.

See also
kill()
Parameters
jobthe job that emitted this signal

◆ resume

bool SJob::resume ( )
slot

Resumes this job.

See also
resumed(), doResume()
Returns
true if the operation is supported and succeeded, false otherwise.

◆ resumed

void Schauer::SJob::resumed ( Schauer::SJob job)
signal

Emitted when the job is resumed.

Note
This is a private signal, it can’t be emitted directly by subclasses of SJob.
See also
resume(), doResume()
Parameters
jobthe job that emitted this signal

◆ setAutoDelete()

void SJob::setAutoDelete ( bool  autodelete)

Sets the auto-delete property of the job.

If autodelete is set to false the job will not delete itself once it is finished.

The default for any SJob is to automatically delete itself.

See also
isAutoDelete()

◆ setCapabilities()

void SJob::setCapabilities ( Capabilities  capabilities)
protected

Sets the capabilities for this job.

See also
capabilities()
Parameters
capabilitiesthe capabilities supported by this job

◆ setError()

void SJob::setError ( int  errorCode)
protected

Sets the error code.

It should be called when an error is encountered in the job, just before calling emitResult().

You should define an (anonymous) enum of error codes, with values starting at SJob::UserDefinedError, and use those. For example:

enum {
InvalidFoo = SJob::UserDefinedError,
BarNotFound
}
Parameters
errorCode

◆ setErrorText()

void SJob::setErrorText ( const QString errorText)
protected

Sets the error text.

It should be called when an error is encountered in the job, just before calling emitResult().

Provides extra information about the error that cannot be determined directly from the error code. For example, a URL or filename. This string is not normally translatable.

See also
errorString(), setError()
Parameters
errorTextthe error text

◆ setFinishedNotificationHidden()

void SJob::setFinishedNotificationHidden ( bool  hide = true)

This method can be used to indicate to classes listening to signals from a job that they should ideally show a progress bar, but not a finished notification.

For example when opening a remote URL, a job will emit the progress of the download, which can be used to show a progress dialog or a Plasma notification, then when the job is done it'll emit e.g. the finished signal. Showing the user the progress dialog is useful, however the dialog/notification about the download being finished isn't of much interest, because the user can see the application that invoked the job opening the actual file that was downloaded.

◆ setPercent()

void SJob::setPercent ( unsigned long  percentage)
protected

Sets the overall progress of the job.

The percent() signal is emitted if the value changed.

The job takes care of this if you call setProcessedAmount in Bytes (or the unit set by setProgressUnit). This method allows you to set your own progress, as an alternative.

Parameters
percentagethe new overall progress

◆ setProcessedAmount()

void SJob::setProcessedAmount ( Unit  unit,
qulonglong  amount 
)
protected

Sets the processed size.

The processedAmount() and percent() signals are emitted if the values changed. The percent() signal is emitted only for the progress unit.

Parameters
unitthe unit of the new processed amount
amountthe new processed amount

◆ setProgressUnit()

void SJob::setProgressUnit ( Unit  unit)
protected

Sets the unit that will be used internally to calculate the progress percentage.

The default progress unit is Bytes.

Parameters
unitthe unit that will be used

◆ setTotalAmount()

void SJob::setTotalAmount ( Unit  unit,
qulonglong  amount 
)
protected

Sets the total size.

The totalSize() and percent() signals are emitted if the values changed. The percent() signal is emitted only for the progress unit.

Parameters
unitthe unit of the new total amount
amountthe new total amount

◆ speed

void Schauer::SJob::speed ( Schauer::SJob job,
unsigned long  speed 
)
signal

Emitted to display information about the speed of this job.

Note
This is a private signal, it shouldn’t be emitted directly by subclasses of SJob, use emitSpeed() instead.
Parameters
jobthe job that emitted this signal
speedthe speed in bytes/s

◆ start()

virtual Q_SCRIPTABLE void Schauer::SJob::start ( )
pure virtual

Starts the job asynchronously.

When the job is finished, result() is emitted.

Warning
Never implement any synchronous workload in this method. This method should just trigger the job startup, not do any work itself. It is expected to be non-blocking.

This is the method all subclasses need to implement. It should setup and trigger the workload of the job. It should not do any work itself. This includes all signals and terminating the job, e.g. by emitResult(). The workload, which could be another method of the subclass, is to be triggered using the event loop, e.g. by code like:

void ExampleJob::start()
{
QTimer:singleShot(0, this, &ExampleJob::doWork);
}

Implemented in Schauer::CreateExecInstanceJob, Schauer::StartExecInstanceJob, Schauer::ListContainersJob, Schauer::RemoveContainerJob, Schauer::ListImagesJob, Schauer::StartContainerJob, Schauer::CreateContainerJob, Schauer::StopContainerJob, and Schauer::GetVersionJob.

◆ suspend

bool SJob::suspend ( )
slot

Suspends this job.

The job should be kept in a state in which it is possible to resume it.

See also
suspended(), doSuspend()
Returns
true if the operation is supported and succeeded, false otherwise

◆ suspended

void Schauer::SJob::suspended ( Schauer::SJob job)
signal

Emitted when the job is suspended.

Note
This is a private signal, it can’t be emitted directly by subclasses of SJob.
See also
suspend(), doSuspend()
Parameters
jobthe job that emitted this signal

◆ totalAmount() [1/2]

qulonglong SJob::totalAmount ( Unit  unit) const

Returns the total amount of a given unit for this job.

Parameters
unitthe unit of the requested amount

◆ totalAmount [2/2]

void Schauer::SJob::totalAmount ( Schauer::SJob job,
SJob::Unit  unit,
qulonglong  amount 
)
signal

Emitted when we know the amount the job will have to process.

The unit of this amount is sent too. It can be emitted several times if the job manages several different units.

Note
This is a private signal, it shouldn’t be emitted directly by subclasses of SJob, use setTotalAmount() instead.
Parameters
jobthe job that emitted this signal
unitthe unit of the total amount
amountthe total amount
Deprecated:
use the SJob::totalAmountChanged(Schauer::SJob *job, SJob::Unit unit, qulonglong amount) signal

◆ totalAmountChanged

void Schauer::SJob::totalAmountChanged ( Schauer::SJob job,
SJob::Unit  unit,
qulonglong  amount 
)
signal

Emitted when we know the amount the job will have to process.

The unit of this amount is sent too. It can be emitted several times if the job manages several different units.

Note
This is a private signal, it shouldn’t be emitted directly by subclasses of SJob, use setTotalAmount() instead.
Parameters
jobthe job that emitted this signal
unitthe unit of the total amount
amountthe total amount

◆ totalSize

void Schauer::SJob::totalSize ( Schauer::SJob job,
qulonglong  size 
)
signal

Emitted when we know the size of this job (data size in bytes for transfers, number of entries for listings, etc).

Note
This is a private signal, it shouldn’t be emitted directly by subclasses of SJob, use setTotalAmount() instead.
Parameters
jobthe job that emitted this signal
sizethe total size

◆ warning

void Schauer::SJob::warning ( Schauer::SJob job,
const QString plain,
const QString rich = QString() 
)
signal

Emitted to display a warning about this job.

Parameters
jobthe job that emitted this signal
plainthe warning message
richthe rich text version of the message, or QString() is none is available

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