Conditionally hide settings in Advanced Options

This commit is contained in:
Chocobo1 2024-02-04 13:32:33 +08:00
parent 5fe5c333b5
commit 9b64d50660
6 changed files with 129 additions and 64 deletions

View file

@ -78,6 +78,17 @@ void AppController::versionAction()
void AppController::buildInfoAction() void AppController::buildInfoAction()
{ {
const QString platformName =
#ifdef Q_OS_LINUX
u"linux"_s;
#elif defined(Q_OS_MACOS)
u"macos"_s;
#elif defined(Q_OS_WIN)
u"windows"_s;
#else
u"unknown"_s;
#endif
const QJsonObject versions = const QJsonObject versions =
{ {
{u"qt"_s, QStringLiteral(QT_VERSION_STR)}, {u"qt"_s, QStringLiteral(QT_VERSION_STR)},
@ -85,7 +96,8 @@ void AppController::buildInfoAction()
{u"boost"_s, Utils::Misc::boostVersionString()}, {u"boost"_s, Utils::Misc::boostVersionString()},
{u"openssl"_s, Utils::Misc::opensslVersionString()}, {u"openssl"_s, Utils::Misc::opensslVersionString()},
{u"zlib"_s, Utils::Misc::zlibVersionString()}, {u"zlib"_s, Utils::Misc::zlibVersionString()},
{u"bitness"_s, (QT_POINTER_SIZE * 8)} {u"bitness"_s, (QT_POINTER_SIZE * 8)},
{u"platform"_s, platformName}
}; };
setResult(versions); setResult(versions);
} }

View file

@ -53,7 +53,7 @@
#include "base/utils/version.h" #include "base/utils/version.h"
#include "api/isessionmanager.h" #include "api/isessionmanager.h"
inline const Utils::Version<3, 2> API_VERSION {2, 10, 2}; inline const Utils::Version<3, 2> API_VERSION {2, 10, 3};
class QTimer; class QTimer;

View file

