DownloadManager::updateDownload(bookId)

This commit is contained in:
Veloman Yunkan 2024-06-04 15:01:15 +04:00 committed by Kelson
parent abd3ed5225
commit 03c45e814b
2 changed files with 14 additions and 12 deletions

View File

@ -95,7 +95,9 @@ void DownloadManager::startDownloadUpdaterThread()
mp_downloadUpdaterThread = QThread::create([=]() { mp_downloadUpdaterThread = QThread::create([=]() {
while ( mp_downloadUpdaterThread != nullptr ) { while ( mp_downloadUpdaterThread != nullptr ) {
updateDownloads(); for ( const auto& bookId : m_downloads.keys() ) {
updateDownload(bookId);
}
QThread::msleep(1000); QThread::msleep(1000);
} }
}); });
@ -114,19 +116,17 @@ void DownloadManager::restoreDownloads()
} }
} }
void DownloadManager::updateDownloads() void DownloadManager::updateDownload(QString bookId)
{ {
DownloadInfo downloadInfo; DownloadInfo downloadInfo;
for ( const auto& bookId : m_downloads.keys() ) { try {
try { downloadInfo = getDownloadInfo(bookId);
downloadInfo = getDownloadInfo(bookId); } catch ( ... ) {
} catch ( ... ) { emit downloadDisappeared(bookId);
emit downloadDisappeared(bookId); return;
continue;
}
emit downloadUpdated(bookId, downloadInfo);
} }
emit downloadUpdated(bookId, downloadInfo);
} }
namespace namespace

View File

@ -97,7 +97,6 @@ public: // functions
DownloadInfo getDownloadInfo(QString bookId) const; DownloadInfo getDownloadInfo(QString bookId) const;
void restoreDownloads(); void restoreDownloads();
void updateDownloads();
// returns the download id // returns the download id
std::string startDownload(const kiwix::Book& book, const QString& downloadDirPath); std::string startDownload(const kiwix::Book& book, const QString& downloadDirPath);
@ -115,6 +114,9 @@ signals:
void downloadUpdated(QString bookId, const DownloadInfo& ); void downloadUpdated(QString bookId, const DownloadInfo& );
void downloadDisappeared(QString bookId); void downloadDisappeared(QString bookId);
private: // functions
void updateDownload(QString bookId);
private: // data private: // data
const Library* const mp_library; const Library* const mp_library;
kiwix::Downloader* const mp_downloader; kiwix::Downloader* const mp_downloader;