Merge pull request #174 from kiwix/download-dialog

add alert if there is not enough storage to download
This commit is contained in:
Matthieu Gautier 2019-06-12 10:03:13 +02:00 committed by GitHub
commit f47d8f2243
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -78,6 +78,10 @@ function init() {
contentManager.downloadBook(book.id, function(did) {
if (did.length == 0)
return;
if (did == "storage_error") {
alert("not enough storage available.");
return;
}
book.downloadId = did;
downloadUpdaters[book.id] = setInterval(function() { getDownloadInfo(book.id); }, 1000);
});

View File

@ -9,6 +9,7 @@
#include <QUrlQuery>
#include <QUrl>
#include <QDir>
#include <QStorageInfo>
ContentManager::ContentManager(Library* library, kiwix::Downloader* downloader, QObject *parent)
: QObject(parent),
@ -181,6 +182,10 @@ QString ContentManager::downloadBook(const QString &id)
return mp_library->getBookById(id);
}
}();
QStorageInfo storage(QString::fromStdString(getDataDirectory()));
if (book.getSize() > storage.bytesAvailable()) {
return "storage_error";
}
auto booksList = mp_library->getBookIds();
for (auto b : booksList)
if (b.toStdString() == book.getId())