Skip to content

Commit

Permalink
Add I2P settings to WebUI
Browse files Browse the repository at this point in the history
PR #19700.
  • Loading branch information
thalieht authored Oct 13, 2023
1 parent 30189ae commit a388881
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/webui/api/appcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,16 @@ void AppController::preferencesAction()
data[u"max_uploads"_s] = session->maxUploads();
data[u"max_uploads_per_torrent"_s] = session->maxUploadsPerTorrent();

// I2P
data[u"i2p_enabled"_s] = session->isI2PEnabled();
data[u"i2p_address"_s] = session->I2PAddress();
data[u"i2p_port"_s] = session->I2PPort();
data[u"i2p_mixed_mode"_s] = session->I2PMixedMode();
data[u"i2p_inbound_quantity"_s] = session->I2PInboundQuantity();
data[u"i2p_outbound_quantity"_s] = session->I2POutboundQuantity();
data[u"i2p_inbound_length"_s] = session->I2PInboundLength();
data[u"i2p_outbound_length"_s] = session->I2POutboundLength();

// Proxy Server
const auto *proxyManager = Net::ProxyConfigurationManager::instance();
Net::ProxyConfiguration proxyConf = proxyManager->proxyConfiguration();
Expand Down Expand Up @@ -632,6 +642,24 @@ void AppController::setPreferencesAction()
if (hasKey(u"max_uploads_per_torrent"_s))
session->setMaxUploadsPerTorrent(it.value().toInt());

// I2P
if (hasKey(u"i2p_enabled"_s))
session->setI2PEnabled(it.value().toBool());
if (hasKey(u"i2p_address"_s))
session->setI2PAddress(it.value().toString());
if (hasKey(u"i2p_port"_s))
session->setI2PPort(it.value().toInt());
if (hasKey(u"i2p_mixed_mode"_s))
session->setI2PMixedMode(it.value().toBool());
if (hasKey(u"i2p_inbound_quantity"_s))
session->setI2PInboundQuantity(it.value().toInt());
if (hasKey(u"i2p_outbound_quantity"_s))
session->setI2POutboundQuantity(it.value().toInt());
if (hasKey(u"i2p_inbound_length"_s))
session->setI2PInboundLength(it.value().toInt());
if (hasKey(u"i2p_outbound_length"_s))
session->setI2POutboundLength(it.value().toInt());

// Proxy Server
auto *proxyManager = Net::ProxyConfigurationManager::instance();
Net::ProxyConfiguration proxyConf = proxyManager->proxyConfiguration();
Expand Down
2 changes: 1 addition & 1 deletion src/webui/webapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
#include "base/utils/version.h"
#include "api/isessionmanager.h"

inline const Utils::Version<3, 2> API_VERSION {2, 9, 5};
inline const Utils::Version<3, 2> API_VERSION {2, 9, 6};

class APIController;
class AuthController;
Expand Down
88 changes: 88 additions & 0 deletions src/webui/www/private/views/preferences.html
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,33 @@
</table>
</fieldset>

<fieldset class="settings">
<legend>
<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>
</legend>
<table>
<tr>
<td>
<label for="i2pAddress">QBT_TR(Host:)QBT_TR[CONTEXT=OptionsDialog]</label>
</td>
<td>
<input type="text" id="i2pAddress" />
</td>
<td>
<label for="i2pPort">QBT_TR(Port:)QBT_TR[CONTEXT=OptionsDialog]</label>
</td>
<td>
<input type="number" id="i2pPort" min="0" max="65535" onchange="qBittorrent.Preferences.numberInputLimiter(this);" style="width: 5em;" />
</td>
</tr>
</table>
<div class="formRow">
<input type="checkbox" id="i2pMixedMode" title="QBT_TR(If &quot;mixed mode&quot; is enabled, I2P torrents are allowed to also get peers from other sources than the tracker, and connect to regular IPs, not providing any anonymization. This may be useful if the user is not interested in the anonymization of I2P, but still wants to be able to connect to I2P peers.)QBT_TR[CONTEXT=OptionsDialog]" />
<label for="i2pMixedMode">QBT_TR(Mixed mode)QBT_TR[CONTEXT=OptionsDialog]</label>
</div>
</fieldset>

