Backport changes to v5.1.x branch

PR #22591.
This commit is contained in:
Vladimir Golovnev
2025-06-20 19:16:30 +03:00
committed by GitHub
45 changed files with 353 additions and 119 deletions

View File

@@ -96,7 +96,7 @@ QVariantMap serialize(const BitTorrent::Torrent &torrent)
const auto adjustRatio = [](const qreal ratio) -> qreal
{
return (ratio > BitTorrent::Torrent::MAX_RATIO) ? -1 : ratio;
return (ratio >= BitTorrent::Torrent::MAX_RATIO) ? -1 : ratio;
};
const auto getLastActivityTime = [&torrent]() -> qlonglong

View File

@@ -522,8 +522,8 @@ void TorrentsController::propertiesAction()
{KEY_PROP_SEEDS_TOTAL, torrent->totalSeedsCount()},
{KEY_PROP_PEERS, torrent->leechsCount()},
{KEY_PROP_PEERS_TOTAL, torrent->totalLeechersCount()},
{KEY_PROP_RATIO, ((ratio > BitTorrent::Torrent::MAX_RATIO) ? -1 : ratio)},
{KEY_PROP_POPULARITY, ((popularity > BitTorrent::Torrent::MAX_RATIO) ? -1 : popularity)},
{KEY_PROP_RATIO, ((ratio >= BitTorrent::Torrent::MAX_RATIO) ? -1 : ratio)},
{KEY_PROP_POPULARITY, ((popularity >= BitTorrent::Torrent::MAX_RATIO) ? -1 : popularity)},
{KEY_PROP_REANNOUNCE, torrent->nextAnnounce()},
{KEY_PROP_TOTAL_SIZE, torrent->totalSize()},
{KEY_PROP_PIECES_NUM, torrent->piecesCount()},

View File

@@ -26,6 +26,7 @@
<script defer src="scripts/lib/MooTools-Core-1.6.0-compat-compressed.js"></script>
<script defer src="scripts/lib/MooTools-More-1.6.0-compat-compressed.js"></script>
<script defer src="scripts/lib/mocha.min.js"></script>
<script defer src="scripts/monkeypatch.js?v=${CACHEID}"></script>
<script defer src="scripts/cache.js?v=${CACHEID}"></script>
<script defer src="scripts/localpreferences.js?v=${CACHEID}"></script>
<script defer src="scripts/color-scheme.js?v=${CACHEID}"></script>

View File

@@ -147,9 +147,9 @@
break;
}
});
});
window.qBittorrent.pathAutofill.attachPathAutofill();
window.qBittorrent.pathAutofill.attachPathAutofill();
});
</script>
</head>

View File

@@ -10,7 +10,6 @@
<script src="scripts/localpreferences.js?v=${CACHEID}"></script>
<script src="scripts/color-scheme.js?v=${CACHEID}"></script>
<script src="scripts/misc.js?locale=${LANG}&v=${CACHEID}"></script>
<script src="scripts/pathAutofill.js?v=${CACHEID}"></script>
<script>
"use strict";
@@ -62,15 +61,13 @@
});
});
});
window.qBittorrent.pathAutofill.attachPathAutofill();
</script>
</head>
<body>
<div style="padding: 10px 10px 0px 10px;">
<label for="folderName" style="font-weight: bold;">QBT_TR(Folder name:)QBT_TR[CONTEXT=RSSWidget]</label>
<input type="text" id="folderName" class="pathDirectory" style="width: 320px;">
<input type="text" id="folderName" style="width: 320px;">
<div style="text-align: center; padding-top: 10px;">
<input type="button" value="QBT_TR(OK)QBT_TR[CONTEXT=HttpServer]" id="submitButton">
</div>

View File

