Clean up Session class variable initialization

This commit is contained in:
Chocobo1 2019-10-01 15:33:11 +08:00
commit 865394a59c
No known key found for this signature in database
GPG key ID: 210D9C873253A68C
2 changed files with 61 additions and 63 deletions

View file

@ -42,8 +42,10 @@
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QHostAddress>
#include <QNetworkAddressEntry>
#include <QNetworkConfigurationManager>
#include <QNetworkInterface>
#include <QRegularExpression>
#include <QString>
@ -243,9 +245,6 @@ Session *Session::m_instance = nullptr;
Session::Session(QObject *parent)
: QObject(parent)
, m_deferredConfigureScheduled(false)
, m_IPFilteringChanged(true)
, m_listenInterfaceChanged(true)
, m_isDHTEnabled(BITTORRENT_SESSION_KEY("DHTEnabled"), true)
, m_isLSDEnabled(BITTORRENT_SESSION_KEY("LSDEnabled"), true)
, m_isPeXEnabled(BITTORRENT_SESSION_KEY("PeXEnabled"), true)
@ -346,10 +345,14 @@ Session::Session(QObject *parent)
return tmp;
}
)
, m_wasPexEnabled(m_isPeXEnabled)
, m_numResumeData(0)
, m_extraLimit(0)
, m_recentErroredTorrentsTimer(new QTimer(this))
, m_resumeFolderLock {new QFile {this}}
, m_refreshTimer {new QTimer {this}}
, m_seedingLimitTimer {new QTimer {this}}
, m_resumeDataTimer {new QTimer {this}}
, m_statistics {new Statistics {this}}
, m_ioThread {new QThread {this}}
, m_recentErroredTorrentsTimer {new QTimer {this}}
, m_networkManager {new QNetworkConfigurationManager {this}}
{
if (port() < 0)
m_port = Utils::Random::rand(1024, 65535);
@ -358,9 +361,9 @@ Session::Session(QObject *parent)
m_recentErroredTorrentsTimer->setSingleShot(true);
m_recentErroredTorrentsTimer->setInterval(1000);
connect(m_recentErroredTorrentsTimer, &QTimer::timeout, this, [this]() { m_recentErroredTorrents.clear(); });
connect(m_recentErroredTorrentsTimer, &QTimer::timeout
, this, [this]() { m_recentErroredTorrents.clear(); });
m_seedingLimitTimer = new QTimer(this);
m_seedingLimitTimer->setInterval(10000);
connect(m_seedingLimitTimer, &QTimer::timeout, this, &Session::processShareLimits);
@ -379,35 +382,31 @@ Session::Session(QObject *parent)
m_tags = QSet<QString>::fromList(m_storedTags.value());
m_refreshTimer = new QTimer(this);
m_refreshTimer->setInterval(refreshInterval());
connect(m_refreshTimer, &QTimer::timeout, this, &Session::refresh);
m_refreshTimer->start();
m_statistics = new Statistics(this);
updateSeedingLimitTimer();
populateAdditionalTrackers();
enableTracker(isTrackerEnabled());
connect(Net::ProxyConfigurationManager::instance(), &Net::ProxyConfigurationManager::proxyConfigurationChanged
, this, &Session::configureDeferred);
connect(Net::ProxyConfigurationManager::instance()
, &Net::ProxyConfigurationManager::proxyConfigurationChanged
, this, &Session::configureDeferred);
// Network configuration monitor
connect(&m_networkManager, &QNetworkConfigurationManager::onlineStateChanged, this, &Session::networkOnlineStateChanged);
connect(&m_networkManager, &QNetworkConfigurationManager::configurationAdded, this, &Session::networkConfigurationChange);
connect(&m_networkManager, &QNetworkConfigurationManager::configurationRemoved, this, &Session::networkConfigurationChange);
connect(&m_networkManager, &QNetworkConfigurationManager::configurationChanged, this, &Session::networkConfigurationChange);
connect(m_networkManager, &QNetworkConfigurationManager::onlineStateChanged, this, &Session::networkOnlineStateChanged);
connect(m_networkManager, &QNetworkConfigurationManager::configurationAdded, this, &Session::networkConfigurationChange);
connect(m_networkManager, &QNetworkConfigurationManager::configurationRemoved, this, &Session::networkConfigurationChange);
connect(m_networkManager, &QNetworkConfigurationManager::configurationChanged, this, &Session::networkConfigurationChange);
m_ioThread = new QThread(this);
m_resumeDataSavingManager = new ResumeDataSavingManager {m_resumeFolderPath};
m_resumeDataSavingManager->moveToThread(m_ioThread);
connect(m_ioThread, &QThread::finished, m_resumeDataSavingManager, &QObject::deleteLater);
m_ioThread->start();
// Regular saving of fastresume data
m_resumeDataTimer = new QTimer(this);
connect(m_resumeDataTimer, &QTimer::timeout, this, [this]() { generateResumeData(); });
const uint saveInterval = saveResumeDataInterval();
if (saveInterval > 0) {
@ -419,8 +418,6 @@ Session::Session(QObject *parent)
new PortForwarderImpl {m_nativeSession};
initMetrics();
qDebug("* BitTorrent Session constructed");
}
bool Session::isDHTEnabled() const
@ -869,8 +866,8 @@ Session::~Session()
m_ioThread->quit();
m_ioThread->wait();
m_resumeFolderLock.close();
m_resumeFolderLock.remove();
m_resumeFolderLock->close();
m_resumeFolderLock->remove();
}
void Session::initInstance()
@ -3559,8 +3556,8 @@ void Session::initResumeFolder()
m_resumeFolderPath = Utils::Fs::expandPathAbs(specialFolderLocation(SpecialFolder::Data) + RESUME_FOLDER);
const QDir resumeFolderDir(m_resumeFolderPath);
if (resumeFolderDir.exists() || resumeFolderDir.mkpath(resumeFolderDir.absolutePath())) {
m_resumeFolderLock.setFileName(resumeFolderDir.absoluteFilePath("session.lock"));
if (!m_resumeFolderLock.open(QFile::WriteOnly)) {
m_resumeFolderLock->setFileName(resumeFolderDir.absoluteFilePath("session.lock"));
if (!m_resumeFolderLock->open(QFile::WriteOnly)) {
throw RuntimeError {tr("Cannot write to torrent resume folder.")};
}
}