mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-24 04:32:15 -04:00
More elegant ContentManager::updateDownload()
This commit is contained in:
parent
defe52a246
commit
e0f79bf9f2
@ -418,6 +418,7 @@ void ContentManager::removeDownload(QString bookId)
|
|||||||
|
|
||||||
void ContentManager::downloadCancelled(QString bookId)
|
void ContentManager::downloadCancelled(QString bookId)
|
||||||
{
|
{
|
||||||
|
removeDownload(bookId);
|
||||||
kiwix::Book bCopy(mp_library->getBookById(bookId));
|
kiwix::Book bCopy(mp_library->getBookById(bookId));
|
||||||
bCopy.setDownloadId("");
|
bCopy.setDownloadId("");
|
||||||
mp_library->getKiwixLibrary()->addOrUpdateBook(bCopy);
|
mp_library->getKiwixLibrary()->addOrUpdateBook(bCopy);
|
||||||
@ -427,6 +428,7 @@ void ContentManager::downloadCancelled(QString bookId)
|
|||||||
|
|
||||||
void ContentManager::downloadCompleted(QString bookId, QString path)
|
void ContentManager::downloadCompleted(QString bookId, QString path)
|
||||||
{
|
{
|
||||||
|
removeDownload(bookId);
|
||||||
kiwix::Book bCopy(mp_library->getBookById(bookId));
|
kiwix::Book bCopy(mp_library->getBookById(bookId));
|
||||||
bCopy.setPath(QDir::toNativeSeparators(path).toStdString());
|
bCopy.setPath(QDir::toNativeSeparators(path).toStdString());
|
||||||
bCopy.setDownloadId("");
|
bCopy.setDownloadId("");
|
||||||
@ -480,12 +482,8 @@ void ContentManager::updateDownload(QString bookId)
|
|||||||
downloadCancelled(bookId);
|
downloadCancelled(bookId);
|
||||||
} else if ( downloadInfo["status"] == "completed" ) {
|
} else if ( downloadInfo["status"] == "completed" ) {
|
||||||
downloadCompleted(bookId, downloadInfo["path"].toString());
|
downloadCompleted(bookId, downloadInfo["path"].toString());
|
||||||
}
|
|
||||||
|
|
||||||
const bool downloadStillValid = downloadState->update(downloadInfo);
|
|
||||||
if ( ! downloadStillValid ) {
|
|
||||||
removeDownload(bookId);
|
|
||||||
} else {
|
} else {
|
||||||
|
downloadState->update(downloadInfo);
|
||||||
managerModel->updateDownload(bookId);
|
managerModel->updateDownload(bookId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,11 +28,6 @@ QString convertToUnits(QString size)
|
|||||||
|
|
||||||
bool DownloadState::update(const DownloadInfo& downloadInfos)
|
bool DownloadState::update(const DownloadInfo& downloadInfos)
|
||||||
{
|
{
|
||||||
if (!downloadInfos["status"].isValid()) {
|
|
||||||
*this = {0, "", "", false};
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
double percent = downloadInfos["completedLength"].toDouble() / downloadInfos["totalLength"].toDouble();
|
double percent = downloadInfos["completedLength"].toDouble() / downloadInfos["totalLength"].toDouble();
|
||||||
percent *= 100;
|
percent *= 100;
|
||||||
percent = QString::number(percent, 'g', 3).toDouble();
|
percent = QString::number(percent, 'g', 3).toDouble();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user