KIO::ForwardingWorkerBase

Search for usage in LXR

KIO::ForwardingWorkerBase Class Referenceabstract

#include <KIO/ForwardingWorkerBase>

Inheritance diagram for KIO::ForwardingWorkerBase:

Public Member Functions

 ForwardingWorkerBase (const QByteArray &protocol, const QByteArray &poolSocket, const QByteArray &appSocket)
 
WorkerResult chmod (const QUrl &url, int permissions) override
 
WorkerResult copy (const QUrl &src, const QUrl &dest, int permissions, JobFlags flags) override
 
WorkerResult del (const QUrl &url, bool isfile) override
 
WorkerResult get (const QUrl &url) override
 
WorkerResult listDir (const QUrl &url) override
 
WorkerResult mimetype (const QUrl &url) override
 
WorkerResult mkdir (const QUrl &url, int permissions) override
 
WorkerResult put (const QUrl &url, int permissions, JobFlags flags) override
 
WorkerResult rename (const QUrl &src, const QUrl &dest, JobFlags flags) override
 
WorkerResult setModificationTime (const QUrl &url, const QDateTime &mtime) override
 
WorkerResult stat (const QUrl &url) override
 
WorkerResult symlink (const QString &target, const QUrl &dest, JobFlags flags) override
 
- 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 QRegExp &regExp, 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
 
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 (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 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
 
- Public Member Functions inherited from KIO::WorkerBase
 WorkerBase (const QByteArray &protocol, const QByteArray &poolSocket, const QByteArray &appSocket)
 
void addTemporaryAuthorization (const QString &action)
 
MetaData allMetaData () const
 
virtual void appConnectionMade ()
 
bool cacheAuthentication (const AuthInfo &info)
 
void canResume ()
 
bool canResume (KIO::filesize_t offset)
 
bool checkCachedAuthentication (AuthInfo &info)
 
virtual WorkerResult chown (const QUrl &url, const QString &owner, const QString &group)
 
virtual WorkerResult close ()
 
virtual void closeConnection ()
 
KConfigGroupconfig ()
 
bool configValue (const QString &key, bool defaultValue) const
 
QString configValue (const QString &key, const QString &defaultValue=QString()) const
 
int configValue (const QString &key, int defaultValue) const
 
int connectTimeout ()
 
void connectWorker (const QString &path)
 
void data (const QByteArray &data)
 
void dataReq ()
 
void disconnectWorker ()
 
void dispatchLoop ()
 
void errorPage ()
 
void exit ()
 
virtual WorkerResult fileSystemFreeSpace (const QUrl &url)
 
bool hasMetaData (const QString &key) const
 
void infoMessage (const QString &msg)
 
void listEntries (const UDSEntryList &_entry)
 
void listEntry (const UDSEntry &entry)
 
void lookupHost (const QString &host)
 
QMap< QString, QVariantmapConfig () const
 
int messageBox (const QString &text, MessageBoxType type, const QString &title=QString(), const QString &primaryActionText=QString(), const QString &secondaryActionText=QString(), const QString &dontAskAgainName=QString())
 
int messageBox (MessageBoxType type, const QString &text, const QString &title=QString(), const QString &primaryActionText=QString(), const QString &secondaryActionText=QString())
 
QString metaData (const QString &key) const
 
void mimeType (const QString &_type)
 
virtual WorkerResult multiGet (const QByteArray &data)
 
void needSubUrlData ()
 
virtual WorkerResult open (const QUrl &url, QIODevice::OpenMode mode)
 
virtual WorkerResult openConnection ()
 
int openPasswordDialog (KIO::AuthInfo &info, const QString &errorMsg=QString())
 
void position (KIO::filesize_t _pos)
 
void processedSize (KIO::filesize_t _bytes)
 
int proxyConnectTimeout ()
 
virtual WorkerResult read (KIO::filesize_t size)
 
int readData (QByteArray &buffer)
 
int readTimeout ()
 
void redirection (const QUrl &_url)
 
KRemoteEncodingremoteEncoding ()
 
virtual void reparseConfiguration ()
 
PrivilegeOperationStatus requestPrivilegeOperation (const QString &operationDetails)
 
int responseTimeout ()
 
virtual WorkerResult seek (KIO::filesize_t offset)
 
void sendAndKeepMetaData ()
 
void sendMetaData ()
 
virtual void setHost (const QString &host, quint16 port, const QString &user, const QString &pass)
 
void setIncomingMetaData (const KIO::MetaData &metaData)
 
void setMetaData (const QString &key, const QString &value)
 
void setTimeoutSpecialCommand (int timeout, const QByteArray &data=QByteArray())
 
virtual WorkerResult special (const QByteArray &data)
 
void speed (unsigned long _bytes_per_second)
 
void statEntry (const UDSEntry &_entry)
 
void totalSize (KIO::filesize_t _bytes)
 
virtual WorkerResult truncate (KIO::filesize_t size)
 
void truncated (KIO::filesize_t _length)
 
int waitForAnswer (int expected1, int expected2, QByteArray &data, int *pCmd=nullptr)
 
int waitForHostInfo (QHostInfo &info)
 
void warning (const QString &msg)
 
bool wasKilled () const
 
virtual void worker_status ()
 
void workerStatus (const QString &host, bool connected)
 
virtual WorkerResult write (const QByteArray &data)
 
void written (KIO::filesize_t _bytes)
 

Protected Types

enum  UDSEntryCreationMode { UDSEntryCreationInStat, UDSEntryCreationInListDir }
 

Protected Member Functions

virtual void adjustUDSEntry (KIO::UDSEntry &entry, UDSEntryCreationMode creationMode) const
 
QUrl processedUrl () const
 
QUrl requestedUrl () const
 
virtual bool rewriteUrl (const QUrl &url, QUrl &newURL)=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 KIO::WorkerBase
enum  ButtonCode {
  Ok = 1, Cancel = 2, PrimaryAction = 3, SecondaryAction = 4,
  Continue = 5, Yes = PrimaryAction, No = SecondaryAction
}
 
enum  MessageBoxType {
  QuestionTwoActions = 1, WarningTwoActions = 2, WarningContinueCancel = 3, WarningTwoActionsCancel = 4,
  Information = 5, SSLMessageBox = 6, WarningContinueCancelDetailed = 10, QuestionYesNo = QuestionTwoActions,
  WarningYesNo = WarningTwoActions, WarningYesNoCancel = WarningTwoActionsCancel
}
 
- Properties inherited from QObject
 objectName
 
- 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)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 
- Public Attributes inherited from QObject
typedef QObjectList
 

