mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-16 02:03:07 -07:00
WebUI: Improve torrent deletion
* Added 'Confirm when deleting torrents' option to the WebUI * Confirm deletion dialog now uses MUI.Modal PR #21289. Closes #18345.
This commit is contained in:
parent
a0c32110f1
commit
0ea35c54a3
4 changed files with 202 additions and 99 deletions
|
@ -127,6 +127,8 @@ void AppController::preferencesAction()
|
||||||
// Language
|
// Language
|
||||||
data[u"locale"_s] = pref->getLocale();
|
data[u"locale"_s] = pref->getLocale();
|
||||||
data[u"performance_warning"_s] = session->isPerformanceWarningEnabled();
|
data[u"performance_warning"_s] = session->isPerformanceWarningEnabled();
|
||||||
|
// Transfer List
|
||||||
|
data[u"confirm_torrent_deletion"_s] = pref->confirmTorrentDeletion();
|
||||||
// Log file
|
// Log file
|
||||||
data[u"file_log_enabled"_s] = app()->isFileLoggerEnabled();
|
data[u"file_log_enabled"_s] = app()->isFileLoggerEnabled();
|
||||||
data[u"file_log_path"_s] = app()->fileLoggerPath().toString();
|
data[u"file_log_path"_s] = app()->fileLoggerPath().toString();
|
||||||
|
@ -504,6 +506,9 @@ void AppController::setPreferencesAction()
|
||||||
}
|
}
|
||||||
if (hasKey(u"performance_warning"_s))
|
if (hasKey(u"performance_warning"_s))
|
||||||
session->setPerformanceWarningEnabled(it.value().toBool());
|
session->setPerformanceWarningEnabled(it.value().toBool());
|
||||||
|
// Transfer List
|
||||||
|
if (hasKey(u"confirm_torrent_deletion"_s))
|
||||||
|
pref->setConfirmTorrentDeletion(it.value().toBool());
|
||||||
// Log file
|
// Log file
|
||||||
if (hasKey(u"file_log_enabled"_s))
|
if (hasKey(u"file_log_enabled"_s))
|
||||||
app()->setFileLoggerEnabled(it.value().toBool());
|
app()->setFileLoggerEnabled(it.value().toBool());
|
||||||
|
|
|
@ -205,7 +205,7 @@ div.mochaToolbarWrapper.bottom {
|
||||||
---------------------------------------------------------------- */
|
---------------------------------------------------------------- */
|
||||||
|
|
||||||
#modalOverlay {
|
#modalOverlay {
|
||||||
background: #000;
|
background: hsla(0deg 0 0 / 30%);
|
||||||
display: none;
|
display: none;
|
||||||
left: 0;
|
left: 0;
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
|
|
|
@ -38,6 +38,53 @@
|
||||||
----------------------------------------------------------------- */
|
----------------------------------------------------------------- */
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
window.qBittorrent ??= {};
|
||||||
|
window.qBittorrent.Dialog ??= (() => {
|
||||||
|
const exports = () => {
|
||||||
|
return {
|
||||||
|
baseModalOptions: baseModalOptions
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const deepFreeze = (obj) => {
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze#examples
|
||||||
|
|
||||||
|
const keys = Reflect.ownKeys(obj);
|
||||||
|
for (const key of keys) {
|
||||||
|
const value = obj[key];
|
||||||
|
if ((value && (typeof value === "object")) || (typeof value === "function"))
|
||||||
|
deepFreeze(value);
|
||||||
|
}
|
||||||
|
Object.freeze(obj);
|
||||||
|
};
|
||||||
|
|
||||||
|
const baseModalOptions = Object.assign(Object.create(null), {
|
||||||
|
addClass: "modalDialog",
|
||||||
|
collapsible: false,
|
||||||
|
cornerRadius: 5,
|
||||||
|
draggable: true,
|
||||||
|
footerHeight: 20,
|
||||||
|
icon: "images/qbittorrent-tray.svg",
|
||||||
|
loadMethod: "xhr",
|
||||||
|
maximizable: false,
|
||||||
|
method: "post",
|
||||||
|
minimizable: false,
|
||||||
|
padding: {
|
||||||
|
top: 15,
|
||||||
|
right: 10,
|
||||||
|
bottom: 15,
|
||||||
|
left: 5
|
||||||
|
},
|
||||||
|
resizable: true,
|
||||||
|
width: 480
|
||||||
|
});
|
||||||
|
|
||||||
|
deepFreeze(baseModalOptions);
|
||||||
|
|
||||||
|
return exports();
|
||||||
|
})();
|
||||||
|
Object.freeze(window.qBittorrent.Dialog);
|
||||||
|
|
||||||
const LocalPreferences = new window.qBittorrent.LocalPreferences.LocalPreferencesClass();
|
const LocalPreferences = new window.qBittorrent.LocalPreferences.LocalPreferencesClass();
|
||||||
|
|
||||||
let saveWindowSize = function() {};
|
let saveWindowSize = function() {};
|
||||||
|
@ -396,32 +443,43 @@ const initializeWindows = function() {
|
||||||
deleteFN = function(forceDeleteFiles = false) {
|
deleteFN = function(forceDeleteFiles = false) {
|
||||||
const hashes = torrentsTable.selectedRowsIds();
|
const hashes = torrentsTable.selectedRowsIds();
|
||||||
if (hashes.length > 0) {
|
if (hashes.length > 0) {
|
||||||
window.qBittorrent.Client.closeWindow("confirmDeletionPage");
|
if (window.qBittorrent.Cache.preferences.get().confirm_torrent_deletion) {
|
||||||
|
new MochaUI.Modal({
|
||||||
new MochaUI.Window({
|
...window.qBittorrent.Dialog.baseModalOptions,
|
||||||
id: "confirmDeletionPage",
|
id: "confirmDeletionPage",
|
||||||
icon: "images/qbittorrent-tray.svg",
|
title: "QBT_TR(Remove torrent(s))QBT_TR[CONTEXT=confirmDeletionDlg]",
|
||||||
title: "QBT_TR(Remove torrent(s))QBT_TR[CONTEXT=confirmDeletionDlg]",
|
data: {
|
||||||
data: {
|
hashes: hashes,
|
||||||
hashes: hashes,
|
forceDeleteFiles: forceDeleteFiles
|
||||||
forceDeleteFiles: forceDeleteFiles
|
},
|
||||||
},
|
contentURL: "views/confirmdeletion.html",
|
||||||
loadMethod: "xhr",
|
onContentLoaded: function(w) {
|
||||||
contentURL: "views/confirmdeletion.html",
|
MochaUI.resizeWindow(w, { centered: true });
|
||||||
maximizable: false,
|
MochaUI.centerWindow(w);
|
||||||
collapsible: false,
|
},
|
||||||
padding: {
|
onCloseComplete: function() {
|
||||||
left: 5,
|
// make sure overlay is properly hidden upon modal closing
|
||||||
right: 10,
|
document.getElementById("modalOverlay").style.display = "none";
|
||||||
top: 15,
|
}
|
||||||
bottom: 15
|
});
|
||||||
},
|
}
|
||||||
width: 480,
|
else {
|
||||||
onContentLoaded: function(w) {
|
new Request({
|
||||||
MochaUI.resizeWindow(w, { centered: true });
|
url: "api/v2/torrents/delete",
|
||||||
MochaUI.centerWindow(w);
|
method: "post",
|
||||||
}
|
data: {
|
||||||
});
|
hashes: hashes.join("|"),
|
||||||
|
deleteFiles: forceDeleteFiles
|
||||||
|
},
|
||||||
|
onSuccess: function() {
|
||||||
|
torrentsTable.deselectAll();
|
||||||
|
updateMainData();
|
||||||
|
},
|
||||||
|
onFailure: function() {
|
||||||
|
alert("QBT_TR(Unable to delete torrents.)QBT_TR[CONTEXT=HttpServer]");
|
||||||
|
}
|
||||||
|
}).send();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -745,29 +803,40 @@ const initializeWindows = function() {
|
||||||
deleteTorrentsByCategoryFN = function(categoryHash) {
|
deleteTorrentsByCategoryFN = function(categoryHash) {
|
||||||
const hashes = torrentsTable.getFilteredTorrentsHashes("all", categoryHash, TAGS_ALL, TRACKERS_ALL);
|
const hashes = torrentsTable.getFilteredTorrentsHashes("all", categoryHash, TAGS_ALL, TRACKERS_ALL);
|
||||||
if (hashes.length > 0) {
|
if (hashes.length > 0) {
|
||||||
window.qBittorrent.Client.closeWindow("confirmDeletionPage");
|
if (window.qBittorrent.Cache.preferences.get().confirm_torrent_deletion) {
|
||||||
|
new MochaUI.Modal({
|
||||||
new MochaUI.Window({
|
...window.qBittorrent.Dialog.baseModalOptions,
|
||||||
id: "confirmDeletionPage",
|
id: "confirmDeletionPage",
|
||||||
icon: "images/qbittorrent-tray.svg",
|
title: "QBT_TR(Remove torrent(s))QBT_TR[CONTEXT=confirmDeletionDlg]",
|
||||||
title: "QBT_TR(Remove torrent(s))QBT_TR[CONTEXT=confirmDeletionDlg]",
|
data: { hashes: hashes },
|
||||||
data: { hashes: hashes },
|
contentURL: "views/confirmdeletion.html",
|
||||||
loadMethod: "xhr",
|
onContentLoaded: function(w) {
|
||||||
contentURL: "views/confirmdeletion.html",
|
MochaUI.resizeWindow(w, { centered: true });
|
||||||
maximizable: false,
|
MochaUI.centerWindow(w);
|
||||||
collapsible: false,
|
},
|
||||||
padding: {
|
onCloseComplete: function() {
|
||||||
left: 5,
|
// make sure overlay is properly hidden upon modal closing
|
||||||
right: 10,
|
document.getElementById("modalOverlay").style.display = "none";
|
||||||
top: 15,
|
}
|
||||||
bottom: 15
|
});
|
||||||
},
|
}
|
||||||
width: 480,
|
else {
|
||||||
onContentLoaded: function(w) {
|
new Request({
|
||||||
MochaUI.resizeWindow(w, { centered: true });
|
url: "api/v2/torrents/delete",
|
||||||
MochaUI.centerWindow(w);
|
method: "post",
|
||||||
}
|
data: {
|
||||||
});
|
hashes: hashes.join("|"),
|
||||||
|
deleteFiles: false,
|
||||||
|
},
|
||||||
|
onSuccess: function() {
|
||||||
|
torrentsTable.deselectAll();
|
||||||
|
updateMainData();
|
||||||
|
},
|
||||||
|
onFailure: function() {
|
||||||
|
alert("QBT_TR(Unable to delete torrents.)QBT_TR[CONTEXT=HttpServer]");
|
||||||
|
}
|
||||||
|
}).send();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -899,29 +968,40 @@ const initializeWindows = function() {
|
||||||
deleteTorrentsByTagFN = function(tagHash) {
|
deleteTorrentsByTagFN = function(tagHash) {
|
||||||
const hashes = torrentsTable.getFilteredTorrentsHashes("all", CATEGORIES_ALL, tagHash, TRACKERS_ALL);
|
const hashes = torrentsTable.getFilteredTorrentsHashes("all", CATEGORIES_ALL, tagHash, TRACKERS_ALL);
|
||||||
if (hashes.length > 0) {
|
if (hashes.length > 0) {
|
||||||
window.qBittorrent.Client.closeWindow("confirmDeletionPage");
|
if (window.qBittorrent.Cache.preferences.get().confirm_torrent_deletion) {
|
||||||
|
new MochaUI.Modal({
|
||||||
new MochaUI.Window({
|
...window.qBittorrent.Dialog.baseModalOptions,
|
||||||
id: "confirmDeletionPage",
|
id: "confirmDeletionPage",
|
||||||
icon: "images/qbittorrent-tray.svg",
|
title: "QBT_TR(Remove torrent(s))QBT_TR[CONTEXT=confirmDeletionDlg]",
|
||||||
title: "QBT_TR(Remove torrent(s))QBT_TR[CONTEXT=confirmDeletionDlg]",
|
data: { hashes: hashes },
|
||||||
data: { hashes: hashes },
|
contentURL: "views/confirmdeletion.html",
|
||||||
loadMethod: "xhr",
|
onContentLoaded: function(w) {
|
||||||
contentURL: "views/confirmdeletion.html",
|
MochaUI.resizeWindow(w, { centered: true });
|
||||||
maximizable: false,
|
MochaUI.centerWindow(w);
|
||||||
collapsible: false,
|
},
|
||||||
padding: {
|
onCloseComplete: function() {
|
||||||
left: 5,
|
// make sure overlay is properly hidden upon modal closing
|
||||||
right: 10,
|
document.getElementById("modalOverlay").style.display = "none";
|
||||||
top: 15,
|
}
|
||||||
bottom: 15
|
});
|
||||||
},
|
}
|
||||||
width: 480,
|
else {
|
||||||
onContentLoaded: function(w) {
|
new Request({
|
||||||
MochaUI.resizeWindow(w, { centered: true });
|
url: "api/v2/torrents/delete",
|
||||||
MochaUI.centerWindow(w);
|
method: "post",
|
||||||
}
|
data: {
|
||||||
});
|
hashes: hashes.join("|"),
|
||||||
|
deleteFiles: false,
|
||||||
|
},
|
||||||
|
onSuccess: function() {
|
||||||
|
torrentsTable.deselectAll();
|
||||||
|
updateMainData();
|
||||||
|
},
|
||||||
|
onFailure: function() {
|
||||||
|
alert("QBT_TR(Unable to delete torrents.)QBT_TR[CONTEXT=HttpServer]");
|
||||||
|
}
|
||||||
|
}).send();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1013,32 +1093,44 @@ const initializeWindows = function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hashes.length > 0) {
|
if (hashes.length > 0) {
|
||||||
window.qBittorrent.Client.closeWindow("confirmDeletionPage");
|
if (window.qBittorrent.Cache.preferences.get().confirm_torrent_deletion) {
|
||||||
|
new MochaUI.Modal({
|
||||||
new MochaUI.Window({
|
...window.qBittorrent.Dialog.baseModalOptions,
|
||||||
id: "confirmDeletionPage",
|
id: "confirmDeletionPage",
|
||||||
icon: "images/qbittorrent-tray.svg",
|
title: "QBT_TR(Remove torrent(s))QBT_TR[CONTEXT=confirmDeletionDlg]",
|
||||||
title: "QBT_TR(Remove torrent(s))QBT_TR[CONTEXT=confirmDeletionDlg]",
|
data: {
|
||||||
data: {
|
hashes: hashes,
|
||||||
hashes: hashes,
|
filterList: "tracker"
|
||||||
filterList: "tracker"
|
},
|
||||||
},
|
contentURL: "views/confirmdeletion.html",
|
||||||
loadMethod: "xhr",
|
onContentLoaded: function(w) {
|
||||||
contentURL: "views/confirmdeletion.html",
|
MochaUI.resizeWindow(w, { centered: true });
|
||||||
maximizable: false,
|
MochaUI.centerWindow(w);
|
||||||
collapsible: false,
|
},
|
||||||
padding: {
|
onCloseComplete: function() {
|
||||||
left: 5,
|
// make sure overlay is properly hidden upon modal closing
|
||||||
right: 10,
|
document.getElementById("modalOverlay").style.display = "none";
|
||||||
top: 15,
|
}
|
||||||
bottom: 15
|
});
|
||||||
},
|
}
|
||||||
width: 480,
|
else {
|
||||||
onContentLoaded: function(w) {
|
new Request({
|
||||||
MochaUI.resizeWindow(w, { centered: true });
|
url: "api/v2/torrents/delete",
|
||||||
MochaUI.centerWindow(w);
|
method: "post",
|
||||||
}
|
data: {
|
||||||
});
|
hashes: hashes.join("|"),
|
||||||
|
deleteFiles: false,
|
||||||
|
},
|
||||||
|
onSuccess: function() {
|
||||||
|
torrentsTable.deselectAll();
|
||||||
|
setTrackerFilter(TRACKERS_ALL);
|
||||||
|
updateMainData();
|
||||||
|
},
|
||||||
|
onFailure: function() {
|
||||||
|
alert("QBT_TR(Unable to delete torrents.)QBT_TR[CONTEXT=HttpServer]");
|
||||||
|
},
|
||||||
|
}).send();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,10 @@
|
||||||
|
|
||||||
<fieldset class="settings">
|
<fieldset class="settings">
|
||||||
<legend>QBT_TR(Transfer list)QBT_TR[CONTEXT=OptionsDialog]</legend>
|
<legend>QBT_TR(Transfer list)QBT_TR[CONTEXT=OptionsDialog]</legend>
|
||||||
|
<div class="formRow" style="margin-bottom: 3px;" title="QBT_TR(Shows a confirmation dialog upon torrent deletion)QBT_TR[CONTEXT=OptionsDialog]">
|
||||||
|
<input type="checkbox" id="confirmTorrentDeletion">
|
||||||
|
<label for="confirmTorrentDeletion">QBT_TR(Confirm when deleting torrents)QBT_TR[CONTEXT=OptionsDialog]</label>
|
||||||
|
</div>
|
||||||
<div class="formRow" style="margin-bottom: 3px;">
|
<div class="formRow" style="margin-bottom: 3px;">
|
||||||
<input type="checkbox" id="useAltRowColorsInput">
|
<input type="checkbox" id="useAltRowColorsInput">
|
||||||
<label for="useAltRowColorsInput">QBT_TR(Use alternating row colors)QBT_TR[CONTEXT=OptionsDialog]</label>
|
<label for="useAltRowColorsInput">QBT_TR(Use alternating row colors)QBT_TR[CONTEXT=OptionsDialog]</label>
|
||||||
|
@ -2107,6 +2111,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
|
||||||
document.getElementById("hideZeroFiltersCheckbox").checked = (LocalPreferences.get("hide_zero_status_filters", "false") === "true");
|
document.getElementById("hideZeroFiltersCheckbox").checked = (LocalPreferences.get("hide_zero_status_filters", "false") === "true");
|
||||||
$("dblclickDownloadSelect").value = LocalPreferences.get("dblclick_download", "1");
|
$("dblclickDownloadSelect").value = LocalPreferences.get("dblclick_download", "1");
|
||||||
$("dblclickCompleteSelect").value = LocalPreferences.get("dblclick_complete", "1");
|
$("dblclickCompleteSelect").value = LocalPreferences.get("dblclick_complete", "1");
|
||||||
|
document.getElementById("confirmTorrentDeletion").checked = pref.confirm_torrent_deletion;
|
||||||
document.getElementById("useAltRowColorsInput").checked = (LocalPreferences.get("use_alt_row_colors", "true") === "true");
|
document.getElementById("useAltRowColorsInput").checked = (LocalPreferences.get("use_alt_row_colors", "true") === "true");
|
||||||
$("filelog_checkbox").checked = pref.file_log_enabled;
|
$("filelog_checkbox").checked = pref.file_log_enabled;
|
||||||
$("filelog_save_path_input").value = pref.file_log_path;
|
$("filelog_save_path_input").value = pref.file_log_path;
|
||||||
|
@ -2522,6 +2527,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
|
||||||
LocalPreferences.set("hide_zero_status_filters", document.getElementById("hideZeroFiltersCheckbox").checked.toString());
|
LocalPreferences.set("hide_zero_status_filters", document.getElementById("hideZeroFiltersCheckbox").checked.toString());
|
||||||
LocalPreferences.set("dblclick_download", $("dblclickDownloadSelect").value);
|
LocalPreferences.set("dblclick_download", $("dblclickDownloadSelect").value);
|
||||||
LocalPreferences.set("dblclick_complete", $("dblclickCompleteSelect").value);
|
LocalPreferences.set("dblclick_complete", $("dblclickCompleteSelect").value);
|
||||||
|
settings["confirm_torrent_deletion"] = document.getElementById("confirmTorrentDeletion").checked;
|
||||||
LocalPreferences.set("use_alt_row_colors", document.getElementById("useAltRowColorsInput").checked.toString());
|
LocalPreferences.set("use_alt_row_colors", document.getElementById("useAltRowColorsInput").checked.toString());
|
||||||
settings["file_log_enabled"] = $("filelog_checkbox").checked;
|
settings["file_log_enabled"] = $("filelog_checkbox").checked;
|
||||||
settings["file_log_path"] = $("filelog_save_path_input").value;
|
settings["file_log_path"] = $("filelog_save_path_input").value;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue