KGAPI2::Job

#include <job.h>

Inheritance diagram for KGAPI2::Job:

Properties

bool isRunning
 
int maxTimeout
 
- Properties inherited from QObject
 objectName
 

Signals

void finished (KGAPI2::Job *job)
 
void progress (KGAPI2::Job *job, int processed, int total)
 

Public Member Functions

 Job (QObject *parent=nullptr)
 
 Job (const AccountPtr &account, QObject *parent=nullptr)
 
 ~Job () override
 
AccountPtr account () const
 
KGAPI2::Error error () const
 
QString errorString () const
 
QStringList fields () const
 
bool isRunning () const
 
int maxTimeout () const
 
bool prettyPrint () const
 
void restart ()
 
void setAccount (const AccountPtr &account)
 
void setFields (const QStringList &fields)
 
void setMaxTimeout (int maxTimeout)
 
void setPrettyPrint (bool prettyPrint)
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
bool blockSignals (bool block)
 
const QObjectListchildren () const const
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectInfo ()
 
void dumpObjectInfo () const const
 
void dumpObjectTree ()
 
void dumpObjectTree () const const
 
QList< QByteArraydynamicPropertyNames () const const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegExp &regExp, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
bool inherits (const char *className) const const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const const
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
QVariant property (const char *name) const const
 
 Q_CLASSINFO (Name, Value)
 
 Q_DISABLE_COPY (Class)
 
 Q_DISABLE_COPY_MOVE (Class)
 
 Q_DISABLE_MOVE (Class)
 
 Q_EMIT Q_EMIT
 
 Q_ENUM (...)
 
 Q_ENUM_NS (...)
 
 Q_ENUMS (...)
 
 Q_FLAG (...)
 
 Q_FLAG_NS (...)
 
 Q_FLAGS (...)
 
 Q_GADGET Q_GADGET
 
 Q_INTERFACES (...)
 
 Q_INVOKABLE Q_INVOKABLE
 
 Q_NAMESPACE Q_NAMESPACE
 
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 
 Q_OBJECT Q_OBJECT
 
 Q_PROPERTY (...)
 
 Q_REVISION Q_REVISION
 
 Q_SET_OBJECT_NAME (Object)
 
 Q_SIGNAL Q_SIGNAL
 
 Q_SIGNALS Q_SIGNALS
 
 Q_SLOT Q_SLOT
 
 Q_SLOTS Q_SLOTS
 
qFindChild (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QRegExp &regExp)
 
QList< T > qFindChildren (const QObject *obj, const QString &name)
 
qobject_cast (QObject *object)
 
qobject_cast (const QObject *object)
 
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const const
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds time, Qt::TimerType timerType)
 
QThreadthread () const const
 

Static Public Member Functions

static QString buildSubfields (const QString &field, const QStringList &fields)
 
- Static Public Member Functions inherited from QObject
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 

Protected Member Functions

virtual void aboutToFinish ()
 
virtual void aboutToStart ()
 
virtual void dispatchRequest (QNetworkAccessManager *accessManager, const QNetworkRequest &request, const QByteArray &data, const QString &contentType)=0
 
virtual void emitFinished ()
 
virtual void emitProgress (int processed, int total)
 
virtual void enqueueRequest (const QNetworkRequest &request, const QByteArray &data=QByteArray(), const QString &contentType=QString())
 
virtual void handleReply (const QNetworkReply *reply, const QByteArray &rawData)=0
 
void setError (KGAPI2::Error error)
 
void setErrorString (const QString &errorString)
 
virtual void start ()=0
 
- Protected Member Functions inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
int receivers (const char *signal) const const
 
QObjectsender () const const
 
int senderSignalIndex () const const
 
virtual void timerEvent (QTimerEvent *event)
 

Additional Inherited Members

- Public Attributes inherited from QObject
typedef QObjectList
 

Detailed Description

Abstract base class for all jobs in LibKGAPI.

Usual workflow of Job subclasses is to reimplement Job::start, Job::dispatchRequest and Job::handleReply, then enqueue a QNetworkRequest using Job::enqueueRequest. Authorization headers and standard query parameters will be set by Job class. The request will automatically be scheduled in a queue and dispatched by calling Job::dispatchRequest implementation. When a reply is received, the Job will automatically perform error handling and if there is no error, the reply is passed to implementation of Job::handleReply.

Job is automatically started when program enters an event loop.

Author
Daniel Vrátil dvrat[email protected][email protected][email protected]edhat[email protected].com
Since
2.0

Definition at line 41 of file job.h.

Property Documentation

bool Job::isRunning
read

Whether the job is running.

This property indicates whether the job is running or not. The value is set to true when the job is started (see Job::start) and back to false right before Job::finished is emitted.

See also
Job::isRunning, Job::finished

Definition at line 68 of file job.h.

int Job::maxTimeout
readwrite

Maximum interval between requests.

Some Google APIs have a quota on maximum amount of requests per account per second. When this quota is exceeded, the Job will automatically increase the interval between dispatching requests, wait for a while and then try again. If however the interval is increased over maxTimeout, the job will fail and finish immediately. By default maxTimeout is -1, which allows the interval to be increased indefinitely.

See also
Job::maxTimeout, Job::setMaxTimeout

Definition at line 57 of file job.h.

Constructor & Destructor Documentation

Job::Job ( QObject parent = nullptr)
explicit

Constructor for jobs that don't require authentication.

Parameters
parent

Definition at line 353 of file job.cpp.

Job::Job ( const AccountPtr account,
QObject parent = nullptr 
)
explicit

Constructor for jobs that require authentication.

Parameters
accountAccount to use to authenticate the requests send by this job
parent
See also
Job::Account, Job::setAccount

Definition at line 360 of file job.cpp.

Job::~Job ( )
override

Destructor.

Definition at line 370 of file job.cpp.

Member Function Documentation

void Job::aboutToFinish ( )
protectedvirtual

This method is invoked right before finished() is emitted.

Subclasses can reimplement this method to do a final cleanup before the Job::finished() signal is emitted.

Note
Note that after Job::finished() the job is not running anymore and therefore the job should not modify any data accessible by user.

Definition at line 519 of file job.cpp.

void Job::aboutToStart ( )
protectedvirtual

This method is invoked right before Job::start() is called.

Subclasses should reset their internal state and call parent implementation.

Reimplemented in KGAPI2::ModifyJob, KGAPI2::FetchJob, and KGAPI2::CreateJob.

Definition at line 523 of file job.cpp.

AccountPtr Job::account ( ) const

Returns account used to authenticate requests.

For jobs that don't require authentication, this method returns a null pointer.

Returns
Am Account or a null pointer when no account was set.

Definition at line 425 of file job.cpp.

virtual void KGAPI2::Job::dispatchRequest ( QNetworkAccessManager accessManager,
const QNetworkRequest request,
const QByteArray data,
const QString contentType 
)
protectedpure virtual

Dispatches request via accessManager.

Because different types of request require different HTTP method to be used, subclasses must reimplement this method and use respective HTTP method to send the request via accessManager.

Parameters
accessManagerQNetworkAccessManager used to dispatch the request
requestRequest to dispatch
dataData to sent in the body of the request
contentTypeContent-Type of data

Implemented in KGAPI2::Drive::FileAbstractResumableJob, KGAPI2::TaskMoveJob, KGAPI2::EventMoveJob, KGAPI2::AuthJob, KGAPI2::ModifyJob, KGAPI2::ContactModifyJob, KGAPI2::FetchJob, KGAPI2::ContactCreateJob, KGAPI2::CreateJob, and KGAPI2::DeleteJob.

void Job::emitFinished ( )
protectedvirtual

Emits Job::finished() signal.

Subclasses should always use this method instead of directly emitting Job::finished().

Definition at line 479 of file job.cpp.

void Job::emitProgress ( int  processed,
int  total 
)
protectedvirtual

Emit progress() signal.

Subclasses should always use this method instead of directly emitting Job::progress().

Parameters
processedAmount of already processed items
totalTotal amount of items to process

Definition at line 492 of file job.cpp.

void Job::enqueueRequest ( const QNetworkRequest request,
const QByteArray data = QByteArray(),
const QString contentType = QString() 
)
protectedvirtual

Enqueues request in dispatcher queue.

Subclasses should call this method to enqueue the request in main job queue. The request is automatically dispatched, and reply is handled. Authorization headers and standards query parameters will be applied.

Parameters
requestRequest to enqueue
dataData to be send in body of the request
contentTypeContent type of data

Definition at line 497 of file job.cpp.

Error Job::error ( ) const

Error code.

This method can only be called after the job has emitted Job::finished signal. Calling this method on a running job will always return KGAPI2::NoError.

