mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-15 09:43:07 -07:00
Reduce number of DownloadManager signals
This commit is contained in:
parent
0f1fc7be9d
commit
6cb15706f5
26 changed files with 317 additions and 337 deletions
|
@ -76,19 +76,20 @@ void DNSUpdater::checkPublicIP()
|
|||
|
||||
DownloadHandler *handler = DownloadManager::instance()->download(
|
||||
DownloadRequest("http://checkip.dyndns.org").userAgent("qBittorrent/" QBT_VERSION_2));
|
||||
connect(handler, static_cast<void (Net::DownloadHandler::*)(const QString &, const QByteArray &)>(&Net::DownloadHandler::downloadFinished)
|
||||
, this, &DNSUpdater::ipRequestFinished);
|
||||
connect(handler, &Net::DownloadHandler::downloadFailed, this, &DNSUpdater::ipRequestFailed);
|
||||
connect(handler, &DownloadHandler::finished, this, &DNSUpdater::ipRequestFinished);
|
||||
|
||||
m_lastIPCheckTime = QDateTime::currentDateTime();
|
||||
}
|
||||
|
||||
void DNSUpdater::ipRequestFinished(const QString &url, const QByteArray &data)
|
||||
void DNSUpdater::ipRequestFinished(const DownloadResult &result)
|
||||
{
|
||||
Q_UNUSED(url);
|
||||
if (result.status != DownloadStatus::Success) {
|
||||
qWarning() << "IP request failed:" << result.errorString;
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse response
|
||||
const QRegularExpressionMatch ipRegexMatch = QRegularExpression("Current IP Address:\\s+([^<]+)</body>").match(data);
|
||||
const QRegularExpressionMatch ipRegexMatch = QRegularExpression("Current IP Address:\\s+([^<]+)</body>").match(result.data);
|
||||
if (ipRegexMatch.hasMatch()) {
|
||||
QString ipStr = ipRegexMatch.captured(1);
|
||||
qDebug() << Q_FUNC_INFO << "Regular expression captured the following IP:" << ipStr;
|
||||
|
@ -110,12 +111,6 @@ void DNSUpdater::ipRequestFinished(const QString &url, const QByteArray &data)
|
|||
}
|
||||
}
|
||||
|
||||
void DNSUpdater::ipRequestFailed(const QString &url, const QString &error)
|
||||
{
|
||||
Q_UNUSED(url);
|
||||
qWarning() << "IP request failed:" << error;
|
||||
}
|
||||
|
||||
void DNSUpdater::updateDNSService()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
|
@ -123,9 +118,7 @@ void DNSUpdater::updateDNSService()
|
|||
m_lastIPCheckTime = QDateTime::currentDateTime();
|
||||
DownloadHandler *handler = DownloadManager::instance()->download(
|
||||
DownloadRequest(getUpdateUrl()).userAgent("qBittorrent/" QBT_VERSION_2));
|
||||
connect(handler, static_cast<void (Net::DownloadHandler::*)(const QString &, const QByteArray &)>(&Net::DownloadHandler::downloadFinished)
|
||||
, this, &DNSUpdater::ipUpdateFinished);
|
||||
connect(handler, &Net::DownloadHandler::downloadFailed, this, &DNSUpdater::ipUpdateFailed);
|
||||
connect(handler, &DownloadHandler::finished, this, &DNSUpdater::ipUpdateFinished);
|
||||
}
|
||||
|
||||
QString DNSUpdater::getUpdateUrl() const
|
||||
|
@ -164,17 +157,12 @@ QString DNSUpdater::getUpdateUrl() const
|
|||
return url.toString();
|
||||
}
|
||||
|
||||
void DNSUpdater::ipUpdateFinished(const QString &url, const QByteArray &data)
|
||||
void DNSUpdater::ipUpdateFinished(const DownloadResult &result)
|
||||
{
|
||||
Q_UNUSED(url);
|
||||
// Parse reply
|
||||
processIPUpdateReply(data);
|
||||
}
|
||||
|
||||
void DNSUpdater::ipUpdateFailed(const QString &url, const QString &error)
|
||||
{
|
||||
Q_UNUSED(url);
|
||||
qWarning() << "IP update failed:" << error;
|
||||
if (result.status == DownloadStatus::Success)
|
||||
processIPUpdateReply(result.data);
|
||||
else
|
||||
qWarning() << "IP update failed:" << result.errorString;
|
||||
}
|
||||
|
||||
void DNSUpdater::processIPUpdateReply(const QString &reply)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue