KIO::NetAccess

Search for usage in LXR

#include <netaccess.h>

Inheritance diagram for KIO::NetAccess:

Public Types

enum  StatSide { SourceSide, DestinationSide }
 

Signals

void leaveModality ()
 

Static Public Member Functions

static bool copy (const QUrl &src, const QUrl &target, QWidget *window=nullptr)
 
static bool del (const QUrl &url, QWidget *window)
 
static bool dircopy (const QUrl &src, const QUrl &target, QWidget *window)
 
static bool dircopy (const QList< QUrl > &src, const QUrl &target, QWidget *window=nullptr)
 
static bool download (const QUrl &src, QString &target, QWidget *window)
 
static bool exists (const QUrl &url, bool source, QWidget *window)
 
static bool exists (const QUrl &url, StatSide statSide, QWidget *window)
 
static bool file_copy (const QUrl &src, const QUrl &target, QWidget *window=nullptr)
 
static QString fish_execute (const QUrl &url, const QString &command, QWidget *window)
 
static int lastError ()
 
static QString lastErrorString ()
 
static QString mimetype (const QUrl &url, QWidget *window)
 
static bool mkdir (const QUrl &url, QWidget *window, int permissions=-1)
 
static QUrl mostLocalUrl (const QUrl &url, QWidget *window)
 
static bool move (const QUrl &src, const QUrl &target, QWidget *window=nullptr)
 
static bool move (const QList< QUrl > &src, const QUrl &target, QWidget *window=nullptr)
 
static void removeTempFile (const QString &name)
 
static bool stat (const QUrl &url, KIO::UDSEntry &entry, QWidget *window)
 
static bool synchronousRun (Job *job, QWidget *window, QByteArray *data=nullptr, QUrl *finalURL=nullptr, QMap< QString, QString > *metaData=nullptr)
 
static bool upload (const QString &src, const QUrl &target, QWidget *window)
 
- 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)
 

Additional Inherited Members

- Properties inherited from QObject
 objectName
 
- 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
 
- Public Attributes inherited from QObject
typedef QObjectList
 
- 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)
 

Detailed Description

Net Transparency.

NetAccess allows you to do simple file operation (load, save, copy, delete...) without working with KIO::Job directly. Whereas a KIO::Job is asynchronous, meaning that the developer has to connect slots for it, KIO::NetAccess provides synchronous downloads and uploads, as well as temporary file creation and removal. The functions appear to be blocking, but the Qt event loop continues running while the operations are handled. More precisely, the GUI will still repaint, but no user interaction will be possible. If you can, please use async KIO jobs instead! See the documentation of KJob::exec() for more about the dangers of NetAccess.

This class isn't meant to be used as a class but only as a simple namespace for static functions, though an instance of the class is built for internal purposes. TODO KDE5: turn into namespace, and make the qobject class private.

Port to kio done by David Faure, faure[email protected]@kde[email protected].org

Provides a blocking interface to KIO file operations.

Definition at line 68 of file netaccess.h.

Member Function Documentation

bool NetAccess::del ( const QUrl url,
QWidget window 
)
static

Deletes a file or a directory in a synchronous way.

This is a convenience function for KIO::del (it saves creating a slot and testing for the job result).

Parameters
urlThe file or directory to delete.
windowmain window associated with this job. This is used to automatically cache and discard authentication information as needed. If NULL, authentication information will be cached only for a short duration after which the user will again be prompted for passwords as needed.
Returns
true on success, false on failure.
Deprecated:
since 5.0, use KIO::del + job->ui()->setWindow() + job->exec() instead

Definition at line 246 of file netaccess.cpp.

bool NetAccess::dircopy ( const QUrl src,
const QUrl target,
QWidget window 
)
static

Alternative method for copying over the network.

This one takes two URLs and is a direct equivalent of KIO::copy!. This means that it can copy files and directories alike (it should have been named copy()).

This method will bring up a dialog if the destination already exists.

