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 3 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
7 changes: 7 additions & 0 deletions src/webui/api/appcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ void AppController::preferencesAction()
data[u"excluded_file_names_enabled"_s] = session->isExcludedFileNamesEnabled();
data[u"excluded_file_names"_s] = session->excludedFileNames().join(u'\n');

// Default setting for torrent file deletion on torrent removal
data[u"delete_torrent_files_as_default"_s] = pref->deleteTorrentFilesAsDefault();

// Email notification upon download completion
data[u"mail_notification_enabled"_s] = pref->isMailNotificationEnabled();
data[u"mail_notification_sender"_s] = pref->getMailNotificationSender();
Expand Down Expand Up @@ -597,6 +600,10 @@ void AppController::setPreferencesAction()
if (hasKey(u"excluded_file_names"_s))
session->setExcludedFileNames(it.value().toString().split(u'\n'));

// Default setting for torrent file deletion on torrent removal
if (hasKey(u"delete_torrent_files_as_default"_s))
pref->setDeleteTorrentFilesAsDefault(it.value().toBool());

// Email notification upon download completion
if (hasKey(u"mail_notification_enabled"_s))
pref->setMailNotificationEnabled(it.value().toBool());
Expand Down
63 changes: 62 additions & 1 deletion src/webui/www/private/confirmdeletion.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,53 @@
const isDeletingFiles = (new URI().getData('deleteFiles') === "true");
$('deleteFromDiskCB').checked = isDeletingFiles;

// Add SVG lock icon to rememberBtn with JS so we can change the fill color
new Request({
url: '/images/object-locked.svg',
method: 'get',
onSuccess: function(text, xml) {
// The SVG's height is 32px, which is too big for our dialog
xml.childNodes[0].style.height = '24px';
xml.childNodes[0].style.width = '24px';
$('rememberBtn').appendChild(xml.childNodes[0]);
// Disable button until delete-files checkbox is clicked
disableRememberBtn();
}
}).send();

new Request.JSON({
url: 'api/v2/app/preferences',
method: 'get',
noCache: true,
onSuccess: function(pref) {
if (pref) {
$('deleteFromDiskCB').checked = pref.delete_torrent_files_as_default;
}
}
}).send();

$('rememberBtn').addEvent('click', function(e) {
const cmd = 'api/v2/app/setPreferences';
const deleteTorrentFilesAsDefault = $('deleteFromDiskCB').checked;
new Request({
url: cmd,
method: 'post',
data: {
'json': JSON.encode({
'delete_torrent_files_as_default': deleteTorrentFilesAsDefault
})
},
onComplete: function() {
disableRememberBtn();
}
}).send();
});

// Undisable rememberBtn if checkbox is clicked
$('deleteFromDiskCB').addEvent('click', function(e) {
enableRememberBtn();
});

const hashes = new URI().getData('hashes').split('|');
$('cancelBtn').focus();
$('cancelBtn').addEvent('click', function(e) {
Expand All @@ -38,14 +85,28 @@
}).send();
});
});

function enableRememberBtn() {
let btn = $('rememberBtn');
btn.disabled = false;
btn.getElementsByTagName('path')[0].style.fill = "";
}

function disableRememberBtn() {
let btn = $('rememberBtn');
btn.disabled = true;
btn.getElementsByTagName('path')[0].style.fill = "lightgray";
}
</script>
</head>

<body>
<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;">
</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
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.
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
Loading