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 @@ -22,22 +22,20 @@ #include #include +class KDirWatch; + class RemoteDirNotify : public QObject { Q_OBJECT public: RemoteDirNotify(); private slots: - void FilesAdded (const QString &directory); - void FilesRemoved (const QStringList &fileList); - void FilesChanged (const QStringList &fileList); + void slotRemoteChanged(); private: - QUrl toRemoteURL(const QUrl &url); - QList toRemoteURLList(const QStringList &list); - QUrl m_baseURL; + KDirWatch *m_dirWatch; }; #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 @@ -19,118 +19,25 @@ #include "remotedirnotify.h" #include "../debug.h" -#include #include -#include +#include #include 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))); -} - -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(); -} - -QList RemoteDirNotify::toRemoteURLList(const QStringList &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(QUrl::fromLocalFile(directory)); - - if (new_dir.isValid()) - { - org::kde::KDirNotify::emitFilesAdded(new_dir); - } -} - -// This hack is required because of the way we manage .desktop files with -// Forwarding Slaves, their URL is out of the ioslave (most remote:/ files -// 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 QList &list) -{ - QList notified; - - QList::const_iterator it = list.begin(); - QList::const_iterator end = list.end(); + m_dirWatch = new KDirWatch(this); + m_dirWatch->addDir(path, KDirWatch::WatchFiles); - for (; it!=end; ++it) - { - QUrl url = KIO::upUrl(*it); - - if (!notified.contains(url)) - { - org::kde::KDirNotify::emitFilesAdded(url); - notified.append(url); - } - } + connect(m_dirWatch, &KDirWatch::created, this, &RemoteDirNotify::slotRemoteChanged); + connect(m_dirWatch, &KDirWatch::deleted, this, &RemoteDirNotify::slotRemoteChanged); + connect(m_dirWatch, &KDirWatch::dirty, this, &RemoteDirNotify::slotRemoteChanged); } - -void RemoteDirNotify::FilesRemoved(const QStringList &fileList) +void RemoteDirNotify::slotRemoteChanged() { - qCDebug(KIOREMOTE_LOG) << "RemoteDirNotify::FilesRemoved"; - - QList new_list = toRemoteURLList(fileList); - - 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"; - - QList new_list = toRemoteURLList(fileList); - - if (!new_list.isEmpty()) - { - //KDirNotify_stub notifier("*", "*"); - //notifier.FilesChanged( new_list ); - evil_hack(new_list); - } + org::kde::KDirNotify::emitFilesAdded(QUrl("remote:/")); }