mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-21 02:51:26 -04:00
Eliminated indirect call to ContentManager::updateDownloadInfos()
Now ContentManager::updateDownloadInfos() is called directly by ContentManager (rather than indirectly via ContentManagerModel).
This commit is contained in:
parent
b112c1b34c
commit
d089dced05
@ -484,10 +484,13 @@ void ContentManager::updateDownload(QString bookId)
|
||||
{
|
||||
const auto downloadState = m_downloads.value(bookId);
|
||||
if ( downloadState && !downloadState->paused ) {
|
||||
// This calls ContentManager::updateDownloadInfos() in a convoluted way
|
||||
// and also has some other side-effects
|
||||
if ( ! managerModel->updateDownload(bookId) ) {
|
||||
const auto downloadInfo = updateDownloadInfos(bookId, {"status", "completedLength", "totalLength", "downloadSpeed"});
|
||||
const bool downloadStillValid = downloadState->update(downloadInfo);
|
||||
if ( ! downloadStillValid ) {
|
||||
m_downloads.remove(bookId);
|
||||
managerModel->removeDownload(bookId);
|
||||
} else {
|
||||
managerModel->updateDownload(bookId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -245,31 +245,15 @@ void ContentManagerModel::updateImage(QString bookId, QString url, QByteArray im
|
||||
emit dataChanged(index, index);
|
||||
}
|
||||
|
||||
bool ContentManagerModel::updateDownload(QString bookId)
|
||||
void ContentManagerModel::updateDownload(QString bookId)
|
||||
{
|
||||
const auto download = m_downloads.value(bookId);
|
||||
|
||||
if ( ! download )
|
||||
return true;
|
||||
|
||||
const auto downloadInfos = KiwixApp::instance()->getContentManager()->updateDownloadInfos(bookId, {"status", "completedLength", "totalLength", "downloadSpeed"});
|
||||
const bool downloadStillValid = download->update(downloadInfos);
|
||||
|
||||
// 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.
|
||||
|
||||
const auto it = bookIdToRowMap.constFind(bookId);
|
||||
|
||||
if ( ! downloadStillValid ) {
|
||||
removeDownload(bookId);
|
||||
} else if ( it != bookIdToRowMap.constEnd() ) {
|
||||
if ( it != bookIdToRowMap.constEnd() ) {
|
||||
const size_t row = it.value();
|
||||
const QModelIndex newIndex = this->index(row, 5);
|
||||
emit dataChanged(newIndex, newIndex);
|
||||
}
|
||||
return downloadStillValid;
|
||||
}
|
||||
|
||||
|
||||
|
@ -50,7 +50,7 @@ public slots:
|
||||
void pauseDownload(QModelIndex index);
|
||||
void resumeDownload(QModelIndex index);
|
||||
void removeDownload(QString bookId);
|
||||
bool updateDownload(QString bookId);
|
||||
void updateDownload(QString bookId);
|
||||
|
||||
protected: // functions
|
||||
bool canFetchMore(const QModelIndex &parent) const override;
|
||||
|
Loading…
x
Reference in New Issue
Block a user