2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2023-2024 Vladimir Golovnev <glassez@yandex.ru>
4 * Copyright (C) 2024 Jonathan Ketchker
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"
38 #include <QApplication>
40 #include <QDesktopServices>
41 #include <QDialogButtonBox>
43 #include <QFileDialog>
44 #include <QMessageBox>
45 #include <QSystemTrayIcon>
46 #include <QTranslator>
49 #include <QStyleFactory>
52 #include "base/bittorrent/session.h"
53 #include "base/bittorrent/sharelimitaction.h"
54 #include "base/exceptions.h"
55 #include "base/global.h"
56 #include "base/net/portforwarder.h"
57 #include "base/net/proxyconfigurationmanager.h"
58 #include "base/path.h"
59 #include "base/preferences.h"
60 #include "base/rss/rss_autodownloader.h"
61 #include "base/rss/rss_session.h"
62 #include "base/torrentfileguard.h"
63 #include "base/torrentfileswatcher.h"
64 #include "base/utils/compare.h"
65 #include "base/utils/io.h"
66 #include "base/utils/misc.h"
67 #include "base/utils/net.h"
68 #include "base/utils/os.h"
69 #include "base/utils/password.h"
70 #include "base/utils/random.h"
71 #include "base/utils/sslkey.h"
72 #include "addnewtorrentdialog.h"
73 #include "advancedsettings.h"
74 #include "banlistoptionsdialog.h"
75 #include "interfaces/iguiapplication.h"
76 #include "ipsubnetwhitelistoptionsdialog.h"
77 #include "rss/automatedrssdownloader.h"
78 #include "ui_optionsdialog.h"
79 #include "uithemedialog.h"
80 #include "uithememanager.h"
82 #include "watchedfolderoptionsdialog.h"
83 #include "watchedfoldersmodel.h"
84 #include "webui/webui.h"
87 #include "base/net/dnsupdater.h"
90 #if defined Q_OS_MACOS || defined Q_OS_WIN
91 #include "base/utils/os.h"
92 #endif // defined Q_OS_MACOS || defined Q_OS_WIN
94 #define SETTINGS_KEY(name) u"OptionsDialog/" name
96 const int WEBUI_MIN_USERNAME_LENGTH
= 3;
97 const int WEBUI_MIN_PASSWORD_LENGTH
= 6;
101 QStringList
translatedWeekdayNames()
103 // return translated strings from Monday to Sunday in user selected locale
105 const QLocale locale
{Preferences::instance()->getLocale()};
106 const QDate date
{2018, 11, 5}; // Monday
108 for (int i
= 0; i
< 7; ++i
)
109 ret
.append(locale
.toString(date
.addDays(i
), u
"dddd"_s
));
113 class WheelEventEater final
: public QObject
116 using QObject::QObject
;
119 bool eventFilter(QObject
*, QEvent
*event
) override
121 return (event
->type() == QEvent::Wheel
);
125 bool isValidWebUIUsername(const QString
&username
)
127 return (username
.length() >= WEBUI_MIN_USERNAME_LENGTH
);
130 bool isValidWebUIPassword(const QString
&password
)
132 return (password
.length() >= WEBUI_MIN_PASSWORD_LENGTH
);
135 // Shortcuts for frequently used signals that have more than one overload. They would require
136 // type casts and that is why we declare required member pointer here instead.
137 void (QComboBox::*qComboBoxCurrentIndexChanged
)(int) = &QComboBox::currentIndexChanged
;
138 void (QSpinBox::*qSpinBoxValueChanged
)(int) = &QSpinBox::valueChanged
;
142 OptionsDialog::OptionsDialog(IGUIApplication
*app
, QWidget
*parent
)
143 : GUIApplicationComponent(app
, parent
)
144 , m_ui
{new Ui::OptionsDialog
}
145 , m_storeDialogSize
{SETTINGS_KEY(u
"Size"_s
)}
146 , m_storeHSplitterSize
{SETTINGS_KEY(u
"HorizontalSplitterSizes"_s
)}
147 , m_storeLastViewedPage
{SETTINGS_KEY(u
"LastViewedPage"_s
)}
150 m_applyButton
= m_ui
->buttonBox
->button(QDialogButtonBox::Apply
);
153 setWindowTitle(tr("Preferences"));
156 m_ui
->hsplitter
->setCollapsible(0, false);
157 m_ui
->hsplitter
->setCollapsible(1, false);
160 m_ui
->tabSelection
->item(TAB_UI
)->setIcon(UIThemeManager::instance()->getIcon(u
"preferences-desktop"_s
));
161 m_ui
->tabSelection
->item(TAB_BITTORRENT
)->setIcon(UIThemeManager::instance()->getIcon(u
"preferences-bittorrent"_s
, u
"preferences-system-network"_s
));
162 m_ui
->tabSelection
->item(TAB_CONNECTION
)->setIcon(UIThemeManager::instance()->getIcon(u
"network-connect"_s
, u
"network-wired"_s
));
163 m_ui
->tabSelection
->item(TAB_DOWNLOADS
)->setIcon(UIThemeManager::instance()->getIcon(u
"download"_s
, u
"folder-download"_s
));
164 m_ui
->tabSelection
->item(TAB_SPEED
)->setIcon(UIThemeManager::instance()->getIcon(u
"speedometer"_s
, u
"chronometer"_s
));
165 m_ui
->tabSelection
->item(TAB_RSS
)->setIcon(UIThemeManager::instance()->getIcon(u
"application-rss"_s
, u
"application-rss+xml"_s
));
167 m_ui
->tabSelection
->item(TAB_WEBUI
)->setHidden(true);
169 m_ui
->tabSelection
->item(TAB_WEBUI
)->setIcon(UIThemeManager::instance()->getIcon(u
"preferences-webui"_s
, u
"network-server"_s
));
171 m_ui
->tabSelection
->item(TAB_ADVANCED
)->setIcon(UIThemeManager::instance()->getIcon(u
"preferences-advanced"_s
, u
"preferences-other"_s
));
173 // set uniform size for all icons
175 for (int i
= 0; i
< m_ui
->tabSelection
->count(); ++i
)
176 maxHeight
= std::max(maxHeight
, m_ui
->tabSelection
->visualItemRect(m_ui
->tabSelection
->item(i
)).size().height());
177 for (int i
= 0; i
< m_ui
->tabSelection
->count(); ++i
)
179 const QSize
size(std::numeric_limits
<int>::max(), static_cast<int>(maxHeight
* 1.2));
180 m_ui
->tabSelection
->item(i
)->setSizeHint(size
);
183 connect(m_ui
->tabSelection
, &QListWidget::currentItemChanged
, this, &ThisType::changePage
);
186 loadBehaviorTabOptions();
187 loadDownloadsTabOptions();
188 loadConnectionTabOptions();
189 loadSpeedTabOptions();
190 loadBittorrentTabOptions();
192 #ifndef DISABLE_WEBUI
193 loadWebUITabOptions();
196 // Load Advanced settings
197 m_advancedSettings
= new AdvancedSettings(app
, m_ui
->tabAdvancedPage
);
198 m_ui
->advPageLayout
->addWidget(m_advancedSettings
);
199 connect(m_advancedSettings
, &AdvancedSettings::settingsChanged
, this, &ThisType::enableApplyButton
);
201 // setup apply button
202 m_applyButton
->setEnabled(false);
203 connect(m_applyButton
, &QPushButton::clicked
, this, [this]
206 m_applyButton
->setEnabled(false);
209 // disable mouse wheel event on widgets to avoid misselection
210 auto *wheelEventEater
= new WheelEventEater(this);
211 for (QComboBox
*widget
: asConst(findChildren
<QComboBox
*>()))
212 widget
->installEventFilter(wheelEventEater
);
213 for (QSpinBox
*widget
: asConst(findChildren
<QSpinBox
*>()))
214 widget
->installEventFilter(wheelEventEater
);
216 m_ui
->tabSelection
->setCurrentRow(m_storeLastViewedPage
);
218 if (const QSize dialogSize
= m_storeDialogSize
; dialogSize
.isValid())
222 OptionsDialog::~OptionsDialog()
224 // save dialog states
225 m_storeDialogSize
= size();
227 QStringList hSplitterSizes
;
228 for (const int size
: asConst(m_ui
->hsplitter
->sizes()))
229 hSplitterSizes
.append(QString::number(size
));
230 m_storeHSplitterSize
= hSplitterSizes
;
232 m_storeLastViewedPage
= m_ui
->tabSelection
->currentRow();
237 void OptionsDialog::loadBehaviorTabOptions()
239 const auto *pref
= Preferences::instance();
240 const auto *session
= BitTorrent::Session::instance();
242 initializeLanguageCombo();
243 setLocale(pref
->getLocale());
245 initializeStyleCombo();
246 initializeColorSchemeOptions();
248 m_ui
->checkUseCustomTheme
->setChecked(Preferences::instance()->useCustomUITheme());
249 m_ui
->customThemeFilePath
->setSelectedPath(Preferences::instance()->customUIThemePath());
250 m_ui
->customThemeFilePath
->setMode(FileSystemPathEdit::Mode::FileOpen
);
251 m_ui
->customThemeFilePath
->setDialogCaption(tr("Select qBittorrent UI Theme file"));
252 m_ui
->customThemeFilePath
->setFileNameFilter(tr("qBittorrent UI Theme file (*.qbtheme config.json)"));
253 #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
254 m_ui
->checkUseSystemIcon
->setChecked(pref
->useSystemIcons());
256 m_ui
->checkUseSystemIcon
->setVisible(false);
259 m_ui
->confirmDeletion
->setChecked(pref
->confirmTorrentDeletion());
260 m_ui
->checkAltRowColors
->setChecked(pref
->useAlternatingRowColors());
261 m_ui
->checkHideZero
->setChecked(pref
->getHideZeroValues());
262 m_ui
->comboHideZero
->setCurrentIndex(pref
->getHideZeroComboValues());
263 m_ui
->comboHideZero
->setEnabled(m_ui
->checkHideZero
->isChecked());
265 m_ui
->actionTorrentDlOnDblClBox
->setItemData(0, TOGGLE_STOP
);
266 m_ui
->actionTorrentDlOnDblClBox
->setItemData(1, OPEN_DEST
);
267 m_ui
->actionTorrentDlOnDblClBox
->setItemData(2, PREVIEW_FILE
);
268 m_ui
->actionTorrentDlOnDblClBox
->setItemData(3, SHOW_OPTIONS
);
269 m_ui
->actionTorrentDlOnDblClBox
->setItemData(4, NO_ACTION
);
270 int actionDownloading
= pref
->getActionOnDblClOnTorrentDl();
271 if ((actionDownloading
< 0) || (actionDownloading
>= m_ui
->actionTorrentDlOnDblClBox
->count()))
272 actionDownloading
= TOGGLE_STOP
;
273 m_ui
->actionTorrentDlOnDblClBox
->setCurrentIndex(m_ui
->actionTorrentDlOnDblClBox
->findData(actionDownloading
));
275 m_ui
->actionTorrentFnOnDblClBox
->setItemData(0, TOGGLE_STOP
);
276 m_ui
->actionTorrentFnOnDblClBox
->setItemData(1, OPEN_DEST
);
277 m_ui
->actionTorrentFnOnDblClBox
->setItemData(2, PREVIEW_FILE
);
278 m_ui
->actionTorrentFnOnDblClBox
->setItemData(3, SHOW_OPTIONS
);
279 m_ui
->actionTorrentFnOnDblClBox
->setItemData(4, NO_ACTION
);
280 int actionSeeding
= pref
->getActionOnDblClOnTorrentFn();
281 if ((actionSeeding
< 0) || (actionSeeding
>= m_ui
->actionTorrentFnOnDblClBox
->count()))
282 actionSeeding
= OPEN_DEST
;
283 m_ui
->actionTorrentFnOnDblClBox
->setCurrentIndex(m_ui
->actionTorrentFnOnDblClBox
->findData(actionSeeding
));
285 m_ui
->checkBoxHideZeroStatusFilters
->setChecked(pref
->getHideZeroStatusFilters());
288 m_ui
->checkStartup
->setVisible(false);
290 m_ui
->checkShowSplash
->setChecked(!pref
->isSplashScreenDisabled());
291 m_ui
->checkProgramExitConfirm
->setChecked(pref
->confirmOnExit());
292 m_ui
->checkProgramAutoExitConfirm
->setChecked(!pref
->dontConfirmAutoExit());
294 m_ui
->windowStateComboBox
->addItem(tr("Normal"), QVariant::fromValue(WindowState::Normal
));
295 m_ui
->windowStateComboBox
->addItem(tr("Minimized"), QVariant::fromValue(WindowState::Minimized
));
297 m_ui
->windowStateComboBox
->addItem(tr("Hidden"), QVariant::fromValue(WindowState::Hidden
));
299 m_ui
->windowStateComboBox
->setCurrentIndex(m_ui
->windowStateComboBox
->findData(QVariant::fromValue(app()->startUpWindowState())));
301 #if !(defined(Q_OS_WIN) || defined(Q_OS_MACOS))
302 m_ui
->groupFileAssociation
->setVisible(false);
303 m_ui
->checkProgramUpdates
->setVisible(false);
307 // Disable systray integration if it is not supported by the system
308 if (!QSystemTrayIcon::isSystemTrayAvailable())
310 m_ui
->checkShowSystray
->setChecked(false);
311 m_ui
->checkShowSystray
->setEnabled(false);
312 m_ui
->checkShowSystray
->setToolTip(tr("Disabled due to failed to detect system tray presence"));
314 m_ui
->checkShowSystray
->setChecked(pref
->systemTrayEnabled());
315 m_ui
->checkMinimizeToSysTray
->setChecked(pref
->minimizeToTray());
316 m_ui
->checkCloseToSystray
->setChecked(pref
->closeToTray());
317 m_ui
->comboTrayIcon
->setCurrentIndex(static_cast<int>(pref
->trayIconStyle()));
321 m_ui
->checkStartup
->setChecked(pref
->WinStartup());
325 m_ui
->checkShowSystray
->setVisible(false);
326 m_ui
->checkAssociateTorrents
->setChecked(Utils::OS::isTorrentFileAssocSet());
327 m_ui
->checkAssociateTorrents
->setEnabled(!m_ui
->checkAssociateTorrents
->isChecked());
328 m_ui
->checkAssociateMagnetLinks
->setChecked(Utils::OS::isMagnetLinkAssocSet());
329 m_ui
->checkAssociateMagnetLinks
->setEnabled(!m_ui
->checkAssociateMagnetLinks
->isChecked());
332 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
333 m_ui
->checkProgramUpdates
->setChecked(pref
->isUpdateCheckEnabled());
336 m_ui
->checkPreventFromSuspendWhenDownloading
->setChecked(pref
->preventFromSuspendWhenDownloading());
337 m_ui
->checkPreventFromSuspendWhenSeeding
->setChecked(pref
->preventFromSuspendWhenSeeding());
339 m_ui
->textFileLogPath
->setDialogCaption(tr("Choose a save directory"));
340 m_ui
->textFileLogPath
->setMode(FileSystemPathEdit::Mode::DirectorySave
);
341 m_ui
->textFileLogPath
->setSelectedPath(app()->fileLoggerPath());
342 const bool fileLogBackup
= app()->isFileLoggerBackup();
343 m_ui
->checkFileLogBackup
->setChecked(fileLogBackup
);
344 m_ui
->spinFileLogSize
->setEnabled(fileLogBackup
);
345 const bool fileLogDelete
= app()->isFileLoggerDeleteOld();
346 m_ui
->checkFileLogDelete
->setChecked(fileLogDelete
);
347 m_ui
->spinFileLogAge
->setEnabled(fileLogDelete
);
348 m_ui
->comboFileLogAgeType
->setEnabled(fileLogDelete
);
349 m_ui
->spinFileLogSize
->setValue(app()->fileLoggerMaxSize() / 1024);
350 m_ui
->spinFileLogAge
->setValue(app()->fileLoggerAge());
351 m_ui
->comboFileLogAgeType
->setCurrentIndex(app()->fileLoggerAgeType());
352 // Groupbox's check state must be initialized after some of its children if they are manually enabled/disabled
353 m_ui
->checkFileLog
->setChecked(app()->isFileLoggerEnabled());
355 m_ui
->checkBoxPerformanceWarning
->setChecked(session
->isPerformanceWarningEnabled());
357 connect(m_ui
->comboLanguage
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
360 connect(m_ui
->comboStyle
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
363 #ifdef QBT_HAS_COLORSCHEME_OPTION
364 connect(m_ui
->comboColorScheme
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
367 #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
368 connect(m_ui
->checkUseSystemIcon
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
370 connect(m_ui
->checkUseCustomTheme
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
371 connect(m_ui
->customThemeFilePath
, &FileSystemPathEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
373 m_ui
->buttonCustomizeUITheme
->setEnabled(!m_ui
->checkUseCustomTheme
->isChecked());
374 connect(m_ui
->checkUseCustomTheme
, &QGroupBox::toggled
, this, [this]
376 m_ui
->buttonCustomizeUITheme
->setEnabled(!m_ui
->checkUseCustomTheme
->isChecked());
378 connect(m_ui
->buttonCustomizeUITheme
, &QPushButton::clicked
, this, [this]
380 auto *dialog
= new UIThemeDialog(this);
381 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
385 connect(m_ui
->confirmDeletion
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
386 connect(m_ui
->checkAltRowColors
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
387 connect(m_ui
->checkHideZero
, &QAbstractButton::toggled
, m_ui
->comboHideZero
, &QWidget::setEnabled
);
388 connect(m_ui
->checkHideZero
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
389 connect(m_ui
->comboHideZero
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
390 connect(m_ui
->actionTorrentDlOnDblClBox
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
391 connect(m_ui
->actionTorrentFnOnDblClBox
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
392 connect(m_ui
->checkBoxHideZeroStatusFilters
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
395 connect(m_ui
->checkStartup
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
397 connect(m_ui
->checkShowSplash
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
398 connect(m_ui
->checkProgramExitConfirm
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
399 connect(m_ui
->checkProgramAutoExitConfirm
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
400 connect(m_ui
->checkShowSystray
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
401 connect(m_ui
->checkMinimizeToSysTray
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
402 connect(m_ui
->checkCloseToSystray
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
403 connect(m_ui
->comboTrayIcon
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
404 connect(m_ui
->windowStateComboBox
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
406 connect(m_ui
->checkPreventFromSuspendWhenDownloading
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
407 connect(m_ui
->checkPreventFromSuspendWhenSeeding
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
409 #if defined(Q_OS_MACOS)
410 connect(m_ui
->checkAssociateTorrents
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
411 connect(m_ui
->checkAssociateMagnetLinks
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
414 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
415 connect(m_ui
->checkProgramUpdates
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
419 m_ui
->assocPanel
->hide();
423 m_ui
->defaultProgramPanel
->hide();
426 #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && !defined(QBT_USES_DBUS)
427 m_ui
->checkPreventFromSuspendWhenDownloading
->setDisabled(true);
428 m_ui
->checkPreventFromSuspendWhenSeeding
->setDisabled(true);
431 connect(m_ui
->checkFileLog
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
432 connect(m_ui
->textFileLogPath
, &FileSystemPathEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
433 connect(m_ui
->checkFileLogBackup
, &QAbstractButton::toggled
, m_ui
->spinFileLogSize
, &QWidget::setEnabled
);
434 connect(m_ui
->checkFileLogBackup
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
435 connect(m_ui
->checkFileLogDelete
, &QAbstractButton::toggled
, m_ui
->comboFileLogAgeType
, &QWidget::setEnabled
);
436 connect(m_ui
->checkFileLogDelete
, &QAbstractButton::toggled
, m_ui
->spinFileLogAge
, &QWidget::setEnabled
);
437 connect(m_ui
->checkFileLogDelete
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
438 connect(m_ui
->spinFileLogSize
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
439 connect(m_ui
->spinFileLogAge
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
440 connect(m_ui
->comboFileLogAgeType
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
442 connect(m_ui
->checkBoxPerformanceWarning
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
445 void OptionsDialog::saveBehaviorTabOptions() const
447 auto *pref
= Preferences::instance();
448 auto *session
= BitTorrent::Session::instance();
450 // Load the translation
451 const QString locale
= getLocale();
452 if (pref
->getLocale() != locale
)
454 auto *translator
= new QTranslator
;
455 if (translator
->load(u
":/lang/qbittorrent_"_s
+ locale
))
456 qDebug("%s locale recognized, using translation.", qUtf8Printable(locale
));
458 qDebug("%s locale unrecognized, using default (en).", qUtf8Printable(locale
));
459 qApp
->installTranslator(translator
);
461 pref
->setLocale(locale
);
464 if (const QVariant systemStyle
= m_ui
->comboStyle
->currentData(); systemStyle
.isValid())
465 pref
->setStyle(systemStyle
.toString());
467 pref
->setStyle(m_ui
->comboStyle
->currentText());
470 #ifdef QBT_HAS_COLORSCHEME_OPTION
471 UIThemeManager::instance()->setColorScheme(m_ui
->comboColorScheme
->currentData().value
<ColorScheme
>());
474 #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
475 pref
->useSystemIcons(m_ui
->checkUseSystemIcon
->isChecked());
477 pref
->setUseCustomUITheme(m_ui
->checkUseCustomTheme
->isChecked());
478 pref
->setCustomUIThemePath(m_ui
->customThemeFilePath
->selectedPath());
480 pref
->setConfirmTorrentDeletion(m_ui
->confirmDeletion
->isChecked());
481 pref
->setAlternatingRowColors(m_ui
->checkAltRowColors
->isChecked());
482 pref
->setHideZeroValues(m_ui
->checkHideZero
->isChecked());
483 pref
->setHideZeroComboValues(m_ui
->comboHideZero
->currentIndex());
485 pref
->setActionOnDblClOnTorrentDl(m_ui
->actionTorrentDlOnDblClBox
->currentData().toInt());
486 pref
->setActionOnDblClOnTorrentFn(m_ui
->actionTorrentFnOnDblClBox
->currentData().toInt());
488 pref
->setHideZeroStatusFilters(m_ui
->checkBoxHideZeroStatusFilters
->isChecked());
490 pref
->setSplashScreenDisabled(isSplashScreenDisabled());
491 pref
->setConfirmOnExit(m_ui
->checkProgramExitConfirm
->isChecked());
492 pref
->setDontConfirmAutoExit(!m_ui
->checkProgramAutoExitConfirm
->isChecked());
495 pref
->setWinStartup(WinStartup());
499 pref
->setSystemTrayEnabled(m_ui
->checkShowSystray
->isChecked());
500 pref
->setTrayIconStyle(TrayIcon::Style(m_ui
->comboTrayIcon
->currentIndex()));
501 pref
->setCloseToTray(m_ui
->checkCloseToSystray
->isChecked());
502 pref
->setMinimizeToTray(m_ui
->checkMinimizeToSysTray
->isChecked());
506 if (m_ui
->checkAssociateTorrents
->isChecked())
508 Utils::OS::setTorrentFileAssoc();
509 m_ui
->checkAssociateTorrents
->setChecked(Utils::OS::isTorrentFileAssocSet());
510 m_ui
->checkAssociateTorrents
->setEnabled(!m_ui
->checkAssociateTorrents
->isChecked());
512 if (m_ui
->checkAssociateMagnetLinks
->isChecked())
514 Utils::OS::setMagnetLinkAssoc();
515 m_ui
->checkAssociateMagnetLinks
->setChecked(Utils::OS::isMagnetLinkAssocSet());
516 m_ui
->checkAssociateMagnetLinks
->setEnabled(!m_ui
->checkAssociateMagnetLinks
->isChecked());
520 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
521 pref
->setUpdateCheckEnabled(m_ui
->checkProgramUpdates
->isChecked());
524 pref
->setPreventFromSuspendWhenDownloading(m_ui
->checkPreventFromSuspendWhenDownloading
->isChecked());
525 pref
->setPreventFromSuspendWhenSeeding(m_ui
->checkPreventFromSuspendWhenSeeding
->isChecked());
527 app()->setFileLoggerPath(m_ui
->textFileLogPath
->selectedPath());
528 app()->setFileLoggerBackup(m_ui
->checkFileLogBackup
->isChecked());
529 app()->setFileLoggerMaxSize(m_ui
->spinFileLogSize
->value() * 1024);
530 app()->setFileLoggerAge(m_ui
->spinFileLogAge
->value());
531 app()->setFileLoggerAgeType(m_ui
->comboFileLogAgeType
->currentIndex());
532 app()->setFileLoggerDeleteOld(m_ui
->checkFileLogDelete
->isChecked());
533 app()->setFileLoggerEnabled(m_ui
->checkFileLog
->isChecked());
535 app()->setStartUpWindowState(m_ui
->windowStateComboBox
->currentData().value
<WindowState
>());
537 session
->setPerformanceWarningEnabled(m_ui
->checkBoxPerformanceWarning
->isChecked());
540 void OptionsDialog::loadDownloadsTabOptions()
542 const auto *pref
= Preferences::instance();
543 const auto *session
= BitTorrent::Session::instance();
545 m_ui
->checkAdditionDialog
->setChecked(pref
->isAddNewTorrentDialogEnabled());
546 m_ui
->checkAdditionDialogFront
->setChecked(pref
->isAddNewTorrentDialogTopLevel());
548 m_ui
->contentLayoutComboBox
->setCurrentIndex(static_cast<int>(session
->torrentContentLayout()));
549 m_ui
->checkAddToQueueTop
->setChecked(session
->isAddTorrentToQueueTop());
550 m_ui
->checkAddStopped
->setChecked(session
->isAddTorrentStopped());
552 m_ui
->stopConditionComboBox
->setToolTip(
553 u
"<html><body><p><b>" + tr("None") + u
"</b> - " + tr("No stop condition is set.") + u
"</p><p><b>" +
554 tr("Metadata received") + u
"</b> - " + tr("Torrent will stop after metadata is received.") +
555 u
" <em>" + tr("Torrents that have metadata initially will be added as stopped.") + u
"</em></p><p><b>" +
556 tr("Files checked") + u
"</b> - " + tr("Torrent will stop after files are initially checked.") +
557 u
" <em>" + tr("This will also download metadata if it wasn't there initially.") + u
"</em></p></body></html>");
558 m_ui
->stopConditionComboBox
->setItemData(0, QVariant::fromValue(BitTorrent::Torrent::StopCondition::None
));
559 m_ui
->stopConditionComboBox
->setItemData(1, QVariant::fromValue(BitTorrent::Torrent::StopCondition::MetadataReceived
));
560 m_ui
->stopConditionComboBox
->setItemData(2, QVariant::fromValue(BitTorrent::Torrent::StopCondition::FilesChecked
));
561 m_ui
->stopConditionComboBox
->setCurrentIndex(m_ui
->stopConditionComboBox
->findData(QVariant::fromValue(session
->torrentStopCondition())));
562 m_ui
->stopConditionLabel
->setEnabled(!m_ui
->checkAddStopped
->isChecked());
563 m_ui
->stopConditionComboBox
->setEnabled(!m_ui
->checkAddStopped
->isChecked());
565 m_ui
->checkMergeTrackers
->setChecked(session
->isMergeTrackersEnabled());
566 m_ui
->checkConfirmMergeTrackers
->setEnabled(m_ui
->checkAdditionDialog
->isChecked());
567 m_ui
->checkConfirmMergeTrackers
->setChecked(m_ui
->checkConfirmMergeTrackers
->isEnabled() ? pref
->confirmMergeTrackers() : false);
568 connect(m_ui
->checkAdditionDialog
, &QGroupBox::toggled
, this, [this, pref
]
570 m_ui
->checkConfirmMergeTrackers
->setEnabled(m_ui
->checkAdditionDialog
->isChecked());
571 m_ui
->checkConfirmMergeTrackers
->setChecked(m_ui
->checkConfirmMergeTrackers
->isEnabled() ? pref
->confirmMergeTrackers() : false);
574 const TorrentFileGuard::AutoDeleteMode autoDeleteMode
= TorrentFileGuard::autoDeleteMode();
575 m_ui
->deleteTorrentBox
->setChecked(autoDeleteMode
!= TorrentFileGuard::Never
);
576 m_ui
->deleteCancelledTorrentBox
->setChecked(autoDeleteMode
== TorrentFileGuard::Always
);
577 m_ui
->deleteTorrentWarningIcon
->setPixmap(QApplication::style()->standardIcon(QStyle::SP_MessageBoxCritical
).pixmap(16, 16));
578 m_ui
->deleteTorrentWarningIcon
->hide();
579 m_ui
->deleteTorrentWarningLabel
->hide();
580 m_ui
->deleteTorrentWarningLabel
->setToolTip(u
"<html><body><p>" +
581 tr("By enabling these options, you can <strong>irrevocably lose</strong> your .torrent files!") +
583 tr("When these options are enabled, qBittorrent will <strong>delete</strong> .torrent files "
584 "after they were successfully (the first option) or not (the second option) added to its "
585 "download queue. This will be applied <strong>not only</strong> to the files opened via "
586 "“Add torrent” menu action but to those opened via <strong>file type association</strong> as well") +
588 tr("If you enable the second option (“Also when addition is cancelled”) the "
589 ".torrent file <strong>will be deleted</strong> even if you press “<strong>Cancel</strong>” in "
590 "the “Add torrent” dialog") +
591 u
"</p></body></html>");
593 m_ui
->checkPreallocateAll
->setChecked(session
->isPreallocationEnabled());
594 m_ui
->checkAppendqB
->setChecked(session
->isAppendExtensionEnabled());
595 m_ui
->checkUnwantedFolder
->setChecked(session
->isUnwantedFolderEnabled());
596 m_ui
->checkRecursiveDownload
->setChecked(pref
->isRecursiveDownloadEnabled());
598 m_ui
->comboSavingMode
->setCurrentIndex(!session
->isAutoTMMDisabledByDefault());
599 m_ui
->comboTorrentCategoryChanged
->setCurrentIndex(session
->isDisableAutoTMMWhenCategoryChanged());
600 m_ui
->comboCategoryChanged
->setCurrentIndex(session
->isDisableAutoTMMWhenCategorySavePathChanged());
601 m_ui
->comboCategoryDefaultPathChanged
->setCurrentIndex(session
->isDisableAutoTMMWhenDefaultSavePathChanged());
603 m_ui
->checkUseSubcategories
->setChecked(session
->isSubcategoriesEnabled());
604 m_ui
->checkUseCategoryPaths
->setChecked(session
->useCategoryPathsInManualMode());
606 m_ui
->textSavePath
->setDialogCaption(tr("Choose a save directory"));
607 m_ui
->textSavePath
->setMode(FileSystemPathEdit::Mode::DirectorySave
);
608 m_ui
->textSavePath
->setSelectedPath(session
->savePath());
610 m_ui
->checkUseDownloadPath
->setChecked(session
->isDownloadPathEnabled());
611 m_ui
->textDownloadPath
->setDialogCaption(tr("Choose a save directory"));
612 m_ui
->textDownloadPath
->setEnabled(m_ui
->checkUseDownloadPath
->isChecked());
613 m_ui
->textDownloadPath
->setMode(FileSystemPathEdit::Mode::DirectorySave
);
614 m_ui
->textDownloadPath
->setSelectedPath(session
->downloadPath());
616 const bool isExportDirEmpty
= session
->torrentExportDirectory().isEmpty();
617 m_ui
->checkExportDir
->setChecked(!isExportDirEmpty
);
618 m_ui
->textExportDir
->setDialogCaption(tr("Choose export directory"));
619 m_ui
->textExportDir
->setEnabled(m_ui
->checkExportDir
->isChecked());
620 m_ui
->textExportDir
->setMode(FileSystemPathEdit::Mode::DirectorySave
);
621 if (!isExportDirEmpty
)
622 m_ui
->textExportDir
->setSelectedPath(session
->torrentExportDirectory());
624 const bool isExportDirFinEmpty
= session
->finishedTorrentExportDirectory().isEmpty();
625 m_ui
->checkExportDirFin
->setChecked(!isExportDirFinEmpty
);
626 m_ui
->textExportDirFin
->setDialogCaption(tr("Choose export directory"));
627 m_ui
->textExportDirFin
->setEnabled(m_ui
->checkExportDirFin
->isChecked());
628 m_ui
->textExportDirFin
->setMode(FileSystemPathEdit::Mode::DirectorySave
);
629 if (!isExportDirFinEmpty
)
630 m_ui
->textExportDirFin
->setSelectedPath(session
->finishedTorrentExportDirectory());
632 auto *watchedFoldersModel
= new WatchedFoldersModel(TorrentFilesWatcher::instance(), this);
633 connect(watchedFoldersModel
, &QAbstractListModel::dataChanged
, this, &ThisType::enableApplyButton
);
634 m_ui
->scanFoldersView
->header()->setSectionResizeMode(QHeaderView::ResizeToContents
);
635 m_ui
->scanFoldersView
->setModel(watchedFoldersModel
);
636 connect(m_ui
->scanFoldersView
->selectionModel(), &QItemSelectionModel::selectionChanged
, this, &ThisType::handleWatchedFolderViewSelectionChanged
);
637 connect(m_ui
->scanFoldersView
, &QTreeView::doubleClicked
, this, &ThisType::editWatchedFolderOptions
);
639 m_ui
->groupExcludedFileNames
->setChecked(session
->isExcludedFileNamesEnabled());
640 m_ui
->textExcludedFileNames
->setPlainText(session
->excludedFileNames().join(u
'\n'));
642 m_ui
->groupMailNotification
->setChecked(pref
->isMailNotificationEnabled());
643 m_ui
->senderEmailTxt
->setText(pref
->getMailNotificationSender());
644 m_ui
->lineEditDestEmail
->setText(pref
->getMailNotificationEmail());
645 m_ui
->lineEditSmtpServer
->setText(pref
->getMailNotificationSMTP());
646 m_ui
->checkSmtpSSL
->setChecked(pref
->getMailNotificationSMTPSSL());
647 m_ui
->groupMailNotifAuth
->setChecked(pref
->getMailNotificationSMTPAuth());
648 m_ui
->mailNotifUsername
->setText(pref
->getMailNotificationSMTPUsername());
649 m_ui
->mailNotifPassword
->setText(pref
->getMailNotificationSMTPPassword());
651 m_ui
->groupBoxRunOnAdded
->setChecked(pref
->isAutoRunOnTorrentAddedEnabled());
652 m_ui
->groupBoxRunOnFinished
->setChecked(pref
->isAutoRunOnTorrentFinishedEnabled());
653 m_ui
->lineEditRunOnAdded
->setText(pref
->getAutoRunOnTorrentAddedProgram());
654 m_ui
->lineEditRunOnFinished
->setText(pref
->getAutoRunOnTorrentFinishedProgram());
655 #if defined(Q_OS_WIN)
656 m_ui
->autoRunConsole
->setChecked(pref
->isAutoRunConsoleEnabled());
658 m_ui
->autoRunConsole
->hide();
660 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
661 .arg(tr("Supported parameters (case sensitive):")
662 , tr("%N: Torrent name")
664 , tr("%G: Tags (separated by comma)")
665 , tr("%F: Content path (same as root path for multifile torrent)")
666 , tr("%R: Root path (first torrent subdirectory path)")
667 , tr("%D: Save path")
668 , tr("%C: Number of files")
669 , tr("%Z: Torrent size (bytes)"))
670 .arg(tr("%T: Current tracker")
671 , tr("%I: Info hash v1 (or '-' if unavailable)")
672 , tr("%J: Info hash v2 (or '-' if unavailable)")
673 , tr("%K: Torrent ID (either sha-1 info hash for v1 torrent or truncated sha-256 info hash for v2/hybrid torrent)")
674 , tr("Tip: Encapsulate parameter with quotation marks to avoid text being cut off at whitespace (e.g., \"%N\")"));
675 m_ui
->labelAutoRunParam
->setText(autoRunStr
);
677 connect(m_ui
->checkAdditionDialog
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
678 connect(m_ui
->checkAdditionDialogFront
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
680 connect(m_ui
->contentLayoutComboBox
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
682 connect(m_ui
->checkAddToQueueTop
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
683 connect(m_ui
->checkAddStopped
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
684 connect(m_ui
->checkAddStopped
, &QAbstractButton::toggled
, this, [this](const bool checked
)
686 m_ui
->stopConditionLabel
->setEnabled(!checked
);
687 m_ui
->stopConditionComboBox
->setEnabled(!checked
);
689 connect(m_ui
->stopConditionComboBox
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
690 connect(m_ui
->checkMergeTrackers
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
691 connect(m_ui
->checkConfirmMergeTrackers
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
692 connect(m_ui
->deleteTorrentBox
, &QGroupBox::toggled
, m_ui
->deleteTorrentWarningIcon
, &QWidget::setVisible
);
693 connect(m_ui
->deleteTorrentBox
, &QGroupBox::toggled
, m_ui
->deleteTorrentWarningLabel
, &QWidget::setVisible
);
694 connect(m_ui
->deleteTorrentBox
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
695 connect(m_ui
->deleteCancelledTorrentBox
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
697 connect(m_ui
->checkPreallocateAll
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
698 connect(m_ui
->checkAppendqB
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
699 connect(m_ui
->checkUnwantedFolder
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
700 connect(m_ui
->checkRecursiveDownload
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
702 connect(m_ui
->comboSavingMode
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
703 connect(m_ui
->comboTorrentCategoryChanged
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
704 connect(m_ui
->comboCategoryChanged
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
705 connect(m_ui
->comboCategoryDefaultPathChanged
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
707 connect(m_ui
->checkUseSubcategories
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
708 connect(m_ui
->checkUseCategoryPaths
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
710 connect(m_ui
->textSavePath
, &FileSystemPathEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
711 connect(m_ui
->textDownloadPath
, &FileSystemPathEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
713 connect(m_ui
->checkExportDir
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
714 connect(m_ui
->checkExportDir
, &QAbstractButton::toggled
, m_ui
->textExportDir
, &QWidget::setEnabled
);
715 connect(m_ui
->checkExportDirFin
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
716 connect(m_ui
->checkExportDirFin
, &QAbstractButton::toggled
, m_ui
->textExportDirFin
, &QWidget::setEnabled
);
717 connect(m_ui
->textExportDir
, &FileSystemPathEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
718 connect(m_ui
->textExportDirFin
, &FileSystemPathEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
719 connect(m_ui
->checkUseDownloadPath
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
720 connect(m_ui
->checkUseDownloadPath
, &QAbstractButton::toggled
, m_ui
->textDownloadPath
, &QWidget::setEnabled
);
722 connect(m_ui
->addWatchedFolderButton
, &QAbstractButton::clicked
, this, &ThisType::enableApplyButton
);
724 connect(m_ui
->groupExcludedFileNames
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
725 connect(m_ui
->textExcludedFileNames
, &QPlainTextEdit::textChanged
, this, &ThisType::enableApplyButton
);
726 connect(m_ui
->removeWatchedFolderButton
, &QAbstractButton::clicked
, this, &ThisType::enableApplyButton
);
728 connect(m_ui
->groupMailNotification
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
729 connect(m_ui
->senderEmailTxt
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
730 connect(m_ui
->lineEditDestEmail
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
731 connect(m_ui
->lineEditSmtpServer
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
732 connect(m_ui
->checkSmtpSSL
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
733 connect(m_ui
->groupMailNotifAuth
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
734 connect(m_ui
->mailNotifUsername
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
735 connect(m_ui
->mailNotifPassword
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
736 connect(m_ui
->sendTestEmail
, &QPushButton::clicked
, this, [this]
738 app()->sendTestEmail();
739 QMessageBox::information(this, tr("Test email"), tr("Attempted to send email. Check your inbox to confirm success"));
742 connect(m_ui
->groupBoxRunOnAdded
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
743 connect(m_ui
->lineEditRunOnAdded
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
744 connect(m_ui
->groupBoxRunOnFinished
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
745 connect(m_ui
->lineEditRunOnFinished
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
746 connect(m_ui
->autoRunConsole
, &QCheckBox::toggled
, this, &ThisType::enableApplyButton
);
749 void OptionsDialog::saveDownloadsTabOptions() const
751 auto *pref
= Preferences::instance();
752 auto *session
= BitTorrent::Session::instance();
754 pref
->setAddNewTorrentDialogEnabled(useAdditionDialog());
755 pref
->setAddNewTorrentDialogTopLevel(m_ui
->checkAdditionDialogFront
->isChecked());
757 session
->setTorrentContentLayout(static_cast<BitTorrent::TorrentContentLayout
>(m_ui
->contentLayoutComboBox
->currentIndex()));
759 session
->setAddTorrentToQueueTop(m_ui
->checkAddToQueueTop
->isChecked());
760 session
->setAddTorrentStopped(addTorrentsStopped());
761 session
->setTorrentStopCondition(m_ui
->stopConditionComboBox
->currentData().value
<BitTorrent::Torrent::StopCondition
>());
762 TorrentFileGuard::setAutoDeleteMode(!m_ui
->deleteTorrentBox
->isChecked() ? TorrentFileGuard::Never
763 : !m_ui
->deleteCancelledTorrentBox
->isChecked() ? TorrentFileGuard::IfAdded
764 : TorrentFileGuard::Always
);
765 session
->setMergeTrackersEnabled(m_ui
->checkMergeTrackers
->isChecked());
766 if (m_ui
->checkConfirmMergeTrackers
->isEnabled())
767 pref
->setConfirmMergeTrackers(m_ui
->checkConfirmMergeTrackers
->isChecked());
769 session
->setPreallocationEnabled(preAllocateAllFiles());
770 session
->setAppendExtensionEnabled(m_ui
->checkAppendqB
->isChecked());
771 session
->setUnwantedFolderEnabled(m_ui
->checkUnwantedFolder
->isChecked());
772 pref
->setRecursiveDownloadEnabled(m_ui
->checkRecursiveDownload
->isChecked());
774 session
->setAutoTMMDisabledByDefault(m_ui
->comboSavingMode
->currentIndex() == 0);
775 session
->setDisableAutoTMMWhenCategoryChanged(m_ui
->comboTorrentCategoryChanged
->currentIndex() == 1);
776 session
->setDisableAutoTMMWhenCategorySavePathChanged(m_ui
->comboCategoryChanged
->currentIndex() == 1);
777 session
->setDisableAutoTMMWhenDefaultSavePathChanged(m_ui
->comboCategoryDefaultPathChanged
->currentIndex() == 1);
779 session
->setSubcategoriesEnabled(m_ui
->checkUseSubcategories
->isChecked());
780 session
->setUseCategoryPathsInManualMode(m_ui
->checkUseCategoryPaths
->isChecked());
782 session
->setSavePath(Path(m_ui
->textSavePath
->selectedPath()));
783 session
->setDownloadPathEnabled(m_ui
->checkUseDownloadPath
->isChecked());
784 session
->setDownloadPath(m_ui
->textDownloadPath
->selectedPath());
785 session
->setTorrentExportDirectory(getTorrentExportDir());
786 session
->setFinishedTorrentExportDirectory(getFinishedTorrentExportDir());
788 auto *watchedFoldersModel
= static_cast<WatchedFoldersModel
*>(m_ui
->scanFoldersView
->model());
789 watchedFoldersModel
->apply();
791 session
->setExcludedFileNamesEnabled(m_ui
->groupExcludedFileNames
->isChecked());
792 session
->setExcludedFileNames(m_ui
->textExcludedFileNames
->toPlainText().split(u
'\n', Qt::SkipEmptyParts
));
794 pref
->setMailNotificationEnabled(m_ui
->groupMailNotification
->isChecked());
795 pref
->setMailNotificationSender(m_ui
->senderEmailTxt
->text());
796 pref
->setMailNotificationEmail(m_ui
->lineEditDestEmail
->text());
797 pref
->setMailNotificationSMTP(m_ui
->lineEditSmtpServer
->text());
798 pref
->setMailNotificationSMTPSSL(m_ui
->checkSmtpSSL
->isChecked());
799 pref
->setMailNotificationSMTPAuth(m_ui
->groupMailNotifAuth
->isChecked());
800 pref
->setMailNotificationSMTPUsername(m_ui
->mailNotifUsername
->text());
801 pref
->setMailNotificationSMTPPassword(m_ui
->mailNotifPassword
->text());
803 pref
->setAutoRunOnTorrentAddedEnabled(m_ui
->groupBoxRunOnAdded
->isChecked());
804 pref
->setAutoRunOnTorrentAddedProgram(m_ui
->lineEditRunOnAdded
->text().trimmed());
805 pref
->setAutoRunOnTorrentFinishedEnabled(m_ui
->groupBoxRunOnFinished
->isChecked());
806 pref
->setAutoRunOnTorrentFinishedProgram(m_ui
->lineEditRunOnFinished
->text().trimmed());
807 #if defined(Q_OS_WIN)
808 pref
->setAutoRunConsoleEnabled(m_ui
->autoRunConsole
->isChecked());
812 void OptionsDialog::loadConnectionTabOptions()
814 const auto *session
= BitTorrent::Session::instance();
816 m_ui
->comboProtocol
->setCurrentIndex(static_cast<int>(session
->btProtocol()));
817 m_ui
->spinPort
->setValue(session
->port());
818 m_ui
->checkUPnP
->setChecked(Net::PortForwarder::instance()->isEnabled());
820 int intValue
= session
->maxConnections();
824 m_ui
->checkMaxConnections
->setChecked(true);
825 m_ui
->spinMaxConnec
->setEnabled(true);
826 m_ui
->spinMaxConnec
->setValue(intValue
);
831 m_ui
->checkMaxConnections
->setChecked(false);
832 m_ui
->spinMaxConnec
->setEnabled(false);
834 intValue
= session
->maxConnectionsPerTorrent();
838 m_ui
->checkMaxConnectionsPerTorrent
->setChecked(true);
839 m_ui
->spinMaxConnecPerTorrent
->setEnabled(true);
840 m_ui
->spinMaxConnecPerTorrent
->setValue(intValue
);
845 m_ui
->checkMaxConnectionsPerTorrent
->setChecked(false);
846 m_ui
->spinMaxConnecPerTorrent
->setEnabled(false);
848 intValue
= session
->maxUploads();
852 m_ui
->checkMaxUploads
->setChecked(true);
853 m_ui
->spinMaxUploads
->setEnabled(true);
854 m_ui
->spinMaxUploads
->setValue(intValue
);
859 m_ui
->checkMaxUploads
->setChecked(false);
860 m_ui
->spinMaxUploads
->setEnabled(false);
862 intValue
= session
->maxUploadsPerTorrent();
866 m_ui
->checkMaxUploadsPerTorrent
->setChecked(true);
867 m_ui
->spinMaxUploadsPerTorrent
->setEnabled(true);
868 m_ui
->spinMaxUploadsPerTorrent
->setValue(intValue
);
873 m_ui
->checkMaxUploadsPerTorrent
->setChecked(false);
874 m_ui
->spinMaxUploadsPerTorrent
->setEnabled(false);
877 #if defined(QBT_USES_LIBTORRENT2) && TORRENT_USE_I2P
878 m_ui
->textI2PHost
->setText(session
->I2PAddress());
879 m_ui
->spinI2PPort
->setValue(session
->I2PPort());
880 m_ui
->checkI2PMixed
->setChecked(session
->I2PMixedMode());
881 m_ui
->groupI2P
->setChecked(session
->isI2PEnabled());
883 m_ui
->groupI2P
->hide();
886 const auto *proxyConfigManager
= Net::ProxyConfigurationManager::instance();
887 const Net::ProxyConfiguration proxyConf
= proxyConfigManager
->proxyConfiguration();
889 m_ui
->comboProxyType
->addItem(tr("(None)"), QVariant::fromValue(Net::ProxyType::None
));
890 m_ui
->comboProxyType
->addItem(tr("SOCKS4"), QVariant::fromValue(Net::ProxyType::SOCKS4
));
891 m_ui
->comboProxyType
->addItem(tr("SOCKS5"), QVariant::fromValue(Net::ProxyType::SOCKS5
));
892 m_ui
->comboProxyType
->addItem(tr("HTTP"), QVariant::fromValue(Net::ProxyType::HTTP
));
893 m_ui
->comboProxyType
->setCurrentIndex(m_ui
->comboProxyType
->findData(QVariant::fromValue(proxyConf
.type
)));
894 adjustProxyOptions();
896 m_ui
->textProxyIP
->setText(proxyConf
.ip
);
897 m_ui
->spinProxyPort
->setValue(proxyConf
.port
);
898 m_ui
->textProxyUsername
->setText(proxyConf
.username
);
899 m_ui
->textProxyPassword
->setText(proxyConf
.password
);
900 m_ui
->checkProxyAuth
->setChecked(proxyConf
.authEnabled
);
901 m_ui
->checkProxyHostnameLookup
->setChecked(proxyConf
.hostnameLookupEnabled
);
903 m_ui
->checkProxyPeerConnections
->setChecked(session
->isProxyPeerConnectionsEnabled());
904 m_ui
->checkProxyBitTorrent
->setChecked(Preferences::instance()->useProxyForBT());
905 m_ui
->checkProxyRSS
->setChecked(Preferences::instance()->useProxyForRSS());
906 m_ui
->checkProxyMisc
->setChecked(Preferences::instance()->useProxyForGeneralPurposes());
908 m_ui
->checkIPFilter
->setChecked(session
->isIPFilteringEnabled());
909 m_ui
->textFilterPath
->setDialogCaption(tr("Choose an IP filter file"));
910 m_ui
->textFilterPath
->setEnabled(m_ui
->checkIPFilter
->isChecked());
911 m_ui
->textFilterPath
->setFileNameFilter(tr("All supported filters") + u
" (*.dat *.p2p *.p2b);;.dat (*.dat);;.p2p (*.p2p);;.p2b (*.p2b)");
912 m_ui
->textFilterPath
->setSelectedPath(session
->IPFilterFile());
914 m_ui
->IpFilterRefreshBtn
->setIcon(UIThemeManager::instance()->getIcon(u
"view-refresh"_s
));
915 m_ui
->IpFilterRefreshBtn
->setEnabled(m_ui
->checkIPFilter
->isChecked());
916 m_ui
->checkIpFilterTrackers
->setChecked(session
->isTrackerFilteringEnabled());
918 connect(m_ui
->comboProtocol
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
919 connect(m_ui
->spinPort
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
920 connect(m_ui
->checkUPnP
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
922 connect(m_ui
->checkMaxConnections
, &QAbstractButton::toggled
, m_ui
->spinMaxConnec
, &QWidget::setEnabled
);
923 connect(m_ui
->checkMaxConnections
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
924 connect(m_ui
->checkMaxConnectionsPerTorrent
, &QAbstractButton::toggled
, m_ui
->spinMaxConnecPerTorrent
, &QWidget::setEnabled
);
925 connect(m_ui
->checkMaxConnectionsPerTorrent
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
926 connect(m_ui
->checkMaxUploads
, &QAbstractButton::toggled
, m_ui
->spinMaxUploads
, &QWidget::setEnabled
);
927 connect(m_ui
->checkMaxUploads
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
928 connect(m_ui
->checkMaxUploadsPerTorrent
, &QAbstractButton::toggled
, m_ui
->spinMaxUploadsPerTorrent
, &QWidget::setEnabled
);
929 connect(m_ui
->checkMaxUploadsPerTorrent
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
930 connect(m_ui
->spinMaxConnec
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
931 connect(m_ui
->spinMaxConnecPerTorrent
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
932 connect(m_ui
->spinMaxUploads
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
933 connect(m_ui
->spinMaxUploadsPerTorrent
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
935 connect(m_ui
->comboProxyType
, qComboBoxCurrentIndexChanged
, this, &ThisType::adjustProxyOptions
);
936 connect(m_ui
->comboProxyType
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
937 connect(m_ui
->textProxyIP
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
938 connect(m_ui
->spinProxyPort
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
940 #if defined(QBT_USES_LIBTORRENT2) && TORRENT_USE_I2P
941 connect(m_ui
->textI2PHost
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
942 connect(m_ui
->spinI2PPort
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
943 connect(m_ui
->checkI2PMixed
, &QCheckBox::toggled
, this, &ThisType::enableApplyButton
);
944 connect(m_ui
->groupI2P
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
947 connect(m_ui
->checkProxyBitTorrent
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
948 connect(m_ui
->checkProxyBitTorrent
, &QGroupBox::toggled
, this, &ThisType::adjustProxyOptions
);
949 connect(m_ui
->checkProxyPeerConnections
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
950 connect(m_ui
->checkProxyHostnameLookup
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
951 connect(m_ui
->checkProxyRSS
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
952 connect(m_ui
->checkProxyMisc
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
954 connect(m_ui
->checkProxyAuth
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
955 connect(m_ui
->textProxyUsername
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
956 connect(m_ui
->textProxyPassword
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
958 connect(m_ui
->checkIPFilter
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
959 connect(m_ui
->checkIPFilter
, &QAbstractButton::toggled
, m_ui
->textFilterPath
, &QWidget::setEnabled
);
960 connect(m_ui
->checkIPFilter
, &QAbstractButton::toggled
, m_ui
->IpFilterRefreshBtn
, &QWidget::setEnabled
);
961 connect(m_ui
->textFilterPath
, &FileSystemPathEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
962 connect(m_ui
->checkIpFilterTrackers
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
965 void OptionsDialog::saveConnectionTabOptions() const
967 auto *session
= BitTorrent::Session::instance();
969 session
->setBTProtocol(static_cast<BitTorrent::BTProtocol
>(m_ui
->comboProtocol
->currentIndex()));
970 session
->setPort(getPort());
971 Net::PortForwarder::instance()->setEnabled(isUPnPEnabled());
973 session
->setMaxConnections(getMaxConnections());
974 session
->setMaxConnectionsPerTorrent(getMaxConnectionsPerTorrent());
975 session
->setMaxUploads(getMaxUploads());
976 session
->setMaxUploadsPerTorrent(getMaxUploadsPerTorrent());
978 #if defined(QBT_USES_LIBTORRENT2) && TORRENT_USE_I2P
979 session
->setI2PEnabled(m_ui
->groupI2P
->isChecked());
980 session
->setI2PAddress(m_ui
->textI2PHost
->text().trimmed());
981 session
->setI2PPort(m_ui
->spinI2PPort
->value());
982 session
->setI2PMixedMode(m_ui
->checkI2PMixed
->isChecked());
985 auto *proxyConfigManager
= Net::ProxyConfigurationManager::instance();
986 Net::ProxyConfiguration proxyConf
;
987 proxyConf
.type
= getProxyType();
988 proxyConf
.ip
= getProxyIp();
989 proxyConf
.port
= getProxyPort();
990 proxyConf
.authEnabled
= m_ui
->checkProxyAuth
->isChecked();
991 proxyConf
.username
= getProxyUsername();
992 proxyConf
.password
= getProxyPassword();
993 proxyConf
.hostnameLookupEnabled
= m_ui
->checkProxyHostnameLookup
->isChecked();
994 proxyConfigManager
->setProxyConfiguration(proxyConf
);
996 Preferences::instance()->setUseProxyForBT(m_ui
->checkProxyBitTorrent
->isChecked());
997 Preferences::instance()->setUseProxyForRSS(m_ui
->checkProxyRSS
->isChecked());
998 Preferences::instance()->setUseProxyForGeneralPurposes(m_ui
->checkProxyMisc
->isChecked());
1000 session
->setProxyPeerConnectionsEnabled(m_ui
->checkProxyPeerConnections
->isChecked());
1003 session
->setIPFilteringEnabled(isIPFilteringEnabled());
1004 session
->setTrackerFilteringEnabled(m_ui
->checkIpFilterTrackers
->isChecked());
1005 session
->setIPFilterFile(m_ui
->textFilterPath
->selectedPath());
1008 void OptionsDialog::loadSpeedTabOptions()
1010 const auto *pref
= Preferences::instance();
1011 const auto *session
= BitTorrent::Session::instance();
1013 m_ui
->labelGlobalRate
->setPixmap(UIThemeManager::instance()->getScaledPixmap(u
"slow_off"_s
, Utils::Gui::mediumIconSize(this).height()));
1014 m_ui
->spinUploadLimit
->setValue(session
->globalUploadSpeedLimit() / 1024);
1015 m_ui
->spinDownloadLimit
->setValue(session
->globalDownloadSpeedLimit() / 1024);
1017 m_ui
->labelAltRate
->setPixmap(UIThemeManager::instance()->getScaledPixmap(u
"slow"_s
, Utils::Gui::mediumIconSize(this).height()));
1018 m_ui
->spinUploadLimitAlt
->setValue(session
->altGlobalUploadSpeedLimit() / 1024);
1019 m_ui
->spinDownloadLimitAlt
->setValue(session
->altGlobalDownloadSpeedLimit() / 1024);
1021 m_ui
->comboBoxScheduleDays
->addItems(translatedWeekdayNames());
1023 m_ui
->groupBoxSchedule
->setChecked(session
->isBandwidthSchedulerEnabled());
1024 m_ui
->timeEditScheduleFrom
->setTime(pref
->getSchedulerStartTime());
1025 m_ui
->timeEditScheduleTo
->setTime(pref
->getSchedulerEndTime());
1026 m_ui
->comboBoxScheduleDays
->setCurrentIndex(static_cast<int>(pref
->getSchedulerDays()));
1028 m_ui
->checkLimituTPConnections
->setChecked(session
->isUTPRateLimited());
1029 m_ui
->checkLimitTransportOverhead
->setChecked(session
->includeOverheadInLimits());
1030 m_ui
->checkLimitLocalPeerRate
->setChecked(!session
->ignoreLimitsOnLAN());
1032 connect(m_ui
->spinUploadLimit
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1033 connect(m_ui
->spinDownloadLimit
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1035 connect(m_ui
->spinUploadLimitAlt
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1036 connect(m_ui
->spinDownloadLimitAlt
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1038 connect(m_ui
->groupBoxSchedule
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1039 connect(m_ui
->timeEditScheduleFrom
, &QDateTimeEdit::timeChanged
, this, &ThisType::enableApplyButton
);
1040 connect(m_ui
->timeEditScheduleTo
, &QDateTimeEdit::timeChanged
, this, &ThisType::enableApplyButton
);
1041 connect(m_ui
->comboBoxScheduleDays
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
1043 connect(m_ui
->checkLimituTPConnections
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1044 connect(m_ui
->checkLimitTransportOverhead
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1045 connect(m_ui
->checkLimitLocalPeerRate
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1048 void OptionsDialog::saveSpeedTabOptions() const
1050 auto *pref
= Preferences::instance();
1051 auto *session
= BitTorrent::Session::instance();
1053 session
->setGlobalUploadSpeedLimit(m_ui
->spinUploadLimit
->value() * 1024);
1054 session
->setGlobalDownloadSpeedLimit(m_ui
->spinDownloadLimit
->value() * 1024);
1056 session
->setAltGlobalUploadSpeedLimit(m_ui
->spinUploadLimitAlt
->value() * 1024);
1057 session
->setAltGlobalDownloadSpeedLimit(m_ui
->spinDownloadLimitAlt
->value() * 1024);
1059 session
->setBandwidthSchedulerEnabled(m_ui
->groupBoxSchedule
->isChecked());
1060 pref
->setSchedulerStartTime(m_ui
->timeEditScheduleFrom
->time());
1061 pref
->setSchedulerEndTime(m_ui
->timeEditScheduleTo
->time());
1062 pref
->setSchedulerDays(static_cast<Scheduler::Days
>(m_ui
->comboBoxScheduleDays
->currentIndex()));
1064 session
->setUTPRateLimited(m_ui
->checkLimituTPConnections
->isChecked());
1065 session
->setIncludeOverheadInLimits(m_ui
->checkLimitTransportOverhead
->isChecked());
1066 session
->setIgnoreLimitsOnLAN(!m_ui
->checkLimitLocalPeerRate
->isChecked());
1069 void OptionsDialog::loadBittorrentTabOptions()
1071 const auto *session
= BitTorrent::Session::instance();
1073 m_ui
->checkDHT
->setChecked(session
->isDHTEnabled());
1074 m_ui
->checkPeX
->setChecked(session
->isPeXEnabled());
1075 m_ui
->checkLSD
->setChecked(session
->isLSDEnabled());
1076 m_ui
->comboEncryption
->setCurrentIndex(session
->encryption());
1077 m_ui
->checkAnonymousMode
->setChecked(session
->isAnonymousModeEnabled());
1079 m_ui
->spinBoxMaxActiveCheckingTorrents
->setValue(session
->maxActiveCheckingTorrents());
1081 m_ui
->checkEnableQueueing
->setChecked(session
->isQueueingSystemEnabled());
1082 m_ui
->spinMaxActiveDownloads
->setValue(session
->maxActiveDownloads());
1083 m_ui
->spinMaxActiveUploads
->setValue(session
->maxActiveUploads());
1084 m_ui
->spinMaxActiveTorrents
->setValue(session
->maxActiveTorrents());
1086 m_ui
->checkIgnoreSlowTorrentsForQueueing
->setChecked(session
->ignoreSlowTorrentsForQueueing());
1087 const QString slowTorrentsExplanation
= u
"<html><body><p>"
1088 + tr("A torrent will be considered slow if its download and upload rates stay below these values for \"Torrent inactivity timer\" seconds")
1089 + u
"</p></body></html>";
1090 m_ui
->labelDownloadRateForSlowTorrents
->setToolTip(slowTorrentsExplanation
);
1091 m_ui
->labelUploadRateForSlowTorrents
->setToolTip(slowTorrentsExplanation
);
1092 m_ui
->labelSlowTorrentInactivityTimer
->setToolTip(slowTorrentsExplanation
);
1093 m_ui
->spinDownloadRateForSlowTorrents
->setValue(session
->downloadRateForSlowTorrents());
1094 m_ui
->spinUploadRateForSlowTorrents
->setValue(session
->uploadRateForSlowTorrents());
1095 m_ui
->spinSlowTorrentsInactivityTimer
->setValue(session
->slowTorrentsInactivityTimer());
1097 if (session
->globalMaxRatio() >= 0.)
1100 m_ui
->checkMaxRatio
->setChecked(true);
1101 m_ui
->spinMaxRatio
->setEnabled(true);
1102 m_ui
->comboRatioLimitAct
->setEnabled(true);
1103 m_ui
->spinMaxRatio
->setValue(session
->globalMaxRatio());
1108 m_ui
->checkMaxRatio
->setChecked(false);
1109 m_ui
->spinMaxRatio
->setEnabled(false);
1111 if (session
->globalMaxSeedingMinutes() >= 0)
1114 m_ui
->checkMaxSeedingMinutes
->setChecked(true);
1115 m_ui
->spinMaxSeedingMinutes
->setEnabled(true);
1116 m_ui
->spinMaxSeedingMinutes
->setValue(session
->globalMaxSeedingMinutes());
1121 m_ui
->checkMaxSeedingMinutes
->setChecked(false);
1122 m_ui
->spinMaxSeedingMinutes
->setEnabled(false);
1124 if (session
->globalMaxInactiveSeedingMinutes() >= 0)
1127 m_ui
->checkMaxInactiveSeedingMinutes
->setChecked(true);
1128 m_ui
->spinMaxInactiveSeedingMinutes
->setEnabled(true);
1129 m_ui
->spinMaxInactiveSeedingMinutes
->setValue(session
->globalMaxInactiveSeedingMinutes());
1134 m_ui
->checkMaxInactiveSeedingMinutes
->setChecked(false);
1135 m_ui
->spinMaxInactiveSeedingMinutes
->setEnabled(false);
1137 m_ui
->comboRatioLimitAct
->setEnabled((session
->globalMaxSeedingMinutes() >= 0) || (session
->globalMaxRatio() >= 0.) || (session
->globalMaxInactiveSeedingMinutes() >= 0));
1139 const QHash
<BitTorrent::ShareLimitAction
, int> actIndex
=
1141 {BitTorrent::ShareLimitAction::Stop
, 0},
1142 {BitTorrent::ShareLimitAction::Remove
, 1},
1143 {BitTorrent::ShareLimitAction::RemoveWithContent
, 2},
1144 {BitTorrent::ShareLimitAction::EnableSuperSeeding
, 3}
1146 m_ui
->comboRatioLimitAct
->setCurrentIndex(actIndex
.value(session
->shareLimitAction()));
1148 m_ui
->checkEnableAddTrackers
->setChecked(session
->isAddTrackersEnabled());
1149 m_ui
->textTrackers
->setPlainText(session
->additionalTrackers());
1151 connect(m_ui
->checkDHT
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1152 connect(m_ui
->checkPeX
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1153 connect(m_ui
->checkLSD
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1154 connect(m_ui
->comboEncryption
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
1155 connect(m_ui
->checkAnonymousMode
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1157 connect(m_ui
->spinBoxMaxActiveCheckingTorrents
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1159 connect(m_ui
->checkEnableQueueing
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1160 connect(m_ui
->spinMaxActiveDownloads
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1161 connect(m_ui
->spinMaxActiveUploads
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1162 connect(m_ui
->spinMaxActiveTorrents
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1163 connect(m_ui
->checkIgnoreSlowTorrentsForQueueing
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1164 connect(m_ui
->spinDownloadRateForSlowTorrents
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1165 connect(m_ui
->spinUploadRateForSlowTorrents
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1166 connect(m_ui
->spinSlowTorrentsInactivityTimer
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1168 connect(m_ui
->checkMaxRatio
, &QAbstractButton::toggled
, m_ui
->spinMaxRatio
, &QWidget::setEnabled
);
1169 connect(m_ui
->checkMaxRatio
, &QAbstractButton::toggled
, this, &ThisType::toggleComboRatioLimitAct
);
1170 connect(m_ui
->checkMaxRatio
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1171 connect(m_ui
->spinMaxRatio
, qOverload
<double>(&QDoubleSpinBox::valueChanged
),this, &ThisType::enableApplyButton
);
1172 connect(m_ui
->comboRatioLimitAct
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
1173 connect(m_ui
->checkMaxSeedingMinutes
, &QAbstractButton::toggled
, m_ui
->spinMaxSeedingMinutes
, &QWidget::setEnabled
);
1174 connect(m_ui
->checkMaxSeedingMinutes
, &QAbstractButton::toggled
, this, &ThisType::toggleComboRatioLimitAct
);
1175 connect(m_ui
->checkMaxSeedingMinutes
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1176 connect(m_ui
->spinMaxSeedingMinutes
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1177 connect(m_ui
->checkMaxInactiveSeedingMinutes
, &QAbstractButton::toggled
, m_ui
->spinMaxInactiveSeedingMinutes
, &QWidget::setEnabled
);
1178 connect(m_ui
->checkMaxInactiveSeedingMinutes
, &QAbstractButton::toggled
, this, &ThisType::toggleComboRatioLimitAct
);
1179 connect(m_ui
->checkMaxInactiveSeedingMinutes
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1180 connect(m_ui
->spinMaxInactiveSeedingMinutes
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1182 connect(m_ui
->checkEnableAddTrackers
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1183 connect(m_ui
->textTrackers
, &QPlainTextEdit::textChanged
, this, &ThisType::enableApplyButton
);
1186 void OptionsDialog::saveBittorrentTabOptions() const
1188 auto *session
= BitTorrent::Session::instance();
1190 session
->setDHTEnabled(isDHTEnabled());
1191 session
->setPeXEnabled(m_ui
->checkPeX
->isChecked());
1192 session
->setLSDEnabled(isLSDEnabled());
1193 session
->setEncryption(getEncryptionSetting());
1194 session
->setAnonymousModeEnabled(m_ui
->checkAnonymousMode
->isChecked());
1196 session
->setMaxActiveCheckingTorrents(m_ui
->spinBoxMaxActiveCheckingTorrents
->value());
1198 session
->setQueueingSystemEnabled(isQueueingSystemEnabled());
1199 session
->setMaxActiveDownloads(m_ui
->spinMaxActiveDownloads
->value());
1200 session
->setMaxActiveUploads(m_ui
->spinMaxActiveUploads
->value());
1201 session
->setMaxActiveTorrents(m_ui
->spinMaxActiveTorrents
->value());
1202 session
->setIgnoreSlowTorrentsForQueueing(m_ui
->checkIgnoreSlowTorrentsForQueueing
->isChecked());
1203 session
->setDownloadRateForSlowTorrents(m_ui
->spinDownloadRateForSlowTorrents
->value());
1204 session
->setUploadRateForSlowTorrents(m_ui
->spinUploadRateForSlowTorrents
->value());
1205 session
->setSlowTorrentsInactivityTimer(m_ui
->spinSlowTorrentsInactivityTimer
->value());
1207 session
->setGlobalMaxRatio(getMaxRatio());
1208 session
->setGlobalMaxSeedingMinutes(getMaxSeedingMinutes());
1209 session
->setGlobalMaxInactiveSeedingMinutes(getMaxInactiveSeedingMinutes());
1210 const QList
<BitTorrent::ShareLimitAction
> actIndex
=
1212 BitTorrent::ShareLimitAction::Stop
,
1213 BitTorrent::ShareLimitAction::Remove
,
1214 BitTorrent::ShareLimitAction::RemoveWithContent
,
1215 BitTorrent::ShareLimitAction::EnableSuperSeeding
1217 session
->setShareLimitAction(actIndex
.value(m_ui
->comboRatioLimitAct
->currentIndex()));
1219 session
->setAddTrackersEnabled(m_ui
->checkEnableAddTrackers
->isChecked());
1220 session
->setAdditionalTrackers(m_ui
->textTrackers
->toPlainText());
1223 void OptionsDialog::loadRSSTabOptions()
1225 const auto *rssSession
= RSS::Session::instance();
1226 const auto *autoDownloader
= RSS::AutoDownloader::instance();
1228 m_ui
->checkRSSEnable
->setChecked(rssSession
->isProcessingEnabled());
1229 m_ui
->spinRSSRefreshInterval
->setValue(rssSession
->refreshInterval());
1230 m_ui
->spinRSSFetchDelay
->setValue(rssSession
->fetchDelay().count());
1231 m_ui
->spinRSSMaxArticlesPerFeed
->setValue(rssSession
->maxArticlesPerFeed());
1232 m_ui
->checkRSSAutoDownloaderEnable
->setChecked(autoDownloader
->isProcessingEnabled());
1233 m_ui
->textSmartEpisodeFilters
->setPlainText(autoDownloader
->smartEpisodeFilters().join(u
'\n'));
1234 m_ui
->checkSmartFilterDownloadRepacks
->setChecked(autoDownloader
->downloadRepacks());
1236 connect(m_ui
->checkRSSEnable
, &QCheckBox::toggled
, this, &OptionsDialog::enableApplyButton
);
1237 connect(m_ui
->checkRSSAutoDownloaderEnable
, &QCheckBox::toggled
, this, &OptionsDialog::enableApplyButton
);
1238 connect(m_ui
->btnEditRules
, &QPushButton::clicked
, this, [this]()
1240 auto *downloader
= new AutomatedRssDownloader(this);
1241 downloader
->setAttribute(Qt::WA_DeleteOnClose
);
1244 connect(m_ui
->textSmartEpisodeFilters
, &QPlainTextEdit::textChanged
, this, &OptionsDialog::enableApplyButton
);
1245 connect(m_ui
->checkSmartFilterDownloadRepacks
, &QCheckBox::toggled
, this, &OptionsDialog::enableApplyButton
);
1246 connect(m_ui
->spinRSSRefreshInterval
, qSpinBoxValueChanged
, this, &OptionsDialog::enableApplyButton
);
1247 connect(m_ui
->spinRSSFetchDelay
, qSpinBoxValueChanged
, this, &OptionsDialog::enableApplyButton
);
1248 connect(m_ui
->spinRSSMaxArticlesPerFeed
, qSpinBoxValueChanged
, this, &OptionsDialog::enableApplyButton
);
1251 void OptionsDialog::saveRSSTabOptions() const
1253 auto *rssSession
= RSS::Session::instance();
1254 auto *autoDownloader
= RSS::AutoDownloader::instance();
1256 rssSession
->setProcessingEnabled(m_ui
->checkRSSEnable
->isChecked());
1257 rssSession
->setRefreshInterval(m_ui
->spinRSSRefreshInterval
->value());
1258 rssSession
->setFetchDelay(std::chrono::seconds(m_ui
->spinRSSFetchDelay
->value()));
1259 rssSession
->setMaxArticlesPerFeed(m_ui
->spinRSSMaxArticlesPerFeed
->value());
1260 autoDownloader
->setProcessingEnabled(m_ui
->checkRSSAutoDownloaderEnable
->isChecked());
1261 autoDownloader
->setSmartEpisodeFilters(m_ui
->textSmartEpisodeFilters
->toPlainText().split(u
'\n', Qt::SkipEmptyParts
));
1262 autoDownloader
->setDownloadRepacks(m_ui
->checkSmartFilterDownloadRepacks
->isChecked());
1265 #ifndef DISABLE_WEBUI
1266 void OptionsDialog::loadWebUITabOptions()
1268 const auto *pref
= Preferences::instance();
1270 m_ui
->textWebUIHttpsCert
->setMode(FileSystemPathEdit::Mode::FileOpen
);
1271 m_ui
->textWebUIHttpsCert
->setFileNameFilter(tr("Certificate") + u
" (*.cer *.crt *.pem)");
1272 m_ui
->textWebUIHttpsCert
->setDialogCaption(tr("Select certificate"));
1273 m_ui
->textWebUIHttpsKey
->setMode(FileSystemPathEdit::Mode::FileOpen
);
1274 m_ui
->textWebUIHttpsKey
->setFileNameFilter(tr("Private key") + u
" (*.key *.pem)");
1275 m_ui
->textWebUIHttpsKey
->setDialogCaption(tr("Select private key"));
1276 m_ui
->textWebUIRootFolder
->setMode(FileSystemPathEdit::Mode::DirectoryOpen
);
1277 m_ui
->textWebUIRootFolder
->setDialogCaption(tr("Choose Alternative UI files location"));
1279 if (app()->webUI()->isErrored())
1280 m_ui
->labelWebUIError
->setText(tr("WebUI configuration failed. Reason: %1").arg(app()->webUI()->errorMessage()));
1282 m_ui
->labelWebUIError
->hide();
1284 m_ui
->checkWebUI
->setChecked(pref
->isWebUIEnabled());
1285 m_ui
->textWebUIAddress
->setText(pref
->getWebUIAddress());
1286 m_ui
->spinWebUIPort
->setValue(pref
->getWebUIPort());
1287 m_ui
->checkWebUIUPnP
->setChecked(pref
->useUPnPForWebUIPort());
1288 m_ui
->checkWebUIHttps
->setChecked(pref
->isWebUIHttpsEnabled());
1289 webUIHttpsCertChanged(pref
->getWebUIHttpsCertificatePath());
1290 webUIHttpsKeyChanged(pref
->getWebUIHttpsKeyPath());
1291 m_ui
->textWebUIUsername
->setText(pref
->getWebUIUsername());
1292 m_ui
->checkBypassLocalAuth
->setChecked(!pref
->isWebUILocalAuthEnabled());
1293 m_ui
->checkBypassAuthSubnetWhitelist
->setChecked(pref
->isWebUIAuthSubnetWhitelistEnabled());
1294 m_ui
->IPSubnetWhitelistButton
->setEnabled(m_ui
->checkBypassAuthSubnetWhitelist
->isChecked());
1295 m_ui
->spinBanCounter
->setValue(pref
->getWebUIMaxAuthFailCount());
1296 m_ui
->spinBanDuration
->setValue(pref
->getWebUIBanDuration().count());
1297 m_ui
->spinSessionTimeout
->setValue(pref
->getWebUISessionTimeout());
1299 m_ui
->groupAltWebUI
->setChecked(pref
->isAltWebUIEnabled());
1300 m_ui
->textWebUIRootFolder
->setSelectedPath(pref
->getWebUIRootFolder());
1302 m_ui
->checkClickjacking
->setChecked(pref
->isWebUIClickjackingProtectionEnabled());
1303 m_ui
->checkCSRFProtection
->setChecked(pref
->isWebUICSRFProtectionEnabled());
1304 m_ui
->checkSecureCookie
->setChecked(pref
->isWebUISecureCookieEnabled());
1305 m_ui
->groupHostHeaderValidation
->setChecked(pref
->isWebUIHostHeaderValidationEnabled());
1306 m_ui
->textServerDomains
->setText(pref
->getServerDomains());
1307 // Custom HTTP headers
1308 m_ui
->groupWebUIAddCustomHTTPHeaders
->setChecked(pref
->isWebUICustomHTTPHeadersEnabled());
1309 m_ui
->textWebUICustomHTTPHeaders
->setPlainText(pref
->getWebUICustomHTTPHeaders());
1311 m_ui
->groupEnableReverseProxySupport
->setChecked(pref
->isWebUIReverseProxySupportEnabled());
1312 m_ui
->textTrustedReverseProxiesList
->setText(pref
->getWebUITrustedReverseProxiesList());
1314 m_ui
->checkDynDNS
->setChecked(pref
->isDynDNSEnabled());
1315 m_ui
->comboDNSService
->setCurrentIndex(static_cast<int>(pref
->getDynDNSService()));
1316 m_ui
->domainNameTxt
->setText(pref
->getDynDomainName());
1317 m_ui
->DNSUsernameTxt
->setText(pref
->getDynDNSUsername());
1318 m_ui
->DNSPasswordTxt
->setText(pref
->getDynDNSPassword());
1320 connect(m_ui
->checkWebUI
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1321 connect(m_ui
->textWebUIAddress
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
1322 connect(m_ui
->spinWebUIPort
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1323 connect(m_ui
->checkWebUIUPnP
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1324 connect(m_ui
->checkWebUIHttps
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1325 connect(m_ui
->textWebUIHttpsCert
, &FileSystemPathLineEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
1326 connect(m_ui
->textWebUIHttpsCert
, &FileSystemPathLineEdit::selectedPathChanged
, this, &OptionsDialog::webUIHttpsCertChanged
);
1327 connect(m_ui
->textWebUIHttpsKey
, &FileSystemPathLineEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
1328 connect(m_ui
->textWebUIHttpsKey
, &FileSystemPathLineEdit::selectedPathChanged
, this, &OptionsDialog::webUIHttpsKeyChanged
);
1330 connect(m_ui
->textWebUIUsername
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
1331 connect(m_ui
->textWebUIPassword
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
1333 connect(m_ui
->checkBypassLocalAuth
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1334 connect(m_ui
->checkBypassAuthSubnetWhitelist
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1335 connect(m_ui
->checkBypassAuthSubnetWhitelist
, &QAbstractButton::toggled
, m_ui
->IPSubnetWhitelistButton
, &QWidget::setEnabled
);
1336 connect(m_ui
->spinBanCounter
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1337 connect(m_ui
->spinBanDuration
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1338 connect(m_ui
->spinSessionTimeout
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1340 connect(m_ui
->groupAltWebUI
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1341 connect(m_ui
->textWebUIRootFolder
, &FileSystemPathLineEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
1343 connect(m_ui
->checkClickjacking
, &QCheckBox::toggled
, this, &ThisType::enableApplyButton
);
1344 connect(m_ui
->checkCSRFProtection
, &QCheckBox::toggled
, this, &ThisType::enableApplyButton
);
1345 connect(m_ui
->checkSecureCookie
, &QCheckBox::toggled
, this, &ThisType::enableApplyButton
);
1346 connect(m_ui
->groupHostHeaderValidation
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1347 connect(m_ui
->textServerDomains
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
1349 connect(m_ui
->groupWebUIAddCustomHTTPHeaders
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1350 connect(m_ui
->textWebUICustomHTTPHeaders
, &QPlainTextEdit::textChanged
, this, &OptionsDialog::enableApplyButton
);
1352 connect(m_ui
->groupEnableReverseProxySupport
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1353 connect(m_ui
->textTrustedReverseProxiesList
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
1355 connect(m_ui
->checkDynDNS
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1356 connect(m_ui
->comboDNSService
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
1357 connect(m_ui
->domainNameTxt
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
1358 connect(m_ui
->DNSUsernameTxt
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
1359 connect(m_ui
->DNSPasswordTxt
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
1362 void OptionsDialog::saveWebUITabOptions() const
1364 auto *pref
= Preferences::instance();
1366 const bool webUIEnabled
= isWebUIEnabled();
1368 pref
->setWebUIEnabled(webUIEnabled
);
1369 pref
->setWebUIAddress(m_ui
->textWebUIAddress
->text());
1370 pref
->setWebUIPort(m_ui
->spinWebUIPort
->value());
1371 pref
->setUPnPForWebUIPort(m_ui
->checkWebUIUPnP
->isChecked());
1372 pref
->setWebUIHttpsEnabled(m_ui
->checkWebUIHttps
->isChecked());
1373 pref
->setWebUIHttpsCertificatePath(m_ui
->textWebUIHttpsCert
->selectedPath());
1374 pref
->setWebUIHttpsKeyPath(m_ui
->textWebUIHttpsKey
->selectedPath());
1375 pref
->setWebUIMaxAuthFailCount(m_ui
->spinBanCounter
->value());
1376 pref
->setWebUIBanDuration(std::chrono::seconds
{m_ui
->spinBanDuration
->value()});
1377 pref
->setWebUISessionTimeout(m_ui
->spinSessionTimeout
->value());
1379 if (const QString username
= webUIUsername(); isValidWebUIUsername(username
))
1380 pref
->setWebUIUsername(username
);
1381 if (const QString password
= webUIPassword(); isValidWebUIPassword(password
))
1382 pref
->setWebUIPassword(Utils::Password::PBKDF2::generate(password
));
1383 pref
->setWebUILocalAuthEnabled(!m_ui
->checkBypassLocalAuth
->isChecked());
1384 pref
->setWebUIAuthSubnetWhitelistEnabled(m_ui
->checkBypassAuthSubnetWhitelist
->isChecked());
1386 pref
->setAltWebUIEnabled(m_ui
->groupAltWebUI
->isChecked());
1387 pref
->setWebUIRootFolder(m_ui
->textWebUIRootFolder
->selectedPath());
1389 pref
->setWebUIClickjackingProtectionEnabled(m_ui
->checkClickjacking
->isChecked());
1390 pref
->setWebUICSRFProtectionEnabled(m_ui
->checkCSRFProtection
->isChecked());
1391 pref
->setWebUISecureCookieEnabled(m_ui
->checkSecureCookie
->isChecked());
1392 pref
->setWebUIHostHeaderValidationEnabled(m_ui
->groupHostHeaderValidation
->isChecked());
1393 pref
->setServerDomains(m_ui
->textServerDomains
->text());
1394 // Custom HTTP headers
1395 pref
->setWebUICustomHTTPHeadersEnabled(m_ui
->groupWebUIAddCustomHTTPHeaders
->isChecked());
1396 pref
->setWebUICustomHTTPHeaders(m_ui
->textWebUICustomHTTPHeaders
->toPlainText());
1398 pref
->setWebUIReverseProxySupportEnabled(m_ui
->groupEnableReverseProxySupport
->isChecked());
1399 pref
->setWebUITrustedReverseProxiesList(m_ui
->textTrustedReverseProxiesList
->text());
1401 pref
->setDynDNSEnabled(m_ui
->checkDynDNS
->isChecked());
1402 pref
->setDynDNSService(static_cast<DNS::Service
>(m_ui
->comboDNSService
->currentIndex()));
1403 pref
->setDynDomainName(m_ui
->domainNameTxt
->text());
1404 pref
->setDynDNSUsername(m_ui
->DNSUsernameTxt
->text());
1405 pref
->setDynDNSPassword(m_ui
->DNSPasswordTxt
->text());
1407 #endif // DISABLE_WEBUI
1409 void OptionsDialog::initializeLanguageCombo()
1411 // List language files
1412 const QStringList langFiles
= QDir(u
":/lang"_s
).entryList({u
"qbittorrent_*.qm"_s
}, QDir::Files
, QDir::Name
);
1413 for (const QString
&langFile
: langFiles
)
1415 const QString langCode
= QStringView(langFile
).sliced(12).chopped(3).toString(); // remove "qbittorrent_" and ".qm"
1416 m_ui
->comboLanguage
->addItem(Utils::Misc::languageToLocalizedString(langCode
), langCode
);
1420 void OptionsDialog::changePage(QListWidgetItem
*current
, QListWidgetItem
*previous
)
1424 m_ui
->tabOption
->setCurrentIndex(m_ui
->tabSelection
->row(current
));
1427 void OptionsDialog::loadSplitterState()
1429 // width has been modified, use height as width reference instead
1430 const int width
= m_ui
->tabSelection
->item(TAB_UI
)->sizeHint().height() * 2;
1431 const QStringList defaultSizes
= {QString::number(width
), QString::number(m_ui
->hsplitter
->width() - width
)};
1433 QList
<int> splitterSizes
;
1434 for (const QString
&string
: asConst(m_storeHSplitterSize
.get(defaultSizes
)))
1435 splitterSizes
.append(string
.toInt());
1437 m_ui
->hsplitter
->setSizes(splitterSizes
);
1440 void OptionsDialog::showEvent(QShowEvent
*e
)
1442 QDialog::showEvent(e
);
1444 loadSplitterState();
1447 void OptionsDialog::saveOptions() const
1449 auto *pref
= Preferences::instance();
1451 saveBehaviorTabOptions();
1452 saveDownloadsTabOptions();
1453 saveConnectionTabOptions();
1454 saveSpeedTabOptions();
1455 saveBittorrentTabOptions();
1456 saveRSSTabOptions();
1457 #ifndef DISABLE_WEBUI
1458 saveWebUITabOptions();
1460 m_advancedSettings
->saveAdvancedSettings();
1462 // Assume that user changed multiple settings
1463 // so it's best to save immediately
1467 bool OptionsDialog::isIPFilteringEnabled() const
1469 return m_ui
->checkIPFilter
->isChecked();
1472 Net::ProxyType
OptionsDialog::getProxyType() const
1474 return m_ui
->comboProxyType
->currentData().value
<Net::ProxyType
>();
1477 int OptionsDialog::getPort() const
1479 return m_ui
->spinPort
->value();
1482 void OptionsDialog::on_randomButton_clicked()
1484 // Range [1024: 65535]
1485 m_ui
->spinPort
->setValue(Utils::Random::rand(1024, 65535));
1488 int OptionsDialog::getEncryptionSetting() const
1490 return m_ui
->comboEncryption
->currentIndex();
1493 int OptionsDialog::getMaxActiveDownloads() const
1495 return m_ui
->spinMaxActiveDownloads
->value();
1498 int OptionsDialog::getMaxActiveUploads() const
1500 return m_ui
->spinMaxActiveUploads
->value();
1503 int OptionsDialog::getMaxActiveTorrents() const
1505 return m_ui
->spinMaxActiveTorrents
->value();
1508 bool OptionsDialog::isQueueingSystemEnabled() const
1510 return m_ui
->checkEnableQueueing
->isChecked();
1513 bool OptionsDialog::isDHTEnabled() const
1515 return m_ui
->checkDHT
->isChecked();
1518 bool OptionsDialog::isLSDEnabled() const
1520 return m_ui
->checkLSD
->isChecked();
1523 bool OptionsDialog::isUPnPEnabled() const
1525 return m_ui
->checkUPnP
->isChecked();
1528 // Return Share ratio
1529 qreal
OptionsDialog::getMaxRatio() const
1531 if (m_ui
->checkMaxRatio
->isChecked())
1532 return m_ui
->spinMaxRatio
->value();
1536 // Return Seeding Minutes
1537 int OptionsDialog::getMaxSeedingMinutes() const
1539 if (m_ui
->checkMaxSeedingMinutes
->isChecked())
1540 return m_ui
->spinMaxSeedingMinutes
->value();
1544 // Return Inactive Seeding Minutes
1545 int OptionsDialog::getMaxInactiveSeedingMinutes() const
1547 return m_ui
->checkMaxInactiveSeedingMinutes
->isChecked()
1548 ? m_ui
->spinMaxInactiveSeedingMinutes
->value()
1552 // Return max connections number
1553 int OptionsDialog::getMaxConnections() const
1555 if (!m_ui
->checkMaxConnections
->isChecked())
1558 return m_ui
->spinMaxConnec
->value();
1561 int OptionsDialog::getMaxConnectionsPerTorrent() const
1563 if (!m_ui
->checkMaxConnectionsPerTorrent
->isChecked())
1566 return m_ui
->spinMaxConnecPerTorrent
->value();
1569 int OptionsDialog::getMaxUploads() const
1571 if (!m_ui
->checkMaxUploads
->isChecked())
1574 return m_ui
->spinMaxUploads
->value();
1577 int OptionsDialog::getMaxUploadsPerTorrent() const
1579 if (!m_ui
->checkMaxUploadsPerTorrent
->isChecked())
1582 return m_ui
->spinMaxUploadsPerTorrent
->value();
1585 void OptionsDialog::on_buttonBox_accepted()
1587 if (m_applyButton
->isEnabled())
1589 if (!applySettings())
1592 m_applyButton
->setEnabled(false);
1598 bool OptionsDialog::applySettings()
1600 if (!schedTimesOk())
1602 m_ui
->tabSelection
->setCurrentRow(TAB_SPEED
);
1605 #ifndef DISABLE_WEBUI
1606 if (isWebUIEnabled() && !webUIAuthenticationOk())
1608 m_ui
->tabSelection
->setCurrentRow(TAB_WEBUI
);
1611 if (!isAlternativeWebUIPathValid())
1613 m_ui
->tabSelection
->setCurrentRow(TAB_WEBUI
);
1622 void OptionsDialog::on_buttonBox_rejected()
1627 bool OptionsDialog::useAdditionDialog() const
1629 return m_ui
->checkAdditionDialog
->isChecked();
1632 void OptionsDialog::enableApplyButton()
1634 m_applyButton
->setEnabled(true);
1637 void OptionsDialog::toggleComboRatioLimitAct()
1639 // Verify if the share action button must be enabled
1640 m_ui
->comboRatioLimitAct
->setEnabled(m_ui
->checkMaxRatio
->isChecked() || m_ui
->checkMaxSeedingMinutes
->isChecked() || m_ui
->checkMaxInactiveSeedingMinutes
->isChecked());
1643 void OptionsDialog::adjustProxyOptions()
1645 const auto currentProxyType
= m_ui
->comboProxyType
->currentData().value
<Net::ProxyType
>();
1646 const bool isAuthSupported
= ((currentProxyType
== Net::ProxyType::SOCKS5
)
1647 || (currentProxyType
== Net::ProxyType::HTTP
));
1649 m_ui
->checkProxyAuth
->setEnabled(isAuthSupported
);
1651 if (currentProxyType
== Net::ProxyType::None
)
1653 m_ui
->labelProxyTypeIncompatible
->setVisible(false);
1655 m_ui
->lblProxyIP
->setEnabled(false);
1656 m_ui
->textProxyIP
->setEnabled(false);
1657 m_ui
->lblProxyPort
->setEnabled(false);
1658 m_ui
->spinProxyPort
->setEnabled(false);
1660 m_ui
->checkProxyHostnameLookup
->setEnabled(false);
1661 m_ui
->checkProxyRSS
->setEnabled(false);
1662 m_ui
->checkProxyMisc
->setEnabled(false);
1663 m_ui
->checkProxyBitTorrent
->setEnabled(false);
1664 m_ui
->checkProxyPeerConnections
->setEnabled(false);
1668 m_ui
->lblProxyIP
->setEnabled(true);
1669 m_ui
->textProxyIP
->setEnabled(true);
1670 m_ui
->lblProxyPort
->setEnabled(true);
1671 m_ui
->spinProxyPort
->setEnabled(true);
1673 m_ui
->checkProxyBitTorrent
->setEnabled(true);
1674 m_ui
->checkProxyPeerConnections
->setEnabled(true);
1676 if (currentProxyType
== Net::ProxyType::SOCKS4
)
1678 m_ui
->labelProxyTypeIncompatible
->setVisible(true);
1680 m_ui
->checkProxyHostnameLookup
->setEnabled(false);
1681 m_ui
->checkProxyRSS
->setEnabled(false);
1682 m_ui
->checkProxyMisc
->setEnabled(false);
1687 m_ui
->labelProxyTypeIncompatible
->setVisible(false);
1689 m_ui
->checkProxyHostnameLookup
->setEnabled(true);
1690 m_ui
->checkProxyRSS
->setEnabled(true);
1691 m_ui
->checkProxyMisc
->setEnabled(true);
1696 bool OptionsDialog::isSplashScreenDisabled() const
1698 return !m_ui
->checkShowSplash
->isChecked();
1701 void OptionsDialog::initializeStyleCombo()
1704 m_ui
->labelStyleHint
->setText(tr("%1 is recommended for best compatibility with Windows dark mode"
1705 , "Fusion is recommended for best compatibility with Windows dark mode").arg(u
"Fusion"_s
));
1706 m_ui
->comboStyle
->addItem(tr("System", "System default Qt style"), u
"system"_s
);
1707 m_ui
->comboStyle
->setItemData(0, tr("Let Qt decide the style for this system"), Qt::ToolTipRole
);
1708 m_ui
->comboStyle
->insertSeparator(1);
1710 QStringList styleNames
= QStyleFactory::keys();
1711 std::sort(styleNames
.begin(), styleNames
.end(), Utils::Compare::NaturalLessThan
<Qt::CaseInsensitive
>());
1712 m_ui
->comboStyle
->addItems(styleNames
);
1714 const QString prefStyleName
= Preferences::instance()->getStyle();
1715 const QString selectedStyleName
= prefStyleName
.isEmpty() ? QApplication::style()->name() : prefStyleName
;
1716 m_ui
->comboStyle
->setCurrentIndex(m_ui
->comboStyle
->findText(selectedStyleName
, Qt::MatchFixedString
));
1718 m_ui
->labelStyle
->hide();
1719 m_ui
->comboStyle
->hide();
1720 m_ui
->labelStyleHint
->hide();
1721 m_ui
->UISettingsBoxLayout
->removeWidget(m_ui
->labelStyle
);
1722 m_ui
->UISettingsBoxLayout
->removeWidget(m_ui
->comboStyle
);
1723 m_ui
->UISettingsBoxLayout
->removeWidget(m_ui
->labelStyleHint
);
1727 void OptionsDialog::initializeColorSchemeOptions()
1729 #ifdef QBT_HAS_COLORSCHEME_OPTION
1730 m_ui
->comboColorScheme
->addItem(tr("Dark", "Dark color scheme"), QVariant::fromValue(ColorScheme::Dark
));
1731 m_ui
->comboColorScheme
->addItem(tr("Light", "Light color scheme"), QVariant::fromValue(ColorScheme::Light
));
1732 m_ui
->comboColorScheme
->addItem(tr("System", "System color scheme"), QVariant::fromValue(ColorScheme::System
));
1733 m_ui
->comboColorScheme
->setCurrentIndex(m_ui
->comboColorScheme
->findData(QVariant::fromValue(UIThemeManager::instance()->colorScheme())));
1735 m_ui
->labelColorScheme
->hide();
1736 m_ui
->comboColorScheme
->hide();
1737 m_ui
->UISettingsBoxLayout
->removeWidget(m_ui
->labelColorScheme
);
1738 m_ui
->UISettingsBoxLayout
->removeWidget(m_ui
->comboColorScheme
);
1739 m_ui
->UISettingsBoxLayout
->removeItem(m_ui
->spacerColorScheme
);
1744 bool OptionsDialog::WinStartup() const
1746 return m_ui
->checkStartup
->isChecked();
1750 bool OptionsDialog::preAllocateAllFiles() const
1752 return m_ui
->checkPreallocateAll
->isChecked();
1755 bool OptionsDialog::addTorrentsStopped() const
1757 return m_ui
->checkAddStopped
->isChecked();
1761 bool OptionsDialog::isProxyEnabled() const
1763 return m_ui
->comboProxyType
->currentIndex();
1766 QString
OptionsDialog::getProxyIp() const
1768 return m_ui
->textProxyIP
->text().trimmed();
1771 unsigned short OptionsDialog::getProxyPort() const
1773 return m_ui
->spinProxyPort
->value();
1776 QString
OptionsDialog::getProxyUsername() const
1778 QString username
= m_ui
->textProxyUsername
->text().trimmed();
1782 QString
OptionsDialog::getProxyPassword() const
1784 QString password
= m_ui
->textProxyPassword
->text();
1785 password
= password
.trimmed();
1790 QString
OptionsDialog::getLocale() const
1792 return m_ui
->comboLanguage
->itemData(m_ui
->comboLanguage
->currentIndex(), Qt::UserRole
).toString();
1795 void OptionsDialog::setLocale(const QString
&localeStr
)
1798 if (localeStr
.startsWith(u
"eo", Qt::CaseInsensitive
))
1802 else if (localeStr
.startsWith(u
"ltg", Qt::CaseInsensitive
))
1808 QLocale
locale(localeStr
);
1809 if (locale
.language() == QLocale::Uzbek
)
1810 name
= u
"uz@Latn"_s
;
1811 else if (locale
.language() == QLocale::Azerbaijani
)
1812 name
= u
"az@latin"_s
;
1814 name
= locale
.name();
1816 // Attempt to find exact match
1817 int index
= m_ui
->comboLanguage
->findData(name
, Qt::UserRole
);
1820 //Attempt to find a language match without a country
1821 int pos
= name
.indexOf(u
'_');
1824 QString lang
= name
.left(pos
);
1825 index
= m_ui
->comboLanguage
->findData(lang
, Qt::UserRole
);
1830 // Unrecognized, use US English
1831 index
= m_ui
->comboLanguage
->findData(u
"en"_s
, Qt::UserRole
);
1832 Q_ASSERT(index
>= 0);
1834 m_ui
->comboLanguage
->setCurrentIndex(index
);
1837 Path
OptionsDialog::getTorrentExportDir() const
1839 if (m_ui
->checkExportDir
->isChecked())
1840 return m_ui
->textExportDir
->selectedPath();
1844 Path
OptionsDialog::getFinishedTorrentExportDir() const
1846 if (m_ui
->checkExportDirFin
->isChecked())
1847 return m_ui
->textExportDirFin
->selectedPath();
1851 void OptionsDialog::on_addWatchedFolderButton_clicked()
1853 Preferences
*const pref
= Preferences::instance();
1854 const Path dir
{QFileDialog::getExistingDirectory(
1855 this, tr("Select folder to monitor"), pref
->getScanDirsLastPath().parentPath().toString())};
1859 auto *dialog
= new WatchedFolderOptionsDialog({}, this);
1860 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
1861 connect(dialog
, &QDialog::accepted
, this, [this, dialog
, dir
, pref
]()
1865 auto *watchedFoldersModel
= static_cast<WatchedFoldersModel
*>(m_ui
->scanFoldersView
->model());
1866 watchedFoldersModel
->addFolder(dir
, dialog
->watchedFolderOptions());
1868 pref
->setScanDirsLastPath(dir
);
1870 for (int i
= 0; i
< watchedFoldersModel
->columnCount(); ++i
)
1871 m_ui
->scanFoldersView
->resizeColumnToContents(i
);
1873 enableApplyButton();
1875 catch (const RuntimeError
&err
)
1877 QMessageBox::critical(this, tr("Adding entry failed"), err
.message());
1884 void OptionsDialog::on_editWatchedFolderButton_clicked()
1886 const QModelIndex selected
1887 = m_ui
->scanFoldersView
->selectionModel()->selectedIndexes().at(0);
1889 editWatchedFolderOptions(selected
);
1892 void OptionsDialog::on_removeWatchedFolderButton_clicked()
1894 const QModelIndexList selected
1895 = m_ui
->scanFoldersView
->selectionModel()->selectedIndexes();
1897 for (const QModelIndex
&index
: selected
)
1898 m_ui
->scanFoldersView
->model()->removeRow(index
.row());
1901 void OptionsDialog::handleWatchedFolderViewSelectionChanged()
1903 const QModelIndexList selectedIndexes
= m_ui
->scanFoldersView
->selectionModel()->selectedIndexes();
1904 m_ui
->removeWatchedFolderButton
->setEnabled(!selectedIndexes
.isEmpty());
1905 m_ui
->editWatchedFolderButton
->setEnabled(selectedIndexes
.count() == 1);
1908 void OptionsDialog::editWatchedFolderOptions(const QModelIndex
&index
)
1910 if (!index
.isValid())
1913 auto *watchedFoldersModel
= static_cast<WatchedFoldersModel
*>(m_ui
->scanFoldersView
->model());
1914 auto *dialog
= new WatchedFolderOptionsDialog(watchedFoldersModel
->folderOptions(index
.row()), this);
1915 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
1916 connect(dialog
, &QDialog::accepted
, this, [this, dialog
, index
, watchedFoldersModel
]()
1918 if (index
.isValid())
1920 // The index could be invalidated while the dialog was displayed,
1921 // for example, if you deleted the folder using the Web API.
1922 watchedFoldersModel
->setFolderOptions(index
.row(), dialog
->watchedFolderOptions());
1923 enableApplyButton();
1930 // Return Filter object to apply to BT session
1931 Path
OptionsDialog::getFilter() const
1933 return m_ui
->textFilterPath
->selectedPath();
1936 #ifndef DISABLE_WEBUI
1937 void OptionsDialog::webUIHttpsCertChanged(const Path
&path
)
1939 const auto readResult
= Utils::IO::readFile(path
, Utils::Net::MAX_SSL_FILE_SIZE
);
1940 const bool isCertValid
= Utils::Net::isSSLCertificatesValid(readResult
.value_or(QByteArray()));
1942 m_ui
->textWebUIHttpsCert
->setSelectedPath(path
);
1943 m_ui
->lblSslCertStatus
->setPixmap(UIThemeManager::instance()->getScaledPixmap(
1944 (isCertValid
? u
"security-high"_s
: u
"security-low"_s
), 24));
1947 void OptionsDialog::webUIHttpsKeyChanged(const Path
&path
)
1949 const auto readResult
= Utils::IO::readFile(path
, Utils::Net::MAX_SSL_FILE_SIZE
);
1950 const bool isKeyValid
= !Utils::SSLKey::load(readResult
.value_or(QByteArray())).isNull();
1952 m_ui
->textWebUIHttpsKey
->setSelectedPath(path
);
1953 m_ui
->lblSslKeyStatus
->setPixmap(UIThemeManager::instance()->getScaledPixmap(
1954 (isKeyValid
? u
"security-high"_s
: u
"security-low"_s
), 24));
1957 bool OptionsDialog::isWebUIEnabled() const
1959 return m_ui
->checkWebUI
->isChecked();
1962 QString
OptionsDialog::webUIUsername() const
1964 return m_ui
->textWebUIUsername
->text();
1967 QString
OptionsDialog::webUIPassword() const
1969 return m_ui
->textWebUIPassword
->text();
1972 bool OptionsDialog::webUIAuthenticationOk()
1974 if (!isValidWebUIUsername(webUIUsername()))
1976 QMessageBox::warning(this, tr("Length Error"), tr("The WebUI username must be at least 3 characters long."));
1980 const bool dontChangePassword
= webUIPassword().isEmpty() && !Preferences::instance()->getWebUIPassword().isEmpty();
1981 if (!isValidWebUIPassword(webUIPassword()) && !dontChangePassword
)
1983 QMessageBox::warning(this, tr("Length Error"), tr("The WebUI password must be at least 6 characters long."));
1989 bool OptionsDialog::isAlternativeWebUIPathValid()
1991 if (m_ui
->groupAltWebUI
->isChecked() && m_ui
->textWebUIRootFolder
->selectedPath().isEmpty())
1993 QMessageBox::warning(this, tr("Location Error"), tr("The alternative WebUI files location cannot be blank."));
2000 void OptionsDialog::showConnectionTab()
2002 m_ui
->tabSelection
->setCurrentRow(TAB_CONNECTION
);
2005 #ifndef DISABLE_WEBUI
2006 void OptionsDialog::on_registerDNSBtn_clicked()
2008 const auto service
= static_cast<DNS::Service
>(m_ui
->comboDNSService
->currentIndex());
2009 QDesktopServices::openUrl(Net::DNSUpdater::getRegistrationUrl(service
));
2013 void OptionsDialog::on_IpFilterRefreshBtn_clicked()
2015 if (m_refreshingIpFilter
) return;
2016 m_refreshingIpFilter
= true;
2017 // Updating program preferences
2018 BitTorrent::Session
*const session
= BitTorrent::Session::instance();
2019 session
->setIPFilteringEnabled(true);
2020 session
->setIPFilterFile({}); // forcing Session reload filter file
2021 session
->setIPFilterFile(getFilter());
2022 connect(session
, &BitTorrent::Session::IPFilterParsed
, this, &OptionsDialog::handleIPFilterParsed
);
2023 setCursor(QCursor(Qt::WaitCursor
));
2026 void OptionsDialog::handleIPFilterParsed(bool error
, int ruleCount
)
2028 setCursor(QCursor(Qt::ArrowCursor
));
2030 QMessageBox::warning(this, tr("Parsing error"), tr("Failed to parse the provided IP filter"));
2032 QMessageBox::information(this, tr("Successfully refreshed"), tr("Successfully parsed the provided IP filter: %1 rules were applied.", "%1 is a number").arg(ruleCount
));
2033 m_refreshingIpFilter
= false;
2034 disconnect(BitTorrent::Session::instance(), &BitTorrent::Session::IPFilterParsed
, this, &OptionsDialog::handleIPFilterParsed
);
2037 bool OptionsDialog::schedTimesOk()
2039 if (m_ui
->timeEditScheduleFrom
->time() == m_ui
->timeEditScheduleTo
->time())
2041 QMessageBox::warning(this, tr("Time Error"), tr("The start time and the end time can't be the same."));
2047 void OptionsDialog::on_banListButton_clicked()
2049 auto *dialog
= new BanListOptionsDialog(this);
2050 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
2051 connect(dialog
, &QDialog::accepted
, this, &OptionsDialog::enableApplyButton
);
2055 void OptionsDialog::on_IPSubnetWhitelistButton_clicked()
2057 auto *dialog
= new IPSubnetWhitelistOptionsDialog(this);
2058 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
2059 connect(dialog
, &QDialog::accepted
, this, &OptionsDialog::enableApplyButton
);