diff --git a/kioslave/remote/kdedmodule/remotedirnotify.h b/kioslave/remote/kdedmodule/remotedirnotify.h --- a/kioslave/remote/kdedmodule/remotedirnotify.h +++ b/kioslave/remote/kdedmodule/remotedirnotify.h @@ -24,20 +24,20 @@ class RemoteDirNotify : public QObject { -Q_OBJECT + Q_OBJECT public: - RemoteDirNotify(); + RemoteDirNotify(); private slots: - void FilesAdded (const QString &directory); - void FilesRemoved (const QStringList &fileList); - void FilesChanged (const QStringList &fileList); + void FilesAdded(const QString &directory); + void FilesRemoved(const QStringList &fileList); + void FilesChanged(const QStringList &fileList); private: - QUrl toRemoteURL(const QUrl &url); - QList toRemoteURLList(const QStringList &list); - QUrl m_baseURL; + QUrl toRemoteURL(const QUrl &url); + QList toRemoteURLList(const QStringList &list); + QUrl m_baseURL; }; #endif diff --git a/kioslave/remote/kdedmodule/remotedirnotify.cpp b/kioslave/remote/kdedmodule/remotedirnotify.cpp --- a/kioslave/remote/kdedmodule/remotedirnotify.cpp +++ b/kioslave/remote/kdedmodule/remotedirnotify.cpp @@ -27,33 +27,32 @@ RemoteDirNotify::RemoteDirNotify() { - const QString path = QStringLiteral("%1/remoteview").arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)); - m_baseURL.setPath(path); - - QDBusConnection::sessionBus().connect(QString(), QString(), QStringLiteral("org.kde.KDirNotify"), - QStringLiteral("FilesAdded"), this, SLOT(FilesAdded(QString))); - QDBusConnection::sessionBus().connect(QString(), QString(), QStringLiteral("org.kde.KDirNotify"), - QStringLiteral("FilesRemoved"), this, SLOT(FilesRemoved(QStringList))); - QDBusConnection::sessionBus().connect(QString(), QString(), QStringLiteral("org.kde.KDirNotify"), - QStringLiteral("FilesChanged"), this, SLOT(FilesChanged(QStringList))); + const QString path = QStringLiteral("%1/remoteview").arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)); + m_baseURL.setPath(path); + + QDBusConnection::sessionBus().connect(QString(), QString(), QStringLiteral("org.kde.KDirNotify"), + QStringLiteral("FilesAdded"), this, SLOT(FilesAdded(QString))); + QDBusConnection::sessionBus().connect(QString(), QString(), QStringLiteral("org.kde.KDirNotify"), + QStringLiteral("FilesRemoved"), this, SLOT(FilesRemoved(QStringList))); + QDBusConnection::sessionBus().connect(QString(), QString(), QStringLiteral("org.kde.KDirNotify"), + QStringLiteral("FilesChanged"), this, SLOT(FilesChanged(QStringList))); } QUrl RemoteDirNotify::toRemoteURL(const QUrl &url) { - qCDebug(KIOREMOTE_LOG) << "RemoteDirNotify::toRemoteURL(" << url << ")"; - if ( m_baseURL.isParentOf(url) ) - { - QString path = QDir(m_baseURL.path()).relativeFilePath(url.path()); - QUrl result; - result.setScheme(QStringLiteral("remote")); - result.setPath(path); - result.setPath(QDir::cleanPath(result.path())); - qCDebug(KIOREMOTE_LOG) << "result => " << result; - return result; - } - - qCDebug(KIOREMOTE_LOG) << "result => QUrl()"; - return QUrl(); + qCDebug(KIOREMOTE_LOG) << "RemoteDirNotify::toRemoteURL(" << url << ")"; + if (m_baseURL.isParentOf(url)) { + QString path = QDir(m_baseURL.path()).relativeFilePath(url.path()); + QUrl result; + result.setScheme(QStringLiteral("remote")); + result.setPath(path); + result.setPath(QDir::cleanPath(result.path())); + qCDebug(KIOREMOTE_LOG) << "result => " << result; + return result; + } + + qCDebug(KIOREMOTE_LOG) << "result => QUrl()"; + return QUrl(); } QList RemoteDirNotify::toRemoteURLList(const QStringList &list) @@ -71,14 +70,13 @@ void RemoteDirNotify::FilesAdded(const QString &directory) { - qCDebug(KIOREMOTE_LOG) << "RemoteDirNotify::FilesAdded"; + qCDebug(KIOREMOTE_LOG) << "RemoteDirNotify::FilesAdded"; - QUrl new_dir = toRemoteURL(QUrl::fromLocalFile(directory)); + QUrl new_dir = toRemoteURL(QUrl::fromLocalFile(directory)); - if (new_dir.isValid()) - { - org::kde::KDirNotify::emitFilesAdded(new_dir); - } + if (new_dir.isValid()) { + org::kde::KDirNotify::emitFilesAdded(new_dir); + } } // This hack is required because of the way we manage .desktop files with @@ -88,49 +86,43 @@ // FilesAdded to re-list the modified directory. inline void evil_hack(const QList &list) { - QList notified; + QList notified; - QList::const_iterator it = list.begin(); - QList::const_iterator end = list.end(); + QList::const_iterator it = list.begin(); + QList::const_iterator end = list.end(); - for (; it!=end; ++it) - { - QUrl url = KIO::upUrl(*it); + for (; it != end; ++it) { + QUrl url = KIO::upUrl(*it); - if (!notified.contains(url)) - { - org::kde::KDirNotify::emitFilesAdded(url); - notified.append(url); - } - } + if (!notified.contains(url)) { + org::kde::KDirNotify::emitFilesAdded(url); + notified.append(url); + } + } } - void RemoteDirNotify::FilesRemoved(const QStringList &fileList) { - qCDebug(KIOREMOTE_LOG) << "RemoteDirNotify::FilesRemoved"; + qCDebug(KIOREMOTE_LOG) << "RemoteDirNotify::FilesRemoved"; - QList new_list = toRemoteURLList(fileList); + QList new_list = toRemoteURLList(fileList); - if (!new_list.isEmpty()) - { - //KDirNotify_stub notifier("*", "*"); - //notifier.FilesRemoved( new_list ); - evil_hack(new_list); - } + if (!new_list.isEmpty()) { + //KDirNotify_stub notifier("*", "*"); + //notifier.FilesRemoved( new_list ); + evil_hack(new_list); + } } void RemoteDirNotify::FilesChanged(const QStringList &fileList) { - qCDebug(KIOREMOTE_LOG) << "RemoteDirNotify::FilesChanged"; + qCDebug(KIOREMOTE_LOG) << "RemoteDirNotify::FilesChanged"; - QList new_list = toRemoteURLList(fileList); + QList new_list = toRemoteURLList(fileList); - if (!new_list.isEmpty()) - { - //KDirNotify_stub notifier("*", "*"); - //notifier.FilesChanged( new_list ); - evil_hack(new_list); - } + if (!new_list.isEmpty()) { + //KDirNotify_stub notifier("*", "*"); + //notifier.FilesChanged( new_list ); + evil_hack(new_list); + } } - diff --git a/kioslave/remote/kdedmodule/remotedirnotifymodule.h b/kioslave/remote/kdedmodule/remotedirnotifymodule.h --- a/kioslave/remote/kdedmodule/remotedirnotifymodule.h +++ b/kioslave/remote/kdedmodule/remotedirnotifymodule.h @@ -27,7 +27,7 @@ { Q_OBJECT public: - RemoteDirNotifyModule(QObject* parent, const QList&); + RemoteDirNotifyModule(QObject *parent, const QList &); private: RemoteDirNotify notifier; }; diff --git a/kioslave/remote/kdedmodule/remotedirnotifymodule.cpp b/kioslave/remote/kdedmodule/remotedirnotifymodule.cpp --- a/kioslave/remote/kdedmodule/remotedirnotifymodule.cpp +++ b/kioslave/remote/kdedmodule/remotedirnotifymodule.cpp @@ -25,8 +25,8 @@ "remotedirnotify.json", registerPlugin();) -RemoteDirNotifyModule::RemoteDirNotifyModule(QObject* parent, const QList&) - : KDEDModule(parent) +RemoteDirNotifyModule::RemoteDirNotifyModule(QObject *parent, const QList &) + : KDEDModule(parent) { } diff --git a/kioslave/remote/kio_remote.h b/kioslave/remote/kio_remote.h --- a/kioslave/remote/kio_remote.h +++ b/kioslave/remote/kio_remote.h @@ -26,20 +26,19 @@ class RemoteProtocol : public KIO::SlaveBase { public: - RemoteProtocol(const QByteArray &protocol, const QByteArray &pool, - const QByteArray &app); - ~RemoteProtocol() override; - void listDir(const QUrl &url) override; - void stat(const QUrl &url) override; - void del(const QUrl &url, bool isFile) override; - void get(const QUrl &url) override; - void rename(const QUrl &src, const QUrl &dest, KIO::JobFlags flags) override; - void symlink(const QString &target, const QUrl &dest, KIO::JobFlags flags) override; + RemoteProtocol(const QByteArray &protocol, const QByteArray &pool, const QByteArray &app); + ~RemoteProtocol() override; + void listDir(const QUrl &url) override; + void stat(const QUrl &url) override; + void del(const QUrl &url, bool isFile) override; + void get(const QUrl &url) override; + void rename(const QUrl &src, const QUrl &dest, KIO::JobFlags flags) override; + void symlink(const QString &target, const QUrl &dest, KIO::JobFlags flags) override; private: - void listRoot(); + void listRoot(); - RemoteImpl m_impl; + RemoteImpl m_impl; }; #endif diff --git a/kioslave/remote/kio_remote.cpp b/kioslave/remote/kio_remote.cpp --- a/kioslave/remote/kio_remote.cpp +++ b/kioslave/remote/kio_remote.cpp @@ -24,23 +24,22 @@ #include extern "C" { - int Q_DECL_EXPORT kdemain( int argc, char **argv ) - { - // necessary to use other kio slaves - QCoreApplication app(argc, argv); - app.setApplicationName("kio_remote"); - - // start the slave - RemoteProtocol slave( argv[1], argv[2], argv[3] ); - slave.dispatchLoop(); - return 0; - } +int Q_DECL_EXPORT kdemain(int argc, char **argv) +{ + // necessary to use other kio slaves + QCoreApplication app(argc, argv); + app.setApplicationName("kio_remote"); + + // start the slave + RemoteProtocol slave(argv[1], argv[2], argv[3]); + slave.dispatchLoop(); + return 0; +} } - -RemoteProtocol::RemoteProtocol(const QByteArray &protocol, - const QByteArray &pool, const QByteArray &app) - : SlaveBase(protocol, pool, app) +RemoteProtocol::RemoteProtocol(const QByteArray &protocol, const QByteArray &pool, + const QByteArray &app) + : SlaveBase(protocol, pool, app) { } @@ -50,186 +49,168 @@ void RemoteProtocol::listDir(const QUrl &url) { - qCDebug(KIOREMOTE_LOG) << "RemoteProtocol::listDir: " << url; - - if ( url.path().length() <= 1 ) - { - listRoot(); - return; - } - - int second_slash_idx = url.path().indexOf( '/', 1 ); - const QString root_dirname = url.path().mid( 1, second_slash_idx-1 ); - - QUrl target = m_impl.findBaseURL( root_dirname ); - qCDebug(KIOREMOTE_LOG) << "possible redirection target : " << target; - if( target.isValid() ) - { - if ( second_slash_idx < 0 ) { - second_slash_idx = url.path().size(); - } - const QString urlPath = url.path().remove(0, second_slash_idx); - if (!urlPath.isEmpty()) { - target.setPath(QStringLiteral("%1/%2").arg(target.path(), urlPath)); - } - qCDebug(KIOREMOTE_LOG) << "complete redirection target : " << target; - redirection(target); - finished(); - return; - } - - error(KIO::ERR_MALFORMED_URL, url.toDisplayString()); + qCDebug(KIOREMOTE_LOG) << "RemoteProtocol::listDir: " << url; + + if (url.path().length() <= 1) { + listRoot(); + return; + } + + int second_slash_idx = url.path().indexOf('/', 1); + const QString root_dirname = url.path().mid(1, second_slash_idx-1); + + QUrl target = m_impl.findBaseURL(root_dirname); + qCDebug(KIOREMOTE_LOG) << "possible redirection target : " << target; + if (target.isValid()) { + if (second_slash_idx < 0) { + second_slash_idx = url.path().size(); + } + const QString urlPath = url.path().remove(0, second_slash_idx); + if (!urlPath.isEmpty()) { + target.setPath(QStringLiteral("%1/%2").arg(target.path(), urlPath)); + } + qCDebug(KIOREMOTE_LOG) << "complete redirection target : " << target; + redirection(target); + finished(); + return; + } + + error(KIO::ERR_MALFORMED_URL, url.toDisplayString()); } void RemoteProtocol::listRoot() { - KIO::UDSEntry entry; + KIO::UDSEntry entry; - KIO::UDSEntryList remote_entries; - m_impl.listRoot(remote_entries); + KIO::UDSEntryList remote_entries; + m_impl.listRoot(remote_entries); - totalSize(remote_entries.count()+2); + totalSize(remote_entries.count()+2); - m_impl.createTopLevelEntry(entry); - listEntry(entry); + m_impl.createTopLevelEntry(entry); + listEntry(entry); - if(m_impl.createWizardEntry(entry)) + if (m_impl.createWizardEntry(entry)) { listEntry(entry); + } - KIO::UDSEntryList::ConstIterator it = remote_entries.constBegin(); - const KIO::UDSEntryList::ConstIterator end = remote_entries.constEnd(); - for(; it!=end; ++it) - { - listEntry(*it); - } + KIO::UDSEntryList::ConstIterator it = remote_entries.constBegin(); + const KIO::UDSEntryList::ConstIterator end = remote_entries.constEnd(); + for (; it != end; ++it) { + listEntry(*it); + } - entry.clear(); - finished(); + entry.clear(); + finished(); } void RemoteProtocol::stat(const QUrl &url) { - qCDebug(KIOREMOTE_LOG) << "RemoteProtocol::stat: " << url; - - QString path = url.path(); - if ( path.isEmpty() || path == QLatin1String("/") ) - { - // The root is "virtual" - it's not a single physical directory - KIO::UDSEntry entry; - m_impl.createTopLevelEntry( entry ); - statEntry( entry ); - finished(); - return; - } - - if (m_impl.isWizardURL(url)) - { - KIO::UDSEntry entry; - if (m_impl.createWizardEntry(entry)) - { - statEntry(entry); - finished(); - } - else - { - error(KIO::ERR_DOES_NOT_EXIST, url.toDisplayString()); - } - return; - } - - int second_slash_idx = url.path().indexOf( '/', 1 ); - const QString root_dirname = url.path().mid( 1, second_slash_idx-1 ); - - if ( second_slash_idx==-1 || ( (int)url.path().length() )==second_slash_idx+1 ) - { - KIO::UDSEntry entry; - if (m_impl.statNetworkFolder(entry, root_dirname)) - { - statEntry(entry); - finished(); - return; - } - } - else - { - QUrl target = m_impl.findBaseURL( root_dirname ); - qCDebug(KIOREMOTE_LOG) << "possible redirection target : " << target; - if ( target.isValid() ) - { - if ( second_slash_idx < 0 ) { - second_slash_idx = url.path().size(); - } - const QString urlPath = url.path().remove(0, second_slash_idx); - if (!urlPath.isEmpty()) { - target.setPath(QStringLiteral("%1/%2").arg(target.path(), urlPath)); - } - qCDebug(KIOREMOTE_LOG) << "complete redirection target : " << target; - redirection( target ); - finished(); - return; - } - } - - error(KIO::ERR_MALFORMED_URL, url.toDisplayString()); + qCDebug(KIOREMOTE_LOG) << "RemoteProtocol::stat: " << url; + + QString path = url.path(); + if (path.isEmpty() || path == QLatin1String("/")) { + // The root is "virtual" - it's not a single physical directory + KIO::UDSEntry entry; + m_impl.createTopLevelEntry(entry); + statEntry(entry); + finished(); + return; + } + + if (m_impl.isWizardURL(url)) { + KIO::UDSEntry entry; + if (m_impl.createWizardEntry(entry)) { + statEntry(entry); + finished(); + } else { + error(KIO::ERR_DOES_NOT_EXIST, url.toDisplayString()); + } + return; + } + + int second_slash_idx = url.path().indexOf('/', 1); + const QString root_dirname = url.path().mid(1, second_slash_idx-1); + + if (second_slash_idx == -1 || ((int)url.path().length()) == second_slash_idx+1) { + KIO::UDSEntry entry; + if (m_impl.statNetworkFolder(entry, root_dirname)) { + statEntry(entry); + finished(); + return; + } + } else { + QUrl target = m_impl.findBaseURL(root_dirname); + qCDebug(KIOREMOTE_LOG) << "possible redirection target : " << target; + if (target.isValid()) { + if (second_slash_idx < 0) { + second_slash_idx = url.path().size(); + } + const QString urlPath = url.path().remove(0, second_slash_idx); + if (!urlPath.isEmpty()) { + target.setPath(QStringLiteral("%1/%2").arg(target.path(), urlPath)); + } + qCDebug(KIOREMOTE_LOG) << "complete redirection target : " << target; + redirection(target); + finished(); + return; + } + } + + error(KIO::ERR_MALFORMED_URL, url.toDisplayString()); } void RemoteProtocol::del(const QUrl &url, bool /*isFile*/) { - qCDebug(KIOREMOTE_LOG) << "RemoteProtocol::del: " << url; + qCDebug(KIOREMOTE_LOG) << "RemoteProtocol::del: " << url; - if (!m_impl.isWizardURL(url) - && m_impl.deleteNetworkFolder(url.fileName())) - { - finished(); - return; - } + if (!m_impl.isWizardURL(url) + && m_impl.deleteNetworkFolder(url.fileName())) { + finished(); + return; + } - error(KIO::ERR_CANNOT_DELETE, url.toDisplayString()); + error(KIO::ERR_CANNOT_DELETE, url.toDisplayString()); } void RemoteProtocol::get(const QUrl &url) { - qCDebug(KIOREMOTE_LOG) << "RemoteProtocol::get: " << url; + qCDebug(KIOREMOTE_LOG) << "RemoteProtocol::get: " << url; - const QString file = m_impl.findDesktopFile( url.fileName() ); - qCDebug(KIOREMOTE_LOG) << "desktop file : " << file; + const QString file = m_impl.findDesktopFile(url.fileName()); + qCDebug(KIOREMOTE_LOG) << "desktop file : " << file; - if (!file.isEmpty()) - { - redirection(QUrl::fromLocalFile(file)); - finished(); - return; - } + if (!file.isEmpty()) { + redirection(QUrl::fromLocalFile(file)); + finished(); + return; + } - error(KIO::ERR_MALFORMED_URL, url.toDisplayString()); + error(KIO::ERR_MALFORMED_URL, url.toDisplayString()); } -void RemoteProtocol::rename(const QUrl &src, const QUrl &dest, - KIO::JobFlags flags) +void RemoteProtocol::rename(const QUrl &src, const QUrl &dest, KIO::JobFlags flags) { - if (src.scheme()!=QLatin1String("remote") || dest.scheme()!=QLatin1String("remote") - || m_impl.isWizardURL(src) || m_impl.isWizardURL(dest)) - { - error(KIO::ERR_UNSUPPORTED_ACTION, src.toDisplayString()); - return; - } - - if (m_impl.renameFolders(src.fileName(), dest.fileName(), flags & KIO::Overwrite)) - { - finished(); - return; - } - - error(KIO::ERR_CANNOT_RENAME, src.toDisplayString()); + if (src.scheme() != QLatin1String("remote") || dest.scheme() != QLatin1String("remote") + || m_impl.isWizardURL(src) || m_impl.isWizardURL(dest)) { + error(KIO::ERR_UNSUPPORTED_ACTION, src.toDisplayString()); + return; + } + + if (m_impl.renameFolders(src.fileName(), dest.fileName(), flags & KIO::Overwrite)) { + finished(); + return; + } + + error(KIO::ERR_CANNOT_RENAME, src.toDisplayString()); } void RemoteProtocol::symlink(const QString &target, const QUrl &dest, KIO::JobFlags flags) { - if (m_impl.changeFolderTarget(dest.fileName(), target, flags & KIO::Overwrite)) - { - finished(); - return; - } + if (m_impl.changeFolderTarget(dest.fileName(), target, flags & KIO::Overwrite)) { + finished(); + return; + } - error(KIO::ERR_CANNOT_SYMLINK, dest.toDisplayString()); + error(KIO::ERR_CANNOT_SYMLINK, dest.toDisplayString()); } diff --git a/kioslave/remote/remoteimpl.h b/kioslave/remote/remoteimpl.h --- a/kioslave/remote/remoteimpl.h +++ b/kioslave/remote/remoteimpl.h @@ -24,33 +24,28 @@ #include #include - - class RemoteImpl { public: - RemoteImpl(); + RemoteImpl(); - void createTopLevelEntry(KIO::UDSEntry &entry) const; - bool createWizardEntry(KIO::UDSEntry &entry) const; - bool isWizardURL(const QUrl &url) const; - bool statNetworkFolder(KIO::UDSEntry &entry, const QString &filename) const; + void createTopLevelEntry(KIO::UDSEntry &entry) const; + bool createWizardEntry(KIO::UDSEntry &entry) const; + bool isWizardURL(const QUrl &url) const; + bool statNetworkFolder(KIO::UDSEntry &entry, const QString &filename) const; - void listRoot(KIO::UDSEntryList& list) const; + void listRoot(KIO::UDSEntryList &list) const; - QUrl findBaseURL(const QString &filename) const; - QString findDesktopFile(const QString &filename) const; + QUrl findBaseURL(const QString &filename) const; + QString findDesktopFile(const QString &filename) const; - bool deleteNetworkFolder(const QString &filename) const; - bool renameFolders(const QString &src, const QString &dest, - bool overwrite) const; - bool changeFolderTarget(const QString &src, const QString &target, - bool overwrite) const; + bool deleteNetworkFolder(const QString &filename) const; + bool renameFolders(const QString &src, const QString &dest, bool overwrite) const; + bool changeFolderTarget(const QString &src, const QString &target, bool overwrite) const; private: - bool findDirectory(const QString &filename, QString &directory) const; - void createEntry(KIO::UDSEntry& entry, const QString &directory, - const QString &file) const; + bool findDirectory(const QString &filename, QString &directory) const; + void createEntry(KIO::UDSEntry &entry, const QString &directory, const QString &file) const; }; #endif diff --git a/kioslave/remote/remoteimpl.cpp b/kioslave/remote/remoteimpl.cpp --- a/kioslave/remote/remoteimpl.cpp +++ b/kioslave/remote/remoteimpl.cpp @@ -35,274 +35,253 @@ RemoteImpl::RemoteImpl() { - const QString path = QStringLiteral("%1/remoteview").arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)); - - QDir dir = path; - if (!dir.exists()) - { - dir.cdUp(); - dir.mkdir(QStringLiteral("remoteview")); - } + const QString path = QStringLiteral("%1/remoteview").arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)); + + QDir dir = path; + if (!dir.exists()) { + dir.cdUp(); + dir.mkdir(QStringLiteral("remoteview")); + } } void RemoteImpl::listRoot(KIO::UDSEntryList &list) const { - qCDebug(KIOREMOTE_LOG) << "RemoteImpl::listRoot"; - - QStringList names_found; - const QStringList dirList = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("remoteview"), QStandardPaths::LocateDirectory); - - QStringList::ConstIterator dirpath = dirList.constBegin(); - const QStringList::ConstIterator end = dirList.constEnd(); - for(; dirpath!=end; ++dirpath) - { - QDir dir = *dirpath; - if (!dir.exists()) continue; - - const QStringList filenames - = dir.entryList( QDir::Files | QDir::Readable ); - - - KIO::UDSEntry entry; - - QStringList::ConstIterator name = filenames.constBegin(); - QStringList::ConstIterator endf = filenames.constEnd(); - - for(; name!=endf; ++name) - { - if (!names_found.contains(*name)) - { - entry.clear(); - createEntry(entry, *dirpath, *name); - list.append(entry); - names_found.append(*name); - } - } - } + qCDebug(KIOREMOTE_LOG) << "RemoteImpl::listRoot"; + + QStringList names_found; + const QStringList dirList = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("remoteview"), + QStandardPaths::LocateDirectory); + + QStringList::ConstIterator dirpath = dirList.constBegin(); + const QStringList::ConstIterator end = dirList.constEnd(); + for (; dirpath != end; ++dirpath) { + QDir dir = *dirpath; + if (!dir.exists()) { + continue; + } + + const QStringList filenames = dir.entryList(QDir::Files | QDir::Readable); + + KIO::UDSEntry entry; + + QStringList::ConstIterator name = filenames.constBegin(); + QStringList::ConstIterator endf = filenames.constEnd(); + + for (; name != endf; ++name) { + if (!names_found.contains(*name)) { + entry.clear(); + createEntry(entry, *dirpath, *name); + list.append(entry); + names_found.append(*name); + } + } + } } bool RemoteImpl::findDirectory(const QString &filename, QString &directory) const { - qCDebug(KIOREMOTE_LOG) << "RemoteImpl::findDirectory"; - - const QStringList dirList = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("remoteview"), QStandardPaths::LocateDirectory); - - QStringList::ConstIterator dirpath = dirList.constBegin(); - const QStringList::ConstIterator end = dirList.constEnd(); - for(; dirpath!=end; ++dirpath) - { - QDir dir = *dirpath; - if (!dir.exists()) continue; - - QStringList filenames - = dir.entryList( QDir::Files | QDir::Readable ); - - QStringList::ConstIterator name = filenames.constBegin(); - QStringList::ConstIterator endf = filenames.constEnd(); - - for(; name!=endf; ++name) - { - if (*name==filename) - { - directory = *dirpath + QLatin1Char('/'); - return true; - } - } - } - - return false; + qCDebug(KIOREMOTE_LOG) << "RemoteImpl::findDirectory"; + + const QStringList dirList = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("remoteview"), + QStandardPaths::LocateDirectory); + + QStringList::ConstIterator dirpath = dirList.constBegin(); + const QStringList::ConstIterator end = dirList.constEnd(); + for (; dirpath != end; ++dirpath) { + QDir dir = *dirpath; + if (!dir.exists()) { + continue; + } + + QStringList filenames = dir.entryList(QDir::Files | QDir::Readable); + + QStringList::ConstIterator name = filenames.constBegin(); + QStringList::ConstIterator endf = filenames.constEnd(); + + for (; name != endf; ++name) { + if (*name == filename) { + directory = *dirpath + QLatin1Char('/'); + return true; + } + } + } + + return false; } QString RemoteImpl::findDesktopFile(const QString &filename) const { - qCDebug(KIOREMOTE_LOG) << "RemoteImpl::findDesktopFile"; + qCDebug(KIOREMOTE_LOG) << "RemoteImpl::findDesktopFile"; - QString directory; - if (findDirectory(filename+".desktop", directory)) - { - return directory+filename+".desktop"; - } + QString directory; + if (findDirectory(filename+".desktop", directory)) { + return directory+filename+".desktop"; + } - return QString(); + return QString(); } QUrl RemoteImpl::findBaseURL(const QString &filename) const { - qCDebug(KIOREMOTE_LOG) << "RemoteImpl::findBaseURL"; + qCDebug(KIOREMOTE_LOG) << "RemoteImpl::findBaseURL"; - const QString file = findDesktopFile(filename); - if (!file.isEmpty()) - { - KDesktopFile desktop( file ); - return QUrl::fromUserInput(desktop.readUrl()); - } + const QString file = findDesktopFile(filename); + if (!file.isEmpty()) { + KDesktopFile desktop(file); + return QUrl::fromUserInput(desktop.readUrl()); + } - return QUrl(); + return QUrl(); } - void RemoteImpl::createTopLevelEntry(KIO::UDSEntry &entry) const { entry.clear(); - entry.insert( KIO::UDSEntry::UDS_NAME, QString::fromLatin1(".")); - entry.insert( KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR); - entry.insert( KIO::UDSEntry::UDS_ACCESS, 0777); - entry.insert( KIO::UDSEntry::UDS_MIME_TYPE, QString::fromLatin1("inode/directory")); - entry.insert( KIO::UDSEntry::UDS_ICON_NAME, QString::fromLatin1("folder-remote")); - entry.insert( KIO::UDSEntry::UDS_USER, QString::fromLatin1("root")); - entry.insert( KIO::UDSEntry::UDS_GROUP, QString::fromLatin1("root")); + entry.insert(KIO::UDSEntry::UDS_NAME, QString::fromLatin1(".")); + entry.insert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR); + entry.insert(KIO::UDSEntry::UDS_ACCESS, 0777); + entry.insert(KIO::UDSEntry::UDS_MIME_TYPE, QString::fromLatin1("inode/directory")); + entry.insert(KIO::UDSEntry::UDS_ICON_NAME, QString::fromLatin1("folder-remote")); + entry.insert(KIO::UDSEntry::UDS_USER, QString::fromLatin1("root")); + entry.insert(KIO::UDSEntry::UDS_GROUP, QString::fromLatin1("root")); } static QUrl findWizardRealURL() { - QUrl url; - KService::Ptr service = KService::serviceByDesktopName(WIZARD_SERVICE); + QUrl url; + KService::Ptr service = KService::serviceByDesktopName(WIZARD_SERVICE); - if (service && service->isValid()) - { - url.setPath(QStandardPaths::locate(QStandardPaths::ApplicationsLocation, - QStringLiteral("%1.desktop").arg(WIZARD_SERVICE))); - } + if (service && service->isValid()) { + url.setPath(QStandardPaths::locate(QStandardPaths::ApplicationsLocation, + QStringLiteral("%1.desktop").arg(WIZARD_SERVICE))); + } - return url; + return url; } bool RemoteImpl::createWizardEntry(KIO::UDSEntry &entry) const { - entry.clear(); + entry.clear(); - QUrl url = findWizardRealURL(); + QUrl url = findWizardRealURL(); - if (!url.isValid()) - { - return false; - } + if (!url.isValid()) { + return false; + } - entry.insert( KIO::UDSEntry::UDS_NAME, i18n("Add Network Folder")); - entry.insert( KIO::UDSEntry::UDS_FILE_TYPE, S_IFREG); - entry.insert( KIO::UDSEntry::UDS_URL, QString::fromLatin1(WIZARD_URL) ); - entry.insert( KIO::UDSEntry::UDS_LOCAL_PATH, url.path()); - entry.insert( KIO::UDSEntry::UDS_ACCESS, 0500); - entry.insert( KIO::UDSEntry::UDS_MIME_TYPE, QString::fromLatin1("application/x-desktop")); - entry.insert( KIO::UDSEntry::UDS_ICON_NAME, QString::fromLatin1("folder-new")); + entry.insert(KIO::UDSEntry::UDS_NAME, i18n("Add Network Folder")); + entry.insert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFREG); + entry.insert(KIO::UDSEntry::UDS_URL, QString::fromLatin1(WIZARD_URL)); + entry.insert(KIO::UDSEntry::UDS_LOCAL_PATH, url.path()); + entry.insert(KIO::UDSEntry::UDS_ACCESS, 0500); + entry.insert(KIO::UDSEntry::UDS_MIME_TYPE, QString::fromLatin1("application/x-desktop")); + entry.insert(KIO::UDSEntry::UDS_ICON_NAME, QString::fromLatin1("folder-new")); - return true; + return true; } bool RemoteImpl::isWizardURL(const QUrl &url) const { - return url==QUrl(WIZARD_URL); + return url == QUrl(WIZARD_URL); } - -void RemoteImpl::createEntry(KIO::UDSEntry &entry, - const QString &directory, +void RemoteImpl::createEntry(KIO::UDSEntry &entry, const QString &directory, const QString &file) const { - qCDebug(KIOREMOTE_LOG) << "RemoteImpl::createEntry"; + qCDebug(KIOREMOTE_LOG) << "RemoteImpl::createEntry"; - QString dir = directory; - if (!dir.endsWith(QLatin1Char('/'))) { - dir += QLatin1Char('/'); - } - KDesktopFile desktop(dir + file); + QString dir = directory; + if (!dir.endsWith(QLatin1Char('/'))) { + dir += QLatin1Char('/'); + } + KDesktopFile desktop(dir + file); - qCDebug(KIOREMOTE_LOG) << "path = " << directory << file; + qCDebug(KIOREMOTE_LOG) << "path = " << directory << file; - entry.clear(); + entry.clear(); - QString new_filename = file; - new_filename.truncate( file.length()-8); + QString new_filename = file; + new_filename.truncate(file.length()-8); - entry.insert( KIO::UDSEntry::UDS_NAME, desktop.readName()); - entry.insert( KIO::UDSEntry::UDS_URL, "remote:/"+new_filename); + entry.insert(KIO::UDSEntry::UDS_NAME, desktop.readName()); + entry.insert(KIO::UDSEntry::UDS_URL, "remote:/"+new_filename); - entry.insert( KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR); - entry.insert( KIO::UDSEntry::UDS_ACCESS, 0500); - entry.insert( KIO::UDSEntry::UDS_MIME_TYPE, QString::fromLatin1("inode/directory")); + entry.insert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR); + entry.insert(KIO::UDSEntry::UDS_ACCESS, 0500); + entry.insert(KIO::UDSEntry::UDS_MIME_TYPE, QString::fromLatin1("inode/directory")); const QString icon = desktop.readIcon(); - entry.insert( KIO::UDSEntry::UDS_ICON_NAME, icon); - entry.insert( KIO::UDSEntry::UDS_LINK_DEST, desktop.readUrl()); - entry.insert( KIO::UDSEntry::UDS_TARGET_URL, desktop.readUrl()); + entry.insert(KIO::UDSEntry::UDS_ICON_NAME, icon); + entry.insert(KIO::UDSEntry::UDS_LINK_DEST, desktop.readUrl()); + entry.insert(KIO::UDSEntry::UDS_TARGET_URL, desktop.readUrl()); } bool RemoteImpl::statNetworkFolder(KIO::UDSEntry &entry, const QString &filename) const { - qCDebug(KIOREMOTE_LOG) << "RemoteImpl::statNetworkFolder: " << filename; + qCDebug(KIOREMOTE_LOG) << "RemoteImpl::statNetworkFolder: " << filename; - QString directory; - if (findDirectory(filename+".desktop", directory)) - { - createEntry(entry, directory, filename+".desktop"); - return true; - } + QString directory; + if (findDirectory(filename+".desktop", directory)) { + createEntry(entry, directory, filename+".desktop"); + return true; + } - return false; + return false; } bool RemoteImpl::deleteNetworkFolder(const QString &filename) const { - qCDebug(KIOREMOTE_LOG) << "RemoteImpl::deleteNetworkFolder: " << filename; + qCDebug(KIOREMOTE_LOG) << "RemoteImpl::deleteNetworkFolder: " << filename; - QString directory; - if (findDirectory(filename+".desktop", directory)) - { - qCDebug(KIOREMOTE_LOG) << "Removing " << directory << filename << ".desktop"; - return QFile::remove(directory+filename+".desktop"); - } + QString directory; + if (findDirectory(filename+".desktop", directory)) { + qCDebug(KIOREMOTE_LOG) << "Removing " << directory << filename << ".desktop"; + return QFile::remove(directory+filename+".desktop"); + } - return false; + return false; } -bool RemoteImpl::renameFolders(const QString &src, const QString &dest, - bool overwrite) const +bool RemoteImpl::renameFolders(const QString &src, const QString &dest, bool overwrite) const { - qCDebug(KIOREMOTE_LOG) << "RemoteImpl::renameFolders: " - << src << ", " << dest << endl; - - QString directory; - if (findDirectory(src+".desktop", directory)) - { - if (!overwrite && QFile::exists(directory+dest+".desktop")) - { - return false; - } - - qCDebug(KIOREMOTE_LOG) << "Renaming " << directory << src << ".desktop"; - QDir dir(directory); - bool res = dir.rename(src+".desktop", dest+".desktop"); - if (res) - { - KDesktopFile desktop(directory+dest+".desktop"); - desktop.desktopGroup().writeEntry("Name", dest); - } - return res; - } - - return false; + qCDebug(KIOREMOTE_LOG) << "RemoteImpl::renameFolders: " + << src << ", " << dest << endl; + + QString directory; + if (findDirectory(src+".desktop", directory)) { + if (!overwrite && QFile::exists(directory+dest+".desktop")) { + return false; + } + + qCDebug(KIOREMOTE_LOG) << "Renaming " << directory << src << ".desktop"; + QDir dir(directory); + bool res = dir.rename(src+".desktop", dest+".desktop"); + if (res) { + KDesktopFile desktop(directory+dest+".desktop"); + desktop.desktopGroup().writeEntry("Name", dest); + } + return res; + } + + return false; } -bool RemoteImpl::changeFolderTarget(const QString &src, const QString &target, - bool overwrite) const +bool RemoteImpl::changeFolderTarget(const QString &src, const QString &target, bool overwrite) const { - qCDebug(KIOREMOTE_LOG) << "RemoteImpl::changeFolderTarget: " - << src << ", " << target << endl; - - QString directory; - if (findDirectory(src+".desktop", directory)) - { - if (!overwrite || !QFile::exists(directory+src+".desktop")) - { - return false; - } - - qCDebug(KIOREMOTE_LOG) << "Changing target " << directory << src << ".desktop"; - KDesktopFile desktop(directory+src+".desktop"); - desktop.desktopGroup().writeEntry("URL", target); - return true; - } - - return false; + qCDebug(KIOREMOTE_LOG) << "RemoteImpl::changeFolderTarget: " + << src << ", " << target << endl; + + QString directory; + if (findDirectory(src+".desktop", directory)) { + if (!overwrite || !QFile::exists(directory+src+".desktop")) { + return false; + } + + qCDebug(KIOREMOTE_LOG) << "Changing target " << directory << src << ".desktop"; + KDesktopFile desktop(directory+src+".desktop"); + desktop.desktopGroup().writeEntry("URL", target); + return true; + } + + return false; } -