Detailed Description

This class should be used as a base for KIO workers acting as a forwarder to other KIO workers. It has been designed to support only local filesystem like KIO workers.

If the resulting KIO worker should be a simple proxy, you only need to implement the ForwardingWorkerBase::rewriteUrl() method.

For more advanced behavior, the classic KIO worker methods should be reimplemented, because their default behavior in this class is to forward using the ForwardingWorkerBase::rewriteUrl() method.

A possible code snippet for an advanced stat() behavior would look like this in the child class:

WorkerResult ChildProtocol::stat(const QUrl &url)
{
bool is_special = false;
// Process the URL to see if it should have
// a special treatment
if (is_special) {
// Handle the URL ourselves
// Fill entry with values
statEntry(entry);
}
// Setup the KIO worker internal state if
// required by ChildProtocol::rewriteUrl()
}

Of course in this case, you surely need to reimplement listDir() and get() accordingly.

If you want view on directories to be correctly refreshed when something changes on a forwarded URL, you'll need a companion kded module to emit the KDirNotify Files*() D-Bus signals.

See also
ForwardingWorkerBase::rewriteUrl()
Author
Kevin Ottens ervin[email protected]@ips[email protected]quad.[email protected]net
Since
5.101

Definition at line 72 of file forwardingworkerbase.h.

Member Enumeration Documentation

◆ UDSEntryCreationMode

Enumerator
UDSEntryCreationInStat 

The entry is created during a stat operation.

UDSEntryCreationInListDir 

The entry is created during a listDir operation.

Definition at line 108 of file forwardingworkerbase.h.

Member Function Documentation

◆ adjustUDSEntry()

void KIO::ForwardingWorkerBase::adjustUDSEntry ( KIO::UDSEntry entry,
UDSEntryCreationMode  creationMode 
) const
protectedvirtual

Adjusts a UDSEntry before it's sent in the reply to the KIO worker endpoint.

This is the default implementation working in most cases, but sometimes you could make use of more forwarding black magic (for example dynamically transform any desktop file into a fake directory...)

Parameters
entrythe UDSEntry to adjust
creationModethe operation for which this entry is created

Definition at line 98 of file forwardingworkerbase.cpp.

◆ chmod()

WorkerResult KIO::ForwardingWorkerBase::chmod ( const QUrl url,
int  permissions 
)
overridevirtual

Change permissions on url.

The worker emits ERR_DOES_NOT_EXIST or ERR_CANNOT_CHMOD

Reimplemented from KIO::WorkerBase.

Definition at line 260 of file forwardingworkerbase.cpp.

◆ copy()

WorkerResult KIO::ForwardingWorkerBase::copy ( const QUrl src,
const QUrl dest,
int  permissions,
JobFlags  flags 
)
overridevirtual