@ -125,24 +125,8 @@ function getSyncMainDataInterval() {
return customSyncMainDataInterval ? customSyncMainDataInterval : serverSyncMainDataInterval; return customSyncMainDataInterval ? customSyncMainDataInterval : serverSyncMainDataInterval;
} }
const fetchQbtVersion = function() {
new Request({
url: 'api/v2/app/version',
method: 'get',
onSuccess: function(info) {
if (!info)
return;
sessionStorage.setItem('qbtVersion', info);
}
}).send();
};
fetchQbtVersion();
const qbtVersion = function() { const qbtVersion = function() {
const version = sessionStorage.getItem('qbtVersion'); return LocalPreferences.get('qbtVersion', '');
if (!version)
return '';
return version;
}; };
window.addEvent('load', function() { window.addEvent('load', function() {
@ -1474,6 +1458,38 @@ window.addEvent('load', function() {
}); });
}; };
registerDragAndDrop(); registerDragAndDrop();
// fetch qbt version and store it locally
new Request({
url: 'api/v2/app/version',
method: 'get',
noCache: true,
onSuccess: (info) => {
if (!info)
return;
LocalPreferences.set('qbtVersion', info);
}
}).send();
// fetch build info and store it locally
new Request.JSON({
url: 'api/v2/app/buildInfo',
method: 'get',
noCache: true,
onSuccess: (info) => {
if (!info)
return;
LocalPreferences.set('buildInfo.qtVersion', info.qt);
LocalPreferences.set('buildInfo.libtorrentVersion', info.libtorrent);
LocalPreferences.set('buildInfo.boostVersion', info.boost);
LocalPreferences.set('buildInfo.opensslVersion', info.openssl);
LocalPreferences.set('buildInfo.zlibVersion', info.zlib);
LocalPreferences.set('buildInfo.bitness', info.bitness);
LocalPreferences.set('buildInfo.platform', info.platform);
}
}).send();
}); });
function registerMagnetHandler() { function registerMagnetHandler() {

View file

@ -40,6 +40,7 @@ window.qBittorrent.Misc = (function() {
friendlyPercentage: friendlyPercentage, friendlyPercentage: friendlyPercentage,
friendlyFloat: friendlyFloat, friendlyFloat: friendlyFloat,
parseHtmlLinks: parseHtmlLinks, parseHtmlLinks: parseHtmlLinks,
parseVersion: parseVersion,
escapeHtml: escapeHtml, escapeHtml: escapeHtml,
naturalSortCollator: naturalSortCollator, naturalSortCollator: naturalSortCollator,
safeTrim: safeTrim, safeTrim: safeTrim,
@ -171,6 +172,29 @@ window.qBittorrent.Misc = (function() {
return text.replace(exp, "<a target='_blank' rel='noopener noreferrer' href='$1'>$1</a>"); return text.replace(exp, "<a target='_blank' rel='noopener noreferrer' href='$1'>$1</a>");
}; };
const parseVersion = function(versionString) {
const failure = {
valid: false
};
if (typeof versionString !== 'string')
return failure;
const tryToNumber = (str) => {
const num = Number(str);
return (isNaN(num) ? str : num);
};
const ver = versionString.split('.', 4).map(val => tryToNumber(val));
return {
valid: true,
major: ver[0],
minor: ver[1],
fix: ver[2],
patch: ver[3]
};
};
const escapeHtml = function(str) { const escapeHtml = function(str) {
const div = document.createElement('div'); const div = document.createElement('div');
div.appendChild(document.createTextNode(str)); div.appendChild(document.createTextNode(str));

View file

@ -843,25 +843,11 @@
<script> <script>
'use strict'; 'use strict';
(function() { $('qbittorrentVersion').innerText = `qBittorrent ${qbtVersion()} QBT_TR(Web UI)QBT_TR[CONTEXT=OptionsDialog]`;
$('qbittorrentVersion').innerText = ("qBittorrent " + qbtVersion() $('qtVersion').textContent = LocalPreferences.get('buildInfo.qtVersion');
+ " QBT_TR(Web UI)QBT_TR[CONTEXT=OptionsDialog]"); $('libtorrentVersion').textContent = LocalPreferences.get('buildInfo.libtorrentVersion');
$('boostVersion').textContent = LocalPreferences.get('buildInfo.boostVersion');
new Request.JSON({ $('opensslVersion').textContent = LocalPreferences.get('buildInfo.opensslVersion');
url: 'api/v2/app/buildInfo', $('zlibVersion').textContent = LocalPreferences.get('buildInfo.zlibVersion');
method: 'get', $('qbittorrentVersion').textContent += ` (${LocalPreferences.get('buildInfo.bitness')}-bit)`;
noCache: true,
onSuccess: function(info) {
if (!info)
return;
$('qtVersion').textContent = info.qt;
$('libtorrentVersion').textContent = info.libtorrent;
$('boostVersion').textContent = info.boost;
$('opensslVersion').textContent = info.openssl;
$('zlibVersion').textContent = info.zlib;
$('qbittorrentVersion').textContent += " (" + info.bitness + "-bit)";
}
}).send();
})();
</script> </script>

View file

@ -355,10 +355,10 @@
</table> </table>
</fieldset> </fieldset>
<fieldset class="settings"> <fieldset class="settings" id="fieldsetI2p">
<legend> <legend>
<input type="checkbox" id="i2pEnabledCheckbox" onclick="qBittorrent.Preferences.updateI2PSettingsEnabled();" /> <input type="checkbox" id="i2pEnabledCheckbox" onclick="qBittorrent.Preferences.updateI2PSettingsEnabled();" />
<label for="i2pEnabledCheckbox">QBT_TR(I2P (Experimental) (requires libtorrent &gt;= 2.0))QBT_TR[CONTEXT=OptionsDialog]</label> <label for="i2pEnabledCheckbox">QBT_TR(I2P (Experimental))QBT_TR[CONTEXT=OptionsDialog]</label>
</legend> </legend>
<table> <table>
<tr> <tr>
@ -993,9 +993,9 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
</select> </select>
</td> </td>
</tr> </tr>
<tr> <tr id="rowMemoryWorkingSetLimit">
<td> <td>
<label for="memoryWorkingSetLimit">QBT_TR(Physical memory (RAM) usage limit (applied if libtorrent &gt;= 2.0):)QBT_TR[CONTEXT=OptionsDialog]&nbsp;<a href="https://wikipedia.org/wiki/Working_set" target="_blank">(?)</a></label> <label for="memoryWorkingSetLimit">QBT_TR(Physical memory (RAM) usage limit:)QBT_TR[CONTEXT=OptionsDialog]&nbsp;<a href="https://wikipedia.org/wiki/Working_set" target="_blank">(?)</a></label>
</td> </td>
<td> <td>
<input type="text" id="memoryWorkingSetLimit" style="width: 15em;" title="QBT_TR(This option is less effective on Linux)QBT_TR[CONTEXT=OptionsDialog]">&nbsp;&nbsp;QBT_TR(MiB)QBT_TR[CONTEXT=OptionsDialog] <input type="text" id="memoryWorkingSetLimit" style="width: 15em;" title="QBT_TR(This option is less effective on Linux)QBT_TR[CONTEXT=OptionsDialog]">&nbsp;&nbsp;QBT_TR(MiB)QBT_TR[CONTEXT=OptionsDialog]
@ -1091,7 +1091,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
<input type="checkbox" id="embeddedTrackerPortForwarding" /> <input type="checkbox" id="embeddedTrackerPortForwarding" />
</td> </td>
</tr> </tr>
<tr> <tr id="rowMarkOfTheWeb">
<td> <td>
<label for="markOfTheWeb">QBT_TR(Enable Mark-of-the-Web (MOTW) for downloaded files (require macOS or Windows):)QBT_TR[CONTEXT=OptionsDialog]</label> <label for="markOfTheWeb">QBT_TR(Enable Mark-of-the-Web (MOTW) for downloaded files (require macOS or Windows):)QBT_TR[CONTEXT=OptionsDialog]</label>
</td> </td>
@ -1136,9 +1136,9 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
<input type="text" id="asyncIOThreads" style="width: 15em;" /> <input type="text" id="asyncIOThreads" style="width: 15em;" />
</td> </td>
</tr> </tr>
<tr> <tr id="rowHashingThreads">
<td> <td>
<label for="hashingThreads">QBT_TR(Hashing threads (requires libtorrent &gt;= 2.0):)QBT_TR[CONTEXT=OptionsDialog]&nbsp;<a href="https://www.libtorrent.org/reference-Settings.html#hashing_threads" target="_blank">(?)</a></label> <label for="hashingThreads">QBT_TR(Hashing threads:)QBT_TR[CONTEXT=OptionsDialog]&nbsp;<a href="https://www.libtorrent.org/reference-Settings.html#hashing_threads" target="_blank">(?)</a></label>
</td> </td>
<td> <td>
<input type="text" id="hashingThreads" style="width: 15em;" /> <input type="text" id="hashingThreads" style="width: 15em;" />
@ -1160,17 +1160,17 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
<input type="text" id="outstandMemoryWhenCheckingTorrents" style="width: 15em;" />&nbsp;&nbsp;QBT_TR(MiB)QBT_TR[CONTEXT=OptionsDialog] <input type="text" id="outstandMemoryWhenCheckingTorrents" style="width: 15em;" />&nbsp;&nbsp;QBT_TR(MiB)QBT_TR[CONTEXT=OptionsDialog]
</td> </td>
</tr> </tr>
<tr> <tr id="rowDiskCache">
<td> <td>
<label for="diskCache">QBT_TR(Disk cache (requires libtorrent &lt; 2.0):)QBT_TR[CONTEXT=OptionsDialog]&nbsp;<a href="https://www.libtorrent.org/reference-Settings.html#cache_size" target="_blank">(?)</a></label> <label for="diskCache">QBT_TR(Disk cache:)QBT_TR[CONTEXT=OptionsDialog]&nbsp;<a href="https://www.libtorrent.org/reference-Settings.html#cache_size" target="_blank">(?)</a></label>
</td> </td>
<td> <td>
<input type="text" id="diskCache" style="width: 15em;" />&nbsp;&nbsp;QBT_TR(MiB)QBT_TR[CONTEXT=OptionsDialog] <input type="text" id="diskCache" style="width: 15em;" />&nbsp;&nbsp;QBT_TR(MiB)QBT_TR[CONTEXT=OptionsDialog]
</td> </td>
</tr> </tr>
<tr> <tr id="rowDiskCacheExpiryInterval">
<td> <td>
<label for="diskCacheExpiryInterval">QBT_TR(Disk cache expiry interval (requires libtorrent &lt; 2.0):)QBT_TR[CONTEXT=OptionsDialog]&nbsp;<a href="https://www.libtorrent.org/reference-Settings.html#cache_expiry" target="_blank">(?)</a></label> <label for="diskCacheExpiryInterval">QBT_TR(Disk cache expiry interval:)QBT_TR[CONTEXT=OptionsDialog]&nbsp;<a href="https://www.libtorrent.org/reference-Settings.html#cache_expiry" target="_blank">(?)</a></label>
</td> </td>
<td> <td>
<input type="text" id="diskCacheExpiryInterval" style="width: 15em;">&nbsp;&nbsp;QBT_TR(s)QBT_TR[CONTEXT=OptionsDialog] <input type="text" id="diskCacheExpiryInterval" style="width: 15em;">&nbsp;&nbsp;QBT_TR(s)QBT_TR[CONTEXT=OptionsDialog]
@ -1184,9 +1184,9 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
<input type="text" id="diskQueueSize" style="width: 15em;">&nbsp;&nbsp;QBT_TR(KiB)QBT_TR[CONTEXT=OptionsDialog] <input type="text" id="diskQueueSize" style="width: 15em;">&nbsp;&nbsp;QBT_TR(KiB)QBT_TR[CONTEXT=OptionsDialog]
</td> </td>
</tr> </tr>
<tr> <tr id="rowDiskIOType">
<td> <td>
<label for="diskIOType">QBT_TR(Disk IO type (libtorrent &gt;= 2.0; requires restart):)QBT_TR[CONTEXT=OptionsDialog]&nbsp;<a href="https://www.libtorrent.org/single-page-ref.html#default-disk-io-constructor" target="_blank">(?)</a></label> <label for="diskIOType">QBT_TR(Disk IO type (requires restart):)QBT_TR[CONTEXT=OptionsDialog]&nbsp;<a href="https://www.libtorrent.org/single-page-ref.html#default-disk-io-constructor" target="_blank">(?)</a></label>
</td> </td>
<td> <td>
<select id="diskIOType" style="width: 15em;"> <select id="diskIOType" style="width: 15em;">
@ -1215,13 +1215,13 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
<select id="diskIOWriteMode" style="width: 15em;"> <select id="diskIOWriteMode" style="width: 15em;">
<option value="0">QBT_TR(Disable OS cache)QBT_TR[CONTEXT=OptionsDialog]</option> <option value="0">QBT_TR(Disable OS cache)QBT_TR[CONTEXT=OptionsDialog]</option>
<option value="1">QBT_TR(Enable OS cache)QBT_TR[CONTEXT=OptionsDialog]</option> <option value="1">QBT_TR(Enable OS cache)QBT_TR[CONTEXT=OptionsDialog]</option>
<option value="2">QBT_TR(Write-through (requires libtorrent &gt;= 2.0.6))QBT_TR[CONTEXT=OptionsDialog]</option> <option value="2" id="diskIOWriteModeWriteThrough">QBT_TR(Write-through)QBT_TR[CONTEXT=OptionsDialog]</option>
</select> </select>
</td> </td>
</tr> </tr>
<tr> <tr id="rowCoalesceReadsAndWrites">
<td> <td>
<label for="coalesceReadsAndWrites">QBT_TR(Coalesce reads &amp; writes (requires libtorrent &lt; 2.0):)QBT_TR[CONTEXT=OptionsDialog]&nbsp;<a href="https://www.libtorrent.org/reference-Settings.html#coalesce_reads" target="_blank">(?)</a></label> <label for="coalesceReadsAndWrites">QBT_TR(Coalesce reads &amp; writes:)QBT_TR[CONTEXT=OptionsDialog]&nbsp;<a href="https://www.libtorrent.org/reference-Settings.html#coalesce_reads" target="_blank">(?)</a></label>
</td> </td>
<td> <td>
<input type="checkbox" id="coalesceReadsAndWrites" /> <input type="checkbox" id="coalesceReadsAndWrites" />
@ -1485,33 +1485,33 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
<input type="text" id="dhtBootstrapNodes" placeholder="QBT_TR(Resets to default if empty)QBT_TR[CONTEXT=OptionsDialog]" style="width: 15em;" /> <input type="text" id="dhtBootstrapNodes" placeholder="QBT_TR(Resets to default if empty)QBT_TR[CONTEXT=OptionsDialog]" style="width: 15em;" />
</td> </td>
</tr> </tr>
<tr> <tr id="rowI2pInboundQuantity">
<td> <td>
<label for="i2pInboundQuantity">QBT_TR(I2P inbound quantity (requires libtorrent &gt;= 2.0):)QBT_TR[CONTEXT=OptionsDialog]&nbsp;<a href="https://www.libtorrent.org/reference-Settings.html#i2p_inbound_quantity" target="_blank">(?)</a></label> <label for="i2pInboundQuantity">QBT_TR(I2P inbound quantity:)QBT_TR[CONTEXT=OptionsDialog]&nbsp;<a href="https://www.libtorrent.org/reference-Settings.html#i2p_inbound_quantity" target="_blank">(?)</a></label>
</td> </td>
<td> <td>
<input id="i2pInboundQuantity" type="number" min="1" max="16" onchange="qBittorrent.Preferences.numberInputLimiter(this);" style="width: 15em;" /> <input id="i2pInboundQuantity" type="number" min="1" max="16" onchange="qBittorrent.Preferences.numberInputLimiter(this);" style="width: 15em;" />
</td> </td>
</tr> </tr>
<tr> <tr id="rowI2pOutboundQuantity">
<td> <td>
<label for="i2pOutboundQuantity">QBT_TR(I2P outbound quantity (requires libtorrent &gt;= 2.0):)QBT_TR[CONTEXT=OptionsDialog]&nbsp;<a href="https://www.libtorrent.org/reference-Settings.html#i2p_outbound_quantity" target="_blank">(?)</a></label> <label for="i2pOutboundQuantity">QBT_TR(I2P outbound quantity:)QBT_TR[CONTEXT=OptionsDialog]&nbsp;<a href="https://www.libtorrent.org/reference-Settings.html#i2p_outbound_quantity" target="_blank">(?)</a></label>
</td> </td>
<td> <td>
<input id="i2pOutboundQuantity" type="number" min="1" max="16" onchange="qBittorrent.Preferences.numberInputLimiter(this);" style="width: 15em;" /> <input id="i2pOutboundQuantity" type="number" min="1" max="16" onchange="qBittorrent.Preferences.numberInputLimiter(this);" style="width: 15em;" />
</td> </td>
</tr> </tr>
<tr> <tr id="rowI2pInboundLength">
<td> <td>
<label for="i2pInboundLength">QBT_TR(I2P inbound length (requires libtorrent &gt;= 2.0):)QBT_TR[CONTEXT=OptionsDialog]&nbsp;<a href="https://www.libtorrent.org/reference-Settings.html#i2p_inbound_length" target="_blank">(?)</a></label> <label for="i2pInboundLength">QBT_TR(I2P inbound length:)QBT_TR[CONTEXT=OptionsDialog]&nbsp;<a href="https://www.libtorrent.org/reference-Settings.html#i2p_inbound_length" target="_blank">(?)</a></label>
</td> </td>
<td> <td>
<input id="i2pInboundLength" type="number" min="0" max="7" onchange="qBittorrent.Preferences.numberInputLimiter(this);" style="width: 15em;" /> <input id="i2pInboundLength" type="number" min="0" max="7" onchange="qBittorrent.Preferences.numberInputLimiter(this);" style="width: 15em;" />
</td> </td>
</tr> </tr>
<tr> <tr id="rowI2pOutboundLength">
<td> <td>
<label for="i2pOutboundLength">QBT_TR(I2P outbound length (requires libtorrent &gt;= 2.0):)QBT_TR[CONTEXT=OptionsDialog]&nbsp;<a href="https://www.libtorrent.org/reference-Settings.html#i2p_outbound_length" target="_blank">(?)</a></label> <label for="i2pOutboundLength">QBT_TR(I2P outbound length:)QBT_TR[CONTEXT=OptionsDialog]&nbsp;<a href="https://www.libtorrent.org/reference-Settings.html#i2p_outbound_length" target="_blank">(?)</a></label>
</td> </td>
<td> <td>
<input id="i2pOutboundLength" type="number" min="0" max="7" onchange="qBittorrent.Preferences.numberInputLimiter(this);" style="width: 15em;" /> <input id="i2pOutboundLength" type="number" min="0" max="7" onchange="qBittorrent.Preferences.numberInputLimiter(this);" style="width: 15em;" />
@ -1574,6 +1574,33 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
}; };
}; };
// hide entries
const libtorrentVersion = window.qBittorrent.Misc.parseVersion(LocalPreferences.get('buildInfo.libtorrentVersion', ''));
if (libtorrentVersion.valid) {
if (libtorrentVersion.major >= 2) {
$('rowDiskCache').style.display = 'none';
$('rowDiskCacheExpiryInterval').style.display = 'none';
$('rowCoalesceReadsAndWrites').style.display = 'none';
}
else {
$('fieldsetI2p').style.display = 'none';
$('rowMemoryWorkingSetLimit').style.display = 'none';
$('rowHashingThreads').style.display = 'none';
$('rowDiskIOType').style.display = 'none';
$('rowI2pInboundQuantity').style.display = 'none';
$('rowI2pOutboundQuantity').style.display = 'none';
$('rowI2pInboundLength').style.display = 'none';
$('rowI2pOutboundLength').style.display = 'none';
}
if (!((libtorrentVersion.major >= 2) && (libtorrentVersion.minor >= 0) && (libtorrentVersion.fix >= 6)))
$('diskIOWriteModeWriteThrough').style.display = 'none';
}
const serverPlatform = LocalPreferences.get('buildInfo.platform', '');
if ((serverPlatform !== 'macos') && (serverPlatform !== 'windows'))
$('rowMarkOfTheWeb').style.display = 'none';
// Behavior tab // Behavior tab
const numberInputLimiter = (input) => { const numberInputLimiter = (input) => {
const min = input.getAttribute("min"); const min = input.getAttribute("min");