Remove QPointer wrapper

This commit is contained in:
Chocobo1 2018-03-19 19:20:04 +08:00
parent bfbd978d3f
commit 65921eaf7b
No known key found for this signature in database
GPG key ID: 210D9C873253A68C
2 changed files with 15 additions and 27 deletions

View file

@ -53,14 +53,13 @@ FileSystemWatcher::FileSystemWatcher(QObject *parent)
: QFileSystemWatcher(parent) : QFileSystemWatcher(parent)
{ {
connect(this, &QFileSystemWatcher::directoryChanged, this, &FileSystemWatcher::scanLocalFolder); connect(this, &QFileSystemWatcher::directoryChanged, this, &FileSystemWatcher::scanLocalFolder);
}
FileSystemWatcher::~FileSystemWatcher() m_partialTorrentTimer.setSingleShot(true);
{ connect(&m_partialTorrentTimer, &QTimer::timeout, this, &FileSystemWatcher::processPartialTorrents);
#ifndef Q_OS_WIN #ifndef Q_OS_WIN
delete m_watchTimer; connect(&m_watchTimer, &QTimer::timeout, this, &FileSystemWatcher::scanNetworkFolders);
#endif #endif
delete m_partialTorrentTimer;
} }
QStringList FileSystemWatcher::directories() const QStringList FileSystemWatcher::directories() const
@ -87,12 +86,8 @@ void FileSystemWatcher::addPath(const QString &path)
qDebug("Network folder detected: %s", qUtf8Printable(path)); qDebug("Network folder detected: %s", qUtf8Printable(path));
qDebug("Using file polling mode instead of inotify..."); qDebug("Using file polling mode instead of inotify...");
m_watchedFolders << dir; m_watchedFolders << dir;
// Set up the watch timer
if (!m_watchTimer) { m_watchTimer.start(WATCH_INTERVAL);
m_watchTimer = new QTimer(this);
connect(m_watchTimer, &QTimer::timeout, this, &FileSystemWatcher::scanNetworkFolders);
m_watchTimer->start(WATCH_INTERVAL);
}
return; return;
} }
#endif #endif
@ -108,7 +103,7 @@ void FileSystemWatcher::removePath(const QString &path)
#ifndef Q_OS_WIN #ifndef Q_OS_WIN
if (m_watchedFolders.removeOne(path)) { if (m_watchedFolders.removeOne(path)) {
if (m_watchedFolders.isEmpty()) if (m_watchedFolders.isEmpty())
delete m_watchTimer; m_watchTimer.stop();
return; return;
} }
#endif #endif
@ -155,13 +150,12 @@ void FileSystemWatcher::processPartialTorrents()
// Stop the partial timer if necessary // Stop the partial timer if necessary
if (m_partialTorrents.empty()) { if (m_partialTorrents.empty()) {
m_partialTorrentTimer->stop(); m_partialTorrentTimer.stop();
m_partialTorrentTimer->deleteLater();
qDebug("No longer any partial torrent."); qDebug("No longer any partial torrent.");
} }
else { else {
qDebug("Still %d partial torrents after delayed processing.", m_partialTorrents.count()); qDebug("Still %d partial torrents after delayed processing.", m_partialTorrents.count());
m_partialTorrentTimer->start(WATCH_INTERVAL); m_partialTorrentTimer.start(WATCH_INTERVAL);
} }
// Notify of new torrents // Notify of new torrents
@ -186,10 +180,6 @@ void FileSystemWatcher::processTorrentsInDir(const QDir &dir)
if (!torrents.empty()) if (!torrents.empty())
emit torrentsAdded(torrents); emit torrentsAdded(torrents);
if (!m_partialTorrents.empty() && !m_partialTorrentTimer) { if (!m_partialTorrents.empty() && !m_partialTorrentTimer.isActive())
m_partialTorrentTimer = new QTimer(this); m_partialTorrentTimer.start(WATCH_INTERVAL);
connect(m_partialTorrentTimer, &QTimer::timeout, this, &FileSystemWatcher::processPartialTorrents);
m_partialTorrentTimer->setSingleShot(true);
m_partialTorrentTimer->start(WATCH_INTERVAL);
}
} }

View file

@ -32,7 +32,6 @@
#include <QDir> #include <QDir>
#include <QFileSystemWatcher> #include <QFileSystemWatcher>
#include <QHash> #include <QHash>
#include <QPointer>
#include <QStringList> #include <QStringList>
#include <QTimer> #include <QTimer>
@ -46,7 +45,6 @@ class FileSystemWatcher : public QFileSystemWatcher
public: public:
explicit FileSystemWatcher(QObject *parent = nullptr); explicit FileSystemWatcher(QObject *parent = nullptr);
~FileSystemWatcher();
QStringList directories() const; QStringList directories() const;
void addPath(const QString &path); void addPath(const QString &path);
@ -65,14 +63,14 @@ protected slots:
private: private:
void processTorrentsInDir(const QDir &dir); void processTorrentsInDir(const QDir &dir);
// Partial torrents
QHash<QString, int> m_partialTorrents;
QTimer m_partialTorrentTimer;
#ifndef Q_OS_WIN #ifndef Q_OS_WIN
QList<QDir> m_watchedFolders; QList<QDir> m_watchedFolders;
QPointer<QTimer> m_watchTimer; QTimer m_watchTimer;
#endif #endif
// Partial torrents
QHash<QString, int> m_partialTorrents;
QPointer<QTimer> m_partialTorrentTimer;
}; };
#endif // FILESYSTEMWATCHER_H #endif // FILESYSTEMWATCHER_H