QPollingFileSystemWatcherEngine Class Reference

Inheritance diagram for QPollingFileSystemWatcherEngine:

Inheritance graph
[legend]
Collaboration diagram for QPollingFileSystemWatcherEngine:

Collaboration graph
[legend]
List of all members.

Detailed Description

Definition at line 46 of file qfilesystemwatcher.cpp.

Public Member Functions

 QPollingFileSystemWatcherEngine ()
void run ()
QStringList addPaths (const QStringList &paths, QStringList *files, QStringList *directories)
QStringList removePaths (const QStringList &paths, QStringList *files, QStringList *directories)
void stop ()

Private Slots

void timeout ()

Private Attributes

QMutex mutex
QHash< QString, QDateTimefiles
QHash< QString, QDateTimedirectories


Constructor & Destructor Documentation

QPollingFileSystemWatcherEngine::QPollingFileSystemWatcherEngine (  ) 

Definition at line 67 of file qfilesystemwatcher.cpp.

References QObject::moveToThread().

00068 {
00069     moveToThread(this);
00070 }

Here is the call graph for this function:


Member Function Documentation

void QPollingFileSystemWatcherEngine::run (  )  [virtual]

This method is pure virtual and must be implemented in derived classes in order to do useful work. Returning from this method will end the execution of the thread.

See also:
wait()

Implements QThread.

Definition at line 72 of file qfilesystemwatcher.cpp.

References QObject::connect(), QThread::exec(), PollingInterval, SIGNAL, SLOT, QTimer::start(), and timeout().

00073 {
00074     QTimer timer;
00075     connect(&timer, SIGNAL(timeout()), SLOT(timeout()));
00076     timer.start(PollingInterval);
00077     (void) exec();
00078 }

Here is the call graph for this function:

QStringList QPollingFileSystemWatcherEngine::addPaths ( const QStringList paths,
QStringList files,
QStringList directories 
) [virtual]

Implements QFileSystemWatcherEngine.

Definition at line 80 of file qfilesystemwatcher.cpp.

References QHash< Key, T >::contains(), directories, QFileInfo::exists(), files, QHash< Key, T >::insert(), QFileInfo::isDir(), QFileInfo::lastModified(), mutex, p, path, and QThread::start().

00083 {
00084     QMutexLocker locker(&mutex);
00085     QStringList p = paths;
00086     QMutableListIterator<QString> it(p);
00087     while (it.hasNext()) {
00088         QString path = it.next();
00089         QFileInfo fi(path);
00090         if (!fi.exists())
00091             continue;
00092         if (fi.isDir()) {
00093             if (!directories->contains(path))
00094                 directories->append(path);
00095             this->directories.insert(path, fi.lastModified());
00096         } else {
00097             if (!files->contains(path))
00098                 files->append(path);
00099             this->files.insert(path, fi.lastModified());
00100         }
00101         it.remove();
00102     }
00103     start();
00104     return p;
00105 }

Here is the call graph for this function:

QStringList QPollingFileSystemWatcherEngine::removePaths ( const QStringList paths,
QStringList files,
QStringList directories 
) [virtual]

Implements QFileSystemWatcherEngine.

Definition at line 107 of file qfilesystemwatcher.cpp.

References directories, files, QHash< Key, T >::isEmpty(), mutex, p, path, QHash< Key, T >::remove(), stop(), QMutexLocker::unlock(), and QThread::wait().

00110 {
00111     QMutexLocker locker(&mutex);
00112     QStringList p = paths;
00113     QMutableListIterator<QString> it(p);
00114     while (it.hasNext()) {
00115         QString path = it.next();
00116         if (this->directories.remove(path)) {
00117             directories->removeAll(path);
00118             it.remove();
00119         } else if (this->files.remove(path)) {
00120             files->removeAll(path);
00121             it.remove();
00122         }
00123     }
00124     if (this->files.isEmpty() && this->directories.isEmpty()) {
00125         locker.unlock();
00126         stop();
00127         wait();
00128     }
00129     return p;
00130 }

Here is the call graph for this function:

void QPollingFileSystemWatcherEngine::stop (  )  [virtual]

Implements QFileSystemWatcherEngine.

Definition at line 132 of file qfilesystemwatcher.cpp.

References QMetaObject::invokeMethod().

Referenced by removePaths().

00133 {
00134     QMetaObject::invokeMethod(this, "quit");
00135 }

Here is the call graph for this function:

void QPollingFileSystemWatcherEngine::timeout (  )  [private, slot]

Definition at line 137 of file qfilesystemwatcher.cpp.

References directories, QFileSystemWatcherEngine::directoryChanged(), emit, QFileInfo::exists(), QFileSystemWatcherEngine::fileChanged(), files, QFileInfo::lastModified(), mutex, path, and x.

Referenced by run().

00138 {
00139     QMutexLocker locker(&mutex);
00140     QMutableHashIterator<QString, QDateTime> fit(files);
00141     while (fit.hasNext()) {
00142         QHash<QString, QDateTime>::iterator x = fit.next();
00143         QString path = x.key();
00144         QFileInfo fi(path);
00145         if (!fi.exists()) {
00146             fit.remove();
00147             emit fileChanged(path, true);
00148         } else if (x.value() != fi.lastModified()) {
00149             x.value() = fi.lastModified();
00150             emit fileChanged(path, false);
00151         }
00152     }
00153     QMutableHashIterator<QString, QDateTime> dit(directories);
00154     while (dit.hasNext()) {
00155         QHash<QString, QDateTime>::iterator x = dit.next();
00156         QString path = x.key();
00157         QFileInfo fi(path);
00158         if (!fi.exists()) {
00159             dit.remove();
00160             emit directoryChanged(path, true);
00161         } else if (x.value() != fi.lastModified()) {
00162             x.value() = fi.lastModified();
00163             emit directoryChanged(path, false);
00164         }
00165     }
00166 }


Member Data Documentation

QMutex QPollingFileSystemWatcherEngine::mutex [mutable, private]

Definition at line 50 of file qfilesystemwatcher.cpp.

Referenced by addPaths(), removePaths(), and timeout().

QHash<QString, QDateTime> QPollingFileSystemWatcherEngine::files [private]

Definition at line 51 of file qfilesystemwatcher.cpp.

Referenced by addPaths(), removePaths(), and timeout().

QHash<QString, QDateTime> QPollingFileSystemWatcherEngine::directories [private]

Definition at line 51 of file qfilesystemwatcher.cpp.

Referenced by addPaths(), removePaths(), and timeout().


The documentation for this class was generated from the following file:
Generated on Thu Mar 15 18:42:40 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1