@@ -411,7 +411,7 @@
<label for="multirename_rememberprefs_checkbox">QBT_TR(Remember Multi-Rename settings)QBT_TR[CONTEXT=OptionsDialog]</label>
</div>
<hr>
<textarea id="multiRenameSearch" placeholder="QBT_TR(Search Files)QBT_TR[CONTEXT=PropertiesWidget]" aria-label="QBT_TR(Search Files)QBT_TR[CONTEXT=PropertiesWidget]" style="width: calc(100% - 8px); resize: vertical; min-height: 30px;"></textarea>
<textarea id="multiRenameSearch" placeholder="QBT_TR(Search Files)QBT_TR[CONTEXT=PropertiesWidget]" aria-label="QBT_TR(Search Files)QBT_TR[CONTEXT=PropertiesWidget]" style="width: calc(100% - 8px); resize: vertical; min-height: 30px; font-family: monospace;"></textarea>
<div class="formRow">
<input type="checkbox" id="use_regex_search">
<label for="use_regex_search">QBT_TR(Use regular expressions)QBT_TR[CONTEXT=PropertiesWidget]</label>
@@ -425,7 +425,7 @@
<label for="case_sensitive">QBT_TR(Case sensitive)QBT_TR[CONTEXT=PropertiesWidget]</label>
</div>
<hr>
<textarea id="multiRenameReplace" placeholder="QBT_TR(Replacement Input)QBT_TR[CONTEXT=PropertiesWidget]" aria-label="QBT_TR(Replacement Input)QBT_TR[CONTEXT=PropertiesWidget]" style="width: calc(100% - 8px); resize: vertical; min-height: 30px;"></textarea>
<textarea id="multiRenameReplace" placeholder="QBT_TR(Replacement Input)QBT_TR[CONTEXT=PropertiesWidget]" aria-label="QBT_TR(Replacement Input)QBT_TR[CONTEXT=PropertiesWidget]" style="width: calc(100% - 8px); resize: vertical; min-height: 30px; font-family: monospace;"></textarea>
<select id="applies_to_option" name="applies_to_option" aria-label="QBT_TR(Apply to which filename part)QBT_TR[CONTEXT=PropertiesWidget]" style="width: 100%; margin-bottom: 5px;">
<option selected value="FilenameExtension">QBT_TR(Filename + Extension)QBT_TR[CONTEXT=PropertiesWidget]</option>
<option value="Filename">QBT_TR(Filename)QBT_TR[CONTEXT=PropertiesWidget]</option>

View File