Parameters
srcURL Referencing the file to upload.
targetURL containing the final location of the file.
windowmain window associated with this job. This is used to automatically cache and discard authentication information as needed. If NULL, authentication information will be cached only for a short duration after which the user will again be prompted for passwords as needed.
Returns
true if successful, false for failure
Deprecated:
since 5.0, use KIO::copy + job->ui()->setWindow() + job->exec() instead

Definition at line 160 of file netaccess.cpp.

bool NetAccess::dircopy ( const QList< QUrl > &  src,
const QUrl target,
QWidget window = nullptr 
)
static

Overloaded method, which takes a list of source URLs.

Deprecated:
since 5.0, use KIO::copy + job->ui()->setWindow() + job->exec() instead

Definition at line 169 of file netaccess.cpp.

bool NetAccess::download ( const QUrl src,
QString target,
QWidget window 
)
static

Downloads a file from an arbitrary URL (src) to a temporary file on the local filesystem (target).

If the argument for target is an empty string, download will generate a unique temporary filename in /tmp. Since target is a reference to QString you can access this filename easily. Download will return true if the download was successful, otherwise false.

Special case: If the URL is of kind file:, then no downloading is processed but the full filename is returned in target. That means you have to take care about the target argument. (This is very easy to do, please see the example below.)

Download is synchronous. That means you can use it like this: (assuming your application has a loadFile() function)

QString tmpFile;
if( KIO::NetAccess::download(url, tmpFile, window)) {
loadFile(tmpFile);
} else {
}

Of course, your user interface will still process exposure/repaint events during the download.

If the download fails, lastError() and lastErrorString() will be set.

If the url is always remote, then you could also just write the more usual way:

if (tmpFile.open()) {
KIO::Job* getJob = KIO::file_copy(url, QUrl::fromLocalFile(tmpFile.fileName()), -1, KIO::Overwrite | KIO::HideProgressInfo);
getJob->ui()->setWindow(window);
loadFile(tmpFile.fileName());
} else {
getJob->ui()->showErrorMessage();
}
}
Parameters
srcURL Reference to the file to download.
targetString containing the final local location of the file. If you insert an empty string, it will return a location in a temporary spot. Note: you are responsible for the removal of this file when you are finished reading it using removeTempFile.
windowmain window associated with this job. This is used to automatically cache and discard authentication information as needed. If NULL, authentication information will be cached only for a short duration after which the user will again be prompted for passwords as needed.
Returns
true if successful, false for failure. Use lastErrorString() to get the reason it failed.
See also
lastErrorString()
Deprecated:
since 5.0, use KIO::storedGet + KJobWidgets::setWindow + job->exec() instead

Definition at line 93 of file netaccess.cpp.

bool NetAccess::exists ( const QUrl url,
bool  source,
QWidget window 
)
static

Tests whether a URL exists.

Parameters
urlthe URL we are testing
sourceif true, we want to read from that URL. If false, we want to write to it. IMPORTANT: see documentation for KIO::stat for more details about this.
windowmain window associated with this job. This is used to automatically cache and discard authentication information as needed. If NULL, authentication information will be cached only for a short duration after which the user will again be prompted for passwords as needed.
Returns
true if the URL exists and we can do the operation specified by source, false otherwise
Deprecated:
use the StatSide enum instead of the bool source

Definition at line 195 of file netaccess.cpp.

bool NetAccess::exists ( const QUrl url,
StatSide  statSide,
QWidget window 
)
static

Tests whether a URL exists.

Parameters
urlthe URL we are testing
statSidedetermines if we want to read or write. IMPORTANT: see documentation for KIO::stat for more details about this.
windowmain window associated with this job. This is used to automatically cache and discard authentication information as needed. If NULL, authentication information will be cached only for a short duration after which the user will again be prompted for passwords as needed.
Returns
true if the URL exists and we can do the operation specified by source, false otherwise
Deprecated:
since 5.0, use QFile::exists for local files and KIO::stat for transparency

Definition at line 206 of file netaccess.cpp.

