Commit 125c7d0e authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Switch to global fileWatcher

parent 6e225f36
Pipeline #117860 passed with stage
in 8 minutes and 36 seconds
......@@ -5,17 +5,17 @@
#include "filewatcher.hpp"
#include <KDirWatch>
#include <QFileInfo>
FileWatcher::FileWatcher(QObject *parent)
: QObject(parent)
, m_fileWatcher(new KDirWatch())
{
// Init clip modification tracker
m_modifiedTimer.setInterval(1500);
connect(m_fileWatcher.get(), &KDirWatch::dirty, this, &FileWatcher::slotUrlModified);
connect(m_fileWatcher.get(), &KDirWatch::deleted, this, &FileWatcher::slotUrlMissing);
connect(m_fileWatcher.get(), &KDirWatch::created, this, &FileWatcher::slotUrlAdded);
connect(KDirWatch::self(), &KDirWatch::dirty, this, &FileWatcher::slotUrlModified);
connect(KDirWatch::self(), &KDirWatch::deleted, this, &FileWatcher::slotUrlMissing);
connect(KDirWatch::self(), &KDirWatch::created, this, &FileWatcher::slotUrlAdded);
connect(&m_modifiedTimer, &QTimer::timeout, this, &FileWatcher::slotProcessModifiedUrls);
}
......@@ -25,7 +25,7 @@ void FileWatcher::addFile(const QString &binId, const QString &url)
return;
}
if (m_occurences.count(url) == 0) {
m_fileWatcher->addFile(url);
KDirWatch::self()->addFile(url);
}
m_occurences[url].insert(binId);
m_binClipPaths[binId] = url;
......@@ -40,7 +40,7 @@ void FileWatcher::removeFile(const QString &binId)
m_occurences[url].erase(binId);
m_binClipPaths.erase(binId);
if (m_occurences[url].empty()) {
m_fileWatcher->removeFile(url);
KDirWatch::self()->removeFile(url);
m_occurences.erase(url);
}
}
......@@ -75,7 +75,7 @@ void FileWatcher::slotProcessModifiedUrls()
{
auto checkList = m_modifiedUrls;
for (const QString &path : checkList) {
if (m_fileWatcher->ctime(path).msecsTo(QDateTime::currentDateTime()) > 2000) {
if (KDirWatch::self()->ctime(path).msecsTo(QDateTime::currentDateTime()) > 2000) {
for (const QString &id : m_occurences[path]) {
emit binClipModified(id);
}
......@@ -89,17 +89,17 @@ void FileWatcher::slotProcessModifiedUrls()
void FileWatcher::clear()
{
m_fileWatcher->stopScan();
KDirWatch::self()->stopScan();
for (const auto &f : m_occurences) {
m_fileWatcher->removeFile(f.first);
KDirWatch::self()->removeFile(f.first);
}
m_occurences.clear();
m_modifiedUrls.clear();
m_binClipPaths.clear();
m_fileWatcher->startScan();
KDirWatch::self()->startScan();
}
bool FileWatcher::contains(const QString &path) const
{
return m_fileWatcher->contains(path);
return KDirWatch::self()->contains(path);
}
......@@ -7,7 +7,6 @@
#define FILEWATCHER_H
#include "definitions.h"
#include <KDirWatch>
#include <QTimer>
#include <unordered_map>
#include <unordered_set>
......@@ -47,8 +46,6 @@ private slots:
void slotProcessModifiedUrls();
private:
// This is a handle to the watcher singleton, not owned by this class.
std::unique_ptr<KDirWatch> m_fileWatcher;
// A list with urls as keys, and the corresponding clip ids as value
std::unordered_map<QString, std::unordered_set<QString>> m_occurences;
// keys are binId, keys are stored paths
......
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