Returns
Returns code of occurred error or KGAPI2::NoError when no error has occurred.

Definition at line 380 of file job.cpp.

QString Job::errorString ( ) const

Error string.

This method can only be called after the job has emitted Job::finished signal. Calling this method on a running job will always return an empty string.

Returns
Returns localized description of error or an empty string if no error has occurred.

Definition at line 395 of file job.cpp.

QStringList Job::fields ( ) const

Returns fields selector.

Returns
List of fields

Definition at line 455 of file job.cpp.

void KGAPI2::Job::finished ( KGAPI2::Job job)
signal

Emitted when job has finished.

The signal is emitted every time, no matter whether the job is successful or an error has occurred.

Subclasses should never ever emit this signal directly. Use Job::emitFinished instead.

Parameters
jobThe job that has finished
See also
emitFinished()
virtual void KGAPI2::Job::handleReply ( const QNetworkReply reply,
const QByteArray rawData 
)
protectedpure virtual

Called when a reply is received.

Sublcasses must reimplement this method to handle reply content.

Parameters
replyA reply received from server
rawDataRaw content of the reply. Don't use QNetworkReply::readAll, because this method has already been called by Job and thus it would return nothing.

Implemented in KGAPI2::Drive::FileAbstractResumableJob, KGAPI2::TaskMoveJob, KGAPI2::TaskDeleteJob, KGAPI2::EventDeleteJob, KGAPI2::ContactsGroupDeleteJob, KGAPI2::TaskListDeleteJob, KGAPI2::ModifyJob, KGAPI2::CalendarDeleteJob, KGAPI2::ContactDeleteJob, KGAPI2::AuthJob, KGAPI2::ContactFetchPhotoJob, KGAPI2::FetchJob, KGAPI2::DeleteJob, and KGAPI2::CreateJob.

bool KGAPI2::Job::isRunning ( ) const

Whether job is running.

A job is considered running from the moment it's started until until Job::finished is emitted. Some methods should not be called when a job is running.

Returns
Returns whether this job is currently running.
See also
start()
int KGAPI2::Job::maxTimeout ( ) const

Maximum quota limit.

Returns
Returns maximum timeout in seconds or -1 if there is no timeout set.
See also
Job::setMaxTimeout
bool Job::prettyPrint ( ) const

Returns prettyPrint query parameter.

Returns
prettyPrint query parameter

Definition at line 440 of file job.cpp.

void KGAPI2::Job::progress ( KGAPI2::Job job,
int  processed,
int  total 
)
signal

Emitted when a job progress changes.

Note that some jobs might not provide progress information, thus this signal will never be emitted.

Parameters
jobThe job that the information relates to
processedAmount of already processed items
totalTotal amount of items to process
void Job::restart ( )

Restarts this job.

When a job finishes, it's possible to run it again, without having to create a new job.

The job will throw away all results retrieved in previous run and retrieve everything again.

See also
Job::aboutToStart

Definition at line 469 of file job.cpp.

void Job::setAccount ( const AccountPtr account)

Set account to be used to authenticate requests.

By default, no account is set and all request are sent without any authentication.

Parameters
accountAccount to use

Definition at line 430 of file job.cpp.

void Job::setError ( KGAPI2::Error  error)
protected

Set job error to error.

Parameters
errorError code to set
See also
Job::error

Definition at line 375 of file job.cpp.

void Job::setErrorString ( const QString errorString)
protected

Set job error description to errorString.

Parameters
errorStringError description to set
See also
Job::errorString

Definition at line 390 of file job.cpp.

void Job::setFields ( const QStringList fields)

Set subset of fields to include in the response.

Use for better performance.

Parameters
fieldsList of fields

Definition at line 460 of file job.cpp.

void Job::setMaxTimeout ( int  maxTimeout)

Set maximum quota timeout.

Sets maximum interval for which the job should wait before trying to submit a request that has previously failed due to exceeded quota.

Default timeout is 1 seconds, then after every failed request the timeout is increased exponentially until reaching maxTimeout.

Parameters
maxTimeoutMaximum timeout (in seconds), or -1 for no timeout

Definition at line 415 of file job.cpp.

void Job::setPrettyPrint ( bool  prettyPrint)

Sets whether response will have indentations and line breaks.

When this is false, it can reduce the response payload size, which might lead to better performance in some environments. Default is false.

Parameters
prettyPrint

Definition at line 445 of file job.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue Oct 27 2020 23:15:07 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.