@@ -174,7 +174,9 @@ let selectedStatus = LocalPreferences.get("selected_filter", "all");
let setStatusFilter = () => {};
let toggleFilterDisplay = () => {};
window.addEventListener("DOMContentLoaded", () => {
window.addEventListener("DOMContentLoaded", (event) => {
window.qBittorrent.LocalPreferences.upgrade();
let isSearchPanelLoaded = false;
let isLogPanelLoaded = false;
let isRssPanelLoaded = false;
@@ -497,7 +499,7 @@ window.addEventListener("DOMContentLoaded", () => {
if (!categoryList)
return;
[...categoryList.children].forEach((el) => { el.destroy(); });
[...categoryList.children].forEach((el) => { el.remove(); });
const categoryItemTemplate = document.getElementById("categoryFilterItem");
@@ -618,7 +620,7 @@ window.addEventListener("DOMContentLoaded", () => {
if (tagFilterList === null)
return;
[...tagFilterList.children].forEach((el) => { el.destroy(); });
[...tagFilterList.children].forEach((el) => { el.remove(); });
const tagItemTemplate = document.getElementById("tagFilterItem");
@@ -671,7 +673,7 @@ window.addEventListener("DOMContentLoaded", () => {
if (trackerFilterList === null)
return;
[...trackerFilterList.children].forEach((el) => { el.destroy(); });
[...trackerFilterList.children].forEach((el) => { el.remove(); });
const trackerItemTemplate = document.getElementById("trackerFilterItem");
@@ -989,9 +991,9 @@ window.addEventListener("DOMContentLoaded", () => {
lastExternalAddressLabel = "QBT_TR(External IPs: %1, %2)QBT_TR[CONTEXT=HttpServer]";
else if (hasIPv4Address || hasIPv6Address)
lastExternalAddressLabel = "QBT_TR(External IP: %1%2)QBT_TR[CONTEXT=HttpServer]";
// replace in reverse order ('%2' before '%1') in case address contains a % character.
// for example, see https://en.wikipedia.org/wiki/IPv6_address#Scoped_literal_IPv6_addresses_(with_zone_index)
externalIPsElement.textContent = lastExternalAddressLabel.replace("%2", lastExternalAddressV6).replace("%1", lastExternalAddressV4);
// https://en.wikipedia.org/wiki/IPv6_address#Scoped_literal_IPv6_addresses_(with_zone_index)
lastExternalAddressLabel = lastExternalAddressLabel.replace("%1", lastExternalAddressV4).replace("%2", lastExternalAddressV6);
externalIPsElement.textContent = lastExternalAddressLabel;
externalIPsElement.classList.remove("invisible");
externalIPsElement.previousElementSibling.classList.remove("invisible");
}

View File

@@ -478,7 +478,7 @@ window.qBittorrent.ContextMenu ??= (() => {
updateCategoriesSubMenu(categories) {
const contextCategoryList = $("contextCategoryList");
[...contextCategoryList.children].forEach((el) => { el.destroy(); });
[...contextCategoryList.children].forEach((el) => { el.remove(); });
const createMenuItem = (text, imgURL, clickFn) => {
const anchor = document.createElement("a");

View File

@@ -907,14 +907,14 @@ window.qBittorrent.DynamicTable ??= (() => {
this.selectedRows.erase(rowId);
this.rows.delete(rowId);
const tr = this.getTrByRowId(rowId);
tr?.destroy();
tr?.remove();
},
clear: function() {
this.deselectAll();
this.rows.clear();
for (const tr of this.getTrs())
tr.destroy();
tr.remove();
},
selectedRowsIds: function() {

View File

@@ -1,5 +1,6 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2025 Mike Tzou (Chocobo1)
* Copyright (C) 2019 Thomas Piccirello <thomas.piccirello@gmail.com>
*
* This program is free software; you can redistribute it and/or
@@ -32,7 +33,8 @@ window.qBittorrent ??= {};
window.qBittorrent.LocalPreferences ??= (() => {
const exports = () => {
return {
LocalPreferences: LocalPreferences
LocalPreferences: LocalPreferences,
upgrade: upgrade
};
};
@@ -53,6 +55,10 @@ window.qBittorrent.LocalPreferences ??= (() => {
}
}
size() {
return localStorage.length;
}
remove(key) {
try {
localStorage.removeItem(key);
@@ -63,6 +69,40 @@ window.qBittorrent.LocalPreferences ??= (() => {
}
};
const localPreferences = new LocalPreferences();
const upgrade = () => {
const MIGRATION_VERSION = 1;
const MIGRATION_VERSION_KEY = "MigrationVersion";
// clean start
if (localPreferences.size() === 0) {
localPreferences.set(MIGRATION_VERSION_KEY, MIGRATION_VERSION);
return;
}
// already in use
const version = Number(localPreferences.get(MIGRATION_VERSION_KEY)); // `0` on first initialization
if (version !== MIGRATION_VERSION) {
if (version < 1)
resetSideFilters();
localPreferences.set(MIGRATION_VERSION_KEY, MIGRATION_VERSION);
}
};
const resetSideFilters = () => {
// conditionally reset the filter to default to avoid none selected
const clear = (key) => {
const value = Number(localPreferences.get(key));
if ((value === 1) || (value === 2)) // affected values
localPreferences.remove(key);
};
clear("selected_category");
clear("selected_tag");
clear("selected_tracker");
};
return exports();
})();
Object.freeze(window.qBittorrent.LocalPreferences);

View File

@@ -0,0 +1,72 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2025 bolshoytoster <toasterbig@gmail.com>
* Copyright (C) 2025 Mike Tzou (Chocobo1)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*/
"use strict";
window.qBittorrent ??= {};
window.qBittorrent.MonkeyPatch ??= (() => {
const exports = () => {
return {
patch: patch
};
};
const patch = () => {
patchMootoolsDocumentId();
};
const patchMootoolsDocumentId = () => {
// Override MooTools' `document.id` (used for `$(id)`), which prevents it
// from allocating a `uniqueNumber` for elements that don't need it.
// MooTools and MochaUI use it internally.
if (document.id === undefined)
return;
document.id = (el) => {
if ((el === null) || (el === undefined))
return null;
switch (typeof el) {
case "object":
return el;
case "string":
return document.getElementById(el);
}
return null;
};
};
return exports();
})();
Object.freeze(window.qBittorrent.MonkeyPatch);
// execute now
window.qBittorrent.MonkeyPatch.patch();

View File

@@ -248,7 +248,7 @@ window.qBittorrent.Search ??= (() => {
if (state && state.running)
stopSearch(searchId);
tab.destroy();
tab.remove();
fetch("api/v2/search/delete", {
method: "POST",

View File

@@ -10,6 +10,7 @@
<script src="scripts/localpreferences.js?v=${CACHEID}"></script>
<script src="scripts/color-scheme.js?v=${CACHEID}"></script>
<script src="scripts/misc.js?locale=${LANG}&v=${CACHEID}"></script>
<script src="scripts/pathAutofill.js?v=${CACHEID}"></script>
<script>
"use strict";
@@ -62,6 +63,8 @@
window.parent.qBittorrent.Client.closeFrameWindow(window);
});
});
window.qBittorrent.pathAutofill.attachPathAutofill();
});
</script>
</head>
@@ -69,7 +72,7 @@
<body>
<div style="padding: 10px 10px 0px 10px;">
<label for="setLocation" style="font-weight: bold;">QBT_TR(Location:)QBT_TR[CONTEXT=TransferListWidget]</label>
<input type="text" id="setLocation" autocorrect="off" autocapitalize="none" style="width: 99%;">
<input type="text" id="setLocation" class="pathDirectory" autocorrect="off" autocapitalize="none" style="width: 99%;">
<div style="float: none; width: 99%;" id="error_div">&nbsp;</div>
<div style="text-align: center; padding-top: 10px;">
<input type="button" value="QBT_TR(Save)QBT_TR[CONTEXT=HttpServer]" id="setLocationButton">

View File

@@ -172,17 +172,17 @@
<div style="margin-left: 40px; margin-bottom: 5px;">
<input type="checkbox" id="setRatio" class="shareLimitInput" onclick="enableInputBoxes()">
<label id="ratioLabel" for="setRatio">QBT_TR(ratio)QBT_TR[CONTEXT=UpDownRatioDialog]</label>
<input type="number" id="ratio" value="0.00" step=".01" min="0" max="9999" class="shareLimitInput" aria-labelledby="ratioLabel">
<input type="number" id="ratio" value="0.00" step=".01" min="0" class="shareLimitInput" aria-labelledby="ratioLabel">
</div>
<div style="margin-left: 40px; margin-bottom: 5px;">
<input type="checkbox" id="setTotalMinutes" class="shareLimitInput" onclick="enableInputBoxes()">
<label id="totalMinutesLabel" for="setTotalMinutes">QBT_TR(total minutes)QBT_TR[CONTEXT=UpDownRatioDialog]</label>
<input type="number" id="totalMinutes" value="0" step="1" min="0" max="525600" class="shareLimitInput" aria-labelledby="totalMinutesLabel">
<input type="number" id="totalMinutes" value="0" step="1" min="0" class="shareLimitInput" aria-labelledby="totalMinutesLabel">
</div>
<div style="margin-left: 40px; margin-bottom: 5px;">
<input type="checkbox" id="setInactiveMinutes" class="shareLimitInput" onclick="enableInputBoxes()">
<label id="inactiveMinutesLabel" for="setInactiveMinutes">QBT_TR(inactive minutes)QBT_TR[CONTEXT=UpDownRatioDialog]</label>
<input type="number" id="inactiveMinutes" value="0" step="1" min="0" max="525600" class="shareLimitInput" aria-labelledby="inactiveMinutesLabel">
<input type="number" id="inactiveMinutes" value="0" step="1" min="0" class="shareLimitInput" aria-labelledby="inactiveMinutesLabel">
</div>
<div style="text-align: center; padding-top: 10px;">
<input type="button" value="QBT_TR(Save)QBT_TR[CONTEXT=HttpServer]" id="save">

View File

@@ -104,7 +104,7 @@
};
const deleteCookie = (element) => {
element.closest("tr").destroy();
element.closest("tr").remove();
};
const save = () => {

View File

@@ -2110,7 +2110,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
// Advanced Tab
const updateNetworkInterfaces = (default_iface, default_iface_name) => {
[...document.getElementById("networkInterface").children].forEach((el) => { el.destroy(); });
[...document.getElementById("networkInterface").children].forEach((el) => { el.remove(); });
fetch("api/v2/app/networkInterfaceList", {
method: "GET",
@@ -2139,7 +2139,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
};
const updateInterfaceAddresses = (iface, default_addr) => {
[...document.getElementById("optionalIPAddressToBind").children].forEach((el) => { el.destroy(); });
[...document.getElementById("optionalIPAddressToBind").children].forEach((el) => { el.remove(); });
const url = new URL("api/v2/app/networkInterfaceAddressList", window.location);
url.search = new URLSearchParams({
@@ -2876,22 +2876,22 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
}
// Share Ratio Limiting
let max_ratio = -1;
if ($("max_ratio_checkbox").checked) {
max_ratio = Number($("max_ratio_value").value);
if (isNaN(max_ratio) || (max_ratio < 0) || (max_ratio > 9998)) {
alert("QBT_TR(Share ratio limit must be between 0 and 9998.)QBT_TR[CONTEXT=HttpServer]");
let maxRatio = -1;
if (document.getElementById("maxRatioCheckbox").checked) {
maxRatio = Number(document.getElementById("maxRatioValue").value);
if (isNaN(maxRatio) || (maxRatio < 0)) {
alert("QBT_TR(Share ratio limit must not have a negative value.)QBT_TR[CONTEXT=HttpServer]");
return;
}
}
settings["max_ratio_enabled"] = $("max_ratio_checkbox").checked;
settings["max_ratio"] = max_ratio;
let max_seeding_time = -1;
if ($("max_seeding_time_checkbox").checked) {
max_seeding_time = Number($("max_seeding_time_value").value);
if (isNaN(max_seeding_time) || (max_seeding_time < 0) || (max_seeding_time > 525600)) {
alert("QBT_TR(Seeding time limit must be between 0 and 525600 minutes.)QBT_TR[CONTEXT=HttpServer]");
let maxSeedingTime = -1;
if (document.getElementById("maxSeedingTimeCheckbox").checked) {
maxSeedingTime = Number(document.getElementById("maxSeedingTimeValue").value);
if (Number.isNaN(maxSeedingTime) || (maxSeedingTime < 0)) {
alert("QBT_TR(Seeding time limit must not have a negative value.)QBT_TR[CONTEXT=HttpServer]");
return;
}
}
@@ -2899,11 +2899,11 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
settings["max_seeding_time"] = max_seeding_time;
settings["max_ratio_act"] = Number($("max_ratio_act").value);
let max_inactive_seeding_time = -1;
if ($("max_inactive_seeding_time_checkbox").checked) {
max_inactive_seeding_time = Number($("max_inactive_seeding_time_value").value);
if (isNaN(max_inactive_seeding_time) || (max_inactive_seeding_time < 0) || (max_inactive_seeding_time > 525600)) {
alert("QBT_TR(Seeding time limit must be between 0 and 525600 minutes.)QBT_TR[CONTEXT=HttpServer]");
let maxInactiveSeedingTime = -1;
if (document.getElementById("maxInactiveSeedingTimeCheckbox").checked) {
maxInactiveSeedingTime = Number(document.getElementById("maxInactiveSeedingTimeValue").value);
if (Number.isNaN(maxInactiveSeedingTime) || (maxInactiveSeedingTime < 0)) {
alert("QBT_TR(Seeding time limit must not have a negative value.)QBT_TR[CONTEXT=HttpServer]");
return;
}
}

View File

@@ -1,4 +1,4 @@
<div id="propGeneral" class="propertiesTabContent invisible unselectable">
<div id="propGeneral" class="propertiesTabContent invisible">
<div id="propProgressWrapper">
<span>QBT_TR(Progress:)QBT_TR[CONTEXT=PropertiesWidget]</span>
<span id="progress"></span>

View File

@@ -422,7 +422,7 @@
};
const clearDetails = () => {
[...document.getElementById("rssDetailsView").children].forEach((el) => { el.destroy(); });
[...document.getElementById("rssDetailsView").children].forEach((el) => { el.remove(); });
};
const showDetails = (feedUid, articleID) => {

View File

@@ -407,6 +407,7 @@
<file>private/scripts/localpreferences.js</file>
<file>private/scripts/misc.js</file>
<file>private/scripts/mocha-init.js</file>
<file>private/scripts/monkeypatch.js</file>
<file>private/scripts/pathAutofill.js</file>
<file>private/scripts/piecesbar.js</file>
<file>private/scripts/progressbar.js</file>