Don't overwrite stored layout of main window with incorrect one
[qBittorrent.git] / src / gui / optionsdialog.cpp
blobdd3520a5680e11657055270889aefaa0ee64b9cc
1 /*
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"
33 #include <chrono>
34 #include <cstdlib>
35 #include <limits>
37 #include <QApplication>
38 #include <QDebug>
39 #include <QDesktopServices>
40 #include <QDialogButtonBox>
41 #include <QEvent>
42 #include <QFileDialog>
43 #include <QMessageBox>
44 #include <QSystemTrayIcon>
45 #include <QTranslator>
47 #include "base/bittorrent/session.h"
48 #include "base/bittorrent/sharelimitaction.h"
49 #include "base/exceptions.h"
50 #include "base/global.h"
51 #include "base/net/portforwarder.h"
52 #include "base/net/proxyconfigurationmanager.h"
53 #include "base/path.h"
54 #include "base/preferences.h"
55 #include "base/rss/rss_autodownloader.h"
56 #include "base/rss/rss_session.h"
57 #include "base/torrentfileguard.h"
58 #include "base/torrentfileswatcher.h"
59 #include "base/utils/io.h"
60 #include "base/utils/misc.h"
61 #include "base/utils/net.h"
62 #include "base/utils/os.h"
63 #include "base/utils/password.h"
64 #include "base/utils/random.h"
65 #include "base/utils/sslkey.h"
66 #include "addnewtorrentdialog.h"
67 #include "advancedsettings.h"
68 #include "banlistoptionsdialog.h"
69 #include "interfaces/iguiapplication.h"
70 #include "ipsubnetwhitelistoptionsdialog.h"
71 #include "rss/automatedrssdownloader.h"
72 #include "ui_optionsdialog.h"
73 #include "uithemedialog.h"
74 #include "uithememanager.h"
75 #include "utils.h"
76 #include "watchedfolderoptionsdialog.h"
77 #include "watchedfoldersmodel.h"
78 #include "webui/webui.h"
80 #ifndef DISABLE_WEBUI
81 #include "base/net/dnsupdater.h"
82 #endif
84 #if defined Q_OS_MACOS || defined Q_OS_WIN
85 #include "base/utils/os.h"
86 #endif // defined Q_OS_MACOS || defined Q_OS_WIN
88 #define SETTINGS_KEY(name) u"OptionsDialog/" name
90 const int WEBUI_MIN_USERNAME_LENGTH = 3;
91 const int WEBUI_MIN_PASSWORD_LENGTH = 6;
93 namespace
95 QStringList translatedWeekdayNames()
97 // return translated strings from Monday to Sunday in user selected locale
99 const QLocale locale {Preferences::instance()->getLocale()};
100 const QDate date {2018, 11, 5}; // Monday
101 QStringList ret;
102 for (int i = 0; i < 7; ++i)
103 ret.append(locale.toString(date.addDays(i), u"dddd"_s));
104 return ret;
107 class WheelEventEater final : public QObject
109 public:
110 using QObject::QObject;
112 private:
113 bool eventFilter(QObject *, QEvent *event) override
115 return (event->type() == QEvent::Wheel);
119 bool isValidWebUIUsername(const QString &username)
121 return (username.length() >= WEBUI_MIN_USERNAME_LENGTH);
124 bool isValidWebUIPassword(const QString &password)
126 return (password.length() >= WEBUI_MIN_PASSWORD_LENGTH);
129 // Shortcuts for frequently used signals that have more than one overload. They would require
130 // type casts and that is why we declare required member pointer here instead.
131 void (QComboBox::*qComboBoxCurrentIndexChanged)(int) = &QComboBox::currentIndexChanged;
132 void (QSpinBox::*qSpinBoxValueChanged)(int) = &QSpinBox::valueChanged;
135 // Constructor
136 OptionsDialog::OptionsDialog(IGUIApplication *app, QWidget *parent)
137 : GUIApplicationComponent(app, parent)
138 , m_ui {new Ui::OptionsDialog}
139 , m_storeDialogSize {SETTINGS_KEY(u"Size"_s)}
140 , m_storeHSplitterSize {SETTINGS_KEY(u"HorizontalSplitterSizes"_s)}
141 , m_storeLastViewedPage {SETTINGS_KEY(u"LastViewedPage"_s)}
143 m_ui->setupUi(this);
144 m_applyButton = m_ui->buttonBox->button(QDialogButtonBox::Apply);
146 #ifdef Q_OS_UNIX
147 setWindowTitle(tr("Preferences"));
148 #endif
150 m_ui->hsplitter->setCollapsible(0, false);
151 m_ui->hsplitter->setCollapsible(1, false);
153 // Main icons
154 m_ui->tabSelection->item(TAB_UI)->setIcon(UIThemeManager::instance()->getIcon(u"preferences-desktop"_s));
155 m_ui->tabSelection->item(TAB_BITTORRENT)->setIcon(UIThemeManager::instance()->getIcon(u"preferences-bittorrent"_s, u"preferences-system-network"_s));
156 m_ui->tabSelection->item(TAB_CONNECTION)->setIcon(UIThemeManager::instance()->getIcon(u"network-connect"_s, u"network-wired"_s));
157 m_ui->tabSelection->item(TAB_DOWNLOADS)->setIcon(UIThemeManager::instance()->getIcon(u"download"_s, u"folder-download"_s));
158 m_ui->tabSelection->item(TAB_SPEED)->setIcon(UIThemeManager::instance()->getIcon(u"speedometer"_s, u"chronometer"_s));
159 m_ui->tabSelection->item(TAB_RSS)->setIcon(UIThemeManager::instance()->getIcon(u"application-rss"_s, u"application-rss+xml"_s));
160 #ifdef DISABLE_WEBUI
161 m_ui->tabSelection->item(TAB_WEBUI)->setHidden(true);
162 #else
163 m_ui->tabSelection->item(TAB_WEBUI)->setIcon(UIThemeManager::instance()->getIcon(u"preferences-webui"_s, u"network-server"_s));
164 #endif
165 m_ui->tabSelection->item(TAB_ADVANCED)->setIcon(UIThemeManager::instance()->getIcon(u"preferences-advanced"_s, u"preferences-other"_s));
167 // set uniform size for all icons
168 int maxHeight = -1;
169 for (int i = 0; i < m_ui->tabSelection->count(); ++i)
170 maxHeight = std::max(maxHeight, m_ui->tabSelection->visualItemRect(m_ui->tabSelection->item(i)).size().height());
171 for (int i = 0; i < m_ui->tabSelection->count(); ++i)
173 const QSize size(std::numeric_limits<int>::max(), static_cast<int>(maxHeight * 1.2));
174 m_ui->tabSelection->item(i)->setSizeHint(size);
177 connect(m_ui->tabSelection, &QListWidget::currentItemChanged, this, &ThisType::changePage);
179 // Load options
180 loadBehaviorTabOptions();
181 loadDownloadsTabOptions();
182 loadConnectionTabOptions();
183 loadSpeedTabOptions();
184 loadBittorrentTabOptions();
185 loadRSSTabOptions();
186 #ifndef DISABLE_WEBUI
187 loadWebUITabOptions();
188 #endif
190 // Load Advanced settings
191 m_advancedSettings = new AdvancedSettings(app, m_ui->tabAdvancedPage);
192 m_ui->advPageLayout->addWidget(m_advancedSettings);
193 connect(m_advancedSettings, &AdvancedSettings::settingsChanged, this, &ThisType::enableApplyButton);
195 // setup apply button
196 m_applyButton->setEnabled(false);
197 connect(m_applyButton, &QPushButton::clicked, this, [this]
199 if (applySettings())
200 m_applyButton->setEnabled(false);
203 // disable mouse wheel event on widgets to avoid misselection
204 auto *wheelEventEater = new WheelEventEater(this);
205 for (QComboBox *widget : asConst(findChildren<QComboBox *>()))
206 widget->installEventFilter(wheelEventEater);
207 for (QSpinBox *widget : asConst(findChildren<QSpinBox *>()))
208 widget->installEventFilter(wheelEventEater);
210 m_ui->tabSelection->setCurrentRow(m_storeLastViewedPage);
212 if (const QSize dialogSize = m_storeDialogSize; dialogSize.isValid())
213 resize(dialogSize);
216 OptionsDialog::~OptionsDialog()
218 // save dialog states
219 m_storeDialogSize = size();
221 QStringList hSplitterSizes;
222 for (const int size : asConst(m_ui->hsplitter->sizes()))
223 hSplitterSizes.append(QString::number(size));
224 m_storeHSplitterSize = hSplitterSizes;
226 m_storeLastViewedPage = m_ui->tabSelection->currentRow();
228 delete m_ui;
231 void OptionsDialog::loadBehaviorTabOptions()
233 const auto *pref = Preferences::instance();
234 const auto *session = BitTorrent::Session::instance();
236 initializeLanguageCombo();
237 setLocale(pref->getLocale());
239 m_ui->checkUseCustomTheme->setChecked(Preferences::instance()->useCustomUITheme());
240 m_ui->customThemeFilePath->setSelectedPath(Preferences::instance()->customUIThemePath());
241 m_ui->customThemeFilePath->setMode(FileSystemPathEdit::Mode::FileOpen);
242 m_ui->customThemeFilePath->setDialogCaption(tr("Select qBittorrent UI Theme file"));
243 m_ui->customThemeFilePath->setFileNameFilter(tr("qBittorrent UI Theme file (*.qbtheme config.json)"));
244 #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
245 m_ui->checkUseSystemIcon->setChecked(pref->useSystemIcons());
246 #else
247 m_ui->checkUseSystemIcon->setVisible(false);
248 #endif
250 m_ui->confirmDeletion->setChecked(pref->confirmTorrentDeletion());
251 m_ui->checkAltRowColors->setChecked(pref->useAlternatingRowColors());
252 m_ui->checkHideZero->setChecked(pref->getHideZeroValues());
253 m_ui->comboHideZero->setCurrentIndex(pref->getHideZeroComboValues());
254 m_ui->comboHideZero->setEnabled(m_ui->checkHideZero->isChecked());
256 m_ui->actionTorrentDlOnDblClBox->setItemData(0, TOGGLE_STOP);
257 m_ui->actionTorrentDlOnDblClBox->setItemData(1, OPEN_DEST);
258 m_ui->actionTorrentDlOnDblClBox->setItemData(2, PREVIEW_FILE);
259 m_ui->actionTorrentDlOnDblClBox->setItemData(3, SHOW_OPTIONS);
260 m_ui->actionTorrentDlOnDblClBox->setItemData(4, NO_ACTION);
261 int actionDownloading = pref->getActionOnDblClOnTorrentDl();
262 if ((actionDownloading < 0) || (actionDownloading >= m_ui->actionTorrentDlOnDblClBox->count()))
263 actionDownloading = TOGGLE_STOP;
264 m_ui->actionTorrentDlOnDblClBox->setCurrentIndex(m_ui->actionTorrentDlOnDblClBox->findData(actionDownloading));
266 m_ui->actionTorrentFnOnDblClBox->setItemData(0, TOGGLE_STOP);
267 m_ui->actionTorrentFnOnDblClBox->setItemData(1, OPEN_DEST);
268 m_ui->actionTorrentFnOnDblClBox->setItemData(2, PREVIEW_FILE);
269 m_ui->actionTorrentFnOnDblClBox->setItemData(3, SHOW_OPTIONS);
270 m_ui->actionTorrentFnOnDblClBox->setItemData(4, NO_ACTION);
271 int actionSeeding = pref->getActionOnDblClOnTorrentFn();
272 if ((actionSeeding < 0) || (actionSeeding >= m_ui->actionTorrentFnOnDblClBox->count()))
273 actionSeeding = OPEN_DEST;
274 m_ui->actionTorrentFnOnDblClBox->setCurrentIndex(m_ui->actionTorrentFnOnDblClBox->findData(actionSeeding));
276 m_ui->checkBoxHideZeroStatusFilters->setChecked(pref->getHideZeroStatusFilters());
278 #ifndef Q_OS_WIN
279 m_ui->checkStartup->setVisible(false);
280 #endif
281 m_ui->checkShowSplash->setChecked(!pref->isSplashScreenDisabled());
282 m_ui->checkProgramExitConfirm->setChecked(pref->confirmOnExit());
283 m_ui->checkProgramAutoExitConfirm->setChecked(!pref->dontConfirmAutoExit());
284 m_ui->checkConfirmStopAndStartAll->setChecked(pref->confirmPauseAndResumeAll());
286 m_ui->windowStateComboBox->addItem(tr("Normal"), QVariant::fromValue(WindowState::Normal));
287 m_ui->windowStateComboBox->addItem(tr("Minimized"), QVariant::fromValue(WindowState::Minimized));
288 #ifndef Q_OS_MACOS
289 m_ui->windowStateComboBox->addItem(tr("Hidden"), QVariant::fromValue(WindowState::Hidden));
290 #endif
291 m_ui->windowStateComboBox->setCurrentIndex(m_ui->windowStateComboBox->findData(QVariant::fromValue(app()->startUpWindowState())));
293 #if !(defined(Q_OS_WIN) || defined(Q_OS_MACOS))
294 m_ui->groupFileAssociation->setVisible(false);
295 m_ui->checkProgramUpdates->setVisible(false);
296 #endif
298 #ifndef Q_OS_MACOS
299 // Disable systray integration if it is not supported by the system
300 if (!QSystemTrayIcon::isSystemTrayAvailable())
302 m_ui->checkShowSystray->setChecked(false);
303 m_ui->checkShowSystray->setEnabled(false);
304 m_ui->checkShowSystray->setToolTip(tr("Disabled due to failed to detect system tray presence"));
306 m_ui->checkShowSystray->setChecked(pref->systemTrayEnabled());
307 m_ui->checkMinimizeToSysTray->setChecked(pref->minimizeToTray());
308 m_ui->checkCloseToSystray->setChecked(pref->closeToTray());
309 m_ui->comboTrayIcon->setCurrentIndex(static_cast<int>(pref->trayIconStyle()));
310 #endif
312 #ifdef Q_OS_WIN
313 m_ui->checkStartup->setChecked(pref->WinStartup());
314 #endif
316 #ifdef Q_OS_MACOS
317 m_ui->checkShowSystray->setVisible(false);
318 m_ui->checkAssociateTorrents->setChecked(Utils::OS::isTorrentFileAssocSet());
319 m_ui->checkAssociateTorrents->setEnabled(!m_ui->checkAssociateTorrents->isChecked());
320 m_ui->checkAssociateMagnetLinks->setChecked(Utils::OS::isMagnetLinkAssocSet());
321 m_ui->checkAssociateMagnetLinks->setEnabled(!m_ui->checkAssociateMagnetLinks->isChecked());
322 #endif
324 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
325 m_ui->checkProgramUpdates->setChecked(pref->isUpdateCheckEnabled());
326 #endif
328 m_ui->checkPreventFromSuspendWhenDownloading->setChecked(pref->preventFromSuspendWhenDownloading());
329 m_ui->checkPreventFromSuspendWhenSeeding->setChecked(pref->preventFromSuspendWhenSeeding());
331 m_ui->textFileLogPath->setDialogCaption(tr("Choose a save directory"));
332 m_ui->textFileLogPath->setMode(FileSystemPathEdit::Mode::DirectorySave);
333 m_ui->textFileLogPath->setSelectedPath(app()->fileLoggerPath());
334 const bool fileLogBackup = app()->isFileLoggerBackup();
335 m_ui->checkFileLogBackup->setChecked(fileLogBackup);
336 m_ui->spinFileLogSize->setEnabled(fileLogBackup);
337 const bool fileLogDelete = app()->isFileLoggerDeleteOld();
338 m_ui->checkFileLogDelete->setChecked(fileLogDelete);
339 m_ui->spinFileLogAge->setEnabled(fileLogDelete);
340 m_ui->comboFileLogAgeType->setEnabled(fileLogDelete);
341 m_ui->spinFileLogSize->setValue(app()->fileLoggerMaxSize() / 1024);
342 m_ui->spinFileLogAge->setValue(app()->fileLoggerAge());
343 m_ui->comboFileLogAgeType->setCurrentIndex(app()->fileLoggerAgeType());
344 // Groupbox's check state must be initialized after some of its children if they are manually enabled/disabled
345 m_ui->checkFileLog->setChecked(app()->isFileLoggerEnabled());
347 m_ui->checkBoxPerformanceWarning->setChecked(session->isPerformanceWarningEnabled());
349 connect(m_ui->comboI18n, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
351 #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
352 connect(m_ui->checkUseSystemIcon, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
353 #endif
354 connect(m_ui->checkUseCustomTheme, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
355 connect(m_ui->customThemeFilePath, &FileSystemPathEdit::selectedPathChanged, this, &ThisType::enableApplyButton);
357 m_ui->buttonCustomizeUITheme->setEnabled(!m_ui->checkUseCustomTheme->isChecked());
358 connect(m_ui->checkUseCustomTheme, &QGroupBox::toggled, this, [this]
360 m_ui->buttonCustomizeUITheme->setEnabled(!m_ui->checkUseCustomTheme->isChecked());
362 connect(m_ui->buttonCustomizeUITheme, &QPushButton::clicked, this, [this]
364 auto *dialog = new UIThemeDialog(this);
365 dialog->setAttribute(Qt::WA_DeleteOnClose);
366 dialog->open();
369 connect(m_ui->confirmDeletion, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
370 connect(m_ui->checkAltRowColors, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
371 connect(m_ui->checkHideZero, &QAbstractButton::toggled, m_ui->comboHideZero, &QWidget::setEnabled);
372 connect(m_ui->checkHideZero, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
373 connect(m_ui->comboHideZero, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
374 connect(m_ui->actionTorrentDlOnDblClBox, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
375 connect(m_ui->actionTorrentFnOnDblClBox, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
376 connect(m_ui->checkBoxHideZeroStatusFilters, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
378 #ifdef Q_OS_WIN
379 connect(m_ui->checkStartup, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
380 #endif
381 connect(m_ui->checkShowSplash, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
382 connect(m_ui->checkProgramExitConfirm, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
383 connect(m_ui->checkProgramAutoExitConfirm, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
384 connect(m_ui->checkConfirmStopAndStartAll, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
385 connect(m_ui->checkShowSystray, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
386 connect(m_ui->checkMinimizeToSysTray, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
387 connect(m_ui->checkCloseToSystray, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
388 connect(m_ui->comboTrayIcon, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
389 connect(m_ui->windowStateComboBox, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
391 connect(m_ui->checkPreventFromSuspendWhenDownloading, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
392 connect(m_ui->checkPreventFromSuspendWhenSeeding, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
394 #if defined(Q_OS_MACOS)
395 connect(m_ui->checkAssociateTorrents, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
396 connect(m_ui->checkAssociateMagnetLinks, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
397 #endif
399 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
400 connect(m_ui->checkProgramUpdates, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
401 #endif
403 #ifdef Q_OS_WIN
404 m_ui->assocPanel->hide();
405 #endif
407 #ifdef Q_OS_MAC
408 m_ui->defaultProgramPanel->hide();
409 #endif
411 #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && !defined(QBT_USES_DBUS)
412 m_ui->checkPreventFromSuspendWhenDownloading->setDisabled(true);
413 m_ui->checkPreventFromSuspendWhenSeeding->setDisabled(true);
414 #endif
416 connect(m_ui->checkFileLog, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
417 connect(m_ui->textFileLogPath, &FileSystemPathEdit::selectedPathChanged, this, &ThisType::enableApplyButton);
418 connect(m_ui->checkFileLogBackup, &QAbstractButton::toggled, m_ui->spinFileLogSize, &QWidget::setEnabled);
419 connect(m_ui->checkFileLogBackup, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
420 connect(m_ui->checkFileLogDelete, &QAbstractButton::toggled, m_ui->comboFileLogAgeType, &QWidget::setEnabled);
421 connect(m_ui->checkFileLogDelete, &QAbstractButton::toggled, m_ui->spinFileLogAge, &QWidget::setEnabled);
422 connect(m_ui->checkFileLogDelete, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
423 connect(m_ui->spinFileLogSize, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
424 connect(m_ui->spinFileLogAge, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
425 connect(m_ui->comboFileLogAgeType, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
427 connect(m_ui->checkBoxPerformanceWarning, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
430 void OptionsDialog::saveBehaviorTabOptions() const
432 auto *pref = Preferences::instance();
433 auto *session = BitTorrent::Session::instance();
435 // Load the translation
436 const QString locale = getLocale();
437 if (pref->getLocale() != locale)
439 auto *translator = new QTranslator;
440 if (translator->load(u":/lang/qbittorrent_"_s + locale))
441 qDebug("%s locale recognized, using translation.", qUtf8Printable(locale));
442 else
443 qDebug("%s locale unrecognized, using default (en).", qUtf8Printable(locale));
444 qApp->installTranslator(translator);
446 pref->setLocale(locale);
448 #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
449 pref->useSystemIcons(m_ui->checkUseSystemIcon->isChecked());
450 #endif
451 pref->setUseCustomUITheme(m_ui->checkUseCustomTheme->isChecked());
452 pref->setCustomUIThemePath(m_ui->customThemeFilePath->selectedPath());
454 pref->setConfirmTorrentDeletion(m_ui->confirmDeletion->isChecked());
455 pref->setAlternatingRowColors(m_ui->checkAltRowColors->isChecked());
456 pref->setHideZeroValues(m_ui->checkHideZero->isChecked());
457 pref->setHideZeroComboValues(m_ui->comboHideZero->currentIndex());
459 pref->setActionOnDblClOnTorrentDl(m_ui->actionTorrentDlOnDblClBox->currentData().toInt());
460 pref->setActionOnDblClOnTorrentFn(m_ui->actionTorrentFnOnDblClBox->currentData().toInt());
462 pref->setHideZeroStatusFilters(m_ui->checkBoxHideZeroStatusFilters->isChecked());
464 pref->setSplashScreenDisabled(isSplashScreenDisabled());
465 pref->setConfirmOnExit(m_ui->checkProgramExitConfirm->isChecked());
466 pref->setDontConfirmAutoExit(!m_ui->checkProgramAutoExitConfirm->isChecked());
467 pref->setConfirmPauseAndResumeAll(m_ui->checkConfirmStopAndStartAll->isChecked());
469 #ifdef Q_OS_WIN
470 pref->setWinStartup(WinStartup());
471 #endif
473 #ifndef Q_OS_MACOS
474 pref->setSystemTrayEnabled(m_ui->checkShowSystray->isChecked());
475 pref->setTrayIconStyle(TrayIcon::Style(m_ui->comboTrayIcon->currentIndex()));
476 pref->setCloseToTray(m_ui->checkCloseToSystray->isChecked());
477 pref->setMinimizeToTray(m_ui->checkMinimizeToSysTray->isChecked());
478 #endif
480 #ifdef Q_OS_MACOS
481 if (m_ui->checkAssociateTorrents->isChecked())
483 Utils::OS::setTorrentFileAssoc();
484 m_ui->checkAssociateTorrents->setChecked(Utils::OS::isTorrentFileAssocSet());
485 m_ui->checkAssociateTorrents->setEnabled(!m_ui->checkAssociateTorrents->isChecked());
487 if (m_ui->checkAssociateMagnetLinks->isChecked())
489 Utils::OS::setMagnetLinkAssoc();
490 m_ui->checkAssociateMagnetLinks->setChecked(Utils::OS::isMagnetLinkAssocSet());
491 m_ui->checkAssociateMagnetLinks->setEnabled(!m_ui->checkAssociateMagnetLinks->isChecked());
493 #endif
495 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
496 pref->setUpdateCheckEnabled(m_ui->checkProgramUpdates->isChecked());
497 #endif
499 pref->setPreventFromSuspendWhenDownloading(m_ui->checkPreventFromSuspendWhenDownloading->isChecked());
500 pref->setPreventFromSuspendWhenSeeding(m_ui->checkPreventFromSuspendWhenSeeding->isChecked());
502 app()->setFileLoggerPath(m_ui->textFileLogPath->selectedPath());
503 app()->setFileLoggerBackup(m_ui->checkFileLogBackup->isChecked());
504 app()->setFileLoggerMaxSize(m_ui->spinFileLogSize->value() * 1024);
505 app()->setFileLoggerAge(m_ui->spinFileLogAge->value());
506 app()->setFileLoggerAgeType(m_ui->comboFileLogAgeType->currentIndex());
507 app()->setFileLoggerDeleteOld(m_ui->checkFileLogDelete->isChecked());
508 app()->setFileLoggerEnabled(m_ui->checkFileLog->isChecked());
510 app()->setStartUpWindowState(m_ui->windowStateComboBox->currentData().value<WindowState>());
512 session->setPerformanceWarningEnabled(m_ui->checkBoxPerformanceWarning->isChecked());
515 void OptionsDialog::loadDownloadsTabOptions()
517 const auto *pref = Preferences::instance();
518 const auto *session = BitTorrent::Session::instance();
520 m_ui->checkAdditionDialog->setChecked(pref->isAddNewTorrentDialogEnabled());
521 m_ui->checkAdditionDialogFront->setChecked(pref->isAddNewTorrentDialogTopLevel());
523 m_ui->contentLayoutComboBox->setCurrentIndex(static_cast<int>(session->torrentContentLayout()));
524 m_ui->checkAddToQueueTop->setChecked(session->isAddTorrentToQueueTop());
525 m_ui->checkAddStopped->setChecked(session->isAddTorrentStopped());
527 m_ui->stopConditionComboBox->setToolTip(
528 u"<html><body><p><b>" + tr("None") + u"</b> - " + tr("No stop condition is set.") + u"</p><p><b>" +
529 tr("Metadata received") + u"</b> - " + tr("Torrent will stop after metadata is received.") +
530 u" <em>" + tr("Torrents that have metadata initially will be added as stopped.") + u"</em></p><p><b>" +
531 tr("Files checked") + u"</b> - " + tr("Torrent will stop after files are initially checked.") +
532 u" <em>" + tr("This will also download metadata if it wasn't there initially.") + u"</em></p></body></html>");
533 m_ui->stopConditionComboBox->setItemData(0, QVariant::fromValue(BitTorrent::Torrent::StopCondition::None));
534 m_ui->stopConditionComboBox->setItemData(1, QVariant::fromValue(BitTorrent::Torrent::StopCondition::MetadataReceived));
535 m_ui->stopConditionComboBox->setItemData(2, QVariant::fromValue(BitTorrent::Torrent::StopCondition::FilesChecked));
536 m_ui->stopConditionComboBox->setCurrentIndex(m_ui->stopConditionComboBox->findData(QVariant::fromValue(session->torrentStopCondition())));
537 m_ui->stopConditionLabel->setEnabled(!m_ui->checkAddStopped->isChecked());
538 m_ui->stopConditionComboBox->setEnabled(!m_ui->checkAddStopped->isChecked());
540 m_ui->checkMergeTrackers->setChecked(session->isMergeTrackersEnabled());
541 m_ui->checkConfirmMergeTrackers->setEnabled(m_ui->checkAdditionDialog->isChecked());
542 m_ui->checkConfirmMergeTrackers->setChecked(m_ui->checkConfirmMergeTrackers->isEnabled() ? pref->confirmMergeTrackers() : false);
543 connect(m_ui->checkAdditionDialog, &QGroupBox::toggled, this, [this, pref]
545 m_ui->checkConfirmMergeTrackers->setEnabled(m_ui->checkAdditionDialog->isChecked());
546 m_ui->checkConfirmMergeTrackers->setChecked(m_ui->checkConfirmMergeTrackers->isEnabled() ? pref->confirmMergeTrackers() : false);
549 const TorrentFileGuard::AutoDeleteMode autoDeleteMode = TorrentFileGuard::autoDeleteMode();
550 m_ui->deleteTorrentBox->setChecked(autoDeleteMode != TorrentFileGuard::Never);
551 m_ui->deleteCancelledTorrentBox->setChecked(autoDeleteMode == TorrentFileGuard::Always);
552 m_ui->deleteTorrentWarningIcon->setPixmap(QApplication::style()->standardIcon(QStyle::SP_MessageBoxCritical).pixmap(16, 16));
553 m_ui->deleteTorrentWarningIcon->hide();
554 m_ui->deleteTorrentWarningLabel->hide();
555 m_ui->deleteTorrentWarningLabel->setToolTip(u"<html><body><p>" +
556 tr("By enabling these options, you can <strong>irrevocably lose</strong> your .torrent files!") +
557 u"</p><p>" +
558 tr("When these options are enabled, qBittorrent will <strong>delete</strong> .torrent files "
559 "after they were successfully (the first option) or not (the second option) added to its "
560 "download queue. This will be applied <strong>not only</strong> to the files opened via "
561 "&ldquo;Add torrent&rdquo; menu action but to those opened via <strong>file type association</strong> as well") +
562 u"</p><p>" +
563 tr("If you enable the second option (&ldquo;Also when addition is cancelled&rdquo;) the "
564 ".torrent file <strong>will be deleted</strong> even if you press &ldquo;<strong>Cancel</strong>&rdquo; in "
565 "the &ldquo;Add torrent&rdquo; dialog") +
566 u"</p></body></html>");
568 m_ui->checkPreallocateAll->setChecked(session->isPreallocationEnabled());
569 m_ui->checkAppendqB->setChecked(session->isAppendExtensionEnabled());
570 m_ui->checkUnwantedFolder->setChecked(session->isUnwantedFolderEnabled());
571 m_ui->checkRecursiveDownload->setChecked(pref->isRecursiveDownloadEnabled());
573 m_ui->comboSavingMode->setCurrentIndex(!session->isAutoTMMDisabledByDefault());
574 m_ui->comboTorrentCategoryChanged->setCurrentIndex(session->isDisableAutoTMMWhenCategoryChanged());
575 m_ui->comboCategoryChanged->setCurrentIndex(session->isDisableAutoTMMWhenCategorySavePathChanged());
576 m_ui->comboCategoryDefaultPathChanged->setCurrentIndex(session->isDisableAutoTMMWhenDefaultSavePathChanged());
578 m_ui->checkUseSubcategories->setChecked(session->isSubcategoriesEnabled());
579 m_ui->checkUseCategoryPaths->setChecked(session->useCategoryPathsInManualMode());
581 m_ui->textSavePath->setDialogCaption(tr("Choose a save directory"));
582 m_ui->textSavePath->setMode(FileSystemPathEdit::Mode::DirectorySave);
583 m_ui->textSavePath->setSelectedPath(session->savePath());
585 m_ui->checkUseDownloadPath->setChecked(session->isDownloadPathEnabled());
586 m_ui->textDownloadPath->setDialogCaption(tr("Choose a save directory"));
587 m_ui->textDownloadPath->setEnabled(m_ui->checkUseDownloadPath->isChecked());
588 m_ui->textDownloadPath->setMode(FileSystemPathEdit::Mode::DirectorySave);
589 m_ui->textDownloadPath->setSelectedPath(session->downloadPath());
591 const bool isExportDirEmpty = session->torrentExportDirectory().isEmpty();
592 m_ui->checkExportDir->setChecked(!isExportDirEmpty);
593 m_ui->textExportDir->setDialogCaption(tr("Choose export directory"));
594 m_ui->textExportDir->setEnabled(m_ui->checkExportDir->isChecked());
595 m_ui->textExportDir->setMode(FileSystemPathEdit::Mode::DirectorySave);
596 if (!isExportDirEmpty)
597 m_ui->textExportDir->setSelectedPath(session->torrentExportDirectory());
599 const bool isExportDirFinEmpty = session->finishedTorrentExportDirectory().isEmpty();
600 m_ui->checkExportDirFin->setChecked(!isExportDirFinEmpty);
601 m_ui->textExportDirFin->setDialogCaption(tr("Choose export directory"));
602 m_ui->textExportDirFin->setEnabled(m_ui->checkExportDirFin->isChecked());
603 m_ui->textExportDirFin->setMode(FileSystemPathEdit::Mode::DirectorySave);
604 if (!isExportDirFinEmpty)
605 m_ui->textExportDirFin->setSelectedPath(session->finishedTorrentExportDirectory());
607 auto *watchedFoldersModel = new WatchedFoldersModel(TorrentFilesWatcher::instance(), this);
608 connect(watchedFoldersModel, &QAbstractListModel::dataChanged, this, &ThisType::enableApplyButton);
609 m_ui->scanFoldersView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
610 m_ui->scanFoldersView->setModel(watchedFoldersModel);
611 connect(m_ui->scanFoldersView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &ThisType::handleWatchedFolderViewSelectionChanged);
612 connect(m_ui->scanFoldersView, &QTreeView::doubleClicked, this, &ThisType::editWatchedFolderOptions);
614 m_ui->groupExcludedFileNames->setChecked(session->isExcludedFileNamesEnabled());
615 m_ui->textExcludedFileNames->setPlainText(session->excludedFileNames().join(u'\n'));
617 m_ui->groupMailNotification->setChecked(pref->isMailNotificationEnabled());
618 m_ui->senderEmailTxt->setText(pref->getMailNotificationSender());
619 m_ui->lineEditDestEmail->setText(pref->getMailNotificationEmail());
620 m_ui->lineEditSmtpServer->setText(pref->getMailNotificationSMTP());
621 m_ui->checkSmtpSSL->setChecked(pref->getMailNotificationSMTPSSL());
622 m_ui->groupMailNotifAuth->setChecked(pref->getMailNotificationSMTPAuth());
623 m_ui->mailNotifUsername->setText(pref->getMailNotificationSMTPUsername());
624 m_ui->mailNotifPassword->setText(pref->getMailNotificationSMTPPassword());
626 m_ui->groupBoxRunOnAdded->setChecked(pref->isAutoRunOnTorrentAddedEnabled());
627 m_ui->groupBoxRunOnFinished->setChecked(pref->isAutoRunOnTorrentFinishedEnabled());
628 m_ui->lineEditRunOnAdded->setText(pref->getAutoRunOnTorrentAddedProgram());
629 m_ui->lineEditRunOnFinished->setText(pref->getAutoRunOnTorrentFinishedProgram());
630 #if defined(Q_OS_WIN)
631 m_ui->autoRunConsole->setChecked(pref->isAutoRunConsoleEnabled());
632 #else
633 m_ui->autoRunConsole->hide();
634 #endif
635 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
636 .arg(tr("Supported parameters (case sensitive):")
637 , tr("%N: Torrent name")
638 , tr("%L: Category")
639 , tr("%G: Tags (separated by comma)")
640 , tr("%F: Content path (same as root path for multifile torrent)")
641 , tr("%R: Root path (first torrent subdirectory path)")
642 , tr("%D: Save path")
643 , tr("%C: Number of files")
644 , tr("%Z: Torrent size (bytes)"))
645 .arg(tr("%T: Current tracker")
646 , tr("%I: Info hash v1 (or '-' if unavailable)")
647 , tr("%J: Info hash v2 (or '-' if unavailable)")
648 , tr("%K: Torrent ID (either sha-1 info hash for v1 torrent or truncated sha-256 info hash for v2/hybrid torrent)")
649 , tr("Tip: Encapsulate parameter with quotation marks to avoid text being cut off at whitespace (e.g., \"%N\")"));
650 m_ui->labelAutoRunParam->setText(autoRunStr);
652 connect(m_ui->checkAdditionDialog, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
653 connect(m_ui->checkAdditionDialogFront, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
655 connect(m_ui->contentLayoutComboBox, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
657 connect(m_ui->checkAddToQueueTop, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
658 connect(m_ui->checkAddStopped, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
659 connect(m_ui->checkAddStopped, &QAbstractButton::toggled, this, [this](const bool checked)
661 m_ui->stopConditionLabel->setEnabled(!checked);
662 m_ui->stopConditionComboBox->setEnabled(!checked);
664 connect(m_ui->stopConditionComboBox, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
665 connect(m_ui->checkMergeTrackers, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
666 connect(m_ui->checkConfirmMergeTrackers, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
667 connect(m_ui->deleteTorrentBox, &QGroupBox::toggled, m_ui->deleteTorrentWarningIcon, &QWidget::setVisible);
668 connect(m_ui->deleteTorrentBox, &QGroupBox::toggled, m_ui->deleteTorrentWarningLabel, &QWidget::setVisible);
669 connect(m_ui->deleteTorrentBox, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
670 connect(m_ui->deleteCancelledTorrentBox, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
672 connect(m_ui->checkPreallocateAll, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
673 connect(m_ui->checkAppendqB, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
674 connect(m_ui->checkUnwantedFolder, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
675 connect(m_ui->checkRecursiveDownload, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
677 connect(m_ui->comboSavingMode, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
678 connect(m_ui->comboTorrentCategoryChanged, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
679 connect(m_ui->comboCategoryChanged, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
680 connect(m_ui->comboCategoryDefaultPathChanged, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
682 connect(m_ui->checkUseSubcategories, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
683 connect(m_ui->checkUseCategoryPaths, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
685 connect(m_ui->textSavePath, &FileSystemPathEdit::selectedPathChanged, this, &ThisType::enableApplyButton);
686 connect(m_ui->textDownloadPath, &FileSystemPathEdit::selectedPathChanged, this, &ThisType::enableApplyButton);
688 connect(m_ui->checkExportDir, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
689 connect(m_ui->checkExportDir, &QAbstractButton::toggled, m_ui->textExportDir, &QWidget::setEnabled);
690 connect(m_ui->checkExportDirFin, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
691 connect(m_ui->checkExportDirFin, &QAbstractButton::toggled, m_ui->textExportDirFin, &QWidget::setEnabled);
692 connect(m_ui->textExportDir, &FileSystemPathEdit::selectedPathChanged, this, &ThisType::enableApplyButton);
693 connect(m_ui->textExportDirFin, &FileSystemPathEdit::selectedPathChanged, this, &ThisType::enableApplyButton);
694 connect(m_ui->checkUseDownloadPath, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
695 connect(m_ui->checkUseDownloadPath, &QAbstractButton::toggled, m_ui->textDownloadPath, &QWidget::setEnabled);
697 connect(m_ui->addWatchedFolderButton, &QAbstractButton::clicked, this, &ThisType::enableApplyButton);
699 connect(m_ui->groupExcludedFileNames, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
700 connect(m_ui->textExcludedFileNames, &QPlainTextEdit::textChanged, this, &ThisType::enableApplyButton);
701 connect(m_ui->removeWatchedFolderButton, &QAbstractButton::clicked, this, &ThisType::enableApplyButton);
703 connect(m_ui->groupMailNotification, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
704 connect(m_ui->senderEmailTxt, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
705 connect(m_ui->lineEditDestEmail, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
706 connect(m_ui->lineEditSmtpServer, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
707 connect(m_ui->checkSmtpSSL, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
708 connect(m_ui->groupMailNotifAuth, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
709 connect(m_ui->mailNotifUsername, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
710 connect(m_ui->mailNotifPassword, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
711 connect(m_ui->sendTestEmail, &QPushButton::clicked, this, [this]
713 app()->sendTestEmail();
714 QMessageBox::information(this, tr("Test email"), tr("Attempted to send email. Check your inbox to confirm success"));
717 connect(m_ui->groupBoxRunOnAdded, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
718 connect(m_ui->lineEditRunOnAdded, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
719 connect(m_ui->groupBoxRunOnFinished, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
720 connect(m_ui->lineEditRunOnFinished, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
721 connect(m_ui->autoRunConsole, &QCheckBox::toggled, this, &ThisType::enableApplyButton);
724 void OptionsDialog::saveDownloadsTabOptions() const
726 auto *pref = Preferences::instance();
727 auto *session = BitTorrent::Session::instance();
729 pref->setAddNewTorrentDialogEnabled(useAdditionDialog());
730 pref->setAddNewTorrentDialogTopLevel(m_ui->checkAdditionDialogFront->isChecked());
732 session->setTorrentContentLayout(static_cast<BitTorrent::TorrentContentLayout>(m_ui->contentLayoutComboBox->currentIndex()));
734 session->setAddTorrentToQueueTop(m_ui->checkAddToQueueTop->isChecked());
735 session->setAddTorrentStopped(addTorrentsStopped());
736 session->setTorrentStopCondition(m_ui->stopConditionComboBox->currentData().value<BitTorrent::Torrent::StopCondition>());
737 TorrentFileGuard::setAutoDeleteMode(!m_ui->deleteTorrentBox->isChecked() ? TorrentFileGuard::Never
738 : !m_ui->deleteCancelledTorrentBox->isChecked() ? TorrentFileGuard::IfAdded
739 : TorrentFileGuard::Always);
740 session->setMergeTrackersEnabled(m_ui->checkMergeTrackers->isChecked());
741 if (m_ui->checkConfirmMergeTrackers->isEnabled())
742 pref->setConfirmMergeTrackers(m_ui->checkConfirmMergeTrackers->isChecked());
744 session->setPreallocationEnabled(preAllocateAllFiles());
745 session->setAppendExtensionEnabled(m_ui->checkAppendqB->isChecked());
746 session->setUnwantedFolderEnabled(m_ui->checkUnwantedFolder->isChecked());
747 pref->setRecursiveDownloadEnabled(m_ui->checkRecursiveDownload->isChecked());
749 session->setAutoTMMDisabledByDefault(m_ui->comboSavingMode->currentIndex() == 0);
750 session->setDisableAutoTMMWhenCategoryChanged(m_ui->comboTorrentCategoryChanged->currentIndex() == 1);
751 session->setDisableAutoTMMWhenCategorySavePathChanged(m_ui->comboCategoryChanged->currentIndex() == 1);
752 session->setDisableAutoTMMWhenDefaultSavePathChanged(m_ui->comboCategoryDefaultPathChanged->currentIndex() == 1);
754 session->setSubcategoriesEnabled(m_ui->checkUseSubcategories->isChecked());
755 session->setUseCategoryPathsInManualMode(m_ui->checkUseCategoryPaths->isChecked());
757 session->setSavePath(Path(m_ui->textSavePath->selectedPath()));
758 session->setDownloadPathEnabled(m_ui->checkUseDownloadPath->isChecked());
759 session->setDownloadPath(m_ui->textDownloadPath->selectedPath());
760 session->setTorrentExportDirectory(getTorrentExportDir());
761 session->setFinishedTorrentExportDirectory(getFinishedTorrentExportDir());
763 auto *watchedFoldersModel = static_cast<WatchedFoldersModel *>(m_ui->scanFoldersView->model());
764 watchedFoldersModel->apply();
766 session->setExcludedFileNamesEnabled(m_ui->groupExcludedFileNames->isChecked());
767 session->setExcludedFileNames(m_ui->textExcludedFileNames->toPlainText().split(u'\n', Qt::SkipEmptyParts));
769 pref->setMailNotificationEnabled(m_ui->groupMailNotification->isChecked());
770 pref->setMailNotificationSender(m_ui->senderEmailTxt->text());
771 pref->setMailNotificationEmail(m_ui->lineEditDestEmail->text());
772 pref->setMailNotificationSMTP(m_ui->lineEditSmtpServer->text());
773 pref->setMailNotificationSMTPSSL(m_ui->checkSmtpSSL->isChecked());
774 pref->setMailNotificationSMTPAuth(m_ui->groupMailNotifAuth->isChecked());
775 pref->setMailNotificationSMTPUsername(m_ui->mailNotifUsername->text());
776 pref->setMailNotificationSMTPPassword(m_ui->mailNotifPassword->text());
778 pref->setAutoRunOnTorrentAddedEnabled(m_ui->groupBoxRunOnAdded->isChecked());
779 pref->setAutoRunOnTorrentAddedProgram(m_ui->lineEditRunOnAdded->text().trimmed());
780 pref->setAutoRunOnTorrentFinishedEnabled(m_ui->groupBoxRunOnFinished->isChecked());
781 pref->setAutoRunOnTorrentFinishedProgram(m_ui->lineEditRunOnFinished->text().trimmed());
782 #if defined(Q_OS_WIN)
783 pref->setAutoRunConsoleEnabled(m_ui->autoRunConsole->isChecked());
784 #endif
787 void OptionsDialog::loadConnectionTabOptions()
789 const auto *session = BitTorrent::Session::instance();
791 m_ui->comboProtocol->setCurrentIndex(static_cast<int>(session->btProtocol()));
792 m_ui->spinPort->setValue(session->port());
793 m_ui->checkUPnP->setChecked(Net::PortForwarder::instance()->isEnabled());
795 int intValue = session->maxConnections();
796 if (intValue > 0)
798 // enable
799 m_ui->checkMaxConnections->setChecked(true);
800 m_ui->spinMaxConnec->setEnabled(true);
801 m_ui->spinMaxConnec->setValue(intValue);
803 else
805 // disable
806 m_ui->checkMaxConnections->setChecked(false);
807 m_ui->spinMaxConnec->setEnabled(false);
809 intValue = session->maxConnectionsPerTorrent();
810 if (intValue > 0)
812 // enable
813 m_ui->checkMaxConnectionsPerTorrent->setChecked(true);
814 m_ui->spinMaxConnecPerTorrent->setEnabled(true);
815 m_ui->spinMaxConnecPerTorrent->setValue(intValue);
817 else
819 // disable
820 m_ui->checkMaxConnectionsPerTorrent->setChecked(false);
821 m_ui->spinMaxConnecPerTorrent->setEnabled(false);
823 intValue = session->maxUploads();
824 if (intValue > 0)
826 // enable
827 m_ui->checkMaxUploads->setChecked(true);
828 m_ui->spinMaxUploads->setEnabled(true);
829 m_ui->spinMaxUploads->setValue(intValue);
831 else
833 // disable
834 m_ui->checkMaxUploads->setChecked(false);
835 m_ui->spinMaxUploads->setEnabled(false);
837 intValue = session->maxUploadsPerTorrent();
838 if (intValue > 0)
840 // enable
841 m_ui->checkMaxUploadsPerTorrent->setChecked(true);
842 m_ui->spinMaxUploadsPerTorrent->setEnabled(true);
843 m_ui->spinMaxUploadsPerTorrent->setValue(intValue);
845 else
847 // disable
848 m_ui->checkMaxUploadsPerTorrent->setChecked(false);
849 m_ui->spinMaxUploadsPerTorrent->setEnabled(false);
852 #if defined(QBT_USES_LIBTORRENT2) && TORRENT_USE_I2P
853 m_ui->textI2PHost->setText(session->I2PAddress());
854 m_ui->spinI2PPort->setValue(session->I2PPort());
855 m_ui->checkI2PMixed->setChecked(session->I2PMixedMode());
856 m_ui->groupI2P->setChecked(session->isI2PEnabled());
857 #else
858 m_ui->groupI2P->hide();
859 #endif
861 const auto *proxyConfigManager = Net::ProxyConfigurationManager::instance();
862 const Net::ProxyConfiguration proxyConf = proxyConfigManager->proxyConfiguration();
864 m_ui->comboProxyType->addItem(tr("(None)"), QVariant::fromValue(Net::ProxyType::None));
865 m_ui->comboProxyType->addItem(tr("SOCKS4"), QVariant::fromValue(Net::ProxyType::SOCKS4));
866 m_ui->comboProxyType->addItem(tr("SOCKS5"), QVariant::fromValue(Net::ProxyType::SOCKS5));
867 m_ui->comboProxyType->addItem(tr("HTTP"), QVariant::fromValue(Net::ProxyType::HTTP));
868 m_ui->comboProxyType->setCurrentIndex(m_ui->comboProxyType->findData(QVariant::fromValue(proxyConf.type)));
869 adjustProxyOptions();
871 m_ui->textProxyIP->setText(proxyConf.ip);
872 m_ui->spinProxyPort->setValue(proxyConf.port);
873 m_ui->textProxyUsername->setText(proxyConf.username);
874 m_ui->textProxyPassword->setText(proxyConf.password);
875 m_ui->checkProxyAuth->setChecked(proxyConf.authEnabled);
876 m_ui->checkProxyHostnameLookup->setChecked(proxyConf.hostnameLookupEnabled);
878 m_ui->checkProxyPeerConnections->setChecked(session->isProxyPeerConnectionsEnabled());
879 m_ui->checkProxyBitTorrent->setChecked(Preferences::instance()->useProxyForBT());
880 m_ui->checkProxyRSS->setChecked(Preferences::instance()->useProxyForRSS());
881 m_ui->checkProxyMisc->setChecked(Preferences::instance()->useProxyForGeneralPurposes());
883 m_ui->checkIPFilter->setChecked(session->isIPFilteringEnabled());
884 m_ui->textFilterPath->setDialogCaption(tr("Choose an IP filter file"));
885 m_ui->textFilterPath->setEnabled(m_ui->checkIPFilter->isChecked());
886 m_ui->textFilterPath->setFileNameFilter(tr("All supported filters") + u" (*.dat *.p2p *.p2b);;.dat (*.dat);;.p2p (*.p2p);;.p2b (*.p2b)");
887 m_ui->textFilterPath->setSelectedPath(session->IPFilterFile());
889 m_ui->IpFilterRefreshBtn->setIcon(UIThemeManager::instance()->getIcon(u"view-refresh"_s));
890 m_ui->IpFilterRefreshBtn->setEnabled(m_ui->checkIPFilter->isChecked());
891 m_ui->checkIpFilterTrackers->setChecked(session->isTrackerFilteringEnabled());
893 connect(m_ui->comboProtocol, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
894 connect(m_ui->spinPort, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
895 connect(m_ui->checkUPnP, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
897 connect(m_ui->checkMaxConnections, &QAbstractButton::toggled, m_ui->spinMaxConnec, &QWidget::setEnabled);
898 connect(m_ui->checkMaxConnections, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
899 connect(m_ui->checkMaxConnectionsPerTorrent, &QAbstractButton::toggled, m_ui->spinMaxConnecPerTorrent, &QWidget::setEnabled);
900 connect(m_ui->checkMaxConnectionsPerTorrent, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
901 connect(m_ui->checkMaxUploads, &QAbstractButton::toggled, m_ui->spinMaxUploads, &QWidget::setEnabled);
902 connect(m_ui->checkMaxUploads, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
903 connect(m_ui->checkMaxUploadsPerTorrent, &QAbstractButton::toggled, m_ui->spinMaxUploadsPerTorrent, &QWidget::setEnabled);
904 connect(m_ui->checkMaxUploadsPerTorrent, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
905 connect(m_ui->spinMaxConnec, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
906 connect(m_ui->spinMaxConnecPerTorrent, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
907 connect(m_ui->spinMaxUploads, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
908 connect(m_ui->spinMaxUploadsPerTorrent, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
910 connect(m_ui->comboProxyType, qComboBoxCurrentIndexChanged, this, &ThisType::adjustProxyOptions);
911 connect(m_ui->comboProxyType, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
912 connect(m_ui->textProxyIP, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
913 connect(m_ui->spinProxyPort, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
915 #if defined(QBT_USES_LIBTORRENT2) && TORRENT_USE_I2P
916 connect(m_ui->textI2PHost, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
917 connect(m_ui->spinI2PPort, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
918 connect(m_ui->checkI2PMixed, &QCheckBox::toggled, this, &ThisType::enableApplyButton);
919 connect(m_ui->groupI2P, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
920 #endif
922 connect(m_ui->checkProxyBitTorrent, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
923 connect(m_ui->checkProxyBitTorrent, &QGroupBox::toggled, this, &ThisType::adjustProxyOptions);
924 connect(m_ui->checkProxyPeerConnections, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
925 connect(m_ui->checkProxyHostnameLookup, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
926 connect(m_ui->checkProxyRSS, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
927 connect(m_ui->checkProxyMisc, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
929 connect(m_ui->checkProxyAuth, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
930 connect(m_ui->textProxyUsername, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
931 connect(m_ui->textProxyPassword, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
933 connect(m_ui->checkIPFilter, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
934 connect(m_ui->checkIPFilter, &QAbstractButton::toggled, m_ui->textFilterPath, &QWidget::setEnabled);
935 connect(m_ui->checkIPFilter, &QAbstractButton::toggled, m_ui->IpFilterRefreshBtn, &QWidget::setEnabled);
936 connect(m_ui->textFilterPath, &FileSystemPathEdit::selectedPathChanged, this, &ThisType::enableApplyButton);
937 connect(m_ui->checkIpFilterTrackers, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
940 void OptionsDialog::saveConnectionTabOptions() const
942 auto *session = BitTorrent::Session::instance();
944 session->setBTProtocol(static_cast<BitTorrent::BTProtocol>(m_ui->comboProtocol->currentIndex()));
945 session->setPort(getPort());
946 Net::PortForwarder::instance()->setEnabled(isUPnPEnabled());
948 session->setMaxConnections(getMaxConnections());
949 session->setMaxConnectionsPerTorrent(getMaxConnectionsPerTorrent());
950 session->setMaxUploads(getMaxUploads());
951 session->setMaxUploadsPerTorrent(getMaxUploadsPerTorrent());
953 #if defined(QBT_USES_LIBTORRENT2) && TORRENT_USE_I2P
954 session->setI2PEnabled(m_ui->groupI2P->isChecked());
955 session->setI2PAddress(m_ui->textI2PHost->text().trimmed());
956 session->setI2PPort(m_ui->spinI2PPort->value());
957 session->setI2PMixedMode(m_ui->checkI2PMixed->isChecked());
958 #endif
960 auto *proxyConfigManager = Net::ProxyConfigurationManager::instance();
961 Net::ProxyConfiguration proxyConf;
962 proxyConf.type = getProxyType();
963 proxyConf.ip = getProxyIp();
964 proxyConf.port = getProxyPort();
965 proxyConf.authEnabled = m_ui->checkProxyAuth->isChecked();
966 proxyConf.username = getProxyUsername();
967 proxyConf.password = getProxyPassword();
968 proxyConf.hostnameLookupEnabled = m_ui->checkProxyHostnameLookup->isChecked();
969 proxyConfigManager->setProxyConfiguration(proxyConf);
971 Preferences::instance()->setUseProxyForBT(m_ui->checkProxyBitTorrent->isChecked());
972 Preferences::instance()->setUseProxyForRSS(m_ui->checkProxyRSS->isChecked());
973 Preferences::instance()->setUseProxyForGeneralPurposes(m_ui->checkProxyMisc->isChecked());
975 session->setProxyPeerConnectionsEnabled(m_ui->checkProxyPeerConnections->isChecked());
977 // IPFilter
978 session->setIPFilteringEnabled(isIPFilteringEnabled());
979 session->setTrackerFilteringEnabled(m_ui->checkIpFilterTrackers->isChecked());
980 session->setIPFilterFile(m_ui->textFilterPath->selectedPath());
983 void OptionsDialog::loadSpeedTabOptions()
985 const auto *pref = Preferences::instance();
986 const auto *session = BitTorrent::Session::instance();
988 m_ui->labelGlobalRate->setPixmap(UIThemeManager::instance()->getScaledPixmap(u"slow_off"_s, Utils::Gui::mediumIconSize(this).height()));
989 m_ui->spinUploadLimit->setValue(session->globalUploadSpeedLimit() / 1024);
990 m_ui->spinDownloadLimit->setValue(session->globalDownloadSpeedLimit() / 1024);
992 m_ui->labelAltRate->setPixmap(UIThemeManager::instance()->getScaledPixmap(u"slow"_s, Utils::Gui::mediumIconSize(this).height()));
993 m_ui->spinUploadLimitAlt->setValue(session->altGlobalUploadSpeedLimit() / 1024);
994 m_ui->spinDownloadLimitAlt->setValue(session->altGlobalDownloadSpeedLimit() / 1024);
996 m_ui->comboBoxScheduleDays->addItems(translatedWeekdayNames());
998 m_ui->groupBoxSchedule->setChecked(session->isBandwidthSchedulerEnabled());
999 m_ui->timeEditScheduleFrom->setTime(pref->getSchedulerStartTime());
1000 m_ui->timeEditScheduleTo->setTime(pref->getSchedulerEndTime());
1001 m_ui->comboBoxScheduleDays->setCurrentIndex(static_cast<int>(pref->getSchedulerDays()));
1003 m_ui->checkLimituTPConnections->setChecked(session->isUTPRateLimited());
1004 m_ui->checkLimitTransportOverhead->setChecked(session->includeOverheadInLimits());
1005 m_ui->checkLimitLocalPeerRate->setChecked(!session->ignoreLimitsOnLAN());
1007 connect(m_ui->spinUploadLimit, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1008 connect(m_ui->spinDownloadLimit, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1010 connect(m_ui->spinUploadLimitAlt, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1011 connect(m_ui->spinDownloadLimitAlt, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1013 connect(m_ui->groupBoxSchedule, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
1014 connect(m_ui->timeEditScheduleFrom, &QDateTimeEdit::timeChanged, this, &ThisType::enableApplyButton);
1015 connect(m_ui->timeEditScheduleTo, &QDateTimeEdit::timeChanged, this, &ThisType::enableApplyButton);
1016 connect(m_ui->comboBoxScheduleDays, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
1018 connect(m_ui->checkLimituTPConnections, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
1019 connect(m_ui->checkLimitTransportOverhead, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
1020 connect(m_ui->checkLimitLocalPeerRate, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
1023 void OptionsDialog::saveSpeedTabOptions() const
1025 auto *pref = Preferences::instance();
1026 auto *session = BitTorrent::Session::instance();
1028 session->setGlobalUploadSpeedLimit(m_ui->spinUploadLimit->value() * 1024);
1029 session->setGlobalDownloadSpeedLimit(m_ui->spinDownloadLimit->value() * 1024);
1031 session->setAltGlobalUploadSpeedLimit(m_ui->spinUploadLimitAlt->value() * 1024);
1032 session->setAltGlobalDownloadSpeedLimit(m_ui->spinDownloadLimitAlt->value() * 1024);
1034 session->setBandwidthSchedulerEnabled(m_ui->groupBoxSchedule->isChecked());
1035 pref->setSchedulerStartTime(m_ui->timeEditScheduleFrom->time());
1036 pref->setSchedulerEndTime(m_ui->timeEditScheduleTo->time());
1037 pref->setSchedulerDays(static_cast<Scheduler::Days>(m_ui->comboBoxScheduleDays->currentIndex()));
1039 session->setUTPRateLimited(m_ui->checkLimituTPConnections->isChecked());
1040 session->setIncludeOverheadInLimits(m_ui->checkLimitTransportOverhead->isChecked());
1041 session->setIgnoreLimitsOnLAN(!m_ui->checkLimitLocalPeerRate->isChecked());
1044 void OptionsDialog::loadBittorrentTabOptions()
1046 const auto *session = BitTorrent::Session::instance();
1048 m_ui->checkDHT->setChecked(session->isDHTEnabled());
1049 m_ui->checkPeX->setChecked(session->isPeXEnabled());
1050 m_ui->checkLSD->setChecked(session->isLSDEnabled());
1051 m_ui->comboEncryption->setCurrentIndex(session->encryption());
1052 m_ui->checkAnonymousMode->setChecked(session->isAnonymousModeEnabled());
1054 m_ui->spinBoxMaxActiveCheckingTorrents->setValue(session->maxActiveCheckingTorrents());
1056 m_ui->checkEnableQueueing->setChecked(session->isQueueingSystemEnabled());
1057 m_ui->spinMaxActiveDownloads->setValue(session->maxActiveDownloads());
1058 m_ui->spinMaxActiveUploads->setValue(session->maxActiveUploads());
1059 m_ui->spinMaxActiveTorrents->setValue(session->maxActiveTorrents());
1061 m_ui->checkIgnoreSlowTorrentsForQueueing->setChecked(session->ignoreSlowTorrentsForQueueing());
1062 const QString slowTorrentsExplanation = u"<html><body><p>"
1063 + tr("A torrent will be considered slow if its download and upload rates stay below these values for \"Torrent inactivity timer\" seconds")
1064 + u"</p></body></html>";
1065 m_ui->labelDownloadRateForSlowTorrents->setToolTip(slowTorrentsExplanation);
1066 m_ui->labelUploadRateForSlowTorrents->setToolTip(slowTorrentsExplanation);
1067 m_ui->labelSlowTorrentInactivityTimer->setToolTip(slowTorrentsExplanation);
1068 m_ui->spinDownloadRateForSlowTorrents->setValue(session->downloadRateForSlowTorrents());
1069 m_ui->spinUploadRateForSlowTorrents->setValue(session->uploadRateForSlowTorrents());
1070 m_ui->spinSlowTorrentsInactivityTimer->setValue(session->slowTorrentsInactivityTimer());
1072 if (session->globalMaxRatio() >= 0.)
1074 // Enable
1075 m_ui->checkMaxRatio->setChecked(true);
1076 m_ui->spinMaxRatio->setEnabled(true);
1077 m_ui->comboRatioLimitAct->setEnabled(true);
1078 m_ui->spinMaxRatio->setValue(session->globalMaxRatio());
1080 else
1082 // Disable
1083 m_ui->checkMaxRatio->setChecked(false);
1084 m_ui->spinMaxRatio->setEnabled(false);
1086 if (session->globalMaxSeedingMinutes() >= 0)
1088 // Enable
1089 m_ui->checkMaxSeedingMinutes->setChecked(true);
1090 m_ui->spinMaxSeedingMinutes->setEnabled(true);
1091 m_ui->spinMaxSeedingMinutes->setValue(session->globalMaxSeedingMinutes());
1093 else
1095 // Disable
1096 m_ui->checkMaxSeedingMinutes->setChecked(false);
1097 m_ui->spinMaxSeedingMinutes->setEnabled(false);
1099 if (session->globalMaxInactiveSeedingMinutes() >= 0)
1101 // Enable
1102 m_ui->checkMaxInactiveSeedingMinutes->setChecked(true);
1103 m_ui->spinMaxInactiveSeedingMinutes->setEnabled(true);
1104 m_ui->spinMaxInactiveSeedingMinutes->setValue(session->globalMaxInactiveSeedingMinutes());
1106 else
1108 // Disable
1109 m_ui->checkMaxInactiveSeedingMinutes->setChecked(false);
1110 m_ui->spinMaxInactiveSeedingMinutes->setEnabled(false);
1112 m_ui->comboRatioLimitAct->setEnabled((session->globalMaxSeedingMinutes() >= 0) || (session->globalMaxRatio() >= 0.) || (session->globalMaxInactiveSeedingMinutes() >= 0));
1114 const QHash<BitTorrent::ShareLimitAction, int> actIndex =
1116 {BitTorrent::ShareLimitAction::Stop, 0},
1117 {BitTorrent::ShareLimitAction::Remove, 1},
1118 {BitTorrent::ShareLimitAction::RemoveWithContent, 2},
1119 {BitTorrent::ShareLimitAction::EnableSuperSeeding, 3}
1121 m_ui->comboRatioLimitAct->setCurrentIndex(actIndex.value(session->shareLimitAction()));
1123 m_ui->checkEnableAddTrackers->setChecked(session->isAddTrackersEnabled());
1124 m_ui->textTrackers->setPlainText(session->additionalTrackers());
1126 connect(m_ui->checkDHT, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
1127 connect(m_ui->checkPeX, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
1128 connect(m_ui->checkLSD, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
1129 connect(m_ui->comboEncryption, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
1130 connect(m_ui->checkAnonymousMode, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
1132 connect(m_ui->spinBoxMaxActiveCheckingTorrents, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1134 connect(m_ui->checkEnableQueueing, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
1135 connect(m_ui->spinMaxActiveDownloads, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1136 connect(m_ui->spinMaxActiveUploads, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1137 connect(m_ui->spinMaxActiveTorrents, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1138 connect(m_ui->checkIgnoreSlowTorrentsForQueueing, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
1139 connect(m_ui->spinDownloadRateForSlowTorrents, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1140 connect(m_ui->spinUploadRateForSlowTorrents, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1141 connect(m_ui->spinSlowTorrentsInactivityTimer, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1143 connect(m_ui->checkMaxRatio, &QAbstractButton::toggled, m_ui->spinMaxRatio, &QWidget::setEnabled);
1144 connect(m_ui->checkMaxRatio, &QAbstractButton::toggled, this, &ThisType::toggleComboRatioLimitAct);
1145 connect(m_ui->checkMaxRatio, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
1146 connect(m_ui->spinMaxRatio, qOverload<double>(&QDoubleSpinBox::valueChanged),this, &ThisType::enableApplyButton);
1147 connect(m_ui->comboRatioLimitAct, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
1148 connect(m_ui->checkMaxSeedingMinutes, &QAbstractButton::toggled, m_ui->spinMaxSeedingMinutes, &QWidget::setEnabled);
1149 connect(m_ui->checkMaxSeedingMinutes, &QAbstractButton::toggled, this, &ThisType::toggleComboRatioLimitAct);
1150 connect(m_ui->checkMaxSeedingMinutes, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
1151 connect(m_ui->spinMaxSeedingMinutes, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1152 connect(m_ui->checkMaxInactiveSeedingMinutes, &QAbstractButton::toggled, m_ui->spinMaxInactiveSeedingMinutes, &QWidget::setEnabled);
1153 connect(m_ui->checkMaxInactiveSeedingMinutes, &QAbstractButton::toggled, this, &ThisType::toggleComboRatioLimitAct);
1154 connect(m_ui->checkMaxInactiveSeedingMinutes, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
1155 connect(m_ui->spinMaxInactiveSeedingMinutes, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1157 connect(m_ui->checkEnableAddTrackers, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
1158 connect(m_ui->textTrackers, &QPlainTextEdit::textChanged, this, &ThisType::enableApplyButton);
1161 void OptionsDialog::saveBittorrentTabOptions() const
1163 auto *session = BitTorrent::Session::instance();
1165 session->setDHTEnabled(isDHTEnabled());
1166 session->setPeXEnabled(m_ui->checkPeX->isChecked());
1167 session->setLSDEnabled(isLSDEnabled());
1168 session->setEncryption(getEncryptionSetting());
1169 session->setAnonymousModeEnabled(m_ui->checkAnonymousMode->isChecked());
1171 session->setMaxActiveCheckingTorrents(m_ui->spinBoxMaxActiveCheckingTorrents->value());
1172 // Queueing system
1173 session->setQueueingSystemEnabled(isQueueingSystemEnabled());
1174 session->setMaxActiveDownloads(m_ui->spinMaxActiveDownloads->value());
1175 session->setMaxActiveUploads(m_ui->spinMaxActiveUploads->value());
1176 session->setMaxActiveTorrents(m_ui->spinMaxActiveTorrents->value());
1177 session->setIgnoreSlowTorrentsForQueueing(m_ui->checkIgnoreSlowTorrentsForQueueing->isChecked());
1178 session->setDownloadRateForSlowTorrents(m_ui->spinDownloadRateForSlowTorrents->value());
1179 session->setUploadRateForSlowTorrents(m_ui->spinUploadRateForSlowTorrents->value());
1180 session->setSlowTorrentsInactivityTimer(m_ui->spinSlowTorrentsInactivityTimer->value());
1182 session->setGlobalMaxRatio(getMaxRatio());
1183 session->setGlobalMaxSeedingMinutes(getMaxSeedingMinutes());
1184 session->setGlobalMaxInactiveSeedingMinutes(getMaxInactiveSeedingMinutes());
1185 const QVector<BitTorrent::ShareLimitAction> actIndex =
1187 BitTorrent::ShareLimitAction::Stop,
1188 BitTorrent::ShareLimitAction::Remove,
1189 BitTorrent::ShareLimitAction::RemoveWithContent,
1190 BitTorrent::ShareLimitAction::EnableSuperSeeding
1192 session->setShareLimitAction(actIndex.value(m_ui->comboRatioLimitAct->currentIndex()));
1194 session->setAddTrackersEnabled(m_ui->checkEnableAddTrackers->isChecked());
1195 session->setAdditionalTrackers(m_ui->textTrackers->toPlainText());
1198 void OptionsDialog::loadRSSTabOptions()
1200 const auto *rssSession = RSS::Session::instance();
1201 const auto *autoDownloader = RSS::AutoDownloader::instance();
1203 m_ui->checkRSSEnable->setChecked(rssSession->isProcessingEnabled());
1204 m_ui->spinRSSRefreshInterval->setValue(rssSession->refreshInterval());
1205 m_ui->spinRSSFetchDelay->setValue(rssSession->fetchDelay().count());
1206 m_ui->spinRSSMaxArticlesPerFeed->setValue(rssSession->maxArticlesPerFeed());
1207 m_ui->checkRSSAutoDownloaderEnable->setChecked(autoDownloader->isProcessingEnabled());
1208 m_ui->textSmartEpisodeFilters->setPlainText(autoDownloader->smartEpisodeFilters().join(u'\n'));
1209 m_ui->checkSmartFilterDownloadRepacks->setChecked(autoDownloader->downloadRepacks());
1211 connect(m_ui->checkRSSEnable, &QCheckBox::toggled, this, &OptionsDialog::enableApplyButton);
1212 connect(m_ui->checkRSSAutoDownloaderEnable, &QCheckBox::toggled, this, &OptionsDialog::enableApplyButton);
1213 connect(m_ui->btnEditRules, &QPushButton::clicked, this, [this]()
1215 auto *downloader = new AutomatedRssDownloader(this);
1216 downloader->setAttribute(Qt::WA_DeleteOnClose);
1217 downloader->open();
1219 connect(m_ui->textSmartEpisodeFilters, &QPlainTextEdit::textChanged, this, &OptionsDialog::enableApplyButton);
1220 connect(m_ui->checkSmartFilterDownloadRepacks, &QCheckBox::toggled, this, &OptionsDialog::enableApplyButton);
1221 connect(m_ui->spinRSSRefreshInterval, qSpinBoxValueChanged, this, &OptionsDialog::enableApplyButton);
1222 connect(m_ui->spinRSSFetchDelay, qSpinBoxValueChanged, this, &OptionsDialog::enableApplyButton);
1223 connect(m_ui->spinRSSMaxArticlesPerFeed, qSpinBoxValueChanged, this, &OptionsDialog::enableApplyButton);
1226 void OptionsDialog::saveRSSTabOptions() const
1228 auto *rssSession = RSS::Session::instance();
1229 auto *autoDownloader = RSS::AutoDownloader::instance();
1231 rssSession->setProcessingEnabled(m_ui->checkRSSEnable->isChecked());
1232 rssSession->setRefreshInterval(m_ui->spinRSSRefreshInterval->value());
1233 rssSession->setFetchDelay(std::chrono::seconds(m_ui->spinRSSFetchDelay->value()));
1234 rssSession->setMaxArticlesPerFeed(m_ui->spinRSSMaxArticlesPerFeed->value());
1235 autoDownloader->setProcessingEnabled(m_ui->checkRSSAutoDownloaderEnable->isChecked());
1236 autoDownloader->setSmartEpisodeFilters(m_ui->textSmartEpisodeFilters->toPlainText().split(u'\n', Qt::SkipEmptyParts));
1237 autoDownloader->setDownloadRepacks(m_ui->checkSmartFilterDownloadRepacks->isChecked());
1240 #ifndef DISABLE_WEBUI
1241 void OptionsDialog::loadWebUITabOptions()
1243 const auto *pref = Preferences::instance();
1245 m_ui->textWebUIHttpsCert->setMode(FileSystemPathEdit::Mode::FileOpen);
1246 m_ui->textWebUIHttpsCert->setFileNameFilter(tr("Certificate") + u" (*.cer *.crt *.pem)");
1247 m_ui->textWebUIHttpsCert->setDialogCaption(tr("Select certificate"));
1248 m_ui->textWebUIHttpsKey->setMode(FileSystemPathEdit::Mode::FileOpen);
1249 m_ui->textWebUIHttpsKey->setFileNameFilter(tr("Private key") + u" (*.key *.pem)");
1250 m_ui->textWebUIHttpsKey->setDialogCaption(tr("Select private key"));
1251 m_ui->textWebUIRootFolder->setMode(FileSystemPathEdit::Mode::DirectoryOpen);
1252 m_ui->textWebUIRootFolder->setDialogCaption(tr("Choose Alternative UI files location"));
1254 if (app()->webUI()->isErrored())
1255 m_ui->labelWebUIError->setText(tr("WebUI configuration failed. Reason: %1").arg(app()->webUI()->errorMessage()));
1256 else
1257 m_ui->labelWebUIError->hide();
1259 m_ui->checkWebUI->setChecked(pref->isWebUIEnabled());
1260 m_ui->textWebUIAddress->setText(pref->getWebUIAddress());
1261 m_ui->spinWebUIPort->setValue(pref->getWebUIPort());
1262 m_ui->checkWebUIUPnP->setChecked(pref->useUPnPForWebUIPort());
1263 m_ui->checkWebUIHttps->setChecked(pref->isWebUIHttpsEnabled());
1264 webUIHttpsCertChanged(pref->getWebUIHttpsCertificatePath());
1265 webUIHttpsKeyChanged(pref->getWebUIHttpsKeyPath());
1266 m_ui->textWebUIUsername->setText(pref->getWebUIUsername());
1267 m_ui->checkBypassLocalAuth->setChecked(!pref->isWebUILocalAuthEnabled());
1268 m_ui->checkBypassAuthSubnetWhitelist->setChecked(pref->isWebUIAuthSubnetWhitelistEnabled());
1269 m_ui->IPSubnetWhitelistButton->setEnabled(m_ui->checkBypassAuthSubnetWhitelist->isChecked());
1270 m_ui->spinBanCounter->setValue(pref->getWebUIMaxAuthFailCount());
1271 m_ui->spinBanDuration->setValue(pref->getWebUIBanDuration().count());
1272 m_ui->spinSessionTimeout->setValue(pref->getWebUISessionTimeout());
1273 // Alternative UI
1274 m_ui->groupAltWebUI->setChecked(pref->isAltWebUIEnabled());
1275 m_ui->textWebUIRootFolder->setSelectedPath(pref->getWebUIRootFolder());
1276 // Security
1277 m_ui->checkClickjacking->setChecked(pref->isWebUIClickjackingProtectionEnabled());
1278 m_ui->checkCSRFProtection->setChecked(pref->isWebUICSRFProtectionEnabled());
1279 m_ui->checkSecureCookie->setEnabled(pref->isWebUIHttpsEnabled());
1280 m_ui->checkSecureCookie->setChecked(pref->isWebUISecureCookieEnabled());
1281 m_ui->groupHostHeaderValidation->setChecked(pref->isWebUIHostHeaderValidationEnabled());
1282 m_ui->textServerDomains->setText(pref->getServerDomains());
1283 // Custom HTTP headers
1284 m_ui->groupWebUIAddCustomHTTPHeaders->setChecked(pref->isWebUICustomHTTPHeadersEnabled());
1285 m_ui->textWebUICustomHTTPHeaders->setPlainText(pref->getWebUICustomHTTPHeaders());
1286 // Reverse proxy
1287 m_ui->groupEnableReverseProxySupport->setChecked(pref->isWebUIReverseProxySupportEnabled());
1288 m_ui->textTrustedReverseProxiesList->setText(pref->getWebUITrustedReverseProxiesList());
1289 // DynDNS
1290 m_ui->checkDynDNS->setChecked(pref->isDynDNSEnabled());
1291 m_ui->comboDNSService->setCurrentIndex(static_cast<int>(pref->getDynDNSService()));
1292 m_ui->domainNameTxt->setText(pref->getDynDomainName());
1293 m_ui->DNSUsernameTxt->setText(pref->getDynDNSUsername());
1294 m_ui->DNSPasswordTxt->setText(pref->getDynDNSPassword());
1296 connect(m_ui->checkWebUI, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
1297 connect(m_ui->textWebUIAddress, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
1298 connect(m_ui->spinWebUIPort, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1299 connect(m_ui->checkWebUIUPnP, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
1300 connect(m_ui->checkWebUIHttps, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
1301 connect(m_ui->textWebUIHttpsCert, &FileSystemPathLineEdit::selectedPathChanged, this, &ThisType::enableApplyButton);
1302 connect(m_ui->textWebUIHttpsCert, &FileSystemPathLineEdit::selectedPathChanged, this, &OptionsDialog::webUIHttpsCertChanged);
1303 connect(m_ui->textWebUIHttpsKey, &FileSystemPathLineEdit::selectedPathChanged, this, &ThisType::enableApplyButton);
1304 connect(m_ui->textWebUIHttpsKey, &FileSystemPathLineEdit::selectedPathChanged, this, &OptionsDialog::webUIHttpsKeyChanged);
1306 connect(m_ui->textWebUIUsername, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
1307 connect(m_ui->textWebUIPassword, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
1309 connect(m_ui->checkBypassLocalAuth, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
1310 connect(m_ui->checkBypassAuthSubnetWhitelist, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
1311 connect(m_ui->checkBypassAuthSubnetWhitelist, &QAbstractButton::toggled, m_ui->IPSubnetWhitelistButton, &QWidget::setEnabled);
1312 connect(m_ui->spinBanCounter, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1313 connect(m_ui->spinBanDuration, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1314 connect(m_ui->spinSessionTimeout, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1316 connect(m_ui->groupAltWebUI, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
1317 connect(m_ui->textWebUIRootFolder, &FileSystemPathLineEdit::selectedPathChanged, this, &ThisType::enableApplyButton);
1319 connect(m_ui->checkClickjacking, &QCheckBox::toggled, this, &ThisType::enableApplyButton);
1320 connect(m_ui->checkCSRFProtection, &QCheckBox::toggled, this, &ThisType::enableApplyButton);
1321 connect(m_ui->checkWebUIHttps, &QGroupBox::toggled, m_ui->checkSecureCookie, &QWidget::setEnabled);
1322 connect(m_ui->checkSecureCookie, &QCheckBox::toggled, this, &ThisType::enableApplyButton);
1323 connect(m_ui->groupHostHeaderValidation, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
1324 connect(m_ui->textServerDomains, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
1326 connect(m_ui->groupWebUIAddCustomHTTPHeaders, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
1327 connect(m_ui->textWebUICustomHTTPHeaders, &QPlainTextEdit::textChanged, this, &OptionsDialog::enableApplyButton);
1329 connect(m_ui->groupEnableReverseProxySupport, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
1330 connect(m_ui->textTrustedReverseProxiesList, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
1332 connect(m_ui->checkDynDNS, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
1333 connect(m_ui->comboDNSService, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
1334 connect(m_ui->domainNameTxt, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
1335 connect(m_ui->DNSUsernameTxt, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
1336 connect(m_ui->DNSPasswordTxt, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
1339 void OptionsDialog::saveWebUITabOptions() const
1341 auto *pref = Preferences::instance();
1343 const bool webUIEnabled = isWebUIEnabled();
1345 pref->setWebUIEnabled(webUIEnabled);
1346 pref->setWebUIAddress(m_ui->textWebUIAddress->text());
1347 pref->setWebUIPort(m_ui->spinWebUIPort->value());
1348 pref->setUPnPForWebUIPort(m_ui->checkWebUIUPnP->isChecked());
1349 pref->setWebUIHttpsEnabled(m_ui->checkWebUIHttps->isChecked());
1350 pref->setWebUIHttpsCertificatePath(m_ui->textWebUIHttpsCert->selectedPath());
1351 pref->setWebUIHttpsKeyPath(m_ui->textWebUIHttpsKey->selectedPath());
1352 pref->setWebUIMaxAuthFailCount(m_ui->spinBanCounter->value());
1353 pref->setWebUIBanDuration(std::chrono::seconds {m_ui->spinBanDuration->value()});
1354 pref->setWebUISessionTimeout(m_ui->spinSessionTimeout->value());
1355 // Authentication
1356 if (const QString username = webUIUsername(); isValidWebUIUsername(username))
1357 pref->setWebUIUsername(username);
1358 if (const QString password = webUIPassword(); isValidWebUIPassword(password))
1359 pref->setWebUIPassword(Utils::Password::PBKDF2::generate(password));
1360 pref->setWebUILocalAuthEnabled(!m_ui->checkBypassLocalAuth->isChecked());
1361 pref->setWebUIAuthSubnetWhitelistEnabled(m_ui->checkBypassAuthSubnetWhitelist->isChecked());
1362 // Alternative UI
1363 pref->setAltWebUIEnabled(m_ui->groupAltWebUI->isChecked());
1364 pref->setWebUIRootFolder(m_ui->textWebUIRootFolder->selectedPath());
1365 // Security
1366 pref->setWebUIClickjackingProtectionEnabled(m_ui->checkClickjacking->isChecked());
1367 pref->setWebUICSRFProtectionEnabled(m_ui->checkCSRFProtection->isChecked());
1368 pref->setWebUISecureCookieEnabled(m_ui->checkSecureCookie->isChecked());
1369 pref->setWebUIHostHeaderValidationEnabled(m_ui->groupHostHeaderValidation->isChecked());
1370 pref->setServerDomains(m_ui->textServerDomains->text());
1371 // Custom HTTP headers
1372 pref->setWebUICustomHTTPHeadersEnabled(m_ui->groupWebUIAddCustomHTTPHeaders->isChecked());
1373 pref->setWebUICustomHTTPHeaders(m_ui->textWebUICustomHTTPHeaders->toPlainText());
1374 // Reverse proxy
1375 pref->setWebUIReverseProxySupportEnabled(m_ui->groupEnableReverseProxySupport->isChecked());
1376 pref->setWebUITrustedReverseProxiesList(m_ui->textTrustedReverseProxiesList->text());
1377 // DynDNS
1378 pref->setDynDNSEnabled(m_ui->checkDynDNS->isChecked());
1379 pref->setDynDNSService(static_cast<DNS::Service>(m_ui->comboDNSService->currentIndex()));
1380 pref->setDynDomainName(m_ui->domainNameTxt->text());
1381 pref->setDynDNSUsername(m_ui->DNSUsernameTxt->text());
1382 pref->setDynDNSPassword(m_ui->DNSPasswordTxt->text());
1384 #endif // DISABLE_WEBUI
1386 void OptionsDialog::initializeLanguageCombo()
1388 // List language files
1389 const QStringList langFiles = QDir(u":/lang"_s).entryList({u"qbittorrent_*.qm"_s}, QDir::Files, QDir::Name);
1390 for (const QString &langFile : langFiles)
1392 const QString langCode = QStringView(langFile).sliced(12).chopped(3).toString(); // remove "qbittorrent_" and ".qm"
1393 m_ui->comboI18n->addItem(Utils::Misc::languageToLocalizedString(langCode), langCode);
1397 void OptionsDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous)
1399 if (!current)
1400 current = previous;
1401 m_ui->tabOption->setCurrentIndex(m_ui->tabSelection->row(current));
1404 void OptionsDialog::loadSplitterState()
1406 // width has been modified, use height as width reference instead
1407 const int width = m_ui->tabSelection->item(TAB_UI)->sizeHint().height() * 2;
1408 const QStringList defaultSizes = {QString::number(width), QString::number(m_ui->hsplitter->width() - width)};
1410 QList<int> splitterSizes;
1411 for (const QString &string : asConst(m_storeHSplitterSize.get(defaultSizes)))
1412 splitterSizes.append(string.toInt());
1414 m_ui->hsplitter->setSizes(splitterSizes);
1417 void OptionsDialog::showEvent(QShowEvent *e)
1419 QDialog::showEvent(e);
1421 loadSplitterState();
1424 void OptionsDialog::saveOptions() const
1426 auto *pref = Preferences::instance();
1428 saveBehaviorTabOptions();
1429 saveDownloadsTabOptions();
1430 saveConnectionTabOptions();
1431 saveSpeedTabOptions();
1432 saveBittorrentTabOptions();
1433 saveRSSTabOptions();
1434 #ifndef DISABLE_WEBUI
1435 saveWebUITabOptions();
1436 #endif
1437 m_advancedSettings->saveAdvancedSettings();
1439 // Assume that user changed multiple settings
1440 // so it's best to save immediately
1441 pref->apply();
1444 bool OptionsDialog::isIPFilteringEnabled() const
1446 return m_ui->checkIPFilter->isChecked();
1449 Net::ProxyType OptionsDialog::getProxyType() const
1451 return m_ui->comboProxyType->currentData().value<Net::ProxyType>();
1454 int OptionsDialog::getPort() const
1456 return m_ui->spinPort->value();
1459 void OptionsDialog::on_randomButton_clicked()
1461 // Range [1024: 65535]
1462 m_ui->spinPort->setValue(Utils::Random::rand(1024, 65535));
1465 int OptionsDialog::getEncryptionSetting() const
1467 return m_ui->comboEncryption->currentIndex();
1470 int OptionsDialog::getMaxActiveDownloads() const
1472 return m_ui->spinMaxActiveDownloads->value();
1475 int OptionsDialog::getMaxActiveUploads() const
1477 return m_ui->spinMaxActiveUploads->value();
1480 int OptionsDialog::getMaxActiveTorrents() const
1482 return m_ui->spinMaxActiveTorrents->value();
1485 bool OptionsDialog::isQueueingSystemEnabled() const
1487 return m_ui->checkEnableQueueing->isChecked();
1490 bool OptionsDialog::isDHTEnabled() const
1492 return m_ui->checkDHT->isChecked();
1495 bool OptionsDialog::isLSDEnabled() const
1497 return m_ui->checkLSD->isChecked();
1500 bool OptionsDialog::isUPnPEnabled() const
1502 return m_ui->checkUPnP->isChecked();
1505 // Return Share ratio
1506 qreal OptionsDialog::getMaxRatio() const
1508 if (m_ui->checkMaxRatio->isChecked())
1509 return m_ui->spinMaxRatio->value();
1510 return -1;
1513 // Return Seeding Minutes
1514 int OptionsDialog::getMaxSeedingMinutes() const
1516 if (m_ui->checkMaxSeedingMinutes->isChecked())
1517 return m_ui->spinMaxSeedingMinutes->value();
1518 return -1;
1521 // Return Inactive Seeding Minutes
1522 int OptionsDialog::getMaxInactiveSeedingMinutes() const
1524 return m_ui->checkMaxInactiveSeedingMinutes->isChecked()
1525 ? m_ui->spinMaxInactiveSeedingMinutes->value()
1526 : -1;
1529 // Return max connections number
1530 int OptionsDialog::getMaxConnections() const
1532 if (!m_ui->checkMaxConnections->isChecked())
1533 return -1;
1535 return m_ui->spinMaxConnec->value();
1538 int OptionsDialog::getMaxConnectionsPerTorrent() const
1540 if (!m_ui->checkMaxConnectionsPerTorrent->isChecked())
1541 return -1;
1543 return m_ui->spinMaxConnecPerTorrent->value();
1546 int OptionsDialog::getMaxUploads() const
1548 if (!m_ui->checkMaxUploads->isChecked())
1549 return -1;
1551 return m_ui->spinMaxUploads->value();
1554 int OptionsDialog::getMaxUploadsPerTorrent() const
1556 if (!m_ui->checkMaxUploadsPerTorrent->isChecked())
1557 return -1;
1559 return m_ui->spinMaxUploadsPerTorrent->value();
1562 void OptionsDialog::on_buttonBox_accepted()
1564 if (m_applyButton->isEnabled())
1566 if (!applySettings())
1567 return;
1569 m_applyButton->setEnabled(false);
1572 accept();
1575 bool OptionsDialog::applySettings()
1577 if (!schedTimesOk())
1579 m_ui->tabSelection->setCurrentRow(TAB_SPEED);
1580 return false;
1582 #ifndef DISABLE_WEBUI
1583 if (isWebUIEnabled() && !webUIAuthenticationOk())
1585 m_ui->tabSelection->setCurrentRow(TAB_WEBUI);
1586 return false;
1588 if (!isAlternativeWebUIPathValid())
1590 m_ui->tabSelection->setCurrentRow(TAB_WEBUI);
1591 return false;
1593 #endif
1595 saveOptions();
1596 return true;
1599 void OptionsDialog::on_buttonBox_rejected()
1601 reject();
1604 bool OptionsDialog::useAdditionDialog() const
1606 return m_ui->checkAdditionDialog->isChecked();
1609 void OptionsDialog::enableApplyButton()
1611 m_applyButton->setEnabled(true);
1614 void OptionsDialog::toggleComboRatioLimitAct()
1616 // Verify if the share action button must be enabled
1617 m_ui->comboRatioLimitAct->setEnabled(m_ui->checkMaxRatio->isChecked() || m_ui->checkMaxSeedingMinutes->isChecked() || m_ui->checkMaxInactiveSeedingMinutes->isChecked());
1620 void OptionsDialog::adjustProxyOptions()
1622 const auto currentProxyType = m_ui->comboProxyType->currentData().value<Net::ProxyType>();
1623 const bool isAuthSupported = ((currentProxyType == Net::ProxyType::SOCKS5)
1624 || (currentProxyType == Net::ProxyType::HTTP));
1626 m_ui->checkProxyAuth->setEnabled(isAuthSupported);
1628 if (currentProxyType == Net::ProxyType::None)
1630 m_ui->labelProxyTypeIncompatible->setVisible(false);
1632 m_ui->lblProxyIP->setEnabled(false);
1633 m_ui->textProxyIP->setEnabled(false);
1634 m_ui->lblProxyPort->setEnabled(false);
1635 m_ui->spinProxyPort->setEnabled(false);
1637 m_ui->checkProxyHostnameLookup->setEnabled(false);
1638 m_ui->checkProxyRSS->setEnabled(false);
1639 m_ui->checkProxyMisc->setEnabled(false);
1640 m_ui->checkProxyBitTorrent->setEnabled(false);
1641 m_ui->checkProxyPeerConnections->setEnabled(false);
1643 else
1645 m_ui->lblProxyIP->setEnabled(true);
1646 m_ui->textProxyIP->setEnabled(true);
1647 m_ui->lblProxyPort->setEnabled(true);
1648 m_ui->spinProxyPort->setEnabled(true);
1650 m_ui->checkProxyBitTorrent->setEnabled(true);
1651 m_ui->checkProxyPeerConnections->setEnabled(true);
1653 if (currentProxyType == Net::ProxyType::SOCKS4)
1655 m_ui->labelProxyTypeIncompatible->setVisible(true);
1657 m_ui->checkProxyHostnameLookup->setEnabled(false);
1658 m_ui->checkProxyRSS->setEnabled(false);
1659 m_ui->checkProxyMisc->setEnabled(false);
1661 else
1663 // SOCKS5 or HTTP
1664 m_ui->labelProxyTypeIncompatible->setVisible(false);
1666 m_ui->checkProxyHostnameLookup->setEnabled(true);
1667 m_ui->checkProxyRSS->setEnabled(true);
1668 m_ui->checkProxyMisc->setEnabled(true);
1673 bool OptionsDialog::isSplashScreenDisabled() const
1675 return !m_ui->checkShowSplash->isChecked();
1678 #ifdef Q_OS_WIN
1679 bool OptionsDialog::WinStartup() const
1681 return m_ui->checkStartup->isChecked();
1683 #endif
1685 bool OptionsDialog::preAllocateAllFiles() const
1687 return m_ui->checkPreallocateAll->isChecked();
1690 bool OptionsDialog::addTorrentsStopped() const
1692 return m_ui->checkAddStopped->isChecked();
1695 // Proxy settings
1696 bool OptionsDialog::isProxyEnabled() const
1698 return m_ui->comboProxyType->currentIndex();
1701 QString OptionsDialog::getProxyIp() const
1703 return m_ui->textProxyIP->text().trimmed();
1706 unsigned short OptionsDialog::getProxyPort() const
1708 return m_ui->spinProxyPort->value();
1711 QString OptionsDialog::getProxyUsername() const
1713 QString username = m_ui->textProxyUsername->text().trimmed();
1714 return username;
1717 QString OptionsDialog::getProxyPassword() const
1719 QString password = m_ui->textProxyPassword->text();
1720 password = password.trimmed();
1721 return password;
1724 // Locale Settings
1725 QString OptionsDialog::getLocale() const
1727 return m_ui->comboI18n->itemData(m_ui->comboI18n->currentIndex(), Qt::UserRole).toString();
1730 void OptionsDialog::setLocale(const QString &localeStr)
1732 QString name;
1733 if (localeStr.startsWith(u"eo", Qt::CaseInsensitive))
1735 name = u"eo"_s;
1737 else if (localeStr.startsWith(u"ltg", Qt::CaseInsensitive))
1739 name = u"ltg"_s;
1741 else
1743 QLocale locale(localeStr);
1744 if (locale.language() == QLocale::Uzbek)
1745 name = u"uz@Latn"_s;
1746 else if (locale.language() == QLocale::Azerbaijani)
1747 name = u"az@latin"_s;
1748 else
1749 name = locale.name();
1751 // Attempt to find exact match
1752 int index = m_ui->comboI18n->findData(name, Qt::UserRole);
1753 if (index < 0)
1755 //Attempt to find a language match without a country
1756 int pos = name.indexOf(u'_');
1757 if (pos > -1)
1759 QString lang = name.left(pos);
1760 index = m_ui->comboI18n->findData(lang, Qt::UserRole);
1763 if (index < 0)
1765 // Unrecognized, use US English
1766 index = m_ui->comboI18n->findData(u"en"_s, Qt::UserRole);
1767 Q_ASSERT(index >= 0);
1769 m_ui->comboI18n->setCurrentIndex(index);
1772 Path OptionsDialog::getTorrentExportDir() const
1774 if (m_ui->checkExportDir->isChecked())
1775 return m_ui->textExportDir->selectedPath();
1776 return {};
1779 Path OptionsDialog::getFinishedTorrentExportDir() const
1781 if (m_ui->checkExportDirFin->isChecked())
1782 return m_ui->textExportDirFin->selectedPath();
1783 return {};
1786 void OptionsDialog::on_addWatchedFolderButton_clicked()
1788 Preferences *const pref = Preferences::instance();
1789 const Path dir {QFileDialog::getExistingDirectory(
1790 this, tr("Select folder to monitor"), pref->getScanDirsLastPath().parentPath().toString())};
1791 if (dir.isEmpty())
1792 return;
1794 auto *dialog = new WatchedFolderOptionsDialog({}, this);
1795 dialog->setAttribute(Qt::WA_DeleteOnClose);
1796 connect(dialog, &QDialog::accepted, this, [this, dialog, dir, pref]()
1800 auto *watchedFoldersModel = static_cast<WatchedFoldersModel *>(m_ui->scanFoldersView->model());
1801 watchedFoldersModel->addFolder(dir, dialog->watchedFolderOptions());
1803 pref->setScanDirsLastPath(dir);
1805 for (int i = 0; i < watchedFoldersModel->columnCount(); ++i)
1806 m_ui->scanFoldersView->resizeColumnToContents(i);
1808 enableApplyButton();
1810 catch (const RuntimeError &err)
1812 QMessageBox::critical(this, tr("Adding entry failed"), err.message());
1816 dialog->open();
1819 void OptionsDialog::on_editWatchedFolderButton_clicked()
1821 const QModelIndex selected
1822 = m_ui->scanFoldersView->selectionModel()->selectedIndexes().at(0);
1824 editWatchedFolderOptions(selected);
1827 void OptionsDialog::on_removeWatchedFolderButton_clicked()
1829 const QModelIndexList selected
1830 = m_ui->scanFoldersView->selectionModel()->selectedIndexes();
1832 for (const QModelIndex &index : selected)
1833 m_ui->scanFoldersView->model()->removeRow(index.row());
1836 void OptionsDialog::handleWatchedFolderViewSelectionChanged()
1838 const QModelIndexList selectedIndexes = m_ui->scanFoldersView->selectionModel()->selectedIndexes();
1839 m_ui->removeWatchedFolderButton->setEnabled(!selectedIndexes.isEmpty());
1840 m_ui->editWatchedFolderButton->setEnabled(selectedIndexes.count() == 1);
1843 void OptionsDialog::editWatchedFolderOptions(const QModelIndex &index)
1845 if (!index.isValid())
1846 return;
1848 auto *watchedFoldersModel = static_cast<WatchedFoldersModel *>(m_ui->scanFoldersView->model());
1849 auto *dialog = new WatchedFolderOptionsDialog(watchedFoldersModel->folderOptions(index.row()), this);
1850 dialog->setAttribute(Qt::WA_DeleteOnClose);
1851 connect(dialog, &QDialog::accepted, this, [this, dialog, index, watchedFoldersModel]()
1853 if (index.isValid())
1855 // The index could be invalidated while the dialog was displayed,
1856 // for example, if you deleted the folder using the Web API.
1857 watchedFoldersModel->setFolderOptions(index.row(), dialog->watchedFolderOptions());
1858 enableApplyButton();
1862 dialog->open();
1865 // Return Filter object to apply to BT session
1866 Path OptionsDialog::getFilter() const
1868 return m_ui->textFilterPath->selectedPath();
1871 #ifndef DISABLE_WEBUI
1872 void OptionsDialog::webUIHttpsCertChanged(const Path &path)
1874 const auto readResult = Utils::IO::readFile(path, Utils::Net::MAX_SSL_FILE_SIZE);
1875 const bool isCertValid = !Utils::SSLKey::load(readResult.value_or(QByteArray())).isNull();
1877 m_ui->textWebUIHttpsCert->setSelectedPath(path);
1878 m_ui->lblSslCertStatus->setPixmap(UIThemeManager::instance()->getScaledPixmap(
1879 (isCertValid ? u"security-high"_s : u"security-low"_s), 24));
1882 void OptionsDialog::webUIHttpsKeyChanged(const Path &path)
1884 const auto readResult = Utils::IO::readFile(path, Utils::Net::MAX_SSL_FILE_SIZE);
1885 const bool isKeyValid = !Utils::SSLKey::load(readResult.value_or(QByteArray())).isNull();
1887 m_ui->textWebUIHttpsKey->setSelectedPath(path);
1888 m_ui->lblSslKeyStatus->setPixmap(UIThemeManager::instance()->getScaledPixmap(
1889 (isKeyValid ? u"security-high"_s : u"security-low"_s), 24));
1892 bool OptionsDialog::isWebUIEnabled() const
1894 return m_ui->checkWebUI->isChecked();
1897 QString OptionsDialog::webUIUsername() const
1899 return m_ui->textWebUIUsername->text();
1902 QString OptionsDialog::webUIPassword() const
1904 return m_ui->textWebUIPassword->text();
1907 bool OptionsDialog::webUIAuthenticationOk()
1909 if (!isValidWebUIUsername(webUIUsername()))
1911 QMessageBox::warning(this, tr("Length Error"), tr("The WebUI username must be at least 3 characters long."));
1912 return false;
1915 const bool dontChangePassword = webUIPassword().isEmpty() && !Preferences::instance()->getWebUIPassword().isEmpty();
1916 if (!isValidWebUIPassword(webUIPassword()) && !dontChangePassword)
1918 QMessageBox::warning(this, tr("Length Error"), tr("The WebUI password must be at least 6 characters long."));
1919 return false;
1921 return true;
1924 bool OptionsDialog::isAlternativeWebUIPathValid()
1926 if (m_ui->groupAltWebUI->isChecked() && m_ui->textWebUIRootFolder->selectedPath().isEmpty())
1928 QMessageBox::warning(this, tr("Location Error"), tr("The alternative WebUI files location cannot be blank."));
1929 return false;
1931 return true;
1933 #endif
1935 void OptionsDialog::showConnectionTab()
1937 m_ui->tabSelection->setCurrentRow(TAB_CONNECTION);
1940 #ifndef DISABLE_WEBUI
1941 void OptionsDialog::on_registerDNSBtn_clicked()
1943 const auto service = static_cast<DNS::Service>(m_ui->comboDNSService->currentIndex());
1944 QDesktopServices::openUrl(Net::DNSUpdater::getRegistrationUrl(service));
1946 #endif
1948 void OptionsDialog::on_IpFilterRefreshBtn_clicked()
1950 if (m_refreshingIpFilter) return;
1951 m_refreshingIpFilter = true;
1952 // Updating program preferences
1953 BitTorrent::Session *const session = BitTorrent::Session::instance();
1954 session->setIPFilteringEnabled(true);
1955 session->setIPFilterFile({}); // forcing Session reload filter file
1956 session->setIPFilterFile(getFilter());
1957 connect(session, &BitTorrent::Session::IPFilterParsed, this, &OptionsDialog::handleIPFilterParsed);
1958 setCursor(QCursor(Qt::WaitCursor));
1961 void OptionsDialog::handleIPFilterParsed(bool error, int ruleCount)
1963 setCursor(QCursor(Qt::ArrowCursor));
1964 if (error)
1965 QMessageBox::warning(this, tr("Parsing error"), tr("Failed to parse the provided IP filter"));
1966 else
1967 QMessageBox::information(this, tr("Successfully refreshed"), tr("Successfully parsed the provided IP filter: %1 rules were applied.", "%1 is a number").arg(ruleCount));
1968 m_refreshingIpFilter = false;
1969 disconnect(BitTorrent::Session::instance(), &BitTorrent::Session::IPFilterParsed, this, &OptionsDialog::handleIPFilterParsed);
1972 bool OptionsDialog::schedTimesOk()
1974 if (m_ui->timeEditScheduleFrom->time() == m_ui->timeEditScheduleTo->time())
1976 QMessageBox::warning(this, tr("Time Error"), tr("The start time and the end time can't be the same."));
1977 return false;
1979 return true;
1982 void OptionsDialog::on_banListButton_clicked()
1984 auto *dialog = new BanListOptionsDialog(this);
1985 dialog->setAttribute(Qt::WA_DeleteOnClose);
1986 connect(dialog, &QDialog::accepted, this, &OptionsDialog::enableApplyButton);
1987 dialog->open();
1990 void OptionsDialog::on_IPSubnetWhitelistButton_clicked()
1992 auto *dialog = new IPSubnetWhitelistOptionsDialog(this);
1993 dialog->setAttribute(Qt::WA_DeleteOnClose);
1994 connect(dialog, &QDialog::accepted, this, &OptionsDialog::enableApplyButton);
1995 dialog->open();