From bfad14d5524e12cd0d68f78e8e483d707a3e6335 Mon Sep 17 00:00:00 2001 From: Goshik Date: Fri, 8 Jun 2018 09:37:34 +0300 Subject: [PATCH] Create non-existing path in setLocationAction() When using qbittorrent-nox it is not always possible to manually create the target path for torrent moving. This commit allows automatic path creation. It also allows to display error messages in the 'Set location' window. --- src/webui/api/torrentscontroller.cpp | 13 ++++++++++--- src/webui/www/private/scripts/mocha-init.js | 2 +- src/webui/www/private/setlocation.html | 10 ++++++++-- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/webui/api/torrentscontroller.cpp b/src/webui/api/torrentscontroller.cpp index 26dd06829..12ddcddfb 100644 --- a/src/webui/api/torrentscontroller.cpp +++ b/src/webui/api/torrentscontroller.cpp @@ -737,9 +737,16 @@ void TorrentsController::setLocationAction() const QStringList hashes {params()["hashes"].split("|")}; const QString newLocation {params()["location"].trimmed()}; - // check if the location exists - if (newLocation.isEmpty() || !QDir(newLocation).exists()) - return; + if (newLocation.isEmpty()) + throw APIError(APIErrorType::BadParams, tr("Save path is empty")); + + // try to create the location if it does not exist + if (!QDir(newLocation).mkpath(".")) + throw APIError(APIErrorType::Conflict, tr("Cannot make save path")); + + // check permissions + if (!QFileInfo(newLocation).isWritable()) + throw APIError(APIErrorType::AccessDenied, tr("Cannot write to directory")); applyToTorrents(hashes, [newLocation](BitTorrent::TorrentHandle *torrent) { diff --git a/src/webui/www/private/scripts/mocha-init.js b/src/webui/www/private/scripts/mocha-init.js index 0d464d67c..76cd50f6f 100644 --- a/src/webui/www/private/scripts/mocha-init.js +++ b/src/webui/www/private/scripts/mocha-init.js @@ -417,7 +417,7 @@ initializeWindows = function() { paddingVertical: 0, paddingHorizontal: 0, width: 400, - height: 100 + height: 130 }); } }; diff --git a/src/webui/www/private/setlocation.html b/src/webui/www/private/setlocation.html index ab1a72bac..a933407f1 100644 --- a/src/webui/www/private/setlocation.html +++ b/src/webui/www/private/setlocation.html @@ -31,8 +31,10 @@ new Event(e).stop(); // check field var location = $('setLocation').value.trim(); - if (location === null || location === "") + if (location === null || location === "") { + $('error_div').set('text', 'QBT_TR(Save path is empty)QBT_TR[CONTEXT=TorrentsController]'); return false; + } var hashesList = new URI().getData('hashes'); new Request({ @@ -42,8 +44,11 @@ hashes: hashesList, location: location }, - onComplete: function() { + onSuccess: function() { window.parent.closeWindows(); + }, + onFailure: function(xhr) { + $('error_div').set('text', xhr.response); } }).send(); }); @@ -55,6 +60,7 @@

QBT_TR(Location)QBT_TR[CONTEXT=TransferListWidget]:

+