Enable customizing the save statistics time interval
[qBittorrent.git] / src / gui / optionsdialog.cpp
blob264018117d33ee94794933d9cfc6318daabc1a16
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());
285 m_ui->windowStateComboBox->addItem(tr("Normal"), QVariant::fromValue(WindowState::Normal));
286 m_ui->windowStateComboBox->addItem(tr("Minimized"), QVariant::fromValue(WindowState::Minimized));
287 #ifndef Q_OS_MACOS
288 m_ui->windowStateComboBox->addItem(tr("Hidden"), QVariant::fromValue(WindowState::Hidden));
289 #endif
290 m_ui->windowStateComboBox->setCurrentIndex(m_ui->windowStateComboBox->findData(QVariant::fromValue(app()->startUpWindowState())));
292 #if !(defined(Q_OS_WIN) || defined(Q_OS_MACOS))
293 m_ui->groupFileAssociation->setVisible(false);
294 m_ui->checkProgramUpdates->setVisible(false);
295 #endif
297 #ifndef Q_OS_MACOS
298 // Disable systray integration if it is not supported by the system
299 if (!QSystemTrayIcon::isSystemTrayAvailable())
301 m_ui->checkShowSystray->setChecked(false);
302 m_ui->checkShowSystray->setEnabled(false);
303 m_ui->checkShowSystray->setToolTip(tr("Disabled due to failed to detect system tray presence"));
305 m_ui->checkShowSystray->setChecked(pref->systemTrayEnabled());
306 m_ui->checkMinimizeToSysTray->setChecked(pref->minimizeToTray());
307 m_ui->checkCloseToSystray->setChecked(pref->closeToTray());
308 m_ui->comboTrayIcon->setCurrentIndex(static_cast<int>(pref->trayIconStyle()));
309 #endif
311 #ifdef Q_OS_WIN
312 m_ui->checkStartup->setChecked(pref->WinStartup());
313 #endif
315 #ifdef Q_OS_MACOS
316 m_ui->checkShowSystray->setVisible(false);
317 m_ui->checkAssociateTorrents->setChecked(Utils::OS::isTorrentFileAssocSet());
318 m_ui->checkAssociateTorrents->setEnabled(!m_ui->checkAssociateTorrents->isChecked());
319 m_ui->checkAssociateMagnetLinks->setChecked(Utils::OS::isMagnetLinkAssocSet());
320 m_ui->checkAssociateMagnetLinks->setEnabled(!m_ui->checkAssociateMagnetLinks->isChecked());
321 #endif
323 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
324 m_ui->checkProgramUpdates->setChecked(pref->isUpdateCheckEnabled());
325 #endif
327 m_ui->checkPreventFromSuspendWhenDownloading->setChecked(pref->preventFromSuspendWhenDownloading());
328 m_ui->checkPreventFromSuspendWhenSeeding->setChecked(pref->preventFromSuspendWhenSeeding());
330 m_ui->textFileLogPath->setDialogCaption(tr("Choose a save directory"));
331 m_ui->textFileLogPath->setMode(FileSystemPathEdit::Mode::DirectorySave);
332 m_ui->textFileLogPath->setSelectedPath(app()->fileLoggerPath());
333 const bool fileLogBackup = app()->isFileLoggerBackup();
334 m_ui->checkFileLogBackup->setChecked(fileLogBackup);
335 m_ui->spinFileLogSize->setEnabled(fileLogBackup);
336 const bool fileLogDelete = app()->isFileLoggerDeleteOld();
337 m_ui->checkFileLogDelete->setChecked(fileLogDelete);
338 m_ui->spinFileLogAge->setEnabled(fileLogDelete);
339 m_ui->comboFileLogAgeType->setEnabled(fileLogDelete);
340 m_ui->spinFileLogSize->setValue(app()->fileLoggerMaxSize() / 1024);
341 m_ui->spinFileLogAge->setValue(app()->fileLoggerAge());
342 m_ui->comboFileLogAgeType->setCurrentIndex(app()->fileLoggerAgeType());
343 // Groupbox's check state must be initialized after some of its children if they are manually enabled/disabled
344 m_ui->checkFileLog->setChecked(app()->isFileLoggerEnabled());
346 m_ui->checkBoxPerformanceWarning->setChecked(session->isPerformanceWarningEnabled());
348 connect(m_ui->comboI18n, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
350 #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
351 connect(m_ui->checkUseSystemIcon, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
352 #endif
353 connect(m_ui->checkUseCustomTheme, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
354 connect(m_ui->customThemeFilePath, &FileSystemPathEdit::selectedPathChanged, this, &ThisType::enableApplyButton);
356 m_ui->buttonCustomizeUITheme->setEnabled(!m_ui->checkUseCustomTheme->isChecked());
357 connect(m_ui->checkUseCustomTheme, &QGroupBox::toggled, this, [this]
359 m_ui->buttonCustomizeUITheme->setEnabled(!m_ui->checkUseCustomTheme->isChecked());
361 connect(m_ui->buttonCustomizeUITheme, &QPushButton::clicked, this, [this]
363 auto *dialog = new UIThemeDialog(this);
364 dialog->setAttribute(Qt::WA_DeleteOnClose);
365 dialog->open();
368 connect(m_ui->confirmDeletion, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
369 connect(m_ui->checkAltRowColors, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
370 connect(m_ui->checkHideZero, &QAbstractButton::toggled, m_ui->comboHideZero, &QWidget::setEnabled);
371 connect(m_ui->checkHideZero, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
372 connect(m_ui->comboHideZero, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
373 connect(m_ui->actionTorrentDlOnDblClBox, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
374 connect(m_ui->actionTorrentFnOnDblClBox, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
375 connect(m_ui->checkBoxHideZeroStatusFilters, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
377 #ifdef Q_OS_WIN
378 connect(m_ui->checkStartup, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
379 #endif
380 connect(m_ui->checkShowSplash, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
381 connect(m_ui->checkProgramExitConfirm, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
382 connect(m_ui->checkProgramAutoExitConfirm, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
383 connect(m_ui->checkShowSystray, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
384 connect(m_ui->checkMinimizeToSysTray, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
385 connect(m_ui->checkCloseToSystray, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
386 connect(m_ui->comboTrayIcon, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
387 connect(m_ui->windowStateComboBox, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
389 connect(m_ui->checkPreventFromSuspendWhenDownloading, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
390 connect(m_ui->checkPreventFromSuspendWhenSeeding, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
392 #if defined(Q_OS_MACOS)
393 connect(m_ui->checkAssociateTorrents, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
394 connect(m_ui->checkAssociateMagnetLinks, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
395 #endif
397 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
398 connect(m_ui->checkProgramUpdates, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
399 #endif
401 #ifdef Q_OS_WIN
402 m_ui->assocPanel->hide();
403 #endif
405 #ifdef Q_OS_MAC
406 m_ui->defaultProgramPanel->hide();
407 #endif
409 #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)) && !defined(QBT_USES_DBUS)
410 m_ui->checkPreventFromSuspendWhenDownloading->setDisabled(true);
411 m_ui->checkPreventFromSuspendWhenSeeding->setDisabled(true);
412 #endif
414 connect(m_ui->checkFileLog, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
415 connect(m_ui->textFileLogPath, &FileSystemPathEdit::selectedPathChanged, this, &ThisType::enableApplyButton);
416 connect(m_ui->checkFileLogBackup, &QAbstractButton::toggled, m_ui->spinFileLogSize, &QWidget::setEnabled);
417 connect(m_ui->checkFileLogBackup, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
418 connect(m_ui->checkFileLogDelete, &QAbstractButton::toggled, m_ui->comboFileLogAgeType, &QWidget::setEnabled);
419 connect(m_ui->checkFileLogDelete, &QAbstractButton::toggled, m_ui->spinFileLogAge, &QWidget::setEnabled);
420 connect(m_ui->checkFileLogDelete, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
421 connect(m_ui->spinFileLogSize, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
422 connect(m_ui->spinFileLogAge, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
423 connect(m_ui->comboFileLogAgeType, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
425 connect(m_ui->checkBoxPerformanceWarning, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
428 void OptionsDialog::saveBehaviorTabOptions() const
430 auto *pref = Preferences::instance();
431 auto *session = BitTorrent::Session::instance();
433 // Load the translation
434 const QString locale = getLocale();
435 if (pref->getLocale() != locale)
437 auto *translator = new QTranslator;
438 if (translator->load(u":/lang/qbittorrent_"_s + locale))
439 qDebug("%s locale recognized, using translation.", qUtf8Printable(locale));
440 else
441 qDebug("%s locale unrecognized, using default (en).", qUtf8Printable(locale));
442 qApp->installTranslator(translator);
444 pref->setLocale(locale);
446 #if (defined(Q_OS_UNIX) && !defined(Q_OS_MACOS))
447 pref->useSystemIcons(m_ui->checkUseSystemIcon->isChecked());
448 #endif
449 pref->setUseCustomUITheme(m_ui->checkUseCustomTheme->isChecked());
450 pref->setCustomUIThemePath(m_ui->customThemeFilePath->selectedPath());
452 pref->setConfirmTorrentDeletion(m_ui->confirmDeletion->isChecked());
453 pref->setAlternatingRowColors(m_ui->checkAltRowColors->isChecked());
454 pref->setHideZeroValues(m_ui->checkHideZero->isChecked());
455 pref->setHideZeroComboValues(m_ui->comboHideZero->currentIndex());
457 pref->setActionOnDblClOnTorrentDl(m_ui->actionTorrentDlOnDblClBox->currentData().toInt());
458 pref->setActionOnDblClOnTorrentFn(m_ui->actionTorrentFnOnDblClBox->currentData().toInt());
460 pref->setHideZeroStatusFilters(m_ui->checkBoxHideZeroStatusFilters->isChecked());
462 pref->setSplashScreenDisabled(isSplashScreenDisabled());
463 pref->setConfirmOnExit(m_ui->checkProgramExitConfirm->isChecked());
464 pref->setDontConfirmAutoExit(!m_ui->checkProgramAutoExitConfirm->isChecked());
466 #ifdef Q_OS_WIN
467 pref->setWinStartup(WinStartup());
468 #endif
470 #ifndef Q_OS_MACOS
471 pref->setSystemTrayEnabled(m_ui->checkShowSystray->isChecked());
472 pref->setTrayIconStyle(TrayIcon::Style(m_ui->comboTrayIcon->currentIndex()));
473 pref->setCloseToTray(m_ui->checkCloseToSystray->isChecked());
474 pref->setMinimizeToTray(m_ui->checkMinimizeToSysTray->isChecked());
475 #endif
477 #ifdef Q_OS_MACOS
478 if (m_ui->checkAssociateTorrents->isChecked())
480 Utils::OS::setTorrentFileAssoc();
481 m_ui->checkAssociateTorrents->setChecked(Utils::OS::isTorrentFileAssocSet());
482 m_ui->checkAssociateTorrents->setEnabled(!m_ui->checkAssociateTorrents->isChecked());
484 if (m_ui->checkAssociateMagnetLinks->isChecked())
486 Utils::OS::setMagnetLinkAssoc();
487 m_ui->checkAssociateMagnetLinks->setChecked(Utils::OS::isMagnetLinkAssocSet());
488 m_ui->checkAssociateMagnetLinks->setEnabled(!m_ui->checkAssociateMagnetLinks->isChecked());
490 #endif
492 #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
493 pref->setUpdateCheckEnabled(m_ui->checkProgramUpdates->isChecked());
494 #endif
496 pref->setPreventFromSuspendWhenDownloading(m_ui->checkPreventFromSuspendWhenDownloading->isChecked());
497 pref->setPreventFromSuspendWhenSeeding(m_ui->checkPreventFromSuspendWhenSeeding->isChecked());
499 app()->setFileLoggerPath(m_ui->textFileLogPath->selectedPath());
500 app()->setFileLoggerBackup(m_ui->checkFileLogBackup->isChecked());
501 app()->setFileLoggerMaxSize(m_ui->spinFileLogSize->value() * 1024);
502 app()->setFileLoggerAge(m_ui->spinFileLogAge->value());
503 app()->setFileLoggerAgeType(m_ui->comboFileLogAgeType->currentIndex());
504 app()->setFileLoggerDeleteOld(m_ui->checkFileLogDelete->isChecked());
505 app()->setFileLoggerEnabled(m_ui->checkFileLog->isChecked());
507 app()->setStartUpWindowState(m_ui->windowStateComboBox->currentData().value<WindowState>());
509 session->setPerformanceWarningEnabled(m_ui->checkBoxPerformanceWarning->isChecked());
512 void OptionsDialog::loadDownloadsTabOptions()
514 const auto *pref = Preferences::instance();
515 const auto *session = BitTorrent::Session::instance();
517 m_ui->checkAdditionDialog->setChecked(pref->isAddNewTorrentDialogEnabled());
518 m_ui->checkAdditionDialogFront->setChecked(pref->isAddNewTorrentDialogTopLevel());
520 m_ui->contentLayoutComboBox->setCurrentIndex(static_cast<int>(session->torrentContentLayout()));
521 m_ui->checkAddToQueueTop->setChecked(session->isAddTorrentToQueueTop());
522 m_ui->checkAddStopped->setChecked(session->isAddTorrentStopped());
524 m_ui->stopConditionComboBox->setToolTip(
525 u"<html><body><p><b>" + tr("None") + u"</b> - " + tr("No stop condition is set.") + u"</p><p><b>" +
526 tr("Metadata received") + u"</b> - " + tr("Torrent will stop after metadata is received.") +
527 u" <em>" + tr("Torrents that have metadata initially will be added as stopped.") + u"</em></p><p><b>" +
528 tr("Files checked") + u"</b> - " + tr("Torrent will stop after files are initially checked.") +
529 u" <em>" + tr("This will also download metadata if it wasn't there initially.") + u"</em></p></body></html>");
530 m_ui->stopConditionComboBox->setItemData(0, QVariant::fromValue(BitTorrent::Torrent::StopCondition::None));
531 m_ui->stopConditionComboBox->setItemData(1, QVariant::fromValue(BitTorrent::Torrent::StopCondition::MetadataReceived));
532 m_ui->stopConditionComboBox->setItemData(2, QVariant::fromValue(BitTorrent::Torrent::StopCondition::FilesChecked));
533 m_ui->stopConditionComboBox->setCurrentIndex(m_ui->stopConditionComboBox->findData(QVariant::fromValue(session->torrentStopCondition())));
534 m_ui->stopConditionLabel->setEnabled(!m_ui->checkAddStopped->isChecked());
535 m_ui->stopConditionComboBox->setEnabled(!m_ui->checkAddStopped->isChecked());
537 m_ui->checkMergeTrackers->setChecked(session->isMergeTrackersEnabled());
538 m_ui->checkConfirmMergeTrackers->setEnabled(m_ui->checkAdditionDialog->isChecked());
539 m_ui->checkConfirmMergeTrackers->setChecked(m_ui->checkConfirmMergeTrackers->isEnabled() ? pref->confirmMergeTrackers() : false);
540 connect(m_ui->checkAdditionDialog, &QGroupBox::toggled, this, [this, pref]
542 m_ui->checkConfirmMergeTrackers->setEnabled(m_ui->checkAdditionDialog->isChecked());
543 m_ui->checkConfirmMergeTrackers->setChecked(m_ui->checkConfirmMergeTrackers->isEnabled() ? pref->confirmMergeTrackers() : false);
546 const TorrentFileGuard::AutoDeleteMode autoDeleteMode = TorrentFileGuard::autoDeleteMode();
547 m_ui->deleteTorrentBox->setChecked(autoDeleteMode != TorrentFileGuard::Never);
548 m_ui->deleteCancelledTorrentBox->setChecked(autoDeleteMode == TorrentFileGuard::Always);
549 m_ui->deleteTorrentWarningIcon->setPixmap(QApplication::style()->standardIcon(QStyle::SP_MessageBoxCritical).pixmap(16, 16));
550 m_ui->deleteTorrentWarningIcon->hide();
551 m_ui->deleteTorrentWarningLabel->hide();
552 m_ui->deleteTorrentWarningLabel->setToolTip(u"<html><body><p>" +
553 tr("By enabling these options, you can <strong>irrevocably lose</strong> your .torrent files!") +
554 u"</p><p>" +
555 tr("When these options are enabled, qBittorrent will <strong>delete</strong> .torrent files "
556 "after they were successfully (the first option) or not (the second option) added to its "
557 "download queue. This will be applied <strong>not only</strong> to the files opened via "
558 "&ldquo;Add torrent&rdquo; menu action but to those opened via <strong>file type association</strong> as well") +
559 u"</p><p>" +
560 tr("If you enable the second option (&ldquo;Also when addition is cancelled&rdquo;) the "
561 ".torrent file <strong>will be deleted</strong> even if you press &ldquo;<strong>Cancel</strong>&rdquo; in "
562 "the &ldquo;Add torrent&rdquo; dialog") +
563 u"</p></body></html>");
565 m_ui->checkPreallocateAll->setChecked(session->isPreallocationEnabled());
566 m_ui->checkAppendqB->setChecked(session->isAppendExtensionEnabled());
567 m_ui->checkUnwantedFolder->setChecked(session->isUnwantedFolderEnabled());
568 m_ui->checkRecursiveDownload->setChecked(pref->isRecursiveDownloadEnabled());
570 m_ui->comboSavingMode->setCurrentIndex(!session->isAutoTMMDisabledByDefault());
571 m_ui->comboTorrentCategoryChanged->setCurrentIndex(session->isDisableAutoTMMWhenCategoryChanged());
572 m_ui->comboCategoryChanged->setCurrentIndex(session->isDisableAutoTMMWhenCategorySavePathChanged());
573 m_ui->comboCategoryDefaultPathChanged->setCurrentIndex(session->isDisableAutoTMMWhenDefaultSavePathChanged());
575 m_ui->checkUseSubcategories->setChecked(session->isSubcategoriesEnabled());
576 m_ui->checkUseCategoryPaths->setChecked(session->useCategoryPathsInManualMode());
578 m_ui->textSavePath->setDialogCaption(tr("Choose a save directory"));
579 m_ui->textSavePath->setMode(FileSystemPathEdit::Mode::DirectorySave);
580 m_ui->textSavePath->setSelectedPath(session->savePath());
582 m_ui->checkUseDownloadPath->setChecked(session->isDownloadPathEnabled());
583 m_ui->textDownloadPath->setDialogCaption(tr("Choose a save directory"));
584 m_ui->textDownloadPath->setEnabled(m_ui->checkUseDownloadPath->isChecked());
585 m_ui->textDownloadPath->setMode(FileSystemPathEdit::Mode::DirectorySave);
586 m_ui->textDownloadPath->setSelectedPath(session->downloadPath());
588 const bool isExportDirEmpty = session->torrentExportDirectory().isEmpty();
589 m_ui->checkExportDir->setChecked(!isExportDirEmpty);
590 m_ui->textExportDir->setDialogCaption(tr("Choose export directory"));
591 m_ui->textExportDir->setEnabled(m_ui->checkExportDir->isChecked());
592 m_ui->textExportDir->setMode(FileSystemPathEdit::Mode::DirectorySave);
593 if (!isExportDirEmpty)
594 m_ui->textExportDir->setSelectedPath(session->torrentExportDirectory());
596 const bool isExportDirFinEmpty = session->finishedTorrentExportDirectory().isEmpty();
597 m_ui->checkExportDirFin->setChecked(!isExportDirFinEmpty);
598 m_ui->textExportDirFin->setDialogCaption(tr("Choose export directory"));
599 m_ui->textExportDirFin->setEnabled(m_ui->checkExportDirFin->isChecked());
600 m_ui->textExportDirFin->setMode(FileSystemPathEdit::Mode::DirectorySave);
601 if (!isExportDirFinEmpty)
602 m_ui->textExportDirFin->setSelectedPath(session->finishedTorrentExportDirectory());
604 auto *watchedFoldersModel = new WatchedFoldersModel(TorrentFilesWatcher::instance(), this);
605 connect(watchedFoldersModel, &QAbstractListModel::dataChanged, this, &ThisType::enableApplyButton);
606 m_ui->scanFoldersView->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
607 m_ui->scanFoldersView->setModel(watchedFoldersModel);
608 connect(m_ui->scanFoldersView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &ThisType::handleWatchedFolderViewSelectionChanged);
609 connect(m_ui->scanFoldersView, &QTreeView::doubleClicked, this, &ThisType::editWatchedFolderOptions);
611 m_ui->groupExcludedFileNames->setChecked(session->isExcludedFileNamesEnabled());
612 m_ui->textExcludedFileNames->setPlainText(session->excludedFileNames().join(u'\n'));
614 m_ui->groupMailNotification->setChecked(pref->isMailNotificationEnabled());
615 m_ui->senderEmailTxt->setText(pref->getMailNotificationSender());
616 m_ui->lineEditDestEmail->setText(pref->getMailNotificationEmail());
617 m_ui->lineEditSmtpServer->setText(pref->getMailNotificationSMTP());
618 m_ui->checkSmtpSSL->setChecked(pref->getMailNotificationSMTPSSL());
619 m_ui->groupMailNotifAuth->setChecked(pref->getMailNotificationSMTPAuth());
620 m_ui->mailNotifUsername->setText(pref->getMailNotificationSMTPUsername());
621 m_ui->mailNotifPassword->setText(pref->getMailNotificationSMTPPassword());
623 m_ui->groupBoxRunOnAdded->setChecked(pref->isAutoRunOnTorrentAddedEnabled());
624 m_ui->groupBoxRunOnFinished->setChecked(pref->isAutoRunOnTorrentFinishedEnabled());
625 m_ui->lineEditRunOnAdded->setText(pref->getAutoRunOnTorrentAddedProgram());
626 m_ui->lineEditRunOnFinished->setText(pref->getAutoRunOnTorrentFinishedProgram());
627 #if defined(Q_OS_WIN)
628 m_ui->autoRunConsole->setChecked(pref->isAutoRunConsoleEnabled());
629 #else
630 m_ui->autoRunConsole->hide();
631 #endif
632 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
633 .arg(tr("Supported parameters (case sensitive):")
634 , tr("%N: Torrent name")
635 , tr("%L: Category")
636 , tr("%G: Tags (separated by comma)")
637 , tr("%F: Content path (same as root path for multifile torrent)")
638 , tr("%R: Root path (first torrent subdirectory path)")
639 , tr("%D: Save path")
640 , tr("%C: Number of files")
641 , tr("%Z: Torrent size (bytes)"))
642 .arg(tr("%T: Current tracker")
643 , tr("%I: Info hash v1 (or '-' if unavailable)")
644 , tr("%J: Info hash v2 (or '-' if unavailable)")
645 , tr("%K: Torrent ID (either sha-1 info hash for v1 torrent or truncated sha-256 info hash for v2/hybrid torrent)")
646 , tr("Tip: Encapsulate parameter with quotation marks to avoid text being cut off at whitespace (e.g., \"%N\")"));
647 m_ui->labelAutoRunParam->setText(autoRunStr);
649 connect(m_ui->checkAdditionDialog, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
650 connect(m_ui->checkAdditionDialogFront, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
652 connect(m_ui->contentLayoutComboBox, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
654 connect(m_ui->checkAddToQueueTop, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
655 connect(m_ui->checkAddStopped, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
656 connect(m_ui->checkAddStopped, &QAbstractButton::toggled, this, [this](const bool checked)
658 m_ui->stopConditionLabel->setEnabled(!checked);
659 m_ui->stopConditionComboBox->setEnabled(!checked);
661 connect(m_ui->stopConditionComboBox, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
662 connect(m_ui->checkMergeTrackers, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
663 connect(m_ui->checkConfirmMergeTrackers, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
664 connect(m_ui->deleteTorrentBox, &QGroupBox::toggled, m_ui->deleteTorrentWarningIcon, &QWidget::setVisible);
665 connect(m_ui->deleteTorrentBox, &QGroupBox::toggled, m_ui->deleteTorrentWarningLabel, &QWidget::setVisible);
666 connect(m_ui->deleteTorrentBox, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
667 connect(m_ui->deleteCancelledTorrentBox, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
669 connect(m_ui->checkPreallocateAll, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
670 connect(m_ui->checkAppendqB, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
671 connect(m_ui->checkUnwantedFolder, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
672 connect(m_ui->checkRecursiveDownload, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
674 connect(m_ui->comboSavingMode, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
675 connect(m_ui->comboTorrentCategoryChanged, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
676 connect(m_ui->comboCategoryChanged, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
677 connect(m_ui->comboCategoryDefaultPathChanged, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
679 connect(m_ui->checkUseSubcategories, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
680 connect(m_ui->checkUseCategoryPaths, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
682 connect(m_ui->textSavePath, &FileSystemPathEdit::selectedPathChanged, this, &ThisType::enableApplyButton);
683 connect(m_ui->textDownloadPath, &FileSystemPathEdit::selectedPathChanged, this, &ThisType::enableApplyButton);
685 connect(m_ui->checkExportDir, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
686 connect(m_ui->checkExportDir, &QAbstractButton::toggled, m_ui->textExportDir, &QWidget::setEnabled);
687 connect(m_ui->checkExportDirFin, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
688 connect(m_ui->checkExportDirFin, &QAbstractButton::toggled, m_ui->textExportDirFin, &QWidget::setEnabled);
689 connect(m_ui->textExportDir, &FileSystemPathEdit::selectedPathChanged, this, &ThisType::enableApplyButton);
690 connect(m_ui->textExportDirFin, &FileSystemPathEdit::selectedPathChanged, this, &ThisType::enableApplyButton);
691 connect(m_ui->checkUseDownloadPath, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
692 connect(m_ui->checkUseDownloadPath, &QAbstractButton::toggled, m_ui->textDownloadPath, &QWidget::setEnabled);
694 connect(m_ui->addWatchedFolderButton, &QAbstractButton::clicked, this, &ThisType::enableApplyButton);
696 connect(m_ui->groupExcludedFileNames, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
697 connect(m_ui->textExcludedFileNames, &QPlainTextEdit::textChanged, this, &ThisType::enableApplyButton);
698 connect(m_ui->removeWatchedFolderButton, &QAbstractButton::clicked, this, &ThisType::enableApplyButton);
700 connect(m_ui->groupMailNotification, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
701 connect(m_ui->senderEmailTxt, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
702 connect(m_ui->lineEditDestEmail, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
703 connect(m_ui->lineEditSmtpServer, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
704 connect(m_ui->checkSmtpSSL, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
705 connect(m_ui->groupMailNotifAuth, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
706 connect(m_ui->mailNotifUsername, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
707 connect(m_ui->mailNotifPassword, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
708 connect(m_ui->sendTestEmail, &QPushButton::clicked, this, [this]
710 app()->sendTestEmail();
711 QMessageBox::information(this, tr("Test email"), tr("Attempted to send email. Check your inbox to confirm success"));
714 connect(m_ui->groupBoxRunOnAdded, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
715 connect(m_ui->lineEditRunOnAdded, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
716 connect(m_ui->groupBoxRunOnFinished, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
717 connect(m_ui->lineEditRunOnFinished, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
718 connect(m_ui->autoRunConsole, &QCheckBox::toggled, this, &ThisType::enableApplyButton);
721 void OptionsDialog::saveDownloadsTabOptions() const
723 auto *pref = Preferences::instance();
724 auto *session = BitTorrent::Session::instance();
726 pref->setAddNewTorrentDialogEnabled(useAdditionDialog());
727 pref->setAddNewTorrentDialogTopLevel(m_ui->checkAdditionDialogFront->isChecked());
729 session->setTorrentContentLayout(static_cast<BitTorrent::TorrentContentLayout>(m_ui->contentLayoutComboBox->currentIndex()));
731 session->setAddTorrentToQueueTop(m_ui->checkAddToQueueTop->isChecked());
732 session->setAddTorrentStopped(addTorrentsStopped());
733 session->setTorrentStopCondition(m_ui->stopConditionComboBox->currentData().value<BitTorrent::Torrent::StopCondition>());
734 TorrentFileGuard::setAutoDeleteMode(!m_ui->deleteTorrentBox->isChecked() ? TorrentFileGuard::Never
735 : !m_ui->deleteCancelledTorrentBox->isChecked() ? TorrentFileGuard::IfAdded
736 : TorrentFileGuard::Always);
737 session->setMergeTrackersEnabled(m_ui->checkMergeTrackers->isChecked());
738 if (m_ui->checkConfirmMergeTrackers->isEnabled())
739 pref->setConfirmMergeTrackers(m_ui->checkConfirmMergeTrackers->isChecked());
741 session->setPreallocationEnabled(preAllocateAllFiles());
742 session->setAppendExtensionEnabled(m_ui->checkAppendqB->isChecked());
743 session->setUnwantedFolderEnabled(m_ui->checkUnwantedFolder->isChecked());
744 pref->setRecursiveDownloadEnabled(m_ui->checkRecursiveDownload->isChecked());
746 session->setAutoTMMDisabledByDefault(m_ui->comboSavingMode->currentIndex() == 0);
747 session->setDisableAutoTMMWhenCategoryChanged(m_ui->comboTorrentCategoryChanged->currentIndex() == 1);
748 session->setDisableAutoTMMWhenCategorySavePathChanged(m_ui->comboCategoryChanged->currentIndex() == 1);
749 session->setDisableAutoTMMWhenDefaultSavePathChanged(m_ui->comboCategoryDefaultPathChanged->currentIndex() == 1);
751 session->setSubcategoriesEnabled(m_ui->checkUseSubcategories->isChecked());
752 session->setUseCategoryPathsInManualMode(m_ui->checkUseCategoryPaths->isChecked());
754 session->setSavePath(Path(m_ui->textSavePath->selectedPath()));
755 session->setDownloadPathEnabled(m_ui->checkUseDownloadPath->isChecked());
756 session->setDownloadPath(m_ui->textDownloadPath->selectedPath());
757 session->setTorrentExportDirectory(getTorrentExportDir());
758 session->setFinishedTorrentExportDirectory(getFinishedTorrentExportDir());
760 auto *watchedFoldersModel = static_cast<WatchedFoldersModel *>(m_ui->scanFoldersView->model());
761 watchedFoldersModel->apply();
763 session->setExcludedFileNamesEnabled(m_ui->groupExcludedFileNames->isChecked());
764 session->setExcludedFileNames(m_ui->textExcludedFileNames->toPlainText().split(u'\n', Qt::SkipEmptyParts));
766 pref->setMailNotificationEnabled(m_ui->groupMailNotification->isChecked());
767 pref->setMailNotificationSender(m_ui->senderEmailTxt->text());
768 pref->setMailNotificationEmail(m_ui->lineEditDestEmail->text());
769 pref->setMailNotificationSMTP(m_ui->lineEditSmtpServer->text());
770 pref->setMailNotificationSMTPSSL(m_ui->checkSmtpSSL->isChecked());
771 pref->setMailNotificationSMTPAuth(m_ui->groupMailNotifAuth->isChecked());
772 pref->setMailNotificationSMTPUsername(m_ui->mailNotifUsername->text());
773 pref->setMailNotificationSMTPPassword(m_ui->mailNotifPassword->text());
775 pref->setAutoRunOnTorrentAddedEnabled(m_ui->groupBoxRunOnAdded->isChecked());
776 pref->setAutoRunOnTorrentAddedProgram(m_ui->lineEditRunOnAdded->text().trimmed());
777 pref->setAutoRunOnTorrentFinishedEnabled(m_ui->groupBoxRunOnFinished->isChecked());
778 pref->setAutoRunOnTorrentFinishedProgram(m_ui->lineEditRunOnFinished->text().trimmed());
779 #if defined(Q_OS_WIN)
780 pref->setAutoRunConsoleEnabled(m_ui->autoRunConsole->isChecked());
781 #endif
784 void OptionsDialog::loadConnectionTabOptions()
786 const auto *session = BitTorrent::Session::instance();
788 m_ui->comboProtocol->setCurrentIndex(static_cast<int>(session->btProtocol()));
789 m_ui->spinPort->setValue(session->port());
790 m_ui->checkUPnP->setChecked(Net::PortForwarder::instance()->isEnabled());
792 int intValue = session->maxConnections();
793 if (intValue > 0)
795 // enable
796 m_ui->checkMaxConnections->setChecked(true);
797 m_ui->spinMaxConnec->setEnabled(true);
798 m_ui->spinMaxConnec->setValue(intValue);
800 else
802 // disable
803 m_ui->checkMaxConnections->setChecked(false);
804 m_ui->spinMaxConnec->setEnabled(false);
806 intValue = session->maxConnectionsPerTorrent();
807 if (intValue > 0)
809 // enable
810 m_ui->checkMaxConnectionsPerTorrent->setChecked(true);
811 m_ui->spinMaxConnecPerTorrent->setEnabled(true);
812 m_ui->spinMaxConnecPerTorrent->setValue(intValue);
814 else
816 // disable
817 m_ui->checkMaxConnectionsPerTorrent->setChecked(false);
818 m_ui->spinMaxConnecPerTorrent->setEnabled(false);
820 intValue = session->maxUploads();
821 if (intValue > 0)
823 // enable
824 m_ui->checkMaxUploads->setChecked(true);
825 m_ui->spinMaxUploads->setEnabled(true);
826 m_ui->spinMaxUploads->setValue(intValue);
828 else
830 // disable
831 m_ui->checkMaxUploads->setChecked(false);
832 m_ui->spinMaxUploads->setEnabled(false);
834 intValue = session->maxUploadsPerTorrent();
835 if (intValue > 0)
837 // enable
838 m_ui->checkMaxUploadsPerTorrent->setChecked(true);
839 m_ui->spinMaxUploadsPerTorrent->setEnabled(true);
840 m_ui->spinMaxUploadsPerTorrent->setValue(intValue);
842 else
844 // disable
845 m_ui->checkMaxUploadsPerTorrent->setChecked(false);
846 m_ui->spinMaxUploadsPerTorrent->setEnabled(false);
849 #if defined(QBT_USES_LIBTORRENT2) && TORRENT_USE_I2P
850 m_ui->textI2PHost->setText(session->I2PAddress());
851 m_ui->spinI2PPort->setValue(session->I2PPort());
852 m_ui->checkI2PMixed->setChecked(session->I2PMixedMode());
853 m_ui->groupI2P->setChecked(session->isI2PEnabled());
854 #else
855 m_ui->groupI2P->hide();
856 #endif
858 const auto *proxyConfigManager = Net::ProxyConfigurationManager::instance();
859 const Net::ProxyConfiguration proxyConf = proxyConfigManager->proxyConfiguration();
861 m_ui->comboProxyType->addItem(tr("(None)"), QVariant::fromValue(Net::ProxyType::None));
862 m_ui->comboProxyType->addItem(tr("SOCKS4"), QVariant::fromValue(Net::ProxyType::SOCKS4));
863 m_ui->comboProxyType->addItem(tr("SOCKS5"), QVariant::fromValue(Net::ProxyType::SOCKS5));
864 m_ui->comboProxyType->addItem(tr("HTTP"), QVariant::fromValue(Net::ProxyType::HTTP));
865 m_ui->comboProxyType->setCurrentIndex(m_ui->comboProxyType->findData(QVariant::fromValue(proxyConf.type)));
866 adjustProxyOptions();
868 m_ui->textProxyIP->setText(proxyConf.ip);
869 m_ui->spinProxyPort->setValue(proxyConf.port);
870 m_ui->textProxyUsername->setText(proxyConf.username);
871 m_ui->textProxyPassword->setText(proxyConf.password);
872 m_ui->checkProxyAuth->setChecked(proxyConf.authEnabled);
873 m_ui->checkProxyHostnameLookup->setChecked(proxyConf.hostnameLookupEnabled);
875 m_ui->checkProxyPeerConnections->setChecked(session->isProxyPeerConnectionsEnabled());
876 m_ui->checkProxyBitTorrent->setChecked(Preferences::instance()->useProxyForBT());
877 m_ui->checkProxyRSS->setChecked(Preferences::instance()->useProxyForRSS());
878 m_ui->checkProxyMisc->setChecked(Preferences::instance()->useProxyForGeneralPurposes());
880 m_ui->checkIPFilter->setChecked(session->isIPFilteringEnabled());
881 m_ui->textFilterPath->setDialogCaption(tr("Choose an IP filter file"));
882 m_ui->textFilterPath->setEnabled(m_ui->checkIPFilter->isChecked());
883 m_ui->textFilterPath->setFileNameFilter(tr("All supported filters") + u" (*.dat *.p2p *.p2b);;.dat (*.dat);;.p2p (*.p2p);;.p2b (*.p2b)");
884 m_ui->textFilterPath->setSelectedPath(session->IPFilterFile());
886 m_ui->IpFilterRefreshBtn->setIcon(UIThemeManager::instance()->getIcon(u"view-refresh"_s));
887 m_ui->IpFilterRefreshBtn->setEnabled(m_ui->checkIPFilter->isChecked());
888 m_ui->checkIpFilterTrackers->setChecked(session->isTrackerFilteringEnabled());
890 connect(m_ui->comboProtocol, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
891 connect(m_ui->spinPort, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
892 connect(m_ui->checkUPnP, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
894 connect(m_ui->checkMaxConnections, &QAbstractButton::toggled, m_ui->spinMaxConnec, &QWidget::setEnabled);
895 connect(m_ui->checkMaxConnections, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
896 connect(m_ui->checkMaxConnectionsPerTorrent, &QAbstractButton::toggled, m_ui->spinMaxConnecPerTorrent, &QWidget::setEnabled);
897 connect(m_ui->checkMaxConnectionsPerTorrent, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
898 connect(m_ui->checkMaxUploads, &QAbstractButton::toggled, m_ui->spinMaxUploads, &QWidget::setEnabled);
899 connect(m_ui->checkMaxUploads, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
900 connect(m_ui->checkMaxUploadsPerTorrent, &QAbstractButton::toggled, m_ui->spinMaxUploadsPerTorrent, &QWidget::setEnabled);
901 connect(m_ui->checkMaxUploadsPerTorrent, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
902 connect(m_ui->spinMaxConnec, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
903 connect(m_ui->spinMaxConnecPerTorrent, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
904 connect(m_ui->spinMaxUploads, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
905 connect(m_ui->spinMaxUploadsPerTorrent, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
907 connect(m_ui->comboProxyType, qComboBoxCurrentIndexChanged, this, &ThisType::adjustProxyOptions);
908 connect(m_ui->comboProxyType, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
909 connect(m_ui->textProxyIP, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
910 connect(m_ui->spinProxyPort, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
912 #if defined(QBT_USES_LIBTORRENT2) && TORRENT_USE_I2P
913 connect(m_ui->textI2PHost, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
914 connect(m_ui->spinI2PPort, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
915 connect(m_ui->checkI2PMixed, &QCheckBox::toggled, this, &ThisType::enableApplyButton);
916 connect(m_ui->groupI2P, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
917 #endif
919 connect(m_ui->checkProxyBitTorrent, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
920 connect(m_ui->checkProxyBitTorrent, &QGroupBox::toggled, this, &ThisType::adjustProxyOptions);
921 connect(m_ui->checkProxyPeerConnections, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
922 connect(m_ui->checkProxyHostnameLookup, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
923 connect(m_ui->checkProxyRSS, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
924 connect(m_ui->checkProxyMisc, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
926 connect(m_ui->checkProxyAuth, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
927 connect(m_ui->textProxyUsername, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
928 connect(m_ui->textProxyPassword, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
930 connect(m_ui->checkIPFilter, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
931 connect(m_ui->checkIPFilter, &QAbstractButton::toggled, m_ui->textFilterPath, &QWidget::setEnabled);
932 connect(m_ui->checkIPFilter, &QAbstractButton::toggled, m_ui->IpFilterRefreshBtn, &QWidget::setEnabled);
933 connect(m_ui->textFilterPath, &FileSystemPathEdit::selectedPathChanged, this, &ThisType::enableApplyButton);
934 connect(m_ui->checkIpFilterTrackers, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
937 void OptionsDialog::saveConnectionTabOptions() const
939 auto *session = BitTorrent::Session::instance();
941 session->setBTProtocol(static_cast<BitTorrent::BTProtocol>(m_ui->comboProtocol->currentIndex()));
942 session->setPort(getPort());
943 Net::PortForwarder::instance()->setEnabled(isUPnPEnabled());
945 session->setMaxConnections(getMaxConnections());
946 session->setMaxConnectionsPerTorrent(getMaxConnectionsPerTorrent());
947 session->setMaxUploads(getMaxUploads());
948 session->setMaxUploadsPerTorrent(getMaxUploadsPerTorrent());
950 #if defined(QBT_USES_LIBTORRENT2) && TORRENT_USE_I2P
951 session->setI2PEnabled(m_ui->groupI2P->isChecked());
952 session->setI2PAddress(m_ui->textI2PHost->text().trimmed());
953 session->setI2PPort(m_ui->spinI2PPort->value());
954 session->setI2PMixedMode(m_ui->checkI2PMixed->isChecked());
955 #endif
957 auto *proxyConfigManager = Net::ProxyConfigurationManager::instance();
958 Net::ProxyConfiguration proxyConf;
959 proxyConf.type = getProxyType();
960 proxyConf.ip = getProxyIp();
961 proxyConf.port = getProxyPort();
962 proxyConf.authEnabled = m_ui->checkProxyAuth->isChecked();
963 proxyConf.username = getProxyUsername();
964 proxyConf.password = getProxyPassword();
965 proxyConf.hostnameLookupEnabled = m_ui->checkProxyHostnameLookup->isChecked();
966 proxyConfigManager->setProxyConfiguration(proxyConf);
968 Preferences::instance()->setUseProxyForBT(m_ui->checkProxyBitTorrent->isChecked());
969 Preferences::instance()->setUseProxyForRSS(m_ui->checkProxyRSS->isChecked());
970 Preferences::instance()->setUseProxyForGeneralPurposes(m_ui->checkProxyMisc->isChecked());
972 session->setProxyPeerConnectionsEnabled(m_ui->checkProxyPeerConnections->isChecked());
974 // IPFilter
975 session->setIPFilteringEnabled(isIPFilteringEnabled());
976 session->setTrackerFilteringEnabled(m_ui->checkIpFilterTrackers->isChecked());
977 session->setIPFilterFile(m_ui->textFilterPath->selectedPath());
980 void OptionsDialog::loadSpeedTabOptions()
982 const auto *pref = Preferences::instance();
983 const auto *session = BitTorrent::Session::instance();
985 m_ui->labelGlobalRate->setPixmap(UIThemeManager::instance()->getScaledPixmap(u"slow_off"_s, Utils::Gui::mediumIconSize(this).height()));
986 m_ui->spinUploadLimit->setValue(session->globalUploadSpeedLimit() / 1024);
987 m_ui->spinDownloadLimit->setValue(session->globalDownloadSpeedLimit() / 1024);
989 m_ui->labelAltRate->setPixmap(UIThemeManager::instance()->getScaledPixmap(u"slow"_s, Utils::Gui::mediumIconSize(this).height()));
990 m_ui->spinUploadLimitAlt->setValue(session->altGlobalUploadSpeedLimit() / 1024);
991 m_ui->spinDownloadLimitAlt->setValue(session->altGlobalDownloadSpeedLimit() / 1024);
993 m_ui->comboBoxScheduleDays->addItems(translatedWeekdayNames());
995 m_ui->groupBoxSchedule->setChecked(session->isBandwidthSchedulerEnabled());
996 m_ui->timeEditScheduleFrom->setTime(pref->getSchedulerStartTime());
997 m_ui->timeEditScheduleTo->setTime(pref->getSchedulerEndTime());
998 m_ui->comboBoxScheduleDays->setCurrentIndex(static_cast<int>(pref->getSchedulerDays()));
1000 m_ui->checkLimituTPConnections->setChecked(session->isUTPRateLimited());
1001 m_ui->checkLimitTransportOverhead->setChecked(session->includeOverheadInLimits());
1002 m_ui->checkLimitLocalPeerRate->setChecked(!session->ignoreLimitsOnLAN());
1004 connect(m_ui->spinUploadLimit, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1005 connect(m_ui->spinDownloadLimit, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1007 connect(m_ui->spinUploadLimitAlt, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1008 connect(m_ui->spinDownloadLimitAlt, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1010 connect(m_ui->groupBoxSchedule, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
1011 connect(m_ui->timeEditScheduleFrom, &QDateTimeEdit::timeChanged, this, &ThisType::enableApplyButton);
1012 connect(m_ui->timeEditScheduleTo, &QDateTimeEdit::timeChanged, this, &ThisType::enableApplyButton);
1013 connect(m_ui->comboBoxScheduleDays, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
1015 connect(m_ui->checkLimituTPConnections, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
1016 connect(m_ui->checkLimitTransportOverhead, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
1017 connect(m_ui->checkLimitLocalPeerRate, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
1020 void OptionsDialog::saveSpeedTabOptions() const
1022 auto *pref = Preferences::instance();
1023 auto *session = BitTorrent::Session::instance();
1025 session->setGlobalUploadSpeedLimit(m_ui->spinUploadLimit->value() * 1024);
1026 session->setGlobalDownloadSpeedLimit(m_ui->spinDownloadLimit->value() * 1024);
1028 session->setAltGlobalUploadSpeedLimit(m_ui->spinUploadLimitAlt->value() * 1024);
1029 session->setAltGlobalDownloadSpeedLimit(m_ui->spinDownloadLimitAlt->value() * 1024);
1031 session->setBandwidthSchedulerEnabled(m_ui->groupBoxSchedule->isChecked());
1032 pref->setSchedulerStartTime(m_ui->timeEditScheduleFrom->time());
1033 pref->setSchedulerEndTime(m_ui->timeEditScheduleTo->time());
1034 pref->setSchedulerDays(static_cast<Scheduler::Days>(m_ui->comboBoxScheduleDays->currentIndex()));
1036 session->setUTPRateLimited(m_ui->checkLimituTPConnections->isChecked());
1037 session->setIncludeOverheadInLimits(m_ui->checkLimitTransportOverhead->isChecked());
1038 session->setIgnoreLimitsOnLAN(!m_ui->checkLimitLocalPeerRate->isChecked());
1041 void OptionsDialog::loadBittorrentTabOptions()
1043 const auto *session = BitTorrent::Session::instance();
1045 m_ui->checkDHT->setChecked(session->isDHTEnabled());
1046 m_ui->checkPeX->setChecked(session->isPeXEnabled());
1047 m_ui->checkLSD->setChecked(session->isLSDEnabled());
1048 m_ui->comboEncryption->setCurrentIndex(session->encryption());
1049 m_ui->checkAnonymousMode->setChecked(session->isAnonymousModeEnabled());
1051 m_ui->spinBoxMaxActiveCheckingTorrents->setValue(session->maxActiveCheckingTorrents());
1053 m_ui->checkEnableQueueing->setChecked(session->isQueueingSystemEnabled());
1054 m_ui->spinMaxActiveDownloads->setValue(session->maxActiveDownloads());
1055 m_ui->spinMaxActiveUploads->setValue(session->maxActiveUploads());
1056 m_ui->spinMaxActiveTorrents->setValue(session->maxActiveTorrents());
1058 m_ui->checkIgnoreSlowTorrentsForQueueing->setChecked(session->ignoreSlowTorrentsForQueueing());
1059 const QString slowTorrentsExplanation = u"<html><body><p>"
1060 + tr("A torrent will be considered slow if its download and upload rates stay below these values for \"Torrent inactivity timer\" seconds")
1061 + u"</p></body></html>";
1062 m_ui->labelDownloadRateForSlowTorrents->setToolTip(slowTorrentsExplanation);
1063 m_ui->labelUploadRateForSlowTorrents->setToolTip(slowTorrentsExplanation);
1064 m_ui->labelSlowTorrentInactivityTimer->setToolTip(slowTorrentsExplanation);
1065 m_ui->spinDownloadRateForSlowTorrents->setValue(session->downloadRateForSlowTorrents());
1066 m_ui->spinUploadRateForSlowTorrents->setValue(session->uploadRateForSlowTorrents());
1067 m_ui->spinSlowTorrentsInactivityTimer->setValue(session->slowTorrentsInactivityTimer());
1069 if (session->globalMaxRatio() >= 0.)
1071 // Enable
1072 m_ui->checkMaxRatio->setChecked(true);
1073 m_ui->spinMaxRatio->setEnabled(true);
1074 m_ui->comboRatioLimitAct->setEnabled(true);
1075 m_ui->spinMaxRatio->setValue(session->globalMaxRatio());
1077 else
1079 // Disable
1080 m_ui->checkMaxRatio->setChecked(false);
1081 m_ui->spinMaxRatio->setEnabled(false);
1083 if (session->globalMaxSeedingMinutes() >= 0)
1085 // Enable
1086 m_ui->checkMaxSeedingMinutes->setChecked(true);
1087 m_ui->spinMaxSeedingMinutes->setEnabled(true);
1088 m_ui->spinMaxSeedingMinutes->setValue(session->globalMaxSeedingMinutes());
1090 else
1092 // Disable
1093 m_ui->checkMaxSeedingMinutes->setChecked(false);
1094 m_ui->spinMaxSeedingMinutes->setEnabled(false);
1096 if (session->globalMaxInactiveSeedingMinutes() >= 0)
1098 // Enable
1099 m_ui->checkMaxInactiveSeedingMinutes->setChecked(true);
1100 m_ui->spinMaxInactiveSeedingMinutes->setEnabled(true);
1101 m_ui->spinMaxInactiveSeedingMinutes->setValue(session->globalMaxInactiveSeedingMinutes());
1103 else
1105 // Disable
1106 m_ui->checkMaxInactiveSeedingMinutes->setChecked(false);
1107 m_ui->spinMaxInactiveSeedingMinutes->setEnabled(false);
1109 m_ui->comboRatioLimitAct->setEnabled((session->globalMaxSeedingMinutes() >= 0) || (session->globalMaxRatio() >= 0.) || (session->globalMaxInactiveSeedingMinutes() >= 0));
1111 const QHash<BitTorrent::ShareLimitAction, int> actIndex =
1113 {BitTorrent::ShareLimitAction::Stop, 0},
1114 {BitTorrent::ShareLimitAction::Remove, 1},
1115 {BitTorrent::ShareLimitAction::RemoveWithContent, 2},
1116 {BitTorrent::ShareLimitAction::EnableSuperSeeding, 3}
1118 m_ui->comboRatioLimitAct->setCurrentIndex(actIndex.value(session->shareLimitAction()));
1120 m_ui->checkEnableAddTrackers->setChecked(session->isAddTrackersEnabled());
1121 m_ui->textTrackers->setPlainText(session->additionalTrackers());
1123 connect(m_ui->checkDHT, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
1124 connect(m_ui->checkPeX, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
1125 connect(m_ui->checkLSD, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
1126 connect(m_ui->comboEncryption, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
1127 connect(m_ui->checkAnonymousMode, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
1129 connect(m_ui->spinBoxMaxActiveCheckingTorrents, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1131 connect(m_ui->checkEnableQueueing, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
1132 connect(m_ui->spinMaxActiveDownloads, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1133 connect(m_ui->spinMaxActiveUploads, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1134 connect(m_ui->spinMaxActiveTorrents, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1135 connect(m_ui->checkIgnoreSlowTorrentsForQueueing, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
1136 connect(m_ui->spinDownloadRateForSlowTorrents, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1137 connect(m_ui->spinUploadRateForSlowTorrents, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1138 connect(m_ui->spinSlowTorrentsInactivityTimer, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1140 connect(m_ui->checkMaxRatio, &QAbstractButton::toggled, m_ui->spinMaxRatio, &QWidget::setEnabled);
1141 connect(m_ui->checkMaxRatio, &QAbstractButton::toggled, this, &ThisType::toggleComboRatioLimitAct);
1142 connect(m_ui->checkMaxRatio, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
1143 connect(m_ui->spinMaxRatio, qOverload<double>(&QDoubleSpinBox::valueChanged),this, &ThisType::enableApplyButton);
1144 connect(m_ui->comboRatioLimitAct, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
1145 connect(m_ui->checkMaxSeedingMinutes, &QAbstractButton::toggled, m_ui->spinMaxSeedingMinutes, &QWidget::setEnabled);
1146 connect(m_ui->checkMaxSeedingMinutes, &QAbstractButton::toggled, this, &ThisType::toggleComboRatioLimitAct);
1147 connect(m_ui->checkMaxSeedingMinutes, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
1148 connect(m_ui->spinMaxSeedingMinutes, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1149 connect(m_ui->checkMaxInactiveSeedingMinutes, &QAbstractButton::toggled, m_ui->spinMaxInactiveSeedingMinutes, &QWidget::setEnabled);
1150 connect(m_ui->checkMaxInactiveSeedingMinutes, &QAbstractButton::toggled, this, &ThisType::toggleComboRatioLimitAct);
1151 connect(m_ui->checkMaxInactiveSeedingMinutes, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
1152 connect(m_ui->spinMaxInactiveSeedingMinutes, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1154 connect(m_ui->checkEnableAddTrackers, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
1155 connect(m_ui->textTrackers, &QPlainTextEdit::textChanged, this, &ThisType::enableApplyButton);
1158 void OptionsDialog::saveBittorrentTabOptions() const
1160 auto *session = BitTorrent::Session::instance();
1162 session->setDHTEnabled(isDHTEnabled());
1163 session->setPeXEnabled(m_ui->checkPeX->isChecked());
1164 session->setLSDEnabled(isLSDEnabled());
1165 session->setEncryption(getEncryptionSetting());
1166 session->setAnonymousModeEnabled(m_ui->checkAnonymousMode->isChecked());
1168 session->setMaxActiveCheckingTorrents(m_ui->spinBoxMaxActiveCheckingTorrents->value());
1169 // Queueing system
1170 session->setQueueingSystemEnabled(isQueueingSystemEnabled());
1171 session->setMaxActiveDownloads(m_ui->spinMaxActiveDownloads->value());
1172 session->setMaxActiveUploads(m_ui->spinMaxActiveUploads->value());
1173 session->setMaxActiveTorrents(m_ui->spinMaxActiveTorrents->value());
1174 session->setIgnoreSlowTorrentsForQueueing(m_ui->checkIgnoreSlowTorrentsForQueueing->isChecked());
1175 session->setDownloadRateForSlowTorrents(m_ui->spinDownloadRateForSlowTorrents->value());
1176 session->setUploadRateForSlowTorrents(m_ui->spinUploadRateForSlowTorrents->value());
1177 session->setSlowTorrentsInactivityTimer(m_ui->spinSlowTorrentsInactivityTimer->value());
1179 session->setGlobalMaxRatio(getMaxRatio());
1180 session->setGlobalMaxSeedingMinutes(getMaxSeedingMinutes());
1181 session->setGlobalMaxInactiveSeedingMinutes(getMaxInactiveSeedingMinutes());
1182 const QList<BitTorrent::ShareLimitAction> actIndex =
1184 BitTorrent::ShareLimitAction::Stop,
1185 BitTorrent::ShareLimitAction::Remove,
1186 BitTorrent::ShareLimitAction::RemoveWithContent,
1187 BitTorrent::ShareLimitAction::EnableSuperSeeding
1189 session->setShareLimitAction(actIndex.value(m_ui->comboRatioLimitAct->currentIndex()));
1191 session->setAddTrackersEnabled(m_ui->checkEnableAddTrackers->isChecked());
1192 session->setAdditionalTrackers(m_ui->textTrackers->toPlainText());
1195 void OptionsDialog::loadRSSTabOptions()
1197 const auto *rssSession = RSS::Session::instance();
1198 const auto *autoDownloader = RSS::AutoDownloader::instance();
1200 m_ui->checkRSSEnable->setChecked(rssSession->isProcessingEnabled());
1201 m_ui->spinRSSRefreshInterval->setValue(rssSession->refreshInterval());
1202 m_ui->spinRSSFetchDelay->setValue(rssSession->fetchDelay().count());
1203 m_ui->spinRSSMaxArticlesPerFeed->setValue(rssSession->maxArticlesPerFeed());
1204 m_ui->checkRSSAutoDownloaderEnable->setChecked(autoDownloader->isProcessingEnabled());
1205 m_ui->textSmartEpisodeFilters->setPlainText(autoDownloader->smartEpisodeFilters().join(u'\n'));
1206 m_ui->checkSmartFilterDownloadRepacks->setChecked(autoDownloader->downloadRepacks());
1208 connect(m_ui->checkRSSEnable, &QCheckBox::toggled, this, &OptionsDialog::enableApplyButton);
1209 connect(m_ui->checkRSSAutoDownloaderEnable, &QCheckBox::toggled, this, &OptionsDialog::enableApplyButton);
1210 connect(m_ui->btnEditRules, &QPushButton::clicked, this, [this]()
1212 auto *downloader = new AutomatedRssDownloader(this);
1213 downloader->setAttribute(Qt::WA_DeleteOnClose);
1214 downloader->open();
1216 connect(m_ui->textSmartEpisodeFilters, &QPlainTextEdit::textChanged, this, &OptionsDialog::enableApplyButton);
1217 connect(m_ui->checkSmartFilterDownloadRepacks, &QCheckBox::toggled, this, &OptionsDialog::enableApplyButton);
1218 connect(m_ui->spinRSSRefreshInterval, qSpinBoxValueChanged, this, &OptionsDialog::enableApplyButton);
1219 connect(m_ui->spinRSSFetchDelay, qSpinBoxValueChanged, this, &OptionsDialog::enableApplyButton);
1220 connect(m_ui->spinRSSMaxArticlesPerFeed, qSpinBoxValueChanged, this, &OptionsDialog::enableApplyButton);
1223 void OptionsDialog::saveRSSTabOptions() const
1225 auto *rssSession = RSS::Session::instance();
1226 auto *autoDownloader = RSS::AutoDownloader::instance();
1228 rssSession->setProcessingEnabled(m_ui->checkRSSEnable->isChecked());
1229 rssSession->setRefreshInterval(m_ui->spinRSSRefreshInterval->value());
1230 rssSession->setFetchDelay(std::chrono::seconds(m_ui->spinRSSFetchDelay->value()));
1231 rssSession->setMaxArticlesPerFeed(m_ui->spinRSSMaxArticlesPerFeed->value());
1232 autoDownloader->setProcessingEnabled(m_ui->checkRSSAutoDownloaderEnable->isChecked());
1233 autoDownloader->setSmartEpisodeFilters(m_ui->textSmartEpisodeFilters->toPlainText().split(u'\n', Qt::SkipEmptyParts));
1234 autoDownloader->setDownloadRepacks(m_ui->checkSmartFilterDownloadRepacks->isChecked());
1237 #ifndef DISABLE_WEBUI
1238 void OptionsDialog::loadWebUITabOptions()
1240 const auto *pref = Preferences::instance();
1242 m_ui->textWebUIHttpsCert->setMode(FileSystemPathEdit::Mode::FileOpen);
1243 m_ui->textWebUIHttpsCert->setFileNameFilter(tr("Certificate") + u" (*.cer *.crt *.pem)");
1244 m_ui->textWebUIHttpsCert->setDialogCaption(tr("Select certificate"));
1245 m_ui->textWebUIHttpsKey->setMode(FileSystemPathEdit::Mode::FileOpen);
1246 m_ui->textWebUIHttpsKey->setFileNameFilter(tr("Private key") + u" (*.key *.pem)");
1247 m_ui->textWebUIHttpsKey->setDialogCaption(tr("Select private key"));
1248 m_ui->textWebUIRootFolder->setMode(FileSystemPathEdit::Mode::DirectoryOpen);
1249 m_ui->textWebUIRootFolder->setDialogCaption(tr("Choose Alternative UI files location"));
1251 if (app()->webUI()->isErrored())
1252 m_ui->labelWebUIError->setText(tr("WebUI configuration failed. Reason: %1").arg(app()->webUI()->errorMessage()));
1253 else
1254 m_ui->labelWebUIError->hide();
1256 m_ui->checkWebUI->setChecked(pref->isWebUIEnabled());
1257 m_ui->textWebUIAddress->setText(pref->getWebUIAddress());
1258 m_ui->spinWebUIPort->setValue(pref->getWebUIPort());
1259 m_ui->checkWebUIUPnP->setChecked(pref->useUPnPForWebUIPort());
1260 m_ui->checkWebUIHttps->setChecked(pref->isWebUIHttpsEnabled());
1261 webUIHttpsCertChanged(pref->getWebUIHttpsCertificatePath());
1262 webUIHttpsKeyChanged(pref->getWebUIHttpsKeyPath());
1263 m_ui->textWebUIUsername->setText(pref->getWebUIUsername());
1264 m_ui->checkBypassLocalAuth->setChecked(!pref->isWebUILocalAuthEnabled());
1265 m_ui->checkBypassAuthSubnetWhitelist->setChecked(pref->isWebUIAuthSubnetWhitelistEnabled());
1266 m_ui->IPSubnetWhitelistButton->setEnabled(m_ui->checkBypassAuthSubnetWhitelist->isChecked());
1267 m_ui->spinBanCounter->setValue(pref->getWebUIMaxAuthFailCount());
1268 m_ui->spinBanDuration->setValue(pref->getWebUIBanDuration().count());
1269 m_ui->spinSessionTimeout->setValue(pref->getWebUISessionTimeout());
1270 // Alternative UI
1271 m_ui->groupAltWebUI->setChecked(pref->isAltWebUIEnabled());
1272 m_ui->textWebUIRootFolder->setSelectedPath(pref->getWebUIRootFolder());
1273 // Security
1274 m_ui->checkClickjacking->setChecked(pref->isWebUIClickjackingProtectionEnabled());
1275 m_ui->checkCSRFProtection->setChecked(pref->isWebUICSRFProtectionEnabled());
1276 m_ui->checkSecureCookie->setChecked(pref->isWebUISecureCookieEnabled());
1277 m_ui->groupHostHeaderValidation->setChecked(pref->isWebUIHostHeaderValidationEnabled());
1278 m_ui->textServerDomains->setText(pref->getServerDomains());
1279 // Custom HTTP headers
1280 m_ui->groupWebUIAddCustomHTTPHeaders->setChecked(pref->isWebUICustomHTTPHeadersEnabled());
1281 m_ui->textWebUICustomHTTPHeaders->setPlainText(pref->getWebUICustomHTTPHeaders());
1282 // Reverse proxy
1283 m_ui->groupEnableReverseProxySupport->setChecked(pref->isWebUIReverseProxySupportEnabled());
1284 m_ui->textTrustedReverseProxiesList->setText(pref->getWebUITrustedReverseProxiesList());
1285 // DynDNS
1286 m_ui->checkDynDNS->setChecked(pref->isDynDNSEnabled());
1287 m_ui->comboDNSService->setCurrentIndex(static_cast<int>(pref->getDynDNSService()));
1288 m_ui->domainNameTxt->setText(pref->getDynDomainName());
1289 m_ui->DNSUsernameTxt->setText(pref->getDynDNSUsername());
1290 m_ui->DNSPasswordTxt->setText(pref->getDynDNSPassword());
1292 connect(m_ui->checkWebUI, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
1293 connect(m_ui->textWebUIAddress, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
1294 connect(m_ui->spinWebUIPort, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1295 connect(m_ui->checkWebUIUPnP, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
1296 connect(m_ui->checkWebUIHttps, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
1297 connect(m_ui->textWebUIHttpsCert, &FileSystemPathLineEdit::selectedPathChanged, this, &ThisType::enableApplyButton);
1298 connect(m_ui->textWebUIHttpsCert, &FileSystemPathLineEdit::selectedPathChanged, this, &OptionsDialog::webUIHttpsCertChanged);
1299 connect(m_ui->textWebUIHttpsKey, &FileSystemPathLineEdit::selectedPathChanged, this, &ThisType::enableApplyButton);
1300 connect(m_ui->textWebUIHttpsKey, &FileSystemPathLineEdit::selectedPathChanged, this, &OptionsDialog::webUIHttpsKeyChanged);
1302 connect(m_ui->textWebUIUsername, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
1303 connect(m_ui->textWebUIPassword, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
1305 connect(m_ui->checkBypassLocalAuth, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
1306 connect(m_ui->checkBypassAuthSubnetWhitelist, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
1307 connect(m_ui->checkBypassAuthSubnetWhitelist, &QAbstractButton::toggled, m_ui->IPSubnetWhitelistButton, &QWidget::setEnabled);
1308 connect(m_ui->spinBanCounter, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1309 connect(m_ui->spinBanDuration, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1310 connect(m_ui->spinSessionTimeout, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
1312 connect(m_ui->groupAltWebUI, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
1313 connect(m_ui->textWebUIRootFolder, &FileSystemPathLineEdit::selectedPathChanged, this, &ThisType::enableApplyButton);
1315 connect(m_ui->checkClickjacking, &QCheckBox::toggled, this, &ThisType::enableApplyButton);
1316 connect(m_ui->checkCSRFProtection, &QCheckBox::toggled, this, &ThisType::enableApplyButton);
1317 connect(m_ui->checkSecureCookie, &QCheckBox::toggled, this, &ThisType::enableApplyButton);
1318 connect(m_ui->groupHostHeaderValidation, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
1319 connect(m_ui->textServerDomains, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
1321 connect(m_ui->groupWebUIAddCustomHTTPHeaders, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
1322 connect(m_ui->textWebUICustomHTTPHeaders, &QPlainTextEdit::textChanged, this, &OptionsDialog::enableApplyButton);
1324 connect(m_ui->groupEnableReverseProxySupport, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
1325 connect(m_ui->textTrustedReverseProxiesList, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
1327 connect(m_ui->checkDynDNS, &QGroupBox::toggled, this, &ThisType::enableApplyButton);
1328 connect(m_ui->comboDNSService, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
1329 connect(m_ui->domainNameTxt, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
1330 connect(m_ui->DNSUsernameTxt, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
1331 connect(m_ui->DNSPasswordTxt, &QLineEdit::textChanged, this, &ThisType::enableApplyButton);
1334 void OptionsDialog::saveWebUITabOptions() const
1336 auto *pref = Preferences::instance();
1338 const bool webUIEnabled = isWebUIEnabled();
1340 pref->setWebUIEnabled(webUIEnabled);
1341 pref->setWebUIAddress(m_ui->textWebUIAddress->text());
1342 pref->setWebUIPort(m_ui->spinWebUIPort->value());
1343 pref->setUPnPForWebUIPort(m_ui->checkWebUIUPnP->isChecked());
1344 pref->setWebUIHttpsEnabled(m_ui->checkWebUIHttps->isChecked());
1345 pref->setWebUIHttpsCertificatePath(m_ui->textWebUIHttpsCert->selectedPath());
1346 pref->setWebUIHttpsKeyPath(m_ui->textWebUIHttpsKey->selectedPath());
1347 pref->setWebUIMaxAuthFailCount(m_ui->spinBanCounter->value());
1348 pref->setWebUIBanDuration(std::chrono::seconds {m_ui->spinBanDuration->value()});
1349 pref->setWebUISessionTimeout(m_ui->spinSessionTimeout->value());
1350 // Authentication
1351 if (const QString username = webUIUsername(); isValidWebUIUsername(username))
1352 pref->setWebUIUsername(username);
1353 if (const QString password = webUIPassword(); isValidWebUIPassword(password))
1354 pref->setWebUIPassword(Utils::Password::PBKDF2::generate(password));
1355 pref->setWebUILocalAuthEnabled(!m_ui->checkBypassLocalAuth->isChecked());
1356 pref->setWebUIAuthSubnetWhitelistEnabled(m_ui->checkBypassAuthSubnetWhitelist->isChecked());
1357 // Alternative UI
1358 pref->setAltWebUIEnabled(m_ui->groupAltWebUI->isChecked());
1359 pref->setWebUIRootFolder(m_ui->textWebUIRootFolder->selectedPath());
1360 // Security
1361 pref->setWebUIClickjackingProtectionEnabled(m_ui->checkClickjacking->isChecked());
1362 pref->setWebUICSRFProtectionEnabled(m_ui->checkCSRFProtection->isChecked());
1363 pref->setWebUISecureCookieEnabled(m_ui->checkSecureCookie->isChecked());
1364 pref->setWebUIHostHeaderValidationEnabled(m_ui->groupHostHeaderValidation->isChecked());
1365 pref->setServerDomains(m_ui->textServerDomains->text());
1366 // Custom HTTP headers
1367 pref->setWebUICustomHTTPHeadersEnabled(m_ui->groupWebUIAddCustomHTTPHeaders->isChecked());
1368 pref->setWebUICustomHTTPHeaders(m_ui->textWebUICustomHTTPHeaders->toPlainText());
1369 // Reverse proxy
1370 pref->setWebUIReverseProxySupportEnabled(m_ui->groupEnableReverseProxySupport->isChecked());
1371 pref->setWebUITrustedReverseProxiesList(m_ui->textTrustedReverseProxiesList->text());
1372 // DynDNS
1373 pref->setDynDNSEnabled(m_ui->checkDynDNS->isChecked());
1374 pref->setDynDNSService(static_cast<DNS::Service>(m_ui->comboDNSService->currentIndex()));
1375 pref->setDynDomainName(m_ui->domainNameTxt->text());
1376 pref->setDynDNSUsername(m_ui->DNSUsernameTxt->text());
1377 pref->setDynDNSPassword(m_ui->DNSPasswordTxt->text());
1379 #endif // DISABLE_WEBUI
1381 void OptionsDialog::initializeLanguageCombo()
1383 // List language files
1384 const QStringList langFiles = QDir(u":/lang"_s).entryList({u"qbittorrent_*.qm"_s}, QDir::Files, QDir::Name);
1385 for (const QString &langFile : langFiles)
1387 const QString langCode = QStringView(langFile).sliced(12).chopped(3).toString(); // remove "qbittorrent_" and ".qm"
1388 m_ui->comboI18n->addItem(Utils::Misc::languageToLocalizedString(langCode), langCode);
1392 void OptionsDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous)
1394 if (!current)
1395 current = previous;
1396 m_ui->tabOption->setCurrentIndex(m_ui->tabSelection->row(current));
1399 void OptionsDialog::loadSplitterState()
1401 // width has been modified, use height as width reference instead
1402 const int width = m_ui->tabSelection->item(TAB_UI)->sizeHint().height() * 2;
1403 const QStringList defaultSizes = {QString::number(width), QString::number(m_ui->hsplitter->width() - width)};
1405 QList<int> splitterSizes;
1406 for (const QString &string : asConst(m_storeHSplitterSize.get(defaultSizes)))
1407 splitterSizes.append(string.toInt());
1409 m_ui->hsplitter->setSizes(splitterSizes);
1412 void OptionsDialog::showEvent(QShowEvent *e)
1414 QDialog::showEvent(e);
1416 loadSplitterState();
1419 void OptionsDialog::saveOptions() const
1421 auto *pref = Preferences::instance();
1423 saveBehaviorTabOptions();
1424 saveDownloadsTabOptions();
1425 saveConnectionTabOptions();
1426 saveSpeedTabOptions();
1427 saveBittorrentTabOptions();
1428 saveRSSTabOptions();
1429 #ifndef DISABLE_WEBUI
1430 saveWebUITabOptions();
1431 #endif
1432 m_advancedSettings->saveAdvancedSettings();
1434 // Assume that user changed multiple settings
1435 // so it's best to save immediately
1436 pref->apply();
1439 bool OptionsDialog::isIPFilteringEnabled() const
1441 return m_ui->checkIPFilter->isChecked();
1444 Net::ProxyType OptionsDialog::getProxyType() const
1446 return m_ui->comboProxyType->currentData().value<Net::ProxyType>();
1449 int OptionsDialog::getPort() const
1451 return m_ui->spinPort->value();
1454 void OptionsDialog::on_randomButton_clicked()
1456 // Range [1024: 65535]
1457 m_ui->spinPort->setValue(Utils::Random::rand(1024, 65535));
1460 int OptionsDialog::getEncryptionSetting() const
1462 return m_ui->comboEncryption->currentIndex();
1465 int OptionsDialog::getMaxActiveDownloads() const
1467 return m_ui->spinMaxActiveDownloads->value();
1470 int OptionsDialog::getMaxActiveUploads() const
1472 return m_ui->spinMaxActiveUploads->value();
1475 int OptionsDialog::getMaxActiveTorrents() const
1477 return m_ui->spinMaxActiveTorrents->value();
1480 bool OptionsDialog::isQueueingSystemEnabled() const
1482 return m_ui->checkEnableQueueing->isChecked();
1485 bool OptionsDialog::isDHTEnabled() const
1487 return m_ui->checkDHT->isChecked();
1490 bool OptionsDialog::isLSDEnabled() const
1492 return m_ui->checkLSD->isChecked();
1495 bool OptionsDialog::isUPnPEnabled() const
1497 return m_ui->checkUPnP->isChecked();
1500 // Return Share ratio
1501 qreal OptionsDialog::getMaxRatio() const
1503 if (m_ui->checkMaxRatio->isChecked())
1504 return m_ui->spinMaxRatio->value();
1505 return -1;
1508 // Return Seeding Minutes
1509 int OptionsDialog::getMaxSeedingMinutes() const
1511 if (m_ui->checkMaxSeedingMinutes->isChecked())
1512 return m_ui->spinMaxSeedingMinutes->value();
1513 return -1;
1516 // Return Inactive Seeding Minutes
1517 int OptionsDialog::getMaxInactiveSeedingMinutes() const
1519 return m_ui->checkMaxInactiveSeedingMinutes->isChecked()
1520 ? m_ui->spinMaxInactiveSeedingMinutes->value()
1521 : -1;
1524 // Return max connections number
1525 int OptionsDialog::getMaxConnections() const
1527 if (!m_ui->checkMaxConnections->isChecked())
1528 return -1;
1530 return m_ui->spinMaxConnec->value();
1533 int OptionsDialog::getMaxConnectionsPerTorrent() const
1535 if (!m_ui->checkMaxConnectionsPerTorrent->isChecked())
1536 return -1;
1538 return m_ui->spinMaxConnecPerTorrent->value();
1541 int OptionsDialog::getMaxUploads() const
1543 if (!m_ui->checkMaxUploads->isChecked())
1544 return -1;
1546 return m_ui->spinMaxUploads->value();
1549 int OptionsDialog::getMaxUploadsPerTorrent() const
1551 if (!m_ui->checkMaxUploadsPerTorrent->isChecked())
1552 return -1;
1554 return m_ui->spinMaxUploadsPerTorrent->value();
1557 void OptionsDialog::on_buttonBox_accepted()
1559 if (m_applyButton->isEnabled())
1561 if (!applySettings())
1562 return;
1564 m_applyButton->setEnabled(false);
1567 accept();
1570 bool OptionsDialog::applySettings()
1572 if (!schedTimesOk())
1574 m_ui->tabSelection->setCurrentRow(TAB_SPEED);
1575 return false;
1577 #ifndef DISABLE_WEBUI
1578 if (isWebUIEnabled() && !webUIAuthenticationOk())
1580 m_ui->tabSelection->setCurrentRow(TAB_WEBUI);
1581 return false;
1583 if (!isAlternativeWebUIPathValid())
1585 m_ui->tabSelection->setCurrentRow(TAB_WEBUI);
1586 return false;
1588 #endif
1590 saveOptions();
1591 return true;
1594 void OptionsDialog::on_buttonBox_rejected()
1596 reject();
1599 bool OptionsDialog::useAdditionDialog() const
1601 return m_ui->checkAdditionDialog->isChecked();
1604 void OptionsDialog::enableApplyButton()
1606 m_applyButton->setEnabled(true);
1609 void OptionsDialog::toggleComboRatioLimitAct()
1611 // Verify if the share action button must be enabled
1612 m_ui->comboRatioLimitAct->setEnabled(m_ui->checkMaxRatio->isChecked() || m_ui->checkMaxSeedingMinutes->isChecked() || m_ui->checkMaxInactiveSeedingMinutes->isChecked());
1615 void OptionsDialog::adjustProxyOptions()
1617 const auto currentProxyType = m_ui->comboProxyType->currentData().value<Net::ProxyType>();
1618 const bool isAuthSupported = ((currentProxyType == Net::ProxyType::SOCKS5)
1619 || (currentProxyType == Net::ProxyType::HTTP));
1621 m_ui->checkProxyAuth->setEnabled(isAuthSupported);
1623 if (currentProxyType == Net::ProxyType::None)
1625 m_ui->labelProxyTypeIncompatible->setVisible(false);
1627 m_ui->lblProxyIP->setEnabled(false);
1628 m_ui->textProxyIP->setEnabled(false);
1629 m_ui->lblProxyPort->setEnabled(false);
1630 m_ui->spinProxyPort->setEnabled(false);
1632 m_ui->checkProxyHostnameLookup->setEnabled(false);
1633 m_ui->checkProxyRSS->setEnabled(false);
1634 m_ui->checkProxyMisc->setEnabled(false);
1635 m_ui->checkProxyBitTorrent->setEnabled(false);
1636 m_ui->checkProxyPeerConnections->setEnabled(false);
1638 else
1640 m_ui->lblProxyIP->setEnabled(true);
1641 m_ui->textProxyIP->setEnabled(true);
1642 m_ui->lblProxyPort->setEnabled(true);
1643 m_ui->spinProxyPort->setEnabled(true);
1645 m_ui->checkProxyBitTorrent->setEnabled(true);
1646 m_ui->checkProxyPeerConnections->setEnabled(true);
1648 if (currentProxyType == Net::ProxyType::SOCKS4)
1650 m_ui->labelProxyTypeIncompatible->setVisible(true);
1652 m_ui->checkProxyHostnameLookup->setEnabled(false);
1653 m_ui->checkProxyRSS->setEnabled(false);
1654 m_ui->checkProxyMisc->setEnabled(false);
1656 else
1658 // SOCKS5 or HTTP
1659 m_ui->labelProxyTypeIncompatible->setVisible(false);
1661 m_ui->checkProxyHostnameLookup->setEnabled(true);
1662 m_ui->checkProxyRSS->setEnabled(true);
1663 m_ui->checkProxyMisc->setEnabled(true);
1668 bool OptionsDialog::isSplashScreenDisabled() const
1670 return !m_ui->checkShowSplash->isChecked();
1673 #ifdef Q_OS_WIN
1674 bool OptionsDialog::WinStartup() const
1676 return m_ui->checkStartup->isChecked();
1678 #endif
1680 bool OptionsDialog::preAllocateAllFiles() const
1682 return m_ui->checkPreallocateAll->isChecked();
1685 bool OptionsDialog::addTorrentsStopped() const
1687 return m_ui->checkAddStopped->isChecked();
1690 // Proxy settings
1691 bool OptionsDialog::isProxyEnabled() const
1693 return m_ui->comboProxyType->currentIndex();
1696 QString OptionsDialog::getProxyIp() const
1698 return m_ui->textProxyIP->text().trimmed();
1701 unsigned short OptionsDialog::getProxyPort() const
1703 return m_ui->spinProxyPort->value();
1706 QString OptionsDialog::getProxyUsername() const
1708 QString username = m_ui->textProxyUsername->text().trimmed();
1709 return username;
1712 QString OptionsDialog::getProxyPassword() const
1714 QString password = m_ui->textProxyPassword->text();
1715 password = password.trimmed();
1716 return password;
1719 // Locale Settings
1720 QString OptionsDialog::getLocale() const
1722 return m_ui->comboI18n->itemData(m_ui->comboI18n->currentIndex(), Qt::UserRole).toString();
1725 void OptionsDialog::setLocale(const QString &localeStr)
1727 QString name;
1728 if (localeStr.startsWith(u"eo", Qt::CaseInsensitive))
1730 name = u"eo"_s;
1732 else if (localeStr.startsWith(u"ltg", Qt::CaseInsensitive))
1734 name = u"ltg"_s;
1736 else
1738 QLocale locale(localeStr);
1739 if (locale.language() == QLocale::Uzbek)
1740 name = u"uz@Latn"_s;
1741 else if (locale.language() == QLocale::Azerbaijani)
1742 name = u"az@latin"_s;
1743 else
1744 name = locale.name();
1746 // Attempt to find exact match
1747 int index = m_ui->comboI18n->findData(name, Qt::UserRole);
1748 if (index < 0)
1750 //Attempt to find a language match without a country
1751 int pos = name.indexOf(u'_');
1752 if (pos > -1)
1754 QString lang = name.left(pos);
1755 index = m_ui->comboI18n->findData(lang, Qt::UserRole);
1758 if (index < 0)
1760 // Unrecognized, use US English
1761 index = m_ui->comboI18n->findData(u"en"_s, Qt::UserRole);
1762 Q_ASSERT(index >= 0);
1764 m_ui->comboI18n->setCurrentIndex(index);
1767 Path OptionsDialog::getTorrentExportDir() const
1769 if (m_ui->checkExportDir->isChecked())
1770 return m_ui->textExportDir->selectedPath();
1771 return {};
1774 Path OptionsDialog::getFinishedTorrentExportDir() const
1776 if (m_ui->checkExportDirFin->isChecked())
1777 return m_ui->textExportDirFin->selectedPath();
1778 return {};
1781 void OptionsDialog::on_addWatchedFolderButton_clicked()
1783 Preferences *const pref = Preferences::instance();
1784 const Path dir {QFileDialog::getExistingDirectory(
1785 this, tr("Select folder to monitor"), pref->getScanDirsLastPath().parentPath().toString())};
1786 if (dir.isEmpty())
1787 return;
1789 auto *dialog = new WatchedFolderOptionsDialog({}, this);
1790 dialog->setAttribute(Qt::WA_DeleteOnClose);
1791 connect(dialog, &QDialog::accepted, this, [this, dialog, dir, pref]()
1795 auto *watchedFoldersModel = static_cast<WatchedFoldersModel *>(m_ui->scanFoldersView->model());
1796 watchedFoldersModel->addFolder(dir, dialog->watchedFolderOptions());
1798 pref->setScanDirsLastPath(dir);
1800 for (int i = 0; i < watchedFoldersModel->columnCount(); ++i)
1801 m_ui->scanFoldersView->resizeColumnToContents(i);
1803 enableApplyButton();
1805 catch (const RuntimeError &err)
1807 QMessageBox::critical(this, tr("Adding entry failed"), err.message());
1811 dialog->open();
1814 void OptionsDialog::on_editWatchedFolderButton_clicked()
1816 const QModelIndex selected
1817 = m_ui->scanFoldersView->selectionModel()->selectedIndexes().at(0);
1819 editWatchedFolderOptions(selected);
1822 void OptionsDialog::on_removeWatchedFolderButton_clicked()
1824 const QModelIndexList selected
1825 = m_ui->scanFoldersView->selectionModel()->selectedIndexes();
1827 for (const QModelIndex &index : selected)
1828 m_ui->scanFoldersView->model()->removeRow(index.row());
1831 void OptionsDialog::handleWatchedFolderViewSelectionChanged()
1833 const QModelIndexList selectedIndexes = m_ui->scanFoldersView->selectionModel()->selectedIndexes();
1834 m_ui->removeWatchedFolderButton->setEnabled(!selectedIndexes.isEmpty());
1835 m_ui->editWatchedFolderButton->setEnabled(selectedIndexes.count() == 1);
1838 void OptionsDialog::editWatchedFolderOptions(const QModelIndex &index)
1840 if (!index.isValid())
1841 return;
1843 auto *watchedFoldersModel = static_cast<WatchedFoldersModel *>(m_ui->scanFoldersView->model());
1844 auto *dialog = new WatchedFolderOptionsDialog(watchedFoldersModel->folderOptions(index.row()), this);
1845 dialog->setAttribute(Qt::WA_DeleteOnClose);
1846 connect(dialog, &QDialog::accepted, this, [this, dialog, index, watchedFoldersModel]()
1848 if (index.isValid())
1850 // The index could be invalidated while the dialog was displayed,
1851 // for example, if you deleted the folder using the Web API.
1852 watchedFoldersModel->setFolderOptions(index.row(), dialog->watchedFolderOptions());
1853 enableApplyButton();
1857 dialog->open();
1860 // Return Filter object to apply to BT session
1861 Path OptionsDialog::getFilter() const
1863 return m_ui->textFilterPath->selectedPath();
1866 #ifndef DISABLE_WEBUI
1867 void OptionsDialog::webUIHttpsCertChanged(const Path &path)
1869 const auto readResult = Utils::IO::readFile(path, Utils::Net::MAX_SSL_FILE_SIZE);
1870 const bool isCertValid = !Utils::SSLKey::load(readResult.value_or(QByteArray())).isNull();
1872 m_ui->textWebUIHttpsCert->setSelectedPath(path);
1873 m_ui->lblSslCertStatus->setPixmap(UIThemeManager::instance()->getScaledPixmap(
1874 (isCertValid ? u"security-high"_s : u"security-low"_s), 24));
1877 void OptionsDialog::webUIHttpsKeyChanged(const Path &path)
1879 const auto readResult = Utils::IO::readFile(path, Utils::Net::MAX_SSL_FILE_SIZE);
1880 const bool isKeyValid = !Utils::SSLKey::load(readResult.value_or(QByteArray())).isNull();
1882 m_ui->textWebUIHttpsKey->setSelectedPath(path);
1883 m_ui->lblSslKeyStatus->setPixmap(UIThemeManager::instance()->getScaledPixmap(
1884 (isKeyValid ? u"security-high"_s : u"security-low"_s), 24));
1887 bool OptionsDialog::isWebUIEnabled() const
1889 return m_ui->checkWebUI->isChecked();
1892 QString OptionsDialog::webUIUsername() const
1894 return m_ui->textWebUIUsername->text();
1897 QString OptionsDialog::webUIPassword() const
1899 return m_ui->textWebUIPassword->text();
1902 bool OptionsDialog::webUIAuthenticationOk()
1904 if (!isValidWebUIUsername(webUIUsername()))
1906 QMessageBox::warning(this, tr("Length Error"), tr("The WebUI username must be at least 3 characters long."));
1907 return false;
1910 const bool dontChangePassword = webUIPassword().isEmpty() && !Preferences::instance()->getWebUIPassword().isEmpty();
1911 if (!isValidWebUIPassword(webUIPassword()) && !dontChangePassword)
1913 QMessageBox::warning(this, tr("Length Error"), tr("The WebUI password must be at least 6 characters long."));
1914 return false;
1916 return true;
1919 bool OptionsDialog::isAlternativeWebUIPathValid()
1921 if (m_ui->groupAltWebUI->isChecked() && m_ui->textWebUIRootFolder->selectedPath().isEmpty())
1923 QMessageBox::warning(this, tr("Location Error"), tr("The alternative WebUI files location cannot be blank."));
1924 return false;
1926 return true;
1928 #endif
1930 void OptionsDialog::showConnectionTab()
1932 m_ui->tabSelection->setCurrentRow(TAB_CONNECTION);
1935 #ifndef DISABLE_WEBUI
1936 void OptionsDialog::on_registerDNSBtn_clicked()
1938 const auto service = static_cast<DNS::Service>(m_ui->comboDNSService->currentIndex());
1939 QDesktopServices::openUrl(Net::DNSUpdater::getRegistrationUrl(service));
1941 #endif
1943 void OptionsDialog::on_IpFilterRefreshBtn_clicked()
1945 if (m_refreshingIpFilter) return;
1946 m_refreshingIpFilter = true;
1947 // Updating program preferences
1948 BitTorrent::Session *const session = BitTorrent::Session::instance();
1949 session->setIPFilteringEnabled(true);
1950 session->setIPFilterFile({}); // forcing Session reload filter file
1951 session->setIPFilterFile(getFilter());
1952 connect(session, &BitTorrent::Session::IPFilterParsed, this, &OptionsDialog::handleIPFilterParsed);
1953 setCursor(QCursor(Qt::WaitCursor));
1956 void OptionsDialog::handleIPFilterParsed(bool error, int ruleCount)
1958 setCursor(QCursor(Qt::ArrowCursor));
1959 if (error)
1960 QMessageBox::warning(this, tr("Parsing error"), tr("Failed to parse the provided IP filter"));
1961 else
1962 QMessageBox::information(this, tr("Successfully refreshed"), tr("Successfully parsed the provided IP filter: %1 rules were applied.", "%1 is a number").arg(ruleCount));
1963 m_refreshingIpFilter = false;
1964 disconnect(BitTorrent::Session::instance(), &BitTorrent::Session::IPFilterParsed, this, &OptionsDialog::handleIPFilterParsed);
1967 bool OptionsDialog::schedTimesOk()
1969 if (m_ui->timeEditScheduleFrom->time() == m_ui->timeEditScheduleTo->time())
1971 QMessageBox::warning(this, tr("Time Error"), tr("The start time and the end time can't be the same."));
1972 return false;
1974 return true;
1977 void OptionsDialog::on_banListButton_clicked()
1979 auto *dialog = new BanListOptionsDialog(this);
1980 dialog->setAttribute(Qt::WA_DeleteOnClose);
1981 connect(dialog, &QDialog::accepted, this, &OptionsDialog::enableApplyButton);
1982 dialog->open();
1985 void OptionsDialog::on_IPSubnetWhitelistButton_clicked()
1987 auto *dialog = new IPSubnetWhitelistOptionsDialog(this);
1988 dialog->setAttribute(Qt::WA_DeleteOnClose);
1989 connect(dialog, &QDialog::accepted, this, &OptionsDialog::enableApplyButton);
1990 dialog->open();