Copy src into dest.

By default, copy() is only called when copying a file from yourproto://host/path to yourproto://host/otherpath.

If you set copyFromFile=true then copy() will also be called when moving a file from file:///path to yourproto://host/otherpath. Otherwise such a copy would have to be done the slow way (get+put). See also KProtocolManager::canCopyFromFile().

If you set copyToFile=true then copy() will also be called when moving a file from yourproto: to file:. See also KProtocolManager::canCopyToFile().

If the worker returns an error ERR_UNSUPPORTED_ACTION, the job will ask for get + put instead.

If the worker returns an error ERR_FILE_ALREADY_EXIST, the job will ask for a different destination filename.

Parameters
srcwhere to copy the file from (decoded)
destwhere to copy the file to (decoded)
permissionsmay be -1. In this case no special permission mode is set, and the owner and group permissions are not preserved.
flagsWe support Overwrite here

Don't forget to set the modification time of dest to be the modification time of src.

Reimplemented from KIO::WorkerBase.

Definition at line 284 of file forwardingworkerbase.cpp.

◆ del()

WorkerResult KIO::ForwardingWorkerBase::del ( const QUrl url,
bool  isfile 
)
overridevirtual

Delete a file or directory.

Parameters
urlfile/directory to delete
isfileif true, a file should be deleted. if false, a directory should be deleted.

By default, del() on a directory should FAIL if the directory is not empty. However, if metadata("recurse") == "true", then the worker can do a recursive deletion. This behavior is only invoked if the worker specifies deleteRecursive=true in its protocol file.

Reimplemented from KIO::WorkerBase.

Definition at line 302 of file forwardingworkerbase.cpp.

◆ get()

WorkerResult KIO::ForwardingWorkerBase::get ( const QUrl url)
overridevirtual

get, aka read.

Parameters
urlthe full url for this request. Host, port and user of the URL can be assumed to be the same as in the last setHost() call.

The worker should first "emit" the MIME type by calling mimeType(), and then "emit" the data using the data() method.

The reason why we need get() to emit the MIME type is: when pasting a URL in krunner, or konqueror's location bar, we have to find out what is the MIME type of that URL. Rather than doing it with a call to mimetype(), then the app or part would have to do a second request to the same server, this is done like this: get() is called, and when it emits the MIME type, the job is put on hold and the right app or part is launched. When that app or part calls get(), the worker is magically reused, and the download can now happen. All with a single call to get() in the worker. This mechanism is also described in KIO::get().

Reimplemented from KIO::WorkerBase.

Definition at line 156 of file forwardingworkerbase.cpp.

◆ listDir()

WorkerResult KIO::ForwardingWorkerBase::listDir ( const QUrl url)
overridevirtual

Lists the contents of url.

The worker should emit ERR_CANNOT_ENTER_DIRECTORY if it doesn't exist, if we don't have enough permissions. You should not list files if the path in url is empty, but redirect to a non-empty path instead.

Reimplemented from KIO::WorkerBase.

Definition at line 204 of file forwardingworkerbase.cpp.

◆ mimetype()

WorkerResult KIO::ForwardingWorkerBase::mimetype ( const QUrl url)
overridevirtual

Finds MIME type for one file or directory.

This method should either emit 'mimeType' or it should send a block of data big enough to be able to determine the MIME type.

If the worker doesn't reimplement it, a get will be issued, i.e. the whole file will be downloaded before determining the MIME type on it - this is obviously not a good thing in most cases.

Reimplemented from KIO::WorkerBase.

Definition at line 192 of file forwardingworkerbase.cpp.

◆ mkdir()

WorkerResult KIO::ForwardingWorkerBase::mkdir ( const QUrl url,
int  permissions 
)
overridevirtual

Create a directory.

Parameters
urlpath to the directory to create
permissionsthe permissions to set after creating the directory (-1 if no permissions to be set) The worker emits ERR_CANNOT_MKDIR if failure.

Reimplemented from KIO::WorkerBase.

Definition at line 216 of file forwardingworkerbase.cpp.

◆ processedUrl()

QUrl KIO::ForwardingWorkerBase::processedUrl ( ) const
protected

Return the URL being processed by the KIO worker Only access it inside adjustUDSEntry()

Definition at line 146 of file forwardingworkerbase.cpp.

◆ put()

WorkerResult KIO::ForwardingWorkerBase::put ( const QUrl url,
int  permissions,
JobFlags  flags 
)
overridevirtual

put, i.e. write data into a file.

