Commit 2a3b74df authored by Elvis Angelaccio's avatar Elvis Angelaccio

[kioslave/remote] Fix broken kded module

Summary:
Commit 72e39f08 broke the kded module. Turns out that the old code
just forced a refresh of the `remote:/` QUrl, so we can just do that
explicitly and remove all the old cruft.

While at it, use a KDirWatcher that just watches the
`.local/share/remote/` folder, instead of checking *every* unrelated
QUrl emitted by KDirNotify.

Test Plan:
Adding/deleting/editing .desktop files in `.local/share/remoteview` now
automatically reloads the `remote:/` url in Dolphin or Folder View.

Reviewers: #plasma

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D4573
parent 3d960a2f
......@@ -19,118 +19,25 @@
#include "remotedirnotify.h"
#include "../debug.h"
#include <kdesktopfile.h>
#include <kdirnotify.h>
#include <KIO/Global>
#include <KDirWatch>
#include <QtDBus/QtDBus>
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<QUrl> RemoteDirNotify::toRemoteURLList(const QStringList &list)
{
QList<QUrl> 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<QUrl> &list)
{
QList<QUrl> notified;
QList<QUrl>::const_iterator it = list.begin();
QList<QUrl>::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<QUrl> 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<QUrl> 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:/"));
}
......@@ -22,6 +22,8 @@
#include <QUrl>
#include <QtCore/QObject>
class KDirWatch;
class RemoteDirNotify : public QObject
{
Q_OBJECT
......@@ -30,14 +32,10 @@ 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<QUrl> toRemoteURLList(const QStringList &list);
QUrl m_baseURL;
KDirWatch *m_dirWatch;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment