KGAPI2::Job

Search for usage in LXR

#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 (const AccountPtr &account, QObject *parent=nullptr)
 
 Job (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)
 
QBindable< QStringbindableObjectName ()
 
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 () const const
 
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 QRegularExpression &re, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (Qt::FindChildOptions options) const const
 
bool inherits (const char *className) const const
 
void installEventFilter (QObject *filterObj)
 
bool isQuickItemType () const const
 
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_EMIT Q_EMIT
 
 Q_ENUM (...)
 
 Q_ENUM_NS (...)
 
 Q_ENUMS (...)
 
 Q_FLAG (...)
 
 Q_FLAG_NS (...)
 
 Q_FLAGS (...)
 
 Q_GADGET Q_GADGET
 
 Q_GADGET_EXPORT (EXPORT_MACRO)
 
 Q_INTERFACES (...)
 
 Q_INVOKABLE Q_INVOKABLE
 
 Q_MOC_INCLUDE Q_MOC_INCLUDE
 
 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
 
qobject_cast (const QObject *object)
 
qobject_cast (QObject *object)
 
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setObjectName (QAnyStringView name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool setProperty (const char *name, QVariant &&value)
 
bool signalsBlocked () const const
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds interval, 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 *context, Functor functor, 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)
 
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, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
QString tr (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 bool handleError (int statusCode, const QByteArray &rawData)
 
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 Types 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.nosp@m.il@r.nosp@m.edhat.nosp@m..com
Since
2.0

Definition at line 40 of file job.h.

Property Documentation

◆ isRunning

bool KGAPI2::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 67 of file job.h.

◆ maxTimeout

int KGAPI2::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 56 of file job.h.

Constructor & Destructor Documentation

◆ Job() [1/2]

Job::Job ( QObject * parent = nullptr)
explicit

Constructor for jobs that don't require authentication.

Parameters
parent

Definition at line 365 of file job.cpp.

◆ Job() [2/2]

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 372 of file job.cpp.

◆ ~Job()

Job::~Job ( )
override

Destructor.

Definition at line 381 of file job.cpp.

Member Function Documentation

◆ aboutToFinish()

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 535 of file job.cpp.

◆ aboutToStart()

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::CreateJob, KGAPI2::FetchJob, and KGAPI2::ModifyJob.

Definition at line 539 of file job.cpp.

◆ account()

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 436 of file job.cpp.

◆ buildSubfields()

QString Job::buildSubfields ( const QString & field,
const QStringList & fields )
static

Definition at line 476 of file job.cpp.

◆ dispatchRequest()

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::AuthJob, KGAPI2::CreateJob, KGAPI2::DeleteJob, KGAPI2::Drive::FileAbstractResumableJob, KGAPI2::EventMoveJob, KGAPI2::FetchJob, KGAPI2::ModifyJob, and KGAPI2::TaskMoveJob.

◆ emitFinished()

void Job::emitFinished ( )
protectedvirtual

Emits Job::finished() signal.

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

Definition at line 493 of file job.cpp.

◆ emitProgress()

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 508 of file job.cpp.

◆ enqueueRequest()

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 513 of file job.cpp.

◆ error()

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 391 of file job.cpp.

◆ errorString()

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 406 of file job.cpp.

◆ fields()

QStringList Job::fields ( ) const

Returns fields selector.

Returns
List of fields

Definition at line 466 of file job.cpp.

◆ finished

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

◆ handleError()

bool Job::handleError ( int statusCode,
const QByteArray & rawData )
protectedvirtual

Called when an error occurs.

This allows subclasses to handle error cases that might be specific for their particular API they are implementing. The re-implementation should return true if the error was handled and KGAPI should not perform any more error handling. If the error was not handled, the re-implementation should return false, which is also what the default implementation returns.

Parameters
statusCodeThe status code of the respons.
rawDataRaw data of the server response.
Returns
Returns true when the error was handled by the subclass, false otherwise.

Reimplemented in KGAPI2::EventFetchJob.

Definition at line 549 of file job.cpp.

◆ handleReply()

virtual void KGAPI2::Job::handleReply ( const QNetworkReply * reply,
const QByteArray & rawData )
protectedpure virtual

Called when a reply is received.

Subclasses 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::AuthJob, KGAPI2::CalendarDeleteJob, KGAPI2::CreateJob, KGAPI2::DeleteJob, KGAPI2::Drive::FileAbstractResumableJob, KGAPI2::EventDeleteJob, KGAPI2::FetchJob, KGAPI2::ModifyJob, KGAPI2::TaskDeleteJob, KGAPI2::TaskListDeleteJob, and KGAPI2::TaskMoveJob.

◆ isRunning()

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

Definition at line 416 of file job.cpp.

◆ maxTimeout()

int Job::maxTimeout ( ) const

Maximum quota limit.

Returns
Returns maximum timeout in seconds or -1 if there is no timeout set.
See also
Job::setMaxTimeout

Definition at line 421 of file job.cpp.

◆ prettyPrint()

bool Job::prettyPrint ( ) const

Returns prettyPrint query parameter.

Returns
prettyPrint query parameter

Definition at line 451 of file job.cpp.

◆ progress

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

◆ restart()

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 481 of file job.cpp.

◆ setAccount()

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 441 of file job.cpp.

◆ setError()

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

Set job error to error.

Parameters
errorError code to set
See also
Job::error

Definition at line 386 of file job.cpp.

◆ setErrorString()

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 401 of file job.cpp.

◆ setFields()

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 471 of file job.cpp.

◆ setMaxTimeout()

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 426 of file job.cpp.

◆ setPrettyPrint()

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 456 of file job.cpp.

◆ start()


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:36:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.