2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2023-2024 Vladimir Golovnev <glassez@yandex.ru>
4 * Copyright (C) 2024 Jonathan Ketchker
5 * Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * In addition, as a special exception, the copyright holders give permission to
22 * link this program with the OpenSSL project's "OpenSSL" library (or with
23 * modified versions of it that use the same license as the "OpenSSL" library),
24 * and distribute the linked executables. You must obey the GNU General Public
25 * License in all respects for all of the code used other than "OpenSSL". If you
26 * modify file(s), you may extend this exception to your version of the file(s),
27 * but you are not obligated to do so. If you do not wish to do so, delete this
28 * exception statement from your version.
31 #include "optionsdialog.h"
38 #include <QApplication>
40 #include <QDesktopServices>
41 #include <QDialogButtonBox>
43 #include <QFileDialog>
44 #include <QMessageBox>
45 #include <QSystemTrayIcon>
46 #include <QTranslator>
49 #include <QStyleFactory>
52 #include "base/bittorrent/session.h"
53 #include "base/bittorrent/sharelimitaction.h"
54 #include "base/exceptions.h"
55 #include "base/global.h"
56 #include "base/net/portforwarder.h"
57 #include "base/net/proxyconfigurationmanager.h"
58 #include "base/path.h"
59 #include "base/preferences.h"
60 #include "base/rss/rss_autodownloader.h"
61 #include "base/rss/rss_session.h"
62 #include "base/torrentfileguard.h"
63 #include "base/torrentfileswatcher.h"
64 #include "base/utils/compare.h"
65 #include "base/utils/io.h"
66 #include "base/utils/misc.h"
67 #include "base/utils/net.h"
68 #include "base/utils/os.h"
69 #include "base/utils/password.h"
70 #include "base/utils/random.h"
71 #include "base/utils/sslkey.h"
72 #include "addnewtorrentdialog.h"
73 #include "advancedsettings.h"
74 #include "banlistoptionsdialog.h"
75 #include "interfaces/iguiapplication.h"
76 #include "ipsubnetwhitelistoptionsdialog.h"
77 #include "rss/automatedrssdownloader.h"
78 #include "ui_optionsdialog.h"
79 #include "uithemedialog.h"
80 #include "uithememanager.h"
82 #include "watchedfolderoptionsdialog.h"
83 #include "watchedfoldersmodel.h"
84 #include "webui/webui.h"
87 #include "base/net/dnsupdater.h"
90 #if defined Q_OS_MACOS || defined Q_OS_WIN
91 #include "base/utils/os.h"
92 #endif // defined Q_OS_MACOS || defined Q_OS_WIN
94 #define SETTINGS_KEY(name) u"OptionsDialog/" name
96 const int WEBUI_MIN_USERNAME_LENGTH
= 3;
97 const int WEBUI_MIN_PASSWORD_LENGTH
= 6;
101 QStringList
translatedWeekdayNames()
103 // return translated strings from Monday to Sunday in user selected locale
105 const QLocale locale
{Preferences::instance()->getLocale()};
106 const QDate date
{2018, 11, 5}; // Monday
108 for (int i
= 0; i
< 7; ++i
)
109 ret
.append(locale
.toString(date
.addDays(i
), u
"dddd"_s
));
113 class WheelEventEater final
: public QObject
116 using QObject::QObject
;
119 bool eventFilter(QObject
*, QEvent
*event
) override
121 return (event
->type() == QEvent::Wheel
);
125 bool isValidWebUIUsername(const QString
&username
)
127 return (username
.length() >= WEBUI_MIN_USERNAME_LENGTH
);
130 bool isValidWebUIPassword(const QString
&password
)
132 return (password
.length() >= WEBUI_MIN_PASSWORD_LENGTH
);
135 // Shortcuts for frequently used signals that have more than one overload. They would require
136 // type casts and that is why we declare required member pointer here instead.
137 void (QComboBox::*qComboBoxCurrentIndexChanged
)(int) = &QComboBox::currentIndexChanged
;
138 void (QSpinBox::*qSpinBoxValueChanged
)(int) = &QSpinBox::valueChanged
;
142 OptionsDialog::OptionsDialog(IGUIApplication
*app
, QWidget
*parent
)
143 : GUIApplicationComponent(app
, parent
)
144 , m_ui
{new Ui::OptionsDialog
}
145 , m_storeDialogSize
{SETTINGS_KEY(u
"Size"_s
)}
146 , m_storeHSplitterSize
{SETTINGS_KEY(u
"HorizontalSplitterSizes"_s
)}
147 , m_storeLastViewedPage
{SETTINGS_KEY(u
"LastViewedPage"_s
)}
150 m_applyButton
= m_ui
->buttonBox
->button(QDialogButtonBox::Apply
);
153 setWindowTitle(tr("Preferences"));
156 m_ui
->hsplitter
->setCollapsible(0, false);
157 m_ui
->hsplitter
->setCollapsible(1, false);
160 m_ui
->tabSelection
->item(TAB_UI
)->setIcon(UIThemeManager::instance()->getIcon(u
"preferences-desktop"_s
));
161 m_ui
->tabSelection
->item(TAB_BITTORRENT
)->setIcon(UIThemeManager::instance()->getIcon(u
"preferences-bittorrent"_s
, u
"preferences-system-network"_s
));
162 m_ui
->tabSelection
->item(TAB_CONNECTION
)->setIcon(UIThemeManager::instance()->getIcon(u
"network-connect"_s
, u
"network-wired"_s
));
163 m_ui
->tabSelection
->item(TAB_DOWNLOADS
)->setIcon(UIThemeManager::instance()->getIcon(u
"download"_s
, u
"folder-download"_s
));
164 m_ui
->tabSelection
->item(TAB_SPEED
)->setIcon(UIThemeManager::instance()->getIcon(u
"speedometer"_s
, u
"chronometer"_s
));
165 m_ui
->tabSelection
->item(TAB_RSS
)->setIcon(UIThemeManager::instance()->getIcon(u
"application-rss"_s
, u
"application-rss+xml"_s
));
167 m_ui
->tabSelection
->item(TAB_WEBUI
)->setHidden(true);
169 m_ui
->tabSelection
->item(TAB_WEBUI
)->setIcon(UIThemeManager::instance()->getIcon(u
"preferences-webui"_s
, u
"network-server"_s
));
171 m_ui
->tabSelection
->item(TAB_ADVANCED
)->setIcon(UIThemeManager::instance()->getIcon(u
"preferences-advanced"_s
, u
"preferences-other"_s
));
173 // set uniform size for all icons
175 for (int i
= 0; i
< m_ui
->tabSelection
->count(); ++i
)
176 maxHeight
= std::max(maxHeight
, m_ui
->tabSelection
->visualItemRect(m_ui
->tabSelection
->item(i
)).size().height());
177 for (int i
= 0; i
< m_ui
->tabSelection
->count(); ++i
)
179 const QSize
size(std::numeric_limits
<int>::max(), static_cast<int>(maxHeight
* 1.2));
180 m_ui
->tabSelection
->item(i
)->setSizeHint(size
);
183 connect(m_ui
->tabSelection
, &QListWidget::currentItemChanged
, this, &ThisType::changePage
);
186 loadBehaviorTabOptions();
187 loadDownloadsTabOptions();
188 loadConnectionTabOptions();
189 loadSpeedTabOptions();
190 loadBittorrentTabOptions();
192 #ifndef DISABLE_WEBUI
193 loadWebUITabOptions();
196 // Load Advanced settings
197 m_advancedSettings
= new AdvancedSettings(app
, m_ui
->tabAdvancedPage
);
198 m_ui
->advPageLayout
->addWidget(m_advancedSettings
);
199 connect(m_advancedSettings
, &AdvancedSettings::settingsChanged
, this, &ThisType::enableApplyButton
);
201 // setup apply button
202 m_applyButton
->setEnabled(false);
203 connect(m_applyButton
, &QPushButton::clicked
, this, [this]
206 m_applyButton
->setEnabled(false);
209 // disable mouse wheel event on widgets to avoid misselection
210 auto *wheelEventEater
= new WheelEventEater(this);
211 for (QComboBox
*widget
: asConst(findChildren
<QComboBox
*>()))
212 widget
->installEventFilter(wheelEventEater
);
213 for (QSpinBox
*widget
: asConst(findChildren
<QSpinBox
*>()))
214 widget
->installEventFilter(wheelEventEater
);
216 m_ui
->tabSelection
->setCurrentRow(m_storeLastViewedPage
);
218 if (const QSize dialogSize
= m_storeDialogSize
; dialogSize
.isValid())
222 OptionsDialog::~OptionsDialog()
224 // save dialog states
225 m_storeDialogSize
= size();
227 QStringList hSplitterSizes
;
228 for (const int size
: asConst(m_ui
->hsplitter
->sizes()))
229 hSplitterSizes
.append(QString::number(size
));
230 m_storeHSplitterSize
= hSplitterSizes
;
232 m_storeLastViewedPage
= m_ui
->tabSelection
->currentRow();
237 void OptionsDialog::loadBehaviorTabOptions()
239 const auto *pref
= Preferences::instance();
240 const auto *session
= BitTorrent::Session::instance();
242 initializeLanguageCombo();
243 setLocale(pref
->getLocale());
245 initializeStyleCombo();
247 m_ui
->checkUseCustomTheme
->setChecked(Preferences::instance()->useCustomUITheme());
248 m_ui
->customThemeFilePath
->setSelectedPath(Preferences::instance()->customUIThemePath());
249 m_ui
->customThemeFilePath
->setMode(FileSystemPathEdit::Mode::FileOpen
);
250 m_ui
->customThemeFilePath
->setDialogCaption(tr("Select qBittorrent UI Theme file"));
251 m_ui
->customThemeFilePath
->setFileNameFilter(tr("qBittorrent UI Theme file (*.qbtheme config.json)"));
252 #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
253 m_ui
->checkUseSystemIcon
->setChecked(pref
->useSystemIcons());
255 m_ui
->checkUseSystemIcon
->setVisible(false);
258 m_ui
->confirmDeletion
->setChecked(pref
->confirmTorrentDeletion());
259 m_ui
->checkAltRowColors
->setChecked(pref
->useAlternatingRowColors());
260 m_ui
->checkHideZero
->setChecked(pref
->getHideZeroValues());
261 m_ui
->comboHideZero
->setCurrentIndex(pref
->getHideZeroComboValues());
262 m_ui
->comboHideZero
->setEnabled(m_ui
->checkHideZero
->isChecked());
264 m_ui
->actionTorrentDlOnDblClBox
->setItemData(0, TOGGLE_STOP
);
265 m_ui
->actionTorrentDlOnDblClBox
->setItemData(1, OPEN_DEST
);
266 m_ui
->actionTorrentDlOnDblClBox
->setItemData(2, PREVIEW_FILE
);
267 m_ui
->actionTorrentDlOnDblClBox
->setItemData(3, SHOW_OPTIONS
);
268 m_ui
->actionTorrentDlOnDblClBox
->setItemData(4, NO_ACTION
);
269 int actionDownloading
= pref
->getActionOnDblClOnTorrentDl();
270 if ((actionDownloading
< 0) || (actionDownloading
>= m_ui
->actionTorrentDlOnDblClBox
->count()))
271 actionDownloading
= TOGGLE_STOP
;
272 m_ui
->actionTorrentDlOnDblClBox
->setCurrentIndex(m_ui
->actionTorrentDlOnDblClBox
->findData(actionDownloading
));
274 m_ui
->actionTorrentFnOnDblClBox
->setItemData(0, TOGGLE_STOP
);
275 m_ui
->actionTorrentFnOnDblClBox
->setItemData(1, OPEN_DEST
);
276 m_ui
->actionTorrentFnOnDblClBox
->setItemData(2, PREVIEW_FILE
);
277 m_ui
->actionTorrentFnOnDblClBox
->setItemData(3, SHOW_OPTIONS
);
278 m_ui
->actionTorrentFnOnDblClBox
->setItemData(4, NO_ACTION
);
279 int actionSeeding
= pref
->getActionOnDblClOnTorrentFn();
280 if ((actionSeeding
< 0) || (actionSeeding
>= m_ui
->actionTorrentFnOnDblClBox
->count()))
281 actionSeeding
= OPEN_DEST
;
282 m_ui
->actionTorrentFnOnDblClBox
->setCurrentIndex(m_ui
->actionTorrentFnOnDblClBox
->findData(actionSeeding
));
284 m_ui
->checkBoxHideZeroStatusFilters
->setChecked(pref
->getHideZeroStatusFilters());
287 m_ui
->checkStartup
->setVisible(false);
289 m_ui
->checkShowSplash
->setChecked(!pref
->isSplashScreenDisabled());
290 m_ui
->checkProgramExitConfirm
->setChecked(pref
->confirmOnExit());
291 m_ui
->checkProgramAutoExitConfirm
->setChecked(!pref
->dontConfirmAutoExit());
293 m_ui
->windowStateComboBox
->addItem(tr("Normal"), QVariant::fromValue(WindowState::Normal
));
294 m_ui
->windowStateComboBox
->addItem(tr("Minimized"), QVariant::fromValue(WindowState::Minimized
));
296 m_ui
->windowStateComboBox
->addItem(tr("Hidden"), QVariant::fromValue(WindowState::Hidden
));
298 m_ui
->windowStateComboBox
->setCurrentIndex(m_ui
->windowStateComboBox
->findData(QVariant::fromValue(app()->startUpWindowState())));
300 #if !(defined(Q_OS_WIN) || defined(Q_OS_MACOS))
301 m_ui
->groupFileAssociation
->setVisible(false);
302 m_ui
->checkProgramUpdates
->setVisible(false);
306 // Disable systray integration if it is not supported by the system
307 if (!QSystemTrayIcon::isSystemTrayAvailable())
309 m_ui
->checkShowSystray
->setChecked(false);
310 m_ui
->checkShowSystray
->setEnabled(false);
311 m_ui
->checkShowSystray
->setToolTip(tr("Disabled due to failed to detect system tray presence"));
313 m_ui
->checkShowSystray
->setChecked(pref
->systemTrayEnabled());
314 m_ui
->checkMinimizeToSysTray
->setChecked(pref
->minimizeToTray());
315 m_ui
->checkCloseToSystray
->setChecked(pref
->closeToTray());
316 m_ui
->comboTrayIcon
->setCurrentIndex(static_cast<int>(pref
->trayIconStyle()));
320 m_ui
->checkStartup
->setChecked(pref
->WinStartup());
324 m_ui
->checkShowSystray
->setVisible(false);
325 m_ui
->checkAssociateTorrents
->setChecked(Utils::OS::isTorrentFileAssocSet());
326 m_ui
->checkAssociateTorrents
->setEnabled(!m_ui
->checkAssociateTorrents
->isChecked());
327 m_ui
->checkAssociateMagnetLinks
->setChecked(Utils::OS::isMagnetLinkAssocSet());
328 m_ui
->checkAssociateMagnetLinks
->setEnabled(!m_ui
->checkAssociateMagnetLinks
->isChecked());
331 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
332 m_ui
->checkProgramUpdates
->setChecked(pref
->isUpdateCheckEnabled());
335 m_ui
->checkPreventFromSuspendWhenDownloading
->setChecked(pref
->preventFromSuspendWhenDownloading());
336 m_ui
->checkPreventFromSuspendWhenSeeding
->setChecked(pref
->preventFromSuspendWhenSeeding());
338 m_ui
->textFileLogPath
->setDialogCaption(tr("Choose a save directory"));
339 m_ui
->textFileLogPath
->setMode(FileSystemPathEdit::Mode::DirectorySave
);
340 m_ui
->textFileLogPath
->setSelectedPath(app()->fileLoggerPath());
341 const bool fileLogBackup
= app()->isFileLoggerBackup();
342 m_ui
->checkFileLogBackup
->setChecked(fileLogBackup
);
343 m_ui
->spinFileLogSize
->setEnabled(fileLogBackup
);
344 const bool fileLogDelete
= app()->isFileLoggerDeleteOld();
345 m_ui
->checkFileLogDelete
->setChecked(fileLogDelete
);
346 m_ui
->spinFileLogAge
->setEnabled(fileLogDelete
);
347 m_ui
->comboFileLogAgeType
->setEnabled(fileLogDelete
);
348 m_ui
->spinFileLogSize
->setValue(app()->fileLoggerMaxSize() / 1024);
349 m_ui
->spinFileLogAge
->setValue(app()->fileLoggerAge());
350 m_ui
->comboFileLogAgeType
->setCurrentIndex(app()->fileLoggerAgeType());
351 // Groupbox's check state must be initialized after some of its children if they are manually enabled/disabled
352 m_ui
->checkFileLog
->setChecked(app()->isFileLoggerEnabled());
354 m_ui
->checkBoxPerformanceWarning
->setChecked(session
->isPerformanceWarningEnabled());
356 connect(m_ui
->comboLanguage
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
359 connect(m_ui
->comboStyle
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
362 #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
363 connect(m_ui
->checkUseSystemIcon
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
365 connect(m_ui
->checkUseCustomTheme
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
366 connect(m_ui
->customThemeFilePath
, &FileSystemPathEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
368 m_ui
->buttonCustomizeUITheme
->setEnabled(!m_ui
->checkUseCustomTheme
->isChecked());
369 connect(m_ui
->checkUseCustomTheme
, &QGroupBox::toggled
, this, [this]
371 m_ui
->buttonCustomizeUITheme
->setEnabled(!m_ui
->checkUseCustomTheme
->isChecked());
373 connect(m_ui
->buttonCustomizeUITheme
, &QPushButton::clicked
, this, [this]
375 auto *dialog
= new UIThemeDialog(this);
376 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
380 connect(m_ui
->confirmDeletion
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
381 connect(m_ui
->checkAltRowColors
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
382 connect(m_ui
->checkHideZero
, &QAbstractButton::toggled
, m_ui
->comboHideZero
, &QWidget::setEnabled
);
383 connect(m_ui
->checkHideZero
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
384 connect(m_ui
->comboHideZero
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
385 connect(m_ui
->actionTorrentDlOnDblClBox
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
386 connect(m_ui
->actionTorrentFnOnDblClBox
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
387 connect(m_ui
->checkBoxHideZeroStatusFilters
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
390 connect(m_ui
->checkStartup
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
392 connect(m_ui
->checkShowSplash
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
393 connect(m_ui
->checkProgramExitConfirm
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
394 connect(m_ui
->checkProgramAutoExitConfirm
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
395 connect(m_ui
->checkShowSystray
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
396 connect(m_ui
->checkMinimizeToSysTray
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
397 connect(m_ui
->checkCloseToSystray
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
398 connect(m_ui
->comboTrayIcon
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
399 connect(m_ui
->windowStateComboBox
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
401 connect(m_ui
->checkPreventFromSuspendWhenDownloading
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
402 connect(m_ui
->checkPreventFromSuspendWhenSeeding
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
404 #if defined(Q_OS_MACOS)
405 connect(m_ui
->checkAssociateTorrents
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
406 connect(m_ui
->checkAssociateMagnetLinks
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
409 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
410 connect(m_ui
->checkProgramUpdates
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
414 m_ui
->assocPanel
->hide();
418 m_ui
->defaultProgramPanel
->hide();
421 #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && !defined(QBT_USES_DBUS)
422 m_ui
->checkPreventFromSuspendWhenDownloading
->setDisabled(true);
423 m_ui
->checkPreventFromSuspendWhenSeeding
->setDisabled(true);
426 connect(m_ui
->checkFileLog
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
427 connect(m_ui
->textFileLogPath
, &FileSystemPathEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
428 connect(m_ui
->checkFileLogBackup
, &QAbstractButton::toggled
, m_ui
->spinFileLogSize
, &QWidget::setEnabled
);
429 connect(m_ui
->checkFileLogBackup
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
430 connect(m_ui
->checkFileLogDelete
, &QAbstractButton::toggled
, m_ui
->comboFileLogAgeType
, &QWidget::setEnabled
);
431 connect(m_ui
->checkFileLogDelete
, &QAbstractButton::toggled
, m_ui
->spinFileLogAge
, &QWidget::setEnabled
);
432 connect(m_ui
->checkFileLogDelete
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
433 connect(m_ui
->spinFileLogSize
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
434 connect(m_ui
->spinFileLogAge
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
435 connect(m_ui
->comboFileLogAgeType
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
437 connect(m_ui
->checkBoxPerformanceWarning
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
440 void OptionsDialog::saveBehaviorTabOptions() const
442 auto *pref
= Preferences::instance();
443 auto *session
= BitTorrent::Session::instance();
445 // Load the translation
446 const QString locale
= getLocale();
447 if (pref
->getLocale() != locale
)
449 auto *translator
= new QTranslator
;
450 if (translator
->load(u
":/lang/qbittorrent_"_s
+ locale
))
451 qDebug("%s locale recognized, using translation.", qUtf8Printable(locale
));
453 qDebug("%s locale unrecognized, using default (en).", qUtf8Printable(locale
));
454 qApp
->installTranslator(translator
);
456 pref
->setLocale(locale
);
459 if (const QVariant systemStyle
= m_ui
->comboStyle
->currentData(); systemStyle
.isValid())
460 pref
->setStyle(systemStyle
.toString());
462 pref
->setStyle(m_ui
->comboStyle
->currentText());
465 #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
466 pref
->useSystemIcons(m_ui
->checkUseSystemIcon
->isChecked());
468 pref
->setUseCustomUITheme(m_ui
->checkUseCustomTheme
->isChecked());
469 pref
->setCustomUIThemePath(m_ui
->customThemeFilePath
->selectedPath());
471 pref
->setConfirmTorrentDeletion(m_ui
->confirmDeletion
->isChecked());
472 pref
->setAlternatingRowColors(m_ui
->checkAltRowColors
->isChecked());
473 pref
->setHideZeroValues(m_ui
->checkHideZero
->isChecked());
474 pref
->setHideZeroComboValues(m_ui
->comboHideZero
->currentIndex());
476 pref
->setActionOnDblClOnTorrentDl(m_ui
->actionTorrentDlOnDblClBox
->currentData().toInt());
477 pref
->setActionOnDblClOnTorrentFn(m_ui
->actionTorrentFnOnDblClBox
->currentData().toInt());
479 pref
->setHideZeroStatusFilters(m_ui
->checkBoxHideZeroStatusFilters
->isChecked());
481 pref
->setSplashScreenDisabled(isSplashScreenDisabled());
482 pref
->setConfirmOnExit(m_ui
->checkProgramExitConfirm
->isChecked());
483 pref
->setDontConfirmAutoExit(!m_ui
->checkProgramAutoExitConfirm
->isChecked());
486 pref
->setWinStartup(WinStartup());
490 pref
->setSystemTrayEnabled(m_ui
->checkShowSystray
->isChecked());
491 pref
->setTrayIconStyle(TrayIcon::Style(m_ui
->comboTrayIcon
->currentIndex()));
492 pref
->setCloseToTray(m_ui
->checkCloseToSystray
->isChecked());
493 pref
->setMinimizeToTray(m_ui
->checkMinimizeToSysTray
->isChecked());
497 if (m_ui
->checkAssociateTorrents
->isChecked())
499 Utils::OS::setTorrentFileAssoc();
500 m_ui
->checkAssociateTorrents
->setChecked(Utils::OS::isTorrentFileAssocSet());
501 m_ui
->checkAssociateTorrents
->setEnabled(!m_ui
->checkAssociateTorrents
->isChecked());
503 if (m_ui
->checkAssociateMagnetLinks
->isChecked())
505 Utils::OS::setMagnetLinkAssoc();
506 m_ui
->checkAssociateMagnetLinks
->setChecked(Utils::OS::isMagnetLinkAssocSet());
507 m_ui
->checkAssociateMagnetLinks
->setEnabled(!m_ui
->checkAssociateMagnetLinks
->isChecked());
511 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
512 pref
->setUpdateCheckEnabled(m_ui
->checkProgramUpdates
->isChecked());
515 pref
->setPreventFromSuspendWhenDownloading(m_ui
->checkPreventFromSuspendWhenDownloading
->isChecked());
516 pref
->setPreventFromSuspendWhenSeeding(m_ui
->checkPreventFromSuspendWhenSeeding
->isChecked());
518 app()->setFileLoggerPath(m_ui
->textFileLogPath
->selectedPath());
519 app()->setFileLoggerBackup(m_ui
->checkFileLogBackup
->isChecked());
520 app()->setFileLoggerMaxSize(m_ui
->spinFileLogSize
->value() * 1024);
521 app()->setFileLoggerAge(m_ui
->spinFileLogAge
->value());
522 app()->setFileLoggerAgeType(m_ui
->comboFileLogAgeType
->currentIndex());
523 app()->setFileLoggerDeleteOld(m_ui
->checkFileLogDelete
->isChecked());
524 app()->setFileLoggerEnabled(m_ui
->checkFileLog
->isChecked());
526 app()->setStartUpWindowState(m_ui
->windowStateComboBox
->currentData().value
<WindowState
>());
528 session
->setPerformanceWarningEnabled(m_ui
->checkBoxPerformanceWarning
->isChecked());
531 void OptionsDialog::loadDownloadsTabOptions()
533 const auto *pref
= Preferences::instance();
534 const auto *session
= BitTorrent::Session::instance();
536 m_ui
->checkAdditionDialog
->setChecked(pref
->isAddNewTorrentDialogEnabled());
537 m_ui
->checkAdditionDialogFront
->setChecked(pref
->isAddNewTorrentDialogTopLevel());
539 m_ui
->contentLayoutComboBox
->setCurrentIndex(static_cast<int>(session
->torrentContentLayout()));
540 m_ui
->checkAddToQueueTop
->setChecked(session
->isAddTorrentToQueueTop());
541 m_ui
->checkAddStopped
->setChecked(session
->isAddTorrentStopped());
543 m_ui
->stopConditionComboBox
->setToolTip(
544 u
"<html><body><p><b>" + tr("None") + u
"</b> - " + tr("No stop condition is set.") + u
"</p><p><b>" +
545 tr("Metadata received") + u
"</b> - " + tr("Torrent will stop after metadata is received.") +
546 u
" <em>" + tr("Torrents that have metadata initially will be added as stopped.") + u
"</em></p><p><b>" +
547 tr("Files checked") + u
"</b> - " + tr("Torrent will stop after files are initially checked.") +
548 u
" <em>" + tr("This will also download metadata if it wasn't there initially.") + u
"</em></p></body></html>");
549 m_ui
->stopConditionComboBox
->setItemData(0, QVariant::fromValue(BitTorrent::Torrent::StopCondition::None
));
550 m_ui
->stopConditionComboBox
->setItemData(1, QVariant::fromValue(BitTorrent::Torrent::StopCondition::MetadataReceived
));
551 m_ui
->stopConditionComboBox
->setItemData(2, QVariant::fromValue(BitTorrent::Torrent::StopCondition::FilesChecked
));
552 m_ui
->stopConditionComboBox
->setCurrentIndex(m_ui
->stopConditionComboBox
->findData(QVariant::fromValue(session
->torrentStopCondition())));
553 m_ui
->stopConditionLabel
->setEnabled(!m_ui
->checkAddStopped
->isChecked());
554 m_ui
->stopConditionComboBox
->setEnabled(!m_ui
->checkAddStopped
->isChecked());
556 m_ui
->checkMergeTrackers
->setChecked(session
->isMergeTrackersEnabled());
557 m_ui
->checkConfirmMergeTrackers
->setEnabled(m_ui
->checkAdditionDialog
->isChecked());
558 m_ui
->checkConfirmMergeTrackers
->setChecked(m_ui
->checkConfirmMergeTrackers
->isEnabled() ? pref
->confirmMergeTrackers() : false);
559 connect(m_ui
->checkAdditionDialog
, &QGroupBox::toggled
, this, [this, pref
]
561 m_ui
->checkConfirmMergeTrackers
->setEnabled(m_ui
->checkAdditionDialog
->isChecked());
562 m_ui
->checkConfirmMergeTrackers
->setChecked(m_ui
->checkConfirmMergeTrackers
->isEnabled() ? pref
->confirmMergeTrackers() : false);
565 const TorrentFileGuard::AutoDeleteMode autoDeleteMode
= TorrentFileGuard::autoDeleteMode();
566 m_ui
->deleteTorrentBox
->setChecked(autoDeleteMode
!= TorrentFileGuard::Never
);
567 m_ui
->deleteCancelledTorrentBox
->setChecked(autoDeleteMode
== TorrentFileGuard::Always
);
568 m_ui
->deleteTorrentWarningIcon
->setPixmap(QApplication::style()->standardIcon(QStyle::SP_MessageBoxCritical
).pixmap(16, 16));
569 m_ui
->deleteTorrentWarningIcon
->hide();
570 m_ui
->deleteTorrentWarningLabel
->hide();
571 m_ui
->deleteTorrentWarningLabel
->setToolTip(u
"<html><body><p>" +
572 tr("By enabling these options, you can <strong>irrevocably lose</strong> your .torrent files!") +
574 tr("When these options are enabled, qBittorrent will <strong>delete</strong> .torrent files "
575 "after they were successfully (the first option) or not (the second option) added to its "
576 "download queue. This will be applied <strong>not only</strong> to the files opened via "
577 "“Add torrent” menu action but to those opened via <strong>file type association</strong> as well") +
579 tr("If you enable the second option (“Also when addition is cancelled”) the "
580 ".torrent file <strong>will be deleted</strong> even if you press “<strong>Cancel</strong>” in "
581 "the “Add torrent” dialog") +
582 u
"</p></body></html>");
584 m_ui
->checkPreallocateAll
->setChecked(session
->isPreallocationEnabled());
585 m_ui
->checkAppendqB
->setChecked(session
->isAppendExtensionEnabled());
586 m_ui
->checkUnwantedFolder
->setChecked(session
->isUnwantedFolderEnabled());
587 m_ui
->checkRecursiveDownload
->setChecked(pref
->isRecursiveDownloadEnabled());
589 m_ui
->comboSavingMode
->setCurrentIndex(!session
->isAutoTMMDisabledByDefault());
590 m_ui
->comboTorrentCategoryChanged
->setCurrentIndex(session
->isDisableAutoTMMWhenCategoryChanged());
591 m_ui
->comboCategoryChanged
->setCurrentIndex(session
->isDisableAutoTMMWhenCategorySavePathChanged());
592 m_ui
->comboCategoryDefaultPathChanged
->setCurrentIndex(session
->isDisableAutoTMMWhenDefaultSavePathChanged());
594 m_ui
->checkUseSubcategories
->setChecked(session
->isSubcategoriesEnabled());
595 m_ui
->checkUseCategoryPaths
->setChecked(session
->useCategoryPathsInManualMode());
597 m_ui
->textSavePath
->setDialogCaption(tr("Choose a save directory"));
598 m_ui
->textSavePath
->setMode(FileSystemPathEdit::Mode::DirectorySave
);
599 m_ui
->textSavePath
->setSelectedPath(session
->savePath());
601 m_ui
->checkUseDownloadPath
->setChecked(session
->isDownloadPathEnabled());
602 m_ui
->textDownloadPath
->setDialogCaption(tr("Choose a save directory"));
603 m_ui
->textDownloadPath
->setEnabled(m_ui
->checkUseDownloadPath
->isChecked());
604 m_ui
->textDownloadPath
->setMode(FileSystemPathEdit::Mode::DirectorySave
);
605 m_ui
->textDownloadPath
->setSelectedPath(session
->downloadPath());
607 const bool isExportDirEmpty
= session
->torrentExportDirectory().isEmpty();
608 m_ui
->checkExportDir
->setChecked(!isExportDirEmpty
);
609 m_ui
->textExportDir
->setDialogCaption(tr("Choose export directory"));
610 m_ui
->textExportDir
->setEnabled(m_ui
->checkExportDir
->isChecked());
611 m_ui
->textExportDir
->setMode(FileSystemPathEdit::Mode::DirectorySave
);
612 if (!isExportDirEmpty
)
613 m_ui
->textExportDir
->setSelectedPath(session
->torrentExportDirectory());
615 const bool isExportDirFinEmpty
= session
->finishedTorrentExportDirectory().isEmpty();
616 m_ui
->checkExportDirFin
->setChecked(!isExportDirFinEmpty
);
617 m_ui
->textExportDirFin
->setDialogCaption(tr("Choose export directory"));
618 m_ui
->textExportDirFin
->setEnabled(m_ui
->checkExportDirFin
->isChecked());
619 m_ui
->textExportDirFin
->setMode(FileSystemPathEdit::Mode::DirectorySave
);
620 if (!isExportDirFinEmpty
)
621 m_ui
->textExportDirFin
->setSelectedPath(session
->finishedTorrentExportDirectory());
623 auto *watchedFoldersModel
= new WatchedFoldersModel(TorrentFilesWatcher::instance(), this);
624 connect(watchedFoldersModel
, &QAbstractListModel::dataChanged
, this, &ThisType::enableApplyButton
);
625 m_ui
->scanFoldersView
->header()->setSectionResizeMode(QHeaderView::ResizeToContents
);
626 m_ui
->scanFoldersView
->setModel(watchedFoldersModel
);
627 connect(m_ui
->scanFoldersView
->selectionModel(), &QItemSelectionModel::selectionChanged
, this, &ThisType::handleWatchedFolderViewSelectionChanged
);
628 connect(m_ui
->scanFoldersView
, &QTreeView::doubleClicked
, this, &ThisType::editWatchedFolderOptions
);
630 m_ui
->groupExcludedFileNames
->setChecked(session
->isExcludedFileNamesEnabled());
631 m_ui
->textExcludedFileNames
->setPlainText(session
->excludedFileNames().join(u
'\n'));
633 m_ui
->groupMailNotification
->setChecked(pref
->isMailNotificationEnabled());
634 m_ui
->senderEmailTxt
->setText(pref
->getMailNotificationSender());
635 m_ui
->lineEditDestEmail
->setText(pref
->getMailNotificationEmail());
636 m_ui
->lineEditSmtpServer
->setText(pref
->getMailNotificationSMTP());
637 m_ui
->checkSmtpSSL
->setChecked(pref
->getMailNotificationSMTPSSL());
638 m_ui
->groupMailNotifAuth
->setChecked(pref
->getMailNotificationSMTPAuth());
639 m_ui
->mailNotifUsername
->setText(pref
->getMailNotificationSMTPUsername());
640 m_ui
->mailNotifPassword
->setText(pref
->getMailNotificationSMTPPassword());
642 m_ui
->groupBoxRunOnAdded
->setChecked(pref
->isAutoRunOnTorrentAddedEnabled());
643 m_ui
->groupBoxRunOnFinished
->setChecked(pref
->isAutoRunOnTorrentFinishedEnabled());
644 m_ui
->lineEditRunOnAdded
->setText(pref
->getAutoRunOnTorrentAddedProgram());
645 m_ui
->lineEditRunOnFinished
->setText(pref
->getAutoRunOnTorrentFinishedProgram());
646 #if defined(Q_OS_WIN)
647 m_ui
->autoRunConsole
->setChecked(pref
->isAutoRunConsoleEnabled());
649 m_ui
->autoRunConsole
->hide();
651 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
652 .arg(tr("Supported parameters (case sensitive):")
653 , tr("%N: Torrent name")
655 , tr("%G: Tags (separated by comma)")
656 , tr("%F: Content path (same as root path for multifile torrent)")
657 , tr("%R: Root path (first torrent subdirectory path)")
658 , tr("%D: Save path")
659 , tr("%C: Number of files")
660 , tr("%Z: Torrent size (bytes)"))
661 .arg(tr("%T: Current tracker")
662 , tr("%I: Info hash v1 (or '-' if unavailable)")
663 , tr("%J: Info hash v2 (or '-' if unavailable)")
664 , tr("%K: Torrent ID (either sha-1 info hash for v1 torrent or truncated sha-256 info hash for v2/hybrid torrent)")
665 , tr("Tip: Encapsulate parameter with quotation marks to avoid text being cut off at whitespace (e.g., \"%N\")"));
666 m_ui
->labelAutoRunParam
->setText(autoRunStr
);
668 connect(m_ui
->checkAdditionDialog
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
669 connect(m_ui
->checkAdditionDialogFront
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
671 connect(m_ui
->contentLayoutComboBox
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
673 connect(m_ui
->checkAddToQueueTop
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
674 connect(m_ui
->checkAddStopped
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
675 connect(m_ui
->checkAddStopped
, &QAbstractButton::toggled
, this, [this](const bool checked
)
677 m_ui
->stopConditionLabel
->setEnabled(!checked
);
678 m_ui
->stopConditionComboBox
->setEnabled(!checked
);
680 connect(m_ui
->stopConditionComboBox
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
681 connect(m_ui
->checkMergeTrackers
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
682 connect(m_ui
->checkConfirmMergeTrackers
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
683 connect(m_ui
->deleteTorrentBox
, &QGroupBox::toggled
, m_ui
->deleteTorrentWarningIcon
, &QWidget::setVisible
);
684 connect(m_ui
->deleteTorrentBox
, &QGroupBox::toggled
, m_ui
->deleteTorrentWarningLabel
, &QWidget::setVisible
);
685 connect(m_ui
->deleteTorrentBox
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
686 connect(m_ui
->deleteCancelledTorrentBox
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
688 connect(m_ui
->checkPreallocateAll
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
689 connect(m_ui
->checkAppendqB
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
690 connect(m_ui
->checkUnwantedFolder
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
691 connect(m_ui
->checkRecursiveDownload
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
693 connect(m_ui
->comboSavingMode
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
694 connect(m_ui
->comboTorrentCategoryChanged
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
695 connect(m_ui
->comboCategoryChanged
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
696 connect(m_ui
->comboCategoryDefaultPathChanged
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
698 connect(m_ui
->checkUseSubcategories
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
699 connect(m_ui
->checkUseCategoryPaths
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
701 connect(m_ui
->textSavePath
, &FileSystemPathEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
702 connect(m_ui
->textDownloadPath
, &FileSystemPathEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
704 connect(m_ui
->checkExportDir
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
705 connect(m_ui
->checkExportDir
, &QAbstractButton::toggled
, m_ui
->textExportDir
, &QWidget::setEnabled
);
706 connect(m_ui
->checkExportDirFin
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
707 connect(m_ui
->checkExportDirFin
, &QAbstractButton::toggled
, m_ui
->textExportDirFin
, &QWidget::setEnabled
);
708 connect(m_ui
->textExportDir
, &FileSystemPathEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
709 connect(m_ui
->textExportDirFin
, &FileSystemPathEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
710 connect(m_ui
->checkUseDownloadPath
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
711 connect(m_ui
->checkUseDownloadPath
, &QAbstractButton::toggled
, m_ui
->textDownloadPath
, &QWidget::setEnabled
);
713 connect(m_ui
->addWatchedFolderButton
, &QAbstractButton::clicked
, this, &ThisType::enableApplyButton
);
715 connect(m_ui
->groupExcludedFileNames
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
716 connect(m_ui
->textExcludedFileNames
, &QPlainTextEdit::textChanged
, this, &ThisType::enableApplyButton
);
717 connect(m_ui
->removeWatchedFolderButton
, &QAbstractButton::clicked
, this, &ThisType::enableApplyButton
);
719 connect(m_ui
->groupMailNotification
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
720 connect(m_ui
->senderEmailTxt
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
721 connect(m_ui
->lineEditDestEmail
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
722 connect(m_ui
->lineEditSmtpServer
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
723 connect(m_ui
->checkSmtpSSL
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
724 connect(m_ui
->groupMailNotifAuth
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
725 connect(m_ui
->mailNotifUsername
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
726 connect(m_ui
->mailNotifPassword
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
727 connect(m_ui
->sendTestEmail
, &QPushButton::clicked
, this, [this]
729 app()->sendTestEmail();
730 QMessageBox::information(this, tr("Test email"), tr("Attempted to send email. Check your inbox to confirm success"));
733 connect(m_ui
->groupBoxRunOnAdded
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
734 connect(m_ui
->lineEditRunOnAdded
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
735 connect(m_ui
->groupBoxRunOnFinished
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
736 connect(m_ui
->lineEditRunOnFinished
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
737 connect(m_ui
->autoRunConsole
, &QCheckBox::toggled
, this, &ThisType::enableApplyButton
);
740 void OptionsDialog::saveDownloadsTabOptions() const
742 auto *pref
= Preferences::instance();
743 auto *session
= BitTorrent::Session::instance();
745 pref
->setAddNewTorrentDialogEnabled(useAdditionDialog());
746 pref
->setAddNewTorrentDialogTopLevel(m_ui
->checkAdditionDialogFront
->isChecked());
748 session
->setTorrentContentLayout(static_cast<BitTorrent::TorrentContentLayout
>(m_ui
->contentLayoutComboBox
->currentIndex()));
750 session
->setAddTorrentToQueueTop(m_ui
->checkAddToQueueTop
->isChecked());
751 session
->setAddTorrentStopped(addTorrentsStopped());
752 session
->setTorrentStopCondition(m_ui
->stopConditionComboBox
->currentData().value
<BitTorrent::Torrent::StopCondition
>());
753 TorrentFileGuard::setAutoDeleteMode(!m_ui
->deleteTorrentBox
->isChecked() ? TorrentFileGuard::Never
754 : !m_ui
->deleteCancelledTorrentBox
->isChecked() ? TorrentFileGuard::IfAdded
755 : TorrentFileGuard::Always
);
756 session
->setMergeTrackersEnabled(m_ui
->checkMergeTrackers
->isChecked());
757 if (m_ui
->checkConfirmMergeTrackers
->isEnabled())
758 pref
->setConfirmMergeTrackers(m_ui
->checkConfirmMergeTrackers
->isChecked());
760 session
->setPreallocationEnabled(preAllocateAllFiles());
761 session
->setAppendExtensionEnabled(m_ui
->checkAppendqB
->isChecked());
762 session
->setUnwantedFolderEnabled(m_ui
->checkUnwantedFolder
->isChecked());
763 pref
->setRecursiveDownloadEnabled(m_ui
->checkRecursiveDownload
->isChecked());
765 session
->setAutoTMMDisabledByDefault(m_ui
->comboSavingMode
->currentIndex() == 0);
766 session
->setDisableAutoTMMWhenCategoryChanged(m_ui
->comboTorrentCategoryChanged
->currentIndex() == 1);
767 session
->setDisableAutoTMMWhenCategorySavePathChanged(m_ui
->comboCategoryChanged
->currentIndex() == 1);
768 session
->setDisableAutoTMMWhenDefaultSavePathChanged(m_ui
->comboCategoryDefaultPathChanged
->currentIndex() == 1);
770 session
->setSubcategoriesEnabled(m_ui
->checkUseSubcategories
->isChecked());
771 session
->setUseCategoryPathsInManualMode(m_ui
->checkUseCategoryPaths
->isChecked());
773 session
->setSavePath(Path(m_ui
->textSavePath
->selectedPath()));
774 session
->setDownloadPathEnabled(m_ui
->checkUseDownloadPath
->isChecked());
775 session
->setDownloadPath(m_ui
->textDownloadPath
->selectedPath());
776 session
->setTorrentExportDirectory(getTorrentExportDir());
777 session
->setFinishedTorrentExportDirectory(getFinishedTorrentExportDir());
779 auto *watchedFoldersModel
= static_cast<WatchedFoldersModel
*>(m_ui
->scanFoldersView
->model());
780 watchedFoldersModel
->apply();
782 session
->setExcludedFileNamesEnabled(m_ui
->groupExcludedFileNames
->isChecked());
783 session
->setExcludedFileNames(m_ui
->textExcludedFileNames
->toPlainText().split(u
'\n', Qt::SkipEmptyParts
));
785 pref
->setMailNotificationEnabled(m_ui
->groupMailNotification
->isChecked());
786 pref
->setMailNotificationSender(m_ui
->senderEmailTxt
->text());
787 pref
->setMailNotificationEmail(m_ui
->lineEditDestEmail
->text());
788 pref
->setMailNotificationSMTP(m_ui
->lineEditSmtpServer
->text());
789 pref
->setMailNotificationSMTPSSL(m_ui
->checkSmtpSSL
->isChecked());
790 pref
->setMailNotificationSMTPAuth(m_ui
->groupMailNotifAuth
->isChecked());
791 pref
->setMailNotificationSMTPUsername(m_ui
->mailNotifUsername
->text());
792 pref
->setMailNotificationSMTPPassword(m_ui
->mailNotifPassword
->text());
794 pref
->setAutoRunOnTorrentAddedEnabled(m_ui
->groupBoxRunOnAdded
->isChecked());
795 pref
->setAutoRunOnTorrentAddedProgram(m_ui
->lineEditRunOnAdded
->text().trimmed());
796 pref
->setAutoRunOnTorrentFinishedEnabled(m_ui
->groupBoxRunOnFinished
->isChecked());
797 pref
->setAutoRunOnTorrentFinishedProgram(m_ui
->lineEditRunOnFinished
->text().trimmed());
798 #if defined(Q_OS_WIN)
799 pref
->setAutoRunConsoleEnabled(m_ui
->autoRunConsole
->isChecked());
803 void OptionsDialog::loadConnectionTabOptions()
805 const auto *session
= BitTorrent::Session::instance();
807 m_ui
->comboProtocol
->setCurrentIndex(static_cast<int>(session
->btProtocol()));
808 m_ui
->spinPort
->setValue(session
->port());
809 m_ui
->checkUPnP
->setChecked(Net::PortForwarder::instance()->isEnabled());
811 int intValue
= session
->maxConnections();
815 m_ui
->checkMaxConnections
->setChecked(true);
816 m_ui
->spinMaxConnec
->setEnabled(true);
817 m_ui
->spinMaxConnec
->setValue(intValue
);
822 m_ui
->checkMaxConnections
->setChecked(false);
823 m_ui
->spinMaxConnec
->setEnabled(false);
825 intValue
= session
->maxConnectionsPerTorrent();
829 m_ui
->checkMaxConnectionsPerTorrent
->setChecked(true);
830 m_ui
->spinMaxConnecPerTorrent
->setEnabled(true);
831 m_ui
->spinMaxConnecPerTorrent
->setValue(intValue
);
836 m_ui
->checkMaxConnectionsPerTorrent
->setChecked(false);
837 m_ui
->spinMaxConnecPerTorrent
->setEnabled(false);
839 intValue
= session
->maxUploads();
843 m_ui
->checkMaxUploads
->setChecked(true);
844 m_ui
->spinMaxUploads
->setEnabled(true);
845 m_ui
->spinMaxUploads
->setValue(intValue
);
850 m_ui
->checkMaxUploads
->setChecked(false);
851 m_ui
->spinMaxUploads
->setEnabled(false);
853 intValue
= session
->maxUploadsPerTorrent();
857 m_ui
->checkMaxUploadsPerTorrent
->setChecked(true);
858 m_ui
->spinMaxUploadsPerTorrent
->setEnabled(true);
859 m_ui
->spinMaxUploadsPerTorrent
->setValue(intValue
);
864 m_ui
->checkMaxUploadsPerTorrent
->setChecked(false);
865 m_ui
->spinMaxUploadsPerTorrent
->setEnabled(false);
868 #if defined(QBT_USES_LIBTORRENT2) && TORRENT_USE_I2P
869 m_ui
->textI2PHost
->setText(session
->I2PAddress());
870 m_ui
->spinI2PPort
->setValue(session
->I2PPort());
871 m_ui
->checkI2PMixed
->setChecked(session
->I2PMixedMode());
872 m_ui
->groupI2P
->setChecked(session
->isI2PEnabled());
874 m_ui
->groupI2P
->hide();
877 const auto *proxyConfigManager
= Net::ProxyConfigurationManager::instance();
878 const Net::ProxyConfiguration proxyConf
= proxyConfigManager
->proxyConfiguration();
880 m_ui
->comboProxyType
->addItem(tr("(None)"), QVariant::fromValue(Net::ProxyType::None
));
881 m_ui
->comboProxyType
->addItem(tr("SOCKS4"), QVariant::fromValue(Net::ProxyType::SOCKS4
));
882 m_ui
->comboProxyType
->addItem(tr("SOCKS5"), QVariant::fromValue(Net::ProxyType::SOCKS5
));
883 m_ui
->comboProxyType
->addItem(tr("HTTP"), QVariant::fromValue(Net::ProxyType::HTTP
));
884 m_ui
->comboProxyType
->setCurrentIndex(m_ui
->comboProxyType
->findData(QVariant::fromValue(proxyConf
.type
)));
885 adjustProxyOptions();
887 m_ui
->textProxyIP
->setText(proxyConf
.ip
);
888 m_ui
->spinProxyPort
->setValue(proxyConf
.port
);
889 m_ui
->textProxyUsername
->setText(proxyConf
.username
);
890 m_ui
->textProxyPassword
->setText(proxyConf
.password
);
891 m_ui
->checkProxyAuth
->setChecked(proxyConf
.authEnabled
);
892 m_ui
->checkProxyHostnameLookup
->setChecked(proxyConf
.hostnameLookupEnabled
);
894 m_ui
->checkProxyPeerConnections
->setChecked(session
->isProxyPeerConnectionsEnabled());
895 m_ui
->checkProxyBitTorrent
->setChecked(Preferences::instance()->useProxyForBT());
896 m_ui
->checkProxyRSS
->setChecked(Preferences::instance()->useProxyForRSS());
897 m_ui
->checkProxyMisc
->setChecked(Preferences::instance()->useProxyForGeneralPurposes());
899 m_ui
->checkIPFilter
->setChecked(session
->isIPFilteringEnabled());
900 m_ui
->textFilterPath
->setDialogCaption(tr("Choose an IP filter file"));
901 m_ui
->textFilterPath
->setEnabled(m_ui
->checkIPFilter
->isChecked());
902 m_ui
->textFilterPath
->setFileNameFilter(tr("All supported filters") + u
" (*.dat *.p2p *.p2b);;.dat (*.dat);;.p2p (*.p2p);;.p2b (*.p2b)");
903 m_ui
->textFilterPath
->setSelectedPath(session
->IPFilterFile());
905 m_ui
->IpFilterRefreshBtn
->setIcon(UIThemeManager::instance()->getIcon(u
"view-refresh"_s
));
906 m_ui
->IpFilterRefreshBtn
->setEnabled(m_ui
->checkIPFilter
->isChecked());
907 m_ui
->checkIpFilterTrackers
->setChecked(session
->isTrackerFilteringEnabled());
909 connect(m_ui
->comboProtocol
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
910 connect(m_ui
->spinPort
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
911 connect(m_ui
->checkUPnP
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
913 connect(m_ui
->checkMaxConnections
, &QAbstractButton::toggled
, m_ui
->spinMaxConnec
, &QWidget::setEnabled
);
914 connect(m_ui
->checkMaxConnections
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
915 connect(m_ui
->checkMaxConnectionsPerTorrent
, &QAbstractButton::toggled
, m_ui
->spinMaxConnecPerTorrent
, &QWidget::setEnabled
);
916 connect(m_ui
->checkMaxConnectionsPerTorrent
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
917 connect(m_ui
->checkMaxUploads
, &QAbstractButton::toggled
, m_ui
->spinMaxUploads
, &QWidget::setEnabled
);
918 connect(m_ui
->checkMaxUploads
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
919 connect(m_ui
->checkMaxUploadsPerTorrent
, &QAbstractButton::toggled
, m_ui
->spinMaxUploadsPerTorrent
, &QWidget::setEnabled
);
920 connect(m_ui
->checkMaxUploadsPerTorrent
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
921 connect(m_ui
->spinMaxConnec
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
922 connect(m_ui
->spinMaxConnecPerTorrent
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
923 connect(m_ui
->spinMaxUploads
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
924 connect(m_ui
->spinMaxUploadsPerTorrent
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
926 connect(m_ui
->comboProxyType
, qComboBoxCurrentIndexChanged
, this, &ThisType::adjustProxyOptions
);
927 connect(m_ui
->comboProxyType
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
928 connect(m_ui
->textProxyIP
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
929 connect(m_ui
->spinProxyPort
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
931 #if defined(QBT_USES_LIBTORRENT2) && TORRENT_USE_I2P
932 connect(m_ui
->textI2PHost
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
933 connect(m_ui
->spinI2PPort
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
934 connect(m_ui
->checkI2PMixed
, &QCheckBox::toggled
, this, &ThisType::enableApplyButton
);
935 connect(m_ui
->groupI2P
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
938 connect(m_ui
->checkProxyBitTorrent
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
939 connect(m_ui
->checkProxyBitTorrent
, &QGroupBox::toggled
, this, &ThisType::adjustProxyOptions
);
940 connect(m_ui
->checkProxyPeerConnections
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
941 connect(m_ui
->checkProxyHostnameLookup
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
942 connect(m_ui
->checkProxyRSS
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
943 connect(m_ui
->checkProxyMisc
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
945 connect(m_ui
->checkProxyAuth
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
946 connect(m_ui
->textProxyUsername
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
947 connect(m_ui
->textProxyPassword
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
949 connect(m_ui
->checkIPFilter
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
950 connect(m_ui
->checkIPFilter
, &QAbstractButton::toggled
, m_ui
->textFilterPath
, &QWidget::setEnabled
);
951 connect(m_ui
->checkIPFilter
, &QAbstractButton::toggled
, m_ui
->IpFilterRefreshBtn
, &QWidget::setEnabled
);
952 connect(m_ui
->textFilterPath
, &FileSystemPathEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
953 connect(m_ui
->checkIpFilterTrackers
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
956 void OptionsDialog::saveConnectionTabOptions() const
958 auto *session
= BitTorrent::Session::instance();
960 session
->setBTProtocol(static_cast<BitTorrent::BTProtocol
>(m_ui
->comboProtocol
->currentIndex()));
961 session
->setPort(getPort());
962 Net::PortForwarder::instance()->setEnabled(isUPnPEnabled());
964 session
->setMaxConnections(getMaxConnections());
965 session
->setMaxConnectionsPerTorrent(getMaxConnectionsPerTorrent());
966 session
->setMaxUploads(getMaxUploads());
967 session
->setMaxUploadsPerTorrent(getMaxUploadsPerTorrent());
969 #if defined(QBT_USES_LIBTORRENT2) && TORRENT_USE_I2P
970 session
->setI2PEnabled(m_ui
->groupI2P
->isChecked());
971 session
->setI2PAddress(m_ui
->textI2PHost
->text().trimmed());
972 session
->setI2PPort(m_ui
->spinI2PPort
->value());
973 session
->setI2PMixedMode(m_ui
->checkI2PMixed
->isChecked());
976 auto *proxyConfigManager
= Net::ProxyConfigurationManager::instance();
977 Net::ProxyConfiguration proxyConf
;
978 proxyConf
.type
= getProxyType();
979 proxyConf
.ip
= getProxyIp();
980 proxyConf
.port
= getProxyPort();
981 proxyConf
.authEnabled
= m_ui
->checkProxyAuth
->isChecked();
982 proxyConf
.username
= getProxyUsername();
983 proxyConf
.password
= getProxyPassword();
984 proxyConf
.hostnameLookupEnabled
= m_ui
->checkProxyHostnameLookup
->isChecked();
985 proxyConfigManager
->setProxyConfiguration(proxyConf
);
987 Preferences::instance()->setUseProxyForBT(m_ui
->checkProxyBitTorrent
->isChecked());
988 Preferences::instance()->setUseProxyForRSS(m_ui
->checkProxyRSS
->isChecked());
989 Preferences::instance()->setUseProxyForGeneralPurposes(m_ui
->checkProxyMisc
->isChecked());
991 session
->setProxyPeerConnectionsEnabled(m_ui
->checkProxyPeerConnections
->isChecked());
994 session
->setIPFilteringEnabled(isIPFilteringEnabled());
995 session
->setTrackerFilteringEnabled(m_ui
->checkIpFilterTrackers
->isChecked());
996 session
->setIPFilterFile(m_ui
->textFilterPath
->selectedPath());
999 void OptionsDialog::loadSpeedTabOptions()
1001 const auto *pref
= Preferences::instance();
1002 const auto *session
= BitTorrent::Session::instance();
1004 m_ui
->labelGlobalRate
->setPixmap(UIThemeManager::instance()->getScaledPixmap(u
"slow_off"_s
, Utils::Gui::mediumIconSize(this).height()));
1005 m_ui
->spinUploadLimit
->setValue(session
->globalUploadSpeedLimit() / 1024);
1006 m_ui
->spinDownloadLimit
->setValue(session
->globalDownloadSpeedLimit() / 1024);
1008 m_ui
->labelAltRate
->setPixmap(UIThemeManager::instance()->getScaledPixmap(u
"slow"_s
, Utils::Gui::mediumIconSize(this).height()));
1009 m_ui
->spinUploadLimitAlt
->setValue(session
->altGlobalUploadSpeedLimit() / 1024);
1010 m_ui
->spinDownloadLimitAlt
->setValue(session
->altGlobalDownloadSpeedLimit() / 1024);
1012 m_ui
->comboBoxScheduleDays
->addItems(translatedWeekdayNames());
1014 m_ui
->groupBoxSchedule
->setChecked(session
->isBandwidthSchedulerEnabled());
1015 m_ui
->timeEditScheduleFrom
->setTime(pref
->getSchedulerStartTime());
1016 m_ui
->timeEditScheduleTo
->setTime(pref
->getSchedulerEndTime());
1017 m_ui
->comboBoxScheduleDays
->setCurrentIndex(static_cast<int>(pref
->getSchedulerDays()));
1019 m_ui
->checkLimituTPConnections
->setChecked(session
->isUTPRateLimited());
1020 m_ui
->checkLimitTransportOverhead
->setChecked(session
->includeOverheadInLimits());
1021 m_ui
->checkLimitLocalPeerRate
->setChecked(!session
->ignoreLimitsOnLAN());
1023 connect(m_ui
->spinUploadLimit
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1024 connect(m_ui
->spinDownloadLimit
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1026 connect(m_ui
->spinUploadLimitAlt
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1027 connect(m_ui
->spinDownloadLimitAlt
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1029 connect(m_ui
->groupBoxSchedule
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1030 connect(m_ui
->timeEditScheduleFrom
, &QDateTimeEdit::timeChanged
, this, &ThisType::enableApplyButton
);
1031 connect(m_ui
->timeEditScheduleTo
, &QDateTimeEdit::timeChanged
, this, &ThisType::enableApplyButton
);
1032 connect(m_ui
->comboBoxScheduleDays
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
1034 connect(m_ui
->checkLimituTPConnections
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1035 connect(m_ui
->checkLimitTransportOverhead
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1036 connect(m_ui
->checkLimitLocalPeerRate
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1039 void OptionsDialog::saveSpeedTabOptions() const
1041 auto *pref
= Preferences::instance();
1042 auto *session
= BitTorrent::Session::instance();
1044 session
->setGlobalUploadSpeedLimit(m_ui
->spinUploadLimit
->value() * 1024);
1045 session
->setGlobalDownloadSpeedLimit(m_ui
->spinDownloadLimit
->value() * 1024);
1047 session
->setAltGlobalUploadSpeedLimit(m_ui
->spinUploadLimitAlt
->value() * 1024);
1048 session
->setAltGlobalDownloadSpeedLimit(m_ui
->spinDownloadLimitAlt
->value() * 1024);
1050 session
->setBandwidthSchedulerEnabled(m_ui
->groupBoxSchedule
->isChecked());
1051 pref
->setSchedulerStartTime(m_ui
->timeEditScheduleFrom
->time());
1052 pref
->setSchedulerEndTime(m_ui
->timeEditScheduleTo
->time());
1053 pref
->setSchedulerDays(static_cast<Scheduler::Days
>(m_ui
->comboBoxScheduleDays
->currentIndex()));
1055 session
->setUTPRateLimited(m_ui
->checkLimituTPConnections
->isChecked());
1056 session
->setIncludeOverheadInLimits(m_ui
->checkLimitTransportOverhead
->isChecked());
1057 session
->setIgnoreLimitsOnLAN(!m_ui
->checkLimitLocalPeerRate
->isChecked());
1060 void OptionsDialog::loadBittorrentTabOptions()
1062 const auto *session
= BitTorrent::Session::instance();
1064 m_ui
->checkDHT
->setChecked(session
->isDHTEnabled());
1065 m_ui
->checkPeX
->setChecked(session
->isPeXEnabled());
1066 m_ui
->checkLSD
->setChecked(session
->isLSDEnabled());
1067 m_ui
->comboEncryption
->setCurrentIndex(session
->encryption());
1068 m_ui
->checkAnonymousMode
->setChecked(session
->isAnonymousModeEnabled());
1070 m_ui
->spinBoxMaxActiveCheckingTorrents
->setValue(session
->maxActiveCheckingTorrents());
1072 m_ui
->checkEnableQueueing
->setChecked(session
->isQueueingSystemEnabled());
1073 m_ui
->spinMaxActiveDownloads
->setValue(session
->maxActiveDownloads());
1074 m_ui
->spinMaxActiveUploads
->setValue(session
->maxActiveUploads());
1075 m_ui
->spinMaxActiveTorrents
->setValue(session
->maxActiveTorrents());
1077 m_ui
->checkIgnoreSlowTorrentsForQueueing
->setChecked(session
->ignoreSlowTorrentsForQueueing());
1078 const QString slowTorrentsExplanation
= u
"<html><body><p>"
1079 + tr("A torrent will be considered slow if its download and upload rates stay below these values for \"Torrent inactivity timer\" seconds")
1080 + u
"</p></body></html>";
1081 m_ui
->labelDownloadRateForSlowTorrents
->setToolTip(slowTorrentsExplanation
);
1082 m_ui
->labelUploadRateForSlowTorrents
->setToolTip(slowTorrentsExplanation
);
1083 m_ui
->labelSlowTorrentInactivityTimer
->setToolTip(slowTorrentsExplanation
);
1084 m_ui
->spinDownloadRateForSlowTorrents
->setValue(session
->downloadRateForSlowTorrents());
1085 m_ui
->spinUploadRateForSlowTorrents
->setValue(session
->uploadRateForSlowTorrents());
1086 m_ui
->spinSlowTorrentsInactivityTimer
->setValue(session
->slowTorrentsInactivityTimer());
1088 if (session
->globalMaxRatio() >= 0.)
1091 m_ui
->checkMaxRatio
->setChecked(true);
1092 m_ui
->spinMaxRatio
->setEnabled(true);
1093 m_ui
->comboRatioLimitAct
->setEnabled(true);
1094 m_ui
->spinMaxRatio
->setValue(session
->globalMaxRatio());
1099 m_ui
->checkMaxRatio
->setChecked(false);
1100 m_ui
->spinMaxRatio
->setEnabled(false);
1102 if (session
->globalMaxSeedingMinutes() >= 0)
1105 m_ui
->checkMaxSeedingMinutes
->setChecked(true);
1106 m_ui
->spinMaxSeedingMinutes
->setEnabled(true);
1107 m_ui
->spinMaxSeedingMinutes
->setValue(session
->globalMaxSeedingMinutes());
1112 m_ui
->checkMaxSeedingMinutes
->setChecked(false);
1113 m_ui
->spinMaxSeedingMinutes
->setEnabled(false);
1115 if (session
->globalMaxInactiveSeedingMinutes() >= 0)
1118 m_ui
->checkMaxInactiveSeedingMinutes
->setChecked(true);
1119 m_ui
->spinMaxInactiveSeedingMinutes
->setEnabled(true);
1120 m_ui
->spinMaxInactiveSeedingMinutes
->setValue(session
->globalMaxInactiveSeedingMinutes());
1125 m_ui
->checkMaxInactiveSeedingMinutes
->setChecked(false);
1126 m_ui
->spinMaxInactiveSeedingMinutes
->setEnabled(false);
1128 m_ui
->comboRatioLimitAct
->setEnabled((session
->globalMaxSeedingMinutes() >= 0) || (session
->globalMaxRatio() >= 0.) || (session
->globalMaxInactiveSeedingMinutes() >= 0));
1130 const QHash
<BitTorrent::ShareLimitAction
, int> actIndex
=
1132 {BitTorrent::ShareLimitAction::Stop
, 0},
1133 {BitTorrent::ShareLimitAction::Remove
, 1},
1134 {BitTorrent::ShareLimitAction::RemoveWithContent
, 2},
1135 {BitTorrent::ShareLimitAction::EnableSuperSeeding
, 3}
1137 m_ui
->comboRatioLimitAct
->setCurrentIndex(actIndex
.value(session
->shareLimitAction()));
1139 m_ui
->checkEnableAddTrackers
->setChecked(session
->isAddTrackersEnabled());
1140 m_ui
->textTrackers
->setPlainText(session
->additionalTrackers());
1142 connect(m_ui
->checkDHT
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1143 connect(m_ui
->checkPeX
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1144 connect(m_ui
->checkLSD
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1145 connect(m_ui
->comboEncryption
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
1146 connect(m_ui
->checkAnonymousMode
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1148 connect(m_ui
->spinBoxMaxActiveCheckingTorrents
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1150 connect(m_ui
->checkEnableQueueing
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1151 connect(m_ui
->spinMaxActiveDownloads
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1152 connect(m_ui
->spinMaxActiveUploads
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1153 connect(m_ui
->spinMaxActiveTorrents
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1154 connect(m_ui
->checkIgnoreSlowTorrentsForQueueing
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1155 connect(m_ui
->spinDownloadRateForSlowTorrents
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1156 connect(m_ui
->spinUploadRateForSlowTorrents
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1157 connect(m_ui
->spinSlowTorrentsInactivityTimer
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1159 connect(m_ui
->checkMaxRatio
, &QAbstractButton::toggled
, m_ui
->spinMaxRatio
, &QWidget::setEnabled
);
1160 connect(m_ui
->checkMaxRatio
, &QAbstractButton::toggled
, this, &ThisType::toggleComboRatioLimitAct
);
1161 connect(m_ui
->checkMaxRatio
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1162 connect(m_ui
->spinMaxRatio
, qOverload
<double>(&QDoubleSpinBox::valueChanged
),this, &ThisType::enableApplyButton
);
1163 connect(m_ui
->comboRatioLimitAct
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
1164 connect(m_ui
->checkMaxSeedingMinutes
, &QAbstractButton::toggled
, m_ui
->spinMaxSeedingMinutes
, &QWidget::setEnabled
);
1165 connect(m_ui
->checkMaxSeedingMinutes
, &QAbstractButton::toggled
, this, &ThisType::toggleComboRatioLimitAct
);
1166 connect(m_ui
->checkMaxSeedingMinutes
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1167 connect(m_ui
->spinMaxSeedingMinutes
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1168 connect(m_ui
->checkMaxInactiveSeedingMinutes
, &QAbstractButton::toggled
, m_ui
->spinMaxInactiveSeedingMinutes
, &QWidget::setEnabled
);
1169 connect(m_ui
->checkMaxInactiveSeedingMinutes
, &QAbstractButton::toggled
, this, &ThisType::toggleComboRatioLimitAct
);
1170 connect(m_ui
->checkMaxInactiveSeedingMinutes
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1171 connect(m_ui
->spinMaxInactiveSeedingMinutes
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1173 connect(m_ui
->checkEnableAddTrackers
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1174 connect(m_ui
->textTrackers
, &QPlainTextEdit::textChanged
, this, &ThisType::enableApplyButton
);
1177 void OptionsDialog::saveBittorrentTabOptions() const
1179 auto *session
= BitTorrent::Session::instance();
1181 session
->setDHTEnabled(isDHTEnabled());
1182 session
->setPeXEnabled(m_ui
->checkPeX
->isChecked());
1183 session
->setLSDEnabled(isLSDEnabled());
1184 session
->setEncryption(getEncryptionSetting());
1185 session
->setAnonymousModeEnabled(m_ui
->checkAnonymousMode
->isChecked());
1187 session
->setMaxActiveCheckingTorrents(m_ui
->spinBoxMaxActiveCheckingTorrents
->value());
1189 session
->setQueueingSystemEnabled(isQueueingSystemEnabled());
1190 session
->setMaxActiveDownloads(m_ui
->spinMaxActiveDownloads
->value());
1191 session
->setMaxActiveUploads(m_ui
->spinMaxActiveUploads
->value());
1192 session
->setMaxActiveTorrents(m_ui
->spinMaxActiveTorrents
->value());
1193 session
->setIgnoreSlowTorrentsForQueueing(m_ui
->checkIgnoreSlowTorrentsForQueueing
->isChecked());
1194 session
->setDownloadRateForSlowTorrents(m_ui
->spinDownloadRateForSlowTorrents
->value());
1195 session
->setUploadRateForSlowTorrents(m_ui
->spinUploadRateForSlowTorrents
->value());
1196 session
->setSlowTorrentsInactivityTimer(m_ui
->spinSlowTorrentsInactivityTimer
->value());
1198 session
->setGlobalMaxRatio(getMaxRatio());
1199 session
->setGlobalMaxSeedingMinutes(getMaxSeedingMinutes());
1200 session
->setGlobalMaxInactiveSeedingMinutes(getMaxInactiveSeedingMinutes());
1201 const QVector
<BitTorrent::ShareLimitAction
> actIndex
=
1203 BitTorrent::ShareLimitAction::Stop
,
1204 BitTorrent::ShareLimitAction::Remove
,
1205 BitTorrent::ShareLimitAction::RemoveWithContent
,
1206 BitTorrent::ShareLimitAction::EnableSuperSeeding
1208 session
->setShareLimitAction(actIndex
.value(m_ui
->comboRatioLimitAct
->currentIndex()));
1210 session
->setAddTrackersEnabled(m_ui
->checkEnableAddTrackers
->isChecked());
1211 session
->setAdditionalTrackers(m_ui
->textTrackers
->toPlainText());
1214 void OptionsDialog::loadRSSTabOptions()
1216 const auto *rssSession
= RSS::Session::instance();
1217 const auto *autoDownloader
= RSS::AutoDownloader::instance();
1219 m_ui
->checkRSSEnable
->setChecked(rssSession
->isProcessingEnabled());
1220 m_ui
->spinRSSRefreshInterval
->setValue(rssSession
->refreshInterval());
1221 m_ui
->spinRSSFetchDelay
->setValue(rssSession
->fetchDelay().count());
1222 m_ui
->spinRSSMaxArticlesPerFeed
->setValue(rssSession
->maxArticlesPerFeed());
1223 m_ui
->checkRSSAutoDownloaderEnable
->setChecked(autoDownloader
->isProcessingEnabled());
1224 m_ui
->textSmartEpisodeFilters
->setPlainText(autoDownloader
->smartEpisodeFilters().join(u
'\n'));
1225 m_ui
->checkSmartFilterDownloadRepacks
->setChecked(autoDownloader
->downloadRepacks());
1227 connect(m_ui
->checkRSSEnable
, &QCheckBox::toggled
, this, &OptionsDialog::enableApplyButton
);
1228 connect(m_ui
->checkRSSAutoDownloaderEnable
, &QCheckBox::toggled
, this, &OptionsDialog::enableApplyButton
);
1229 connect(m_ui
->btnEditRules
, &QPushButton::clicked
, this, [this]()
1231 auto *downloader
= new AutomatedRssDownloader(this);
1232 downloader
->setAttribute(Qt::WA_DeleteOnClose
);
1235 connect(m_ui
->textSmartEpisodeFilters
, &QPlainTextEdit::textChanged
, this, &OptionsDialog::enableApplyButton
);
1236 connect(m_ui
->checkSmartFilterDownloadRepacks
, &QCheckBox::toggled
, this, &OptionsDialog::enableApplyButton
);
1237 connect(m_ui
->spinRSSRefreshInterval
, qSpinBoxValueChanged
, this, &OptionsDialog::enableApplyButton
);
1238 connect(m_ui
->spinRSSFetchDelay
, qSpinBoxValueChanged
, this, &OptionsDialog::enableApplyButton
);
1239 connect(m_ui
->spinRSSMaxArticlesPerFeed
, qSpinBoxValueChanged
, this, &OptionsDialog::enableApplyButton
);
1242 void OptionsDialog::saveRSSTabOptions() const
1244 auto *rssSession
= RSS::Session::instance();
1245 auto *autoDownloader
= RSS::AutoDownloader::instance();
1247 rssSession
->setProcessingEnabled(m_ui
->checkRSSEnable
->isChecked());
1248 rssSession
->setRefreshInterval(m_ui
->spinRSSRefreshInterval
->value());
1249 rssSession
->setFetchDelay(std::chrono::seconds(m_ui
->spinRSSFetchDelay
->value()));
1250 rssSession
->setMaxArticlesPerFeed(m_ui
->spinRSSMaxArticlesPerFeed
->value());
1251 autoDownloader
->setProcessingEnabled(m_ui
->checkRSSAutoDownloaderEnable
->isChecked());
1252 autoDownloader
->setSmartEpisodeFilters(m_ui
->textSmartEpisodeFilters
->toPlainText().split(u
'\n', Qt::SkipEmptyParts
));
1253 autoDownloader
->setDownloadRepacks(m_ui
->checkSmartFilterDownloadRepacks
->isChecked());
1256 #ifndef DISABLE_WEBUI
1257 void OptionsDialog::loadWebUITabOptions()
1259 const auto *pref
= Preferences::instance();
1261 m_ui
->textWebUIHttpsCert
->setMode(FileSystemPathEdit::Mode::FileOpen
);
1262 m_ui
->textWebUIHttpsCert
->setFileNameFilter(tr("Certificate") + u
" (*.cer *.crt *.pem)");
1263 m_ui
->textWebUIHttpsCert
->setDialogCaption(tr("Select certificate"));
1264 m_ui
->textWebUIHttpsKey
->setMode(FileSystemPathEdit::Mode::FileOpen
);
1265 m_ui
->textWebUIHttpsKey
->setFileNameFilter(tr("Private key") + u
" (*.key *.pem)");
1266 m_ui
->textWebUIHttpsKey
->setDialogCaption(tr("Select private key"));
1267 m_ui
->textWebUIRootFolder
->setMode(FileSystemPathEdit::Mode::DirectoryOpen
);
1268 m_ui
->textWebUIRootFolder
->setDialogCaption(tr("Choose Alternative UI files location"));
1270 if (app()->webUI()->isErrored())
1271 m_ui
->labelWebUIError
->setText(tr("WebUI configuration failed. Reason: %1").arg(app()->webUI()->errorMessage()));
1273 m_ui
->labelWebUIError
->hide();
1275 m_ui
->checkWebUI
->setChecked(pref
->isWebUIEnabled());
1276 m_ui
->textWebUIAddress
->setText(pref
->getWebUIAddress());
1277 m_ui
->spinWebUIPort
->setValue(pref
->getWebUIPort());
1278 m_ui
->checkWebUIUPnP
->setChecked(pref
->useUPnPForWebUIPort());
1279 m_ui
->checkWebUIHttps
->setChecked(pref
->isWebUIHttpsEnabled());
1280 webUIHttpsCertChanged(pref
->getWebUIHttpsCertificatePath());
1281 webUIHttpsKeyChanged(pref
->getWebUIHttpsKeyPath());
1282 m_ui
->textWebUIUsername
->setText(pref
->getWebUIUsername());
1283 m_ui
->checkBypassLocalAuth
->setChecked(!pref
->isWebUILocalAuthEnabled());
1284 m_ui
->checkBypassAuthSubnetWhitelist
->setChecked(pref
->isWebUIAuthSubnetWhitelistEnabled());
1285 m_ui
->IPSubnetWhitelistButton
->setEnabled(m_ui
->checkBypassAuthSubnetWhitelist
->isChecked());
1286 m_ui
->spinBanCounter
->setValue(pref
->getWebUIMaxAuthFailCount());
1287 m_ui
->spinBanDuration
->setValue(pref
->getWebUIBanDuration().count());
1288 m_ui
->spinSessionTimeout
->setValue(pref
->getWebUISessionTimeout());
1290 m_ui
->groupAltWebUI
->setChecked(pref
->isAltWebUIEnabled());
1291 m_ui
->textWebUIRootFolder
->setSelectedPath(pref
->getWebUIRootFolder());
1293 m_ui
->checkClickjacking
->setChecked(pref
->isWebUIClickjackingProtectionEnabled());
1294 m_ui
->checkCSRFProtection
->setChecked(pref
->isWebUICSRFProtectionEnabled());
1295 m_ui
->checkSecureCookie
->setEnabled(pref
->isWebUIHttpsEnabled());
1296 m_ui
->checkSecureCookie
->setChecked(pref
->isWebUISecureCookieEnabled());
1297 m_ui
->groupHostHeaderValidation
->setChecked(pref
->isWebUIHostHeaderValidationEnabled());
1298 m_ui
->textServerDomains
->setText(pref
->getServerDomains());
1299 // Custom HTTP headers
1300 m_ui
->groupWebUIAddCustomHTTPHeaders
->setChecked(pref
->isWebUICustomHTTPHeadersEnabled());
1301 m_ui
->textWebUICustomHTTPHeaders
->setPlainText(pref
->getWebUICustomHTTPHeaders());
1303 m_ui
->groupEnableReverseProxySupport
->setChecked(pref
->isWebUIReverseProxySupportEnabled());
1304 m_ui
->textTrustedReverseProxiesList
->setText(pref
->getWebUITrustedReverseProxiesList());
1306 m_ui
->checkDynDNS
->setChecked(pref
->isDynDNSEnabled());
1307 m_ui
->comboDNSService
->setCurrentIndex(static_cast<int>(pref
->getDynDNSService()));
1308 m_ui
->domainNameTxt
->setText(pref
->getDynDomainName());
1309 m_ui
->DNSUsernameTxt
->setText(pref
->getDynDNSUsername());
1310 m_ui
->DNSPasswordTxt
->setText(pref
->getDynDNSPassword());
1312 connect(m_ui
->checkWebUI
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1313 connect(m_ui
->textWebUIAddress
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
1314 connect(m_ui
->spinWebUIPort
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1315 connect(m_ui
->checkWebUIUPnP
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1316 connect(m_ui
->checkWebUIHttps
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1317 connect(m_ui
->textWebUIHttpsCert
, &FileSystemPathLineEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
1318 connect(m_ui
->textWebUIHttpsCert
, &FileSystemPathLineEdit::selectedPathChanged
, this, &OptionsDialog::webUIHttpsCertChanged
);
1319 connect(m_ui
->textWebUIHttpsKey
, &FileSystemPathLineEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
1320 connect(m_ui
->textWebUIHttpsKey
, &FileSystemPathLineEdit::selectedPathChanged
, this, &OptionsDialog::webUIHttpsKeyChanged
);
1322 connect(m_ui
->textWebUIUsername
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
1323 connect(m_ui
->textWebUIPassword
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
1325 connect(m_ui
->checkBypassLocalAuth
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1326 connect(m_ui
->checkBypassAuthSubnetWhitelist
, &QAbstractButton::toggled
, this, &ThisType::enableApplyButton
);
1327 connect(m_ui
->checkBypassAuthSubnetWhitelist
, &QAbstractButton::toggled
, m_ui
->IPSubnetWhitelistButton
, &QWidget::setEnabled
);
1328 connect(m_ui
->spinBanCounter
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1329 connect(m_ui
->spinBanDuration
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1330 connect(m_ui
->spinSessionTimeout
, qSpinBoxValueChanged
, this, &ThisType::enableApplyButton
);
1332 connect(m_ui
->groupAltWebUI
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1333 connect(m_ui
->textWebUIRootFolder
, &FileSystemPathLineEdit::selectedPathChanged
, this, &ThisType::enableApplyButton
);
1335 connect(m_ui
->checkClickjacking
, &QCheckBox::toggled
, this, &ThisType::enableApplyButton
);
1336 connect(m_ui
->checkCSRFProtection
, &QCheckBox::toggled
, this, &ThisType::enableApplyButton
);
1337 connect(m_ui
->checkWebUIHttps
, &QGroupBox::toggled
, m_ui
->checkSecureCookie
, &QWidget::setEnabled
);
1338 connect(m_ui
->checkSecureCookie
, &QCheckBox::toggled
, this, &ThisType::enableApplyButton
);
1339 connect(m_ui
->groupHostHeaderValidation
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1340 connect(m_ui
->textServerDomains
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
1342 connect(m_ui
->groupWebUIAddCustomHTTPHeaders
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1343 connect(m_ui
->textWebUICustomHTTPHeaders
, &QPlainTextEdit::textChanged
, this, &OptionsDialog::enableApplyButton
);
1345 connect(m_ui
->groupEnableReverseProxySupport
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1346 connect(m_ui
->textTrustedReverseProxiesList
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
1348 connect(m_ui
->checkDynDNS
, &QGroupBox::toggled
, this, &ThisType::enableApplyButton
);
1349 connect(m_ui
->comboDNSService
, qComboBoxCurrentIndexChanged
, this, &ThisType::enableApplyButton
);
1350 connect(m_ui
->domainNameTxt
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
1351 connect(m_ui
->DNSUsernameTxt
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
1352 connect(m_ui
->DNSPasswordTxt
, &QLineEdit::textChanged
, this, &ThisType::enableApplyButton
);
1355 void OptionsDialog::saveWebUITabOptions() const
1357 auto *pref
= Preferences::instance();
1359 const bool webUIEnabled
= isWebUIEnabled();
1361 pref
->setWebUIEnabled(webUIEnabled
);
1362 pref
->setWebUIAddress(m_ui
->textWebUIAddress
->text());
1363 pref
->setWebUIPort(m_ui
->spinWebUIPort
->value());
1364 pref
->setUPnPForWebUIPort(m_ui
->checkWebUIUPnP
->isChecked());
1365 pref
->setWebUIHttpsEnabled(m_ui
->checkWebUIHttps
->isChecked());
1366 pref
->setWebUIHttpsCertificatePath(m_ui
->textWebUIHttpsCert
->selectedPath());
1367 pref
->setWebUIHttpsKeyPath(m_ui
->textWebUIHttpsKey
->selectedPath());
1368 pref
->setWebUIMaxAuthFailCount(m_ui
->spinBanCounter
->value());
1369 pref
->setWebUIBanDuration(std::chrono::seconds
{m_ui
->spinBanDuration
->value()});
1370 pref
->setWebUISessionTimeout(m_ui
->spinSessionTimeout
->value());
1372 if (const QString username
= webUIUsername(); isValidWebUIUsername(username
))
1373 pref
->setWebUIUsername(username
);
1374 if (const QString password
= webUIPassword(); isValidWebUIPassword(password
))
1375 pref
->setWebUIPassword(Utils::Password::PBKDF2::generate(password
));
1376 pref
->setWebUILocalAuthEnabled(!m_ui
->checkBypassLocalAuth
->isChecked());
1377 pref
->setWebUIAuthSubnetWhitelistEnabled(m_ui
->checkBypassAuthSubnetWhitelist
->isChecked());
1379 pref
->setAltWebUIEnabled(m_ui
->groupAltWebUI
->isChecked());
1380 pref
->setWebUIRootFolder(m_ui
->textWebUIRootFolder
->selectedPath());
1382 pref
->setWebUIClickjackingProtectionEnabled(m_ui
->checkClickjacking
->isChecked());
1383 pref
->setWebUICSRFProtectionEnabled(m_ui
->checkCSRFProtection
->isChecked());
1384 pref
->setWebUISecureCookieEnabled(m_ui
->checkSecureCookie
->isChecked());
1385 pref
->setWebUIHostHeaderValidationEnabled(m_ui
->groupHostHeaderValidation
->isChecked());
1386 pref
->setServerDomains(m_ui
->textServerDomains
->text());
1387 // Custom HTTP headers
1388 pref
->setWebUICustomHTTPHeadersEnabled(m_ui
->groupWebUIAddCustomHTTPHeaders
->isChecked());
1389 pref
->setWebUICustomHTTPHeaders(m_ui
->textWebUICustomHTTPHeaders
->toPlainText());
1391 pref
->setWebUIReverseProxySupportEnabled(m_ui
->groupEnableReverseProxySupport
->isChecked());
1392 pref
->setWebUITrustedReverseProxiesList(m_ui
->textTrustedReverseProxiesList
->text());
1394 pref
->setDynDNSEnabled(m_ui
->checkDynDNS
->isChecked());
1395 pref
->setDynDNSService(static_cast<DNS::Service
>(m_ui
->comboDNSService
->currentIndex()));
1396 pref
->setDynDomainName(m_ui
->domainNameTxt
->text());
1397 pref
->setDynDNSUsername(m_ui
->DNSUsernameTxt
->text());
1398 pref
->setDynDNSPassword(m_ui
->DNSPasswordTxt
->text());
1400 #endif // DISABLE_WEBUI
1402 void OptionsDialog::initializeLanguageCombo()
1404 // List language files
1405 const QStringList langFiles
= QDir(u
":/lang"_s
).entryList({u
"qbittorrent_*.qm"_s
}, QDir::Files
, QDir::Name
);
1406 for (const QString
&langFile
: langFiles
)
1408 const QString langCode
= QStringView(langFile
).sliced(12).chopped(3).toString(); // remove "qbittorrent_" and ".qm"
1409 m_ui
->comboLanguage
->addItem(Utils::Misc::languageToLocalizedString(langCode
), langCode
);
1413 void OptionsDialog::changePage(QListWidgetItem
*current
, QListWidgetItem
*previous
)
1417 m_ui
->tabOption
->setCurrentIndex(m_ui
->tabSelection
->row(current
));
1420 void OptionsDialog::loadSplitterState()
1422 // width has been modified, use height as width reference instead
1423 const int width
= m_ui
->tabSelection
->item(TAB_UI
)->sizeHint().height() * 2;
1424 const QStringList defaultSizes
= {QString::number(width
), QString::number(m_ui
->hsplitter
->width() - width
)};
1426 QList
<int> splitterSizes
;
1427 for (const QString
&string
: asConst(m_storeHSplitterSize
.get(defaultSizes
)))
1428 splitterSizes
.append(string
.toInt());
1430 m_ui
->hsplitter
->setSizes(splitterSizes
);
1433 void OptionsDialog::showEvent(QShowEvent
*e
)
1435 QDialog::showEvent(e
);
1437 loadSplitterState();
1440 void OptionsDialog::saveOptions() const
1442 auto *pref
= Preferences::instance();
1444 saveBehaviorTabOptions();
1445 saveDownloadsTabOptions();
1446 saveConnectionTabOptions();
1447 saveSpeedTabOptions();
1448 saveBittorrentTabOptions();
1449 saveRSSTabOptions();
1450 #ifndef DISABLE_WEBUI
1451 saveWebUITabOptions();
1453 m_advancedSettings
->saveAdvancedSettings();
1455 // Assume that user changed multiple settings
1456 // so it's best to save immediately
1460 bool OptionsDialog::isIPFilteringEnabled() const
1462 return m_ui
->checkIPFilter
->isChecked();
1465 Net::ProxyType
OptionsDialog::getProxyType() const
1467 return m_ui
->comboProxyType
->currentData().value
<Net::ProxyType
>();
1470 int OptionsDialog::getPort() const
1472 return m_ui
->spinPort
->value();
1475 void OptionsDialog::on_randomButton_clicked()
1477 // Range [1024: 65535]
1478 m_ui
->spinPort
->setValue(Utils::Random::rand(1024, 65535));
1481 int OptionsDialog::getEncryptionSetting() const
1483 return m_ui
->comboEncryption
->currentIndex();
1486 int OptionsDialog::getMaxActiveDownloads() const
1488 return m_ui
->spinMaxActiveDownloads
->value();
1491 int OptionsDialog::getMaxActiveUploads() const
1493 return m_ui
->spinMaxActiveUploads
->value();
1496 int OptionsDialog::getMaxActiveTorrents() const
1498 return m_ui
->spinMaxActiveTorrents
->value();
1501 bool OptionsDialog::isQueueingSystemEnabled() const
1503 return m_ui
->checkEnableQueueing
->isChecked();
1506 bool OptionsDialog::isDHTEnabled() const
1508 return m_ui
->checkDHT
->isChecked();
1511 bool OptionsDialog::isLSDEnabled() const
1513 return m_ui
->checkLSD
->isChecked();
1516 bool OptionsDialog::isUPnPEnabled() const
1518 return m_ui
->checkUPnP
->isChecked();
1521 // Return Share ratio
1522 qreal
OptionsDialog::getMaxRatio() const
1524 if (m_ui
->checkMaxRatio
->isChecked())
1525 return m_ui
->spinMaxRatio
->value();
1529 // Return Seeding Minutes
1530 int OptionsDialog::getMaxSeedingMinutes() const
1532 if (m_ui
->checkMaxSeedingMinutes
->isChecked())
1533 return m_ui
->spinMaxSeedingMinutes
->value();
1537 // Return Inactive Seeding Minutes
1538 int OptionsDialog::getMaxInactiveSeedingMinutes() const
1540 return m_ui
->checkMaxInactiveSeedingMinutes
->isChecked()
1541 ? m_ui
->spinMaxInactiveSeedingMinutes
->value()
1545 // Return max connections number
1546 int OptionsDialog::getMaxConnections() const
1548 if (!m_ui
->checkMaxConnections
->isChecked())
1551 return m_ui
->spinMaxConnec
->value();
1554 int OptionsDialog::getMaxConnectionsPerTorrent() const
1556 if (!m_ui
->checkMaxConnectionsPerTorrent
->isChecked())
1559 return m_ui
->spinMaxConnecPerTorrent
->value();
1562 int OptionsDialog::getMaxUploads() const
1564 if (!m_ui
->checkMaxUploads
->isChecked())
1567 return m_ui
->spinMaxUploads
->value();
1570 int OptionsDialog::getMaxUploadsPerTorrent() const
1572 if (!m_ui
->checkMaxUploadsPerTorrent
->isChecked())
1575 return m_ui
->spinMaxUploadsPerTorrent
->value();
1578 void OptionsDialog::on_buttonBox_accepted()
1580 if (m_applyButton
->isEnabled())
1582 if (!applySettings())
1585 m_applyButton
->setEnabled(false);
1591 bool OptionsDialog::applySettings()
1593 if (!schedTimesOk())
1595 m_ui
->tabSelection
->setCurrentRow(TAB_SPEED
);
1598 #ifndef DISABLE_WEBUI
1599 if (isWebUIEnabled() && !webUIAuthenticationOk())
1601 m_ui
->tabSelection
->setCurrentRow(TAB_WEBUI
);
1604 if (!isAlternativeWebUIPathValid())
1606 m_ui
->tabSelection
->setCurrentRow(TAB_WEBUI
);
1615 void OptionsDialog::on_buttonBox_rejected()
1620 bool OptionsDialog::useAdditionDialog() const
1622 return m_ui
->checkAdditionDialog
->isChecked();
1625 void OptionsDialog::enableApplyButton()
1627 m_applyButton
->setEnabled(true);
1630 void OptionsDialog::toggleComboRatioLimitAct()
1632 // Verify if the share action button must be enabled
1633 m_ui
->comboRatioLimitAct
->setEnabled(m_ui
->checkMaxRatio
->isChecked() || m_ui
->checkMaxSeedingMinutes
->isChecked() || m_ui
->checkMaxInactiveSeedingMinutes
->isChecked());
1636 void OptionsDialog::adjustProxyOptions()
1638 const auto currentProxyType
= m_ui
->comboProxyType
->currentData().value
<Net::ProxyType
>();
1639 const bool isAuthSupported
= ((currentProxyType
== Net::ProxyType::SOCKS5
)
1640 || (currentProxyType
== Net::ProxyType::HTTP
));
1642 m_ui
->checkProxyAuth
->setEnabled(isAuthSupported
);
1644 if (currentProxyType
== Net::ProxyType::None
)
1646 m_ui
->labelProxyTypeIncompatible
->setVisible(false);
1648 m_ui
->lblProxyIP
->setEnabled(false);
1649 m_ui
->textProxyIP
->setEnabled(false);
1650 m_ui
->lblProxyPort
->setEnabled(false);
1651 m_ui
->spinProxyPort
->setEnabled(false);
1653 m_ui
->checkProxyHostnameLookup
->setEnabled(false);
1654 m_ui
->checkProxyRSS
->setEnabled(false);
1655 m_ui
->checkProxyMisc
->setEnabled(false);
1656 m_ui
->checkProxyBitTorrent
->setEnabled(false);
1657 m_ui
->checkProxyPeerConnections
->setEnabled(false);
1661 m_ui
->lblProxyIP
->setEnabled(true);
1662 m_ui
->textProxyIP
->setEnabled(true);
1663 m_ui
->lblProxyPort
->setEnabled(true);
1664 m_ui
->spinProxyPort
->setEnabled(true);
1666 m_ui
->checkProxyBitTorrent
->setEnabled(true);
1667 m_ui
->checkProxyPeerConnections
->setEnabled(true);
1669 if (currentProxyType
== Net::ProxyType::SOCKS4
)
1671 m_ui
->labelProxyTypeIncompatible
->setVisible(true);
1673 m_ui
->checkProxyHostnameLookup
->setEnabled(false);
1674 m_ui
->checkProxyRSS
->setEnabled(false);
1675 m_ui
->checkProxyMisc
->setEnabled(false);
1680 m_ui
->labelProxyTypeIncompatible
->setVisible(false);
1682 m_ui
->checkProxyHostnameLookup
->setEnabled(true);
1683 m_ui
->checkProxyRSS
->setEnabled(true);
1684 m_ui
->checkProxyMisc
->setEnabled(true);
1689 bool OptionsDialog::isSplashScreenDisabled() const
1691 return !m_ui
->checkShowSplash
->isChecked();
1694 void OptionsDialog::initializeStyleCombo()
1697 m_ui
->labelStyleHint
->setText(tr("%1 is recommended for best compatibility with Windows dark mode"
1698 , "Fusion is recommended for best compatibility with Windows dark mode").arg(u
"Fusion"_s
));
1699 m_ui
->comboStyle
->addItem(tr("System", "System default Qt style"), u
"system"_s
);
1700 m_ui
->comboStyle
->setItemData(0, tr("Let Qt decide the style for this system"), Qt::ToolTipRole
);
1701 m_ui
->comboStyle
->insertSeparator(1);
1703 QStringList styleNames
= QStyleFactory::keys();
1704 std::sort(styleNames
.begin(), styleNames
.end(), Utils::Compare::NaturalLessThan
<Qt::CaseInsensitive
>());
1705 m_ui
->comboStyle
->addItems(styleNames
);
1707 const QString prefStyleName
= Preferences::instance()->getStyle();
1708 const QString selectedStyleName
= prefStyleName
.isEmpty() ? QApplication::style()->name() : prefStyleName
;
1709 m_ui
->comboStyle
->setCurrentIndex(m_ui
->comboStyle
->findText(selectedStyleName
, Qt::MatchFixedString
));
1711 m_ui
->labelStyle
->hide();
1712 m_ui
->comboStyle
->hide();
1713 m_ui
->labelStyleHint
->hide();
1714 m_ui
->UISettingsBoxLayout
->removeWidget(m_ui
->labelStyle
);
1715 m_ui
->UISettingsBoxLayout
->removeWidget(m_ui
->comboStyle
);
1716 m_ui
->UISettingsBoxLayout
->removeWidget(m_ui
->labelStyleHint
);
1721 bool OptionsDialog::WinStartup() const
1723 return m_ui
->checkStartup
->isChecked();
1727 bool OptionsDialog::preAllocateAllFiles() const
1729 return m_ui
->checkPreallocateAll
->isChecked();
1732 bool OptionsDialog::addTorrentsStopped() const
1734 return m_ui
->checkAddStopped
->isChecked();
1738 bool OptionsDialog::isProxyEnabled() const
1740 return m_ui
->comboProxyType
->currentIndex();
1743 QString
OptionsDialog::getProxyIp() const
1745 return m_ui
->textProxyIP
->text().trimmed();
1748 unsigned short OptionsDialog::getProxyPort() const
1750 return m_ui
->spinProxyPort
->value();
1753 QString
OptionsDialog::getProxyUsername() const
1755 QString username
= m_ui
->textProxyUsername
->text().trimmed();
1759 QString
OptionsDialog::getProxyPassword() const
1761 QString password
= m_ui
->textProxyPassword
->text();
1762 password
= password
.trimmed();
1767 QString
OptionsDialog::getLocale() const
1769 return m_ui
->comboLanguage
->itemData(m_ui
->comboLanguage
->currentIndex(), Qt::UserRole
).toString();
1772 void OptionsDialog::setLocale(const QString
&localeStr
)
1775 if (localeStr
.startsWith(u
"eo", Qt::CaseInsensitive
))
1779 else if (localeStr
.startsWith(u
"ltg", Qt::CaseInsensitive
))
1785 QLocale
locale(localeStr
);
1786 if (locale
.language() == QLocale::Uzbek
)
1787 name
= u
"uz@Latn"_s
;
1788 else if (locale
.language() == QLocale::Azerbaijani
)
1789 name
= u
"az@latin"_s
;
1791 name
= locale
.name();
1793 // Attempt to find exact match
1794 int index
= m_ui
->comboLanguage
->findData(name
, Qt::UserRole
);
1797 //Attempt to find a language match without a country
1798 int pos
= name
.indexOf(u
'_');
1801 QString lang
= name
.left(pos
);
1802 index
= m_ui
->comboLanguage
->findData(lang
, Qt::UserRole
);
1807 // Unrecognized, use US English
1808 index
= m_ui
->comboLanguage
->findData(u
"en"_s
, Qt::UserRole
);
1809 Q_ASSERT(index
>= 0);
1811 m_ui
->comboLanguage
->setCurrentIndex(index
);
1814 Path
OptionsDialog::getTorrentExportDir() const
1816 if (m_ui
->checkExportDir
->isChecked())
1817 return m_ui
->textExportDir
->selectedPath();
1821 Path
OptionsDialog::getFinishedTorrentExportDir() const
1823 if (m_ui
->checkExportDirFin
->isChecked())
1824 return m_ui
->textExportDirFin
->selectedPath();
1828 void OptionsDialog::on_addWatchedFolderButton_clicked()
1830 Preferences
*const pref
= Preferences::instance();
1831 const Path dir
{QFileDialog::getExistingDirectory(
1832 this, tr("Select folder to monitor"), pref
->getScanDirsLastPath().parentPath().toString())};
1836 auto *dialog
= new WatchedFolderOptionsDialog({}, this);
1837 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
1838 connect(dialog
, &QDialog::accepted
, this, [this, dialog
, dir
, pref
]()
1842 auto *watchedFoldersModel
= static_cast<WatchedFoldersModel
*>(m_ui
->scanFoldersView
->model());
1843 watchedFoldersModel
->addFolder(dir
, dialog
->watchedFolderOptions());
1845 pref
->setScanDirsLastPath(dir
);
1847 for (int i
= 0; i
< watchedFoldersModel
->columnCount(); ++i
)
1848 m_ui
->scanFoldersView
->resizeColumnToContents(i
);
1850 enableApplyButton();
1852 catch (const RuntimeError
&err
)
1854 QMessageBox::critical(this, tr("Adding entry failed"), err
.message());
1861 void OptionsDialog::on_editWatchedFolderButton_clicked()
1863 const QModelIndex selected
1864 = m_ui
->scanFoldersView
->selectionModel()->selectedIndexes().at(0);
1866 editWatchedFolderOptions(selected
);
1869 void OptionsDialog::on_removeWatchedFolderButton_clicked()
1871 const QModelIndexList selected
1872 = m_ui
->scanFoldersView
->selectionModel()->selectedIndexes();
1874 for (const QModelIndex
&index
: selected
)
1875 m_ui
->scanFoldersView
->model()->removeRow(index
.row());
1878 void OptionsDialog::handleWatchedFolderViewSelectionChanged()
1880 const QModelIndexList selectedIndexes
= m_ui
->scanFoldersView
->selectionModel()->selectedIndexes();
1881 m_ui
->removeWatchedFolderButton
->setEnabled(!selectedIndexes
.isEmpty());
1882 m_ui
->editWatchedFolderButton
->setEnabled(selectedIndexes
.count() == 1);
1885 void OptionsDialog::editWatchedFolderOptions(const QModelIndex
&index
)
1887 if (!index
.isValid())
1890 auto *watchedFoldersModel
= static_cast<WatchedFoldersModel
*>(m_ui
->scanFoldersView
->model());
1891 auto *dialog
= new WatchedFolderOptionsDialog(watchedFoldersModel
->folderOptions(index
.row()), this);
1892 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
1893 connect(dialog
, &QDialog::accepted
, this, [this, dialog
, index
, watchedFoldersModel
]()
1895 if (index
.isValid())
1897 // The index could be invalidated while the dialog was displayed,
1898 // for example, if you deleted the folder using the Web API.
1899 watchedFoldersModel
->setFolderOptions(index
.row(), dialog
->watchedFolderOptions());
1900 enableApplyButton();
1907 // Return Filter object to apply to BT session
1908 Path
OptionsDialog::getFilter() const
1910 return m_ui
->textFilterPath
->selectedPath();
1913 #ifndef DISABLE_WEBUI
1914 void OptionsDialog::webUIHttpsCertChanged(const Path
&path
)
1916 const auto readResult
= Utils::IO::readFile(path
, Utils::Net::MAX_SSL_FILE_SIZE
);
1917 const bool isCertValid
= Utils::Net::isSSLCertificatesValid(readResult
.value_or(QByteArray()));
1919 m_ui
->textWebUIHttpsCert
->setSelectedPath(path
);
1920 m_ui
->lblSslCertStatus
->setPixmap(UIThemeManager::instance()->getScaledPixmap(
1921 (isCertValid
? u
"security-high"_s
: u
"security-low"_s
), 24));
1924 void OptionsDialog::webUIHttpsKeyChanged(const Path
&path
)
1926 const auto readResult
= Utils::IO::readFile(path
, Utils::Net::MAX_SSL_FILE_SIZE
);
1927 const bool isKeyValid
= !Utils::SSLKey::load(readResult
.value_or(QByteArray())).isNull();
1929 m_ui
->textWebUIHttpsKey
->setSelectedPath(path
);
1930 m_ui
->lblSslKeyStatus
->setPixmap(UIThemeManager::instance()->getScaledPixmap(
1931 (isKeyValid
? u
"security-high"_s
: u
"security-low"_s
), 24));
1934 bool OptionsDialog::isWebUIEnabled() const
1936 return m_ui
->checkWebUI
->isChecked();
1939 QString
OptionsDialog::webUIUsername() const
1941 return m_ui
->textWebUIUsername
->text();
1944 QString
OptionsDialog::webUIPassword() const
1946 return m_ui
->textWebUIPassword
->text();
1949 bool OptionsDialog::webUIAuthenticationOk()
1951 if (!isValidWebUIUsername(webUIUsername()))
1953 QMessageBox::warning(this, tr("Length Error"), tr("The WebUI username must be at least 3 characters long."));
1957 const bool dontChangePassword
= webUIPassword().isEmpty() && !Preferences::instance()->getWebUIPassword().isEmpty();
1958 if (!isValidWebUIPassword(webUIPassword()) && !dontChangePassword
)
1960 QMessageBox::warning(this, tr("Length Error"), tr("The WebUI password must be at least 6 characters long."));
1966 bool OptionsDialog::isAlternativeWebUIPathValid()
1968 if (m_ui
->groupAltWebUI
->isChecked() && m_ui
->textWebUIRootFolder
->selectedPath().isEmpty())
1970 QMessageBox::warning(this, tr("Location Error"), tr("The alternative WebUI files location cannot be blank."));
1977 void OptionsDialog::showConnectionTab()
1979 m_ui
->tabSelection
->setCurrentRow(TAB_CONNECTION
);
1982 #ifndef DISABLE_WEBUI
1983 void OptionsDialog::on_registerDNSBtn_clicked()
1985 const auto service
= static_cast<DNS::Service
>(m_ui
->comboDNSService
->currentIndex());
1986 QDesktopServices::openUrl(Net::DNSUpdater::getRegistrationUrl(service
));
1990 void OptionsDialog::on_IpFilterRefreshBtn_clicked()
1992 if (m_refreshingIpFilter
) return;
1993 m_refreshingIpFilter
= true;
1994 // Updating program preferences
1995 BitTorrent::Session
*const session
= BitTorrent::Session::instance();
1996 session
->setIPFilteringEnabled(true);
1997 session
->setIPFilterFile({}); // forcing Session reload filter file
1998 session
->setIPFilterFile(getFilter());
1999 connect(session
, &BitTorrent::Session::IPFilterParsed
, this, &OptionsDialog::handleIPFilterParsed
);
2000 setCursor(QCursor(Qt::WaitCursor
));
2003 void OptionsDialog::handleIPFilterParsed(bool error
, int ruleCount
)
2005 setCursor(QCursor(Qt::ArrowCursor
));
2007 QMessageBox::warning(this, tr("Parsing error"), tr("Failed to parse the provided IP filter"));
2009 QMessageBox::information(this, tr("Successfully refreshed"), tr("Successfully parsed the provided IP filter: %1 rules were applied.", "%1 is a number").arg(ruleCount
));
2010 m_refreshingIpFilter
= false;
2011 disconnect(BitTorrent::Session::instance(), &BitTorrent::Session::IPFilterParsed
, this, &OptionsDialog::handleIPFilterParsed
);
2014 bool OptionsDialog::schedTimesOk()
2016 if (m_ui
->timeEditScheduleFrom
->time() == m_ui
->timeEditScheduleTo
->time())
2018 QMessageBox::warning(this, tr("Time Error"), tr("The start time and the end time can't be the same."));
2024 void OptionsDialog::on_banListButton_clicked()
2026 auto *dialog
= new BanListOptionsDialog(this);
2027 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
2028 connect(dialog
, &QDialog::accepted
, this, &OptionsDialog::enableApplyButton
);
2032 void OptionsDialog::on_IPSubnetWhitelistButton_clicked()
2034 auto *dialog
= new IPSubnetWhitelistOptionsDialog(this);
2035 dialog
->setAttribute(Qt::WA_DeleteOnClose
);
2036 connect(dialog
, &QDialog::accepted
, this, &OptionsDialog::enableApplyButton
);