Parameters
urlwhere to write the file
permissionsmay be -1. In this case no special permission mode is set.
flagsWe support Overwrite here. Hopefully, we're going to support Resume in the future, too. If the file indeed already exists, the worker should NOT apply the permissions change to it. The support for resuming using .part files is done by calling canResume().

IMPORTANT: Use the "modified" metadata in order to set the modification time of the file.

See also
canResume()

Reimplemented from KIO::WorkerBase.

Definition at line 168 of file forwardingworkerbase.cpp.

◆ rename()

WorkerResult KIO::ForwardingWorkerBase::rename ( const QUrl src,
const QUrl dest,
JobFlags  flags 
)
overridevirtual

Rename oldname into newname.

If the worker returns an error ERR_UNSUPPORTED_ACTION, the job will ask for copy + del instead.

Important: the worker must implement the logic "if the destination already exists, error ERR_DIR_ALREADY_EXIST or ERR_FILE_ALREADY_EXIST". For performance reasons no stat is done in the destination before hand, the worker must do it.

By default, rename() is only called when renaming (moving) from yourproto://host/path to yourproto://host/otherpath.

If you set renameFromFile=true then rename() will also be called when moving a file from file:///path to yourproto://host/otherpath. Otherwise such a move would have to be done the slow way (copy+delete). See KProtocolManager::canRenameFromFile() for more details.

If you set renameToFile=true then rename() will also be called when moving a file from yourproto: to file:. See KProtocolManager::canRenameToFile() for more details.

Parameters
srcwhere to move the file from
destwhere to move the file to
flagsWe support Overwrite here

Reimplemented from KIO::WorkerBase.

Definition at line 228 of file forwardingworkerbase.cpp.

◆ requestedUrl()

QUrl KIO::ForwardingWorkerBase::requestedUrl ( ) const
protected

Return the URL asked to the KIO worker Only access it inside adjustUDSEntry()

Definition at line 151 of file forwardingworkerbase.cpp.

◆ rewriteUrl()

virtual bool KIO::ForwardingWorkerBase::rewriteUrl ( const QUrl url,
QUrl newURL 
)
protectedpure virtual

Rewrite an url to its forwarded counterpart.

It should return true if everything was ok, and false otherwise.

If a problem is detected it's up to this method to trigger error() before returning. Returning false silently cancels the current KIO worker operation.

Parameters
urlThe URL as given during the KIO worker call
newURLThe new URL to forward the KIO worker call to
Returns
true if the given url could be correctly rewritten

◆ setModificationTime()

WorkerResult KIO::ForwardingWorkerBase::setModificationTime ( const QUrl url,
const QDateTime mtime 
)
overridevirtual

Sets the modification time for @url.

For instance this is what CopyJob uses to set mtime on dirs at the end of a copy. It could also be used to set the mtime on any file, in theory. The usual implementation on unix is to call utime(path, &myutimbuf). The worker emits ERR_DOES_NOT_EXIST or ERR_CANNOT_SETTIME

Reimplemented from KIO::WorkerBase.

Definition at line 272 of file forwardingworkerbase.cpp.

◆ stat()

WorkerResult KIO::ForwardingWorkerBase::stat ( const QUrl url)
overridevirtual

Finds all details for one file or directory.

The information returned is the same as what listDir returns, but only for one file or directory. Call statEntry() after creating the appropriate UDSEntry for this url.

You can use the "details" metadata to optimize this method to only do as much work as needed by the application. By default details is 2 (all details wanted, including modification time, size, etc.), details==1 is used when deleting: we don't need all the information if it takes too much time, no need to follow symlinks etc. details==0 is used for very simple probing: we'll only get the answer "it's a file or a directory (or a symlink), or it doesn't exist".

Reimplemented from KIO::WorkerBase.

Definition at line 180 of file forwardingworkerbase.cpp.

◆ symlink()

WorkerResult KIO::ForwardingWorkerBase::symlink ( const QString target,
const QUrl dest,
JobFlags  flags 
)
overridevirtual

Creates a symbolic link named dest, pointing to target, which may be a relative or an absolute path.

Parameters
targetThe string that will become the "target" of the link (can be relative)
destThe symlink to create.
flagsWe support Overwrite here

Reimplemented from KIO::WorkerBase.

Definition at line 246 of file forwardingworkerbase.cpp.


The documentation for this class was generated from the following files:
static WorkerResult pass()
Constructs a success result.
Definition: workerbase.cpp:479
WorkerResult stat(const QUrl &url) override
Finds all details for one file or directory.
void statEntry(const UDSEntry &_entry)
Call this from stat() to express details about an object, the UDSEntry customarily contains the atoms...
Definition: workerbase.cpp:185
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Jan 30 2023 04:00:34 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.