Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to remember torrent content files deletion in WebUI #20150

Merged
merged 6 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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