From e020d52745833e81968d6461a26afb9cbe12db96 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Wed, 13 Dec 2023 22:03:21 +0400 Subject: [PATCH] Rearranged code in DonwloadState::update() It's more logical to check for the conditions of a disappeared download first. --- src/rownode.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/rownode.cpp b/src/rownode.cpp index 2a5c15f..2559b99 100644 --- a/src/rownode.cpp +++ b/src/rownode.cpp @@ -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; }