Browse Source

Add option for enable/disable performance warnings from libtorrent

adaptive-webui-19844
Chocobo1 3 years ago
parent
commit
fad954df18
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 36
      src/base/bittorrent/session.cpp
  2. 3
      src/base/bittorrent/session.h
  3. 26
      src/gui/optionsdialog.cpp
  4. 7
      src/gui/optionsdialog.ui
  5. 10
      src/webui/api/appcontroller.cpp
  6. 2
      src/webui/webapplication.h
  7. 7
      src/webui/www/private/views/preferences.html

36
src/base/bittorrent/session.cpp

@ -443,6 +443,7 @@ Session::Session(QObject *parent) @@ -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() @@ -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() @@ -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) @@ -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;

3
src/base/bittorrent/session.h

@ -312,6 +312,8 @@ namespace BitTorrent @@ -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 @@ -741,6 +743,7 @@ namespace BitTorrent
CachedSettingValue<int> m_altGlobalUploadSpeedLimit;
CachedSettingValue<bool> m_isAltGlobalSpeedLimitEnabled;
CachedSettingValue<bool> m_isBandwidthSchedulerEnabled;
CachedSettingValue<bool> m_isPerformanceWarningEnabled;
CachedSettingValue<int> m_saveResumeDataInterval;
CachedSettingValue<int> m_port;
CachedSettingValue<QString> m_networkInterface;

26
src/gui/optionsdialog.cpp

@ -338,6 +338,7 @@ OptionsDialog::OptionsDialog(QWidget *parent) @@ -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() @@ -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() @@ -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<Application *>(QCoreApplication::instance());
app->setFileLoggerPath(m_ui->textFileLogPath->selectedPath());
app->setFileLoggerBackup(m_ui->checkFileLogBackup->isChecked());
@ -730,8 +736,6 @@ void OptionsDialog::saveOptions() @@ -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 @@ -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() @@ -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<Application*>(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() @@ -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() @@ -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

7
src/gui/optionsdialog.ui

@ -707,6 +707,13 @@ @@ -707,6 +707,13 @@
</layout>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxPerformanceWarning">
<property name="text">
<string>Log performance warnings</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">

10
src/webui/api/appcontroller.cpp

@ -97,8 +97,9 @@ void AppController::shutdownAction() @@ -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() @@ -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() @@ -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() @@ -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());

2
src/webui/webapplication.h

@ -44,7 +44,7 @@ @@ -44,7 +44,7 @@
#include "base/utils/net.h"
#include "base/utils/version.h"
inline const Utils::Version<int, 3, 2> API_VERSION {2, 8, 7};
inline const Utils::Version<int, 3, 2> API_VERSION {2, 8, 8};
class APIController;
class WebApplication;

7
src/webui/www/private/views/preferences.html

@ -693,6 +693,11 @@ @@ -693,6 +693,11 @@
</select>
</fieldset>
<div class="formRow">
<input type="checkbox" id="performanceWarning" />
<label for="performanceWarning">QBT_TR(Log performance warnings)QBT_TR[CONTEXT=OptionsDialog]</label>
</div>
<fieldset class="settings">
<legend>QBT_TR(Web User Interface (Remote control))QBT_TR[CONTEXT=OptionsDialog]</legend>
<table>
@ -1881,6 +1886,7 @@ @@ -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 @@ @@ -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'));

Loading…
Cancel
Save