1
1
#include " filewatcher.h"
2
2
#include < QDebug>
3
- #include < QFile>
4
3
#include < QDir>
5
4
#include < QDirIterator>
5
+ #include < QFile>
6
6
#include < QLoggingCategory>
7
7
8
8
Q_LOGGING_CATEGORY (filewatcherCategory, " filewatcher" );
9
9
10
- FileWatcher::FileWatcher (QObject * parent)
10
+ FileWatcher::FileWatcher (QObject* parent)
11
11
: QObject(parent)
12
12
, m_fileUrl(QLatin1String(" " ))
13
13
, m_enabled(true )
@@ -41,7 +41,7 @@ QStringList FileWatcher::nameFilters() const
41
41
return m_nameFilters;
42
42
}
43
43
44
- void FileWatcher::setFileUrl (const QUrl & fileUrl)
44
+ void FileWatcher::setFileUrl (const QUrl& fileUrl)
45
45
{
46
46
if (m_fileUrl == fileUrl) {
47
47
return ;
@@ -71,7 +71,7 @@ void FileWatcher::setRecursive(bool recursive)
71
71
emit recursiveChanged (m_recursive);
72
72
}
73
73
74
- void FileWatcher::setNameFilters (const QStringList & nameFilters)
74
+ void FileWatcher::setNameFilters (const QStringList& nameFilters)
75
75
{
76
76
if (m_nameFilters == nameFilters) {
77
77
return ;
@@ -86,31 +86,31 @@ void FileWatcher::setNameFilters(const QStringList &nameFilters)
86
86
void FileWatcher::updateRegExps ()
87
87
{
88
88
m_regExps.clear ();
89
- for (QString & filter: m_nameFilters) {
89
+ for (QString& filter : m_nameFilters) {
90
90
m_regExps.append (QRegExp (filter, Qt::CaseInsensitive, QRegExp::WildcardUnix));
91
91
}
92
92
}
93
93
94
94
bool FileWatcher::updateWatchedFile ()
95
95
{
96
- const auto & files = m_fileSystemWatcher.files ();
96
+ const auto & files = m_fileSystemWatcher.files ();
97
97
if (files.length () > 0 ) {
98
98
m_fileSystemWatcher.removePaths (files);
99
99
}
100
- const auto & directories = m_fileSystemWatcher.directories ();
100
+ const auto & directories = m_fileSystemWatcher.directories ();
101
101
if (directories.length () > 0 ) {
102
102
m_fileSystemWatcher.removePaths (directories);
103
103
}
104
104
105
- if (!m_fileUrl.isValid () || !m_enabled) {
105
+ if (!m_fileUrl.isValid () || !m_enabled) {
106
106
return false ;
107
107
}
108
108
109
109
if (!m_fileUrl.isLocalFile ()) {
110
110
qCWarning (filewatcherCategory) << " Can only watch local files" ;
111
111
return false ;
112
112
}
113
- const auto & localFile = m_fileUrl.toLocalFile ();
113
+ const auto & localFile = m_fileUrl.toLocalFile ();
114
114
if (localFile.isEmpty ()) {
115
115
return false ;
116
116
}
@@ -122,10 +122,10 @@ bool FileWatcher::updateWatchedFile()
122
122
123
123
QDirIterator it (localFile, QDirIterator::Subdirectories | QDirIterator::FollowSymlinks);
124
124
while (it.hasNext ()) {
125
- const auto & file = it.next ();
125
+ const auto & file = it.next ();
126
126
const QString extension = it.fileInfo ().completeSuffix ();
127
127
bool filtered = false ;
128
- for (QRegExp & regExp: m_regExps) {
128
+ for (QRegExp& regExp : m_regExps) {
129
129
if (regExp.exactMatch (extension)) {
130
130
filtered = true ;
131
131
break ;
@@ -140,11 +140,9 @@ bool FileWatcher::updateWatchedFile()
140
140
}
141
141
142
142
return newPaths != QSet<QString>::fromList (files).unite (QSet<QString>::fromList (directories));
143
- }
144
- else if (QFile::exists (localFile)) {
143
+ } else if (QFile::exists (localFile)) {
145
144
m_fileSystemWatcher.addPath (localFile);
146
- }
147
- else {
145
+ } else {
148
146
#ifdef QT_DEBUG
149
147
qCWarning (filewatcherCategory) << " File to watch does not exist" << localFile;
150
148
#endif
@@ -159,7 +157,7 @@ void FileWatcher::onWatchedFileChanged()
159
157
}
160
158
}
161
159
162
- void FileWatcher::onWatchedDirectoryChanged (const QString &)
160
+ void FileWatcher::onWatchedDirectoryChanged (const QString&)
163
161
{
164
162
if (updateWatchedFile ()) {
165
163
onWatchedFileChanged (); // propagate event
0 commit comments