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

WebUI: Add 'Confirm torrent recheck' option #21348

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 @@ -368,6 +368,8 @@ void AppController::preferencesAction()
data[u"save_statistics_interval"_s] = static_cast<int>(session->saveStatisticsInterval().count());
// .torrent file size limit
data[u"torrent_file_size_limit"_s] = pref->getTorrentFileSizeLimit();
// Confirm torrent recheck
data[u"confirm_torrent_recheck"_s] = pref->confirmTorrentRecheck();
// Recheck completed torrents
data[u"recheck_completed_torrents"_s] = pref->recheckTorrentsOnCompletion();
// Customize application instance name
Expand Down Expand Up @@ -977,6 +979,9 @@ void AppController::setPreferencesAction()
// .torrent file size limit
if (hasKey(u"torrent_file_size_limit"_s))
pref->setTorrentFileSizeLimit(it.value().toLongLong());
// Confirm torrent recheck
if (hasKey(u"confirm_torrent_recheck"_s))
pref->setConfirmTorrentRecheck(it.value().toBool());
// Recheck completed torrents
if (hasKey(u"recheck_completed_torrents"_s))
pref->recheckTorrentsOnCompletion(it.value().toBool());
Expand Down
19 changes: 13 additions & 6 deletions src/webui/www/private/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -755,23 +755,23 @@ td.statusBarSeparator {
color: var(--color-text-white);
}

/* Confirm deletion dialog */
/* Modals */

#confirmDeletionPage * {
.modalDialog * {
box-sizing: border-box;
}

#confirmDeletionPage_content {
.modalDialog .mochaContent.pad {
display: flex !important; /* override for default mocha inline style */
flex-direction: column;
height: 100%;
}

#confirmDeletionPage_content > :last-child {
.modalDialog .mochaContent.pad > :last-child {
align-self: flex-end;
}

#confirmDeletionDialog {
.modalDialog .mochaContent.pad > :first-child {
margin: auto 0;
}

Expand All @@ -792,10 +792,11 @@ td.statusBarSeparator {
vertical-align: -1px;
}

#deleteTorrentMessage {
.dialogMessage {
overflow-wrap: anywhere;
}

