14#include <QCoreApplication>
24 if (!connect(&m_watcher, SIGNAL(directoryChanged(QString)),
this, SLOT(slotDirectoryChanged(QString)) ))
26 std::cerr <<
"LimaFileSystemWatcherPrivate::LimaFileSystemWatcherPrivate failed to connect directoryChanged signal" << std::endl;
28 if (!connect(&m_watcher, SIGNAL(
fileChanged(QString)),
this, SLOT(slotFileChanged(QString)) ))
30 std::cerr <<
"LimaFileSystemWatcherPrivate::LimaFileSystemWatcherPrivate failed to connect fileChanged signal" << std::endl;
39void LimaFileSystemWatcherPrivate::delay(
int millisecondsToWait )
41 QTime dieTime = QTime::currentTime().addMSecs( millisecondsToWait );
42 while( QTime::currentTime() < dieTime )
44 QCoreApplication::processEvents( QEventLoop::AllEvents, 100 );
47void LimaFileSystemWatcherPrivate::slotDirectoryChanged (
const QString & path )
50 std::cerr <<
"LimaFileSystemWatcherPrivate::slotDirectoryChanged" << path.toUtf8().constData() << std::endl;
51 QMutexLocker locker(&m_pathToDeletedFileMapMutex);
52 if (m_pathToDeletedFileMap.contains(path))
55 QList<QString> files = m_pathToDeletedFileMap.values(path);
56 for(
auto& file : files)
59 if (QFileInfo::exists(file))
64 m_pathToDeletedFileMap.remove(path, file);
66 if (!m_pathToDeletedFileMap.contains(path))
68 m_watcher.removePath(path);
70 std::cerr <<
"LimaFileSystemWatcherPrivate::slotDirectoryChanged watching again" << file.toUtf8().constData() << std::endl ;
72 m_watcher.addPath(file);
80void LimaFileSystemWatcherPrivate::slotFileChanged (
const QString & path )
82 std::cerr <<
"LimaFileSystemWatcherPrivate::slotFileChanged " << path.toUtf8().constData() << std::endl;
85 if (!QFileInfo::exists(path))
87 std::cerr <<
"LimaFileSystemWatcherPrivate::slotFileChanged removed" << path.toUtf8().constData() << std::endl;
88 QMutexLocker locker(&m_pathToDeletedFileMapMutex);
91 m_watcher.removePath(path);
93 QString dir = QFileInfo(path).absoluteDir().absolutePath();
95 m_pathToDeletedFileMap.insert(dir, path);
97 m_watcher.addPath(dir);
100 std::cerr <<
"LimaFileSystemWatcherPrivate::slotFileChanged emiting fileChanged from private " << path.toUtf8().constData() << std::endl;
109 std::cerr <<
"LimaFileSystemWatcher::LimaFileSystemWatcher failed to connect fileChanged signal" << std::endl;
118 std::cerr <<
"LimaFileSystemWatcher::LimaFileSystemWatcher failed to connect fileChanged signal" << std::endl;
120 m_d->m_watcher.removePaths(m_d->m_watcher.directories());
121 m_d->m_watcher.removePaths(m_d->m_watcher.files());
122 m_d->m_watcher.addPaths(other.m_d->m_watcher.directories());
123 m_d->m_watcher.addPaths(other.m_d->m_watcher.files());
133 if(!m_d->m_watcher.files().contains(path))
134 m_d->m_watcher.addPath(path);
139 m_d->m_watcher.removePath(path);
144 m_d->m_watcher.removePaths(m_d->m_watcher.directories());
145 m_d->m_watcher.removePaths(m_d->m_watcher.files());
146 m_d->m_watcher.addPaths(other.m_d->m_watcher.directories());
147 m_d->m_watcher.addPaths(other.m_d->m_watcher.files());
153 return m_d->m_watcher.directories() == other.m_d->m_watcher.directories()
154 && m_d->m_watcher.files() == other.m_d->m_watcher.files();
LimaFileSystemWatcherPrivate(LimaFileSystemWatcher *q, QObject *parent=0)
virtual ~LimaFileSystemWatcherPrivate()
void fileChanged(const QString &path)
LimaFileSystemWatcher extends QFileSystemWatcher to work on replaced files
void addPath(const QString &path)
void fileChanged(const QString &path)
This signal is emited whenever path change, either modified, suppressed or recreated.
LimaFileSystemWatcher(QObject *parent=0)
void removePath(const QString &path)
bool operator==(const LimaFileSystemWatcher &other)
LimaFileSystemWatcher & operator=(const LimaFileSystemWatcher &other)