@@ -103,9 +103,19 @@ void FileWatcher::setNameFilters(const QStringList &nameFilters)
103103
104104 m_nameFilters = nameFilters;
105105 emit nameFiltersChanged (m_nameFilters);
106+
107+ updateRegExps ();
108+ }
109+
110+ void FileWatcher::updateRegExps ()
111+ {
112+ m_regExps.clear ();
113+ for (QString &filter: m_nameFilters) {
114+ m_regExps.append (QRegExp (filter, Qt::CaseInsensitive, QRegExp::WildcardUnix));
115+ }
106116}
107117
108- void FileWatcher::updateWatchedFile ()
118+ bool FileWatcher::updateWatchedFile ()
109119{
110120 const auto &files = m_fileSystemWatcher.files ();
111121 if (files.length () > 0 ) {
@@ -117,29 +127,43 @@ void FileWatcher::updateWatchedFile()
117127 }
118128
119129 if (!m_fileUrl.isValid () || !m_enabled) {
120- return ;
130+ return false ;
121131 }
122132
123133 if (!m_fileUrl.isLocalFile ()) {
124134 qCWarning (filewatcherCategory) << " Can only watch local files" ;
125- return ;
135+ return false ;
126136 }
127137 const auto &localFile = m_fileUrl.toLocalFile ();
128138 if (localFile.isEmpty ()) {
129- return ;
139+ return false ;
130140 }
131141
132142 if (m_recursive && QDir (localFile).exists ()) {
143+ QSet<QString> newPaths;
133144 m_fileSystemWatcher.addPath (localFile);
145+ newPaths.insert (localFile);
146+
134147 QDirIterator it (localFile, QDirIterator::Subdirectories | QDirIterator::FollowSymlinks);
135148 while (it.hasNext ()) {
136149 const auto &file = it.next ();
150+ const QString extension = it.fileInfo ().completeSuffix ();
151+ bool filtered = false ;
152+ for (QRegExp ®Exp: m_regExps) {
153+ if (regExp.exactMatch (extension)) {
154+ filtered = true ;
155+ break ;
156+ }
157+ }
137158 if ((it.fileName () == QLatin1String (" .." )) || (it.fileName () == QLatin1String (" ." ))
138- || m_nameFilters. contains (it. fileInfo (). completeSuffix ()) ) {
159+ || filtered ) {
139160 continue ;
140161 }
141162 m_fileSystemWatcher.addPath (file);
163+ newPaths.insert (it.filePath ());
142164 }
165+
166+ return newPaths != QSet<QString>::fromList (files).unite (QSet<QString>::fromList (directories));
143167 }
144168 else if (QFile::exists (localFile)) {
145169 m_fileSystemWatcher.addPath (localFile);
@@ -149,6 +173,7 @@ void FileWatcher::updateWatchedFile()
149173 qCWarning (filewatcherCategory) << " File to watch does not exist" << localFile;
150174#endif
151175 }
176+ return false ;
152177}
153178
154179void FileWatcher::onWatchedFileChanged ()
@@ -160,8 +185,9 @@ void FileWatcher::onWatchedFileChanged()
160185
161186void FileWatcher::onWatchedDirectoryChanged (const QString &)
162187{
163- updateWatchedFile ();
164- onWatchedFileChanged (); // propagate event
188+ if (updateWatchedFile ()) {
189+ onWatchedFileChanged (); // propagate event
190+ }
165191}
166192
167193} // namespace qtquickvcp
0 commit comments