Reduced the in-use API of ContentManagerModel::Downloads

... in preparation for converting `ContentManagerModel::Downloads` into
a thread-safe class.
This commit is contained in:
Veloman Yunkan 2024-03-01 19:18:24 +04:00
parent de296ed548
commit 728a8a44bb
2 changed files with 7 additions and 6 deletions

View File

@ -674,7 +674,9 @@ void ContentManager::pauseBook(const QString& id, QModelIndex index)
auto download = mp_downloader->getDownload(b.getDownloadId());
if (download->getStatus() == kiwix::Download::K_ACTIVE) {
download->pauseDownload();
m_downloads[id]->pause();
if ( const auto downloadState = m_downloads.value(id) ) {
downloadState->pause();
}
}
managerModel->triggerDataUpdateAt(index);
}
@ -685,7 +687,9 @@ void ContentManager::resumeBook(const QString& id, QModelIndex index)
auto download = mp_downloader->getDownload(b.getDownloadId());
if (download->getStatus() == kiwix::Download::K_PAUSED) {
download->resumeDownload();
m_downloads[id]->resume();
if ( const auto downloadState = m_downloads.value(id) ) {
downloadState->resume();
}
}
managerModel->triggerDataUpdateAt(index);
}

View File

@ -123,10 +123,7 @@ void ContentManagerModel::setBooksData(const BookInfoList& data, const Downloads
const auto rowNode = createNode(bookItem);
// Restore download state during model updates (filtering, etc)
const auto downloadIter = downloads.constFind(rowNode->getBookId());
if ( downloadIter != downloads.constEnd() ) {
rowNode->setDownloadState(downloadIter.value());
}
rowNode->setDownloadState(downloads.value(rowNode->getBookId()));
bookIdToRowMap[bookItem["id"].toString()] = rootNode->childCount();
rootNode->appendChild(rowNode);