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