Allow to remember torrent content files deletion in WebUI

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  #20150.

---------

Co-authored-by: Chocobo1 <Chocobo1@users.noreply.github.com>
This commit is contained in:
David 2024-01-07 21:39:51 -09:00 committed by GitHub
parent 0b6d785e87
commit e69f857828
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 81 additions and 11 deletions

View File

@ -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
@ -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

View File

@ -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;

View File

@ -1,7 +1,7 @@
{
"env": {
"browser": true,
"es2020": true
"es2021": true
},
"extends": "eslint:recommended",
"plugins": [

View File

@ -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) {
@ -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>

View File

@ -34,6 +34,10 @@ button {
padding: 4px 16px;
}
button:disabled {
cursor: initial;
}
/*table { border-collapse: collapse; border-spacing: 0; }*/
:focus {

View File

@ -0,0 +1 @@
<svg height="32" viewBox="0 0 32 32" width="32" xmlns="http://www.w3.org/2000/svg"><path d="m22.58889 13.856795h-13.1776846v-3.690063c0-3.2959186 2.9557016-5.9772288 6.5888426-5.9772288 3.633136 0 6.588842 2.6814977 6.588842 5.9772288zm3.515031.03355v-3.723984c0-5.0541989-4.532547-9.16636116-10.103873-9.16636116-5.571329 0-10.1038769 4.11216226-10.1038769 9.16636116v3.72398c-.7962418.150954-1.3961709.793694-1.3961709 1.560369v13.955002c0 .879047.7884216 1.594288 1.7575164 1.594288h19.4849724c.969092 0 1.757511-.715241 1.757511-1.594288v-13.955002c0-.766675-.599832-1.408677-1.396079-1.560372z" fill="#ff8c00" stroke-width="1.980014"/></svg>

After

Width:  |  Height:  |  Size: 646 B

View File

@ -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();
}
@ -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();
}
@ -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();
}
@ -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);

View File

@ -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>