Drop WebUI default credentials
[qBittorrent.git] / src / gui / advancedsettings.cpp
blob187194d02b35c7292316fa4229c850226cc9ab44
1 /*
2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2016 qBittorrent project
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * In addition, as a special exception, the copyright holders give permission to
20 * link this program with the OpenSSL project's "OpenSSL" library (or with
21 * modified versions of it that use the same license as the "OpenSSL" library),
22 * and distribute the linked executables. You must obey the GNU General Public
23 * License in all respects for all of the code used other than "OpenSSL". If you
24 * modify file(s), you may extend this exception to your version of the file(s),
25 * but you are not obligated to do so. If you do not wish to do so, delete this
26 * exception statement from your version.
29 #include "advancedsettings.h"
31 #include <limits>
33 #include <QHeaderView>
34 #include <QHostAddress>
35 #include <QLabel>
36 #include <QNetworkInterface>
38 #include "base/bittorrent/session.h"
39 #include "base/global.h"
40 #include "base/preferences.h"
41 #include "base/unicodestrings.h"
42 #include "gui/addnewtorrentdialog.h"
43 #include "gui/desktopintegration.h"
44 #include "gui/mainwindow.h"
45 #include "interfaces/iguiapplication.h"
47 namespace
49 QString makeLink(const QStringView url, const QStringView linkLabel)
51 return u"<a href=\"%1\">%2</a>"_s.arg(url, linkLabel);
54 enum AdvSettingsCols
56 PROPERTY,
57 VALUE,
58 COL_COUNT
61 enum AdvSettingsRows
63 // qBittorrent section
64 QBITTORRENT_HEADER,
65 RESUME_DATA_STORAGE,
66 #if defined(QBT_USES_LIBTORRENT2) && !defined(Q_OS_MACOS)
67 MEMORY_WORKING_SET_LIMIT,
68 #endif
69 #if defined(Q_OS_WIN)
70 OS_MEMORY_PRIORITY,
71 #endif
72 // network interface
73 NETWORK_IFACE,
74 //Optional network address
75 NETWORK_IFACE_ADDRESS,
76 // behavior
77 SAVE_RESUME_DATA_INTERVAL,
78 TORRENT_FILE_SIZE_LIMIT,
79 CONFIRM_RECHECK_TORRENT,
80 RECHECK_COMPLETED,
81 // UI related
82 LIST_REFRESH,
83 RESOLVE_HOSTS,
84 RESOLVE_COUNTRIES,
85 PROGRAM_NOTIFICATIONS,
86 TORRENT_ADDED_NOTIFICATIONS,
87 #ifdef QBT_USES_DBUS
88 NOTIFICATION_TIMEOUT,
89 #endif
90 CONFIRM_REMOVE_ALL_TAGS,
91 CONFIRM_REMOVE_TRACKER_FROM_ALL_TORRENTS,
92 REANNOUNCE_WHEN_ADDRESS_CHANGED,
93 DOWNLOAD_TRACKER_FAVICON,
94 SAVE_PATH_HISTORY_LENGTH,
95 ENABLE_SPEED_WIDGET,
96 #ifndef Q_OS_MACOS
97 ENABLE_ICONS_IN_MENUS,
98 #endif
99 // embedded tracker
100 TRACKER_STATUS,
101 TRACKER_PORT,
102 TRACKER_PORT_FORWARDING,
103 #if defined(Q_OS_MACOS) || defined(Q_OS_WIN)
104 ENABLE_MARK_OF_THE_WEB,
105 #endif // Q_OS_MACOS || Q_OS_WIN
106 PYTHON_EXECUTABLE_PATH,
108 // libtorrent section
109 LIBTORRENT_HEADER,
110 BDECODE_DEPTH_LIMIT,
111 BDECODE_TOKEN_LIMIT,
112 ASYNC_IO_THREADS,
113 #ifdef QBT_USES_LIBTORRENT2
114 HASHING_THREADS,
115 #endif
116 FILE_POOL_SIZE,
117 CHECKING_MEM_USAGE,
118 #ifndef QBT_USES_LIBTORRENT2
119 // cache
120 DISK_CACHE,
121 DISK_CACHE_TTL,
122 #endif
123 DISK_QUEUE_SIZE,
124 #ifdef QBT_USES_LIBTORRENT2
125 DISK_IO_TYPE,
126 #endif
127 DISK_IO_READ_MODE,
128 DISK_IO_WRITE_MODE,
129 #ifndef QBT_USES_LIBTORRENT2
130 COALESCE_RW,
131 #endif
132 PIECE_EXTENT_AFFINITY,
133 SUGGEST_MODE,
134 SEND_BUF_WATERMARK,
135 SEND_BUF_LOW_WATERMARK,
136 SEND_BUF_WATERMARK_FACTOR,
137 // networking & ports
138 CONNECTION_SPEED,
139 SOCKET_SEND_BUFFER_SIZE,
140 SOCKET_RECEIVE_BUFFER_SIZE,
141 SOCKET_BACKLOG_SIZE,
142 OUTGOING_PORT_MIN,
143 OUTGOING_PORT_MAX,
144 UPNP_LEASE_DURATION,
145 PEER_TOS,
146 UTP_MIX_MODE,
147 IDN_SUPPORT,
148 MULTI_CONNECTIONS_PER_IP,
149 VALIDATE_HTTPS_TRACKER_CERTIFICATE,
150 SSRF_MITIGATION,
151 BLOCK_PEERS_ON_PRIVILEGED_PORTS,
152 // seeding
153 CHOKING_ALGORITHM,
154 SEED_CHOKING_ALGORITHM,
155 // tracker
156 ANNOUNCE_ALL_TRACKERS,
157 ANNOUNCE_ALL_TIERS,
158 ANNOUNCE_IP,
159 MAX_CONCURRENT_HTTP_ANNOUNCES,
160 STOP_TRACKER_TIMEOUT,
161 PEER_TURNOVER,
162 PEER_TURNOVER_CUTOFF,
163 PEER_TURNOVER_INTERVAL,
164 REQUEST_QUEUE_SIZE,
165 DHT_BOOTSTRAP_NODES,
166 #if defined(QBT_USES_LIBTORRENT2) && TORRENT_USE_I2P
167 I2P_INBOUND_QUANTITY,
168 I2P_OUTBOUND_QUANTITY,
169 I2P_INBOUND_LENGTH,
170 I2P_OUTBOUND_LENGTH,
171 #endif
173 ROW_COUNT
177 AdvancedSettings::AdvancedSettings(IGUIApplication *app, QWidget *parent)
178 : GUIApplicationComponent(app, parent)
180 // column
181 setColumnCount(COL_COUNT);
182 const QStringList header = {tr("Setting"), tr("Value", "Value set for this setting")};
183 setHorizontalHeaderLabels(header);
184 // row
185 setRowCount(ROW_COUNT);
186 verticalHeader()->setVisible(false);
187 // etc.
188 setAlternatingRowColors(true);
189 setSelectionMode(QAbstractItemView::NoSelection);
190 setEditTriggers(QAbstractItemView::NoEditTriggers);
191 // Load settings
192 loadAdvancedSettings();
193 resizeColumnToContents(0);
194 horizontalHeader()->setStretchLastSection(true);
197 void AdvancedSettings::saveAdvancedSettings() const
199 Preferences *const pref = Preferences::instance();
200 BitTorrent::Session *const session = BitTorrent::Session::instance();
202 session->setResumeDataStorageType(m_comboBoxResumeDataStorage.currentData().value<BitTorrent::ResumeDataStorageType>());
203 #if defined(QBT_USES_LIBTORRENT2) && !defined(Q_OS_MACOS)
204 // Physical memory (RAM) usage limit
205 app()->setMemoryWorkingSetLimit(m_spinBoxMemoryWorkingSetLimit.value());
206 #endif
207 #if defined(Q_OS_WIN)
208 app()->setProcessMemoryPriority(m_comboBoxOSMemoryPriority.currentData().value<MemoryPriority>());
209 #endif
210 // Bdecode depth limit
211 pref->setBdecodeDepthLimit(m_spinBoxBdecodeDepthLimit.value());
212 // Bdecode token limit
213 pref->setBdecodeTokenLimit(m_spinBoxBdecodeTokenLimit.value());
214 // Async IO threads
215 session->setAsyncIOThreads(m_spinBoxAsyncIOThreads.value());
216 #ifdef QBT_USES_LIBTORRENT2
217 // Hashing threads
218 session->setHashingThreads(m_spinBoxHashingThreads.value());
219 #endif
220 // File pool size
221 session->setFilePoolSize(m_spinBoxFilePoolSize.value());
222 // Checking Memory Usage
223 session->setCheckingMemUsage(m_spinBoxCheckingMemUsage.value());
224 #ifndef QBT_USES_LIBTORRENT2
225 // Disk write cache
226 session->setDiskCacheSize(m_spinBoxCache.value());
227 session->setDiskCacheTTL(m_spinBoxCacheTTL.value());
228 #endif
229 // Disk queue size
230 session->setDiskQueueSize(m_spinBoxDiskQueueSize.value() * 1024);
231 #ifdef QBT_USES_LIBTORRENT2
232 session->setDiskIOType(m_comboBoxDiskIOType.currentData().value<BitTorrent::DiskIOType>());
233 #endif
234 // Disk IO read mode
235 session->setDiskIOReadMode(m_comboBoxDiskIOReadMode.currentData().value<BitTorrent::DiskIOReadMode>());
236 // Disk IO write mode
237 session->setDiskIOWriteMode(m_comboBoxDiskIOWriteMode.currentData().value<BitTorrent::DiskIOWriteMode>());
238 #ifndef QBT_USES_LIBTORRENT2
239 // Coalesce reads & writes
240 session->setCoalesceReadWriteEnabled(m_checkBoxCoalesceRW.isChecked());
241 #endif
242 // Piece extent affinity
243 session->setPieceExtentAffinity(m_checkBoxPieceExtentAffinity.isChecked());
244 // Suggest mode
245 session->setSuggestMode(m_checkBoxSuggestMode.isChecked());
246 // Send buffer watermark
247 session->setSendBufferWatermark(m_spinBoxSendBufferWatermark.value());
248 session->setSendBufferLowWatermark(m_spinBoxSendBufferLowWatermark.value());
249 session->setSendBufferWatermarkFactor(m_spinBoxSendBufferWatermarkFactor.value());
250 // Outgoing connections per second
251 session->setConnectionSpeed(m_spinBoxConnectionSpeed.value());
252 // Socket send buffer size
253 session->setSocketSendBufferSize(m_spinBoxSocketSendBufferSize.value() * 1024);
254 // Socket receive buffer size
255 session->setSocketReceiveBufferSize(m_spinBoxSocketReceiveBufferSize.value() * 1024);
256 // Socket listen backlog size
257 session->setSocketBacklogSize(m_spinBoxSocketBacklogSize.value());
258 // Save resume data interval
259 session->setSaveResumeDataInterval(m_spinBoxSaveResumeDataInterval.value());
260 // .torrent file size limit
261 pref->setTorrentFileSizeLimit(m_spinBoxTorrentFileSizeLimit.value() * 1024 * 1024);
262 // Outgoing ports
263 session->setOutgoingPortsMin(m_spinBoxOutgoingPortsMin.value());
264 session->setOutgoingPortsMax(m_spinBoxOutgoingPortsMax.value());
265 // UPnP lease duration
266 session->setUPnPLeaseDuration(m_spinBoxUPnPLeaseDuration.value());
267 // Type of service
268 session->setPeerToS(m_spinBoxPeerToS.value());
269 // uTP-TCP mixed mode
270 session->setUtpMixedMode(m_comboBoxUtpMixedMode.currentData().value<BitTorrent::MixedModeAlgorithm>());
271 // Support internationalized domain name (IDN)
272 session->setIDNSupportEnabled(m_checkBoxIDNSupport.isChecked());
273 // multiple connections per IP
274 session->setMultiConnectionsPerIpEnabled(m_checkBoxMultiConnectionsPerIp.isChecked());
275 // Validate HTTPS tracker certificate
276 session->setValidateHTTPSTrackerCertificate(m_checkBoxValidateHTTPSTrackerCertificate.isChecked());
277 // SSRF mitigation
278 session->setSSRFMitigationEnabled(m_checkBoxSSRFMitigation.isChecked());
279 // Disallow connection to peers on privileged ports
280 session->setBlockPeersOnPrivilegedPorts(m_checkBoxBlockPeersOnPrivilegedPorts.isChecked());
281 // Recheck torrents on completion
282 pref->recheckTorrentsOnCompletion(m_checkBoxRecheckCompleted.isChecked());
283 // Transfer list refresh interval
284 session->setRefreshInterval(m_spinBoxListRefresh.value());
285 // Peer resolution
286 pref->resolvePeerCountries(m_checkBoxResolveCountries.isChecked());
287 pref->resolvePeerHostNames(m_checkBoxResolveHosts.isChecked());
288 // Network interface
289 session->setNetworkInterface(m_comboBoxInterface.currentData().toString());
290 session->setNetworkInterfaceName((m_comboBoxInterface.currentIndex() == 0)
291 ? QString()
292 : m_comboBoxInterface.currentText());
293 // Interface address
294 // Construct a QHostAddress to filter malformed strings
295 const QHostAddress ifaceAddr {m_comboBoxInterfaceAddress.currentData().toString()};
296 session->setNetworkInterfaceAddress(ifaceAddr.toString());
297 // Announce IP
298 // Construct a QHostAddress to filter malformed strings
299 const QHostAddress addr(m_lineEditAnnounceIP.text().trimmed());
300 session->setAnnounceIP(addr.toString());
301 // Max concurrent HTTP announces
302 session->setMaxConcurrentHTTPAnnounces(m_spinBoxMaxConcurrentHTTPAnnounces.value());
303 // Stop tracker timeout
304 session->setStopTrackerTimeout(m_spinBoxStopTrackerTimeout.value());
305 // Program notification
306 app()->desktopIntegration()->setNotificationsEnabled(m_checkBoxProgramNotifications.isChecked());
307 #ifdef QBT_USES_DBUS
308 app()->desktopIntegration()->setNotificationTimeout(m_spinBoxNotificationTimeout.value());
309 #endif
310 app()->setTorrentAddedNotificationsEnabled(m_checkBoxTorrentAddedNotifications.isChecked());
311 // Reannounce to all trackers when ip/port changed
312 session->setReannounceWhenAddressChangedEnabled(m_checkBoxReannounceWhenAddressChanged.isChecked());
313 // Misc GUI properties
314 app()->mainWindow()->setDownloadTrackerFavicon(m_checkBoxTrackerFavicon.isChecked());
315 pref->setAddNewTorrentDialogSavePathHistoryLength(m_spinBoxSavePathHistoryLength.value());
316 pref->setSpeedWidgetEnabled(m_checkBoxSpeedWidgetEnabled.isChecked());
317 #ifndef Q_OS_MACOS
318 pref->setIconsInMenusEnabled(m_checkBoxIconsInMenusEnabled.isChecked());
319 #endif
321 // Tracker
322 pref->setTrackerPort(m_spinBoxTrackerPort.value());
323 pref->setTrackerPortForwardingEnabled(m_checkBoxTrackerPortForwarding.isChecked());
324 session->setTrackerEnabled(m_checkBoxTrackerStatus.isChecked());
325 #if defined(Q_OS_MACOS) || defined(Q_OS_WIN)
326 // Mark-of-the-Web
327 pref->setMarkOfTheWebEnabled(m_checkBoxMarkOfTheWeb.isChecked());
328 #endif // Q_OS_MACOS || Q_OS_WIN
329 // Python executable path
330 pref->setPythonExecutablePath(Path(m_pythonExecutablePath.text().trimmed()));
331 // Choking algorithm
332 session->setChokingAlgorithm(m_comboBoxChokingAlgorithm.currentData().value<BitTorrent::ChokingAlgorithm>());
333 // Seed choking algorithm
334 session->setSeedChokingAlgorithm(m_comboBoxSeedChokingAlgorithm.currentData().value<BitTorrent::SeedChokingAlgorithm>());
336 pref->setConfirmTorrentRecheck(m_checkBoxConfirmTorrentRecheck.isChecked());
338 pref->setConfirmRemoveAllTags(m_checkBoxConfirmRemoveAllTags.isChecked());
339 pref->setConfirmRemoveTrackerFromAllTorrents(m_checkBoxConfirmRemoveTrackerFromAllTorrents.isChecked());
341 session->setAnnounceToAllTrackers(m_checkBoxAnnounceAllTrackers.isChecked());
342 session->setAnnounceToAllTiers(m_checkBoxAnnounceAllTiers.isChecked());
344 session->setPeerTurnover(m_spinBoxPeerTurnover.value());
345 session->setPeerTurnoverCutoff(m_spinBoxPeerTurnoverCutoff.value());
346 session->setPeerTurnoverInterval(m_spinBoxPeerTurnoverInterval.value());
347 // Maximum outstanding requests to a single peer
348 session->setRequestQueueSize(m_spinBoxRequestQueueSize.value());
349 // DHT bootstrap nodes
350 session->setDHTBootstrapNodes(m_lineEditDHTBootstrapNodes.text());
351 #if defined(QBT_USES_LIBTORRENT2) && TORRENT_USE_I2P
352 // I2P session options
353 session->setI2PInboundQuantity(m_spinBoxI2PInboundQuantity.value());
354 session->setI2POutboundQuantity(m_spinBoxI2POutboundQuantity.value());
355 session->setI2PInboundLength(m_spinBoxI2PInboundLength.value());
356 session->setI2POutboundLength(m_spinBoxI2POutboundLength.value());
357 #endif
360 #ifndef QBT_USES_LIBTORRENT2
361 void AdvancedSettings::updateCacheSpinSuffix(const int value)
363 if (value == 0)
364 m_spinBoxCache.setSuffix(tr(" (disabled)"));
365 else if (value < 0)
366 m_spinBoxCache.setSuffix(tr(" (auto)"));
367 else
368 m_spinBoxCache.setSuffix(tr(" MiB"));
370 #endif
372 #ifdef QBT_USES_DBUS
373 void AdvancedSettings::updateNotificationTimeoutSuffix(const int value)
375 if (value == 0)
376 m_spinBoxNotificationTimeout.setSuffix(tr(" (infinite)"));
377 else if (value < 0)
378 m_spinBoxNotificationTimeout.setSuffix(tr(" (system default)"));
379 else
380 m_spinBoxNotificationTimeout.setSuffix(tr(" ms", " milliseconds"));
382 #endif
384 void AdvancedSettings::updateInterfaceAddressCombo()
386 const auto toString = [](const QHostAddress &address) -> QString
388 switch (address.protocol()) {
389 case QAbstractSocket::IPv4Protocol:
390 return address.toString();
391 case QAbstractSocket::IPv6Protocol:
392 return Utils::Net::canonicalIPv6Addr(address).toString();
393 default:
394 Q_ASSERT(false);
395 break;
397 return {};
400 // Clear all items and reinsert them
401 m_comboBoxInterfaceAddress.clear();
402 m_comboBoxInterfaceAddress.addItem(tr("All addresses"), QString());
403 m_comboBoxInterfaceAddress.addItem(tr("All IPv4 addresses"), QHostAddress(QHostAddress::AnyIPv4).toString());
404 m_comboBoxInterfaceAddress.addItem(tr("All IPv6 addresses"), QHostAddress(QHostAddress::AnyIPv6).toString());
406 const QString currentIface = m_comboBoxInterface.currentData().toString();
407 if (currentIface.isEmpty()) // `any` interface
409 for (const QHostAddress &address : asConst(QNetworkInterface::allAddresses()))
411 const QString addressString = toString(address);
412 m_comboBoxInterfaceAddress.addItem(addressString, addressString);
415 else
417 const QList<QNetworkAddressEntry> addresses = QNetworkInterface::interfaceFromName(currentIface).addressEntries();
418 for (const QNetworkAddressEntry &entry : addresses)
420 const QString addressString = toString(entry.ip());
421 m_comboBoxInterfaceAddress.addItem(addressString, addressString);
425 const QString currentAddress = BitTorrent::Session::instance()->networkInterfaceAddress();
426 const int index = m_comboBoxInterfaceAddress.findData(currentAddress);
427 if (index > -1)
429 m_comboBoxInterfaceAddress.setCurrentIndex(index);
431 else
433 // not found, for the sake of UI consistency, add such entry
434 m_comboBoxInterfaceAddress.addItem(currentAddress, currentAddress);
435 m_comboBoxInterfaceAddress.setCurrentIndex(m_comboBoxInterfaceAddress.count() - 1);
439 void AdvancedSettings::loadAdvancedSettings()
441 const Preferences *const pref = Preferences::instance();
442 const BitTorrent::Session *const session = BitTorrent::Session::instance();
444 // add section headers
445 auto *labelQbtLink = new QLabel(
446 makeLink(u"https://github.com/qbittorrent/qBittorrent/wiki/Explanation-of-Options-in-qBittorrent#Advanced"
447 , tr("Open documentation"))
448 , this);
449 labelQbtLink->setOpenExternalLinks(true);
450 addRow(QBITTORRENT_HEADER, u"<b>%1</b>"_s.arg(tr("qBittorrent Section")), labelQbtLink);
451 static_cast<QLabel *>(cellWidget(QBITTORRENT_HEADER, PROPERTY))->setAlignment(Qt::AlignCenter | Qt::AlignVCenter);
453 auto *labelLibtorrentLink = new QLabel(
454 makeLink(u"https://www.libtorrent.org/reference-Settings.html"
455 , tr("Open documentation"))
456 , this);
457 labelLibtorrentLink->setOpenExternalLinks(true);
458 addRow(LIBTORRENT_HEADER, u"<b>%1</b>"_s.arg(tr("libtorrent Section")), labelLibtorrentLink);
459 static_cast<QLabel *>(cellWidget(LIBTORRENT_HEADER, PROPERTY))->setAlignment(Qt::AlignCenter | Qt::AlignVCenter);
461 m_comboBoxResumeDataStorage.addItem(tr("Fastresume files"), QVariant::fromValue(BitTorrent::ResumeDataStorageType::Legacy));
462 m_comboBoxResumeDataStorage.addItem(tr("SQLite database (experimental)"), QVariant::fromValue(BitTorrent::ResumeDataStorageType::SQLite));
463 m_comboBoxResumeDataStorage.setCurrentIndex(m_comboBoxResumeDataStorage.findData(QVariant::fromValue(session->resumeDataStorageType())));
464 addRow(RESUME_DATA_STORAGE, tr("Resume data storage type (requires restart)"), &m_comboBoxResumeDataStorage);
466 #if defined(QBT_USES_LIBTORRENT2) && !defined(Q_OS_MACOS)
467 // Physical memory (RAM) usage limit
468 m_spinBoxMemoryWorkingSetLimit.setMinimum(1);
469 m_spinBoxMemoryWorkingSetLimit.setMaximum(std::numeric_limits<int>::max());
470 m_spinBoxMemoryWorkingSetLimit.setSuffix(tr(" MiB"));
471 m_spinBoxMemoryWorkingSetLimit.setToolTip(tr("This option is less effective on Linux"));
472 m_spinBoxMemoryWorkingSetLimit.setValue(app()->memoryWorkingSetLimit());
473 addRow(MEMORY_WORKING_SET_LIMIT, (tr("Physical memory (RAM) usage limit") + u' ' + makeLink(u"https://wikipedia.org/wiki/Working_set", u"(?)"))
474 , &m_spinBoxMemoryWorkingSetLimit);
475 #endif
476 #if defined(Q_OS_WIN)
477 m_comboBoxOSMemoryPriority.addItem(tr("Normal"), QVariant::fromValue(MemoryPriority::Normal));
478 m_comboBoxOSMemoryPriority.addItem(tr("Below normal"), QVariant::fromValue(MemoryPriority::BelowNormal));
479 m_comboBoxOSMemoryPriority.addItem(tr("Medium"), QVariant::fromValue(MemoryPriority::Medium));
480 m_comboBoxOSMemoryPriority.addItem(tr("Low"), QVariant::fromValue(MemoryPriority::Low));
481 m_comboBoxOSMemoryPriority.addItem(tr("Very low"), QVariant::fromValue(MemoryPriority::VeryLow));
482 m_comboBoxOSMemoryPriority.setCurrentIndex(m_comboBoxOSMemoryPriority.findData(QVariant::fromValue(app()->processMemoryPriority())));
483 addRow(OS_MEMORY_PRIORITY, (tr("Process memory priority")
484 + u' ' + makeLink(u"https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/ns-processthreadsapi-memory_priority_information", u"(?)"))
485 , &m_comboBoxOSMemoryPriority);
486 #endif
487 // Bdecode depth limit
488 m_spinBoxBdecodeDepthLimit.setMinimum(0);
489 m_spinBoxBdecodeDepthLimit.setMaximum(std::numeric_limits<int>::max());
490 m_spinBoxBdecodeDepthLimit.setValue(pref->getBdecodeDepthLimit());
491 addRow(BDECODE_DEPTH_LIMIT, (tr("Bdecode depth limit") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Bdecoding.html#bdecode()", u"(?)"))
492 , &m_spinBoxBdecodeDepthLimit);
493 // Bdecode token limit
494 m_spinBoxBdecodeTokenLimit.setMinimum(0);
495 m_spinBoxBdecodeTokenLimit.setMaximum(std::numeric_limits<int>::max());
496 m_spinBoxBdecodeTokenLimit.setValue(pref->getBdecodeTokenLimit());
497 addRow(BDECODE_TOKEN_LIMIT, (tr("Bdecode token limit") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Bdecoding.html#bdecode()", u"(?)"))
498 , &m_spinBoxBdecodeTokenLimit);
499 // Async IO threads
500 m_spinBoxAsyncIOThreads.setMinimum(1);
501 m_spinBoxAsyncIOThreads.setMaximum(1024);
502 m_spinBoxAsyncIOThreads.setValue(session->asyncIOThreads());
503 addRow(ASYNC_IO_THREADS, (tr("Asynchronous I/O threads") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#aio_threads", u"(?)"))
504 , &m_spinBoxAsyncIOThreads);
506 #ifdef QBT_USES_LIBTORRENT2
507 // Hashing threads
508 m_spinBoxHashingThreads.setMinimum(1);
509 m_spinBoxHashingThreads.setMaximum(1024);
510 m_spinBoxHashingThreads.setValue(session->hashingThreads());
511 addRow(HASHING_THREADS, (tr("Hashing threads") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#hashing_threads", u"(?)"))
512 , &m_spinBoxHashingThreads);
513 #endif
515 // File pool size
516 m_spinBoxFilePoolSize.setMinimum(1);
517 m_spinBoxFilePoolSize.setMaximum(std::numeric_limits<int>::max());
518 m_spinBoxFilePoolSize.setValue(session->filePoolSize());
519 addRow(FILE_POOL_SIZE, (tr("File pool size") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#file_pool_size", u"(?)"))
520 , &m_spinBoxFilePoolSize);
522 // Checking Memory Usage
523 m_spinBoxCheckingMemUsage.setMinimum(1);
524 // When build as 32bit binary, set the maximum value lower to prevent crashes.
525 #ifdef QBT_APP_64BIT
526 m_spinBoxCheckingMemUsage.setMaximum(1024);
527 #else
528 // Allocate at most 128MiB out of the remaining 512MiB (see the cache part below)
529 m_spinBoxCheckingMemUsage.setMaximum(128);
530 #endif
531 m_spinBoxCheckingMemUsage.setValue(session->checkingMemUsage());
532 m_spinBoxCheckingMemUsage.setSuffix(tr(" MiB"));
533 addRow(CHECKING_MEM_USAGE, (tr("Outstanding memory when checking torrents") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#checking_mem_usage", u"(?)"))
534 , &m_spinBoxCheckingMemUsage);
535 #ifndef QBT_USES_LIBTORRENT2
536 // Disk write cache
537 m_spinBoxCache.setMinimum(-1);
538 // When build as 32bit binary, set the maximum at less than 2GB to prevent crashes.
539 #ifdef QBT_APP_64BIT
540 m_spinBoxCache.setMaximum(33554431); // 32768GiB
541 #else
542 // allocate 1536MiB and leave 512MiB to the rest of program data in RAM
543 m_spinBoxCache.setMaximum(1536);
544 #endif
545 m_spinBoxCache.setValue(session->diskCacheSize());
546 updateCacheSpinSuffix(m_spinBoxCache.value());
547 connect(&m_spinBoxCache, qOverload<int>(&QSpinBox::valueChanged)
548 , this, &AdvancedSettings::updateCacheSpinSuffix);
549 addRow(DISK_CACHE, (tr("Disk cache") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#cache_size", u"(?)"))
550 , &m_spinBoxCache);
551 // Disk cache expiry
552 m_spinBoxCacheTTL.setMinimum(1);
553 m_spinBoxCacheTTL.setMaximum(std::numeric_limits<int>::max());
554 m_spinBoxCacheTTL.setValue(session->diskCacheTTL());
555 m_spinBoxCacheTTL.setSuffix(tr(" s", " seconds"));
556 addRow(DISK_CACHE_TTL, (tr("Disk cache expiry interval") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#cache_expiry", u"(?)"))
557 , &m_spinBoxCacheTTL);
558 #endif
559 // Disk queue size
560 m_spinBoxDiskQueueSize.setMinimum(1);
561 m_spinBoxDiskQueueSize.setMaximum(std::numeric_limits<int>::max() / 1024);
562 m_spinBoxDiskQueueSize.setValue(session->diskQueueSize() / 1024);
563 m_spinBoxDiskQueueSize.setSuffix(tr(" KiB"));
564 addRow(DISK_QUEUE_SIZE, (tr("Disk queue size") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#max_queued_disk_bytes", u"(?)"))
565 , &m_spinBoxDiskQueueSize);
566 #ifdef QBT_USES_LIBTORRENT2
567 // Disk IO type
568 m_comboBoxDiskIOType.addItem(tr("Default"), QVariant::fromValue(BitTorrent::DiskIOType::Default));
569 m_comboBoxDiskIOType.addItem(tr("Memory mapped files"), QVariant::fromValue(BitTorrent::DiskIOType::MMap));
570 m_comboBoxDiskIOType.addItem(tr("POSIX-compliant"), QVariant::fromValue(BitTorrent::DiskIOType::Posix));
571 m_comboBoxDiskIOType.setCurrentIndex(m_comboBoxDiskIOType.findData(QVariant::fromValue(session->diskIOType())));
572 addRow(DISK_IO_TYPE, tr("Disk IO type (requires restart)") + u' ' + makeLink(u"https://www.libtorrent.org/single-page-ref.html#default-disk-io-constructor", u"(?)")
573 , &m_comboBoxDiskIOType);
574 #endif
575 // Disk IO read mode
576 m_comboBoxDiskIOReadMode.addItem(tr("Disable OS cache"), QVariant::fromValue(BitTorrent::DiskIOReadMode::DisableOSCache));
577 m_comboBoxDiskIOReadMode.addItem(tr("Enable OS cache"), QVariant::fromValue(BitTorrent::DiskIOReadMode::EnableOSCache));
578 m_comboBoxDiskIOReadMode.setCurrentIndex(m_comboBoxDiskIOReadMode.findData(QVariant::fromValue(session->diskIOReadMode())));
579 addRow(DISK_IO_READ_MODE, (tr("Disk IO read mode") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#disk_io_read_mode", u"(?)"))
580 , &m_comboBoxDiskIOReadMode);
581 // Disk IO write mode
582 m_comboBoxDiskIOWriteMode.addItem(tr("Disable OS cache"), QVariant::fromValue(BitTorrent::DiskIOWriteMode::DisableOSCache));
583 m_comboBoxDiskIOWriteMode.addItem(tr("Enable OS cache"), QVariant::fromValue(BitTorrent::DiskIOWriteMode::EnableOSCache));
584 #ifdef QBT_USES_LIBTORRENT2
585 m_comboBoxDiskIOWriteMode.addItem(tr("Write-through"), QVariant::fromValue(BitTorrent::DiskIOWriteMode::WriteThrough));
586 #endif
587 m_comboBoxDiskIOWriteMode.setCurrentIndex(m_comboBoxDiskIOWriteMode.findData(QVariant::fromValue(session->diskIOWriteMode())));
588 addRow(DISK_IO_WRITE_MODE, (tr("Disk IO write mode") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#disk_io_write_mode", u"(?)"))
589 , &m_comboBoxDiskIOWriteMode);
590 #ifndef QBT_USES_LIBTORRENT2
591 // Coalesce reads & writes
592 m_checkBoxCoalesceRW.setChecked(session->isCoalesceReadWriteEnabled());
593 addRow(COALESCE_RW, (tr("Coalesce reads & writes") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#coalesce_reads", u"(?)"))
594 , &m_checkBoxCoalesceRW);
595 #endif
596 // Piece extent affinity
597 m_checkBoxPieceExtentAffinity.setChecked(session->usePieceExtentAffinity());
598 addRow(PIECE_EXTENT_AFFINITY, (tr("Use piece extent affinity") + u' ' + makeLink(u"https://libtorrent.org/single-page-ref.html#piece_extent_affinity", u"(?)")), &m_checkBoxPieceExtentAffinity);
599 // Suggest mode
600 m_checkBoxSuggestMode.setChecked(session->isSuggestModeEnabled());
601 addRow(SUGGEST_MODE, (tr("Send upload piece suggestions") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#suggest_mode", u"(?)"))
602 , &m_checkBoxSuggestMode);
603 // Send buffer watermark
604 m_spinBoxSendBufferWatermark.setMinimum(1);
605 m_spinBoxSendBufferWatermark.setMaximum(std::numeric_limits<int>::max());
606 m_spinBoxSendBufferWatermark.setSuffix(tr(" KiB"));
607 m_spinBoxSendBufferWatermark.setValue(session->sendBufferWatermark());
608 addRow(SEND_BUF_WATERMARK, (tr("Send buffer watermark") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#send_buffer_watermark", u"(?)"))
609 , &m_spinBoxSendBufferWatermark);
610 m_spinBoxSendBufferLowWatermark.setMinimum(1);
611 m_spinBoxSendBufferLowWatermark.setMaximum(std::numeric_limits<int>::max());
612 m_spinBoxSendBufferLowWatermark.setSuffix(tr(" KiB"));
613 m_spinBoxSendBufferLowWatermark.setValue(session->sendBufferLowWatermark());
614 addRow(SEND_BUF_LOW_WATERMARK, (tr("Send buffer low watermark") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#send_buffer_low_watermark", u"(?)"))
615 , &m_spinBoxSendBufferLowWatermark);
616 m_spinBoxSendBufferWatermarkFactor.setMinimum(1);
617 m_spinBoxSendBufferWatermarkFactor.setMaximum(std::numeric_limits<int>::max());
618 m_spinBoxSendBufferWatermarkFactor.setSuffix(u" %"_s);
619 m_spinBoxSendBufferWatermarkFactor.setValue(session->sendBufferWatermarkFactor());
620 addRow(SEND_BUF_WATERMARK_FACTOR, (tr("Send buffer watermark factor") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#send_buffer_watermark_factor", u"(?)"))
621 , &m_spinBoxSendBufferWatermarkFactor);
622 // Outgoing connections per second
623 m_spinBoxConnectionSpeed.setMinimum(0);
624 m_spinBoxConnectionSpeed.setMaximum(std::numeric_limits<int>::max());
625 m_spinBoxConnectionSpeed.setValue(session->connectionSpeed());
626 addRow(CONNECTION_SPEED, (tr("Outgoing connections per second") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#connection_speed", u"(?)"))
627 , &m_spinBoxConnectionSpeed);
628 // Socket send buffer size
629 m_spinBoxSocketSendBufferSize.setMinimum(0);
630 m_spinBoxSocketSendBufferSize.setMaximum(std::numeric_limits<int>::max() / 1024);
631 m_spinBoxSocketSendBufferSize.setValue(session->socketSendBufferSize() / 1024);
632 m_spinBoxSocketSendBufferSize.setSuffix(tr(" KiB"));
633 m_spinBoxSocketSendBufferSize.setSpecialValueText(tr("0 (system default)"));
634 addRow(SOCKET_SEND_BUFFER_SIZE, (tr("Socket send buffer size [0: system default]") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#send_socket_buffer_size", u"(?)"))
635 , &m_spinBoxSocketSendBufferSize);
636 // Socket receive buffer size
637 m_spinBoxSocketReceiveBufferSize.setMinimum(0);
638 m_spinBoxSocketReceiveBufferSize.setMaximum(std::numeric_limits<int>::max() / 1024);
639 m_spinBoxSocketReceiveBufferSize.setValue(session->socketReceiveBufferSize() / 1024);
640 m_spinBoxSocketReceiveBufferSize.setSuffix(tr(" KiB"));
641 m_spinBoxSocketReceiveBufferSize.setSpecialValueText(tr("0 (system default)"));
642 addRow(SOCKET_RECEIVE_BUFFER_SIZE, (tr("Socket receive buffer size [0: system default]") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#recv_socket_buffer_size", u"(?)"))
643 , &m_spinBoxSocketReceiveBufferSize);
644 // Socket listen backlog size
645 m_spinBoxSocketBacklogSize.setMinimum(1);
646 m_spinBoxSocketBacklogSize.setMaximum(std::numeric_limits<int>::max());
647 m_spinBoxSocketBacklogSize.setValue(session->socketBacklogSize());
648 addRow(SOCKET_BACKLOG_SIZE, (tr("Socket backlog size") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#listen_queue_size", u"(?)"))
649 , &m_spinBoxSocketBacklogSize);
650 // Save resume data interval
651 m_spinBoxSaveResumeDataInterval.setMinimum(0);
652 m_spinBoxSaveResumeDataInterval.setMaximum(std::numeric_limits<int>::max());
653 m_spinBoxSaveResumeDataInterval.setValue(session->saveResumeDataInterval());
654 m_spinBoxSaveResumeDataInterval.setSuffix(tr(" min", " minutes"));
655 m_spinBoxSaveResumeDataInterval.setSpecialValueText(tr("0 (disabled)"));
656 addRow(SAVE_RESUME_DATA_INTERVAL, tr("Save resume data interval [0: disabled]", "How often the fastresume file is saved."), &m_spinBoxSaveResumeDataInterval);
657 // .torrent file size limit
658 m_spinBoxTorrentFileSizeLimit.setMinimum(1);
659 m_spinBoxTorrentFileSizeLimit.setMaximum(std::numeric_limits<int>::max() / 1024 / 1024);
660 m_spinBoxTorrentFileSizeLimit.setValue(pref->getTorrentFileSizeLimit() / 1024 / 1024);
661 m_spinBoxTorrentFileSizeLimit.setSuffix(tr(" MiB"));
662 addRow(TORRENT_FILE_SIZE_LIMIT, tr(".torrent file size limit"), &m_spinBoxTorrentFileSizeLimit);
663 // Outgoing port Min
664 m_spinBoxOutgoingPortsMin.setMinimum(0);
665 m_spinBoxOutgoingPortsMin.setMaximum(65535);
666 m_spinBoxOutgoingPortsMin.setValue(session->outgoingPortsMin());
667 m_spinBoxOutgoingPortsMin.setSpecialValueText(tr("0 (disabled)"));
668 addRow(OUTGOING_PORT_MIN, (tr("Outgoing ports (Min) [0: disabled]")
669 + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#outgoing_port", u"(?)"))
670 , &m_spinBoxOutgoingPortsMin);
671 // Outgoing port Max
672 m_spinBoxOutgoingPortsMax.setMinimum(0);
673 m_spinBoxOutgoingPortsMax.setMaximum(65535);
674 m_spinBoxOutgoingPortsMax.setValue(session->outgoingPortsMax());
675 m_spinBoxOutgoingPortsMax.setSpecialValueText(tr("0 (disabled)"));
676 addRow(OUTGOING_PORT_MAX, (tr("Outgoing ports (Max) [0: disabled]")
677 + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#outgoing_port", u"(?)"))
678 , &m_spinBoxOutgoingPortsMax);
679 // UPnP lease duration
680 m_spinBoxUPnPLeaseDuration.setMinimum(0);
681 m_spinBoxUPnPLeaseDuration.setMaximum(std::numeric_limits<int>::max());
682 m_spinBoxUPnPLeaseDuration.setValue(session->UPnPLeaseDuration());
683 m_spinBoxUPnPLeaseDuration.setSuffix(tr(" s", " seconds"));
684 m_spinBoxUPnPLeaseDuration.setSpecialValueText(tr("0 (permanent lease)"));
685 addRow(UPNP_LEASE_DURATION, (tr("UPnP lease duration [0: permanent lease]") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#upnp_lease_duration", u"(?)"))
686 , &m_spinBoxUPnPLeaseDuration);
687 // Type of service
688 m_spinBoxPeerToS.setMinimum(0);
689 m_spinBoxPeerToS.setMaximum(255);
690 m_spinBoxPeerToS.setValue(session->peerToS());
691 addRow(PEER_TOS, (tr("Type of service (ToS) for connections to peers") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#peer_tos", u"(?)"))
692 , &m_spinBoxPeerToS);
693 // uTP-TCP mixed mode
694 m_comboBoxUtpMixedMode.addItem(tr("Prefer TCP"), QVariant::fromValue(BitTorrent::MixedModeAlgorithm::TCP));
695 m_comboBoxUtpMixedMode.addItem(tr("Peer proportional (throttles TCP)"), QVariant::fromValue(BitTorrent::MixedModeAlgorithm::Proportional));
696 m_comboBoxUtpMixedMode.setCurrentIndex(m_comboBoxUtpMixedMode.findData(QVariant::fromValue(session->utpMixedMode())));
697 addRow(UTP_MIX_MODE, (tr("%1-TCP mixed mode algorithm", "uTP-TCP mixed mode algorithm").arg(C_UTP)
698 + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#mixed_mode_algorithm", u"(?)"))
699 , &m_comboBoxUtpMixedMode);
700 // Support internationalized domain name (IDN)
701 m_checkBoxIDNSupport.setChecked(session->isIDNSupportEnabled());
702 addRow(IDN_SUPPORT, (tr("Support internationalized domain name (IDN)")
703 + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#allow_idna", u"(?)"))
704 , &m_checkBoxIDNSupport);
705 // multiple connections per IP
706 m_checkBoxMultiConnectionsPerIp.setChecked(session->multiConnectionsPerIpEnabled());
707 addRow(MULTI_CONNECTIONS_PER_IP, (tr("Allow multiple connections from the same IP address")
708 + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#allow_multiple_connections_per_ip", u"(?)"))
709 , &m_checkBoxMultiConnectionsPerIp);
710 // Validate HTTPS tracker certificate
711 m_checkBoxValidateHTTPSTrackerCertificate.setChecked(session->validateHTTPSTrackerCertificate());
712 addRow(VALIDATE_HTTPS_TRACKER_CERTIFICATE, (tr("Validate HTTPS tracker certificates")
713 + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#validate_https_trackers", u"(?)"))
714 , &m_checkBoxValidateHTTPSTrackerCertificate);
715 // SSRF mitigation
716 m_checkBoxSSRFMitigation.setChecked(session->isSSRFMitigationEnabled());
717 addRow(SSRF_MITIGATION, (tr("Server-side request forgery (SSRF) mitigation")
718 + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#ssrf_mitigation", u"(?)"))
719 , &m_checkBoxSSRFMitigation);
720 // Disallow connection to peers on privileged ports
721 m_checkBoxBlockPeersOnPrivilegedPorts.setChecked(session->blockPeersOnPrivilegedPorts());
722 addRow(BLOCK_PEERS_ON_PRIVILEGED_PORTS, (tr("Disallow connection to peers on privileged ports") + u' ' + makeLink(u"https://libtorrent.org/single-page-ref.html#no_connect_privileged_ports", u"(?)")), &m_checkBoxBlockPeersOnPrivilegedPorts);
723 // Recheck completed torrents
724 m_checkBoxRecheckCompleted.setChecked(pref->recheckTorrentsOnCompletion());
725 addRow(RECHECK_COMPLETED, tr("Recheck torrents on completion"), &m_checkBoxRecheckCompleted);
726 // Refresh interval
727 m_spinBoxListRefresh.setMinimum(30);
728 m_spinBoxListRefresh.setMaximum(99999);
729 m_spinBoxListRefresh.setValue(session->refreshInterval());
730 m_spinBoxListRefresh.setSuffix(tr(" ms", " milliseconds"));
731 m_spinBoxListRefresh.setToolTip(tr("It controls the internal state update interval which in turn will affect UI updates"));
732 addRow(LIST_REFRESH, tr("Refresh interval"), &m_spinBoxListRefresh);
733 // Resolve Peer countries
734 m_checkBoxResolveCountries.setChecked(pref->resolvePeerCountries());
735 addRow(RESOLVE_COUNTRIES, tr("Resolve peer countries"), &m_checkBoxResolveCountries);
736 // Resolve peer hosts
737 m_checkBoxResolveHosts.setChecked(pref->resolvePeerHostNames());
738 addRow(RESOLVE_HOSTS, tr("Resolve peer host names"), &m_checkBoxResolveHosts);
739 // Network interface
740 m_comboBoxInterface.addItem(tr("Any interface", "i.e. Any network interface"), QString());
741 for (const QNetworkInterface &iface : asConst(QNetworkInterface::allInterfaces()))
742 m_comboBoxInterface.addItem(iface.humanReadableName(), iface.name());
744 const QString currentInterface = session->networkInterface();
745 const int ifaceIndex = m_comboBoxInterface.findData(currentInterface);
746 if (ifaceIndex > -1)
748 m_comboBoxInterface.setCurrentIndex(ifaceIndex);
750 else
752 // Saved interface does not exist, show it
753 m_comboBoxInterface.addItem(session->networkInterfaceName(), currentInterface);
754 m_comboBoxInterface.setCurrentIndex(m_comboBoxInterface.count() - 1);
757 connect(&m_comboBoxInterface, qOverload<int>(&QComboBox::currentIndexChanged)
758 , this, &AdvancedSettings::updateInterfaceAddressCombo);
759 addRow(NETWORK_IFACE, tr("Network interface"), &m_comboBoxInterface);
760 // Network interface address
761 updateInterfaceAddressCombo();
762 addRow(NETWORK_IFACE_ADDRESS, tr("Optional IP address to bind to"), &m_comboBoxInterfaceAddress);
763 // Announce IP
764 m_lineEditAnnounceIP.setText(session->announceIP());
765 addRow(ANNOUNCE_IP, (tr("IP address reported to trackers (requires restart)")
766 + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#announce_ip", u"(?)"))
767 , &m_lineEditAnnounceIP);
768 // Max concurrent HTTP announces
769 m_spinBoxMaxConcurrentHTTPAnnounces.setMaximum(std::numeric_limits<int>::max());
770 m_spinBoxMaxConcurrentHTTPAnnounces.setValue(session->maxConcurrentHTTPAnnounces());
771 addRow(MAX_CONCURRENT_HTTP_ANNOUNCES, (tr("Max concurrent HTTP announces") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#max_concurrent_http_announces", u"(?)"))
772 , &m_spinBoxMaxConcurrentHTTPAnnounces);
773 // Stop tracker timeout
774 m_spinBoxStopTrackerTimeout.setMaximum(std::numeric_limits<int>::max());
775 m_spinBoxStopTrackerTimeout.setValue(session->stopTrackerTimeout());
776 m_spinBoxStopTrackerTimeout.setSuffix(tr(" s", " seconds"));
777 m_spinBoxStopTrackerTimeout.setSpecialValueText(tr("0 (disabled)"));
778 addRow(STOP_TRACKER_TIMEOUT, (tr("Stop tracker timeout [0: disabled]") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#stop_tracker_timeout", u"(?)"))
779 , &m_spinBoxStopTrackerTimeout);
780 // Program notifications
781 m_checkBoxProgramNotifications.setChecked(app()->desktopIntegration()->isNotificationsEnabled());
782 addRow(PROGRAM_NOTIFICATIONS, tr("Display notifications"), &m_checkBoxProgramNotifications);
783 // Torrent added notifications
784 m_checkBoxTorrentAddedNotifications.setChecked(app()->isTorrentAddedNotificationsEnabled());
785 addRow(TORRENT_ADDED_NOTIFICATIONS, tr("Display notifications for added torrents"), &m_checkBoxTorrentAddedNotifications);
786 #ifdef QBT_USES_DBUS
787 // Notification timeout
788 m_spinBoxNotificationTimeout.setMinimum(-1);
789 m_spinBoxNotificationTimeout.setMaximum(std::numeric_limits<int>::max());
790 m_spinBoxNotificationTimeout.setValue(app()->desktopIntegration()->notificationTimeout());
791 connect(&m_spinBoxNotificationTimeout, qOverload<int>(&QSpinBox::valueChanged)
792 , this, &AdvancedSettings::updateNotificationTimeoutSuffix);
793 updateNotificationTimeoutSuffix(m_spinBoxNotificationTimeout.value());
794 addRow(NOTIFICATION_TIMEOUT, tr("Notification timeout [0: infinite, -1: system default]"), &m_spinBoxNotificationTimeout);
795 #endif
796 // Reannounce to all trackers when ip/port changed
797 m_checkBoxReannounceWhenAddressChanged.setChecked(session->isReannounceWhenAddressChangedEnabled());
798 addRow(REANNOUNCE_WHEN_ADDRESS_CHANGED, tr("Reannounce to all trackers when IP or port changed"), &m_checkBoxReannounceWhenAddressChanged);
799 // Download tracker's favicon
800 m_checkBoxTrackerFavicon.setChecked(app()->mainWindow()->isDownloadTrackerFavicon());
801 addRow(DOWNLOAD_TRACKER_FAVICON, tr("Download tracker's favicon"), &m_checkBoxTrackerFavicon);
802 // Save path history length
803 m_spinBoxSavePathHistoryLength.setRange(0, 99);
804 m_spinBoxSavePathHistoryLength.setValue(pref->addNewTorrentDialogSavePathHistoryLength());
805 addRow(SAVE_PATH_HISTORY_LENGTH, tr("Save path history length"), &m_spinBoxSavePathHistoryLength);
806 // Enable speed graphs
807 m_checkBoxSpeedWidgetEnabled.setChecked(pref->isSpeedWidgetEnabled());
808 addRow(ENABLE_SPEED_WIDGET, tr("Enable speed graphs"), &m_checkBoxSpeedWidgetEnabled);
809 #ifndef Q_OS_MACOS
810 // Enable icons in menus
811 m_checkBoxIconsInMenusEnabled.setChecked(pref->iconsInMenusEnabled());
812 addRow(ENABLE_ICONS_IN_MENUS, tr("Enable icons in menus"), &m_checkBoxIconsInMenusEnabled);
813 #endif
814 // Tracker State
815 m_checkBoxTrackerStatus.setChecked(session->isTrackerEnabled());
816 addRow(TRACKER_STATUS, tr("Enable embedded tracker"), &m_checkBoxTrackerStatus);
817 // Tracker port
818 m_spinBoxTrackerPort.setMinimum(1);
819 m_spinBoxTrackerPort.setMaximum(65535);
820 m_spinBoxTrackerPort.setValue(pref->getTrackerPort());
821 addRow(TRACKER_PORT, tr("Embedded tracker port"), &m_spinBoxTrackerPort);
822 // Tracker port forwarding
823 m_checkBoxTrackerPortForwarding.setChecked(pref->isTrackerPortForwardingEnabled());
824 addRow(TRACKER_PORT_FORWARDING, tr("Enable port forwarding for embedded tracker"), &m_checkBoxTrackerPortForwarding);
825 #if defined(Q_OS_MACOS) || defined(Q_OS_WIN)
826 // Mark-of-the-Web
827 #ifdef Q_OS_MACOS
828 const QString motwLabel = tr("Enable quarantine for downloaded files");
829 #elif defined(Q_OS_WIN)
830 const QString motwLabel = tr("Enable Mark-of-the-Web (MOTW) for downloaded files");
831 #endif
832 m_checkBoxMarkOfTheWeb.setChecked(pref->isMarkOfTheWebEnabled());
833 addRow(ENABLE_MARK_OF_THE_WEB, motwLabel, &m_checkBoxMarkOfTheWeb);
834 #endif // Q_OS_MACOS || Q_OS_WIN
835 // Python executable path
836 m_pythonExecutablePath.setPlaceholderText(tr("(Auto detect if empty)"));
837 m_pythonExecutablePath.setText(pref->getPythonExecutablePath().toString());
838 addRow(PYTHON_EXECUTABLE_PATH, tr("Python executable path (may require restart)"), &m_pythonExecutablePath);
839 // Choking algorithm
840 m_comboBoxChokingAlgorithm.addItem(tr("Fixed slots"), QVariant::fromValue(BitTorrent::ChokingAlgorithm::FixedSlots));
841 m_comboBoxChokingAlgorithm.addItem(tr("Upload rate based"), QVariant::fromValue(BitTorrent::ChokingAlgorithm::RateBased));
842 m_comboBoxChokingAlgorithm.setCurrentIndex(m_comboBoxChokingAlgorithm.findData(QVariant::fromValue(session->chokingAlgorithm())));
843 addRow(CHOKING_ALGORITHM, (tr("Upload slots behavior") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#choking_algorithm", u"(?)"))
844 , &m_comboBoxChokingAlgorithm);
845 // Seed choking algorithm
846 m_comboBoxSeedChokingAlgorithm.addItem(tr("Round-robin"), QVariant::fromValue(BitTorrent::SeedChokingAlgorithm::RoundRobin));
847 m_comboBoxSeedChokingAlgorithm.addItem(tr("Fastest upload"), QVariant::fromValue(BitTorrent::SeedChokingAlgorithm::FastestUpload));
848 m_comboBoxSeedChokingAlgorithm.addItem(tr("Anti-leech"), QVariant::fromValue(BitTorrent::SeedChokingAlgorithm::AntiLeech));
849 m_comboBoxSeedChokingAlgorithm.setCurrentIndex(m_comboBoxSeedChokingAlgorithm.findData(QVariant::fromValue(session->seedChokingAlgorithm())));
850 addRow(SEED_CHOKING_ALGORITHM, (tr("Upload choking algorithm") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#seed_choking_algorithm", u"(?)"))
851 , &m_comboBoxSeedChokingAlgorithm);
853 // Torrent recheck confirmation
854 m_checkBoxConfirmTorrentRecheck.setChecked(pref->confirmTorrentRecheck());
855 addRow(CONFIRM_RECHECK_TORRENT, tr("Confirm torrent recheck"), &m_checkBoxConfirmTorrentRecheck);
857 // Remove all tags confirmation
858 m_checkBoxConfirmRemoveAllTags.setChecked(pref->confirmRemoveAllTags());
859 addRow(CONFIRM_REMOVE_ALL_TAGS, tr("Confirm removal of all tags"), &m_checkBoxConfirmRemoveAllTags);
861 // Remove tracker from all torrents confirmation
862 m_checkBoxConfirmRemoveTrackerFromAllTorrents.setChecked(pref->confirmRemoveTrackerFromAllTorrents());
863 addRow(CONFIRM_REMOVE_TRACKER_FROM_ALL_TORRENTS, tr("Confirm removal of tracker from all torrents"), &m_checkBoxConfirmRemoveTrackerFromAllTorrents);
865 // Announce to all trackers in a tier
866 m_checkBoxAnnounceAllTrackers.setChecked(session->announceToAllTrackers());
867 addRow(ANNOUNCE_ALL_TRACKERS, (tr("Always announce to all trackers in a tier")
868 + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#announce_to_all_trackers", u"(?)"))
869 , &m_checkBoxAnnounceAllTrackers);
871 // Announce to all tiers
872 m_checkBoxAnnounceAllTiers.setChecked(session->announceToAllTiers());
873 addRow(ANNOUNCE_ALL_TIERS, (tr("Always announce to all tiers")
874 + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#announce_to_all_tiers", u"(?)"))
875 , &m_checkBoxAnnounceAllTiers);
877 m_spinBoxPeerTurnover.setMinimum(0);
878 m_spinBoxPeerTurnover.setMaximum(100);
879 m_spinBoxPeerTurnover.setValue(session->peerTurnover());
880 m_spinBoxPeerTurnover.setSuffix(u" %"_s);
881 addRow(PEER_TURNOVER, (tr("Peer turnover disconnect percentage") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#peer_turnover", u"(?)"))
882 , &m_spinBoxPeerTurnover);
883 m_spinBoxPeerTurnoverCutoff.setMinimum(0);
884 m_spinBoxPeerTurnoverCutoff.setMaximum(100);
885 m_spinBoxPeerTurnoverCutoff.setSuffix(u" %"_s);
886 m_spinBoxPeerTurnoverCutoff.setValue(session->peerTurnoverCutoff());
887 addRow(PEER_TURNOVER_CUTOFF, (tr("Peer turnover threshold percentage") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#peer_turnover", u"(?)"))
888 , &m_spinBoxPeerTurnoverCutoff);
889 m_spinBoxPeerTurnoverInterval.setMinimum(30);
890 m_spinBoxPeerTurnoverInterval.setMaximum(3600);
891 m_spinBoxPeerTurnoverInterval.setSuffix(tr(" s", " seconds"));
892 m_spinBoxPeerTurnoverInterval.setValue(session->peerTurnoverInterval());
893 addRow(PEER_TURNOVER_INTERVAL, (tr("Peer turnover disconnect interval") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#peer_turnover", u"(?)"))
894 , &m_spinBoxPeerTurnoverInterval);
895 // Maximum outstanding requests to a single peer
896 m_spinBoxRequestQueueSize.setMinimum(1);
897 m_spinBoxRequestQueueSize.setMaximum(std::numeric_limits<int>::max());
898 m_spinBoxRequestQueueSize.setValue(session->requestQueueSize());
899 addRow(REQUEST_QUEUE_SIZE, (tr("Maximum outstanding requests to a single peer") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#max_out_request_queue", u"(?)"))
900 , &m_spinBoxRequestQueueSize);
901 // DHT bootstrap nodes
902 m_lineEditDHTBootstrapNodes.setPlaceholderText(tr("Resets to default if empty"));
903 m_lineEditDHTBootstrapNodes.setText(session->getDHTBootstrapNodes());
904 addRow(DHT_BOOTSTRAP_NODES, (tr("DHT bootstrap nodes") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#dht_bootstrap_nodes", u"(?)"))
905 , &m_lineEditDHTBootstrapNodes);
906 #if defined(QBT_USES_LIBTORRENT2) && TORRENT_USE_I2P
907 // I2P session options
908 m_spinBoxI2PInboundQuantity.setMinimum(1);
909 m_spinBoxI2PInboundQuantity.setMaximum(16);
910 m_spinBoxI2PInboundQuantity.setValue(session->I2PInboundQuantity());
911 addRow(I2P_INBOUND_QUANTITY, (tr("I2P inbound quantity") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#i2p_inbound_quantity", u"(?)"))
912 , &m_spinBoxI2PInboundQuantity);
913 m_spinBoxI2POutboundQuantity.setMinimum(1);
914 m_spinBoxI2POutboundQuantity.setMaximum(16);
915 m_spinBoxI2POutboundQuantity.setValue(session->I2POutboundQuantity());
916 addRow(I2P_OUTBOUND_QUANTITY, (tr("I2P outbound quantity") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#i2p_outbound_quantity", u"(?)"))
917 , &m_spinBoxI2POutboundQuantity);
918 m_spinBoxI2PInboundLength.setMinimum(0);
919 m_spinBoxI2PInboundLength.setMaximum(7);
920 m_spinBoxI2PInboundLength.setValue(session->I2PInboundLength());
921 addRow(I2P_INBOUND_LENGTH, (tr("I2P inbound length") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#i2p_inbound_length", u"(?)"))
922 , &m_spinBoxI2PInboundLength);
923 m_spinBoxI2POutboundLength.setMinimum(0);
924 m_spinBoxI2POutboundLength.setMaximum(7);
925 m_spinBoxI2POutboundLength.setValue(session->I2POutboundLength());
926 addRow(I2P_OUTBOUND_LENGTH, (tr("I2P outbound length") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#i2p_outbound_length", u"(?)"))
927 , &m_spinBoxI2POutboundLength);
928 #endif
931 template <typename T>
932 void AdvancedSettings::addRow(const int row, const QString &text, T *widget)
934 auto *label = new QLabel(text);
935 label->setOpenExternalLinks(true);
937 setCellWidget(row, PROPERTY, label);
938 setCellWidget(row, VALUE, widget);
940 if constexpr (std::is_same_v<T, QCheckBox>)
941 connect(widget, &QCheckBox::stateChanged, this, &AdvancedSettings::settingsChanged);
942 else if constexpr (std::is_same_v<T, QSpinBox>)
943 connect(widget, qOverload<int>(&QSpinBox::valueChanged), this, &AdvancedSettings::settingsChanged);
944 else if constexpr (std::is_same_v<T, QComboBox>)
945 connect(widget, qOverload<int>(&QComboBox::currentIndexChanged), this, &AdvancedSettings::settingsChanged);
946 else if constexpr (std::is_same_v<T, QLineEdit>)
947 connect(widget, &QLineEdit::textChanged, this, &AdvancedSettings::settingsChanged);