Reduce number of DownloadManager signals

This commit is contained in:
Vladimir Golovnev (Glassez)
2019-03-01 10:38:16 +03:00
parent 0f1fc7be9d
commit 6cb15706f5
26 changed files with 317 additions and 337 deletions

View File

@@ -131,10 +131,7 @@ void Feed::refresh()
// NOTE: Should we allow manually refreshing for disabled session?
Net::DownloadHandler *handler = Net::DownloadManager::instance()->download(m_url);
connect(handler
, static_cast<void (Net::DownloadHandler::*)(const QString &, const QByteArray &)>(&Net::DownloadHandler::downloadFinished)
, this, &Feed::handleDownloadFinished);
connect(handler, &Net::DownloadHandler::downloadFailed, this, &Feed::handleDownloadFailed);
connect(handler, &Net::DownloadHandler::finished, this, &Feed::handleDownloadFinished);
m_isLoading = true;
emit stateChanged(this);
@@ -182,12 +179,12 @@ void Feed::handleMaxArticlesPerFeedChanged(const int n)
// We don't need store articles here
}
void Feed::handleIconDownloadFinished(const QString &url, const QString &filePath)
void Feed::handleIconDownloadFinished(const Net::DownloadResult &result)
{
Q_UNUSED(url);
m_iconPath = Utils::Fs::fromNativePath(filePath);
emit iconLoaded(this);
if (result.status == Net::DownloadStatus::Success) {
m_iconPath = Utils::Fs::fromNativePath(result.filePath);
emit iconLoaded(this);
}
}
bool Feed::hasError() const
@@ -195,22 +192,22 @@ bool Feed::hasError() const
return m_hasError;
}
void Feed::handleDownloadFinished(const QString &url, const QByteArray &data)
void Feed::handleDownloadFinished(const Net::DownloadResult &result)
{
qDebug() << "Successfully downloaded RSS feed at" << url;
// Parse the download RSS
m_parser->parse(data);
}
if (result.status == Net::DownloadStatus::Success) {
qDebug() << "Successfully downloaded RSS feed at" << result.url;
// Parse the download RSS
m_parser->parse(result.data);
}
else {
m_isLoading = false;
m_hasError = true;
void Feed::handleDownloadFailed(const QString &url, const QString &error)
{
m_isLoading = false;
m_hasError = true;
LogMsg(tr("Failed to download RSS feed at '%1'. Reason: %2")
.arg(result.url, result.errorString), Log::WARNING);
LogMsg(tr("Failed to download RSS feed at '%1'. Reason: %2").arg(url, error)
, Log::WARNING);
emit stateChanged(this);
emit stateChanged(this);
}
}
void Feed::handleParsingFinished(const RSS::Private::ParsingResult &result)
@@ -404,9 +401,7 @@ void Feed::downloadIcon()
const auto iconUrl = QString("%1://%2/favicon.ico").arg(url.scheme(), url.host());
const Net::DownloadHandler *handler = Net::DownloadManager::instance()->download(
Net::DownloadRequest(iconUrl).saveToFile(true));
connect(handler
, static_cast<void (Net::DownloadHandler::*)(const QString &, const QString &)>(&Net::DownloadHandler::downloadFinished)
, this, &Feed::handleIconDownloadFinished);
connect(handler, &Net::DownloadHandler::finished, this, &Feed::handleIconDownloadFinished);
}
int Feed::updateArticles(const QList<QVariantHash> &loadedArticles)