Rearranged code in DonwloadState::update()

It's more logical to check for the conditions of a disappeared download
first.
This commit is contained in:
Veloman Yunkan 2023-12-13 22:03:21 +04:00
parent c20eedf9f6
commit e020d52745

View File

@ -36,12 +36,6 @@ QString convertToUnits(QString size)
bool DownloadState::update(QString id)
{
auto downloadInfos = KiwixApp::instance()->getContentManager()->updateDownloadInfos(id, {"status", "completedLength", "totalLength", "downloadSpeed"});
double percent = downloadInfos["completedLength"].toDouble() / downloadInfos["totalLength"].toDouble();
percent *= 100;
percent = QString::number(percent, 'g', 3).toDouble();
auto completedLength = convertToUnits(downloadInfos["completedLength"].toString());
auto downloadSpeed = convertToUnits(downloadInfos["downloadSpeed"].toString()) + "/s";
m_downloadInfo = {percent, completedLength, downloadSpeed, false};
if (!downloadInfos["status"].isValid()) {
m_downloadUpdateTimer->stop();
@ -53,6 +47,13 @@ bool DownloadState::update(QString id)
m_downloadInfo = {0, "", "", false};
return false;
}
double percent = downloadInfos["completedLength"].toDouble() / downloadInfos["totalLength"].toDouble();
percent *= 100;
percent = QString::number(percent, 'g', 3).toDouble();
auto completedLength = convertToUnits(downloadInfos["completedLength"].toString());
auto downloadSpeed = convertToUnits(downloadInfos["downloadSpeed"].toString()) + "/s";
m_downloadInfo = {percent, completedLength, downloadSpeed, false};
return true;
}