Browse Source

Remove QPointer wrapper

adaptive-webui-19844
Chocobo1 7 years ago
parent
commit
65921eaf7b
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 32
      src/base/filesystemwatcher.cpp
  2. 10
      src/base/filesystemwatcher.h

32
src/base/filesystemwatcher.cpp

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

10
src/base/filesystemwatcher.h

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

Loading…
Cancel
Save