<fieldset class="settings">
<legend>QBT_TR(Proxy Server)QBT_TR[CONTEXT=OptionsDialog]</legend>
<table>
Expand Down Expand Up @@ -1436,6 +1463,38 @@
<input type="text" id="dhtBootstrapNodes" placeholder="QBT_TR(Resets to default if empty)QBT_TR[CONTEXT=OptionsDialog]" style="width: 15em;" />
</td>
</tr>
<tr>
<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>
</td>
<td>
<input id="i2pInboundQuantity" type="number" min="1" max="16" onchange="qBittorrent.Preferences.numberInputLimiter(this);" style="width: 15em;" />
</td>
</tr>
<tr>
<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>
</td>
<td>
<input id="i2pOutboundQuantity" type="number" min="1" max="16" onchange="qBittorrent.Preferences.numberInputLimiter(this);" style="width: 15em;" />
</td>
</tr>
<tr>
<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>
</td>
<td>
<input id="i2pInboundLength" type="number" min="0" max="7" onchange="qBittorrent.Preferences.numberInputLimiter(this);" style="width: 15em;" />
</td>
</tr>
<tr>
<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>
</td>
<td>
<input id="i2pOutboundLength" type="number" min="0" max="7" onchange="qBittorrent.Preferences.numberInputLimiter(this);" style="width: 15em;" />
</td>
</tr>
</table>
</fieldset>
</div>
Expand Down Expand Up @@ -1471,6 +1530,7 @@
updateMaxConnecPerTorrentEnabled: updateMaxConnecPerTorrentEnabled,
updateMaxUploadsEnabled: updateMaxUploadsEnabled,
updateMaxUploadsPerTorrentEnabled: updateMaxUploadsPerTorrentEnabled,
updateI2PSettingsEnabled: updateI2PSettingsEnabled,
updatePeerProxySettings: updatePeerProxySettings,
updatePeerProxyAuthSettings: updatePeerProxyAuthSettings,
updateFilterSettings: updateFilterSettings,
Expand Down Expand Up @@ -1660,6 +1720,13 @@
$('max_uploads_per_torrent_value').setProperty('disabled', !isMaxUploadsPerTorrentEnabled);
};

const updateI2PSettingsEnabled = function() {
const isI2PEnabled = $('i2pEnabledCheckbox').getProperty('checked');
$('i2pAddress').setProperty('disabled', !isI2PEnabled);
$('i2pPort').setProperty('disabled', !isI2PEnabled);
$('i2pMixedMode').setProperty('disabled', !isI2PEnabled);
};

const updatePeerProxySettings = function() {
const proxyType = $('peer_proxy_type_select').getProperty('value');
const isProxyDisabled = (proxyType === "None");
Expand Down Expand Up @@ -2039,6 +2106,13 @@
}
updateMaxUploadsPerTorrentEnabled();

// I2P
$('i2pEnabledCheckbox').setProperty('checked', pref.i2p_enabled);
$('i2pAddress').setProperty('value', pref.i2p_address);
$('i2pPort').setProperty('value', pref.i2p_port);
$('i2pMixedMode').setProperty('checked', pref.i2p_mixed_mode);
updateI2PSettingsEnabled();

// Proxy Server
$('peer_proxy_type_select').setProperty('value', pref.proxy_type);
$('peer_proxy_host_text').setProperty('value', pref.proxy_ip);
Expand Down Expand Up @@ -2259,6 +2333,10 @@
$('peerTurnoverInterval').setProperty('value', pref.peer_turnover_interval);
$('requestQueueSize').setProperty('value', pref.request_queue_size);
$('dhtBootstrapNodes').setProperty('value', pref.dht_bootstrap_nodes);
$('i2pInboundQuantity').setProperty('value', pref.i2p_inbound_quantity);
$('i2pOutboundQuantity').setProperty('value', pref.i2p_outbound_quantity);
$('i2pInboundLength').setProperty('value', pref.i2p_inbound_length);
$('i2pOutboundLength').setProperty('value', pref.i2p_outbound_length);
}
}
}).send();
Expand Down Expand Up @@ -2378,6 +2456,12 @@
}
settings.set('max_uploads_per_torrent', max_uploads_per_torrent);

// I2P
settings.set('i2p_enabled', $('i2pEnabledCheckbox').getProperty('checked'));
settings.set('i2p_address', $('i2pAddress').getProperty('value'));
settings.set('i2p_port', $('i2pPort').getProperty('value').toInt());
settings.set('i2p_mixed_mode', $('i2pMixedMode').getProperty('checked'));

// Proxy Server
settings.set('proxy_type', $('peer_proxy_type_select').getProperty('value'));
settings.set('proxy_ip', $('peer_proxy_host_text').getProperty('value'));
Expand Down Expand Up @@ -2693,6 +2777,10 @@
settings.set('peer_turnover_interval', $('peerTurnoverInterval').getProperty('value'));
settings.set('request_queue_size', $('requestQueueSize').getProperty('value'));
settings.set('dht_bootstrap_nodes', $('dhtBootstrapNodes').getProperty('value'));
settings.set('i2p_inbound_quantity', $('i2pInboundQuantity').getProperty('value'));
settings.set('i2p_outbound_quantity', $('i2pOutboundQuantity').getProperty('value'));
settings.set('i2p_inbound_length', $('i2pInboundLength').getProperty('value'));
settings.set('i2p_outbound_length', $('i2pOutboundLength').getProperty('value'));

// Send it to qBT
const json_str = JSON.encode(settings);
Expand Down

0 comments on commit a388881

Please sign in to comment.