Made DownloadState::update() a setter

DownloadState::update() no longer calls ContentManager::updateDownloadInfos()
This commit is contained in:
Veloman Yunkan 2024-02-11 15:21:25 +04:00
parent a6359af1ab
commit b288f287f2
5 changed files with 9 additions and 9 deletions

View File

@ -437,7 +437,7 @@ void ContentManager::downloadCompleted(QString bookId, QString path)
}
}
ContentManager::DownloadInfo ContentManager::getDownloadInfo(QString bookId, const QStringList &keys) const
DownloadInfo ContentManager::getDownloadInfo(QString bookId, const QStringList &keys) const
{
DownloadInfo values;
if (!mp_downloader) {
@ -464,7 +464,7 @@ ContentManager::DownloadInfo ContentManager::getDownloadInfo(QString bookId, con
return values;
}
ContentManager::DownloadInfo ContentManager::updateDownloadInfos(QString bookId, QStringList keys)
DownloadInfo ContentManager::updateDownloadInfos(QString bookId, QStringList keys)
{
if ( !keys.contains("status") ) keys.append("status");
if ( !keys.contains("path") ) keys.append("path");

View File

@ -20,8 +20,6 @@ public: // types
typedef ContentManagerModel::BookInfo BookInfo;
typedef ContentManagerModel::BookInfoList BookInfoList;
typedef QMap<QString, QVariant> DownloadInfo;
public: // functions
explicit ContentManager(Library* library, kiwix::Downloader *downloader, QObject *parent = nullptr);
virtual ~ContentManager() {}

View File

@ -252,9 +252,10 @@ void ContentManagerModel::updateDownload(QString bookId)
if ( ! download )
return;
const bool downloadStillValid = download->update(bookId);
const auto downloadInfos = KiwixApp::instance()->getContentManager()->updateDownloadInfos(bookId, {"status", "completedLength", "totalLength", "downloadSpeed"});
const bool downloadStillValid = download->update(downloadInfos);
// The download->update() call above may result in
// The ContentManager::updateDownloadInfos() call above may result in
// ContentManagerModel::setBooksData() being called (through a chain
// of signals), which in turn will rebuild bookIdToRowMap. Hence
// bookIdToRowMap access must happen after it.

View File

@ -26,9 +26,8 @@ QString convertToUnits(QString size)
} // unnamed namespace
bool DownloadState::update(QString id)
bool DownloadState::update(const DownloadInfo& downloadInfos)
{
auto downloadInfos = KiwixApp::instance()->getContentManager()->updateDownloadInfos(id, {"status", "completedLength", "totalLength", "downloadSpeed"});
if (!downloadInfos["status"].isValid()) {
*this = {0, "", "", false};
return false;

View File

@ -6,6 +6,8 @@
#include <QIcon>
#include "kiwix/book.h"
typedef QMap<QString, QVariant> DownloadInfo;
class DownloadState
{
public:
@ -17,7 +19,7 @@ public:
public:
void pause();
void resume();
bool update(QString id);
bool update(const DownloadInfo& info);
};
class RowNode : public Node