From 72e39f083a103e0887624482d6a0ce8b0556dd5e Mon Sep 17 00:00:00 2001 From: Elvis Angelaccio Date: Fri, 4 Nov 2016 11:27:26 +0100 Subject: [PATCH] [kioslave/remote] Port away from kdelibs4support Differential Revision: https://phabricator.kde.org/D3243 --- kioslave/remote/CMakeLists.txt | 2 +- kioslave/remote/kdedmodule/CMakeLists.txt | 2 +- .../remote/kdedmodule/remotedirnotify.cpp | 66 ++++++++----------- kioslave/remote/kdedmodule/remotedirnotify.h | 8 +-- .../kdedmodule/remotedirnotifymodule.cpp | 4 -- kioslave/remote/kio_remote.cpp | 12 ++-- kioslave/remote/remoteimpl.cpp | 40 ++++++----- kioslave/remote/remoteimpl.h | 6 +- 8 files changed, 63 insertions(+), 77 deletions(-) diff --git a/kioslave/remote/CMakeLists.txt b/kioslave/remote/CMakeLists.txt index 558d2c6a2..1119cfc51 100644 --- a/kioslave/remote/CMakeLists.txt +++ b/kioslave/remote/CMakeLists.txt @@ -14,7 +14,7 @@ ecm_qt_declare_logging_category(kio_remote_SRCS HEADER debug.h DEFAULT_SEVERITY Info) add_library(kio_remote MODULE ${kio_remote_SRCS}) -target_link_libraries(kio_remote KF5::KIOCore KF5::KDELibs4Support) +target_link_libraries(kio_remote KF5::KIOCore KF5::I18n) install(TARGETS kio_remote DESTINATION ${KDE_INSTALL_PLUGINDIR} ) install( FILES remote.protocol DESTINATION ${KDE_INSTALL_KSERVICES5DIR} ) diff --git a/kioslave/remote/kdedmodule/CMakeLists.txt b/kioslave/remote/kdedmodule/CMakeLists.txt index 493d8ea8c..cbf481fb3 100644 --- a/kioslave/remote/kdedmodule/CMakeLists.txt +++ b/kioslave/remote/kdedmodule/CMakeLists.txt @@ -1,6 +1,6 @@ add_library(remotedirnotify MODULE remotedirnotify.cpp remotedirnotifymodule.cpp ../debug.cpp) kcoreaddons_desktop_to_json(remotedirnotify remotedirnotify.desktop) -target_link_libraries(remotedirnotify KF5::DBusAddons KF5::KIOCore KF5::KDELibs4Support) +target_link_libraries(remotedirnotify KF5::DBusAddons KF5::KIOCore) install(TARGETS remotedirnotify DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/kded ) diff --git a/kioslave/remote/kdedmodule/remotedirnotify.cpp b/kioslave/remote/kdedmodule/remotedirnotify.cpp index 64397403f..808707c68 100644 --- a/kioslave/remote/kdedmodule/remotedirnotify.cpp +++ b/kioslave/remote/kdedmodule/remotedirnotify.cpp @@ -19,19 +19,15 @@ #include "remotedirnotify.h" #include "../debug.h" -#include -#include -#include #include #include +#include #include RemoteDirNotify::RemoteDirNotify() { - KGlobal::dirs()->addResourceType("remote_entries", "data", "remoteview"); - - const QString path = KGlobal::dirs()->saveLocation("remote_entries"); + const QString path = QStringLiteral("%1/remoteview").arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)); m_baseURL.setPath(path); QDBusConnection::sessionBus().connect(QString(), QString(), QStringLiteral("org.kde.KDirNotify"), @@ -42,48 +38,42 @@ RemoteDirNotify::RemoteDirNotify() QStringLiteral("FilesChanged"), this, SLOT(FilesChanged(QStringList))); } -KUrl RemoteDirNotify::toRemoteURL(const KUrl &url) +QUrl RemoteDirNotify::toRemoteURL(const QUrl &url) { qCDebug(KIOREMOTE_LOG) << "RemoteDirNotify::toRemoteURL(" << url << ")"; if ( m_baseURL.isParentOf(url) ) { - QString path = KUrl::relativePath(m_baseURL.path(), - url.path()); - KUrl result("remote:/"+path); - result.cleanPath(); + 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 => KUrl()"; - return KUrl(); + qCDebug(KIOREMOTE_LOG) << "result => QUrl()"; + return QUrl(); } -KUrl::List RemoteDirNotify::toRemoteURLList(const KUrl::List &list) +QList RemoteDirNotify::toRemoteURLList(const QStringList &list) { - KUrl::List new_list; - - KUrl::List::const_iterator it = list.begin(); - KUrl::List::const_iterator end = list.end(); - - for (; it!=end; ++it) - { - KUrl url = toRemoteURL(*it); - - if (url.isValid()) - { - new_list.append(url); - } - } - - return new_list; + QList urls; + for (const QString &file : list) { + QUrl url = toRemoteURL(QUrl::fromLocalFile(file)); + if (url.isValid()) { + urls.append(url); + } + } + + return urls; } void RemoteDirNotify::FilesAdded(const QString &directory) { qCDebug(KIOREMOTE_LOG) << "RemoteDirNotify::FilesAdded"; - QUrl new_dir = toRemoteURL(directory); + QUrl new_dir = toRemoteURL(QUrl::fromLocalFile(directory)); if (new_dir.isValid()) { @@ -96,16 +86,16 @@ void RemoteDirNotify::FilesAdded(const QString &directory) // have a file:/ based UDS_URL so that they are executed correctly. // Hence, FilesRemoved and FilesChanged does nothing... We're forced to use // FilesAdded to re-list the modified directory. -inline void evil_hack(const KUrl::List &list) +inline void evil_hack(const QList &list) { - KUrl::List notified; + QList notified; - KUrl::List::const_iterator it = list.begin(); - KUrl::List::const_iterator end = list.end(); + QList::const_iterator it = list.begin(); + QList::const_iterator end = list.end(); for (; it!=end; ++it) { - QUrl url = (*it).upUrl(); + QUrl url = KIO::upUrl(*it); if (!notified.contains(url)) { @@ -120,7 +110,7 @@ void RemoteDirNotify::FilesRemoved(const QStringList &fileList) { qCDebug(KIOREMOTE_LOG) << "RemoteDirNotify::FilesRemoved"; - KUrl::List new_list = toRemoteURLList(fileList); + QList new_list = toRemoteURLList(fileList); if (!new_list.isEmpty()) { @@ -134,7 +124,7 @@ void RemoteDirNotify::FilesChanged(const QStringList &fileList) { qCDebug(KIOREMOTE_LOG) << "RemoteDirNotify::FilesChanged"; - KUrl::List new_list = toRemoteURLList(fileList); + QList new_list = toRemoteURLList(fileList); if (!new_list.isEmpty()) { diff --git a/kioslave/remote/kdedmodule/remotedirnotify.h b/kioslave/remote/kdedmodule/remotedirnotify.h index d8c0c3afd..20125df51 100644 --- a/kioslave/remote/kdedmodule/remotedirnotify.h +++ b/kioslave/remote/kdedmodule/remotedirnotify.h @@ -19,7 +19,7 @@ #ifndef REMOTEDIRNOTIFY_H #define REMOTEDIRNOTIFY_H -#include +#include #include class RemoteDirNotify : public QObject @@ -35,9 +35,9 @@ private slots: void FilesChanged (const QStringList &fileList); private: - KUrl toRemoteURL(const KUrl &url); - KUrl::List toRemoteURLList(const KUrl::List &list); - KUrl m_baseURL; + QUrl toRemoteURL(const QUrl &url); + QList toRemoteURLList(const QStringList &list); + QUrl m_baseURL; }; #endif diff --git a/kioslave/remote/kdedmodule/remotedirnotifymodule.cpp b/kioslave/remote/kdedmodule/remotedirnotifymodule.cpp index 3190dfff0..65ab0a14a 100644 --- a/kioslave/remote/kdedmodule/remotedirnotifymodule.cpp +++ b/kioslave/remote/kdedmodule/remotedirnotifymodule.cpp @@ -18,10 +18,6 @@ #include "remotedirnotifymodule.h" -#include -#include -#include - #include //#include diff --git a/kioslave/remote/kio_remote.cpp b/kioslave/remote/kio_remote.cpp index cb4d07500..050721096 100644 --- a/kioslave/remote/kio_remote.cpp +++ b/kioslave/remote/kio_remote.cpp @@ -61,14 +61,15 @@ void RemoteProtocol::listDir(const QUrl &url) int second_slash_idx = url.path().indexOf( '/', 1 ); const QString root_dirname = url.path().mid( 1, second_slash_idx-1 ); - KUrl target = m_impl.findBaseURL( root_dirname ); + 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(); } - target.addPath( url.path().remove(0, second_slash_idx) ); + target = target.adjusted(QUrl::StripTrailingSlash); + target.setPath(target.path() + '/' + ( url.path().remove(0, second_slash_idx) )); qCDebug(KIOREMOTE_LOG) << "complete redirection target : " << target; redirection(target); finished(); @@ -149,7 +150,7 @@ void RemoteProtocol::stat(const QUrl &url) } else { - KUrl target = m_impl.findBaseURL( root_dirname ); + QUrl target = m_impl.findBaseURL( root_dirname ); qCDebug(KIOREMOTE_LOG) << "possible redirection target : " << target; if ( target.isValid() ) { @@ -157,7 +158,8 @@ void RemoteProtocol::stat(const QUrl &url) second_slash_idx = url.path().size(); } qCDebug(KIOREMOTE_LOG) << "complete redirection target : " << target; - target.addPath( url.path().remove( 0, second_slash_idx ) ); + target = target.adjusted(QUrl::StripTrailingSlash); + target.setPath(target.path() + '/' + ( url.path().remove( 0, second_slash_idx ) )); redirection( target ); finished(); return; @@ -190,7 +192,7 @@ void RemoteProtocol::get(const QUrl &url) if (!file.isEmpty()) { - KUrl desktop; + QUrl desktop; desktop.setPath(file); redirection(desktop); diff --git a/kioslave/remote/remoteimpl.cpp b/kioslave/remote/remoteimpl.cpp index 56ce13c34..f0ce37da3 100644 --- a/kioslave/remote/remoteimpl.cpp +++ b/kioslave/remote/remoteimpl.cpp @@ -20,13 +20,10 @@ #include "remoteimpl.h" #include "debug.h" -#include -#include #include #include -#include -#include #include +#include #include #include @@ -38,9 +35,7 @@ RemoteImpl::RemoteImpl() { - KGlobal::dirs()->addResourceType("remote_entries", "data", "remoteview"); - - const QString path = KGlobal::dirs()->saveLocation("remote_entries"); + const QString path = QStringLiteral("%1/remoteview").arg(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation)); QDir dir = path; if (!dir.exists()) @@ -55,7 +50,7 @@ void RemoteImpl::listRoot(KIO::UDSEntryList &list) const qCDebug(KIOREMOTE_LOG) << "RemoteImpl::listRoot"; QStringList names_found; - const QStringList dirList = KGlobal::dirs()->resourceDirs("remote_entries"); + const QStringList dirList = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("remoteview"), QStandardPaths::LocateDirectory); QStringList::ConstIterator dirpath = dirList.constBegin(); const QStringList::ConstIterator end = dirList.constEnd(); @@ -90,7 +85,7 @@ bool RemoteImpl::findDirectory(const QString &filename, QString &directory) cons { qCDebug(KIOREMOTE_LOG) << "RemoteImpl::findDirectory"; - const QStringList dirList = KGlobal::dirs()->resourceDirs("remote_entries"); + const QStringList dirList = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("remoteview"), QStandardPaths::LocateDirectory); QStringList::ConstIterator dirpath = dirList.constBegin(); const QStringList::ConstIterator end = dirList.constEnd(); @@ -134,7 +129,7 @@ QString RemoteImpl::findDesktopFile(const QString &filename) const return QString(); } -KUrl RemoteImpl::findBaseURL(const QString &filename) const +QUrl RemoteImpl::findBaseURL(const QString &filename) const { qCDebug(KIOREMOTE_LOG) << "RemoteImpl::findBaseURL"; @@ -142,10 +137,10 @@ KUrl RemoteImpl::findBaseURL(const QString &filename) const if (!file.isEmpty()) { KDesktopFile desktop( file ); - return desktop.readUrl(); + return QUrl::fromLocalFile(desktop.readUrl()); } - return KUrl(); + return QUrl(); } @@ -161,16 +156,15 @@ void RemoteImpl::createTopLevelEntry(KIO::UDSEntry &entry) const entry.insert( KIO::UDSEntry::UDS_GROUP, QString::fromLatin1("root")); } -static KUrl findWizardRealURL() +static QUrl findWizardRealURL() { - KUrl url; + QUrl url; KService::Ptr service = KService::serviceByDesktopName(WIZARD_SERVICE); if (service && service->isValid()) { - url.setPath( KStandardDirs::locate("apps", - service->entryPath()) - ); + url.setPath(QStandardPaths::locate(QStandardPaths::ApplicationsLocation, + QStringLiteral("%1.desktop").arg(WIZARD_SERVICE))); } return url; @@ -180,7 +174,7 @@ bool RemoteImpl::createWizardEntry(KIO::UDSEntry &entry) const { entry.clear(); - KUrl url = findWizardRealURL(); + QUrl url = findWizardRealURL(); if (!url.isValid()) { @@ -198,9 +192,9 @@ bool RemoteImpl::createWizardEntry(KIO::UDSEntry &entry) const return true; } -bool RemoteImpl::isWizardURL(const KUrl &url) const +bool RemoteImpl::isWizardURL(const QUrl &url) const { - return url==KUrl(WIZARD_URL); + return url==QUrl(WIZARD_URL); } @@ -210,7 +204,11 @@ void RemoteImpl::createEntry(KIO::UDSEntry &entry, { qCDebug(KIOREMOTE_LOG) << "RemoteImpl::createEntry"; - KDesktopFile desktop(directory+file); + QString dir = directory; + if (!dir.endsWith(QLatin1Char('/'))) { + dir += QLatin1Char('/'); + } + KDesktopFile desktop(dir + file); qCDebug(KIOREMOTE_LOG) << "path = " << directory << file; diff --git a/kioslave/remote/remoteimpl.h b/kioslave/remote/remoteimpl.h index 6b512900a..be7063eb6 100644 --- a/kioslave/remote/remoteimpl.h +++ b/kioslave/remote/remoteimpl.h @@ -22,7 +22,7 @@ #include #include -#include +#include @@ -33,12 +33,12 @@ public: void createTopLevelEntry(KIO::UDSEntry &entry) const; bool createWizardEntry(KIO::UDSEntry &entry) const; - bool isWizardURL(const KUrl &url) const; + bool isWizardURL(const QUrl &url) const; bool statNetworkFolder(KIO::UDSEntry &entry, const QString &filename) const; void listRoot(KIO::UDSEntryList& list) const; - KUrl findBaseURL(const QString &filename) const; + QUrl findBaseURL(const QString &filename) const; QString findDesktopFile(const QString &filename) const; bool deleteNetworkFolder(const QString &filename) const;