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