bool NetAccess::file_copy ( const QUrl src,
const QUrl target,
QWidget window = nullptr 
)
static

Alternative to upload for copying over the network.

Overwrite is false, so this will fail if target exists.

This one takes two URLs and is a direct equivalent of KIO::file_copy.

Parameters
srcURL Referencing the file to upload.
targetURL containing the final location of the file.
windowmain window associated with this job. This is used to automatically cache and discard authentication information as needed. If NULL, authentication information will be cached only for a short duration after which the user will again be prompted for passwords as needed.
Returns
true if successful, false for failure
Deprecated:
since 5.0, use KIO::file_copy + job->ui()->setWindow() + job->exec() instead

Definition at line 144 of file netaccess.cpp.

QString NetAccess::fish_execute ( const QUrl url,
const QString command,
QWidget window 
)
static

Executes a remote process via the fish ioslave in a synchronous way.

Parameters
urlThe remote machine where the command should be executed. e.g. fish://[email protected]:sshport/ some special cases exist. fish://[email protected]/ will use su instead of ssh to connect and execute the command. fish://[email protected]:port/ will use ssh to connect and execute the command.
commandThe command to be executed.
windowmain window associated with this job. This is used to automatically cache and discard authentication information as needed. If NULL, authentication information will be cached only for a short duration after which the user will again be prompted for passwords as needed.
Returns
The resulting output of the command that is executed.

Definition at line 261 of file netaccess.cpp.

int NetAccess::lastError ( )
static

Returns the error code for the last job, in case it failed.

Returns
the last error code

Definition at line 293 of file netaccess.cpp.

QString NetAccess::lastErrorString ( )
static

Returns the error string for the last job, in case it failed.

Note that this is already translated.

Returns
the last error string, or QString()

Definition at line 288 of file netaccess.cpp.

QString NetAccess::mimetype ( const QUrl url,
QWidget window 
)
static

Determines the mimetype of a given URL.

This is a convenience function for KIO::mimetype. You should call this only when really necessary. QMimeDatabase::mimeTypeForUrl can determine the mimetype a lot faster, but less reliably for remote files. When mimeTypeForUrl() returns unknown (application/octet-stream) for a remote file, then this one should be used.

Parameters
urlThe URL whose mimetype we are interested in.
windowmain window associated with this job. This is used to automatically cache and discard authentication information as needed. If NULL, authentication information will be cached only for a short duration after which the user will again be prompted for passwords as needed.
Returns
The mimetype name.
Deprecated:
since 5.0, use KIO::mimetype + KJobWidgets::setWindow + job->exec() instead

Definition at line 282 of file netaccess.cpp.

bool NetAccess::mkdir ( const QUrl url,
QWidget window,
int  permissions = -1 
)
static

Creates a directory in a synchronous way.

This is a convenience function for KIO::mkdir (it saves creating a slot and testing for the job result).

Parameters
urlThe directory to create.
windowmain window associated with this job. This is used to automatically cache and discard authentication information as needed. If NULL, authentication information will be cached only for a short duration after which the user will again be prompted for passwords as needed.
permissionsdirectory permissions.
Returns
true on success, false on failure.
Deprecated:
since 5.0, use KIO::mkdir + job->ui()->setWindow() + job->exec() instead

Definition at line 254 of file netaccess.cpp.

QUrl NetAccess::mostLocalUrl ( const QUrl url,
QWidget window 
)
static

Tries to map a local URL for the given URL.

This is a convenience function for KIO::stat + parsing the resulting UDSEntry.

Parameters
urlThe URL we are testing.
windowmain window associated with this job. This is used to automatically cache and discard authentication information as needed. If NULL, authentication information will be cached only for a short duration after which the user will again be prompted for passwords as needed.
Returns
a local URL corresponding to the same resource than the original URL, or the original URL if no local URL can be mapped
Deprecated:
since 5.0, use KIO::mostLocalUrl + KJobWidgets::setWindow + job->exec() instead

Definition at line 225 of file netaccess.cpp.

