KIO
kdirwatch_win.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "kdirwatch_p.h"
00020
00021 #include <windows.h>
00022
00023 KFileSystemWatcher::KFileSystemWatcher()
00024 : QObject(), m_recentWatcher(0)
00025 {
00026 }
00027
00028 KFileSystemWatcher::~KFileSystemWatcher()
00029 {
00030 qDeleteAll(m_watchers);
00031 }
00032
00033 QFileSystemWatcher* KFileSystemWatcher::availableWatcher()
00034 {
00035 QFileSystemWatcher* watcher = m_recentWatcher;
00036 if (!watcher || m_usedObjects.value(watcher) >= MAXIMUM_WAIT_OBJECTS) {
00037 uint i = 0;
00038 watcher = 0;
00039 for (QList<QFileSystemWatcher*>::ConstIterator watchersIt(m_watchers.constBegin());
00040 watchersIt!=m_watchers.constEnd(); ++watchersIt, i++)
00041 {
00042 if (m_usedObjects.value(*watchersIt) < MAXIMUM_WAIT_OBJECTS) {
00043 watcher = *watchersIt;
00044 m_recentWatcher = watcher;
00045 return watcher;
00046 }
00047 }
00048 }
00049 if (!watcher) {
00050 watcher = new QFileSystemWatcher();
00051 connect(watcher, SIGNAL(directoryChanged(QString)), this, SIGNAL(directoryChanged(QString)));
00052 connect(watcher, SIGNAL(fileChanged(QString)), this, SIGNAL(fileChanged(QString)));
00053 m_watchers.append( watcher );
00054 m_usedObjects.insert(watcher, 0);
00055 m_recentWatcher = watcher;
00056 }
00057 return watcher;
00058 }
00059
00060 void KFileSystemWatcher::addPath(const QString &file)
00061 {
00062 QFileSystemWatcher* watcher = availableWatcher();
00063 watcher->addPath(file);
00064 m_usedObjects[watcher]++;
00065 m_paths.insert(file, watcher);
00066 }
00067
00068 void KFileSystemWatcher::removePath(const QString &file)
00069 {
00070 QFileSystemWatcher* watcher = m_paths.value(file);
00071 if (!watcher)
00072 return;
00073 watcher->removePath(file);
00074 m_usedObjects[watcher]--;
00075 if (m_recentWatcher != watcher)
00076 m_recentWatcher = 0;
00077 }