2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2024 Jonathan Ketchker
4 * Copyright (C) 2023 Vladimir Golovnev <glassez@yandex.ru>
5 * Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * In addition, as a special exception, the copyright holders give permission to
22 * link this program with the OpenSSL project's "OpenSSL" library (or with
23 * modified versions of it that use the same license as the "OpenSSL" library),
24 * and distribute the linked executables. You must obey the GNU General Public
25 * License in all respects for all of the code used other than "OpenSSL". If you
26 * modify file(s), you may extend this exception to your version of the file(s),
27 * but you are not obligated to do so. If you do not wish to do so, delete this
28 * exception statement from your version.
31 #include "optionsdialog.h"
37 #include <QApplication>
39 #include <QDesktopServices>
40 #include <QDialogButtonBox>
42 #include <QFileDialog>
43 #include <QMessageBox>
44 #include <QSystemTrayIcon>
45 #include <QTranslator>
47 #include "base/bittorrent/session.h"
48 #include "base/exceptions.h"
49 #include "base/global.h"
50 #include "base/net/portforwarder.h"
51 #include "base/net/proxyconfigurationmanager.h"
52 #include "base/path.h"
53 #include "base/preferences.h"
54 #include "base/rss/rss_autodownloader.h"
55 #include "base/rss/rss_session.h"
56 #include "base/torrentfileguard.h"
57 #include "base/torrentfileswatcher.h"
58 #include "base/utils/io.h"
59 #include "base/utils/misc.h"
60 #include "base/utils/net.h"
61 #include "base/utils/os.h"
62 #include "base/utils/password.h"
63 #include "base/utils/random.h"
64 #include "base/utils/sslkey.h"
65 #include "addnewtorrentdialog.h"
66 #include "advancedsettings.h"
67 #include "banlistoptionsdialog.h"
68 #include "interfaces/iguiapplication.h"
69 #include "ipsubnetwhitelistoptionsdialog.h"
70 #include "rss/automatedrssdownloader.h"
71 #include "ui_optionsdialog.h"
72 #include "uithemedialog.h"
73 #include "uithememanager.h"
75 #include "watchedfolderoptionsdialog.h"
76 #include "watchedfoldersmodel.h"
77 #include "webui/webui.h"
80 #include "base/net/dnsupdater.h"
83 #if defined Q_OS_MACOS || defined Q_OS_WIN
84 #include "base/utils/os.h"
85 #endif // defined Q_OS_MACOS || defined Q_OS_WIN
87 #define SETTINGS_KEY(name) u"OptionsDialog/" name
89 const int WEBUI_MIN_USERNAME_LENGTH
= 3;
90 const int WEBUI_MIN_PASSWORD_LENGTH
= 6;
94 QStringList
translatedWeekdayNames()
96 // return translated strings from Monday to Sunday in user selected locale
98 const QLocale locale
{Preferences::instance()->getLocale()};
99 const QDate date
{2018, 11, 5}; // Monday
101 for (int i
= 0; i
< 7; ++i
)
102 ret
.append(locale
.toString(date
.addDays(i
), u
"dddd"_s
));
106 class WheelEventEater final
: public QObject
109 using QObject::QObject
;
112 bool eventFilter(QObject
*, QEvent
*event
) override
114 return (event
->type() == QEvent::Wheel
);
118 bool isValidWebUIUsername(const QString
&username
)
120 return (username
.length() >= WEBUI_MIN_USERNAME_LENGTH
);
123 bool isValidWebUIPassword(const QString
&password
)
125 return (password
.length() >= WEBUI_MIN_PASSWORD_LENGTH
);
128 // Shortcuts for frequently used signals that have more than one overload. They would require
129 // type casts and that is why we declare required member pointer here instead.
130 void (QComboBox::*qComboBoxCurrentIndexChanged
)(int) = &QComboBox::currentIndexChanged
;
131 void (QSpinBox::*qSpinBoxValueChanged
)(int) = &QSpinBox::valueChanged
;
135 OptionsDialog::OptionsDialog(IGUIApplication
*app
, QWidget
*parent
)
136 : GUIApplicationComponent(app
, parent
)
137 , m_ui
{new Ui::OptionsDialog
}
138 , m_storeDialogSize
{SETTINGS_KEY(u
"Size"_s
)}
139 , m_storeHSplitterSize
{SETTINGS_KEY(u
"HorizontalSplitterSizes"_s
)}
140 , m_storeLastViewedPage
{SETTINGS_KEY(u
"LastViewedPage"_s
)}
143 m_applyButton
= m_ui
->buttonBox
->button(QDialogButtonBox::Apply
);
146 setWindowTitle(tr("Preferences"));
149 m_ui
->hsplitter
->setCollapsible(0, false);
150 m_ui
->hsplitter
->setCollapsible(1, false);
153 m_ui
->tabSelection
->item(TAB_UI
)->setIcon(UIThemeManager::instance()->getIcon(u
"preferences-desktop"_s
));
154 m_ui
->tabSelection
->item(TAB_BITTORRENT
)->setIcon(UIThemeManager::instance()->getIcon(u
"preferences-bittorrent"_s
, u
"preferences-system-network"_s
));
155 m_ui
->tabSelection
->item(TAB_CONNECTION
)->setIcon(UIThemeManager::instance()->getIcon(u
"network-connect"_s
, u
"network-wired"_s
));
156 m_ui
->tabSelection
->item(TAB_DOWNLOADS
)->setIcon(UIThemeManager::instance()->getIcon(u
"download"_s
, u
"folder-download"_s
));
157 m_ui
->tabSelection
->item(TAB_SPEED
)->setIcon(UIThemeManager::instance()->getIcon(u
"speedometer"_s
, u
"chronometer"_s
));
158 m_ui
->tabSelection
->item(TAB_RSS
)->setIcon(UIThemeManager::instance()->getIcon(u
"application-rss"_s
, u
"application-rss+xml"_s
));
160 m_ui
->tabSelection
->item(TAB_WEBUI
)->setHidden(true);
162 m_ui
->tabSelection
->item(TAB_WEBUI
)->setIcon(UIThemeManager::instance()->getIcon(u
"preferences-webui"_s
, u
"network-server"_s
));
164 m_ui
->tabSelection
->item(TAB_ADVANCED
)->setIcon(UIThemeManager::instance()->getIcon(u
"preferences-advanced"_s
, u
"preferences-other"_s
));
166 // set uniform size for all icons
168 for (int i
= 0; i
< m_ui
->tabSelection
->count(); ++i
)
169 maxHeight
= std::max(maxHeight
, m_ui
->tabSelection
->visualItemRect(m_ui
->tabSelection
->item(i
)).size().height());
170 for (int i
= 0; i
< m_ui
->tabSelection
->count(); ++i
)
172 const QSize
size(std::numeric_limits
<int>::max(), static_cast<int>(maxHeight
* 1.2));
173 m_ui
->tabSelection
->item(i
)->setSizeHint(size
);
176 connect(m_ui
->tabSelection
, &QListWidget::currentItemChanged
, this, &ThisType::changePage
);
179 loadBehaviorTabOptions();
180 loadDownloadsTabOptions();
181 loadConnectionTabOptions();
182 loadSpeedTabOptions();
183 loadBittorrentTabOptions();
185 #ifndef DISABLE_WEBUI
186 loadWebUITabOptions();
189 // Load Advanced settings
190 m_advancedSettings
= new AdvancedSettings(app
, m_ui
->tabAdvancedPage
);
191 m_ui
->advPageLayout
->addWidget(m_advancedSettings
);
192 connect(m_advancedSettings
, &AdvancedSettings::settingsChanged
, this, &ThisType::enableApplyButton
);
194 // setup apply button
195 m_applyButton
->setEnabled(false);
196 connect(m_applyButton
, &QPushButton::clicked
, this, [this]
199 m_applyButton
->setEnabled(false);
202 // disable mouse wheel event on widgets to avoid misselection
203 auto *wheelEventEater
= new WheelEventEater(this);
204 for (QComboBox
*widget
: asConst(findChildren
<QComboBox
*>()))
205 widget
->installEventFilter(wheelEventEater
);
206 for (QSpinBox
*widget
: asConst(findChildren
<QSpinBox
*>()))
207 widget
->installEventFilter(wheelEventEater
);
209 m_ui
->tabSelection
->setCurrentRow(m_storeLastViewedPage
);
211 if (const QSize dialogSize
= m_storeDialogSize
; dialogSize
.isValid())
215 OptionsDialog::~OptionsDialog()
217 // save dialog states
218 m_storeDialogSize
= size();
220 QStringList hSplitterSizes
;
221 for (const int size
: asConst(m_ui
->hsplitter
->sizes()))
222 hSplitterSizes
.append(QString::number(size
));
223 m_storeHSplitterSize
= hSplitterSizes
;
225 m_storeLastViewedPage
= m_ui
->tabSelection
->currentRow();
230 void OptionsDialog::loadBehaviorTabOptions()
232 const auto *pref
= Preferences::instance();
233 const auto *session
= BitTorrent::Session::instance();
235 initializeLanguageCombo();
236 setLocale(pref
->getLocale());
238 m_ui
->checkUseCustomTheme
->setChecked(Preferences::instance()->useCustomUITheme());
239 m_ui
->customThemeFilePath
->setSelectedPath(Preferences::instance()->customUIThemePath());
240 m_ui
->customThemeFilePath
->setMode(FileSystemPathEdit::Mode::FileOpen
);
241 m_ui
->customThemeFilePath
->setDialogCaption(tr("Select qBittorrent UI Theme file"));
242 m_ui
->customThemeFilePath
->setFileNameFilter(tr("qBittorrent UI Theme file (*.qbtheme config.json)"));
243 #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
244 m_ui
->checkUseSystemIcon
->setChecked(pref
->useSystemIcons());
246 m_ui
->checkUseSystemIcon
->setVisible(false);
249 m_ui
->confirmDeletion
->setChecked(pref
->confirmTorrentDeletion());
250 m_ui
->checkAltRowColors
->setChecked(pref
->useAlternatingRowColors());
251 m_ui
->checkHideZero
->setChecked(pref
->getHideZeroValues());
252 m_ui
->comboHideZero
->setCurrentIndex(pref
->getHideZeroComboValues());
253 m_ui
->comboHideZero
->setEnabled(m_ui
->checkHideZero
->isChecked());
255 m_ui
->actionTorrentDlOnDblClBox
->setItemData(0, TOGGLE_PAUSE
);
256 m_ui
->actionTorrentDlOnDblClBox
->setItemData(1, OPEN_DEST
);
257 m_ui
->actionTorrentDlOnDblClBox
->setItemData(2, PREVIEW_FILE
);
258 m_ui
->actionTorrentDlOnDblClBox
->setItemData(3, SHOW_OPTIONS
);
259 m_ui
->actionTorrentDlOnDblClBox
->setItemData(4, NO_ACTION
);
260 int actionDownloading
= pref
->getActionOnDblClOnTorrentDl();
261 if ((actionDownloading
< 0) || (actionDownloading
>= m_ui
->actionTorrentDlOnDblClBox
->count()))
262 actionDownloading
= TOGGLE_PAUSE
;
263 m_ui
->actionTorrentDlOnDblClBox
->setCurrentIndex(m_ui
->actionTorrentDlOnDblClBox
->findData(actionDownloading
));
265 m_ui
->actionTorrentFnOnDblClBox
->setItemData(0, TOGGLE_PAUSE
);
266 m_ui
->actionTorrentFnOnDblClBox
->setItemData(1, OPEN_DEST
);
267 m_ui
->actionTorrentFnOnDblClBox
->setItemData(2, PREVIEW_FILE
);
268 m_ui
->actionTorrentFnOnDblClBox
->setItemData(3, SHOW_OPTIONS
);
269 m_ui
->actionTorrentFnOnDblClBox
->setItemData(4, NO_ACTION
);
270 int actionSeeding
= pref
->getActionOnDblClOnTorrentFn();
271 if ((actionSeeding
< 0) || (actionSeeding
>= m_ui
->actionTorrentFnOnDblClBox
->count()))
272 actionSeeding
= OPEN_DEST
;
273 m_ui
->actionTorrentFnOnDblClBox
->setCurrentIndex(m_ui
->actionTorrentFnOnDblClBox
->findData(actionSeeding
));
275 m_ui
->checkBoxHideZeroStatusFilters
->setChecked(pref
->getHideZeroStatusFilters());
278 m_ui
->checkStartup
->setVisible(false);
280 m_ui
->checkShowSplash
->setChecked(!pref
->isSplashScreenDisabled());
281 m_ui
->checkProgramExitConfirm
->setChecked(pref
->confirmOnExit());
282 m_ui
->checkProgramAutoExitConfirm
->setChecked(!pref
->dontConfirmAutoExit());
283 m_ui
->checkConfirmPauseAndResumeAll
->setChecked(pref
->confirmPauseAndResumeAll());
285 m_ui
->windowStateComboBox
->addItem(tr("Normal"), QVariant::fromValue(WindowState::Normal
));
286 m_ui
->windowStateComboBox
->addItem(tr("Minimized"), QVariant::fromValue(WindowState::Minimized
));
288 m_ui
->windowStateComboBox
->addItem(tr("Hidden"), QVariant::fromValue(WindowState::Hidden
));
290 m_ui
->windowStateComboBox
->setCurrentIndex(m_ui
->windowStateComboBox
->findData(QVariant::fromValue(app()->startUpWindowState())));
292 #if !(defined(Q_OS_WIN) || defined(Q_OS_MACOS))
293 m_ui
->groupFileAssociation
->setVisible(false);
294 m_ui
->checkProgramUpdates
->setVisible(false);
298 // Disable systray integration if it is not supported by the system
299 if (!QSystemTrayIcon::isSystemTrayAvailable())
301 m_ui
->checkShowSystray
->setChecked(false);
302 m_ui
->checkShowSystray
->setEnabled(false);
303 m_ui
->checkShowSystray
->setToolTip(tr("Disabled due to failed to detect system tray presence"));
305 m_ui
->checkShowSystray
->setChecked(pref
->systemTrayEnabled());
306 m_ui
->checkMinimizeToSysTray
->setChecked(pref
->minimizeToTray());
307 m_ui
->checkCloseToSystray
->setChecked(pref
->closeToTray());
308 m_ui
->comboTrayIcon
->setCurrentIndex(static_cast<int>(pref
->trayIconStyle()));
312 m_ui
->checkStartup
->setChecked(pref
->WinStartup());
316 m_ui
->checkShowSystray
->setVisible(false);
317 m_ui
->checkAssociateTorrents
->setChecked(Utils::OS::isTorrentFileAssocSet());
318 m_ui
->checkAssociateTorrents
->setEnabled(!m_ui
->checkAssociateTorrents
->isChecked());
319 m_ui
->checkAssociateMagnetLinks
->setChecked(Utils::OS::isMagnetLinkAssocSet());
320 m_ui
->checkAssociateMagnetLinks
->setEnabled(!m_ui
->checkAssociateMagnetLinks
->isChecked());
323 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
324 m_ui
->checkProgramUpdates
->setChecked(pref
->isUpdateCheckEnabled());
327 m_ui
->checkPreventFromSuspendWhenDownloading
->setChecked(pref
->preventFromSuspendWhenDownloading());
328 m_ui
->checkPreventFromSuspendWhenSeeding
->setChecked(pref
->preventFromSuspendWhenSeeding());
330 m_ui
->textFileLogPath
->setDialogCaption(tr("Choose a save directory"));
331 m_ui
->textFileLogPath
->setMode(FileSystemPathEdit::Mode::DirectorySave
);
332 m_ui
->textFileLogPath
->setSelectedPath(app()->fileLoggerPath());
333 const bool fileLogBackup
= app()->isFileLoggerBackup();
334 m_ui
->checkFileLogBackup
->setChecked(fileLogBackup
);
335 m_ui
->spinFileLogSize
->setEnabled(fileLogBackup
);
336 const bool fileLogDelete
= app()->isFileLoggerDeleteOld();
337 m_ui
->checkFileLogDelete
->setChecked(fileLogDelete
);
338 m_ui
->spinFileLogAge
->setEnabled(fileLogDelete
);
339 m_ui
->comboFileLogAgeType
->setEnabled(fileLogDelete
);
340 m_ui
->spinFileLogSize
->setValue(app()->fileLoggerMaxSize() / 1024);
341 m_ui
->spinFileLogAge
->setValue(app()->fileLoggerAge());
342 m_ui
->comboFileLogAgeType
->setCurrentIndex(app()->fileLoggerAgeType());
343 // Groupbox's check state must be initialized after some of its children if they are manually enabled/disabled
344 m_ui
->checkFileLog
->setChecked(app()->isFileLoggerEnabled());
346 m_ui
->checkBoxPerformanceWarning
->setChecked(session
->isPerformanceWarningEnabled());
348 connect(m_ui
->comboI18n
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
350 #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
351 connect(m_ui
->checkUseSystemIcon
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
353 connect(m_ui
->checkUseCustomTheme
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
354 connect(m_ui
->customThemeFilePath
, &FileSystemPathEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
356 m_ui
->buttonCustomizeUITheme
->setEnabled(!m_ui
->checkUseCustomTheme
->isChecked());
357 connect(m_ui
->checkUseCustomTheme
, &QGroupBox::toggled
, this, [this]
359 m_ui
->buttonCustomizeUITheme
->setEnabled(!m_ui
->checkUseCustomTheme
->isChecked());
361 connect(m_ui
->buttonCustomizeUITheme
, &QPushButton::clicked
, this, [this]
363 auto *dialog
= new UIThemeDialog(this);
364 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
368 connect(m_ui
->confirmDeletion
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
369 connect(m_ui
->checkAltRowColors
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
370 connect(m_ui
->checkHideZero
, &QAbstractButton::toggled
, m_ui
->comboHideZero
, &QWidget::setEnabled
);
371 connect(m_ui
->checkHideZero
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
372 connect(m_ui
->comboHideZero
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
373 connect(m_ui
->actionTorrentDlOnDblClBox
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
374 connect(m_ui
->actionTorrentFnOnDblClBox
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
375 connect(m_ui
->checkBoxHideZeroStatusFilters
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
378 connect(m_ui
->checkStartup
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
380 connect(m_ui
->checkShowSplash
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
381 connect(m_ui
->checkProgramExitConfirm
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
382 connect(m_ui
->checkProgramAutoExitConfirm
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
383 connect(m_ui
->checkConfirmPauseAndResumeAll
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
384 connect(m_ui
->checkShowSystray
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
385 connect(m_ui
->checkMinimizeToSysTray
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
386 connect(m_ui
->checkCloseToSystray
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
387 connect(m_ui
->comboTrayIcon
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
388 connect(m_ui
->windowStateComboBox
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
390 connect(m_ui
->checkPreventFromSuspendWhenDownloading
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
391 connect(m_ui
->checkPreventFromSuspendWhenSeeding
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
393 #if defined(Q_OS_MACOS)
394 connect(m_ui
->checkAssociateTorrents
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
395 connect(m_ui
->checkAssociateMagnetLinks
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
398 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
399 connect(m_ui
->checkProgramUpdates
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
403 m_ui
->assocPanel
->hide();
407 m_ui
->defaultProgramPanel
->hide();
410 #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && !defined(QBT_USES_DBUS)
411 m_ui
->checkPreventFromSuspendWhenDownloading
->setDisabled(true);
412 m_ui
->checkPreventFromSuspendWhenSeeding
->setDisabled(true);
415 connect(m_ui
->checkFileLog
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
416 connect(m_ui
->textFileLogPath
, &FileSystemPathEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
417 connect(m_ui
->checkFileLogBackup
, &QAbstractButton::toggled
, m_ui
->spinFileLogSize
, &QWidget::setEnabled
);
418 connect(m_ui
->checkFileLogBackup
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
419 connect(m_ui
->checkFileLogDelete
, &QAbstractButton::toggled
, m_ui
->comboFileLogAgeType
, &QWidget::setEnabled
);
420 connect(m_ui
->checkFileLogDelete
, &QAbstractButton::toggled
, m_ui
->spinFileLogAge
, &QWidget::setEnabled
);
421 connect(m_ui
->checkFileLogDelete
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
422 connect(m_ui
->spinFileLogSize
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
423 connect(m_ui
->spinFileLogAge
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
424 connect(m_ui
->comboFileLogAgeType
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
426 connect(m_ui
->checkBoxPerformanceWarning
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
429 void OptionsDialog::saveBehaviorTabOptions() const
431 auto *pref
= Preferences::instance();
432 auto *session
= BitTorrent::Session::instance();
434 // Load the translation
435 const QString locale
= getLocale();
436 if (pref
->getLocale() != locale
)
438 auto *translator
= new QTranslator
;
439 if (translator
->load(u
":/lang/qbittorrent_"_s
+ locale
))
440 qDebug("%s locale recognized, using translation.", qUtf8Printable(locale
));
442 qDebug("%s locale unrecognized, using default (en).", qUtf8Printable(locale
));
443 qApp
->installTranslator(translator
);
445 pref
->setLocale(locale
);
447 #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
448 pref
->useSystemIcons(m_ui
->checkUseSystemIcon
->isChecked());
450 pref
->setUseCustomUITheme(m_ui
->checkUseCustomTheme
->isChecked());
451 pref
->setCustomUIThemePath(m_ui
->customThemeFilePath
->selectedPath());
453 pref
->setConfirmTorrentDeletion(m_ui
->confirmDeletion
->isChecked());
454 pref
->setAlternatingRowColors(m_ui
->checkAltRowColors
->isChecked());
455 pref
->setHideZeroValues(m_ui
->checkHideZero
->isChecked());
456 pref
->setHideZeroComboValues(m_ui
->comboHideZero
->currentIndex());
458 pref
->setActionOnDblClOnTorrentDl(m_ui
->actionTorrentDlOnDblClBox
->currentData().toInt());
459 pref
->setActionOnDblClOnTorrentFn(m_ui
->actionTorrentFnOnDblClBox
->currentData().toInt());
461 pref
->setHideZeroStatusFilters(m_ui
->checkBoxHideZeroStatusFilters
->isChecked());
463 pref
->setSplashScreenDisabled(isSplashScreenDisabled());
464 pref
->setConfirmOnExit(m_ui
->checkProgramExitConfirm
->isChecked());
465 pref
->setDontConfirmAutoExit(!m_ui
->checkProgramAutoExitConfirm
->isChecked());
466 pref
->setConfirmPauseAndResumeAll(m_ui
->checkConfirmPauseAndResumeAll
->isChecked());
469 pref
->setWinStartup(WinStartup());
473 pref
->setSystemTrayEnabled(m_ui
->checkShowSystray
->isChecked());
474 pref
->setTrayIconStyle(TrayIcon::Style(m_ui
->comboTrayIcon
->currentIndex()));
475 pref
->setCloseToTray(m_ui
->checkCloseToSystray
->isChecked());
476 pref
->setMinimizeToTray(m_ui
->checkMinimizeToSysTray
->isChecked());
480 if (m_ui
->checkAssociateTorrents
->isChecked())
482 Utils::OS::setTorrentFileAssoc();
483 m_ui
->checkAssociateTorrents
->setChecked(Utils::OS::isTorrentFileAssocSet());
484 m_ui
->checkAssociateTorrents
->setEnabled(!m_ui
->checkAssociateTorrents
->isChecked());
486 if (m_ui
->checkAssociateMagnetLinks
->isChecked())
488 Utils::OS::setMagnetLinkAssoc();
489 m_ui
->checkAssociateMagnetLinks
->setChecked(Utils::OS::isMagnetLinkAssocSet());
490 m_ui
->checkAssociateMagnetLinks
->setEnabled(!m_ui
->checkAssociateMagnetLinks
->isChecked());
494 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
495 pref
->setUpdateCheckEnabled(m_ui
->checkProgramUpdates
->isChecked());
498 pref
->setPreventFromSuspendWhenDownloading(m_ui
->checkPreventFromSuspendWhenDownloading
->isChecked());
499 pref
->setPreventFromSuspendWhenSeeding(m_ui
->checkPreventFromSuspendWhenSeeding
->isChecked());
501 app()->setFileLoggerPath(m_ui
->textFileLogPath
->selectedPath());
502 app()->setFileLoggerBackup(m_ui
->checkFileLogBackup
->isChecked());
503 app()->setFileLoggerMaxSize(m_ui
->spinFileLogSize
->value() * 1024);
504 app()->setFileLoggerAge(m_ui
->spinFileLogAge
->value());
505 app()->setFileLoggerAgeType(m_ui
->comboFileLogAgeType
->currentIndex());
506 app()->setFileLoggerDeleteOld(m_ui
->checkFileLogDelete
->isChecked());
507 app()->setFileLoggerEnabled(m_ui
->checkFileLog
->isChecked());
509 app()->setStartUpWindowState(m_ui
->windowStateComboBox
->currentData().value
<WindowState
>());
511 session
->setPerformanceWarningEnabled(m_ui
->checkBoxPerformanceWarning
->isChecked());
514 void OptionsDialog::loadDownloadsTabOptions()
516 const auto *pref
= Preferences::instance();
517 const auto *session
= BitTorrent::Session::instance();
519 m_ui
->checkAdditionDialog
->setChecked(pref
->isAddNewTorrentDialogEnabled());
520 m_ui
->checkAdditionDialogFront
->setChecked(pref
->isAddNewTorrentDialogTopLevel());
522 m_ui
->contentLayoutComboBox
->setCurrentIndex(static_cast<int>(session
->torrentContentLayout()));
523 m_ui
->checkAddToQueueTop
->setChecked(session
->isAddTorrentToQueueTop());
524 m_ui
->checkStartPaused
->setChecked(session
->isAddTorrentPaused());
526 m_ui
->stopConditionComboBox
->setToolTip(
527 u
"<html><body><p><b>" + tr("None") + u
"</b> - " + tr("No stop condition is set.") + u
"</p><p><b>" +
528 tr("Metadata received") + u
"</b> - " + tr("Torrent will stop after metadata is received.") +
529 u
" <em>" + tr("Torrents that have metadata initially will be added as stopped.") + u
"</em></p><p><b>" +
530 tr("Files checked") + u
"</b> - " + tr("Torrent will stop after files are initially checked.") +
531 u
" <em>" + tr("This will also download metadata if it wasn't there initially.") + u
"</em></p></body></html>");
532 m_ui
->stopConditionComboBox
->setItemData(0, QVariant::fromValue(BitTorrent::Torrent::StopCondition::None
));
533 m_ui
->stopConditionComboBox
->setItemData(1, QVariant::fromValue(BitTorrent::Torrent::StopCondition::MetadataReceived
));
534 m_ui
->stopConditionComboBox
->setItemData(2, QVariant::fromValue(BitTorrent::Torrent::StopCondition::FilesChecked
));
535 m_ui
->stopConditionComboBox
->setCurrentIndex(m_ui
->stopConditionComboBox
->findData(QVariant::fromValue(session
->torrentStopCondition())));
536 m_ui
->stopConditionLabel
->setEnabled(!m_ui
->checkStartPaused
->isChecked());
537 m_ui
->stopConditionComboBox
->setEnabled(!m_ui
->checkStartPaused
->isChecked());
539 m_ui
->checkMergeTrackers
->setChecked(session
->isMergeTrackersEnabled());
540 m_ui
->checkConfirmMergeTrackers
->setEnabled(m_ui
->checkAdditionDialog
->isChecked());
541 m_ui
->checkConfirmMergeTrackers
->setChecked(m_ui
->checkConfirmMergeTrackers
->isEnabled() ? pref
->confirmMergeTrackers() : false);
542 connect(m_ui
->checkAdditionDialog
, &QGroupBox::toggled
, this, [this, pref
]
544 m_ui
->checkConfirmMergeTrackers
->setEnabled(m_ui
->checkAdditionDialog
->isChecked());
545 m_ui
->checkConfirmMergeTrackers
->setChecked(m_ui
->checkConfirmMergeTrackers
->isEnabled() ? pref
->confirmMergeTrackers() : false);
548 const TorrentFileGuard::AutoDeleteMode autoDeleteMode
= TorrentFileGuard::autoDeleteMode();
549 m_ui
->deleteTorrentBox
->setChecked(autoDeleteMode
!= TorrentFileGuard::Never
);
550 m_ui
->deleteCancelledTorrentBox
->setChecked(autoDeleteMode
== TorrentFileGuard::Always
);
551 m_ui
->deleteTorrentWarningIcon
->setPixmap(QApplication::style()->standardIcon(QStyle::SP_MessageBoxCritical
).pixmap(16, 16));
552 m_ui
->deleteTorrentWarningIcon
->hide();
553 m_ui
->deleteTorrentWarningLabel
->hide();
554 m_ui
->deleteTorrentWarningLabel
->setToolTip(u
"<html><body><p>" +
555 tr("By enabling these options, you can <strong>irrevocably lose</strong> your .torrent files!") +
557 tr("When these options are enabled, qBittorrent will <strong>delete</strong> .torrent files "
558 "after they were successfully (the first option) or not (the second option) added to its "
559 "download queue. This will be applied <strong>not only</strong> to the files opened via "
560 "“Add torrent” menu action but to those opened via <strong>file type association</strong> as well") +
562 tr("If you enable the second option (“Also when addition is cancelled”) the "
563 ".torrent file <strong>will be deleted</strong> even if you press “<strong>Cancel</strong>” in "
564 "the “Add torrent” dialog") +
565 u
"</p></body></html>");
567 m_ui
->checkPreallocateAll
->setChecked(session
->isPreallocationEnabled());
568 m_ui
->checkAppendqB
->setChecked(session
->isAppendExtensionEnabled());
569 m_ui
->checkUnwantedFolder
->setChecked(session
->isUnwantedFolderEnabled());
570 m_ui
->checkRecursiveDownload
->setChecked(pref
->isRecursiveDownloadEnabled());
572 m_ui
->comboSavingMode
->setCurrentIndex(!session
->isAutoTMMDisabledByDefault());
573 m_ui
->comboTorrentCategoryChanged
->setCurrentIndex(session
->isDisableAutoTMMWhenCategoryChanged());
574 m_ui
->comboCategoryChanged
->setCurrentIndex(session
->isDisableAutoTMMWhenCategorySavePathChanged());
575 m_ui
->comboCategoryDefaultPathChanged
->setCurrentIndex(session
->isDisableAutoTMMWhenDefaultSavePathChanged());
577 m_ui
->checkUseSubcategories
->setChecked(session
->isSubcategoriesEnabled());
578 m_ui
->checkUseCategoryPaths
->setChecked(session
->useCategoryPathsInManualMode());
580 m_ui
->textSavePath
->setDialogCaption(tr("Choose a save directory"));
581 m_ui
->textSavePath
->setMode(FileSystemPathEdit::Mode::DirectorySave
);
582 m_ui
->textSavePath
->setSelectedPath(session
->savePath());
584 m_ui
->checkUseDownloadPath
->setChecked(session
->isDownloadPathEnabled());
585 m_ui
->textDownloadPath
->setDialogCaption(tr("Choose a save directory"));
586 m_ui
->textDownloadPath
->setEnabled(m_ui
->checkUseDownloadPath
->isChecked());
587 m_ui
->textDownloadPath
->setMode(FileSystemPathEdit::Mode::DirectorySave
);
588 m_ui
->textDownloadPath
->setSelectedPath(session
->downloadPath());
590 const bool isExportDirEmpty
= session
->torrentExportDirectory().isEmpty();
591 m_ui
->checkExportDir
->setChecked(!isExportDirEmpty
);
592 m_ui
->textExportDir
->setDialogCaption(tr("Choose export directory"));
593 m_ui
->textExportDir
->setEnabled(m_ui
->checkExportDir
->isChecked());
594 m_ui
->textExportDir
->setMode(FileSystemPathEdit::Mode::DirectorySave
);
595 if (!isExportDirEmpty
)
596 m_ui
->textExportDir
->setSelectedPath(session
->torrentExportDirectory());
598 const bool isExportDirFinEmpty
= session
->finishedTorrentExportDirectory().isEmpty();
599 m_ui
->checkExportDirFin
->setChecked(!isExportDirFinEmpty
);
600 m_ui
->textExportDirFin
->setDialogCaption(tr("Choose export directory"));
601 m_ui
->textExportDirFin
->setEnabled(m_ui
->checkExportDirFin
->isChecked());
602 m_ui
->textExportDirFin
->setMode(FileSystemPathEdit::Mode::DirectorySave
);
603 if (!isExportDirFinEmpty
)
604 m_ui
->textExportDirFin
->setSelectedPath(session
->finishedTorrentExportDirectory());
606 auto *watchedFoldersModel
= new WatchedFoldersModel(TorrentFilesWatcher::instance(), this);
607 connect(watchedFoldersModel
, &QAbstractListModel::dataChanged
, this, &ThisType::enableApplyButton
);
608 m_ui
->scanFoldersView
->header()->setSectionResizeMode(QHeaderView::ResizeToContents
);
609 m_ui
->scanFoldersView
->setModel(watchedFoldersModel
);
610 connect(m_ui
->scanFoldersView
->selectionModel(), &QItemSelectionModel::selectionChanged
, this, &ThisType::handleWatchedFolderViewSelectionChanged
);
611 connect(m_ui
->scanFoldersView
, &QTreeView::doubleClicked
, this, &ThisType::editWatchedFolderOptions
);
613 m_ui
->groupExcludedFileNames
->setChecked(session
->isExcludedFileNamesEnabled());
614 m_ui
->textExcludedFileNames
->setPlainText(session
->excludedFileNames().join(u
'\n'));
616 m_ui
->groupMailNotification
->setChecked(pref
->isMailNotificationEnabled());
617 m_ui
->senderEmailTxt
->setText(pref
->getMailNotificationSender());
618 m_ui
->lineEditDestEmail
->setText(pref
->getMailNotificationEmail());
619 m_ui
->lineEditSmtpServer
->setText(pref
->getMailNotificationSMTP());
620 m_ui
->checkSmtpSSL
->setChecked(pref
->getMailNotificationSMTPSSL());
621 m_ui
->groupMailNotifAuth
->setChecked(pref
->getMailNotificationSMTPAuth());
622 m_ui
->mailNotifUsername
->setText(pref
->getMailNotificationSMTPUsername());
623 m_ui
->mailNotifPassword
->setText(pref
->getMailNotificationSMTPPassword());
625 m_ui
->groupBoxRunOnAdded
->setChecked(pref
->isAutoRunOnTorrentAddedEnabled());
626 m_ui
->groupBoxRunOnFinished
->setChecked(pref
->isAutoRunOnTorrentFinishedEnabled());
627 m_ui
->lineEditRunOnAdded
->setText(pref
->getAutoRunOnTorrentAddedProgram());
628 m_ui
->lineEditRunOnFinished
->setText(pref
->getAutoRunOnTorrentFinishedProgram());
629 #if defined(Q_OS_WIN)
630 m_ui
->autoRunConsole
->setChecked(pref
->isAutoRunConsoleEnabled());
632 m_ui
->autoRunConsole
->hide();
634 const auto autoRunStr
= u
"%1\n %2\n %3\n %4\n %5\n %6\n %7\n %8\n %9\n %10\n %11\n %12\n %13\n%14"_s
635 .arg(tr("Supported parameters (case sensitive):")
636 , tr("%N: Torrent name")
638 , tr("%G: Tags (separated by comma)")
639 , tr("%F: Content path (same as root path for multifile torrent)")
640 , tr("%R: Root path (first torrent subdirectory path)")
641 , tr("%D: Save path")
642 , tr("%C: Number of files")
643 , tr("%Z: Torrent size (bytes)"))
644 .arg(tr("%T: Current tracker")
645 , tr("%I: Info hash v1 (or '-' if unavailable)")
646 , tr("%J: Info hash v2 (or '-' if unavailable)")
647 , tr("%K: Torrent ID (either sha-1 info hash for v1 torrent or truncated sha-256 info hash for v2/hybrid torrent)")
648 , tr("Tip: Encapsulate parameter with quotation marks to avoid text being cut off at whitespace (e.g., \"%N\")"));
649 m_ui
->labelAutoRunParam
->setText(autoRunStr
);
651 connect(m_ui
->checkAdditionDialog
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
652 connect(m_ui
->checkAdditionDialogFront
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
654 connect(m_ui
->contentLayoutComboBox
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
656 connect(m_ui
->checkAddToQueueTop
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
657 connect(m_ui
->checkStartPaused
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
658 connect(m_ui
->checkStartPaused
, &QAbstractButton::toggled
, this, [this](const bool checked
)
660 m_ui
->stopConditionLabel
->setEnabled(!checked
);
661 m_ui
->stopConditionComboBox
->setEnabled(!checked
);
663 connect(m_ui
->stopConditionComboBox
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
664 connect(m_ui
->checkMergeTrackers
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
665 connect(m_ui
->checkConfirmMergeTrackers
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
666 connect(m_ui
->deleteTorrentBox
, &QGroupBox::toggled
, m_ui
->deleteTorrentWarningIcon
, &QWidget::setVisible
);
667 connect(m_ui
->deleteTorrentBox
, &QGroupBox::toggled
, m_ui
->deleteTorrentWarningLabel
, &QWidget::setVisible
);
668 connect(m_ui
->deleteTorrentBox
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
669 connect(m_ui
->deleteCancelledTorrentBox
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
671 connect(m_ui
->checkPreallocateAll
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
672 connect(m_ui
->checkAppendqB
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
673 connect(m_ui
->checkUnwantedFolder
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
674 connect(m_ui
->checkRecursiveDownload
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
676 connect(m_ui
->comboSavingMode
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
677 connect(m_ui
->comboTorrentCategoryChanged
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
678 connect(m_ui
->comboCategoryChanged
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
679 connect(m_ui
->comboCategoryDefaultPathChanged
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
681 connect(m_ui
->checkUseSubcategories
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
682 connect(m_ui
->checkUseCategoryPaths
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
684 connect(m_ui
->textSavePath
, &FileSystemPathEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
685 connect(m_ui
->textDownloadPath
, &FileSystemPathEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
687 connect(m_ui
->checkExportDir
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
688 connect(m_ui
->checkExportDir
, &QAbstractButton::toggled
, m_ui
->textExportDir
, &QWidget::setEnabled
);
689 connect(m_ui
->checkExportDirFin
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
690 connect(m_ui
->checkExportDirFin
, &QAbstractButton::toggled
, m_ui
->textExportDirFin
, &QWidget::setEnabled
);
691 connect(m_ui
->textExportDir
, &FileSystemPathEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
692 connect(m_ui
->textExportDirFin
, &FileSystemPathEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
693 connect(m_ui
->checkUseDownloadPath
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
694 connect(m_ui
->checkUseDownloadPath
, &QAbstractButton::toggled
, m_ui
->textDownloadPath
, &QWidget::setEnabled
);
696 connect(m_ui
->addWatchedFolderButton
, &QAbstractButton::clicked
, this, &ThisType::enableApplyButton
);
698 connect(m_ui
->groupExcludedFileNames
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
699 connect(m_ui
->textExcludedFileNames
, &QPlainTextEdit::textChanged
, this, &ThisType::enableApplyButton
);
700 connect(m_ui
->removeWatchedFolderButton
, &QAbstractButton::clicked
, this, &ThisType::enableApplyButton
);
702 connect(m_ui
->groupMailNotification
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
703 connect(m_ui
->senderEmailTxt
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
704 connect(m_ui
->lineEditDestEmail
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
705 connect(m_ui
->lineEditSmtpServer
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
706 connect(m_ui
->checkSmtpSSL
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
707 connect(m_ui
->groupMailNotifAuth
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
708 connect(m_ui
->mailNotifUsername
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
709 connect(m_ui
->mailNotifPassword
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
711 connect(m_ui
->groupBoxRunOnAdded
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
712 connect(m_ui
->lineEditRunOnAdded
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
713 connect(m_ui
->groupBoxRunOnFinished
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
714 connect(m_ui
->lineEditRunOnFinished
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
715 connect(m_ui
->autoRunConsole
, &QCheckBox::toggled
, this, &ThisType::enableApplyButton
);
718 void OptionsDialog::saveDownloadsTabOptions() const
720 auto *pref
= Preferences::instance();
721 auto *session
= BitTorrent::Session::instance();
723 pref
->setAddNewTorrentDialogEnabled(useAdditionDialog());
724 pref
->setAddNewTorrentDialogTopLevel(m_ui
->checkAdditionDialogFront
->isChecked());
726 session
->setTorrentContentLayout(static_cast<BitTorrent::TorrentContentLayout
>(m_ui
->contentLayoutComboBox
->currentIndex()));
728 session
->setAddTorrentToQueueTop(m_ui
->checkAddToQueueTop
->isChecked());
729 session
->setAddTorrentPaused(addTorrentsInPause());
730 session
->setTorrentStopCondition(m_ui
->stopConditionComboBox
->currentData().value
<BitTorrent::Torrent::StopCondition
>());
731 TorrentFileGuard::setAutoDeleteMode(!m_ui
->deleteTorrentBox
->isChecked() ? TorrentFileGuard::Never
732 : !m_ui
->deleteCancelledTorrentBox
->isChecked() ? TorrentFileGuard::IfAdded
733 : TorrentFileGuard::Always
);
734 session
->setMergeTrackersEnabled(m_ui
->checkMergeTrackers
->isChecked());
735 if (m_ui
->checkConfirmMergeTrackers
->isEnabled())
736 pref
->setConfirmMergeTrackers(m_ui
->checkConfirmMergeTrackers
->isChecked());
738 session
->setPreallocationEnabled(preAllocateAllFiles());
739 session
->setAppendExtensionEnabled(m_ui
->checkAppendqB
->isChecked());
740 session
->setUnwantedFolderEnabled(m_ui
->checkUnwantedFolder
->isChecked());
741 pref
->setRecursiveDownloadEnabled(m_ui
->checkRecursiveDownload
->isChecked());
743 session
->setAutoTMMDisabledByDefault(m_ui
->comboSavingMode
->currentIndex() == 0);
744 session
->setDisableAutoTMMWhenCategoryChanged(m_ui
->comboTorrentCategoryChanged
->currentIndex() == 1);
745 session
->setDisableAutoTMMWhenCategorySavePathChanged(m_ui
->comboCategoryChanged
->currentIndex() == 1);
746 session
->setDisableAutoTMMWhenDefaultSavePathChanged(m_ui
->comboCategoryDefaultPathChanged
->currentIndex() == 1);
748 session
->setSubcategoriesEnabled(m_ui
->checkUseSubcategories
->isChecked());
749 session
->setUseCategoryPathsInManualMode(m_ui
->checkUseCategoryPaths
->isChecked());
751 session
->setSavePath(Path(m_ui
->textSavePath
->selectedPath()));
752 session
->setDownloadPathEnabled(m_ui
->checkUseDownloadPath
->isChecked());
753 session
->setDownloadPath(m_ui
->textDownloadPath
->selectedPath());
754 session
->setTorrentExportDirectory(getTorrentExportDir());
755 session
->setFinishedTorrentExportDirectory(getFinishedTorrentExportDir());
757 auto *watchedFoldersModel
= static_cast<WatchedFoldersModel
*>(m_ui
->scanFoldersView
->model());
758 watchedFoldersModel
->apply();
760 session
->setExcludedFileNamesEnabled(m_ui
->groupExcludedFileNames
->isChecked());
761 session
->setExcludedFileNames(m_ui
->textExcludedFileNames
->toPlainText().split(u
'\n', Qt::SkipEmptyParts
));
763 pref
->setMailNotificationEnabled(m_ui
->groupMailNotification
->isChecked());
764 pref
->setMailNotificationSender(m_ui
->senderEmailTxt
->text());
765 pref
->setMailNotificationEmail(m_ui
->lineEditDestEmail
->text());
766 pref
->setMailNotificationSMTP(m_ui
->lineEditSmtpServer
->text());
767 pref
->setMailNotificationSMTPSSL(m_ui
->checkSmtpSSL
->isChecked());
768 pref
->setMailNotificationSMTPAuth(m_ui
->groupMailNotifAuth
->isChecked());
769 pref
->setMailNotificationSMTPUsername(m_ui
->mailNotifUsername
->text());
770 pref
->setMailNotificationSMTPPassword(m_ui
->mailNotifPassword
->text());
772 pref
->setAutoRunOnTorrentAddedEnabled(m_ui
->groupBoxRunOnAdded
->isChecked());
773 pref
->setAutoRunOnTorrentAddedProgram(m_ui
->lineEditRunOnAdded
->text().trimmed());
774 pref
->setAutoRunOnTorrentFinishedEnabled(m_ui
->groupBoxRunOnFinished
->isChecked());
775 pref
->setAutoRunOnTorrentFinishedProgram(m_ui
->lineEditRunOnFinished
->text().trimmed());
776 #if defined(Q_OS_WIN)
777 pref
->setAutoRunConsoleEnabled(m_ui
->autoRunConsole
->isChecked());
781 void OptionsDialog::loadConnectionTabOptions()
783 const auto *session
= BitTorrent::Session::instance();
785 m_ui
->comboProtocol
->setCurrentIndex(static_cast<int>(session
->btProtocol()));
786 m_ui
->spinPort
->setValue(session
->port());
787 m_ui
->checkUPnP
->setChecked(Net::PortForwarder::instance()->isEnabled());
789 int intValue
= session
->maxConnections();
793 m_ui
->checkMaxConnections
->setChecked(true);
794 m_ui
->spinMaxConnec
->setEnabled(true);
795 m_ui
->spinMaxConnec
->setValue(intValue
);
800 m_ui
->checkMaxConnections
->setChecked(false);
801 m_ui
->spinMaxConnec
->setEnabled(false);
803 intValue
= session
->maxConnectionsPerTorrent();
807 m_ui
->checkMaxConnectionsPerTorrent
->setChecked(true);
808 m_ui
->spinMaxConnecPerTorrent
->setEnabled(true);
809 m_ui
->spinMaxConnecPerTorrent
->setValue(intValue
);
814 m_ui
->checkMaxConnectionsPerTorrent
->setChecked(false);
815 m_ui
->spinMaxConnecPerTorrent
->setEnabled(false);
817 intValue
= session
->maxUploads();
821 m_ui
->checkMaxUploads
->setChecked(true);
822 m_ui
->spinMaxUploads
->setEnabled(true);
823 m_ui
->spinMaxUploads
->setValue(intValue
);
828 m_ui
->checkMaxUploads
->setChecked(false);
829 m_ui
->spinMaxUploads
->setEnabled(false);
831 intValue
= session
->maxUploadsPerTorrent();
835 m_ui
->checkMaxUploadsPerTorrent
->setChecked(true);
836 m_ui
->spinMaxUploadsPerTorrent
->setEnabled(true);
837 m_ui
->spinMaxUploadsPerTorrent
->setValue(intValue
);
842 m_ui
->checkMaxUploadsPerTorrent
->setChecked(false);
843 m_ui
->spinMaxUploadsPerTorrent
->setEnabled(false);
846 #if defined(QBT_USES_LIBTORRENT2) && TORRENT_USE_I2P
847 m_ui
->textI2PHost
->setText(session
->I2PAddress());
848 m_ui
->spinI2PPort
->setValue(session
->I2PPort());
849 m_ui
->checkI2PMixed
->setChecked(session
->I2PMixedMode());
850 m_ui
->groupI2P
->setChecked(session
->isI2PEnabled());
852 m_ui
->groupI2P
->hide();
855 const auto *proxyConfigManager
= Net::ProxyConfigurationManager::instance();
856 const Net::ProxyConfiguration proxyConf
= proxyConfigManager
->proxyConfiguration();
858 m_ui
->comboProxyType
->addItem(tr("(None)"), QVariant::fromValue(Net::ProxyType::None
));
859 m_ui
->comboProxyType
->addItem(tr("SOCKS4"), QVariant::fromValue(Net::ProxyType::SOCKS4
));
860 m_ui
->comboProxyType
->addItem(tr("SOCKS5"), QVariant::fromValue(Net::ProxyType::SOCKS5
));
861 m_ui
->comboProxyType
->addItem(tr("HTTP"), QVariant::fromValue(Net::ProxyType::HTTP
));
862 m_ui
->comboProxyType
->setCurrentIndex(m_ui
->comboProxyType
->findData(QVariant::fromValue(proxyConf
.type
)));
863 adjustProxyOptions();
865 m_ui
->textProxyIP
->setText(proxyConf
.ip
);
866 m_ui
->spinProxyPort
->setValue(proxyConf
.port
);
867 m_ui
->textProxyUsername
->setText(proxyConf
.username
);
868 m_ui
->textProxyPassword
->setText(proxyConf
.password
);
869 m_ui
->checkProxyAuth
->setChecked(proxyConf
.authEnabled
);
870 m_ui
->checkProxyHostnameLookup
->setChecked(proxyConf
.hostnameLookupEnabled
);
872 m_ui
->checkProxyPeerConnections
->setChecked(session
->isProxyPeerConnectionsEnabled());
873 m_ui
->checkProxyBitTorrent
->setChecked(Preferences::instance()->useProxyForBT());
874 m_ui
->checkProxyRSS
->setChecked(Preferences::instance()->useProxyForRSS());
875 m_ui
->checkProxyMisc
->setChecked(Preferences::instance()->useProxyForGeneralPurposes());
877 m_ui
->checkIPFilter
->setChecked(session
->isIPFilteringEnabled());
878 m_ui
->textFilterPath
->setDialogCaption(tr("Choose an IP filter file"));
879 m_ui
->textFilterPath
->setEnabled(m_ui
->checkIPFilter
->isChecked());
880 m_ui
->textFilterPath
->setFileNameFilter(tr("All supported filters") + u
" (*.dat *.p2p *.p2b);;.dat (*.dat);;.p2p (*.p2p);;.p2b (*.p2b)");
881 m_ui
->textFilterPath
->setSelectedPath(session
->IPFilterFile());
883 m_ui
->IpFilterRefreshBtn
->setIcon(UIThemeManager::instance()->getIcon(u
"view-refresh"_s
));
884 m_ui
->IpFilterRefreshBtn
->setEnabled(m_ui
->checkIPFilter
->isChecked());
885 m_ui
->checkIpFilterTrackers
->setChecked(session
->isTrackerFilteringEnabled());
887 connect(m_ui
->comboProtocol
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
888 connect(m_ui
->spinPort
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
889 connect(m_ui
->checkUPnP
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
891 connect(m_ui
->checkMaxConnections
, &QAbstractButton::toggled
, m_ui
->spinMaxConnec
, &QWidget::setEnabled
);
892 connect(m_ui
->checkMaxConnections
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
893 connect(m_ui
->checkMaxConnectionsPerTorrent
, &QAbstractButton::toggled
, m_ui
->spinMaxConnecPerTorrent
, &QWidget::setEnabled
);
894 connect(m_ui
->checkMaxConnectionsPerTorrent
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
895 connect(m_ui
->checkMaxUploads
, &QAbstractButton::toggled
, m_ui
->spinMaxUploads
, &QWidget::setEnabled
);
896 connect(m_ui
->checkMaxUploads
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
897 connect(m_ui
->checkMaxUploadsPerTorrent
, &QAbstractButton::toggled
, m_ui
->spinMaxUploadsPerTorrent
, &QWidget::setEnabled
);
898 connect(m_ui
->checkMaxUploadsPerTorrent
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
899 connect(m_ui
->spinMaxConnec
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
900 connect(m_ui
->spinMaxConnecPerTorrent
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
901 connect(m_ui
->spinMaxUploads
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
902 connect(m_ui
->spinMaxUploadsPerTorrent
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
904 connect(m_ui
->comboProxyType
, qComboBoxCurrentIndexChanged
, this, &ThisType::adjustProxyOptions
);
905 connect(m_ui
->comboProxyType
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
906 connect(m_ui
->textProxyIP
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
907 connect(m_ui
->spinProxyPort
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
909 #if defined(QBT_USES_LIBTORRENT2) && TORRENT_USE_I2P
910 connect(m_ui
->textI2PHost
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
911 connect(m_ui
->spinI2PPort
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
912 connect(m_ui
->checkI2PMixed
, &QCheckBox::toggled
, this, &ThisType::enableApplyButton
);
913 connect(m_ui
->groupI2P
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
916 connect(m_ui
->checkProxyBitTorrent
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
917 connect(m_ui
->checkProxyBitTorrent
, &QGroupBox::toggled
, this, &ThisType::adjustProxyOptions
);
918 connect(m_ui
->checkProxyPeerConnections
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
919 connect(m_ui
->checkProxyHostnameLookup
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
920 connect(m_ui
->checkProxyRSS
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
921 connect(m_ui
->checkProxyMisc
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
923 connect(m_ui
->checkProxyAuth
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
924 connect(m_ui
->textProxyUsername
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
925 connect(m_ui
->textProxyPassword
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
927 connect(m_ui
->checkIPFilter
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
928 connect(m_ui
->checkIPFilter
, &QAbstractButton::toggled
, m_ui
->textFilterPath
, &QWidget::setEnabled
);
929 connect(m_ui
->checkIPFilter
, &QAbstractButton::toggled
, m_ui
->IpFilterRefreshBtn
, &QWidget::setEnabled
);
930 connect(m_ui
->textFilterPath
, &FileSystemPathEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
931 connect(m_ui
->checkIpFilterTrackers
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
934 void OptionsDialog::saveConnectionTabOptions() const
936 auto *session
= BitTorrent::Session::instance();
938 session
->setBTProtocol(static_cast<BitTorrent::BTProtocol
>(m_ui
->comboProtocol
->currentIndex()));
939 session
->setPort(getPort());
940 Net::PortForwarder::instance()->setEnabled(isUPnPEnabled());
942 session
->setMaxConnections(getMaxConnections());
943 session
->setMaxConnectionsPerTorrent(getMaxConnectionsPerTorrent());
944 session
->setMaxUploads(getMaxUploads());
945 session
->setMaxUploadsPerTorrent(getMaxUploadsPerTorrent());
947 #if defined(QBT_USES_LIBTORRENT2) && TORRENT_USE_I2P
948 session
->setI2PEnabled(m_ui
->groupI2P
->isChecked());
949 session
->setI2PAddress(m_ui
->textI2PHost
->text().trimmed());
950 session
->setI2PPort(m_ui
->spinI2PPort
->value());
951 session
->setI2PMixedMode(m_ui
->checkI2PMixed
->isChecked());
954 auto *proxyConfigManager
= Net::ProxyConfigurationManager::instance();
955 Net::ProxyConfiguration proxyConf
;
956 proxyConf
.type
= getProxyType();
957 proxyConf
.ip
= getProxyIp();
958 proxyConf
.port
= getProxyPort();
959 proxyConf
.authEnabled
= m_ui
->checkProxyAuth
->isChecked();
960 proxyConf
.username
= getProxyUsername();
961 proxyConf
.password
= getProxyPassword();
962 proxyConf
.hostnameLookupEnabled
= m_ui
->checkProxyHostnameLookup
->isChecked();
963 proxyConfigManager
->setProxyConfiguration(proxyConf
);
965 Preferences::instance()->setUseProxyForBT(m_ui
->checkProxyBitTorrent
->isChecked());
966 Preferences::instance()->setUseProxyForRSS(m_ui
->checkProxyRSS
->isChecked());
967 Preferences::instance()->setUseProxyForGeneralPurposes(m_ui
->checkProxyMisc
->isChecked());
969 session
->setProxyPeerConnectionsEnabled(m_ui
->checkProxyPeerConnections
->isChecked());
972 session
->setIPFilteringEnabled(isIPFilteringEnabled());
973 session
->setTrackerFilteringEnabled(m_ui
->checkIpFilterTrackers
->isChecked());
974 session
->setIPFilterFile(m_ui
->textFilterPath
->selectedPath());
977 void OptionsDialog::loadSpeedTabOptions()
979 const auto *pref
= Preferences::instance();
980 const auto *session
= BitTorrent::Session::instance();
982 m_ui
->labelGlobalRate
->setPixmap(UIThemeManager::instance()->getScaledPixmap(u
"slow_off"_s
, Utils::Gui::mediumIconSize(this).height()));
983 m_ui
->spinUploadLimit
->setValue(session
->globalUploadSpeedLimit() / 1024);
984 m_ui
->spinDownloadLimit
->setValue(session
->globalDownloadSpeedLimit() / 1024);
986 m_ui
->labelAltRate
->setPixmap(UIThemeManager::instance()->getScaledPixmap(u
"slow"_s
, Utils::Gui::mediumIconSize(this).height()));
987 m_ui
->spinUploadLimitAlt
->setValue(session
->altGlobalUploadSpeedLimit() / 1024);
988 m_ui
->spinDownloadLimitAlt
->setValue(session
->altGlobalDownloadSpeedLimit() / 1024);
990 m_ui
->comboBoxScheduleDays
->addItems(translatedWeekdayNames());
992 m_ui
->groupBoxSchedule
->setChecked(session
->isBandwidthSchedulerEnabled());
993 m_ui
->timeEditScheduleFrom
->setTime(pref
->getSchedulerStartTime());
994 m_ui
->timeEditScheduleTo
->setTime(pref
->getSchedulerEndTime());
995 m_ui
->comboBoxScheduleDays
->setCurrentIndex(static_cast<int>(pref
->getSchedulerDays()));
997 m_ui
->checkLimituTPConnections
->setChecked(session
->isUTPRateLimited());
998 m_ui
->checkLimitTransportOverhead
->setChecked(session
->includeOverheadInLimits());
999 m_ui
->checkLimitLocalPeerRate
->setChecked(!session
->ignoreLimitsOnLAN());
1001 connect(m_ui
->spinUploadLimit
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1002 connect(m_ui
->spinDownloadLimit
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1004 connect(m_ui
->spinUploadLimitAlt
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1005 connect(m_ui
->spinDownloadLimitAlt
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1007 connect(m_ui
->groupBoxSchedule
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1008 connect(m_ui
->timeEditScheduleFrom
, &QDateTimeEdit::timeChanged
, this, &ThisType::enableApplyButton
);
1009 connect(m_ui
->timeEditScheduleTo
, &QDateTimeEdit::timeChanged
, this, &ThisType::enableApplyButton
);
1010 connect(m_ui
->comboBoxScheduleDays
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
1012 connect(m_ui
->checkLimituTPConnections
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1013 connect(m_ui
->checkLimitTransportOverhead
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1014 connect(m_ui
->checkLimitLocalPeerRate
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1017 void OptionsDialog::saveSpeedTabOptions() const
1019 auto *pref
= Preferences::instance();
1020 auto *session
= BitTorrent::Session::instance();
1022 session
->setGlobalUploadSpeedLimit(m_ui
->spinUploadLimit
->value() * 1024);
1023 session
->setGlobalDownloadSpeedLimit(m_ui
->spinDownloadLimit
->value() * 1024);
1025 session
->setAltGlobalUploadSpeedLimit(m_ui
->spinUploadLimitAlt
->value() * 1024);
1026 session
->setAltGlobalDownloadSpeedLimit(m_ui
->spinDownloadLimitAlt
->value() * 1024);
1028 session
->setBandwidthSchedulerEnabled(m_ui
->groupBoxSchedule
->isChecked());
1029 pref
->setSchedulerStartTime(m_ui
->timeEditScheduleFrom
->time());
1030 pref
->setSchedulerEndTime(m_ui
->timeEditScheduleTo
->time());
1031 pref
->setSchedulerDays(static_cast<Scheduler::Days
>(m_ui
->comboBoxScheduleDays
->currentIndex()));
1033 session
->setUTPRateLimited(m_ui
->checkLimituTPConnections
->isChecked());
1034 session
->setIncludeOverheadInLimits(m_ui
->checkLimitTransportOverhead
->isChecked());
1035 session
->setIgnoreLimitsOnLAN(!m_ui
->checkLimitLocalPeerRate
->isChecked());
1038 void OptionsDialog::loadBittorrentTabOptions()
1040 const auto *session
= BitTorrent::Session::instance();
1042 m_ui
->checkDHT
->setChecked(session
->isDHTEnabled());
1043 m_ui
->checkPeX
->setChecked(session
->isPeXEnabled());
1044 m_ui
->checkLSD
->setChecked(session
->isLSDEnabled());
1045 m_ui
->comboEncryption
->setCurrentIndex(session
->encryption());
1046 m_ui
->checkAnonymousMode
->setChecked(session
->isAnonymousModeEnabled());
1048 m_ui
->spinBoxMaxActiveCheckingTorrents
->setValue(session
->maxActiveCheckingTorrents());
1050 m_ui
->checkEnableQueueing
->setChecked(session
->isQueueingSystemEnabled());
1051 m_ui
->spinMaxActiveDownloads
->setValue(session
->maxActiveDownloads());
1052 m_ui
->spinMaxActiveUploads
->setValue(session
->maxActiveUploads());
1053 m_ui
->spinMaxActiveTorrents
->setValue(session
->maxActiveTorrents());
1055 m_ui
->checkIgnoreSlowTorrentsForQueueing
->setChecked(session
->ignoreSlowTorrentsForQueueing());
1056 const QString slowTorrentsExplanation
= u
"<html><body><p>"
1057 + tr("A torrent will be considered slow if its download and upload rates stay below these values for \"Torrent inactivity timer\" seconds")
1058 + u
"</p></body></html>";
1059 m_ui
->labelDownloadRateForSlowTorrents
->setToolTip(slowTorrentsExplanation
);
1060 m_ui
->labelUploadRateForSlowTorrents
->setToolTip(slowTorrentsExplanation
);
1061 m_ui
->labelSlowTorrentInactivityTimer
->setToolTip(slowTorrentsExplanation
);
1062 m_ui
->spinDownloadRateForSlowTorrents
->setValue(session
->downloadRateForSlowTorrents());
1063 m_ui
->spinUploadRateForSlowTorrents
->setValue(session
->uploadRateForSlowTorrents());
1064 m_ui
->spinSlowTorrentsInactivityTimer
->setValue(session
->slowTorrentsInactivityTimer());
1066 if (session
->globalMaxRatio() >= 0.)
1069 m_ui
->checkMaxRatio
->setChecked(true);
1070 m_ui
->spinMaxRatio
->setEnabled(true);
1071 m_ui
->comboRatioLimitAct
->setEnabled(true);
1072 m_ui
->spinMaxRatio
->setValue(session
->globalMaxRatio());
1077 m_ui
->checkMaxRatio
->setChecked(false);
1078 m_ui
->spinMaxRatio
->setEnabled(false);
1080 if (session
->globalMaxSeedingMinutes() >= 0)
1083 m_ui
->checkMaxSeedingMinutes
->setChecked(true);
1084 m_ui
->spinMaxSeedingMinutes
->setEnabled(true);
1085 m_ui
->spinMaxSeedingMinutes
->setValue(session
->globalMaxSeedingMinutes());
1090 m_ui
->checkMaxSeedingMinutes
->setChecked(false);
1091 m_ui
->spinMaxSeedingMinutes
->setEnabled(false);
1093 if (session
->globalMaxInactiveSeedingMinutes() >= 0)
1096 m_ui
->checkMaxInactiveSeedingMinutes
->setChecked(true);
1097 m_ui
->spinMaxInactiveSeedingMinutes
->setEnabled(true);
1098 m_ui
->spinMaxInactiveSeedingMinutes
->setValue(session
->globalMaxInactiveSeedingMinutes());
1103 m_ui
->checkMaxInactiveSeedingMinutes
->setChecked(false);
1104 m_ui
->spinMaxInactiveSeedingMinutes
->setEnabled(false);
1106 m_ui
->comboRatioLimitAct
->setEnabled((session
->globalMaxSeedingMinutes() >= 0) || (session
->globalMaxRatio() >= 0.) || (session
->globalMaxInactiveSeedingMinutes() >= 0));
1108 const QHash
<MaxRatioAction
, int> actIndex
=
1113 {EnableSuperSeeding
, 3}
1115 m_ui
->comboRatioLimitAct
->setCurrentIndex(actIndex
.value(session
->maxRatioAction()));
1117 m_ui
->checkEnableAddTrackers
->setChecked(session
->isAddTrackersEnabled());
1118 m_ui
->textTrackers
->setPlainText(session
->additionalTrackers());
1120 connect(m_ui
->checkDHT
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1121 connect(m_ui
->checkPeX
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1122 connect(m_ui
->checkLSD
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1123 connect(m_ui
->comboEncryption
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
1124 connect(m_ui
->checkAnonymousMode
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1126 connect(m_ui
->spinBoxMaxActiveCheckingTorrents
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1128 connect(m_ui
->checkEnableQueueing
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1129 connect(m_ui
->spinMaxActiveDownloads
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1130 connect(m_ui
->spinMaxActiveUploads
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1131 connect(m_ui
->spinMaxActiveTorrents
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1132 connect(m_ui
->checkIgnoreSlowTorrentsForQueueing
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1133 connect(m_ui
->spinDownloadRateForSlowTorrents
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1134 connect(m_ui
->spinUploadRateForSlowTorrents
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1135 connect(m_ui
->spinSlowTorrentsInactivityTimer
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1137 connect(m_ui
->checkMaxRatio
, &QAbstractButton::toggled
, m_ui
->spinMaxRatio
, &QWidget::setEnabled
);
1138 connect(m_ui
->checkMaxRatio
, &QAbstractButton::toggled
, this, &ThisType::toggleComboRatioLimitAct
);
1139 connect(m_ui
->checkMaxRatio
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1140 connect(m_ui
->spinMaxRatio
, qOverload
<double>(&QDoubleSpinBox::valueChanged
),this, &ThisType::enableApplyButton
);
1141 connect(m_ui
->comboRatioLimitAct
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
1142 connect(m_ui
->checkMaxSeedingMinutes
, &QAbstractButton::toggled
, m_ui
->spinMaxSeedingMinutes
, &QWidget::setEnabled
);
1143 connect(m_ui
->checkMaxSeedingMinutes
, &QAbstractButton::toggled
, this, &ThisType::toggleComboRatioLimitAct
);
1144 connect(m_ui
->checkMaxSeedingMinutes
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1145 connect(m_ui
->spinMaxSeedingMinutes
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1146 connect(m_ui
->checkMaxInactiveSeedingMinutes
, &QAbstractButton::toggled
, m_ui
->spinMaxInactiveSeedingMinutes
, &QWidget::setEnabled
);
1147 connect(m_ui
->checkMaxInactiveSeedingMinutes
, &QAbstractButton::toggled
, this, &ThisType::toggleComboRatioLimitAct
);
1148 connect(m_ui
->checkMaxInactiveSeedingMinutes
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1149 connect(m_ui
->spinMaxInactiveSeedingMinutes
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1151 connect(m_ui
->checkEnableAddTrackers
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1152 connect(m_ui
->textTrackers
, &QPlainTextEdit::textChanged
, this, &ThisType::enableApplyButton
);
1155 void OptionsDialog::saveBittorrentTabOptions() const
1157 auto *session
= BitTorrent::Session::instance();
1159 session
->setDHTEnabled(isDHTEnabled());
1160 session
->setPeXEnabled(m_ui
->checkPeX
->isChecked());
1161 session
->setLSDEnabled(isLSDEnabled());
1162 session
->setEncryption(getEncryptionSetting());
1163 session
->setAnonymousModeEnabled(m_ui
->checkAnonymousMode
->isChecked());
1165 session
->setMaxActiveCheckingTorrents(m_ui
->spinBoxMaxActiveCheckingTorrents
->value());
1167 session
->setQueueingSystemEnabled(isQueueingSystemEnabled());
1168 session
->setMaxActiveDownloads(m_ui
->spinMaxActiveDownloads
->value());
1169 session
->setMaxActiveUploads(m_ui
->spinMaxActiveUploads
->value());
1170 session
->setMaxActiveTorrents(m_ui
->spinMaxActiveTorrents
->value());
1171 session
->setIgnoreSlowTorrentsForQueueing(m_ui
->checkIgnoreSlowTorrentsForQueueing
->isChecked());
1172 session
->setDownloadRateForSlowTorrents(m_ui
->spinDownloadRateForSlowTorrents
->value());
1173 session
->setUploadRateForSlowTorrents(m_ui
->spinUploadRateForSlowTorrents
->value());
1174 session
->setSlowTorrentsInactivityTimer(m_ui
->spinSlowTorrentsInactivityTimer
->value());
1176 session
->setGlobalMaxRatio(getMaxRatio());
1177 session
->setGlobalMaxSeedingMinutes(getMaxSeedingMinutes());
1178 session
->setGlobalMaxInactiveSeedingMinutes(getMaxInactiveSeedingMinutes());
1179 const QVector
<MaxRatioAction
> actIndex
=
1186 session
->setMaxRatioAction(actIndex
.value(m_ui
->comboRatioLimitAct
->currentIndex()));
1188 session
->setAddTrackersEnabled(m_ui
->checkEnableAddTrackers
->isChecked());
1189 session
->setAdditionalTrackers(m_ui
->textTrackers
->toPlainText());
1192 void OptionsDialog::loadRSSTabOptions()
1194 const auto *rssSession
= RSS::Session::instance();
1195 const auto *autoDownloader
= RSS::AutoDownloader::instance();
1197 m_ui
->checkRSSEnable
->setChecked(rssSession
->isProcessingEnabled());
1198 m_ui
->spinRSSRefreshInterval
->setValue(rssSession
->refreshInterval());
1199 m_ui
->spinRSSFetchDelay
->setValue(rssSession
->fetchDelay().count());
1200 m_ui
->spinRSSMaxArticlesPerFeed
->setValue(rssSession
->maxArticlesPerFeed());
1201 m_ui
->checkRSSAutoDownloaderEnable
->setChecked(autoDownloader
->isProcessingEnabled());
1202 m_ui
->textSmartEpisodeFilters
->setPlainText(autoDownloader
->smartEpisodeFilters().join(u
'\n'));
1203 m_ui
->checkSmartFilterDownloadRepacks
->setChecked(autoDownloader
->downloadRepacks());
1205 connect(m_ui
->checkRSSEnable
, &QCheckBox::toggled
, this, &OptionsDialog::enableApplyButton
);
1206 connect(m_ui
->checkRSSAutoDownloaderEnable
, &QCheckBox::toggled
, this, &OptionsDialog::enableApplyButton
);
1207 connect(m_ui
->btnEditRules
, &QPushButton::clicked
, this, [this]()
1209 auto *downloader
= new AutomatedRssDownloader(this);
1210 downloader
->setAttribute(Qt::WA_DeleteOnClose
);
1213 connect(m_ui
->textSmartEpisodeFilters
, &QPlainTextEdit::textChanged
, this, &OptionsDialog::enableApplyButton
);
1214 connect(m_ui
->checkSmartFilterDownloadRepacks
, &QCheckBox::toggled
, this, &OptionsDialog::enableApplyButton
);
1215 connect(m_ui
->spinRSSRefreshInterval
, qSpinBoxValueChanged
, this, &OptionsDialog::enableApplyButton
);
1216 connect(m_ui
->spinRSSFetchDelay
, qSpinBoxValueChanged
, this, &OptionsDialog::enableApplyButton
);
1217 connect(m_ui
->spinRSSMaxArticlesPerFeed
, qSpinBoxValueChanged
, this, &OptionsDialog::enableApplyButton
);
1220 void OptionsDialog::saveRSSTabOptions() const
1222 auto *rssSession
= RSS::Session::instance();
1223 auto *autoDownloader
= RSS::AutoDownloader::instance();
1225 rssSession
->setProcessingEnabled(m_ui
->checkRSSEnable
->isChecked());
1226 rssSession
->setRefreshInterval(m_ui
->spinRSSRefreshInterval
->value());
1227 rssSession
->setFetchDelay(std::chrono::seconds(m_ui
->spinRSSFetchDelay
->value()));
1228 rssSession
->setMaxArticlesPerFeed(m_ui
->spinRSSMaxArticlesPerFeed
->value());
1229 autoDownloader
->setProcessingEnabled(m_ui
->checkRSSAutoDownloaderEnable
->isChecked());
1230 autoDownloader
->setSmartEpisodeFilters(m_ui
->textSmartEpisodeFilters
->toPlainText().split(u
'\n', Qt::SkipEmptyParts
));
1231 autoDownloader
->setDownloadRepacks(m_ui
->checkSmartFilterDownloadRepacks
->isChecked());
1234 #ifndef DISABLE_WEBUI
1235 void OptionsDialog::loadWebUITabOptions()
1237 const auto *pref
= Preferences::instance();
1239 m_ui
->textWebUIHttpsCert
->setMode(FileSystemPathEdit::Mode::FileOpen
);
1240 m_ui
->textWebUIHttpsCert
->setFileNameFilter(tr("Certificate") + u
" (*.cer *.crt *.pem)");
1241 m_ui
->textWebUIHttpsCert
->setDialogCaption(tr("Select certificate"));
1242 m_ui
->textWebUIHttpsKey
->setMode(FileSystemPathEdit::Mode::FileOpen
);
1243 m_ui
->textWebUIHttpsKey
->setFileNameFilter(tr("Private key") + u
" (*.key *.pem)");
1244 m_ui
->textWebUIHttpsKey
->setDialogCaption(tr("Select private key"));
1245 m_ui
->textWebUIRootFolder
->setMode(FileSystemPathEdit::Mode::DirectoryOpen
);
1246 m_ui
->textWebUIRootFolder
->setDialogCaption(tr("Choose Alternative UI files location"));
1248 if (app()->webUI()->isErrored())
1249 m_ui
->labelWebUIError
->setText(tr("WebUI configuration failed. Reason: %1").arg(app()->webUI()->errorMessage()));
1251 m_ui
->labelWebUIError
->hide();
1253 m_ui
->checkWebUI
->setChecked(pref
->isWebUIEnabled());
1254 m_ui
->textWebUIAddress
->setText(pref
->getWebUIAddress());
1255 m_ui
->spinWebUIPort
->setValue(pref
->getWebUIPort());
1256 m_ui
->checkWebUIUPnP
->setChecked(pref
->useUPnPForWebUIPort());
1257 m_ui
->checkWebUIHttps
->setChecked(pref
->isWebUIHttpsEnabled());
1258 webUIHttpsCertChanged(pref
->getWebUIHttpsCertificatePath());
1259 webUIHttpsKeyChanged(pref
->getWebUIHttpsKeyPath());
1260 m_ui
->textWebUIUsername
->setText(pref
->getWebUIUsername());
1261 m_ui
->checkBypassLocalAuth
->setChecked(!pref
->isWebUILocalAuthEnabled());
1262 m_ui
->checkBypassAuthSubnetWhitelist
->setChecked(pref
->isWebUIAuthSubnetWhitelistEnabled());
1263 m_ui
->IPSubnetWhitelistButton
->setEnabled(m_ui
->checkBypassAuthSubnetWhitelist
->isChecked());
1264 m_ui
->spinBanCounter
->setValue(pref
->getWebUIMaxAuthFailCount());
1265 m_ui
->spinBanDuration
->setValue(pref
->getWebUIBanDuration().count());
1266 m_ui
->spinSessionTimeout
->setValue(pref
->getWebUISessionTimeout());
1268 m_ui
->groupAltWebUI
->setChecked(pref
->isAltWebUIEnabled());
1269 m_ui
->textWebUIRootFolder
->setSelectedPath(pref
->getWebUIRootFolder());
1271 m_ui
->checkClickjacking
->setChecked(pref
->isWebUIClickjackingProtectionEnabled());
1272 m_ui
->checkCSRFProtection
->setChecked(pref
->isWebUICSRFProtectionEnabled());
1273 m_ui
->checkSecureCookie
->setEnabled(pref
->isWebUIHttpsEnabled());
1274 m_ui
->checkSecureCookie
->setChecked(pref
->isWebUISecureCookieEnabled());
1275 m_ui
->groupHostHeaderValidation
->setChecked(pref
->isWebUIHostHeaderValidationEnabled());
1276 m_ui
->textServerDomains
->setText(pref
->getServerDomains());
1277 // Custom HTTP headers
1278 m_ui
->groupWebUIAddCustomHTTPHeaders
->setChecked(pref
->isWebUICustomHTTPHeadersEnabled());
1279 m_ui
->textWebUICustomHTTPHeaders
->setPlainText(pref
->getWebUICustomHTTPHeaders());
1281 m_ui
->groupEnableReverseProxySupport
->setChecked(pref
->isWebUIReverseProxySupportEnabled());
1282 m_ui
->textTrustedReverseProxiesList
->setText(pref
->getWebUITrustedReverseProxiesList());
1284 m_ui
->checkDynDNS
->setChecked(pref
->isDynDNSEnabled());
1285 m_ui
->comboDNSService
->setCurrentIndex(static_cast<int>(pref
->getDynDNSService()));
1286 m_ui
->domainNameTxt
->setText(pref
->getDynDomainName());
1287 m_ui
->DNSUsernameTxt
->setText(pref
->getDynDNSUsername());
1288 m_ui
->DNSPasswordTxt
->setText(pref
->getDynDNSPassword());
1290 connect(m_ui
->checkWebUI
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1291 connect(m_ui
->textWebUIAddress
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
1292 connect(m_ui
->spinWebUIPort
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1293 connect(m_ui
->checkWebUIUPnP
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1294 connect(m_ui
->checkWebUIHttps
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1295 connect(m_ui
->textWebUIHttpsCert
, &FileSystemPathLineEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
1296 connect(m_ui
->textWebUIHttpsCert
, &FileSystemPathLineEdit::selectedPathChanged
, this, &OptionsDialog::webUIHttpsCertChanged
);
1297 connect(m_ui
->textWebUIHttpsKey
, &FileSystemPathLineEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
1298 connect(m_ui
->textWebUIHttpsKey
, &FileSystemPathLineEdit::selectedPathChanged
, this, &OptionsDialog::webUIHttpsKeyChanged
);
1300 connect(m_ui
->textWebUIUsername
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
1301 connect(m_ui
->textWebUIPassword
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
1303 connect(m_ui
->checkBypassLocalAuth
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1304 connect(m_ui
->checkBypassAuthSubnetWhitelist
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1305 connect(m_ui
->checkBypassAuthSubnetWhitelist
, &QAbstractButton::toggled
, m_ui
->IPSubnetWhitelistButton
, &QWidget::setEnabled
);
1306 connect(m_ui
->spinBanCounter
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1307 connect(m_ui
->spinBanDuration
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1308 connect(m_ui
->spinSessionTimeout
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1310 connect(m_ui
->groupAltWebUI
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1311 connect(m_ui
->textWebUIRootFolder
, &FileSystemPathLineEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
1313 connect(m_ui
->checkClickjacking
, &QCheckBox::toggled
, this, &ThisType::enableApplyButton
);
1314 connect(m_ui
->checkCSRFProtection
, &QCheckBox::toggled
, this, &ThisType::enableApplyButton
);
1315 connect(m_ui
->checkWebUIHttps
, &QGroupBox::toggled
, m_ui
->checkSecureCookie
, &QWidget::setEnabled
);
1316 connect(m_ui
->checkSecureCookie
, &QCheckBox::toggled
, this, &ThisType::enableApplyButton
);
1317 connect(m_ui
->groupHostHeaderValidation
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1318 connect(m_ui
->textServerDomains
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
1320 connect(m_ui
->groupWebUIAddCustomHTTPHeaders
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1321 connect(m_ui
->textWebUICustomHTTPHeaders
, &QPlainTextEdit::textChanged
, this, &OptionsDialog::enableApplyButton
);
1323 connect(m_ui
->groupEnableReverseProxySupport
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1324 connect(m_ui
->textTrustedReverseProxiesList
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
1326 connect(m_ui
->checkDynDNS
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1327 connect(m_ui
->comboDNSService
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
1328 connect(m_ui
->domainNameTxt
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
1329 connect(m_ui
->DNSUsernameTxt
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
1330 connect(m_ui
->DNSPasswordTxt
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
1333 void OptionsDialog::saveWebUITabOptions() const
1335 auto *pref
= Preferences::instance();
1337 const bool webUIEnabled
= isWebUIEnabled();
1339 pref
->setWebUIEnabled(webUIEnabled
);
1340 pref
->setWebUIAddress(m_ui
->textWebUIAddress
->text());
1341 pref
->setWebUIPort(m_ui
->spinWebUIPort
->value());
1342 pref
->setUPnPForWebUIPort(m_ui
->checkWebUIUPnP
->isChecked());
1343 pref
->setWebUIHttpsEnabled(m_ui
->checkWebUIHttps
->isChecked());
1344 pref
->setWebUIHttpsCertificatePath(m_ui
->textWebUIHttpsCert
->selectedPath());
1345 pref
->setWebUIHttpsKeyPath(m_ui
->textWebUIHttpsKey
->selectedPath());
1346 pref
->setWebUIMaxAuthFailCount(m_ui
->spinBanCounter
->value());
1347 pref
->setWebUIBanDuration(std::chrono::seconds
{m_ui
->spinBanDuration
->value()});
1348 pref
->setWebUISessionTimeout(m_ui
->spinSessionTimeout
->value());
1350 if (const QString username
= webUIUsername(); isValidWebUIUsername(username
))
1351 pref
->setWebUIUsername(username
);
1352 if (const QString password
= webUIPassword(); isValidWebUIPassword(password
))
1353 pref
->setWebUIPassword(Utils::Password::PBKDF2::generate(password
));
1354 pref
->setWebUILocalAuthEnabled(!m_ui
->checkBypassLocalAuth
->isChecked());
1355 pref
->setWebUIAuthSubnetWhitelistEnabled(m_ui
->checkBypassAuthSubnetWhitelist
->isChecked());
1357 pref
->setAltWebUIEnabled(m_ui
->groupAltWebUI
->isChecked());
1358 pref
->setWebUIRootFolder(m_ui
->textWebUIRootFolder
->selectedPath());
1360 pref
->setWebUIClickjackingProtectionEnabled(m_ui
->checkClickjacking
->isChecked());
1361 pref
->setWebUICSRFProtectionEnabled(m_ui
->checkCSRFProtection
->isChecked());
1362 pref
->setWebUISecureCookieEnabled(m_ui
->checkSecureCookie
->isChecked());
1363 pref
->setWebUIHostHeaderValidationEnabled(m_ui
->groupHostHeaderValidation
->isChecked());
1364 pref
->setServerDomains(m_ui
->textServerDomains
->text());
1365 // Custom HTTP headers
1366 pref
->setWebUICustomHTTPHeadersEnabled(m_ui
->groupWebUIAddCustomHTTPHeaders
->isChecked());
1367 pref
->setWebUICustomHTTPHeaders(m_ui
->textWebUICustomHTTPHeaders
->toPlainText());
1369 pref
->setWebUIReverseProxySupportEnabled(m_ui
->groupEnableReverseProxySupport
->isChecked());
1370 pref
->setWebUITrustedReverseProxiesList(m_ui
->textTrustedReverseProxiesList
->text());
1372 pref
->setDynDNSEnabled(m_ui
->checkDynDNS
->isChecked());
1373 pref
->setDynDNSService(static_cast<DNS::Service
>(m_ui
->comboDNSService
->currentIndex()));
1374 pref
->setDynDomainName(m_ui
->domainNameTxt
->text());
1375 pref
->setDynDNSUsername(m_ui
->DNSUsernameTxt
->text());
1376 pref
->setDynDNSPassword(m_ui
->DNSPasswordTxt
->text());
1378 #endif // DISABLE_WEBUI
1380 void OptionsDialog::initializeLanguageCombo()
1382 // List language files
1383 const QStringList langFiles
= QDir(u
":/lang"_s
).entryList({u
"qbittorrent_*.qm"_s
}, QDir::Files
, QDir::Name
);
1384 for (const QString
&langFile
: langFiles
)
1386 const QString langCode
= QStringView(langFile
).sliced(12).chopped(3).toString(); // remove "qbittorrent_" and ".qm"
1387 m_ui
->comboI18n
->addItem(Utils::Misc::languageToLocalizedString(langCode
), langCode
);
1391 void OptionsDialog::changePage(QListWidgetItem
*current
, QListWidgetItem
*previous
)
1395 m_ui
->tabOption
->setCurrentIndex(m_ui
->tabSelection
->row(current
));
1398 void OptionsDialog::loadSplitterState()
1400 // width has been modified, use height as width reference instead
1401 const int width
= m_ui
->tabSelection
->item(TAB_UI
)->sizeHint().height() * 2;
1402 const QStringList defaultSizes
= {QString::number(width
), QString::number(m_ui
->hsplitter
->width() - width
)};
1404 QList
<int> splitterSizes
;
1405 for (const QString
&string
: asConst(m_storeHSplitterSize
.get(defaultSizes
)))
1406 splitterSizes
.append(string
.toInt());
1408 m_ui
->hsplitter
->setSizes(splitterSizes
);
1411 void OptionsDialog::showEvent(QShowEvent
*e
)
1413 QDialog::showEvent(e
);
1415 loadSplitterState();
1418 void OptionsDialog::saveOptions() const
1420 auto *pref
= Preferences::instance();
1422 saveBehaviorTabOptions();
1423 saveDownloadsTabOptions();
1424 saveConnectionTabOptions();
1425 saveSpeedTabOptions();
1426 saveBittorrentTabOptions();
1427 saveRSSTabOptions();
1428 #ifndef DISABLE_WEBUI
1429 saveWebUITabOptions();
1431 m_advancedSettings
->saveAdvancedSettings();
1433 // Assume that user changed multiple settings
1434 // so it's best to save immediately
1438 bool OptionsDialog::isIPFilteringEnabled() const
1440 return m_ui
->checkIPFilter
->isChecked();
1443 Net::ProxyType
OptionsDialog::getProxyType() const
1445 return m_ui
->comboProxyType
->currentData().value
<Net::ProxyType
>();
1448 int OptionsDialog::getPort() const
1450 return m_ui
->spinPort
->value();
1453 void OptionsDialog::on_randomButton_clicked()
1455 // Range [1024: 65535]
1456 m_ui
->spinPort
->setValue(Utils::Random::rand(1024, 65535));
1459 int OptionsDialog::getEncryptionSetting() const
1461 return m_ui
->comboEncryption
->currentIndex();
1464 int OptionsDialog::getMaxActiveDownloads() const
1466 return m_ui
->spinMaxActiveDownloads
->value();
1469 int OptionsDialog::getMaxActiveUploads() const
1471 return m_ui
->spinMaxActiveUploads
->value();
1474 int OptionsDialog::getMaxActiveTorrents() const
1476 return m_ui
->spinMaxActiveTorrents
->value();
1479 bool OptionsDialog::isQueueingSystemEnabled() const
1481 return m_ui
->checkEnableQueueing
->isChecked();
1484 bool OptionsDialog::isDHTEnabled() const
1486 return m_ui
->checkDHT
->isChecked();
1489 bool OptionsDialog::isLSDEnabled() const
1491 return m_ui
->checkLSD
->isChecked();
1494 bool OptionsDialog::isUPnPEnabled() const
1496 return m_ui
->checkUPnP
->isChecked();
1499 // Return Share ratio
1500 qreal
OptionsDialog::getMaxRatio() const
1502 if (m_ui
->checkMaxRatio
->isChecked())
1503 return m_ui
->spinMaxRatio
->value();
1507 // Return Seeding Minutes
1508 int OptionsDialog::getMaxSeedingMinutes() const
1510 if (m_ui
->checkMaxSeedingMinutes
->isChecked())
1511 return m_ui
->spinMaxSeedingMinutes
->value();
1515 // Return Inactive Seeding Minutes
1516 int OptionsDialog::getMaxInactiveSeedingMinutes() const
1518 return m_ui
->checkMaxInactiveSeedingMinutes
->isChecked()
1519 ? m_ui
->spinMaxInactiveSeedingMinutes
->value()
1523 // Return max connections number
1524 int OptionsDialog::getMaxConnections() const
1526 if (!m_ui
->checkMaxConnections
->isChecked())
1529 return m_ui
->spinMaxConnec
->value();
1532 int OptionsDialog::getMaxConnectionsPerTorrent() const
1534 if (!m_ui
->checkMaxConnectionsPerTorrent
->isChecked())
1537 return m_ui
->spinMaxConnecPerTorrent
->value();
1540 int OptionsDialog::getMaxUploads() const
1542 if (!m_ui
->checkMaxUploads
->isChecked())
1545 return m_ui
->spinMaxUploads
->value();
1548 int OptionsDialog::getMaxUploadsPerTorrent() const
1550 if (!m_ui
->checkMaxUploadsPerTorrent
->isChecked())
1553 return m_ui
->spinMaxUploadsPerTorrent
->value();
1556 void OptionsDialog::on_buttonBox_accepted()
1558 if (m_applyButton
->isEnabled())
1560 if (!applySettings())
1563 m_applyButton
->setEnabled(false);
1569 bool OptionsDialog::applySettings()
1571 if (!schedTimesOk())
1573 m_ui
->tabSelection
->setCurrentRow(TAB_SPEED
);
1576 #ifndef DISABLE_WEBUI
1577 if (isWebUIEnabled() && !webUIAuthenticationOk())
1579 m_ui
->tabSelection
->setCurrentRow(TAB_WEBUI
);
1582 if (!isAlternativeWebUIPathValid())
1584 m_ui
->tabSelection
->setCurrentRow(TAB_WEBUI
);
1593 void OptionsDialog::on_buttonBox_rejected()
1598 bool OptionsDialog::useAdditionDialog() const
1600 return m_ui
->checkAdditionDialog
->isChecked();
1603 void OptionsDialog::enableApplyButton()
1605 m_applyButton
->setEnabled(true);
1608 void OptionsDialog::toggleComboRatioLimitAct()
1610 // Verify if the share action button must be enabled
1611 m_ui
->comboRatioLimitAct
->setEnabled(m_ui
->checkMaxRatio
->isChecked() || m_ui
->checkMaxSeedingMinutes
->isChecked() || m_ui
->checkMaxInactiveSeedingMinutes
->isChecked());
1614 void OptionsDialog::adjustProxyOptions()
1616 const auto currentProxyType
= m_ui
->comboProxyType
->currentData().value
<Net::ProxyType
>();
1617 const bool isAuthSupported
= ((currentProxyType
== Net::ProxyType::SOCKS5
)
1618 || (currentProxyType
== Net::ProxyType::HTTP
));
1620 m_ui
->checkProxyAuth
->setEnabled(isAuthSupported
);
1622 if (currentProxyType
== Net::ProxyType::None
)
1624 m_ui
->labelProxyTypeIncompatible
->setVisible(false);
1626 m_ui
->lblProxyIP
->setEnabled(false);
1627 m_ui
->textProxyIP
->setEnabled(false);
1628 m_ui
->lblProxyPort
->setEnabled(false);
1629 m_ui
->spinProxyPort
->setEnabled(false);
1631 m_ui
->checkProxyHostnameLookup
->setEnabled(false);
1632 m_ui
->checkProxyRSS
->setEnabled(false);
1633 m_ui
->checkProxyMisc
->setEnabled(false);
1634 m_ui
->checkProxyBitTorrent
->setEnabled(false);
1635 m_ui
->checkProxyPeerConnections
->setEnabled(false);
1639 m_ui
->lblProxyIP
->setEnabled(true);
1640 m_ui
->textProxyIP
->setEnabled(true);
1641 m_ui
->lblProxyPort
->setEnabled(true);
1642 m_ui
->spinProxyPort
->setEnabled(true);
1644 m_ui
->checkProxyBitTorrent
->setEnabled(true);
1645 m_ui
->checkProxyPeerConnections
->setEnabled(true);
1647 if (currentProxyType
== Net::ProxyType::SOCKS4
)
1649 m_ui
->labelProxyTypeIncompatible
->setVisible(true);
1651 m_ui
->checkProxyHostnameLookup
->setEnabled(false);
1652 m_ui
->checkProxyRSS
->setEnabled(false);
1653 m_ui
->checkProxyMisc
->setEnabled(false);
1658 m_ui
->labelProxyTypeIncompatible
->setVisible(false);
1660 m_ui
->checkProxyHostnameLookup
->setEnabled(true);
1661 m_ui
->checkProxyRSS
->setEnabled(true);
1662 m_ui
->checkProxyMisc
->setEnabled(true);
1667 bool OptionsDialog::isSplashScreenDisabled() const
1669 return !m_ui
->checkShowSplash
->isChecked();
1673 bool OptionsDialog::WinStartup() const
1675 return m_ui
->checkStartup
->isChecked();
1679 bool OptionsDialog::preAllocateAllFiles() const
1681 return m_ui
->checkPreallocateAll
->isChecked();
1684 bool OptionsDialog::addTorrentsInPause() const
1686 return m_ui
->checkStartPaused
->isChecked();
1690 bool OptionsDialog::isProxyEnabled() const
1692 return m_ui
->comboProxyType
->currentIndex();
1695 QString
OptionsDialog::getProxyIp() const
1697 return m_ui
->textProxyIP
->text().trimmed();
1700 unsigned short OptionsDialog::getProxyPort() const
1702 return m_ui
->spinProxyPort
->value();
1705 QString
OptionsDialog::getProxyUsername() const
1707 QString username
= m_ui
->textProxyUsername
->text().trimmed();
1711 QString
OptionsDialog::getProxyPassword() const
1713 QString password
= m_ui
->textProxyPassword
->text();
1714 password
= password
.trimmed();
1719 QString
OptionsDialog::getLocale() const
1721 return m_ui
->comboI18n
->itemData(m_ui
->comboI18n
->currentIndex(), Qt::UserRole
).toString();
1724 void OptionsDialog::setLocale(const QString
&localeStr
)
1727 if (localeStr
.startsWith(u
"eo", Qt::CaseInsensitive
))
1731 else if (localeStr
.startsWith(u
"ltg", Qt::CaseInsensitive
))
1737 QLocale
locale(localeStr
);
1738 if (locale
.language() == QLocale::Uzbek
)
1739 name
= u
"uz@Latn"_s
;
1740 else if (locale
.language() == QLocale::Azerbaijani
)
1741 name
= u
"az@latin"_s
;
1743 name
= locale
.name();
1745 // Attempt to find exact match
1746 int index
= m_ui
->comboI18n
->findData(name
, Qt::UserRole
);
1749 //Attempt to find a language match without a country
1750 int pos
= name
.indexOf(u
'_');
1753 QString lang
= name
.left(pos
);
1754 index
= m_ui
->comboI18n
->findData(lang
, Qt::UserRole
);
1759 // Unrecognized, use US English
1760 index
= m_ui
->comboI18n
->findData(u
"en"_s
, Qt::UserRole
);
1761 Q_ASSERT(index
>= 0);
1763 m_ui
->comboI18n
->setCurrentIndex(index
);
1766 Path
OptionsDialog::getTorrentExportDir() const
1768 if (m_ui
->checkExportDir
->isChecked())
1769 return m_ui
->textExportDir
->selectedPath();
1773 Path
OptionsDialog::getFinishedTorrentExportDir() const
1775 if (m_ui
->checkExportDirFin
->isChecked())
1776 return m_ui
->textExportDirFin
->selectedPath();
1780 void OptionsDialog::on_addWatchedFolderButton_clicked()
1782 Preferences
*const pref
= Preferences::instance();
1783 const Path dir
{QFileDialog::getExistingDirectory(
1784 this, tr("Select folder to monitor"), pref
->getScanDirsLastPath().parentPath().toString())};
1788 auto *dialog
= new WatchedFolderOptionsDialog({}, this);
1789 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
1790 connect(dialog
, &QDialog::accepted
, this, [this, dialog
, dir
, pref
]()
1794 auto *watchedFoldersModel
= static_cast<WatchedFoldersModel
*>(m_ui
->scanFoldersView
->model());
1795 watchedFoldersModel
->addFolder(dir
, dialog
->watchedFolderOptions());
1797 pref
->setScanDirsLastPath(dir
);
1799 for (int i
= 0; i
< watchedFoldersModel
->columnCount(); ++i
)
1800 m_ui
->scanFoldersView
->resizeColumnToContents(i
);
1802 enableApplyButton();
1804 catch (const RuntimeError
&err
)
1806 QMessageBox::critical(this, tr("Adding entry failed"), err
.message());
1813 void OptionsDialog::on_editWatchedFolderButton_clicked()
1815 const QModelIndex selected
1816 = m_ui
->scanFoldersView
->selectionModel()->selectedIndexes().at(0);
1818 editWatchedFolderOptions(selected
);
1821 void OptionsDialog::on_removeWatchedFolderButton_clicked()
1823 const QModelIndexList selected
1824 = m_ui
->scanFoldersView
->selectionModel()->selectedIndexes();
1826 for (const QModelIndex
&index
: selected
)
1827 m_ui
->scanFoldersView
->model()->removeRow(index
.row());
1830 void OptionsDialog::handleWatchedFolderViewSelectionChanged()
1832 const QModelIndexList selectedIndexes
= m_ui
->scanFoldersView
->selectionModel()->selectedIndexes();
1833 m_ui
->removeWatchedFolderButton
->setEnabled(!selectedIndexes
.isEmpty());
1834 m_ui
->editWatchedFolderButton
->setEnabled(selectedIndexes
.count() == 1);
1837 void OptionsDialog::editWatchedFolderOptions(const QModelIndex
&index
)
1839 if (!index
.isValid())
1842 auto *watchedFoldersModel
= static_cast<WatchedFoldersModel
*>(m_ui
->scanFoldersView
->model());
1843 auto *dialog
= new WatchedFolderOptionsDialog(watchedFoldersModel
->folderOptions(index
.row()), this);
1844 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
1845 connect(dialog
, &QDialog::accepted
, this, [this, dialog
, index
, watchedFoldersModel
]()
1847 if (index
.isValid())
1849 // The index could be invalidated while the dialog was displayed,
1850 // for example, if you deleted the folder using the Web API.
1851 watchedFoldersModel
->setFolderOptions(index
.row(), dialog
->watchedFolderOptions());
1852 enableApplyButton();
1859 // Return Filter object to apply to BT session
1860 Path
OptionsDialog::getFilter() const
1862 return m_ui
->textFilterPath
->selectedPath();
1865 #ifndef DISABLE_WEBUI
1866 void OptionsDialog::webUIHttpsCertChanged(const Path
&path
)
1868 const auto readResult
= Utils::IO::readFile(path
, Utils::Net::MAX_SSL_FILE_SIZE
);
1869 const bool isCertValid
= !Utils::SSLKey::load(readResult
.value_or(QByteArray())).isNull();
1871 m_ui
->textWebUIHttpsCert
->setSelectedPath(path
);
1872 m_ui
->lblSslCertStatus
->setPixmap(UIThemeManager::instance()->getScaledPixmap(
1873 (isCertValid
? u
"security-high"_s
: u
"security-low"_s
), 24));
1876 void OptionsDialog::webUIHttpsKeyChanged(const Path
&path
)
1878 const auto readResult
= Utils::IO::readFile(path
, Utils::Net::MAX_SSL_FILE_SIZE
);
1879 const bool isKeyValid
= !Utils::SSLKey::load(readResult
.value_or(QByteArray())).isNull();
1881 m_ui
->textWebUIHttpsKey
->setSelectedPath(path
);
1882 m_ui
->lblSslKeyStatus
->setPixmap(UIThemeManager::instance()->getScaledPixmap(
1883 (isKeyValid
? u
"security-high"_s
: u
"security-low"_s
), 24));
1886 bool OptionsDialog::isWebUIEnabled() const
1888 return m_ui
->checkWebUI
->isChecked();
1891 QString
OptionsDialog::webUIUsername() const
1893 return m_ui
->textWebUIUsername
->text();
1896 QString
OptionsDialog::webUIPassword() const
1898 return m_ui
->textWebUIPassword
->text();
1901 bool OptionsDialog::webUIAuthenticationOk()
1903 if (!isValidWebUIUsername(webUIUsername()))
1905 QMessageBox::warning(this, tr("Length Error"), tr("The WebUI username must be at least 3 characters long."));
1909 const bool dontChangePassword
= webUIPassword().isEmpty() && !Preferences::instance()->getWebUIPassword().isEmpty();
1910 if (!isValidWebUIPassword(webUIPassword()) && !dontChangePassword
)
1912 QMessageBox::warning(this, tr("Length Error"), tr("The WebUI password must be at least 6 characters long."));
1918 bool OptionsDialog::isAlternativeWebUIPathValid()
1920 if (m_ui
->groupAltWebUI
->isChecked() && m_ui
->textWebUIRootFolder
->selectedPath().isEmpty())
1922 QMessageBox::warning(this, tr("Location Error"), tr("The alternative WebUI files location cannot be blank."));
1929 void OptionsDialog::showConnectionTab()
1931 m_ui
->tabSelection
->setCurrentRow(TAB_CONNECTION
);
1934 #ifndef DISABLE_WEBUI
1935 void OptionsDialog::on_registerDNSBtn_clicked()
1937 const auto service
= static_cast<DNS::Service
>(m_ui
->comboDNSService
->currentIndex());
1938 QDesktopServices::openUrl(Net::DNSUpdater::getRegistrationUrl(service
));
1942 void OptionsDialog::on_IpFilterRefreshBtn_clicked()
1944 if (m_refreshingIpFilter
) return;
1945 m_refreshingIpFilter
= true;
1946 // Updating program preferences
1947 BitTorrent::Session
*const session
= BitTorrent::Session::instance();
1948 session
->setIPFilteringEnabled(true);
1949 session
->setIPFilterFile({}); // forcing Session reload filter file
1950 session
->setIPFilterFile(getFilter());
1951 connect(session
, &BitTorrent::Session::IPFilterParsed
, this, &OptionsDialog::handleIPFilterParsed
);
1952 setCursor(QCursor(Qt::WaitCursor
));
1955 void OptionsDialog::handleIPFilterParsed(bool error
, int ruleCount
)
1957 setCursor(QCursor(Qt::ArrowCursor
));
1959 QMessageBox::warning(this, tr("Parsing error"), tr("Failed to parse the provided IP filter"));
1961 QMessageBox::information(this, tr("Successfully refreshed"), tr("Successfully parsed the provided IP filter: %1 rules were applied.", "%1 is a number").arg(ruleCount
));
1962 m_refreshingIpFilter
= false;
1963 disconnect(BitTorrent::Session::instance(), &BitTorrent::Session::IPFilterParsed
, this, &OptionsDialog::handleIPFilterParsed
);
1966 bool OptionsDialog::schedTimesOk()
1968 if (m_ui
->timeEditScheduleFrom
->time() == m_ui
->timeEditScheduleTo
->time())
1970 QMessageBox::warning(this, tr("Time Error"), tr("The start time and the end time can't be the same."));
1976 void OptionsDialog::on_banListButton_clicked()
1978 auto *dialog
= new BanListOptionsDialog(this);
1979 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
1980 connect(dialog
, &QDialog::accepted
, this, &OptionsDialog::enableApplyButton
);
1984 void OptionsDialog::on_IPSubnetWhitelistButton_clicked()
1986 auto *dialog
= new IPSubnetWhitelistOptionsDialog(this);
1987 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
1988 connect(dialog
, &QDialog::accepted
, this, &OptionsDialog::enableApplyButton
);