Skip to content

Commit

Permalink
Allow to remember torrent content files deletion in WebUI
Browse files Browse the repository at this point in the history
Add a 'remember choice' button to the WebUI Torrent Deletion dialog that sets the default file deletion setting. The setting is shared with GUI, so if you set it in WebUI and open the Qt app, the 'delete files' checkbox will match WebUI (checked or unchecked).

PR  qbittorrent#20150.

---------

Co-authored-by: Chocobo1 <[email protected]>
  • Loading branch information
solarfl4re and Chocobo1 authored Jan 8, 2024
1 parent 0b6d785 commit e69f857
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 11 deletions.
5 changes: 5 additions & 0 deletions src/webui/api/appcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ void AppController::preferencesAction()
data[u"file_log_delete_old"_s] = app()->isFileLoggerDeleteOld();
data[u"file_log_age"_s] = app()->fileLoggerAge();
data[u"file_log_age_type"_s] = app()->fileLoggerAgeType();
// Delete torrent contents files on torrent removal
data[u"delete_torrent_content_files"_s] = pref->deleteTorrentFilesAsDefault();

// Downloads
// When adding a torrent
Expand Down Expand Up @@ -494,6 +496,9 @@ void AppController::setPreferencesAction()
app()->setFileLoggerAge(it.value().toInt());
if (hasKey(u"file_log_age_type"_s))
app()->setFileLoggerAgeType(it.value().toInt());
// Delete torrent content files on torrent removal
if (hasKey(u"delete_torrent_content_files"_s))
pref->setDeleteTorrentFilesAsDefault(it.value().toBool());

// Downloads
// When adding a torrent
Expand Down
2 changes: 1 addition & 1 deletion src/webui/webapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
#include "base/utils/version.h"
#include "api/isessionmanager.h"

inline const Utils::Version<3, 2> API_VERSION {2, 10, 1};
inline const Utils::Version<3, 2> API_VERSION {2, 10, 2};

class QTimer;

