mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-24 04:32:15 -04:00
Merge pull request #1092 from kiwix/download_dir_checks
Detection and reporting of issues with the download directory
This commit is contained in:
commit
073dd06937
@ -146,6 +146,8 @@
|
|||||||
"delete-book-text": "Are you sure you want to delete <b>{{ZIM}}</b>?",
|
"delete-book-text": "Are you sure you want to delete <b>{{ZIM}}</b>?",
|
||||||
"download-storage-error": "Storage Error",
|
"download-storage-error": "Storage Error",
|
||||||
"download-storage-error-text": "The system doesn't have enough storage available.",
|
"download-storage-error-text": "The system doesn't have enough storage available.",
|
||||||
|
"download-dir-missing": "Download directory doesn't exist.",
|
||||||
|
"download-dir-not-writable": "Download directory is not writable.",
|
||||||
"download-unavailable": "Download Unavailable",
|
"download-unavailable": "Download Unavailable",
|
||||||
"download-unavailable-text": "This download is unavailable.",
|
"download-unavailable-text": "This download is unavailable.",
|
||||||
"open-book": "Open book",
|
"open-book": "Open book",
|
||||||
|
@ -39,9 +39,11 @@
|
|||||||
"videos": "{{identical|Video}}",
|
"videos": "{{identical|Video}}",
|
||||||
"yes": "{{identical|yes}}",
|
"yes": "{{identical|yes}}",
|
||||||
"no": "{{identical|no}}",
|
"no": "{{identical|no}}",
|
||||||
|
"download-dir-missing": "Error text displayed when it turns out that the download directory doesn't exist.",
|
||||||
|
"download-dir-not-writable": "Error text displayed when files cannot be created/saved in the download directory due to permissions",
|
||||||
"add-bookmark": "Represents the action of adding a page as a bookmark",
|
"add-bookmark": "Represents the action of adding a page as a bookmark",
|
||||||
"remove-bookmark": "Represents the action of removing a page from the bookmarks",
|
"remove-bookmark": "Represents the action of removing a page from the bookmarks",
|
||||||
"open-link-in-web-browser": "Ouvrir le lien dans le navigateur",
|
"open-link-in-web-browser": "Hint for the action of opening the link in a web browser",
|
||||||
"download-dir-dialog-msg": "Please note that <code><nowiki>{{DIRECTORY}}</nowiki></code> should be placed on a newline.",
|
"download-dir-dialog-msg": "Please note that <code><nowiki>{{DIRECTORY}}</nowiki></code> should be placed on a newline.",
|
||||||
"monitor-dir-dialog-title": "\"Monitor\" means \"watch\" in this context. The monitor directory is monitored/watched for new ZIM files.",
|
"monitor-dir-dialog-title": "\"Monitor\" means \"watch\" in this context. The monitor directory is monitored/watched for new ZIM files.",
|
||||||
"monitor-dir-dialog-msg": "\"Monitor\" means \"watch\" in this context. The monitor directory is monitored/watched for new ZIM files.",
|
"monitor-dir-dialog-msg": "\"Monitor\" means \"watch\" in this context. The monitor directory is monitored/watched for new ZIM files.",
|
||||||
|
@ -53,8 +53,21 @@ void throwDownloadUnavailableError()
|
|||||||
gt("download-unavailable-text"));
|
gt("download-unavailable-text"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkEnoughStorageAvailable(const kiwix::Book& book, QString targetDir)
|
void checkThatBookCanBeSaved(const kiwix::Book& book, QString targetDir)
|
||||||
{
|
{
|
||||||
|
const QFileInfo targetDirInfo(targetDir);
|
||||||
|
if ( !targetDirInfo.isDir() ) {
|
||||||
|
throw ContentManagerError(gt("download-storage-error"),
|
||||||
|
gt("download-dir-missing"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// XXX: This may lie under Windows
|
||||||
|
// XXX: (see https://doc.qt.io/qt-5/qfile.html#platform-specific-issues)
|
||||||
|
if ( !targetDirInfo.isWritable() ) {
|
||||||
|
throw ContentManagerError(gt("download-storage-error"),
|
||||||
|
gt("download-dir-not-writable"));
|
||||||
|
}
|
||||||
|
|
||||||
QStorageInfo storage(targetDir);
|
QStorageInfo storage(targetDir);
|
||||||
auto bytesAvailable = storage.bytesAvailable();
|
auto bytesAvailable = storage.bytesAvailable();
|
||||||
if (bytesAvailable == -1 || book.getSize() > (unsigned long long) bytesAvailable) {
|
if (bytesAvailable == -1 || book.getSize() > (unsigned long long) bytesAvailable) {
|
||||||
@ -580,7 +593,7 @@ const kiwix::Book& ContentManager::getRemoteOrLocalBook(const QString &id)
|
|||||||
std::string ContentManager::startDownload(const kiwix::Book& book)
|
std::string ContentManager::startDownload(const kiwix::Book& book)
|
||||||
{
|
{
|
||||||
auto downloadPath = getSettingsManager()->getDownloadDir();
|
auto downloadPath = getSettingsManager()->getDownloadDir();
|
||||||
checkEnoughStorageAvailable(book, downloadPath);
|
checkThatBookCanBeSaved(book, downloadPath);
|
||||||
|
|
||||||
typedef std::vector<std::pair<std::string, std::string>> DownloadOptions;
|
typedef std::vector<std::pair<std::string, std::string>> DownloadOptions;
|
||||||
|
|
||||||
@ -600,6 +613,8 @@ void ContentManager::downloadBook(const QString &id)
|
|||||||
std::string downloadId;
|
std::string downloadId;
|
||||||
try {
|
try {
|
||||||
downloadId = startDownload(book);
|
downloadId = startDownload(book);
|
||||||
|
} catch (const ContentManagerError& ) {
|
||||||
|
throw;
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
throwDownloadUnavailableError();
|
throwDownloadUnavailableError();
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,9 @@ void ReadingListBar::setupList()
|
|||||||
} catch (std::out_of_range& e) {
|
} catch (std::out_of_range& e) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if ( !archive ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
auto illustration = archive->getIllustrationItem(48);
|
auto illustration = archive->getIllustrationItem(48);
|
||||||
std::string content = illustration.getData();
|
std::string content = illustration.getData();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user