/** * Creates a new instance of watcher thread. The watcher is not started but keeps the references * to the directory to be watched, and the associated filter. The lastPass member is used to * detect modification/creation of files between two passes. */ Watcher::Watcher(QString url, bool recursive, Filter *filterP) : QThread(), m_watchSem(1) { m_url = url; m_recursive = recursive; m_filterP = filterP; m_lastPass = QDateTime::currentDateTime(); // connect the activity signals/slots connect(this, SIGNAL(displayActivity(QString)), filterP, SIGNAL(displayActivity(QString))); connect(this, SIGNAL(displayProgress(int,int,int)), filterP, SIGNAL(displayProgress(int,int,int))); // connect the scan results signals/slots connect(this, SIGNAL(fileAdded(QString)), filterP, SLOT(fileAdded(QString))); connect(this, SIGNAL(fileDeleted(QString)), filterP, SLOT(fileDeleted(QString))); connect(this, SIGNAL(fileModified(QString)), filterP, SLOT(fileModified(QString))); connect(this, SIGNAL(directoryAdded(QString)), filterP, SLOT(directoryAdded(QString))); connect(this, SIGNAL(directoryDeleted(QString)), filterP, SLOT(directoryDeleted(QString))); connect(this, SIGNAL(directoryModified(QString)), filterP, SLOT(directoryModified(QString))); }
void MailCache::addDirectory(Directory* dir) { if (dir == NULL) return; if (dir->getId() == -2) { dir->setId(nextDirectoryId()); } if (!directoryList.contains(dir)) { directoryList.append(dir); emit directoryAdded(dir); } }
/** * Returns in m_newFiles the newly found sub directories of root. */ void Watcher::getNewSubDirectories(QString root) { if (root.isEmpty() || m_stop) return; // add new root to the list of directories m_newFiles.addPath(root, true); // signal new directory directoryAdded(root); // create a directory QDirExt rootDir(root); // get the directory entries QStringList entries = rootDir.entryList(); if (entries.isEmpty()) return; // give the user a hint about what's going on down here displayActivity(tr("Exploring directory %1").arg(root)); // walk down recursively through the directories for (QList<QString>::iterator i = entries.begin(); !m_stop && i != entries.end(); i++) { QString entryPath = root; entryPath.append(QDirExt::separator(root)); entryPath.append(*i); QFileInfoExt entry(entryPath); if (entry.isHidden()) continue; if (entry.isDir()) { // recursively go through children dirs if required if (m_recursive && !m_files.findPath(entryPath)) { getNewSubDirectories(entryPath); #ifdef _VERBOSE_WATCHER qDebug() << "Detected new directory " << entryPath; #endif } } } }