Expand Down
2 changes: 1 addition & 1 deletion src/webui/www/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"env": {
"browser": true,
"es2020": true
"es2021": true
},
"extends": "eslint:recommended",
"plugins": [
Expand Down
61 changes: 60 additions & 1 deletion src/webui/www/private/confirmdeletion.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,67 @@
<script>
'use strict';

function setRememberBtnEnabled(enable) {
const btn = $('rememberBtn');
btn.disabled = !enable;

const icon = btn.getElementsByTagName('path')[0];
if (enable)
icon.style.removeProperty('fill');
else
icon.style.fill = "var(--color-border-default)";
}

window.addEvent('domready', function() {
new Request({
url: 'images/object-locked.svg',
method: 'get',
onSuccess: function(text, xml) {
const newIcon = xml.childNodes[0];
newIcon.style.height = '24px';
newIcon.style.width = '24px';
$('rememberBtn').appendChild(newIcon);
setRememberBtnEnabled(false);
}
}).send();

const isDeletingFiles = (new URI().getData('deleteFiles') === "true");
$('deleteFromDiskCB').checked = isDeletingFiles;

let prefDeleteContentFiles = false;
new Request.JSON({
url: 'api/v2/app/preferences',
method: 'get',
noCache: true,
onSuccess: function(pref) {
if (!pref)
return;

prefDeleteContentFiles = pref.delete_torrent_content_files;
$('deleteFromDiskCB').checked ||= prefDeleteContentFiles;
}
}).send();
$('deleteFromDiskCB').addEvent('click', function(e) {
setRememberBtnEnabled($('deleteFromDiskCB').checked !== prefDeleteContentFiles);
});

// Set current "Delete files" choice as the default
$('rememberBtn').addEvent('click', function(e) {
new Request({
url: 'api/v2/app/setPreferences',
method: 'post',
data: {
'json': JSON.encode({
'delete_torrent_content_files': $('deleteFromDiskCB').checked
})
},
onSuccess: function() {
prefDeleteContentFiles = $('deleteFromDiskCB').checked;
setRememberBtnEnabled(false);
}
}).send();
});

const hashes = new URI().getData('hashes').split('|');
$('cancelBtn').focus();
$('cancelBtn').addEvent('click', function(e) {
Expand Down Expand Up @@ -45,7 +102,9 @@
<br />

<p>&nbsp;&nbsp;QBT_TR(Are you sure you want to remove the selected torrents from the transfer list?)QBT_TR[CONTEXT=HttpServer]</p>
&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" id="deleteFromDiskCB" /> <label for="deleteFromDiskCB"><i>QBT_TR(Also permanently delete the files)QBT_TR[CONTEXT=confirmDeletionDlg]</i></label><br /><br />
&nbsp;&nbsp;&nbsp;&nbsp;<button id="rememberBtn" type="button" title="Remember choice" style="vertical-align: middle; padding: 4px 6px;">
</button>
<input type="checkbox" id="deleteFromDiskCB" /> <label for="deleteFromDiskCB"><i>QBT_TR(Also permanently delete the files)QBT_TR[CONTEXT=confirmDeletionDlg]</i></label><br /><br />
<div style="text-align: right;">
<input type="button" id="cancelBtn" value="QBT_TR(Cancel)QBT_TR[CONTEXT=MainWindow]" />&nbsp;&nbsp;<input type="button" id="confirmBtn" value="QBT_TR(Remove)QBT_TR[CONTEXT=MainWindow]" />&nbsp;&nbsp;
</div>
Expand Down
4 changes: 4 additions & 0 deletions src/webui/www/private/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ button {
padding: 4px 16px;
}

button:disabled {
cursor: initial;
}

/*table { border-collapse: collapse; border-spacing: 0; }*/

:focus {
Expand Down
1 change: 1 addition & 0 deletions src/webui/www/private/images/object-locked.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions src/webui/www/private/scripts/mocha-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,11 @@ const initializeWindows = function() {
loadMethod: 'iframe',
contentURL: new URI("confirmdeletion.html").setData("hashes", hashes.join("|")).setData("deleteFiles", deleteFiles).toString(),
scrollbars: false,
resizable: false,
resizable: true,
maximizable: false,
padding: 10,
width: 424,
height: 140
height: 160
});
updateMainData();
}
Expand Down Expand Up @@ -711,11 +711,11 @@ const initializeWindows = function() {
loadMethod: 'iframe',
contentURL: new URI("confirmdeletion.html").setData("hashes", hashes.join("|")).toString(),
scrollbars: false,
resizable: false,
resizable: true,
maximizable: false,
padding: 10,
width: 424,
height: 140
height: 160
});
updateMainData();
}
Expand Down Expand Up @@ -852,11 +852,11 @@ const initializeWindows = function() {
loadMethod: 'iframe',
contentURL: new URI("confirmdeletion.html").setData("hashes", hashes.join("|")).toString(),
scrollbars: false,
resizable: false,
resizable: true,
maximizable: false,
padding: 10,
width: 424,
height: 140
height: 160
});
updateMainData();
}
Expand Down Expand Up @@ -938,11 +938,11 @@ const initializeWindows = function() {
loadMethod: 'iframe',
contentURL: new URI("confirmdeletion.html").setData("hashes", hashes.join("|")).toString(),
scrollbars: false,
resizable: false,
resizable: true,
maximizable: false,
padding: 10,
width: 424,
height: 140,
height: 160,
onCloseComplete: function() {
updateMainData();
setTrackerFilter(TRACKERS_ALL);
Expand Down
1 change: 1 addition & 0 deletions src/webui/www/webui.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@
<file>private/images/mail-inbox.svg</file>
<file>private/images/mascot.png</file>
<file>private/images/name.svg</file>
<file>private/images/object-locked.svg</file>
<file>private/images/peers-add.svg</file>
<file>private/images/peers-remove.svg</file>
<file>private/images/queued.svg</file>
Expand Down

0 comments on commit e69f857

Please sign in to comment.