mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-24 02:42:48 +00:00
kio: format and indent
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
c40e6014ce
commit
75eeefb652
2 changed files with 246 additions and 275 deletions
|
@ -78,12 +78,7 @@ namespace KIO
|
|||
|
||||
using namespace KIO;
|
||||
|
||||
|
||||
/**
|
||||
* List of temporary files
|
||||
*/
|
||||
static QStringList tmpfiles;
|
||||
|
||||
static QString lastErrorMsg;
|
||||
static int lastErrorCode = 0;
|
||||
|
||||
|
@ -129,129 +124,109 @@ bool NetAccess::download(const KUrl& u, QString & target, QWidget* window)
|
|||
return kioNet.filecopyInternal( u, dest, -1, KIO::Overwrite, window, false /*copy*/);
|
||||
}
|
||||
|
||||
bool NetAccess::upload(const QString& src, const KUrl& target, QWidget* window)
|
||||
bool NetAccess::upload(const QString &src, const KUrl &target, QWidget *window)
|
||||
{
|
||||
if (target.isEmpty())
|
||||
return false;
|
||||
if (target.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If target is local... well, just copy. This can be useful
|
||||
// when the client code uses a temp file no matter what.
|
||||
// Let's make sure it's not the exact same file though
|
||||
if (target.isLocalFile() && target.toLocalFile() == src)
|
||||
return true;
|
||||
// If target is local... well, just copy. This can be useful
|
||||
// when the client code uses a temp file no matter what.
|
||||
// Let's make sure it's not the exact same file though
|
||||
if (target.isLocalFile() && target.toLocalFile() == src) {
|
||||
return true;
|
||||
}
|
||||
|
||||
NetAccess kioNet;
|
||||
KUrl s;
|
||||
s.setPath(src);
|
||||
return kioNet.filecopyInternal( s, target, -1, KIO::Overwrite, window, false /*copy*/ );
|
||||
NetAccess kioNet;
|
||||
KUrl s;
|
||||
s.setPath(src);
|
||||
return kioNet.filecopyInternal(s, target, -1, KIO::Overwrite, window, false /*copy*/);
|
||||
}
|
||||
|
||||
bool NetAccess::file_copy( const KUrl & src, const KUrl & target, QWidget* window )
|
||||
bool NetAccess::file_copy(const KUrl &src, const KUrl &target, QWidget *window)
|
||||
{
|
||||
NetAccess kioNet;
|
||||
return kioNet.filecopyInternal( src, target, -1, KIO::DefaultFlags,
|
||||
window, false /*copy*/ );
|
||||
return kioNet.filecopyInternal(src, target, -1, KIO::DefaultFlags, window, false /*copy*/);
|
||||
}
|
||||
|
||||
|
||||
// bool NetAccess::file_copy( const KUrl& src, const KUrl& target, int permissions,
|
||||
// bool overwrite, bool resume, QWidget* window )
|
||||
// {
|
||||
// NetAccess kioNet;
|
||||
// return kioNet.filecopyInternal( src, target, permissions, overwrite, resume,
|
||||
// window, false /*copy*/ );
|
||||
// }
|
||||
|
||||
|
||||
// bool NetAccess::file_move( const KUrl& src, const KUrl& target, int permissions,
|
||||
// bool overwrite, bool resume, QWidget* window )
|
||||
// {
|
||||
// NetAccess kioNet;
|
||||
// return kioNet.filecopyInternal( src, target, permissions, overwrite, resume,
|
||||
// window, true /*move*/ );
|
||||
// }
|
||||
|
||||
bool NetAccess::dircopy( const KUrl & src, const KUrl & target, QWidget* window )
|
||||
bool NetAccess::dircopy(const KUrl &src, const KUrl &target, QWidget *window)
|
||||
{
|
||||
KUrl::List srcList;
|
||||
srcList.append( src );
|
||||
return NetAccess::dircopy( srcList, target, window );
|
||||
KUrl::List srcList;
|
||||
srcList.append(src);
|
||||
return NetAccess::dircopy(srcList, target, window);
|
||||
}
|
||||
|
||||
bool NetAccess::dircopy( const KUrl::List & srcList, const KUrl & target, QWidget* window )
|
||||
bool NetAccess::dircopy(const KUrl::List &srcList, const KUrl &target, QWidget *window)
|
||||
{
|
||||
NetAccess kioNet;
|
||||
return kioNet.dircopyInternal( srcList, target, window, false /*copy*/ );
|
||||
NetAccess kioNet;
|
||||
return kioNet.dircopyInternal(srcList, target, window, false /*copy*/);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool NetAccess::exists(const KUrl & url, StatSide side, QWidget* window)
|
||||
bool NetAccess::exists(const KUrl &url, StatSide side, QWidget *window)
|
||||
{
|
||||
if (url.isLocalFile()) {
|
||||
return QFileInfo(url.toLocalFile()).exists();
|
||||
}
|
||||
NetAccess kioNet;
|
||||
return kioNet.statInternal(url, 0 /*no details*/, side, window);
|
||||
if (url.isLocalFile()) {
|
||||
return QFileInfo(url.toLocalFile()).exists();
|
||||
}
|
||||
NetAccess kioNet;
|
||||
return kioNet.statInternal(url, 0 /*no details*/, side, window);
|
||||
}
|
||||
|
||||
bool NetAccess::stat(const KUrl& url, KIO::UDSEntry &entry, QWidget* window)
|
||||
bool NetAccess::stat(const KUrl &url, KIO::UDSEntry &entry, QWidget *window)
|
||||
{
|
||||
NetAccess kioNet;
|
||||
bool ret = kioNet.statInternal(url, 2 /*all details*/, SourceSide, window);
|
||||
if (ret) {
|
||||
entry = kioNet.d->m_entry;
|
||||
}
|
||||
return ret;
|
||||
NetAccess kioNet;
|
||||
bool ret = kioNet.statInternal(url, 2 /*all details*/, SourceSide, window);
|
||||
if (ret) {
|
||||
entry = kioNet.d->m_entry;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
KUrl NetAccess::mostLocalUrl(const KUrl &url, QWidget* window)
|
||||
KUrl NetAccess::mostLocalUrl(const KUrl &url, QWidget *window)
|
||||
{
|
||||
if (url.isLocalFile()) {
|
||||
if (url.isLocalFile()) {
|
||||
return url;
|
||||
}
|
||||
|
||||
KIO::UDSEntry entry;
|
||||
if (!stat(url, entry, window)) {
|
||||
return url;
|
||||
}
|
||||
|
||||
const QString path = entry.stringValue(KIO::UDSEntry::UDS_LOCAL_PATH);
|
||||
if (!path.isEmpty()) {
|
||||
KUrl new_url;
|
||||
new_url.setPath(path);
|
||||
return new_url;
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
KIO::UDSEntry entry;
|
||||
if (!stat(url, entry, window)) {
|
||||
return url;
|
||||
}
|
||||
|
||||
const QString path = entry.stringValue( KIO::UDSEntry::UDS_LOCAL_PATH );
|
||||
if ( !path.isEmpty() ) {
|
||||
KUrl new_url;
|
||||
new_url.setPath(path);
|
||||
return new_url;
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
bool NetAccess::del( const KUrl & url, QWidget* window )
|
||||
bool NetAccess::del(const KUrl &url, QWidget *window)
|
||||
{
|
||||
NetAccess kioNet;
|
||||
return kioNet.delInternal( url, window );
|
||||
NetAccess kioNet;
|
||||
return kioNet.delInternal(url, window);
|
||||
}
|
||||
|
||||
bool NetAccess::mkdir( const KUrl & url, QWidget* window, int permissions )
|
||||
bool NetAccess::mkdir(const KUrl &url, QWidget *window, int permissions)
|
||||
{
|
||||
NetAccess kioNet;
|
||||
return kioNet.mkdirInternal( url, permissions, window );
|
||||
NetAccess kioNet;
|
||||
return kioNet.mkdirInternal(url, permissions, window);
|
||||
}
|
||||
|
||||
bool NetAccess::synchronousRun( Job* job, QWidget* window, QByteArray* data,
|
||||
KUrl* finalURL, MetaData* metaData )
|
||||
bool NetAccess::synchronousRun(Job *job, QWidget *window, QByteArray *data,
|
||||
KUrl *finalURL, MetaData *metaData)
|
||||
{
|
||||
NetAccess kioNet;
|
||||
// Disable autodeletion until we are back from this event loop (#170963)
|
||||
// We just have to hope people don't mess with setAutoDelete in slots connected to the job, though.
|
||||
const bool wasAutoDelete = job->isAutoDelete();
|
||||
job->setAutoDelete(false);
|
||||
const bool ok = kioNet.synchronousRunInternal(job, window, data, finalURL, metaData);
|
||||
if (wasAutoDelete) {
|
||||
job->deleteLater();
|
||||
}
|
||||
return ok;
|
||||
NetAccess kioNet;
|
||||
// Disable autodeletion until we are back from this event loop (#170963)
|
||||
// We just have to hope people don't mess with setAutoDelete in slots connected to the job, though.
|
||||
const bool wasAutoDelete = job->isAutoDelete();
|
||||
job->setAutoDelete(false);
|
||||
const bool ok = kioNet.synchronousRunInternal(job, window, data, finalURL, metaData);
|
||||
if (wasAutoDelete) {
|
||||
job->deleteLater();
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
QString NetAccess::lastErrorString()
|
||||
|
@ -264,172 +239,168 @@ int NetAccess::lastError()
|
|||
return lastErrorCode;
|
||||
}
|
||||
|
||||
void NetAccess::removeTempFile(const QString& name)
|
||||
void NetAccess::removeTempFile(const QString &name)
|
||||
{
|
||||
if (tmpfiles.contains(name))
|
||||
{
|
||||
unlink(QFile::encodeName(name));
|
||||
tmpfiles.removeAll(name);
|
||||
}
|
||||
if (tmpfiles.contains(name)) {
|
||||
unlink(QFile::encodeName(name));
|
||||
tmpfiles.removeAll(name);
|
||||
}
|
||||
}
|
||||
|
||||
bool NetAccess::filecopyInternal(const KUrl& src, const KUrl& target, int permissions,
|
||||
KIO::JobFlags flags, QWidget* window, bool move)
|
||||
bool NetAccess::filecopyInternal(const KUrl &src, const KUrl &target, int permissions,
|
||||
KIO::JobFlags flags, QWidget *window, bool move)
|
||||
{
|
||||
d->bJobOK = true; // success unless further error occurs
|
||||
|
||||
KIO::Job * job = move
|
||||
? KIO::file_move( src, target, permissions, flags )
|
||||
: KIO::file_copy( src, target, permissions, flags );
|
||||
job->ui()->setWindow (window);
|
||||
connect( job, SIGNAL(result(KJob*)),
|
||||
this, SLOT(slotResult(KJob*)) );
|
||||
|
||||
enter_loop();
|
||||
return d->bJobOK;
|
||||
d->bJobOK = true; // success unless further error occurs
|
||||
KIO::Job *job = (
|
||||
move
|
||||
? KIO::file_move(src, target, permissions, flags)
|
||||
: KIO::file_copy(src, target, permissions, flags)
|
||||
);
|
||||
job->ui()->setWindow(window);
|
||||
connect(job, SIGNAL(result(KJob*)), this, SLOT(slotResult(KJob*)));
|
||||
enter_loop();
|
||||
return d->bJobOK;
|
||||
}
|
||||
|
||||
bool NetAccess::dircopyInternal(const KUrl::List& src, const KUrl& target,
|
||||
QWidget* window, bool move)
|
||||
bool NetAccess::dircopyInternal(const KUrl::List &src, const KUrl &target,
|
||||
QWidget *window, bool move)
|
||||
{
|
||||
d->bJobOK = true; // success unless further error occurs
|
||||
|
||||
KIO::Job * job = move
|
||||
? KIO::move( src, target )
|
||||
: KIO::copy( src, target );
|
||||
job->ui()->setWindow (window);
|
||||
connect( job, SIGNAL(result(KJob*)),
|
||||
this, SLOT(slotResult(KJob*)) );
|
||||
|
||||
enter_loop();
|
||||
return d->bJobOK;
|
||||
d->bJobOK = true; // success unless further error occurs
|
||||
KIO::Job * job = move ? KIO::move(src, target) : KIO::copy(src, target);
|
||||
job->ui()->setWindow(window);
|
||||
connect(job, SIGNAL(result(KJob*)), this, SLOT(slotResult(KJob*)) );
|
||||
enter_loop();
|
||||
return d->bJobOK;
|
||||
}
|
||||
|
||||
bool NetAccess::statInternal( const KUrl & url, int details, StatSide side,
|
||||
QWidget* window )
|
||||
bool NetAccess::statInternal(const KUrl &url, int details, StatSide side, QWidget* window)
|
||||
{
|
||||
d->bJobOK = true; // success unless further error occurs
|
||||
d->m_statJob = KIO::stat( url, KIO::HideProgressInfo );
|
||||
d->m_statJob->ui()->setWindow (window);
|
||||
d->m_statJob->setDetails( details );
|
||||
d->m_statJob->setSide( side == SourceSide ? StatJob::SourceSide : StatJob::DestinationSide );
|
||||
connect( d->m_statJob, SIGNAL(result(KJob*)),
|
||||
this, SLOT(slotResult(KJob*)) );
|
||||
if (!url.isLocalFile()) {
|
||||
QTimer::singleShot(3000, this, SLOT(slotShowProgress()));
|
||||
}
|
||||
enter_loop();
|
||||
return d->bJobOK;
|
||||
d->bJobOK = true; // success unless further error occurs
|
||||
d->m_statJob = KIO::stat(url, KIO::HideProgressInfo);
|
||||
d->m_statJob->ui()->setWindow (window);
|
||||
d->m_statJob->setDetails( details );
|
||||
d->m_statJob->setSide(side == SourceSide ? StatJob::SourceSide : StatJob::DestinationSide);
|
||||
connect(d->m_statJob, SIGNAL(result(KJob*)), this, SLOT(slotResult(KJob*)));
|
||||
if (!url.isLocalFile()) {
|
||||
QTimer::singleShot(3000, this, SLOT(slotShowProgress()));
|
||||
}
|
||||
enter_loop();
|
||||
return d->bJobOK;
|
||||
}
|
||||
|
||||
bool NetAccess::delInternal( const KUrl & url, QWidget* window )
|
||||
bool NetAccess::delInternal(const KUrl &url, QWidget *window)
|
||||
{
|
||||
d->bJobOK = true; // success unless further error occurs
|
||||
KIO::Job * job = KIO::del( url );
|
||||
job->ui()->setWindow (window);
|
||||
connect( job, SIGNAL(result(KJob*)),
|
||||
this, SLOT(slotResult(KJob*)) );
|
||||
enter_loop();
|
||||
return d->bJobOK;
|
||||
d->bJobOK = true; // success unless further error occurs
|
||||
KIO::Job* job = KIO::del(url);
|
||||
job->ui()->setWindow(window);
|
||||
connect(job, SIGNAL(result(KJob*)), this, SLOT(slotResult(KJob*)));
|
||||
enter_loop();
|
||||
return d->bJobOK;
|
||||
}
|
||||
|
||||
bool NetAccess::mkdirInternal( const KUrl & url, int permissions,
|
||||
QWidget* window )
|
||||
bool NetAccess::mkdirInternal(const KUrl &url, int permissions, QWidget *window)
|
||||
{
|
||||
d->bJobOK = true; // success unless further error occurs
|
||||
KIO::Job * job = KIO::mkdir( url, permissions );
|
||||
job->ui()->setWindow (window);
|
||||
connect( job, SIGNAL(result(KJob*)),
|
||||
this, SLOT(slotResult(KJob*)) );
|
||||
enter_loop();
|
||||
return d->bJobOK;
|
||||
d->bJobOK = true; // success unless further error occurs
|
||||
KIO::Job* job = KIO::mkdir(url, permissions);
|
||||
job->ui()->setWindow(window);
|
||||
connect(job, SIGNAL(result(KJob*)), this, SLOT(slotResult(KJob*)));
|
||||
enter_loop();
|
||||
return d->bJobOK;
|
||||
}
|
||||
|
||||
bool NetAccess::synchronousRunInternal( Job* job, QWidget* window, QByteArray* data,
|
||||
KUrl* finalURL, MetaData* metaData )
|
||||
bool NetAccess::synchronousRunInternal(Job* job, QWidget *window, QByteArray *data,
|
||||
KUrl *finalURL, MetaData *metaData)
|
||||
{
|
||||
if ( job->ui() ) job->ui()->setWindow( window );
|
||||
if (job->ui()) {
|
||||
job->ui()->setWindow(window);
|
||||
}
|
||||
|
||||
d->m_metaData = metaData;
|
||||
if ( d->m_metaData ) {
|
||||
for ( MetaData::iterator it = d->m_metaData->begin(); it != d->m_metaData->end(); ++it ) {
|
||||
job->addMetaData( it.key(), it.value() );
|
||||
}
|
||||
}
|
||||
d->m_metaData = metaData;
|
||||
if (d->m_metaData) {
|
||||
for (MetaData::iterator it = d->m_metaData->begin(); it != d->m_metaData->end(); ++it) {
|
||||
job->addMetaData(it.key(), it.value());
|
||||
}
|
||||
}
|
||||
|
||||
if ( finalURL ) {
|
||||
SimpleJob *sj = qobject_cast<SimpleJob*>( job );
|
||||
if ( sj ) {
|
||||
d->m_url = sj->url();
|
||||
}
|
||||
}
|
||||
if (finalURL) {
|
||||
SimpleJob *simpleJob = qobject_cast<SimpleJob*>(job);
|
||||
if (simpleJob) {
|
||||
d->m_url = simpleJob->url();
|
||||
}
|
||||
}
|
||||
|
||||
connect( job, SIGNAL(result(KJob*)),
|
||||
this, SLOT(slotResult(KJob*)) );
|
||||
connect(job, SIGNAL(result(KJob*)), this, SLOT(slotResult(KJob*)));
|
||||
|
||||
const QMetaObject* meta = job->metaObject();
|
||||
const QMetaObject* meta = job->metaObject();
|
||||
static const char dataSignal[] = "data(KIO::Job*,QByteArray)";
|
||||
if (meta->indexOfSignal(dataSignal) != -1) {
|
||||
connect(
|
||||
job, SIGNAL(data(KIO::Job*,QByteArray)),
|
||||
this, SLOT(slotData(KIO::Job*,QByteArray))
|
||||
);
|
||||
}
|
||||
static const char redirSignal[] = "redirection(KIO::Job*,KUrl)";
|
||||
if (meta->indexOfSignal(redirSignal) != -1) {
|
||||
connect(
|
||||
job, SIGNAL(redirection(KIO::Job*,KUrl)),
|
||||
this, SLOT(slotRedirection(KIO::Job*,KUrl))
|
||||
);
|
||||
}
|
||||
|
||||
static const char dataSignal[] = "data(KIO::Job*,QByteArray)";
|
||||
if ( meta->indexOfSignal( dataSignal ) != -1 ) {
|
||||
connect( job, SIGNAL(data(KIO::Job*,QByteArray)),
|
||||
this, SLOT(slotData(KIO::Job*,QByteArray)) );
|
||||
}
|
||||
enter_loop();
|
||||
|
||||
static const char redirSignal[] = "redirection(KIO::Job*,KUrl)";
|
||||
if ( meta->indexOfSignal( redirSignal ) != -1 ) {
|
||||
connect( job, SIGNAL(redirection(KIO::Job*,KUrl)),
|
||||
this, SLOT(slotRedirection(KIO::Job*,KUrl)) );
|
||||
}
|
||||
if (finalURL) {
|
||||
*finalURL = d->m_url;
|
||||
}
|
||||
if (data) {
|
||||
*data = d->m_data;
|
||||
}
|
||||
|
||||
enter_loop();
|
||||
|
||||
if ( finalURL )
|
||||
*finalURL = d->m_url;
|
||||
if ( data )
|
||||
*data = d->m_data;
|
||||
|
||||
return d->bJobOK;
|
||||
return d->bJobOK;
|
||||
}
|
||||
|
||||
void NetAccess::enter_loop()
|
||||
{
|
||||
QEventLoop eventLoop;
|
||||
connect(this, SIGNAL(leaveModality()),
|
||||
&eventLoop, SLOT(quit()));
|
||||
connect(this, SIGNAL(leaveModality()), &eventLoop, SLOT(quit()));
|
||||
eventLoop.exec();
|
||||
}
|
||||
|
||||
void NetAccess::slotResult( KJob * job )
|
||||
void NetAccess::slotResult(KJob *job)
|
||||
{
|
||||
lastErrorCode = job->error();
|
||||
d->bJobOK = !job->error();
|
||||
if ( !d->bJobOK )
|
||||
{
|
||||
lastErrorMsg = job->errorString();
|
||||
}
|
||||
KIO::StatJob* statJob = qobject_cast<KIO::StatJob *>( job );
|
||||
if ( statJob )
|
||||
d->m_entry = statJob->statResult();
|
||||
lastErrorCode = job->error();
|
||||
d->bJobOK = (job->error() == KJob::NoError);
|
||||
if (!d->bJobOK) {
|
||||
lastErrorMsg = job->errorString();
|
||||
}
|
||||
|
||||
KIO::Job* kioJob = qobject_cast<KIO::Job *>( job );
|
||||
if ( kioJob && d->m_metaData )
|
||||
*d->m_metaData = kioJob->metaData();
|
||||
KIO::StatJob* statJob = qobject_cast<KIO::StatJob*>(job);
|
||||
if (statJob) {
|
||||
d->m_entry = statJob->statResult();
|
||||
}
|
||||
|
||||
emit leaveModality();
|
||||
KIO::Job* kioJob = qobject_cast<KIO::Job*>(job);
|
||||
if (kioJob && d->m_metaData) {
|
||||
*d->m_metaData = kioJob->metaData();
|
||||
}
|
||||
|
||||
emit leaveModality();
|
||||
}
|
||||
|
||||
void NetAccess::slotData( KIO::Job*, const QByteArray& data )
|
||||
void NetAccess::slotData(KIO::Job *job, const QByteArray &data)
|
||||
{
|
||||
if ( data.isEmpty() )
|
||||
return;
|
||||
|
||||
unsigned offset = d->m_data.size();
|
||||
d->m_data.resize( offset + data.size() );
|
||||
std::memcpy( d->m_data.data() + offset, data.data(), data.size() );
|
||||
Q_UNUSED(job);
|
||||
if (data.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
unsigned offset = d->m_data.size();
|
||||
d->m_data.resize(offset + data.size());
|
||||
::memcpy(d->m_data.data() + offset, data.data(), data.size());
|
||||
}
|
||||
|
||||
void NetAccess::slotRedirection( KIO::Job*, const KUrl& url )
|
||||
void NetAccess::slotRedirection(KIO::Job *job, const KUrl &url)
|
||||
{
|
||||
Q_UNUSED(job);
|
||||
d->m_url = url;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,46 +23,45 @@
|
|||
#ifndef KIO_NETACCESS_H
|
||||
#define KIO_NETACCESS_H
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
#include <QWidget>
|
||||
#include <kio/global.h>
|
||||
#include <kio/udsentry.h>
|
||||
#include <kurl.h>
|
||||
#include <kio/jobclasses.h> // for KIO::JobFlags
|
||||
#include <kio/jobclasses.h>
|
||||
|
||||
class KJob;
|
||||
namespace KIO {
|
||||
|
||||
class Job;
|
||||
class Job;
|
||||
class NetAccessPrivate;
|
||||
|
||||
class NetAccessPrivate;
|
||||
/**
|
||||
* 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@kde.org
|
||||
*
|
||||
* @short Provides a blocking interface to KIO file operations.
|
||||
*/
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* Port to kio done by David Faure, faure@kde.org
|
||||
*
|
||||
* @short Provides a blocking interface to KIO file operations.
|
||||
*/
|
||||
class KIO_EXPORT NetAccess : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum StatSide {
|
||||
|
@ -134,7 +133,7 @@ public:
|
|||
*
|
||||
* @see lastErrorString()
|
||||
*/
|
||||
static bool download(const KUrl& src, QString & target, QWidget* window);
|
||||
static bool download(const KUrl &src, QString &target, QWidget *window);
|
||||
|
||||
/**
|
||||
* Removes the specified file if and only if it was created
|
||||
|
@ -144,10 +143,9 @@ public:
|
|||
* use KTempFile::unlink() or KTempFile::setAutoDelete() to have
|
||||
* it removed.
|
||||
*
|
||||
* @param name Path to temporary file to remove. May not be
|
||||
* empty.
|
||||
* @param name Path to temporary file to remove. May not be empty.
|
||||
*/
|
||||
static void removeTempFile(const QString& name);
|
||||
static void removeTempFile(const QString &name);
|
||||
|
||||
/**
|
||||
* Uploads file @p src to URL @p target.
|
||||
|
@ -167,7 +165,7 @@ public:
|
|||
*
|
||||
* @return true if successful, false for failure
|
||||
*/
|
||||
static bool upload(const QString& src, const KUrl& target, QWidget* window);
|
||||
static bool upload(const QString &src, const KUrl &target, QWidget *window);
|
||||
|
||||
/**
|
||||
* Alternative to upload for copying over the network.
|
||||
|
@ -185,7 +183,7 @@ public:
|
|||
*
|
||||
* @return true if successful, false for failure
|
||||
*/
|
||||
static bool file_copy( const KUrl& src, const KUrl& target, QWidget* window = 0 );
|
||||
static bool file_copy(const KUrl &src, const KUrl &target, QWidget* window = nullptr);
|
||||
|
||||
/**
|
||||
* Alternative method for copying over the network.
|
||||
|
@ -207,12 +205,14 @@ public:
|
|||
* prompted for passwords as needed.
|
||||
* @return true if successful, false for failure
|
||||
*/
|
||||
static bool dircopy( const KUrl& src, const KUrl& target, QWidget* window ); // TODO deprecate in favor of KIO::copy + synchronousRun (or job->exec())
|
||||
// TODO deprecate in favor of KIO::copy + synchronousRun (or job->exec())
|
||||
static bool dircopy(const KUrl &src, const KUrl &target, QWidget *window);
|
||||
|
||||
/**
|
||||
* Overloaded method, which takes a list of source URLs
|
||||
*/
|
||||
static bool dircopy( const KUrl::List& src, const KUrl& target, QWidget* window = 0L ); // TODO deprecate in favor of KIO::copy + synchronousRun (or job->exec())
|
||||
// TODO deprecate in favor of KIO::copy + synchronousRun (or job->exec())
|
||||
static bool dircopy(const KUrl::List &src, const KUrl &target, QWidget *window = nullptr);
|
||||
|
||||
/**
|
||||
* Tests whether a URL exists.
|
||||
|
@ -228,7 +228,7 @@ public:
|
|||
* @return true if the URL exists and we can do the operation specified by
|
||||
* @p source, false otherwise
|
||||
*/
|
||||
static bool exists(const KUrl& url, StatSide statSide, QWidget* window);
|
||||
static bool exists(const KUrl &url, StatSide statSide, QWidget *window);
|
||||
|
||||
/**
|
||||
* Tests whether a URL exists and return information on it.
|
||||
|
@ -246,7 +246,7 @@ public:
|
|||
* again be prompted for passwords as needed.
|
||||
* @return true if successful, false for failure
|
||||
*/
|
||||
static bool stat(const KUrl& url, KIO::UDSEntry & entry, QWidget* window);
|
||||
static bool stat(const KUrl &url, KIO::UDSEntry &entry, QWidget *window);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -264,7 +264,7 @@ public:
|
|||
* @return a local URL corresponding to the same resource than the
|
||||
* original URL, or the original URL if no local URL can be mapped
|
||||
*/
|
||||
static KUrl mostLocalUrl(const KUrl& url, QWidget* window);
|
||||
static KUrl mostLocalUrl(const KUrl &url, QWidget *window);
|
||||
|
||||
/**
|
||||
* Deletes a file or a directory in a synchronous way.
|
||||
|
@ -280,7 +280,7 @@ public:
|
|||
* again be prompted for passwords as needed.
|
||||
* @return true on success, false on failure.
|
||||
*/
|
||||
static bool del( const KUrl & url, QWidget* window );
|
||||
static bool del(const KUrl &url, QWidget* window);
|
||||
|
||||
/**
|
||||
* Creates a directory in a synchronous way.
|
||||
|
@ -297,7 +297,7 @@ public:
|
|||
* @param permissions directory permissions.
|
||||
* @return true on success, false on failure.
|
||||
*/
|
||||
static bool mkdir( const KUrl & url, QWidget* window, int permissions = -1 );
|
||||
static bool mkdir(const KUrl &url, QWidget *window, int permissions = -1);
|
||||
|
||||
/**
|
||||
* This function executes a job in a synchronous way.
|
||||
|
@ -330,8 +330,8 @@ public:
|
|||
*
|
||||
* @return true on success, false on failure.
|
||||
*/
|
||||
static bool synchronousRun( Job* job, QWidget* window, QByteArray* data=0,
|
||||
KUrl* finalURL=0, MetaData* metaData=0 );
|
||||
static bool synchronousRun(Job *job, QWidget *window, QByteArray *data = nullptr,
|
||||
KUrl* finalURL = nullptr, MetaData *metaData = nullptr);
|
||||
|
||||
/**
|
||||
* Returns the error string for the last job, in case it failed.
|
||||
|
@ -362,23 +362,23 @@ private:
|
|||
/**
|
||||
* Internal methods
|
||||
*/
|
||||
bool filecopyInternal(const KUrl& src, const KUrl& target, int permissions,
|
||||
KIO::JobFlags flags, QWidget* window, bool move);
|
||||
bool dircopyInternal(const KUrl::List& src, const KUrl& target,
|
||||
QWidget* window, bool move);
|
||||
bool statInternal(const KUrl & url, int details, StatSide side, QWidget* window = 0);
|
||||
bool filecopyInternal(const KUrl &src, const KUrl &target, int permissions,
|
||||
KIO::JobFlags flags, QWidget *window, bool move);
|
||||
bool dircopyInternal(const KUrl::List &src, const KUrl &target,
|
||||
QWidget *window, bool move);
|
||||
bool statInternal(const KUrl & url, int details, StatSide side, QWidget* window);
|
||||
|
||||
bool delInternal(const KUrl & url, QWidget* window = 0);
|
||||
bool mkdirInternal(const KUrl & url, int permissions, QWidget* window = 0);
|
||||
bool synchronousRunInternal( Job* job, QWidget* window, QByteArray* data,
|
||||
KUrl* finalURL, MetaData* metaData );
|
||||
bool delInternal(const KUrl &url, QWidget *window);
|
||||
bool mkdirInternal(const KUrl &url, int permissions, QWidget *window);
|
||||
bool synchronousRunInternal(Job *job, QWidget *window, QByteArray *data,
|
||||
KUrl *finalURL, MetaData* metaData);
|
||||
|
||||
void enter_loop();
|
||||
|
||||
private Q_SLOTS:
|
||||
void slotResult( KJob * job );
|
||||
void slotData( KIO::Job*, const QByteArray& );
|
||||
void slotRedirection( KIO::Job*, const KUrl& );
|
||||
void slotResult(KJob *job);
|
||||
void slotData(KIO::Job *job, const QByteArray &data);
|
||||
void slotRedirection(KIO::Job *job, const KUrl &url);
|
||||
void slotShowProgress();
|
||||
|
||||
private:
|
||||
|
@ -387,4 +387,4 @@ private:
|
|||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif // KIO_NETACCESS_H
|
||||
|
|
Loading…
Add table
Reference in a new issue