diff options
author | Erik Verbruggen <erik@verbruggen.consulting> | 2021-10-07 21:27:54 +0300 |
---|---|---|
committer | Hannah von Reth <vonreth@kde.org> | 2021-10-27 15:30:39 +0300 |
commit | 648237a54a4067313ae1eb01553b7e7198aed7e7 (patch) | |
tree | cfba1311dd594f6ffafe3fa8406977f8ed190ba8 /src/gui/folderwatcher_win.h | |
parent | 530560862bc51203c957d5afed2c33e6ff3b8eb3 (diff) |
Windows: clean-up FolderWatcher
- use a QScopedPointer for heap-allocation handling of the thread
- change WatcherThread::watchChanges result type to more clearly indicate why it is returning
- remove the _done field: it's not needed after changing watchChanges
- do conversions for _longPath/_longPathW once in the constructor, not on every call or watchChanges
- break nested loop out of watchChanges for readability
Diffstat (limited to 'src/gui/folderwatcher_win.h')
-rw-r--r-- | src/gui/folderwatcher_win.h | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/src/gui/folderwatcher_win.h b/src/gui/folderwatcher_win.h index 0d5c78f65..ad1126463 100644 --- a/src/gui/folderwatcher_win.h +++ b/src/gui/folderwatcher_win.h @@ -31,24 +31,21 @@ class WatcherThread : public QThread { Q_OBJECT public: - WatcherThread(const QString &path) - : QThread() - , _path(path + (path.endsWith(QLatin1Char('/')) ? QString() : QStringLiteral("/"))) - , _directory(0) - , _resultEvent(0) - , _stopEvent(0) - , _done(false) - { - } - - ~WatcherThread(); + WatcherThread(const QString &path); + ~WatcherThread() override; void stop(); protected: - void run(); - void watchChanges(size_t fileNotifyBufferSize, - bool *increaseBufferSize); + enum class WatchChanges { + Done, + NeedBiggerBuffer, + Error, + }; + + void run() override; + WatchChanges watchChanges(size_t fileNotifyBufferSize); + void processEntries(FILE_NOTIFY_INFORMATION *curEntry); void closeHandle(); signals: @@ -57,11 +54,11 @@ signals: void ready(); private: - QString _path; + const QString _path; + const QString _longPath; HANDLE _directory; HANDLE _resultEvent; HANDLE _stopEvent; - QAtomicInt _done; }; /** @@ -73,7 +70,7 @@ class FolderWatcherPrivate : public QObject Q_OBJECT public: FolderWatcherPrivate(FolderWatcher *p, const QString &path); - ~FolderWatcherPrivate(); + ~FolderWatcherPrivate() override; /// Set to non-zero once the WatcherThread is capturing events. bool isReady() const @@ -83,7 +80,7 @@ public: private: FolderWatcher *_parent; - WatcherThread *_thread; + QScopedPointer<WatcherThread> _thread; QAtomicInt _ready; }; } |