From fad954df18944962694ab817ddc6c33b111ee4f3 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sat, 5 Mar 2022 15:17:05 +0800 Subject: [PATCH] Add option for enable/disable performance warnings from libtorrent --- src/base/bittorrent/session.cpp | 36 ++++++++++++++------ src/base/bittorrent/session.h | 3 ++ src/gui/optionsdialog.cpp | 26 +++++++------- src/gui/optionsdialog.ui | 7 ++++ src/webui/api/appcontroller.cpp | 10 ++++-- src/webui/webapplication.h | 2 +- src/webui/www/private/views/preferences.html | 7 ++++ 7 files changed, 64 insertions(+), 27 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 735acf0b7..ab1059e73 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -443,6 +443,7 @@ Session::Session(QObject *parent) , m_altGlobalUploadSpeedLimit(BITTORRENT_SESSION_KEY("AlternativeGlobalUPSpeedLimit"), 10, lowerLimited(0)) , m_isAltGlobalSpeedLimitEnabled(BITTORRENT_SESSION_KEY("UseAlternativeGlobalSpeedLimit"), false) , m_isBandwidthSchedulerEnabled(BITTORRENT_SESSION_KEY("BandwidthSchedulerEnabled"), false) + , m_isPerformanceWarningEnabled(BITTORRENT_SESSION_KEY("PerformanceWarning"), false) , m_saveResumeDataInterval(BITTORRENT_SESSION_KEY("SaveResumeDataInterval"), 60) , m_port(BITTORRENT_SESSION_KEY("Port"), -1) , m_networkInterface(BITTORRENT_SESSION_KEY("Interface")) @@ -1123,19 +1124,9 @@ void Session::configureComponents() void Session::initializeNativeSession() { - const lt::alert_category_t alertMask = lt::alert::error_notification - | lt::alert::file_progress_notification - | lt::alert::ip_block_notification - | lt::alert::peer_notification - | lt::alert::performance_warning - | lt::alert::port_mapping_notification - | lt::alert::status_notification - | lt::alert::storage_notification - | lt::alert::tracker_notification; const std::string peerId = lt::generate_fingerprint(PEER_ID, QBT_VERSION_MAJOR, QBT_VERSION_MINOR, QBT_VERSION_BUGFIX, QBT_VERSION_BUILD); lt::settings_pack pack; - pack.set_int(lt::settings_pack::alert_mask, alertMask); pack.set_str(lt::settings_pack::peer_fingerprint, peerId); pack.set_bool(lt::settings_pack::listen_system_port_fallback, false); pack.set_str(lt::settings_pack::user_agent, USER_AGENT); @@ -1258,6 +1249,17 @@ void Session::initMetrics() void Session::loadLTSettings(lt::settings_pack &settingsPack) { + const lt::alert_category_t alertMask = lt::alert::error_notification + | lt::alert::file_progress_notification + | lt::alert::ip_block_notification + | lt::alert::peer_notification + | (isPerformanceWarningEnabled() ? lt::alert::performance_warning : lt::alert_category_t()) + | lt::alert::port_mapping_notification + | lt::alert::status_notification + | lt::alert::storage_notification + | lt::alert::tracker_notification; + settingsPack.set_int(lt::settings_pack::alert_mask, alertMask); + settingsPack.set_int(lt::settings_pack::connection_speed, connectionSpeed()); // from libtorrent doc: @@ -2874,6 +2876,20 @@ void Session::setBandwidthSchedulerEnabled(const bool enabled) } } +bool Session::isPerformanceWarningEnabled() const +{ + return m_isPerformanceWarningEnabled; +} + +void Session::setPerformanceWarningEnabled(const bool enable) +{ + if (enable == m_isPerformanceWarningEnabled) + return; + + m_isPerformanceWarningEnabled = enable; + configureDeferred(); +} + int Session::saveResumeDataInterval() const { return m_saveResumeDataInterval; diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index b478f1a31..7447451ac 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -312,6 +312,8 @@ namespace BitTorrent bool isBandwidthSchedulerEnabled() const; void setBandwidthSchedulerEnabled(bool enabled); + bool isPerformanceWarningEnabled() const; + void setPerformanceWarningEnabled(bool enable); int saveResumeDataInterval() const; void setSaveResumeDataInterval(int value); int port() const; @@ -741,6 +743,7 @@ namespace BitTorrent CachedSettingValue m_altGlobalUploadSpeedLimit; CachedSettingValue m_isAltGlobalSpeedLimitEnabled; CachedSettingValue m_isBandwidthSchedulerEnabled; + CachedSettingValue m_isPerformanceWarningEnabled; CachedSettingValue m_saveResumeDataInterval; CachedSettingValue m_port; CachedSettingValue m_networkInterface; diff --git a/src/gui/optionsdialog.cpp b/src/gui/optionsdialog.cpp index 065201a38..6224718a0 100644 --- a/src/gui/optionsdialog.cpp +++ b/src/gui/optionsdialog.cpp @@ -338,6 +338,7 @@ OptionsDialog::OptionsDialog(QWidget *parent) connect(m_ui->checkAssociateMagnetLinks, &QAbstractButton::toggled, this, &ThisType::enableApplyButton); connect(m_ui->checkProgramUpdates, &QAbstractButton::toggled, this, &ThisType::enableApplyButton); #endif + connect(m_ui->checkBoxPerformanceWarning, &QAbstractButton::toggled, this, &ThisType::enableApplyButton); connect(m_ui->checkFileLog, &QGroupBox::toggled, this, &ThisType::enableApplyButton); connect(m_ui->textFileLogPath, &FileSystemPathEdit::selectedPathChanged, this, &ThisType::enableApplyButton); connect(m_ui->checkFileLogBackup, &QAbstractButton::toggled, this, &ThisType::enableApplyButton); @@ -650,8 +651,11 @@ void OptionsDialog::loadSplitterState() void OptionsDialog::saveOptions() { + auto *pref = Preferences::instance(); + auto *session = BitTorrent::Session::instance(); + m_applyButton->setEnabled(false); - Preferences *const pref = Preferences::instance(); + // Load the translation QString locale = getLocale(); if (pref->getLocale() != locale) @@ -713,6 +717,8 @@ void OptionsDialog::saveOptions() #if defined(Q_OS_WIN) || defined(Q_OS_MACOS) pref->setUpdateCheckEnabled(m_ui->checkProgramUpdates->isChecked()); #endif + session->setPerformanceWarningEnabled(m_ui->checkBoxPerformanceWarning->isChecked()); + auto *const app = static_cast(QCoreApplication::instance()); app->setFileLoggerPath(m_ui->textFileLogPath->selectedPath()); app->setFileLoggerBackup(m_ui->checkFileLogBackup->isChecked()); @@ -730,8 +736,6 @@ void OptionsDialog::saveOptions() RSS::AutoDownloader::instance()->setSmartEpisodeFilters(m_ui->textSmartEpisodeFilters->toPlainText().split('\n', Qt::SkipEmptyParts)); RSS::AutoDownloader::instance()->setDownloadRepacks(m_ui->checkSmartFilterDownloadRepacks->isChecked()); - auto session = BitTorrent::Session::instance(); - // Downloads preferences session->setSavePath(Path(m_ui->textSavePath->selectedPath())); session->setSubcategoriesEnabled(m_ui->checkUseSubcategories->isChecked()); @@ -919,11 +923,8 @@ Net::ProxyType OptionsDialog::getProxyType() const void OptionsDialog::loadOptions() { - int intValue; - QString strValue; - bool fileLogBackup = true; - bool fileLogDelete = true; - const Preferences *const pref = Preferences::instance(); + const auto *pref = Preferences::instance(); + const auto *session = BitTorrent::Session::instance(); // Behavior preferences setLocale(pref->getLocale()); @@ -965,14 +966,15 @@ void OptionsDialog::loadOptions() #if defined(Q_OS_WIN) || defined(Q_OS_MACOS) m_ui->checkProgramUpdates->setChecked(pref->isUpdateCheckEnabled()); #endif + m_ui->checkBoxPerformanceWarning->setChecked(session->isPerformanceWarningEnabled()); const Application *const app = static_cast(QCoreApplication::instance()); m_ui->checkFileLog->setChecked(app->isFileLoggerEnabled()); m_ui->textFileLogPath->setSelectedPath(app->fileLoggerPath()); - fileLogBackup = app->isFileLoggerBackup(); + const bool fileLogBackup = app->isFileLoggerBackup(); m_ui->checkFileLogBackup->setChecked(fileLogBackup); m_ui->spinFileLogSize->setEnabled(fileLogBackup); - fileLogDelete = app->isFileLoggerDeleteOld(); + const bool fileLogDelete = app->isFileLoggerDeleteOld(); m_ui->checkFileLogDelete->setChecked(fileLogDelete); m_ui->spinFileLogAge->setEnabled(fileLogDelete); m_ui->comboFileLogAgeType->setEnabled(fileLogDelete); @@ -989,8 +991,6 @@ void OptionsDialog::loadOptions() m_ui->spinRSSRefreshInterval->setValue(RSS::Session::instance()->refreshInterval()); m_ui->spinRSSMaxArticlesPerFeed->setValue(RSS::Session::instance()->maxArticlesPerFeed()); - const auto *session = BitTorrent::Session::instance(); - // Downloads preferences m_ui->checkAdditionDialog->setChecked(AddNewTorrentDialog::isEnabled()); m_ui->checkAdditionDialogFront->setChecked(AddNewTorrentDialog::isTopLevel()); @@ -1085,7 +1085,7 @@ void OptionsDialog::loadOptions() m_ui->spinPort->setValue(session->port()); m_ui->checkUPnP->setChecked(Net::PortForwarder::instance()->isEnabled()); - intValue = session->maxConnections(); + int intValue = session->maxConnections(); if (intValue > 0) { // enable diff --git a/src/gui/optionsdialog.ui b/src/gui/optionsdialog.ui index 6851b77bc..3c19804d0 100644 --- a/src/gui/optionsdialog.ui +++ b/src/gui/optionsdialog.ui @@ -707,6 +707,13 @@ + + + + Log performance warnings + + + diff --git a/src/webui/api/appcontroller.cpp b/src/webui/api/appcontroller.cpp index 8a514c158..8443b1c8c 100644 --- a/src/webui/api/appcontroller.cpp +++ b/src/webui/api/appcontroller.cpp @@ -97,8 +97,9 @@ void AppController::shutdownAction() void AppController::preferencesAction() { - const Preferences *const pref = Preferences::instance(); + const auto *pref = Preferences::instance(); const auto *session = BitTorrent::Session::instance(); + QJsonObject data; // Downloads @@ -231,6 +232,7 @@ void AppController::preferencesAction() // Web UI // Language data["locale"] = pref->getLocale(); + data["performance_warning"] = session->isPerformanceWarningEnabled(); // HTTP Server data["web_ui_domain_list"] = pref->getServerDomains(); data["web_ui_address"] = pref->getWebUiAddress(); @@ -370,8 +372,8 @@ void AppController::setPreferencesAction() { requireParams({"json"}); - Preferences *const pref = Preferences::instance(); - auto session = BitTorrent::Session::instance(); + auto *pref = Preferences::instance(); + auto *session = BitTorrent::Session::instance(); const QVariantHash m = QJsonDocument::fromJson(params()["json"].toUtf8()).toVariant().toHash(); QVariantHash::ConstIterator it; @@ -643,6 +645,8 @@ void AppController::setPreferencesAction() pref->setLocale(locale); } } + if (hasKey("performance_warning")) + session->setPerformanceWarningEnabled(it.value().toBool()); // HTTP Server if (hasKey("web_ui_domain_list")) pref->setServerDomains(it.value().toString()); diff --git a/src/webui/webapplication.h b/src/webui/webapplication.h index 5446cec3f..1fd3e1e41 100644 --- a/src/webui/webapplication.h +++ b/src/webui/webapplication.h @@ -44,7 +44,7 @@ #include "base/utils/net.h" #include "base/utils/version.h" -inline const Utils::Version API_VERSION {2, 8, 7}; +inline const Utils::Version API_VERSION {2, 8, 8}; class APIController; class WebApplication; diff --git a/src/webui/www/private/views/preferences.html b/src/webui/www/private/views/preferences.html index b7dcc576d..4b174797d 100644 --- a/src/webui/www/private/views/preferences.html +++ b/src/webui/www/private/views/preferences.html @@ -693,6 +693,11 @@ +
+ + +
+
QBT_TR(Web User Interface (Remote control))QBT_TR[CONTEXT=OptionsDialog] @@ -1881,6 +1886,7 @@ // Web UI tab // Language $('locale_select').setProperty('value', pref.locale); + $('performanceWarning').setProperty('checked', pref.performance_warning); // HTTP Server $('webui_domain_textarea').setProperty('value', pref.web_ui_domain_list); @@ -2259,6 +2265,7 @@ // Web UI tab // Language settings.set('locale', $('locale_select').getProperty('value')); + settings.set('performance_warning', $('performanceWarning').getProperty('checked')); // HTTP Server settings.set('web_ui_domain_list', $('webui_domain_textarea').getProperty('value'));