From b288f287f2ef478c1b6aa87b0d5f14654d78fd52 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Sun, 11 Feb 2024 15:21:25 +0400 Subject: [PATCH] Made DownloadState::update() a setter DownloadState::update() no longer calls ContentManager::updateDownloadInfos() --- src/contentmanager.cpp | 4 ++-- src/contentmanager.h | 2 -- src/contentmanagermodel.cpp | 5 +++-- src/rownode.cpp | 3 +-- src/rownode.h | 4 +++- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/contentmanager.cpp b/src/contentmanager.cpp index 297da37..622a6ff 100644 --- a/src/contentmanager.cpp +++ b/src/contentmanager.cpp @@ -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"); diff --git a/src/contentmanager.h b/src/contentmanager.h index c441a6e..d128c22 100644 --- a/src/contentmanager.h +++ b/src/contentmanager.h @@ -20,8 +20,6 @@ public: // types typedef ContentManagerModel::BookInfo BookInfo; typedef ContentManagerModel::BookInfoList BookInfoList; - typedef QMap DownloadInfo; - public: // functions explicit ContentManager(Library* library, kiwix::Downloader *downloader, QObject *parent = nullptr); virtual ~ContentManager() {} diff --git a/src/contentmanagermodel.cpp b/src/contentmanagermodel.cpp index 4c80d3d..e39c547 100644 --- a/src/contentmanagermodel.cpp +++ b/src/contentmanagermodel.cpp @@ -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. diff --git a/src/rownode.cpp b/src/rownode.cpp index cea54b2..2c98968 100644 --- a/src/rownode.cpp +++ b/src/rownode.cpp @@ -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; diff --git a/src/rownode.h b/src/rownode.h index cea055f..db51b57 100644 --- a/src/rownode.h +++ b/src/rownode.h @@ -6,6 +6,8 @@ #include #include "kiwix/book.h" +typedef QMap 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