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"
37 #include <QApplication>
39 #include <QDesktopServices>
40 #include <QDialogButtonBox>
42 #include <QFileDialog>
43 #include <QMessageBox>
44 #include <QSystemTrayIcon>
45 #include <QTranslator>
48 #include <QStyleFactory>
51 #include "base/bittorrent/session.h"
52 #include "base/bittorrent/sharelimitaction.h"
53 #include "base/exceptions.h"
54 #include "base/global.h"
55 #include "base/net/portforwarder.h"
56 #include "base/net/proxyconfigurationmanager.h"
57 #include "base/path.h"
58 #include "base/preferences.h"
59 #include "base/rss/rss_autodownloader.h"
60 #include "base/rss/rss_session.h"
61 #include "base/torrentfileguard.h"
62 #include "base/torrentfileswatcher.h"
63 #include "base/utils/io.h"
64 #include "base/utils/misc.h"
65 #include "base/utils/net.h"
66 #include "base/utils/os.h"
67 #include "base/utils/password.h"
68 #include "base/utils/random.h"
69 #include "base/utils/sslkey.h"
70 #include "addnewtorrentdialog.h"
71 #include "advancedsettings.h"
72 #include "banlistoptionsdialog.h"
73 #include "interfaces/iguiapplication.h"
74 #include "ipsubnetwhitelistoptionsdialog.h"
75 #include "rss/automatedrssdownloader.h"
76 #include "ui_optionsdialog.h"
77 #include "uithemedialog.h"
78 #include "uithememanager.h"
80 #include "watchedfolderoptionsdialog.h"
81 #include "watchedfoldersmodel.h"
82 #include "webui/webui.h"
85 #include "base/net/dnsupdater.h"
88 #if defined Q_OS_MACOS || defined Q_OS_WIN
89 #include "base/utils/os.h"
90 #endif // defined Q_OS_MACOS || defined Q_OS_WIN
92 #define SETTINGS_KEY(name) u"OptionsDialog/" name
94 const int WEBUI_MIN_USERNAME_LENGTH
= 3;
95 const int WEBUI_MIN_PASSWORD_LENGTH
= 6;
99 QStringList
translatedWeekdayNames()
101 // return translated strings from Monday to Sunday in user selected locale
103 const QLocale locale
{Preferences::instance()->getLocale()};
104 const QDate date
{2018, 11, 5}; // Monday
106 for (int i
= 0; i
< 7; ++i
)
107 ret
.append(locale
.toString(date
.addDays(i
), u
"dddd"_s
));
111 class WheelEventEater final
: public QObject
114 using QObject::QObject
;
117 bool eventFilter(QObject
*, QEvent
*event
) override
119 return (event
->type() == QEvent::Wheel
);
123 bool isValidWebUIUsername(const QString
&username
)
125 return (username
.length() >= WEBUI_MIN_USERNAME_LENGTH
);
128 bool isValidWebUIPassword(const QString
&password
)
130 return (password
.length() >= WEBUI_MIN_PASSWORD_LENGTH
);
133 // Shortcuts for frequently used signals that have more than one overload. They would require
134 // type casts and that is why we declare required member pointer here instead.
135 void (QComboBox::*qComboBoxCurrentIndexChanged
)(int) = &QComboBox::currentIndexChanged
;
136 void (QSpinBox::*qSpinBoxValueChanged
)(int) = &QSpinBox::valueChanged
;
140 OptionsDialog::OptionsDialog(IGUIApplication
*app
, QWidget
*parent
)
141 : GUIApplicationComponent(app
, parent
)
142 , m_ui
{new Ui::OptionsDialog
}
143 , m_storeDialogSize
{SETTINGS_KEY(u
"Size"_s
)}
144 , m_storeHSplitterSize
{SETTINGS_KEY(u
"HorizontalSplitterSizes"_s
)}
145 , m_storeLastViewedPage
{SETTINGS_KEY(u
"LastViewedPage"_s
)}
148 m_applyButton
= m_ui
->buttonBox
->button(QDialogButtonBox::Apply
);
151 setWindowTitle(tr("Preferences"));
154 m_ui
->hsplitter
->setCollapsible(0, false);
155 m_ui
->hsplitter
->setCollapsible(1, false);
158 m_ui
->tabSelection
->item(TAB_UI
)->setIcon(UIThemeManager::instance()->getIcon(u
"preferences-desktop"_s
));
159 m_ui
->tabSelection
->item(TAB_BITTORRENT
)->setIcon(UIThemeManager::instance()->getIcon(u
"preferences-bittorrent"_s
, u
"preferences-system-network"_s
));
160 m_ui
->tabSelection
->item(TAB_CONNECTION
)->setIcon(UIThemeManager::instance()->getIcon(u
"network-connect"_s
, u
"network-wired"_s
));
161 m_ui
->tabSelection
->item(TAB_DOWNLOADS
)->setIcon(UIThemeManager::instance()->getIcon(u
"download"_s
, u
"folder-download"_s
));
162 m_ui
->tabSelection
->item(TAB_SPEED
)->setIcon(UIThemeManager::instance()->getIcon(u
"speedometer"_s
, u
"chronometer"_s
));
163 m_ui
->tabSelection
->item(TAB_RSS
)->setIcon(UIThemeManager::instance()->getIcon(u
"application-rss"_s
, u
"application-rss+xml"_s
));
165 m_ui
->tabSelection
->item(TAB_WEBUI
)->setHidden(true);
167 m_ui
->tabSelection
->item(TAB_WEBUI
)->setIcon(UIThemeManager::instance()->getIcon(u
"preferences-webui"_s
, u
"network-server"_s
));
169 m_ui
->tabSelection
->item(TAB_ADVANCED
)->setIcon(UIThemeManager::instance()->getIcon(u
"preferences-advanced"_s
, u
"preferences-other"_s
));
171 // set uniform size for all icons
173 for (int i
= 0; i
< m_ui
->tabSelection
->count(); ++i
)
174 maxHeight
= std::max(maxHeight
, m_ui
->tabSelection
->visualItemRect(m_ui
->tabSelection
->item(i
)).size().height());
175 for (int i
= 0; i
< m_ui
->tabSelection
->count(); ++i
)
177 const QSize
size(std::numeric_limits
<int>::max(), static_cast<int>(maxHeight
* 1.2));
178 m_ui
->tabSelection
->item(i
)->setSizeHint(size
);
181 connect(m_ui
->tabSelection
, &QListWidget::currentItemChanged
, this, &ThisType::changePage
);
184 loadBehaviorTabOptions();
185 loadDownloadsTabOptions();
186 loadConnectionTabOptions();
187 loadSpeedTabOptions();
188 loadBittorrentTabOptions();
190 #ifndef DISABLE_WEBUI
191 loadWebUITabOptions();
194 // Load Advanced settings
195 m_advancedSettings
= new AdvancedSettings(app
, m_ui
->tabAdvancedPage
);
196 m_ui
->advPageLayout
->addWidget(m_advancedSettings
);
197 connect(m_advancedSettings
, &AdvancedSettings::settingsChanged
, this, &ThisType::enableApplyButton
);
199 // setup apply button
200 m_applyButton
->setEnabled(false);
201 connect(m_applyButton
, &QPushButton::clicked
, this, [this]
204 m_applyButton
->setEnabled(false);
207 // disable mouse wheel event on widgets to avoid misselection
208 auto *wheelEventEater
= new WheelEventEater(this);
209 for (QComboBox
*widget
: asConst(findChildren
<QComboBox
*>()))
210 widget
->installEventFilter(wheelEventEater
);
211 for (QSpinBox
*widget
: asConst(findChildren
<QSpinBox
*>()))
212 widget
->installEventFilter(wheelEventEater
);
214 m_ui
->tabSelection
->setCurrentRow(m_storeLastViewedPage
);
216 if (const QSize dialogSize
= m_storeDialogSize
; dialogSize
.isValid())
220 OptionsDialog::~OptionsDialog()
222 // save dialog states
223 m_storeDialogSize
= size();
225 QStringList hSplitterSizes
;
226 for (const int size
: asConst(m_ui
->hsplitter
->sizes()))
227 hSplitterSizes
.append(QString::number(size
));
228 m_storeHSplitterSize
= hSplitterSizes
;
230 m_storeLastViewedPage
= m_ui
->tabSelection
->currentRow();
235 void OptionsDialog::loadBehaviorTabOptions()
237 const auto *pref
= Preferences::instance();
238 const auto *session
= BitTorrent::Session::instance();
240 initializeLanguageCombo();
241 setLocale(pref
->getLocale());
243 initializeStyleCombo();
245 m_ui
->checkUseCustomTheme
->setChecked(Preferences::instance()->useCustomUITheme());
246 m_ui
->customThemeFilePath
->setSelectedPath(Preferences::instance()->customUIThemePath());
247 m_ui
->customThemeFilePath
->setMode(FileSystemPathEdit::Mode::FileOpen
);
248 m_ui
->customThemeFilePath
->setDialogCaption(tr("Select qBittorrent UI Theme file"));
249 m_ui
->customThemeFilePath
->setFileNameFilter(tr("qBittorrent UI Theme file (*.qbtheme config.json)"));
250 #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
251 m_ui
->checkUseSystemIcon
->setChecked(pref
->useSystemIcons());
253 m_ui
->checkUseSystemIcon
->setVisible(false);
256 m_ui
->confirmDeletion
->setChecked(pref
->confirmTorrentDeletion());
257 m_ui
->checkAltRowColors
->setChecked(pref
->useAlternatingRowColors());
258 m_ui
->checkHideZero
->setChecked(pref
->getHideZeroValues());
259 m_ui
->comboHideZero
->setCurrentIndex(pref
->getHideZeroComboValues());
260 m_ui
->comboHideZero
->setEnabled(m_ui
->checkHideZero
->isChecked());
262 m_ui
->actionTorrentDlOnDblClBox
->setItemData(0, TOGGLE_STOP
);
263 m_ui
->actionTorrentDlOnDblClBox
->setItemData(1, OPEN_DEST
);
264 m_ui
->actionTorrentDlOnDblClBox
->setItemData(2, PREVIEW_FILE
);
265 m_ui
->actionTorrentDlOnDblClBox
->setItemData(3, SHOW_OPTIONS
);
266 m_ui
->actionTorrentDlOnDblClBox
->setItemData(4, NO_ACTION
);
267 int actionDownloading
= pref
->getActionOnDblClOnTorrentDl();
268 if ((actionDownloading
< 0) || (actionDownloading
>= m_ui
->actionTorrentDlOnDblClBox
->count()))
269 actionDownloading
= TOGGLE_STOP
;
270 m_ui
->actionTorrentDlOnDblClBox
->setCurrentIndex(m_ui
->actionTorrentDlOnDblClBox
->findData(actionDownloading
));
272 m_ui
->actionTorrentFnOnDblClBox
->setItemData(0, TOGGLE_STOP
);
273 m_ui
->actionTorrentFnOnDblClBox
->setItemData(1, OPEN_DEST
);
274 m_ui
->actionTorrentFnOnDblClBox
->setItemData(2, PREVIEW_FILE
);
275 m_ui
->actionTorrentFnOnDblClBox
->setItemData(3, SHOW_OPTIONS
);
276 m_ui
->actionTorrentFnOnDblClBox
->setItemData(4, NO_ACTION
);
277 int actionSeeding
= pref
->getActionOnDblClOnTorrentFn();
278 if ((actionSeeding
< 0) || (actionSeeding
>= m_ui
->actionTorrentFnOnDblClBox
->count()))
279 actionSeeding
= OPEN_DEST
;
280 m_ui
->actionTorrentFnOnDblClBox
->setCurrentIndex(m_ui
->actionTorrentFnOnDblClBox
->findData(actionSeeding
));
282 m_ui
->checkBoxHideZeroStatusFilters
->setChecked(pref
->getHideZeroStatusFilters());
285 m_ui
->checkStartup
->setVisible(false);
287 m_ui
->checkShowSplash
->setChecked(!pref
->isSplashScreenDisabled());
288 m_ui
->checkProgramExitConfirm
->setChecked(pref
->confirmOnExit());
289 m_ui
->checkProgramAutoExitConfirm
->setChecked(!pref
->dontConfirmAutoExit());
291 m_ui
->windowStateComboBox
->addItem(tr("Normal"), QVariant::fromValue(WindowState::Normal
));
292 m_ui
->windowStateComboBox
->addItem(tr("Minimized"), QVariant::fromValue(WindowState::Minimized
));
294 m_ui
->windowStateComboBox
->addItem(tr("Hidden"), QVariant::fromValue(WindowState::Hidden
));
296 m_ui
->windowStateComboBox
->setCurrentIndex(m_ui
->windowStateComboBox
->findData(QVariant::fromValue(app()->startUpWindowState())));
298 #if !(defined(Q_OS_WIN) || defined(Q_OS_MACOS))
299 m_ui
->groupFileAssociation
->setVisible(false);
300 m_ui
->checkProgramUpdates
->setVisible(false);
304 // Disable systray integration if it is not supported by the system
305 if (!QSystemTrayIcon::isSystemTrayAvailable())
307 m_ui
->checkShowSystray
->setChecked(false);
308 m_ui
->checkShowSystray
->setEnabled(false);
309 m_ui
->checkShowSystray
->setToolTip(tr("Disabled due to failed to detect system tray presence"));
311 m_ui
->checkShowSystray
->setChecked(pref
->systemTrayEnabled());
312 m_ui
->checkMinimizeToSysTray
->setChecked(pref
->minimizeToTray());
313 m_ui
->checkCloseToSystray
->setChecked(pref
->closeToTray());
314 m_ui
->comboTrayIcon
->setCurrentIndex(static_cast<int>(pref
->trayIconStyle()));
318 m_ui
->checkStartup
->setChecked(pref
->WinStartup());
322 m_ui
->checkShowSystray
->setVisible(false);
323 m_ui
->checkAssociateTorrents
->setChecked(Utils::OS::isTorrentFileAssocSet());
324 m_ui
->checkAssociateTorrents
->setEnabled(!m_ui
->checkAssociateTorrents
->isChecked());
325 m_ui
->checkAssociateMagnetLinks
->setChecked(Utils::OS::isMagnetLinkAssocSet());
326 m_ui
->checkAssociateMagnetLinks
->setEnabled(!m_ui
->checkAssociateMagnetLinks
->isChecked());
329 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
330 m_ui
->checkProgramUpdates
->setChecked(pref
->isUpdateCheckEnabled());
333 m_ui
->checkPreventFromSuspendWhenDownloading
->setChecked(pref
->preventFromSuspendWhenDownloading());
334 m_ui
->checkPreventFromSuspendWhenSeeding
->setChecked(pref
->preventFromSuspendWhenSeeding());
336 m_ui
->textFileLogPath
->setDialogCaption(tr("Choose a save directory"));
337 m_ui
->textFileLogPath
->setMode(FileSystemPathEdit::Mode::DirectorySave
);
338 m_ui
->textFileLogPath
->setSelectedPath(app()->fileLoggerPath());
339 const bool fileLogBackup
= app()->isFileLoggerBackup();
340 m_ui
->checkFileLogBackup
->setChecked(fileLogBackup
);
341 m_ui
->spinFileLogSize
->setEnabled(fileLogBackup
);
342 const bool fileLogDelete
= app()->isFileLoggerDeleteOld();
343 m_ui
->checkFileLogDelete
->setChecked(fileLogDelete
);
344 m_ui
->spinFileLogAge
->setEnabled(fileLogDelete
);
345 m_ui
->comboFileLogAgeType
->setEnabled(fileLogDelete
);
346 m_ui
->spinFileLogSize
->setValue(app()->fileLoggerMaxSize() / 1024);
347 m_ui
->spinFileLogAge
->setValue(app()->fileLoggerAge());
348 m_ui
->comboFileLogAgeType
->setCurrentIndex(app()->fileLoggerAgeType());
349 // Groupbox's check state must be initialized after some of its children if they are manually enabled/disabled
350 m_ui
->checkFileLog
->setChecked(app()->isFileLoggerEnabled());
352 m_ui
->checkBoxPerformanceWarning
->setChecked(session
->isPerformanceWarningEnabled());
354 connect(m_ui
->comboLanguage
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
357 connect(m_ui
->comboStyle
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
360 #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
361 connect(m_ui
->checkUseSystemIcon
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
363 connect(m_ui
->checkUseCustomTheme
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
364 connect(m_ui
->customThemeFilePath
, &FileSystemPathEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
366 m_ui
->buttonCustomizeUITheme
->setEnabled(!m_ui
->checkUseCustomTheme
->isChecked());
367 connect(m_ui
->checkUseCustomTheme
, &QGroupBox::toggled
, this, [this]
369 m_ui
->buttonCustomizeUITheme
->setEnabled(!m_ui
->checkUseCustomTheme
->isChecked());
371 connect(m_ui
->buttonCustomizeUITheme
, &QPushButton::clicked
, this, [this]
373 auto *dialog
= new UIThemeDialog(this);
374 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
378 connect(m_ui
->confirmDeletion
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
379 connect(m_ui
->checkAltRowColors
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
380 connect(m_ui
->checkHideZero
, &QAbstractButton::toggled
, m_ui
->comboHideZero
, &QWidget::setEnabled
);
381 connect(m_ui
->checkHideZero
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
382 connect(m_ui
->comboHideZero
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
383 connect(m_ui
->actionTorrentDlOnDblClBox
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
384 connect(m_ui
->actionTorrentFnOnDblClBox
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
385 connect(m_ui
->checkBoxHideZeroStatusFilters
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
388 connect(m_ui
->checkStartup
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
390 connect(m_ui
->checkShowSplash
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
391 connect(m_ui
->checkProgramExitConfirm
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
392 connect(m_ui
->checkProgramAutoExitConfirm
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
393 connect(m_ui
->checkShowSystray
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
394 connect(m_ui
->checkMinimizeToSysTray
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
395 connect(m_ui
->checkCloseToSystray
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
396 connect(m_ui
->comboTrayIcon
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
397 connect(m_ui
->windowStateComboBox
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
399 connect(m_ui
->checkPreventFromSuspendWhenDownloading
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
400 connect(m_ui
->checkPreventFromSuspendWhenSeeding
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
402 #if defined(Q_OS_MACOS)
403 connect(m_ui
->checkAssociateTorrents
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
404 connect(m_ui
->checkAssociateMagnetLinks
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
407 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
408 connect(m_ui
->checkProgramUpdates
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
412 m_ui
->assocPanel
->hide();
416 m_ui
->defaultProgramPanel
->hide();
419 #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && !defined(QBT_USES_DBUS)
420 m_ui
->checkPreventFromSuspendWhenDownloading
->setDisabled(true);
421 m_ui
->checkPreventFromSuspendWhenSeeding
->setDisabled(true);
424 connect(m_ui
->checkFileLog
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
425 connect(m_ui
->textFileLogPath
, &FileSystemPathEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
426 connect(m_ui
->checkFileLogBackup
, &QAbstractButton::toggled
, m_ui
->spinFileLogSize
, &QWidget::setEnabled
);
427 connect(m_ui
->checkFileLogBackup
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
428 connect(m_ui
->checkFileLogDelete
, &QAbstractButton::toggled
, m_ui
->comboFileLogAgeType
, &QWidget::setEnabled
);
429 connect(m_ui
->checkFileLogDelete
, &QAbstractButton::toggled
, m_ui
->spinFileLogAge
, &QWidget::setEnabled
);
430 connect(m_ui
->checkFileLogDelete
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
431 connect(m_ui
->spinFileLogSize
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
432 connect(m_ui
->spinFileLogAge
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
433 connect(m_ui
->comboFileLogAgeType
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
435 connect(m_ui
->checkBoxPerformanceWarning
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
438 void OptionsDialog::saveBehaviorTabOptions() const
440 auto *pref
= Preferences::instance();
441 auto *session
= BitTorrent::Session::instance();
443 // Load the translation
444 const QString locale
= getLocale();
445 if (pref
->getLocale() != locale
)
447 auto *translator
= new QTranslator
;
448 if (translator
->load(u
":/lang/qbittorrent_"_s
+ locale
))
449 qDebug("%s locale recognized, using translation.", qUtf8Printable(locale
));
451 qDebug("%s locale unrecognized, using default (en).", qUtf8Printable(locale
));
452 qApp
->installTranslator(translator
);
454 pref
->setLocale(locale
);
457 pref
->setStyle(m_ui
->comboStyle
->currentText());
460 #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
461 pref
->useSystemIcons(m_ui
->checkUseSystemIcon
->isChecked());
463 pref
->setUseCustomUITheme(m_ui
->checkUseCustomTheme
->isChecked());
464 pref
->setCustomUIThemePath(m_ui
->customThemeFilePath
->selectedPath());
466 pref
->setConfirmTorrentDeletion(m_ui
->confirmDeletion
->isChecked());
467 pref
->setAlternatingRowColors(m_ui
->checkAltRowColors
->isChecked());
468 pref
->setHideZeroValues(m_ui
->checkHideZero
->isChecked());
469 pref
->setHideZeroComboValues(m_ui
->comboHideZero
->currentIndex());
471 pref
->setActionOnDblClOnTorrentDl(m_ui
->actionTorrentDlOnDblClBox
->currentData().toInt());
472 pref
->setActionOnDblClOnTorrentFn(m_ui
->actionTorrentFnOnDblClBox
->currentData().toInt());
474 pref
->setHideZeroStatusFilters(m_ui
->checkBoxHideZeroStatusFilters
->isChecked());
476 pref
->setSplashScreenDisabled(isSplashScreenDisabled());
477 pref
->setConfirmOnExit(m_ui
->checkProgramExitConfirm
->isChecked());
478 pref
->setDontConfirmAutoExit(!m_ui
->checkProgramAutoExitConfirm
->isChecked());
481 pref
->setWinStartup(WinStartup());
485 pref
->setSystemTrayEnabled(m_ui
->checkShowSystray
->isChecked());
486 pref
->setTrayIconStyle(TrayIcon::Style(m_ui
->comboTrayIcon
->currentIndex()));
487 pref
->setCloseToTray(m_ui
->checkCloseToSystray
->isChecked());
488 pref
->setMinimizeToTray(m_ui
->checkMinimizeToSysTray
->isChecked());
492 if (m_ui
->checkAssociateTorrents
->isChecked())
494 Utils::OS::setTorrentFileAssoc();
495 m_ui
->checkAssociateTorrents
->setChecked(Utils::OS::isTorrentFileAssocSet());
496 m_ui
->checkAssociateTorrents
->setEnabled(!m_ui
->checkAssociateTorrents
->isChecked());
498 if (m_ui
->checkAssociateMagnetLinks
->isChecked())
500 Utils::OS::setMagnetLinkAssoc();
501 m_ui
->checkAssociateMagnetLinks
->setChecked(Utils::OS::isMagnetLinkAssocSet());
502 m_ui
->checkAssociateMagnetLinks
->setEnabled(!m_ui
->checkAssociateMagnetLinks
->isChecked());
506 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
507 pref
->setUpdateCheckEnabled(m_ui
->checkProgramUpdates
->isChecked());
510 pref
->setPreventFromSuspendWhenDownloading(m_ui
->checkPreventFromSuspendWhenDownloading
->isChecked());
511 pref
->setPreventFromSuspendWhenSeeding(m_ui
->checkPreventFromSuspendWhenSeeding
->isChecked());
513 app()->setFileLoggerPath(m_ui
->textFileLogPath
->selectedPath());
514 app()->setFileLoggerBackup(m_ui
->checkFileLogBackup
->isChecked());
515 app()->setFileLoggerMaxSize(m_ui
->spinFileLogSize
->value() * 1024);
516 app()->setFileLoggerAge(m_ui
->spinFileLogAge
->value());
517 app()->setFileLoggerAgeType(m_ui
->comboFileLogAgeType
->currentIndex());
518 app()->setFileLoggerDeleteOld(m_ui
->checkFileLogDelete
->isChecked());
519 app()->setFileLoggerEnabled(m_ui
->checkFileLog
->isChecked());
521 app()->setStartUpWindowState(m_ui
->windowStateComboBox
->currentData().value
<WindowState
>());
523 session
->setPerformanceWarningEnabled(m_ui
->checkBoxPerformanceWarning
->isChecked());
526 void OptionsDialog::loadDownloadsTabOptions()
528 const auto *pref
= Preferences::instance();
529 const auto *session
= BitTorrent::Session::instance();
531 m_ui
->checkAdditionDialog
->setChecked(pref
->isAddNewTorrentDialogEnabled());
532 m_ui
->checkAdditionDialogFront
->setChecked(pref
->isAddNewTorrentDialogTopLevel());
534 m_ui
->contentLayoutComboBox
->setCurrentIndex(static_cast<int>(session
->torrentContentLayout()));
535 m_ui
->checkAddToQueueTop
->setChecked(session
->isAddTorrentToQueueTop());
536 m_ui
->checkAddStopped
->setChecked(session
->isAddTorrentStopped());
538 m_ui
->stopConditionComboBox
->setToolTip(
539 u
"<html><body><p><b>" + tr("None") + u
"</b> - " + tr("No stop condition is set.") + u
"</p><p><b>" +
540 tr("Metadata received") + u
"</b> - " + tr("Torrent will stop after metadata is received.") +
541 u
" <em>" + tr("Torrents that have metadata initially will be added as stopped.") + u
"</em></p><p><b>" +
542 tr("Files checked") + u
"</b> - " + tr("Torrent will stop after files are initially checked.") +
543 u
" <em>" + tr("This will also download metadata if it wasn't there initially.") + u
"</em></p></body></html>");
544 m_ui
->stopConditionComboBox
->setItemData(0, QVariant::fromValue(BitTorrent::Torrent::StopCondition::None
));
545 m_ui
->stopConditionComboBox
->setItemData(1, QVariant::fromValue(BitTorrent::Torrent::StopCondition::MetadataReceived
));
546 m_ui
->stopConditionComboBox
->setItemData(2, QVariant::fromValue(BitTorrent::Torrent::StopCondition::FilesChecked
));
547 m_ui
->stopConditionComboBox
->setCurrentIndex(m_ui
->stopConditionComboBox
->findData(QVariant::fromValue(session
->torrentStopCondition())));
548 m_ui
->stopConditionLabel
->setEnabled(!m_ui
->checkAddStopped
->isChecked());
549 m_ui
->stopConditionComboBox
->setEnabled(!m_ui
->checkAddStopped
->isChecked());
551 m_ui
->checkMergeTrackers
->setChecked(session
->isMergeTrackersEnabled());
552 m_ui
->checkConfirmMergeTrackers
->setEnabled(m_ui
->checkAdditionDialog
->isChecked());
553 m_ui
->checkConfirmMergeTrackers
->setChecked(m_ui
->checkConfirmMergeTrackers
->isEnabled() ? pref
->confirmMergeTrackers() : false);
554 connect(m_ui
->checkAdditionDialog
, &QGroupBox::toggled
, this, [this, pref
]
556 m_ui
->checkConfirmMergeTrackers
->setEnabled(m_ui
->checkAdditionDialog
->isChecked());
557 m_ui
->checkConfirmMergeTrackers
->setChecked(m_ui
->checkConfirmMergeTrackers
->isEnabled() ? pref
->confirmMergeTrackers() : false);
560 const TorrentFileGuard::AutoDeleteMode autoDeleteMode
= TorrentFileGuard::autoDeleteMode();
561 m_ui
->deleteTorrentBox
->setChecked(autoDeleteMode
!= TorrentFileGuard::Never
);
562 m_ui
->deleteCancelledTorrentBox
->setChecked(autoDeleteMode
== TorrentFileGuard::Always
);
563 m_ui
->deleteTorrentWarningIcon
->setPixmap(QApplication::style()->standardIcon(QStyle::SP_MessageBoxCritical
).pixmap(16, 16));
564 m_ui
->deleteTorrentWarningIcon
->hide();
565 m_ui
->deleteTorrentWarningLabel
->hide();
566 m_ui
->deleteTorrentWarningLabel
->setToolTip(u
"<html><body><p>" +
567 tr("By enabling these options, you can <strong>irrevocably lose</strong> your .torrent files!") +
569 tr("When these options are enabled, qBittorrent will <strong>delete</strong> .torrent files "
570 "after they were successfully (the first option) or not (the second option) added to its "
571 "download queue. This will be applied <strong>not only</strong> to the files opened via "
572 "“Add torrent” menu action but to those opened via <strong>file type association</strong> as well") +
574 tr("If you enable the second option (“Also when addition is cancelled”) the "
575 ".torrent file <strong>will be deleted</strong> even if you press “<strong>Cancel</strong>” in "
576 "the “Add torrent” dialog") +
577 u
"</p></body></html>");
579 m_ui
->checkPreallocateAll
->setChecked(session
->isPreallocationEnabled());
580 m_ui
->checkAppendqB
->setChecked(session
->isAppendExtensionEnabled());
581 m_ui
->checkUnwantedFolder
->setChecked(session
->isUnwantedFolderEnabled());
582 m_ui
->checkRecursiveDownload
->setChecked(pref
->isRecursiveDownloadEnabled());
584 m_ui
->comboSavingMode
->setCurrentIndex(!session
->isAutoTMMDisabledByDefault());
585 m_ui
->comboTorrentCategoryChanged
->setCurrentIndex(session
->isDisableAutoTMMWhenCategoryChanged());
586 m_ui
->comboCategoryChanged
->setCurrentIndex(session
->isDisableAutoTMMWhenCategorySavePathChanged());
587 m_ui
->comboCategoryDefaultPathChanged
->setCurrentIndex(session
->isDisableAutoTMMWhenDefaultSavePathChanged());
589 m_ui
->checkUseSubcategories
->setChecked(session
->isSubcategoriesEnabled());
590 m_ui
->checkUseCategoryPaths
->setChecked(session
->useCategoryPathsInManualMode());
592 m_ui
->textSavePath
->setDialogCaption(tr("Choose a save directory"));
593 m_ui
->textSavePath
->setMode(FileSystemPathEdit::Mode::DirectorySave
);
594 m_ui
->textSavePath
->setSelectedPath(session
->savePath());
596 m_ui
->checkUseDownloadPath
->setChecked(session
->isDownloadPathEnabled());
597 m_ui
->textDownloadPath
->setDialogCaption(tr("Choose a save directory"));
598 m_ui
->textDownloadPath
->setEnabled(m_ui
->checkUseDownloadPath
->isChecked());
599 m_ui
->textDownloadPath
->setMode(FileSystemPathEdit::Mode::DirectorySave
);
600 m_ui
->textDownloadPath
->setSelectedPath(session
->downloadPath());
602 const bool isExportDirEmpty
= session
->torrentExportDirectory().isEmpty();
603 m_ui
->checkExportDir
->setChecked(!isExportDirEmpty
);
604 m_ui
->textExportDir
->setDialogCaption(tr("Choose export directory"));
605 m_ui
->textExportDir
->setEnabled(m_ui
->checkExportDir
->isChecked());
606 m_ui
->textExportDir
->setMode(FileSystemPathEdit::Mode::DirectorySave
);
607 if (!isExportDirEmpty
)
608 m_ui
->textExportDir
->setSelectedPath(session
->torrentExportDirectory());
610 const bool isExportDirFinEmpty
= session
->finishedTorrentExportDirectory().isEmpty();
611 m_ui
->checkExportDirFin
->setChecked(!isExportDirFinEmpty
);
612 m_ui
->textExportDirFin
->setDialogCaption(tr("Choose export directory"));
613 m_ui
->textExportDirFin
->setEnabled(m_ui
->checkExportDirFin
->isChecked());
614 m_ui
->textExportDirFin
->setMode(FileSystemPathEdit::Mode::DirectorySave
);
615 if (!isExportDirFinEmpty
)
616 m_ui
->textExportDirFin
->setSelectedPath(session
->finishedTorrentExportDirectory());
618 auto *watchedFoldersModel
= new WatchedFoldersModel(TorrentFilesWatcher::instance(), this);
619 connect(watchedFoldersModel
, &QAbstractListModel::dataChanged
, this, &ThisType::enableApplyButton
);
620 m_ui
->scanFoldersView
->header()->setSectionResizeMode(QHeaderView::ResizeToContents
);
621 m_ui
->scanFoldersView
->setModel(watchedFoldersModel
);
622 connect(m_ui
->scanFoldersView
->selectionModel(), &QItemSelectionModel::selectionChanged
, this, &ThisType::handleWatchedFolderViewSelectionChanged
);
623 connect(m_ui
->scanFoldersView
, &QTreeView::doubleClicked
, this, &ThisType::editWatchedFolderOptions
);
625 m_ui
->groupExcludedFileNames
->setChecked(session
->isExcludedFileNamesEnabled());
626 m_ui
->textExcludedFileNames
->setPlainText(session
->excludedFileNames().join(u
'\n'));
628 m_ui
->groupMailNotification
->setChecked(pref
->isMailNotificationEnabled());
629 m_ui
->senderEmailTxt
->setText(pref
->getMailNotificationSender());
630 m_ui
->lineEditDestEmail
->setText(pref
->getMailNotificationEmail());
631 m_ui
->lineEditSmtpServer
->setText(pref
->getMailNotificationSMTP());
632 m_ui
->checkSmtpSSL
->setChecked(pref
->getMailNotificationSMTPSSL());
633 m_ui
->groupMailNotifAuth
->setChecked(pref
->getMailNotificationSMTPAuth());
634 m_ui
->mailNotifUsername
->setText(pref
->getMailNotificationSMTPUsername());
635 m_ui
->mailNotifPassword
->setText(pref
->getMailNotificationSMTPPassword());
637 m_ui
->groupBoxRunOnAdded
->setChecked(pref
->isAutoRunOnTorrentAddedEnabled());
638 m_ui
->groupBoxRunOnFinished
->setChecked(pref
->isAutoRunOnTorrentFinishedEnabled());
639 m_ui
->lineEditRunOnAdded
->setText(pref
->getAutoRunOnTorrentAddedProgram());
640 m_ui
->lineEditRunOnFinished
->setText(pref
->getAutoRunOnTorrentFinishedProgram());
641 #if defined(Q_OS_WIN)
642 m_ui
->autoRunConsole
->setChecked(pref
->isAutoRunConsoleEnabled());
644 m_ui
->autoRunConsole
->hide();
646 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
647 .arg(tr("Supported parameters (case sensitive):")
648 , tr("%N: Torrent name")
650 , tr("%G: Tags (separated by comma)")
651 , tr("%F: Content path (same as root path for multifile torrent)")
652 , tr("%R: Root path (first torrent subdirectory path)")
653 , tr("%D: Save path")
654 , tr("%C: Number of files")
655 , tr("%Z: Torrent size (bytes)"))
656 .arg(tr("%T: Current tracker")
657 , tr("%I: Info hash v1 (or '-' if unavailable)")
658 , tr("%J: Info hash v2 (or '-' if unavailable)")
659 , tr("%K: Torrent ID (either sha-1 info hash for v1 torrent or truncated sha-256 info hash for v2/hybrid torrent)")
660 , tr("Tip: Encapsulate parameter with quotation marks to avoid text being cut off at whitespace (e.g., \"%N\")"));
661 m_ui
->labelAutoRunParam
->setText(autoRunStr
);
663 connect(m_ui
->checkAdditionDialog
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
664 connect(m_ui
->checkAdditionDialogFront
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
666 connect(m_ui
->contentLayoutComboBox
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
668 connect(m_ui
->checkAddToQueueTop
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
669 connect(m_ui
->checkAddStopped
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
670 connect(m_ui
->checkAddStopped
, &QAbstractButton::toggled
, this, [this](const bool checked
)
672 m_ui
->stopConditionLabel
->setEnabled(!checked
);
673 m_ui
->stopConditionComboBox
->setEnabled(!checked
);
675 connect(m_ui
->stopConditionComboBox
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
676 connect(m_ui
->checkMergeTrackers
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
677 connect(m_ui
->checkConfirmMergeTrackers
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
678 connect(m_ui
->deleteTorrentBox
, &QGroupBox::toggled
, m_ui
->deleteTorrentWarningIcon
, &QWidget::setVisible
);
679 connect(m_ui
->deleteTorrentBox
, &QGroupBox::toggled
, m_ui
->deleteTorrentWarningLabel
, &QWidget::setVisible
);
680 connect(m_ui
->deleteTorrentBox
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
681 connect(m_ui
->deleteCancelledTorrentBox
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
683 connect(m_ui
->checkPreallocateAll
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
684 connect(m_ui
->checkAppendqB
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
685 connect(m_ui
->checkUnwantedFolder
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
686 connect(m_ui
->checkRecursiveDownload
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
688 connect(m_ui
->comboSavingMode
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
689 connect(m_ui
->comboTorrentCategoryChanged
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
690 connect(m_ui
->comboCategoryChanged
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
691 connect(m_ui
->comboCategoryDefaultPathChanged
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
693 connect(m_ui
->checkUseSubcategories
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
694 connect(m_ui
->checkUseCategoryPaths
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
696 connect(m_ui
->textSavePath
, &FileSystemPathEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
697 connect(m_ui
->textDownloadPath
, &FileSystemPathEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
699 connect(m_ui
->checkExportDir
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
700 connect(m_ui
->checkExportDir
, &QAbstractButton::toggled
, m_ui
->textExportDir
, &QWidget::setEnabled
);
701 connect(m_ui
->checkExportDirFin
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
702 connect(m_ui
->checkExportDirFin
, &QAbstractButton::toggled
, m_ui
->textExportDirFin
, &QWidget::setEnabled
);
703 connect(m_ui
->textExportDir
, &FileSystemPathEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
704 connect(m_ui
->textExportDirFin
, &FileSystemPathEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
705 connect(m_ui
->checkUseDownloadPath
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
706 connect(m_ui
->checkUseDownloadPath
, &QAbstractButton::toggled
, m_ui
->textDownloadPath
, &QWidget::setEnabled
);
708 connect(m_ui
->addWatchedFolderButton
, &QAbstractButton::clicked
, this, &ThisType::enableApplyButton
);
710 connect(m_ui
->groupExcludedFileNames
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
711 connect(m_ui
->textExcludedFileNames
, &QPlainTextEdit::textChanged
, this, &ThisType::enableApplyButton
);
712 connect(m_ui
->removeWatchedFolderButton
, &QAbstractButton::clicked
, this, &ThisType::enableApplyButton
);
714 connect(m_ui
->groupMailNotification
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
715 connect(m_ui
->senderEmailTxt
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
716 connect(m_ui
->lineEditDestEmail
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
717 connect(m_ui
->lineEditSmtpServer
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
718 connect(m_ui
->checkSmtpSSL
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
719 connect(m_ui
->groupMailNotifAuth
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
720 connect(m_ui
->mailNotifUsername
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
721 connect(m_ui
->mailNotifPassword
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
722 connect(m_ui
->sendTestEmail
, &QPushButton::clicked
, this, [this]
724 app()->sendTestEmail();
725 QMessageBox::information(this, tr("Test email"), tr("Attempted to send email. Check your inbox to confirm success"));
728 connect(m_ui
->groupBoxRunOnAdded
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
729 connect(m_ui
->lineEditRunOnAdded
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
730 connect(m_ui
->groupBoxRunOnFinished
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
731 connect(m_ui
->lineEditRunOnFinished
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
732 connect(m_ui
->autoRunConsole
, &QCheckBox::toggled
, this, &ThisType::enableApplyButton
);
735 void OptionsDialog::saveDownloadsTabOptions() const
737 auto *pref
= Preferences::instance();
738 auto *session
= BitTorrent::Session::instance();
740 pref
->setAddNewTorrentDialogEnabled(useAdditionDialog());
741 pref
->setAddNewTorrentDialogTopLevel(m_ui
->checkAdditionDialogFront
->isChecked());
743 session
->setTorrentContentLayout(static_cast<BitTorrent::TorrentContentLayout
>(m_ui
->contentLayoutComboBox
->currentIndex()));
745 session
->setAddTorrentToQueueTop(m_ui
->checkAddToQueueTop
->isChecked());
746 session
->setAddTorrentStopped(addTorrentsStopped());
747 session
->setTorrentStopCondition(m_ui
->stopConditionComboBox
->currentData().value
<BitTorrent::Torrent::StopCondition
>());
748 TorrentFileGuard::setAutoDeleteMode(!m_ui
->deleteTorrentBox
->isChecked() ? TorrentFileGuard::Never
749 : !m_ui
->deleteCancelledTorrentBox
->isChecked() ? TorrentFileGuard::IfAdded
750 : TorrentFileGuard::Always
);
751 session
->setMergeTrackersEnabled(m_ui
->checkMergeTrackers
->isChecked());
752 if (m_ui
->checkConfirmMergeTrackers
->isEnabled())
753 pref
->setConfirmMergeTrackers(m_ui
->checkConfirmMergeTrackers
->isChecked());
755 session
->setPreallocationEnabled(preAllocateAllFiles());
756 session
->setAppendExtensionEnabled(m_ui
->checkAppendqB
->isChecked());
757 session
->setUnwantedFolderEnabled(m_ui
->checkUnwantedFolder
->isChecked());
758 pref
->setRecursiveDownloadEnabled(m_ui
->checkRecursiveDownload
->isChecked());
760 session
->setAutoTMMDisabledByDefault(m_ui
->comboSavingMode
->currentIndex() == 0);
761 session
->setDisableAutoTMMWhenCategoryChanged(m_ui
->comboTorrentCategoryChanged
->currentIndex() == 1);
762 session
->setDisableAutoTMMWhenCategorySavePathChanged(m_ui
->comboCategoryChanged
->currentIndex() == 1);
763 session
->setDisableAutoTMMWhenDefaultSavePathChanged(m_ui
->comboCategoryDefaultPathChanged
->currentIndex() == 1);
765 session
->setSubcategoriesEnabled(m_ui
->checkUseSubcategories
->isChecked());
766 session
->setUseCategoryPathsInManualMode(m_ui
->checkUseCategoryPaths
->isChecked());
768 session
->setSavePath(Path(m_ui
->textSavePath
->selectedPath()));
769 session
->setDownloadPathEnabled(m_ui
->checkUseDownloadPath
->isChecked());
770 session
->setDownloadPath(m_ui
->textDownloadPath
->selectedPath());
771 session
->setTorrentExportDirectory(getTorrentExportDir());
772 session
->setFinishedTorrentExportDirectory(getFinishedTorrentExportDir());
774 auto *watchedFoldersModel
= static_cast<WatchedFoldersModel
*>(m_ui
->scanFoldersView
->model());
775 watchedFoldersModel
->apply();
777 session
->setExcludedFileNamesEnabled(m_ui
->groupExcludedFileNames
->isChecked());
778 session
->setExcludedFileNames(m_ui
->textExcludedFileNames
->toPlainText().split(u
'\n', Qt::SkipEmptyParts
));
780 pref
->setMailNotificationEnabled(m_ui
->groupMailNotification
->isChecked());
781 pref
->setMailNotificationSender(m_ui
->senderEmailTxt
->text());
782 pref
->setMailNotificationEmail(m_ui
->lineEditDestEmail
->text());
783 pref
->setMailNotificationSMTP(m_ui
->lineEditSmtpServer
->text());
784 pref
->setMailNotificationSMTPSSL(m_ui
->checkSmtpSSL
->isChecked());
785 pref
->setMailNotificationSMTPAuth(m_ui
->groupMailNotifAuth
->isChecked());
786 pref
->setMailNotificationSMTPUsername(m_ui
->mailNotifUsername
->text());
787 pref
->setMailNotificationSMTPPassword(m_ui
->mailNotifPassword
->text());
789 pref
->setAutoRunOnTorrentAddedEnabled(m_ui
->groupBoxRunOnAdded
->isChecked());
790 pref
->setAutoRunOnTorrentAddedProgram(m_ui
->lineEditRunOnAdded
->text().trimmed());
791 pref
->setAutoRunOnTorrentFinishedEnabled(m_ui
->groupBoxRunOnFinished
->isChecked());
792 pref
->setAutoRunOnTorrentFinishedProgram(m_ui
->lineEditRunOnFinished
->text().trimmed());
793 #if defined(Q_OS_WIN)
794 pref
->setAutoRunConsoleEnabled(m_ui
->autoRunConsole
->isChecked());
798 void OptionsDialog::loadConnectionTabOptions()
800 const auto *session
= BitTorrent::Session::instance();
802 m_ui
->comboProtocol
->setCurrentIndex(static_cast<int>(session
->btProtocol()));
803 m_ui
->spinPort
->setValue(session
->port());
804 m_ui
->checkUPnP
->setChecked(Net::PortForwarder::instance()->isEnabled());
806 int intValue
= session
->maxConnections();
810 m_ui
->checkMaxConnections
->setChecked(true);
811 m_ui
->spinMaxConnec
->setEnabled(true);
812 m_ui
->spinMaxConnec
->setValue(intValue
);
817 m_ui
->checkMaxConnections
->setChecked(false);
818 m_ui
->spinMaxConnec
->setEnabled(false);
820 intValue
= session
->maxConnectionsPerTorrent();
824 m_ui
->checkMaxConnectionsPerTorrent
->setChecked(true);
825 m_ui
->spinMaxConnecPerTorrent
->setEnabled(true);
826 m_ui
->spinMaxConnecPerTorrent
->setValue(intValue
);
831 m_ui
->checkMaxConnectionsPerTorrent
->setChecked(false);
832 m_ui
->spinMaxConnecPerTorrent
->setEnabled(false);
834 intValue
= session
->maxUploads();
838 m_ui
->checkMaxUploads
->setChecked(true);
839 m_ui
->spinMaxUploads
->setEnabled(true);
840 m_ui
->spinMaxUploads
->setValue(intValue
);
845 m_ui
->checkMaxUploads
->setChecked(false);
846 m_ui
->spinMaxUploads
->setEnabled(false);
848 intValue
= session
->maxUploadsPerTorrent();
852 m_ui
->checkMaxUploadsPerTorrent
->setChecked(true);
853 m_ui
->spinMaxUploadsPerTorrent
->setEnabled(true);
854 m_ui
->spinMaxUploadsPerTorrent
->setValue(intValue
);
859 m_ui
->checkMaxUploadsPerTorrent
->setChecked(false);
860 m_ui
->spinMaxUploadsPerTorrent
->setEnabled(false);
863 #if defined(QBT_USES_LIBTORRENT2) && TORRENT_USE_I2P
864 m_ui
->textI2PHost
->setText(session
->I2PAddress());
865 m_ui
->spinI2PPort
->setValue(session
->I2PPort());
866 m_ui
->checkI2PMixed
->setChecked(session
->I2PMixedMode());
867 m_ui
->groupI2P
->setChecked(session
->isI2PEnabled());
869 m_ui
->groupI2P
->hide();
872 const auto *proxyConfigManager
= Net::ProxyConfigurationManager::instance();
873 const Net::ProxyConfiguration proxyConf
= proxyConfigManager
->proxyConfiguration();
875 m_ui
->comboProxyType
->addItem(tr("(None)"), QVariant::fromValue(Net::ProxyType::None
));
876 m_ui
->comboProxyType
->addItem(tr("SOCKS4"), QVariant::fromValue(Net::ProxyType::SOCKS4
));
877 m_ui
->comboProxyType
->addItem(tr("SOCKS5"), QVariant::fromValue(Net::ProxyType::SOCKS5
));
878 m_ui
->comboProxyType
->addItem(tr("HTTP"), QVariant::fromValue(Net::ProxyType::HTTP
));
879 m_ui
->comboProxyType
->setCurrentIndex(m_ui
->comboProxyType
->findData(QVariant::fromValue(proxyConf
.type
)));
880 adjustProxyOptions();
882 m_ui
->textProxyIP
->setText(proxyConf
.ip
);
883 m_ui
->spinProxyPort
->setValue(proxyConf
.port
);
884 m_ui
->textProxyUsername
->setText(proxyConf
.username
);
885 m_ui
->textProxyPassword
->setText(proxyConf
.password
);
886 m_ui
->checkProxyAuth
->setChecked(proxyConf
.authEnabled
);
887 m_ui
->checkProxyHostnameLookup
->setChecked(proxyConf
.hostnameLookupEnabled
);
889 m_ui
->checkProxyPeerConnections
->setChecked(session
->isProxyPeerConnectionsEnabled());
890 m_ui
->checkProxyBitTorrent
->setChecked(Preferences::instance()->useProxyForBT());
891 m_ui
->checkProxyRSS
->setChecked(Preferences::instance()->useProxyForRSS());
892 m_ui
->checkProxyMisc
->setChecked(Preferences::instance()->useProxyForGeneralPurposes());
894 m_ui
->checkIPFilter
->setChecked(session
->isIPFilteringEnabled());
895 m_ui
->textFilterPath
->setDialogCaption(tr("Choose an IP filter file"));
896 m_ui
->textFilterPath
->setEnabled(m_ui
->checkIPFilter
->isChecked());
897 m_ui
->textFilterPath
->setFileNameFilter(tr("All supported filters") + u
" (*.dat *.p2p *.p2b);;.dat (*.dat);;.p2p (*.p2p);;.p2b (*.p2b)");
898 m_ui
->textFilterPath
->setSelectedPath(session
->IPFilterFile());
900 m_ui
->IpFilterRefreshBtn
->setIcon(UIThemeManager::instance()->getIcon(u
"view-refresh"_s
));
901 m_ui
->IpFilterRefreshBtn
->setEnabled(m_ui
->checkIPFilter
->isChecked());
902 m_ui
->checkIpFilterTrackers
->setChecked(session
->isTrackerFilteringEnabled());
904 connect(m_ui
->comboProtocol
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
905 connect(m_ui
->spinPort
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
906 connect(m_ui
->checkUPnP
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
908 connect(m_ui
->checkMaxConnections
, &QAbstractButton::toggled
, m_ui
->spinMaxConnec
, &QWidget::setEnabled
);
909 connect(m_ui
->checkMaxConnections
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
910 connect(m_ui
->checkMaxConnectionsPerTorrent
, &QAbstractButton::toggled
, m_ui
->spinMaxConnecPerTorrent
, &QWidget::setEnabled
);
911 connect(m_ui
->checkMaxConnectionsPerTorrent
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
912 connect(m_ui
->checkMaxUploads
, &QAbstractButton::toggled
, m_ui
->spinMaxUploads
, &QWidget::setEnabled
);
913 connect(m_ui
->checkMaxUploads
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
914 connect(m_ui
->checkMaxUploadsPerTorrent
, &QAbstractButton::toggled
, m_ui
->spinMaxUploadsPerTorrent
, &QWidget::setEnabled
);
915 connect(m_ui
->checkMaxUploadsPerTorrent
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
916 connect(m_ui
->spinMaxConnec
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
917 connect(m_ui
->spinMaxConnecPerTorrent
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
918 connect(m_ui
->spinMaxUploads
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
919 connect(m_ui
->spinMaxUploadsPerTorrent
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
921 connect(m_ui
->comboProxyType
, qComboBoxCurrentIndexChanged
, this, &ThisType::adjustProxyOptions
);
922 connect(m_ui
->comboProxyType
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
923 connect(m_ui
->textProxyIP
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
924 connect(m_ui
->spinProxyPort
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
926 #if defined(QBT_USES_LIBTORRENT2) && TORRENT_USE_I2P
927 connect(m_ui
->textI2PHost
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
928 connect(m_ui
->spinI2PPort
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
929 connect(m_ui
->checkI2PMixed
, &QCheckBox::toggled
, this, &ThisType::enableApplyButton
);
930 connect(m_ui
->groupI2P
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
933 connect(m_ui
->checkProxyBitTorrent
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
934 connect(m_ui
->checkProxyBitTorrent
, &QGroupBox::toggled
, this, &ThisType::adjustProxyOptions
);
935 connect(m_ui
->checkProxyPeerConnections
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
936 connect(m_ui
->checkProxyHostnameLookup
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
937 connect(m_ui
->checkProxyRSS
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
938 connect(m_ui
->checkProxyMisc
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
940 connect(m_ui
->checkProxyAuth
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
941 connect(m_ui
->textProxyUsername
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
942 connect(m_ui
->textProxyPassword
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
944 connect(m_ui
->checkIPFilter
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
945 connect(m_ui
->checkIPFilter
, &QAbstractButton::toggled
, m_ui
->textFilterPath
, &QWidget::setEnabled
);
946 connect(m_ui
->checkIPFilter
, &QAbstractButton::toggled
, m_ui
->IpFilterRefreshBtn
, &QWidget::setEnabled
);
947 connect(m_ui
->textFilterPath
, &FileSystemPathEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
948 connect(m_ui
->checkIpFilterTrackers
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
951 void OptionsDialog::saveConnectionTabOptions() const
953 auto *session
= BitTorrent::Session::instance();
955 session
->setBTProtocol(static_cast<BitTorrent::BTProtocol
>(m_ui
->comboProtocol
->currentIndex()));
956 session
->setPort(getPort());
957 Net::PortForwarder::instance()->setEnabled(isUPnPEnabled());
959 session
->setMaxConnections(getMaxConnections());
960 session
->setMaxConnectionsPerTorrent(getMaxConnectionsPerTorrent());
961 session
->setMaxUploads(getMaxUploads());
962 session
->setMaxUploadsPerTorrent(getMaxUploadsPerTorrent());
964 #if defined(QBT_USES_LIBTORRENT2) && TORRENT_USE_I2P
965 session
->setI2PEnabled(m_ui
->groupI2P
->isChecked());
966 session
->setI2PAddress(m_ui
->textI2PHost
->text().trimmed());
967 session
->setI2PPort(m_ui
->spinI2PPort
->value());
968 session
->setI2PMixedMode(m_ui
->checkI2PMixed
->isChecked());
971 auto *proxyConfigManager
= Net::ProxyConfigurationManager::instance();
972 Net::ProxyConfiguration proxyConf
;
973 proxyConf
.type
= getProxyType();
974 proxyConf
.ip
= getProxyIp();
975 proxyConf
.port
= getProxyPort();
976 proxyConf
.authEnabled
= m_ui
->checkProxyAuth
->isChecked();
977 proxyConf
.username
= getProxyUsername();
978 proxyConf
.password
= getProxyPassword();
979 proxyConf
.hostnameLookupEnabled
= m_ui
->checkProxyHostnameLookup
->isChecked();
980 proxyConfigManager
->setProxyConfiguration(proxyConf
);
982 Preferences::instance()->setUseProxyForBT(m_ui
->checkProxyBitTorrent
->isChecked());
983 Preferences::instance()->setUseProxyForRSS(m_ui
->checkProxyRSS
->isChecked());
984 Preferences::instance()->setUseProxyForGeneralPurposes(m_ui
->checkProxyMisc
->isChecked());
986 session
->setProxyPeerConnectionsEnabled(m_ui
->checkProxyPeerConnections
->isChecked());
989 session
->setIPFilteringEnabled(isIPFilteringEnabled());
990 session
->setTrackerFilteringEnabled(m_ui
->checkIpFilterTrackers
->isChecked());
991 session
->setIPFilterFile(m_ui
->textFilterPath
->selectedPath());
994 void OptionsDialog::loadSpeedTabOptions()
996 const auto *pref
= Preferences::instance();
997 const auto *session
= BitTorrent::Session::instance();
999 m_ui
->labelGlobalRate
->setPixmap(UIThemeManager::instance()->getScaledPixmap(u
"slow_off"_s
, Utils::Gui::mediumIconSize(this).height()));
1000 m_ui
->spinUploadLimit
->setValue(session
->globalUploadSpeedLimit() / 1024);
1001 m_ui
->spinDownloadLimit
->setValue(session
->globalDownloadSpeedLimit() / 1024);
1003 m_ui
->labelAltRate
->setPixmap(UIThemeManager::instance()->getScaledPixmap(u
"slow"_s
, Utils::Gui::mediumIconSize(this).height()));
1004 m_ui
->spinUploadLimitAlt
->setValue(session
->altGlobalUploadSpeedLimit() / 1024);
1005 m_ui
->spinDownloadLimitAlt
->setValue(session
->altGlobalDownloadSpeedLimit() / 1024);
1007 m_ui
->comboBoxScheduleDays
->addItems(translatedWeekdayNames());
1009 m_ui
->groupBoxSchedule
->setChecked(session
->isBandwidthSchedulerEnabled());
1010 m_ui
->timeEditScheduleFrom
->setTime(pref
->getSchedulerStartTime());
1011 m_ui
->timeEditScheduleTo
->setTime(pref
->getSchedulerEndTime());
1012 m_ui
->comboBoxScheduleDays
->setCurrentIndex(static_cast<int>(pref
->getSchedulerDays()));
1014 m_ui
->checkLimituTPConnections
->setChecked(session
->isUTPRateLimited());
1015 m_ui
->checkLimitTransportOverhead
->setChecked(session
->includeOverheadInLimits());
1016 m_ui
->checkLimitLocalPeerRate
->setChecked(!session
->ignoreLimitsOnLAN());
1018 connect(m_ui
->spinUploadLimit
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1019 connect(m_ui
->spinDownloadLimit
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1021 connect(m_ui
->spinUploadLimitAlt
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1022 connect(m_ui
->spinDownloadLimitAlt
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1024 connect(m_ui
->groupBoxSchedule
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1025 connect(m_ui
->timeEditScheduleFrom
, &QDateTimeEdit::timeChanged
, this, &ThisType::enableApplyButton
);
1026 connect(m_ui
->timeEditScheduleTo
, &QDateTimeEdit::timeChanged
, this, &ThisType::enableApplyButton
);
1027 connect(m_ui
->comboBoxScheduleDays
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
1029 connect(m_ui
->checkLimituTPConnections
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1030 connect(m_ui
->checkLimitTransportOverhead
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1031 connect(m_ui
->checkLimitLocalPeerRate
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1034 void OptionsDialog::saveSpeedTabOptions() const
1036 auto *pref
= Preferences::instance();
1037 auto *session
= BitTorrent::Session::instance();
1039 session
->setGlobalUploadSpeedLimit(m_ui
->spinUploadLimit
->value() * 1024);
1040 session
->setGlobalDownloadSpeedLimit(m_ui
->spinDownloadLimit
->value() * 1024);
1042 session
->setAltGlobalUploadSpeedLimit(m_ui
->spinUploadLimitAlt
->value() * 1024);
1043 session
->setAltGlobalDownloadSpeedLimit(m_ui
->spinDownloadLimitAlt
->value() * 1024);
1045 session
->setBandwidthSchedulerEnabled(m_ui
->groupBoxSchedule
->isChecked());
1046 pref
->setSchedulerStartTime(m_ui
->timeEditScheduleFrom
->time());
1047 pref
->setSchedulerEndTime(m_ui
->timeEditScheduleTo
->time());
1048 pref
->setSchedulerDays(static_cast<Scheduler::Days
>(m_ui
->comboBoxScheduleDays
->currentIndex()));
1050 session
->setUTPRateLimited(m_ui
->checkLimituTPConnections
->isChecked());
1051 session
->setIncludeOverheadInLimits(m_ui
->checkLimitTransportOverhead
->isChecked());
1052 session
->setIgnoreLimitsOnLAN(!m_ui
->checkLimitLocalPeerRate
->isChecked());
1055 void OptionsDialog::loadBittorrentTabOptions()
1057 const auto *session
= BitTorrent::Session::instance();
1059 m_ui
->checkDHT
->setChecked(session
->isDHTEnabled());
1060 m_ui
->checkPeX
->setChecked(session
->isPeXEnabled());
1061 m_ui
->checkLSD
->setChecked(session
->isLSDEnabled());
1062 m_ui
->comboEncryption
->setCurrentIndex(session
->encryption());
1063 m_ui
->checkAnonymousMode
->setChecked(session
->isAnonymousModeEnabled());
1065 m_ui
->spinBoxMaxActiveCheckingTorrents
->setValue(session
->maxActiveCheckingTorrents());
1067 m_ui
->checkEnableQueueing
->setChecked(session
->isQueueingSystemEnabled());
1068 m_ui
->spinMaxActiveDownloads
->setValue(session
->maxActiveDownloads());
1069 m_ui
->spinMaxActiveUploads
->setValue(session
->maxActiveUploads());
1070 m_ui
->spinMaxActiveTorrents
->setValue(session
->maxActiveTorrents());
1072 m_ui
->checkIgnoreSlowTorrentsForQueueing
->setChecked(session
->ignoreSlowTorrentsForQueueing());
1073 const QString slowTorrentsExplanation
= u
"<html><body><p>"
1074 + tr("A torrent will be considered slow if its download and upload rates stay below these values for \"Torrent inactivity timer\" seconds")
1075 + u
"</p></body></html>";
1076 m_ui
->labelDownloadRateForSlowTorrents
->setToolTip(slowTorrentsExplanation
);
1077 m_ui
->labelUploadRateForSlowTorrents
->setToolTip(slowTorrentsExplanation
);
1078 m_ui
->labelSlowTorrentInactivityTimer
->setToolTip(slowTorrentsExplanation
);
1079 m_ui
->spinDownloadRateForSlowTorrents
->setValue(session
->downloadRateForSlowTorrents());
1080 m_ui
->spinUploadRateForSlowTorrents
->setValue(session
->uploadRateForSlowTorrents());
1081 m_ui
->spinSlowTorrentsInactivityTimer
->setValue(session
->slowTorrentsInactivityTimer());
1083 if (session
->globalMaxRatio() >= 0.)
1086 m_ui
->checkMaxRatio
->setChecked(true);
1087 m_ui
->spinMaxRatio
->setEnabled(true);
1088 m_ui
->comboRatioLimitAct
->setEnabled(true);
1089 m_ui
->spinMaxRatio
->setValue(session
->globalMaxRatio());
1094 m_ui
->checkMaxRatio
->setChecked(false);
1095 m_ui
->spinMaxRatio
->setEnabled(false);
1097 if (session
->globalMaxSeedingMinutes() >= 0)
1100 m_ui
->checkMaxSeedingMinutes
->setChecked(true);
1101 m_ui
->spinMaxSeedingMinutes
->setEnabled(true);
1102 m_ui
->spinMaxSeedingMinutes
->setValue(session
->globalMaxSeedingMinutes());
1107 m_ui
->checkMaxSeedingMinutes
->setChecked(false);
1108 m_ui
->spinMaxSeedingMinutes
->setEnabled(false);
1110 if (session
->globalMaxInactiveSeedingMinutes() >= 0)
1113 m_ui
->checkMaxInactiveSeedingMinutes
->setChecked(true);
1114 m_ui
->spinMaxInactiveSeedingMinutes
->setEnabled(true);
1115 m_ui
->spinMaxInactiveSeedingMinutes
->setValue(session
->globalMaxInactiveSeedingMinutes());
1120 m_ui
->checkMaxInactiveSeedingMinutes
->setChecked(false);
1121 m_ui
->spinMaxInactiveSeedingMinutes
->setEnabled(false);
1123 m_ui
->comboRatioLimitAct
->setEnabled((session
->globalMaxSeedingMinutes() >= 0) || (session
->globalMaxRatio() >= 0.) || (session
->globalMaxInactiveSeedingMinutes() >= 0));
1125 const QHash
<BitTorrent::ShareLimitAction
, int> actIndex
=
1127 {BitTorrent::ShareLimitAction::Stop
, 0},
1128 {BitTorrent::ShareLimitAction::Remove
, 1},
1129 {BitTorrent::ShareLimitAction::RemoveWithContent
, 2},
1130 {BitTorrent::ShareLimitAction::EnableSuperSeeding
, 3}
1132 m_ui
->comboRatioLimitAct
->setCurrentIndex(actIndex
.value(session
->shareLimitAction()));
1134 m_ui
->checkEnableAddTrackers
->setChecked(session
->isAddTrackersEnabled());
1135 m_ui
->textTrackers
->setPlainText(session
->additionalTrackers());
1137 connect(m_ui
->checkDHT
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1138 connect(m_ui
->checkPeX
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1139 connect(m_ui
->checkLSD
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1140 connect(m_ui
->comboEncryption
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
1141 connect(m_ui
->checkAnonymousMode
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1143 connect(m_ui
->spinBoxMaxActiveCheckingTorrents
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1145 connect(m_ui
->checkEnableQueueing
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1146 connect(m_ui
->spinMaxActiveDownloads
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1147 connect(m_ui
->spinMaxActiveUploads
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1148 connect(m_ui
->spinMaxActiveTorrents
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1149 connect(m_ui
->checkIgnoreSlowTorrentsForQueueing
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1150 connect(m_ui
->spinDownloadRateForSlowTorrents
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1151 connect(m_ui
->spinUploadRateForSlowTorrents
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1152 connect(m_ui
->spinSlowTorrentsInactivityTimer
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1154 connect(m_ui
->checkMaxRatio
, &QAbstractButton::toggled
, m_ui
->spinMaxRatio
, &QWidget::setEnabled
);
1155 connect(m_ui
->checkMaxRatio
, &QAbstractButton::toggled
, this, &ThisType::toggleComboRatioLimitAct
);
1156 connect(m_ui
->checkMaxRatio
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1157 connect(m_ui
->spinMaxRatio
, qOverload
<double>(&QDoubleSpinBox::valueChanged
),this, &ThisType::enableApplyButton
);
1158 connect(m_ui
->comboRatioLimitAct
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
1159 connect(m_ui
->checkMaxSeedingMinutes
, &QAbstractButton::toggled
, m_ui
->spinMaxSeedingMinutes
, &QWidget::setEnabled
);
1160 connect(m_ui
->checkMaxSeedingMinutes
, &QAbstractButton::toggled
, this, &ThisType::toggleComboRatioLimitAct
);
1161 connect(m_ui
->checkMaxSeedingMinutes
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1162 connect(m_ui
->spinMaxSeedingMinutes
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1163 connect(m_ui
->checkMaxInactiveSeedingMinutes
, &QAbstractButton::toggled
, m_ui
->spinMaxInactiveSeedingMinutes
, &QWidget::setEnabled
);
1164 connect(m_ui
->checkMaxInactiveSeedingMinutes
, &QAbstractButton::toggled
, this, &ThisType::toggleComboRatioLimitAct
);
1165 connect(m_ui
->checkMaxInactiveSeedingMinutes
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1166 connect(m_ui
->spinMaxInactiveSeedingMinutes
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1168 connect(m_ui
->checkEnableAddTrackers
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1169 connect(m_ui
->textTrackers
, &QPlainTextEdit::textChanged
, this, &ThisType::enableApplyButton
);
1172 void OptionsDialog::saveBittorrentTabOptions() const
1174 auto *session
= BitTorrent::Session::instance();
1176 session
->setDHTEnabled(isDHTEnabled());
1177 session
->setPeXEnabled(m_ui
->checkPeX
->isChecked());
1178 session
->setLSDEnabled(isLSDEnabled());
1179 session
->setEncryption(getEncryptionSetting());
1180 session
->setAnonymousModeEnabled(m_ui
->checkAnonymousMode
->isChecked());
1182 session
->setMaxActiveCheckingTorrents(m_ui
->spinBoxMaxActiveCheckingTorrents
->value());
1184 session
->setQueueingSystemEnabled(isQueueingSystemEnabled());
1185 session
->setMaxActiveDownloads(m_ui
->spinMaxActiveDownloads
->value());
1186 session
->setMaxActiveUploads(m_ui
->spinMaxActiveUploads
->value());
1187 session
->setMaxActiveTorrents(m_ui
->spinMaxActiveTorrents
->value());
1188 session
->setIgnoreSlowTorrentsForQueueing(m_ui
->checkIgnoreSlowTorrentsForQueueing
->isChecked());
1189 session
->setDownloadRateForSlowTorrents(m_ui
->spinDownloadRateForSlowTorrents
->value());
1190 session
->setUploadRateForSlowTorrents(m_ui
->spinUploadRateForSlowTorrents
->value());
1191 session
->setSlowTorrentsInactivityTimer(m_ui
->spinSlowTorrentsInactivityTimer
->value());
1193 session
->setGlobalMaxRatio(getMaxRatio());
1194 session
->setGlobalMaxSeedingMinutes(getMaxSeedingMinutes());
1195 session
->setGlobalMaxInactiveSeedingMinutes(getMaxInactiveSeedingMinutes());
1196 const QList
<BitTorrent::ShareLimitAction
> actIndex
=
1198 BitTorrent::ShareLimitAction::Stop
,
1199 BitTorrent::ShareLimitAction::Remove
,
1200 BitTorrent::ShareLimitAction::RemoveWithContent
,
1201 BitTorrent::ShareLimitAction::EnableSuperSeeding
1203 session
->setShareLimitAction(actIndex
.value(m_ui
->comboRatioLimitAct
->currentIndex()));
1205 session
->setAddTrackersEnabled(m_ui
->checkEnableAddTrackers
->isChecked());
1206 session
->setAdditionalTrackers(m_ui
->textTrackers
->toPlainText());
1209 void OptionsDialog::loadRSSTabOptions()
1211 const auto *rssSession
= RSS::Session::instance();
1212 const auto *autoDownloader
= RSS::AutoDownloader::instance();
1214 m_ui
->checkRSSEnable
->setChecked(rssSession
->isProcessingEnabled());
1215 m_ui
->spinRSSRefreshInterval
->setValue(rssSession
->refreshInterval());
1216 m_ui
->spinRSSFetchDelay
->setValue(rssSession
->fetchDelay().count());
1217 m_ui
->spinRSSMaxArticlesPerFeed
->setValue(rssSession
->maxArticlesPerFeed());
1218 m_ui
->checkRSSAutoDownloaderEnable
->setChecked(autoDownloader
->isProcessingEnabled());
1219 m_ui
->textSmartEpisodeFilters
->setPlainText(autoDownloader
->smartEpisodeFilters().join(u
'\n'));
1220 m_ui
->checkSmartFilterDownloadRepacks
->setChecked(autoDownloader
->downloadRepacks());
1222 connect(m_ui
->checkRSSEnable
, &QCheckBox::toggled
, this, &OptionsDialog::enableApplyButton
);
1223 connect(m_ui
->checkRSSAutoDownloaderEnable
, &QCheckBox::toggled
, this, &OptionsDialog::enableApplyButton
);
1224 connect(m_ui
->btnEditRules
, &QPushButton::clicked
, this, [this]()
1226 auto *downloader
= new AutomatedRssDownloader(this);
1227 downloader
->setAttribute(Qt::WA_DeleteOnClose
);
1230 connect(m_ui
->textSmartEpisodeFilters
, &QPlainTextEdit::textChanged
, this, &OptionsDialog::enableApplyButton
);
1231 connect(m_ui
->checkSmartFilterDownloadRepacks
, &QCheckBox::toggled
, this, &OptionsDialog::enableApplyButton
);
1232 connect(m_ui
->spinRSSRefreshInterval
, qSpinBoxValueChanged
, this, &OptionsDialog::enableApplyButton
);
1233 connect(m_ui
->spinRSSFetchDelay
, qSpinBoxValueChanged
, this, &OptionsDialog::enableApplyButton
);
1234 connect(m_ui
->spinRSSMaxArticlesPerFeed
, qSpinBoxValueChanged
, this, &OptionsDialog::enableApplyButton
);
1237 void OptionsDialog::saveRSSTabOptions() const
1239 auto *rssSession
= RSS::Session::instance();
1240 auto *autoDownloader
= RSS::AutoDownloader::instance();
1242 rssSession
->setProcessingEnabled(m_ui
->checkRSSEnable
->isChecked());
1243 rssSession
->setRefreshInterval(m_ui
->spinRSSRefreshInterval
->value());
1244 rssSession
->setFetchDelay(std::chrono::seconds(m_ui
->spinRSSFetchDelay
->value()));
1245 rssSession
->setMaxArticlesPerFeed(m_ui
->spinRSSMaxArticlesPerFeed
->value());
1246 autoDownloader
->setProcessingEnabled(m_ui
->checkRSSAutoDownloaderEnable
->isChecked());
1247 autoDownloader
->setSmartEpisodeFilters(m_ui
->textSmartEpisodeFilters
->toPlainText().split(u
'\n', Qt::SkipEmptyParts
));
1248 autoDownloader
->setDownloadRepacks(m_ui
->checkSmartFilterDownloadRepacks
->isChecked());
1251 #ifndef DISABLE_WEBUI
1252 void OptionsDialog::loadWebUITabOptions()
1254 const auto *pref
= Preferences::instance();
1256 m_ui
->textWebUIHttpsCert
->setMode(FileSystemPathEdit::Mode::FileOpen
);
1257 m_ui
->textWebUIHttpsCert
->setFileNameFilter(tr("Certificate") + u
" (*.cer *.crt *.pem)");
1258 m_ui
->textWebUIHttpsCert
->setDialogCaption(tr("Select certificate"));
1259 m_ui
->textWebUIHttpsKey
->setMode(FileSystemPathEdit::Mode::FileOpen
);
1260 m_ui
->textWebUIHttpsKey
->setFileNameFilter(tr("Private key") + u
" (*.key *.pem)");
1261 m_ui
->textWebUIHttpsKey
->setDialogCaption(tr("Select private key"));
1262 m_ui
->textWebUIRootFolder
->setMode(FileSystemPathEdit::Mode::DirectoryOpen
);
1263 m_ui
->textWebUIRootFolder
->setDialogCaption(tr("Choose Alternative UI files location"));
1265 if (app()->webUI()->isErrored())
1266 m_ui
->labelWebUIError
->setText(tr("WebUI configuration failed. Reason: %1").arg(app()->webUI()->errorMessage()));
1268 m_ui
->labelWebUIError
->hide();
1270 m_ui
->checkWebUI
->setChecked(pref
->isWebUIEnabled());
1271 m_ui
->textWebUIAddress
->setText(pref
->getWebUIAddress());
1272 m_ui
->spinWebUIPort
->setValue(pref
->getWebUIPort());
1273 m_ui
->checkWebUIUPnP
->setChecked(pref
->useUPnPForWebUIPort());
1274 m_ui
->checkWebUIHttps
->setChecked(pref
->isWebUIHttpsEnabled());
1275 webUIHttpsCertChanged(pref
->getWebUIHttpsCertificatePath());
1276 webUIHttpsKeyChanged(pref
->getWebUIHttpsKeyPath());
1277 m_ui
->textWebUIUsername
->setText(pref
->getWebUIUsername());
1278 m_ui
->checkBypassLocalAuth
->setChecked(!pref
->isWebUILocalAuthEnabled());
1279 m_ui
->checkBypassAuthSubnetWhitelist
->setChecked(pref
->isWebUIAuthSubnetWhitelistEnabled());
1280 m_ui
->IPSubnetWhitelistButton
->setEnabled(m_ui
->checkBypassAuthSubnetWhitelist
->isChecked());
1281 m_ui
->spinBanCounter
->setValue(pref
->getWebUIMaxAuthFailCount());
1282 m_ui
->spinBanDuration
->setValue(pref
->getWebUIBanDuration().count());
1283 m_ui
->spinSessionTimeout
->setValue(pref
->getWebUISessionTimeout());
1285 m_ui
->groupAltWebUI
->setChecked(pref
->isAltWebUIEnabled());
1286 m_ui
->textWebUIRootFolder
->setSelectedPath(pref
->getWebUIRootFolder());
1288 m_ui
->checkClickjacking
->setChecked(pref
->isWebUIClickjackingProtectionEnabled());
1289 m_ui
->checkCSRFProtection
->setChecked(pref
->isWebUICSRFProtectionEnabled());
1290 m_ui
->checkSecureCookie
->setChecked(pref
->isWebUISecureCookieEnabled());
1291 m_ui
->groupHostHeaderValidation
->setChecked(pref
->isWebUIHostHeaderValidationEnabled());
1292 m_ui
->textServerDomains
->setText(pref
->getServerDomains());
1293 // Custom HTTP headers
1294 m_ui
->groupWebUIAddCustomHTTPHeaders
->setChecked(pref
->isWebUICustomHTTPHeadersEnabled());
1295 m_ui
->textWebUICustomHTTPHeaders
->setPlainText(pref
->getWebUICustomHTTPHeaders());
1297 m_ui
->groupEnableReverseProxySupport
->setChecked(pref
->isWebUIReverseProxySupportEnabled());
1298 m_ui
->textTrustedReverseProxiesList
->setText(pref
->getWebUITrustedReverseProxiesList());
1300 m_ui
->checkDynDNS
->setChecked(pref
->isDynDNSEnabled());
1301 m_ui
->comboDNSService
->setCurrentIndex(static_cast<int>(pref
->getDynDNSService()));
1302 m_ui
->domainNameTxt
->setText(pref
->getDynDomainName());
1303 m_ui
->DNSUsernameTxt
->setText(pref
->getDynDNSUsername());
1304 m_ui
->DNSPasswordTxt
->setText(pref
->getDynDNSPassword());
1306 connect(m_ui
->checkWebUI
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1307 connect(m_ui
->textWebUIAddress
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
1308 connect(m_ui
->spinWebUIPort
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1309 connect(m_ui
->checkWebUIUPnP
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1310 connect(m_ui
->checkWebUIHttps
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1311 connect(m_ui
->textWebUIHttpsCert
, &FileSystemPathLineEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
1312 connect(m_ui
->textWebUIHttpsCert
, &FileSystemPathLineEdit::selectedPathChanged
, this, &OptionsDialog::webUIHttpsCertChanged
);
1313 connect(m_ui
->textWebUIHttpsKey
, &FileSystemPathLineEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
1314 connect(m_ui
->textWebUIHttpsKey
, &FileSystemPathLineEdit::selectedPathChanged
, this, &OptionsDialog::webUIHttpsKeyChanged
);
1316 connect(m_ui
->textWebUIUsername
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
1317 connect(m_ui
->textWebUIPassword
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
1319 connect(m_ui
->checkBypassLocalAuth
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1320 connect(m_ui
->checkBypassAuthSubnetWhitelist
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1321 connect(m_ui
->checkBypassAuthSubnetWhitelist
, &QAbstractButton::toggled
, m_ui
->IPSubnetWhitelistButton
, &QWidget::setEnabled
);
1322 connect(m_ui
->spinBanCounter
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1323 connect(m_ui
->spinBanDuration
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1324 connect(m_ui
->spinSessionTimeout
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1326 connect(m_ui
->groupAltWebUI
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1327 connect(m_ui
->textWebUIRootFolder
, &FileSystemPathLineEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
1329 connect(m_ui
->checkClickjacking
, &QCheckBox::toggled
, this, &ThisType::enableApplyButton
);
1330 connect(m_ui
->checkCSRFProtection
, &QCheckBox::toggled
, this, &ThisType::enableApplyButton
);
1331 connect(m_ui
->checkSecureCookie
, &QCheckBox::toggled
, this, &ThisType::enableApplyButton
);
1332 connect(m_ui
->groupHostHeaderValidation
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1333 connect(m_ui
->textServerDomains
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
1335 connect(m_ui
->groupWebUIAddCustomHTTPHeaders
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1336 connect(m_ui
->textWebUICustomHTTPHeaders
, &QPlainTextEdit::textChanged
, this, &OptionsDialog::enableApplyButton
);
1338 connect(m_ui
->groupEnableReverseProxySupport
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1339 connect(m_ui
->textTrustedReverseProxiesList
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
1341 connect(m_ui
->checkDynDNS
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1342 connect(m_ui
->comboDNSService
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
1343 connect(m_ui
->domainNameTxt
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
1344 connect(m_ui
->DNSUsernameTxt
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
1345 connect(m_ui
->DNSPasswordTxt
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
1348 void OptionsDialog::saveWebUITabOptions() const
1350 auto *pref
= Preferences::instance();
1352 const bool webUIEnabled
= isWebUIEnabled();
1354 pref
->setWebUIEnabled(webUIEnabled
);
1355 pref
->setWebUIAddress(m_ui
->textWebUIAddress
->text());
1356 pref
->setWebUIPort(m_ui
->spinWebUIPort
->value());
1357 pref
->setUPnPForWebUIPort(m_ui
->checkWebUIUPnP
->isChecked());
1358 pref
->setWebUIHttpsEnabled(m_ui
->checkWebUIHttps
->isChecked());
1359 pref
->setWebUIHttpsCertificatePath(m_ui
->textWebUIHttpsCert
->selectedPath());
1360 pref
->setWebUIHttpsKeyPath(m_ui
->textWebUIHttpsKey
->selectedPath());
1361 pref
->setWebUIMaxAuthFailCount(m_ui
->spinBanCounter
->value());
1362 pref
->setWebUIBanDuration(std::chrono::seconds
{m_ui
->spinBanDuration
->value()});
1363 pref
->setWebUISessionTimeout(m_ui
->spinSessionTimeout
->value());
1365 if (const QString username
= webUIUsername(); isValidWebUIUsername(username
))
1366 pref
->setWebUIUsername(username
);
1367 if (const QString password
= webUIPassword(); isValidWebUIPassword(password
))
1368 pref
->setWebUIPassword(Utils::Password::PBKDF2::generate(password
));
1369 pref
->setWebUILocalAuthEnabled(!m_ui
->checkBypassLocalAuth
->isChecked());
1370 pref
->setWebUIAuthSubnetWhitelistEnabled(m_ui
->checkBypassAuthSubnetWhitelist
->isChecked());
1372 pref
->setAltWebUIEnabled(m_ui
->groupAltWebUI
->isChecked());
1373 pref
->setWebUIRootFolder(m_ui
->textWebUIRootFolder
->selectedPath());
1375 pref
->setWebUIClickjackingProtectionEnabled(m_ui
->checkClickjacking
->isChecked());
1376 pref
->setWebUICSRFProtectionEnabled(m_ui
->checkCSRFProtection
->isChecked());
1377 pref
->setWebUISecureCookieEnabled(m_ui
->checkSecureCookie
->isChecked());
1378 pref
->setWebUIHostHeaderValidationEnabled(m_ui
->groupHostHeaderValidation
->isChecked());
1379 pref
->setServerDomains(m_ui
->textServerDomains
->text());
1380 // Custom HTTP headers
1381 pref
->setWebUICustomHTTPHeadersEnabled(m_ui
->groupWebUIAddCustomHTTPHeaders
->isChecked());
1382 pref
->setWebUICustomHTTPHeaders(m_ui
->textWebUICustomHTTPHeaders
->toPlainText());
1384 pref
->setWebUIReverseProxySupportEnabled(m_ui
->groupEnableReverseProxySupport
->isChecked());
1385 pref
->setWebUITrustedReverseProxiesList(m_ui
->textTrustedReverseProxiesList
->text());
1387 pref
->setDynDNSEnabled(m_ui
->checkDynDNS
->isChecked());
1388 pref
->setDynDNSService(static_cast<DNS::Service
>(m_ui
->comboDNSService
->currentIndex()));
1389 pref
->setDynDomainName(m_ui
->domainNameTxt
->text());
1390 pref
->setDynDNSUsername(m_ui
->DNSUsernameTxt
->text());
1391 pref
->setDynDNSPassword(m_ui
->DNSPasswordTxt
->text());
1393 #endif // DISABLE_WEBUI
1395 void OptionsDialog::initializeLanguageCombo()
1397 // List language files
1398 const QStringList langFiles
= QDir(u
":/lang"_s
).entryList({u
"qbittorrent_*.qm"_s
}, QDir::Files
, QDir::Name
);
1399 for (const QString
&langFile
: langFiles
)
1401 const QString langCode
= QStringView(langFile
).sliced(12).chopped(3).toString(); // remove "qbittorrent_" and ".qm"
1402 m_ui
->comboLanguage
->addItem(Utils::Misc::languageToLocalizedString(langCode
), langCode
);
1406 void OptionsDialog::changePage(QListWidgetItem
*current
, QListWidgetItem
*previous
)
1410 m_ui
->tabOption
->setCurrentIndex(m_ui
->tabSelection
->row(current
));
1413 void OptionsDialog::loadSplitterState()
1415 // width has been modified, use height as width reference instead
1416 const int width
= m_ui
->tabSelection
->item(TAB_UI
)->sizeHint().height() * 2;
1417 const QStringList defaultSizes
= {QString::number(width
), QString::number(m_ui
->hsplitter
->width() - width
)};
1419 QList
<int> splitterSizes
;
1420 for (const QString
&string
: asConst(m_storeHSplitterSize
.get(defaultSizes
)))
1421 splitterSizes
.append(string
.toInt());
1423 m_ui
->hsplitter
->setSizes(splitterSizes
);
1426 void OptionsDialog::showEvent(QShowEvent
*e
)
1428 QDialog::showEvent(e
);
1430 loadSplitterState();
1433 void OptionsDialog::saveOptions() const
1435 auto *pref
= Preferences::instance();
1437 saveBehaviorTabOptions();
1438 saveDownloadsTabOptions();
1439 saveConnectionTabOptions();
1440 saveSpeedTabOptions();
1441 saveBittorrentTabOptions();
1442 saveRSSTabOptions();
1443 #ifndef DISABLE_WEBUI
1444 saveWebUITabOptions();
1446 m_advancedSettings
->saveAdvancedSettings();
1448 // Assume that user changed multiple settings
1449 // so it's best to save immediately
1453 bool OptionsDialog::isIPFilteringEnabled() const
1455 return m_ui
->checkIPFilter
->isChecked();
1458 Net::ProxyType
OptionsDialog::getProxyType() const
1460 return m_ui
->comboProxyType
->currentData().value
<Net::ProxyType
>();
1463 int OptionsDialog::getPort() const
1465 return m_ui
->spinPort
->value();
1468 void OptionsDialog::on_randomButton_clicked()
1470 // Range [1024: 65535]
1471 m_ui
->spinPort
->setValue(Utils::Random::rand(1024, 65535));
1474 int OptionsDialog::getEncryptionSetting() const
1476 return m_ui
->comboEncryption
->currentIndex();
1479 int OptionsDialog::getMaxActiveDownloads() const
1481 return m_ui
->spinMaxActiveDownloads
->value();
1484 int OptionsDialog::getMaxActiveUploads() const
1486 return m_ui
->spinMaxActiveUploads
->value();
1489 int OptionsDialog::getMaxActiveTorrents() const
1491 return m_ui
->spinMaxActiveTorrents
->value();
1494 bool OptionsDialog::isQueueingSystemEnabled() const
1496 return m_ui
->checkEnableQueueing
->isChecked();
1499 bool OptionsDialog::isDHTEnabled() const
1501 return m_ui
->checkDHT
->isChecked();
1504 bool OptionsDialog::isLSDEnabled() const
1506 return m_ui
->checkLSD
->isChecked();
1509 bool OptionsDialog::isUPnPEnabled() const
1511 return m_ui
->checkUPnP
->isChecked();
1514 // Return Share ratio
1515 qreal
OptionsDialog::getMaxRatio() const
1517 if (m_ui
->checkMaxRatio
->isChecked())
1518 return m_ui
->spinMaxRatio
->value();
1522 // Return Seeding Minutes
1523 int OptionsDialog::getMaxSeedingMinutes() const
1525 if (m_ui
->checkMaxSeedingMinutes
->isChecked())
1526 return m_ui
->spinMaxSeedingMinutes
->value();
1530 // Return Inactive Seeding Minutes
1531 int OptionsDialog::getMaxInactiveSeedingMinutes() const
1533 return m_ui
->checkMaxInactiveSeedingMinutes
->isChecked()
1534 ? m_ui
->spinMaxInactiveSeedingMinutes
->value()
1538 // Return max connections number
1539 int OptionsDialog::getMaxConnections() const
1541 if (!m_ui
->checkMaxConnections
->isChecked())
1544 return m_ui
->spinMaxConnec
->value();
1547 int OptionsDialog::getMaxConnectionsPerTorrent() const
1549 if (!m_ui
->checkMaxConnectionsPerTorrent
->isChecked())
1552 return m_ui
->spinMaxConnecPerTorrent
->value();
1555 int OptionsDialog::getMaxUploads() const
1557 if (!m_ui
->checkMaxUploads
->isChecked())
1560 return m_ui
->spinMaxUploads
->value();
1563 int OptionsDialog::getMaxUploadsPerTorrent() const
1565 if (!m_ui
->checkMaxUploadsPerTorrent
->isChecked())
1568 return m_ui
->spinMaxUploadsPerTorrent
->value();
1571 void OptionsDialog::on_buttonBox_accepted()
1573 if (m_applyButton
->isEnabled())
1575 if (!applySettings())
1578 m_applyButton
->setEnabled(false);
1584 bool OptionsDialog::applySettings()
1586 if (!schedTimesOk())
1588 m_ui
->tabSelection
->setCurrentRow(TAB_SPEED
);
1591 #ifndef DISABLE_WEBUI
1592 if (isWebUIEnabled() && !webUIAuthenticationOk())
1594 m_ui
->tabSelection
->setCurrentRow(TAB_WEBUI
);
1597 if (!isAlternativeWebUIPathValid())
1599 m_ui
->tabSelection
->setCurrentRow(TAB_WEBUI
);
1608 void OptionsDialog::on_buttonBox_rejected()
1613 bool OptionsDialog::useAdditionDialog() const
1615 return m_ui
->checkAdditionDialog
->isChecked();
1618 void OptionsDialog::enableApplyButton()
1620 m_applyButton
->setEnabled(true);
1623 void OptionsDialog::toggleComboRatioLimitAct()
1625 // Verify if the share action button must be enabled
1626 m_ui
->comboRatioLimitAct
->setEnabled(m_ui
->checkMaxRatio
->isChecked() || m_ui
->checkMaxSeedingMinutes
->isChecked() || m_ui
->checkMaxInactiveSeedingMinutes
->isChecked());
1629 void OptionsDialog::adjustProxyOptions()
1631 const auto currentProxyType
= m_ui
->comboProxyType
->currentData().value
<Net::ProxyType
>();
1632 const bool isAuthSupported
= ((currentProxyType
== Net::ProxyType::SOCKS5
)
1633 || (currentProxyType
== Net::ProxyType::HTTP
));
1635 m_ui
->checkProxyAuth
->setEnabled(isAuthSupported
);
1637 if (currentProxyType
== Net::ProxyType::None
)
1639 m_ui
->labelProxyTypeIncompatible
->setVisible(false);
1641 m_ui
->lblProxyIP
->setEnabled(false);
1642 m_ui
->textProxyIP
->setEnabled(false);
1643 m_ui
->lblProxyPort
->setEnabled(false);
1644 m_ui
->spinProxyPort
->setEnabled(false);
1646 m_ui
->checkProxyHostnameLookup
->setEnabled(false);
1647 m_ui
->checkProxyRSS
->setEnabled(false);
1648 m_ui
->checkProxyMisc
->setEnabled(false);
1649 m_ui
->checkProxyBitTorrent
->setEnabled(false);
1650 m_ui
->checkProxyPeerConnections
->setEnabled(false);
1654 m_ui
->lblProxyIP
->setEnabled(true);
1655 m_ui
->textProxyIP
->setEnabled(true);
1656 m_ui
->lblProxyPort
->setEnabled(true);
1657 m_ui
->spinProxyPort
->setEnabled(true);
1659 m_ui
->checkProxyBitTorrent
->setEnabled(true);
1660 m_ui
->checkProxyPeerConnections
->setEnabled(true);
1662 if (currentProxyType
== Net::ProxyType::SOCKS4
)
1664 m_ui
->labelProxyTypeIncompatible
->setVisible(true);
1666 m_ui
->checkProxyHostnameLookup
->setEnabled(false);
1667 m_ui
->checkProxyRSS
->setEnabled(false);
1668 m_ui
->checkProxyMisc
->setEnabled(false);
1673 m_ui
->labelProxyTypeIncompatible
->setVisible(false);
1675 m_ui
->checkProxyHostnameLookup
->setEnabled(true);
1676 m_ui
->checkProxyRSS
->setEnabled(true);
1677 m_ui
->checkProxyMisc
->setEnabled(true);
1682 bool OptionsDialog::isSplashScreenDisabled() const
1684 return !m_ui
->checkShowSplash
->isChecked();
1687 void OptionsDialog::initializeStyleCombo()
1690 const QString prefStyleName
= Preferences::instance()->getStyle();
1691 const QString selectedStyleName
= prefStyleName
.isEmpty() ? QApplication::style()->name() : prefStyleName
;
1692 QStringList styleNames
= QStyleFactory::keys();
1693 for (qsizetype i
= 1, stylesCount
= styleNames
.size(); i
< stylesCount
; ++i
)
1695 if (selectedStyleName
.compare(styleNames
.at(i
), Qt::CaseInsensitive
) == 0)
1697 styleNames
.swapItemsAt(0, i
);
1701 m_ui
->comboStyle
->addItems(styleNames
);
1703 m_ui
->labelStyle
->hide();
1704 m_ui
->comboStyle
->hide();
1705 m_ui
->UISettingsBoxLayout
->removeWidget(m_ui
->labelStyle
);
1706 m_ui
->UISettingsBoxLayout
->removeWidget(m_ui
->comboStyle
);
1707 m_ui
->UISettingsBoxLayout
->removeItem(m_ui
->spacerStyle
);
1712 bool OptionsDialog::WinStartup() const
1714 return m_ui
->checkStartup
->isChecked();
1718 bool OptionsDialog::preAllocateAllFiles() const
1720 return m_ui
->checkPreallocateAll
->isChecked();
1723 bool OptionsDialog::addTorrentsStopped() const
1725 return m_ui
->checkAddStopped
->isChecked();
1729 bool OptionsDialog::isProxyEnabled() const
1731 return m_ui
->comboProxyType
->currentIndex();
1734 QString
OptionsDialog::getProxyIp() const
1736 return m_ui
->textProxyIP
->text().trimmed();
1739 unsigned short OptionsDialog::getProxyPort() const
1741 return m_ui
->spinProxyPort
->value();
1744 QString
OptionsDialog::getProxyUsername() const
1746 QString username
= m_ui
->textProxyUsername
->text().trimmed();
1750 QString
OptionsDialog::getProxyPassword() const
1752 QString password
= m_ui
->textProxyPassword
->text();
1753 password
= password
.trimmed();
1758 QString
OptionsDialog::getLocale() const
1760 return m_ui
->comboLanguage
->itemData(m_ui
->comboLanguage
->currentIndex(), Qt::UserRole
).toString();
1763 void OptionsDialog::setLocale(const QString
&localeStr
)
1766 if (localeStr
.startsWith(u
"eo", Qt::CaseInsensitive
))
1770 else if (localeStr
.startsWith(u
"ltg", Qt::CaseInsensitive
))
1776 QLocale
locale(localeStr
);
1777 if (locale
.language() == QLocale::Uzbek
)
1778 name
= u
"uz@Latn"_s
;
1779 else if (locale
.language() == QLocale::Azerbaijani
)
1780 name
= u
"az@latin"_s
;
1782 name
= locale
.name();
1784 // Attempt to find exact match
1785 int index
= m_ui
->comboLanguage
->findData(name
, Qt::UserRole
);
1788 //Attempt to find a language match without a country
1789 int pos
= name
.indexOf(u
'_');
1792 QString lang
= name
.left(pos
);
1793 index
= m_ui
->comboLanguage
->findData(lang
, Qt::UserRole
);
1798 // Unrecognized, use US English
1799 index
= m_ui
->comboLanguage
->findData(u
"en"_s
, Qt::UserRole
);
1800 Q_ASSERT(index
>= 0);
1802 m_ui
->comboLanguage
->setCurrentIndex(index
);
1805 Path
OptionsDialog::getTorrentExportDir() const
1807 if (m_ui
->checkExportDir
->isChecked())
1808 return m_ui
->textExportDir
->selectedPath();
1812 Path
OptionsDialog::getFinishedTorrentExportDir() const
1814 if (m_ui
->checkExportDirFin
->isChecked())
1815 return m_ui
->textExportDirFin
->selectedPath();
1819 void OptionsDialog::on_addWatchedFolderButton_clicked()
1821 Preferences
*const pref
= Preferences::instance();
1822 const Path dir
{QFileDialog::getExistingDirectory(
1823 this, tr("Select folder to monitor"), pref
->getScanDirsLastPath().parentPath().toString())};
1827 auto *dialog
= new WatchedFolderOptionsDialog({}, this);
1828 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
1829 connect(dialog
, &QDialog::accepted
, this, [this, dialog
, dir
, pref
]()
1833 auto *watchedFoldersModel
= static_cast<WatchedFoldersModel
*>(m_ui
->scanFoldersView
->model());
1834 watchedFoldersModel
->addFolder(dir
, dialog
->watchedFolderOptions());
1836 pref
->setScanDirsLastPath(dir
);
1838 for (int i
= 0; i
< watchedFoldersModel
->columnCount(); ++i
)
1839 m_ui
->scanFoldersView
->resizeColumnToContents(i
);
1841 enableApplyButton();
1843 catch (const RuntimeError
&err
)
1845 QMessageBox::critical(this, tr("Adding entry failed"), err
.message());
1852 void OptionsDialog::on_editWatchedFolderButton_clicked()
1854 const QModelIndex selected
1855 = m_ui
->scanFoldersView
->selectionModel()->selectedIndexes().at(0);
1857 editWatchedFolderOptions(selected
);
1860 void OptionsDialog::on_removeWatchedFolderButton_clicked()
1862 const QModelIndexList selected
1863 = m_ui
->scanFoldersView
->selectionModel()->selectedIndexes();
1865 for (const QModelIndex
&index
: selected
)
1866 m_ui
->scanFoldersView
->model()->removeRow(index
.row());
1869 void OptionsDialog::handleWatchedFolderViewSelectionChanged()
1871 const QModelIndexList selectedIndexes
= m_ui
->scanFoldersView
->selectionModel()->selectedIndexes();
1872 m_ui
->removeWatchedFolderButton
->setEnabled(!selectedIndexes
.isEmpty());
1873 m_ui
->editWatchedFolderButton
->setEnabled(selectedIndexes
.count() == 1);
1876 void OptionsDialog::editWatchedFolderOptions(const QModelIndex
&index
)
1878 if (!index
.isValid())
1881 auto *watchedFoldersModel
= static_cast<WatchedFoldersModel
*>(m_ui
->scanFoldersView
->model());
1882 auto *dialog
= new WatchedFolderOptionsDialog(watchedFoldersModel
->folderOptions(index
.row()), this);
1883 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
1884 connect(dialog
, &QDialog::accepted
, this, [this, dialog
, index
, watchedFoldersModel
]()
1886 if (index
.isValid())
1888 // The index could be invalidated while the dialog was displayed,
1889 // for example, if you deleted the folder using the Web API.
1890 watchedFoldersModel
->setFolderOptions(index
.row(), dialog
->watchedFolderOptions());
1891 enableApplyButton();
1898 // Return Filter object to apply to BT session
1899 Path
OptionsDialog::getFilter() const
1901 return m_ui
->textFilterPath
->selectedPath();
1904 #ifndef DISABLE_WEBUI
1905 void OptionsDialog::webUIHttpsCertChanged(const Path
&path
)
1907 const auto readResult
= Utils::IO::readFile(path
, Utils::Net::MAX_SSL_FILE_SIZE
);
1908 const bool isCertValid
= !Utils::SSLKey::load(readResult
.value_or(QByteArray())).isNull();
1910 m_ui
->textWebUIHttpsCert
->setSelectedPath(path
);
1911 m_ui
->lblSslCertStatus
->setPixmap(UIThemeManager::instance()->getScaledPixmap(
1912 (isCertValid
? u
"security-high"_s
: u
"security-low"_s
), 24));
1915 void OptionsDialog::webUIHttpsKeyChanged(const Path
&path
)
1917 const auto readResult
= Utils::IO::readFile(path
, Utils::Net::MAX_SSL_FILE_SIZE
);
1918 const bool isKeyValid
= !Utils::SSLKey::load(readResult
.value_or(QByteArray())).isNull();
1920 m_ui
->textWebUIHttpsKey
->setSelectedPath(path
);
1921 m_ui
->lblSslKeyStatus
->setPixmap(UIThemeManager::instance()->getScaledPixmap(
1922 (isKeyValid
? u
"security-high"_s
: u
"security-low"_s
), 24));
1925 bool OptionsDialog::isWebUIEnabled() const
1927 return m_ui
->checkWebUI
->isChecked();
1930 QString
OptionsDialog::webUIUsername() const
1932 return m_ui
->textWebUIUsername
->text();
1935 QString
OptionsDialog::webUIPassword() const
1937 return m_ui
->textWebUIPassword
->text();
1940 bool OptionsDialog::webUIAuthenticationOk()
1942 if (!isValidWebUIUsername(webUIUsername()))
1944 QMessageBox::warning(this, tr("Length Error"), tr("The WebUI username must be at least 3 characters long."));
1948 const bool dontChangePassword
= webUIPassword().isEmpty() && !Preferences::instance()->getWebUIPassword().isEmpty();
1949 if (!isValidWebUIPassword(webUIPassword()) && !dontChangePassword
)
1951 QMessageBox::warning(this, tr("Length Error"), tr("The WebUI password must be at least 6 characters long."));
1957 bool OptionsDialog::isAlternativeWebUIPathValid()
1959 if (m_ui
->groupAltWebUI
->isChecked() && m_ui
->textWebUIRootFolder
->selectedPath().isEmpty())
1961 QMessageBox::warning(this, tr("Location Error"), tr("The alternative WebUI files location cannot be blank."));
1968 void OptionsDialog::showConnectionTab()
1970 m_ui
->tabSelection
->setCurrentRow(TAB_CONNECTION
);
1973 #ifndef DISABLE_WEBUI
1974 void OptionsDialog::on_registerDNSBtn_clicked()
1976 const auto service
= static_cast<DNS::Service
>(m_ui
->comboDNSService
->currentIndex());
1977 QDesktopServices::openUrl(Net::DNSUpdater::getRegistrationUrl(service
));
1981 void OptionsDialog::on_IpFilterRefreshBtn_clicked()
1983 if (m_refreshingIpFilter
) return;
1984 m_refreshingIpFilter
= true;
1985 // Updating program preferences
1986 BitTorrent::Session
*const session
= BitTorrent::Session::instance();
1987 session
->setIPFilteringEnabled(true);
1988 session
->setIPFilterFile({}); // forcing Session reload filter file
1989 session
->setIPFilterFile(getFilter());
1990 connect(session
, &BitTorrent::Session::IPFilterParsed
, this, &OptionsDialog::handleIPFilterParsed
);
1991 setCursor(QCursor(Qt::WaitCursor
));
1994 void OptionsDialog::handleIPFilterParsed(bool error
, int ruleCount
)
1996 setCursor(QCursor(Qt::ArrowCursor
));
1998 QMessageBox::warning(this, tr("Parsing error"), tr("Failed to parse the provided IP filter"));
2000 QMessageBox::information(this, tr("Successfully refreshed"), tr("Successfully parsed the provided IP filter: %1 rules were applied.", "%1 is a number").arg(ruleCount
));
2001 m_refreshingIpFilter
= false;
2002 disconnect(BitTorrent::Session::instance(), &BitTorrent::Session::IPFilterParsed
, this, &OptionsDialog::handleIPFilterParsed
);
2005 bool OptionsDialog::schedTimesOk()
2007 if (m_ui
->timeEditScheduleFrom
->time() == m_ui
->timeEditScheduleTo
->time())
2009 QMessageBox::warning(this, tr("Time Error"), tr("The start time and the end time can't be the same."));
2015 void OptionsDialog::on_banListButton_clicked()
2017 auto *dialog
= new BanListOptionsDialog(this);
2018 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
2019 connect(dialog
, &QDialog::accepted
, this, &OptionsDialog::enableApplyButton
);
2023 void OptionsDialog::on_IPSubnetWhitelistButton_clicked()
2025 auto *dialog
= new IPSubnetWhitelistOptionsDialog(this);
2026 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
2027 connect(dialog
, &QDialog::accepted
, this, &OptionsDialog::enableApplyButton
);