diff --git a/kioslave/remote/kdedmodule/remotedirnotify.cpp b/kioslave/remote/kdedmodule/remotedirnotify.cpp index 808707c68..acf529704 100644 --- a/kioslave/remote/kdedmodule/remotedirnotify.cpp +++ b/kioslave/remote/kdedmodule/remotedirnotify.cpp @@ -1,136 +1,43 @@ /* This file is part of the KDE Project Copyright (c) 2004 Kévin Ottens This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #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:/")); } diff --git a/kioslave/remote/kdedmodule/remotedirnotify.h b/kioslave/remote/kdedmodule/remotedirnotify.h index 20125df51..e15572b78 100644 --- a/kioslave/remote/kdedmodule/remotedirnotify.h +++ b/kioslave/remote/kdedmodule/remotedirnotify.h @@ -1,43 +1,41 @@ /* This file is part of the KDE Project Copyright (c) 2004 Kévin Ottens This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef REMOTEDIRNOTIFY_H #define REMOTEDIRNOTIFY_H #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