From 6f10585d7fa6e9e663e2b35202ce43f5fe778da2 Mon Sep 17 00:00:00 2001 From: luddens Date: Fri, 7 Jun 2019 15:33:30 +0200 Subject: [PATCH] add alert if there is not enough storage to download Check the available storage before the start of a download thanks to QStorageInfo::bytesAvailable(), if the book size is bigger than this value an alert message appears. --- resources/js/_contentManager.js | 4 ++++ src/contentmanager.cpp | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/resources/js/_contentManager.js b/resources/js/_contentManager.js index b932fe0..e78e887 100644 --- a/resources/js/_contentManager.js +++ b/resources/js/_contentManager.js @@ -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); }); diff --git a/src/contentmanager.cpp b/src/contentmanager.cpp index c7a3486..e4f22ee 100644 --- a/src/contentmanager.cpp +++ b/src/contentmanager.cpp @@ -9,6 +9,7 @@ #include #include #include +#include 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())