bool NetAccess::move ( const QUrl src,
const QUrl target,
QWidget window = nullptr 
)
static

Full-fledged equivalent of KIO::move.

Moves or renames one file or directory.

Deprecated:
since 5.0, use KIO::move + job->ui()->setWindow() + job->exec() instead

Definition at line 177 of file netaccess.cpp.

bool NetAccess::move ( const QList< QUrl > &  src,
const QUrl target,
QWidget window = nullptr 
)
static

Full-fledged equivalent of KIO::move.

Moves or renames a list of files or directories.

Deprecated:
since 5.0, use KIO::move + job->ui()->setWindow() + job->exec() instead

Definition at line 187 of file netaccess.cpp.

void NetAccess::removeTempFile ( const QString name)
static

Removes the specified file if and only if it was created by KIO::NetAccess as a temporary file for a former download.

Note: This means that if you created your temporary with KTempFile, use KTempFile::unlink() or KTempFile::setAutoDelete() to have it removed.

Parameters
namePath to temporary file to remove. May not be empty.

Definition at line 298 of file netaccess.cpp.

bool NetAccess::stat ( const QUrl url,
KIO::UDSEntry entry,
QWidget window 
)
static

Tests whether a URL exists and return information on it.

This is a convenience function for KIO::stat (it saves creating a slot and testing for the job result).

Parameters
urlThe URL we are testing.
entryThe result of the stat. Iterate over the list of atoms to get hold of name, type, size, etc., or use KFileItem.
windowmain window associated with this job. This is used to automatically cache and discard authentication information as needed. If NULL, authentication information will be cached only for a short duration after which the user will again be prompted for passwords as needed.
Returns
true if successful, false for failure
Deprecated:
since 5.0, use KIO::stat + KJobWidgets::setWindow + job->exec() instead

Definition at line 215 of file netaccess.cpp.

bool NetAccess::synchronousRun ( Job job,
QWidget window,
QByteArray data = nullptr,
QUrl finalURL = nullptr,
QMap< QString, QString > *  metaData = nullptr 
)
static

This function executes a job in a synchronous way.

If a job fetches some data, pass a QByteArray pointer as data parameter to this function and after the function returns it will contain all the data fetched by this job.

KIO::Job *job = KIO::get( url );
metaData.insert( "PropagateHttpHeader", "true" );
if ( NetAccess::synchronousRun( job, 0, &data, &url, &metaData ) ) {
QString responseHeaders = metaData[ "HTTP-Headers" ];
qDebug()<<"Response header = "<< responseHeaders;
}
Parameters
jobjob which the function will run. Note that after this function finishes running, job is deleted and you can't access it anymore!
windowmain window associated with this job. This is used to automatically cache and discard authentication information as needed. If NULL, authentication information will be cached only for a short duration after which the user will again be prompted for passwords as needed.
dataif passed and relevant to this job then it will contain the data that was fetched by the job
finalURLif passed will contain the final url of this job (it might differ from the one it was created with if there was a redirection)
metaDatayou can pass a pointer to the map with meta data you wish to set on the job. After the job finishes this map will hold all the meta data from the job.
Returns
true on success, false on failure.
Deprecated:
since 5.0, KJobWidgets::setWindow + job->exec() instead

Definition at line 267 of file netaccess.cpp.

bool NetAccess::upload ( const QString src,
const QUrl target,
QWidget window 
)
static

Uploads file src to URL target.

Both must be specified, unlike download. Note that this is assumed to be used for saving a file over the network, so overwriting is set to true. This is not the case with copy.

Parameters
srcURL Referencing the file to upload.
targetURL containing the final location of the file.
windowmain window associated with this job. This is used to automatically cache and discard authentication information as needed. If NULL, authentication information will be cached only for a short duration after which the user will again be prompted for passwords as needed.
Returns
true if successful, false for failure
Deprecated:
since 5.0, use KIO::storedPut or KIO::file_copy + KJobWidgets::setWindow + job->exec() instead

Definition at line 125 of file netaccess.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Wed May 12 2021 22:58:12 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.