.genericConfirmGrid,
.confirmDeletionGrid {
align-items: center;
display: grid;
Expand All @@ -804,6 +805,7 @@ td.statusBarSeparator {
margin-bottom: 10px;
}

.confirmGridItem,
.deletionGridItem {
padding: 3px;
}
Expand All @@ -812,8 +814,13 @@ td.statusBarSeparator {
justify-self: center;
}

.confirmWarning,
.confirmDialogWarning {
background: url("../images/dialog-warning.svg") center center no-repeat;
height: 38px;
width: 38px;
}

.confirmWarning {
background-image: url("../images/help-about.svg");
}
64 changes: 47 additions & 17 deletions src/webui/www/private/scripts/mocha-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,24 @@ window.qBittorrent.Dialog ??= (() => {

const deepFreeze = (obj) => {
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze#examples
// accounts for circular refs
const frozen = new WeakSet();
const deepFreezeSafe = (obj) => {
if (frozen.has(obj))
return;

frozen.add(obj);

const keys = Reflect.ownKeys(obj);
for (const key of keys) {
const value = obj[key];
if ((value && (typeof value === "object")) || (typeof value === "function"))
deepFreezeSafe(value);
}
Object.freeze(obj);
};

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

const baseModalOptions = Object.assign(Object.create(null), {
Expand All @@ -76,7 +86,11 @@ window.qBittorrent.Dialog ??= (() => {
left: 5
},
resizable: true,
width: 480
width: 480,
onCloseComplete: function() {
// make sure overlay is properly hidden upon modal closing
document.getElementById("modalOverlay").style.display = "none";
}
});

deepFreeze(baseModalOptions);
Expand Down Expand Up @@ -541,15 +555,31 @@ const initializeWindows = function() {

recheckFN = function() {
const hashes = torrentsTable.selectedRowsIds();
if (hashes.length) {
new Request({
url: "api/v2/torrents/recheck",
method: "post",
data: {
hashes: hashes.join("|"),
}
}).send();
updateMainData();
if (hashes.length > 0) {
if (window.qBittorrent.Cache.preferences.get().confirm_torrent_recheck) {
new MochaUI.Modal({
...window.qBittorrent.Dialog.baseModalOptions,
id: "confirmRecheckDialog",
title: "QBT_TR(Recheck confirmation)QBT_TR[CONTEXT=confirmRecheckDialog]",
data: { hashes: hashes },
contentURL: "views/confirmRecheck.html"
});
}
else {
new Request({
url: "api/v2/torrents/recheck",
method: "post",
data: {
"hashes": hashes.join("|"),
},
onSuccess: function() {
updateMainData();
},
onFailure: function() {
alert("QBT_TR(Unable to recheck torrents.)QBT_TR[CONTEXT=HttpServer]");
}
}).send();
}
}
};

Expand Down
59 changes: 59 additions & 0 deletions src/webui/www/private/views/confirmRecheck.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<div id="confirmRecheckDialog">
<div class="genericConfirmGrid">
<span class="confirmGridItem confirmWarning"></span>
<span class="confirmGridItem dialogMessage" id="confirmRecheckMessage"></span>
</div>
</div>
<div>
<input type="button" value="QBT_TR(Yes)QBT_TR[CONTEXT=MainWindow]" id="confirmRecheckButton">
<input type="button" value="QBT_TR(No)QBT_TR[CONTEXT=MainWindow]" id="cancelRecheckButton">
</div>

<script>
"use strict";

(() => {
const confirmButton = document.getElementById("confirmRecheckButton");
const cancelButton = document.getElementById("cancelRecheckButton");
const confirmText = document.getElementById("confirmRecheckMessage");

const {
options: { data: { hashes } },
windowEl
} = window.MUI.Windows.instances["confirmRecheckDialog"];

confirmText.textContent = "QBT_TR(Are you sure you want to recheck the selected torrent(s)?)QBT_TR[CONTEXT=confirmRecheckDialog]";

cancelButton.addEventListener("click", (e) => { window.qBittorrent.Client.closeWindow("confirmRecheckDialog"); });
confirmButton.addEventListener("click", (e) => {
new Request({
url: "api/v2/torrents/recheck",
method: "post",
data: {
hashes: hashes.join("|"),
},
onSuccess: function() {
updateMainData();
window.qBittorrent.Client.closeWindow("confirmRecheckDialog");
},
onFailure: function() {
alert("QBT_TR(Unable to recheck torrents.)QBT_TR[CONTEXT=HttpServer]");
}
}).send();
});

// set tabindex so window element receives keydown events
windowEl.setAttribute("tabindex", "-1");
windowEl.focus();
windowEl.addEventListener("keydown", (e) => {
switch (e.key) {
case "Enter":
confirmButton.click();
break;
case "Escape":
window.qBittorrent.Client.closeWindow("confirmRecheckDialog");
break;
}
});
})();
</script>
2 changes: 1 addition & 1 deletion src/webui/www/private/views/confirmdeletion.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div id="confirmDeletionDialog">
<div class="confirmDeletionGrid">
<span class="deletionGridItem confirmDialogWarning"></span>
<span class="deletionGridItem" id="deleteTorrentMessage"></span>
<span class="deletionGridItem dialogMessage" id="deleteTorrentMessage"></span>
<span class="deletionGridItem">
<button class="disabled" type="button" id="rememberBtn" title="QBT_TR(Remember choice)QBT_TR[CONTEXT=HttpServer]" aria-label="QBT_TR(Remember choice)QBT_TR[CONTEXT=HttpServer]" disabled></button>
</span>
Expand Down
10 changes: 10 additions & 0 deletions src/webui/www/private/views/preferences.html
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,14 @@
<input type="text" id="torrentFileSizeLimit" style="width: 15em;">&nbsp;&nbsp;QBT_TR(MiB)QBT_TR[CONTEXT=OptionsDialog]
</td>
</tr>
<tr>
<td>
<label for="confirmTorrentRecheck">QBT_TR(Confirm torrent recheck:)QBT_TR[CONTEXT=OptionsDialog]</label>
</td>
<td>
<input type="checkbox" id="confirmTorrentRecheck">
</td>
</tr>
<tr>
<td>
<label for="recheckTorrentsOnCompletion">QBT_TR(Recheck torrents on completion:)QBT_TR[CONTEXT=OptionsDialog]</label>
Expand Down Expand Up @@ -2464,6 +2472,7 @@
$("saveResumeDataInterval").value = pref.save_resume_data_interval;
$("saveStatisticsInterval").value = pref.save_statistics_interval;
$("torrentFileSizeLimit").value = (pref.torrent_file_size_limit / 1024 / 1024);
document.getElementById("confirmTorrentRecheck").checked = pref.confirm_torrent_recheck;
$("recheckTorrentsOnCompletion").checked = pref.recheck_completed_torrents;
$("appInstanceName").value = pref.app_instance_name;
$("refreshInterval").value = pref.refresh_interval;
Expand Down Expand Up @@ -2920,6 +2929,7 @@
settings["save_resume_data_interval"] = Number($("saveResumeDataInterval").value);
settings["save_statistics_interval"] = Number($("saveStatisticsInterval").value);
settings["torrent_file_size_limit"] = ($("torrentFileSizeLimit").value * 1024 * 1024);
settings["confirm_torrent_recheck"] = document.getElementById("confirmTorrentRecheck").checked;
settings["recheck_completed_torrents"] = $("recheckTorrentsOnCompletion").checked;
settings["app_instance_name"] = $("appInstanceName").value;
settings["refresh_interval"] = Number($("refreshInterval").value);
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 @@ -421,6 +421,7 @@
<file>private/views/about.html</file>
<file>private/views/aboutToolbar.html</file>
<file>private/views/confirmdeletion.html</file>
<file>private/views/confirmRecheck.html</file>
<file>private/views/filters.html</file>
<file>private/views/installsearchplugin.html</file>
<file>private/views/log.html</file>
Expand Down
Loading