From 2d0f0cb372437d069949b6b9754b7f10f9e8dbe4 Mon Sep 17 00:00:00 2001 From: dzmat Date: Sun, 23 Sep 2018 13:20:05 +0700 Subject: [PATCH] Allow to disable speed graphs --- src/base/preferences.cpp | 10 ++++++++ src/base/preferences.h | 2 ++ src/gui/advancedsettings.cpp | 5 ++++ src/gui/advancedsettings.h | 2 +- src/gui/properties/propertieswidget.cpp | 34 +++++++++++++++++++------ src/gui/properties/propertieswidget.h | 4 +-- 6 files changed, 46 insertions(+), 11 deletions(-) diff --git a/src/base/preferences.cpp b/src/base/preferences.cpp index b0b8b5db6..c3dbe6568 100644 --- a/src/base/preferences.cpp +++ b/src/base/preferences.cpp @@ -1431,6 +1431,16 @@ void Preferences::setNetworkCookies(const QList &cookies) setValue("Network/Cookies", rawCookies); } +bool Preferences::isSpeedWidgetEnabled() const +{ + return value("SpeedWidget/Enabled", true).toBool(); +} + +void Preferences::setSpeedWidgetEnabled(bool enabled) +{ + setValue("SpeedWidget/Enabled", enabled); +} + int Preferences::getSpeedWidgetPeriod() const { return value("SpeedWidget/period", 1).toInt(); diff --git a/src/base/preferences.h b/src/base/preferences.h index 2c66ef04c..2f1658e12 100644 --- a/src/base/preferences.h +++ b/src/base/preferences.h @@ -371,6 +371,8 @@ public: void setNetworkCookies(const QList &cookies); // SpeedWidget + bool isSpeedWidgetEnabled() const; + void setSpeedWidgetEnabled(bool enabled); int getSpeedWidgetPeriod() const; void setSpeedWidgetPeriod(const int period); bool getSpeedWidgetGraphEnable(int id) const; diff --git a/src/gui/advancedsettings.cpp b/src/gui/advancedsettings.cpp index e9622440a..fd59048d8 100644 --- a/src/gui/advancedsettings.cpp +++ b/src/gui/advancedsettings.cpp @@ -73,6 +73,7 @@ enum AdvSettingsRows CONFIRM_REMOVE_ALL_TAGS, DOWNLOAD_TRACKER_FAVICON, SAVE_PATH_HISTORY_LENGTH, + ENABLE_SPEED_WIDGET, #if (defined(Q_OS_UNIX) && !defined(Q_OS_MAC)) USE_ICON_THEME, #endif @@ -218,6 +219,7 @@ void AdvancedSettings::saveAdvancedSettings() // Misc GUI properties mainWindow->setDownloadTrackerFavicon(checkBoxTrackerFavicon.isChecked()); AddNewTorrentDialog::setSavePathHistoryLength(spinBoxSavePathHistoryLength.value()); + pref->setSpeedWidgetEnabled(checkBoxSpeedWidgetEnabled.isChecked()); // Tracker session->setTrackerEnabled(checkBoxTrackerStatus.isChecked()); @@ -467,6 +469,9 @@ void AdvancedSettings::loadAdvancedSettings() spinBoxSavePathHistoryLength.setRange(AddNewTorrentDialog::minPathHistoryLength, AddNewTorrentDialog::maxPathHistoryLength); spinBoxSavePathHistoryLength.setValue(AddNewTorrentDialog::savePathHistoryLength()); addRow(SAVE_PATH_HISTORY_LENGTH, tr("Save path history length"), &spinBoxSavePathHistoryLength); + // Enable speed graphs + checkBoxSpeedWidgetEnabled.setChecked(pref->isSpeedWidgetEnabled()); + addRow(ENABLE_SPEED_WIDGET, tr("Enable speed graphs"), &checkBoxSpeedWidgetEnabled); // Tracker State checkBoxTrackerStatus.setChecked(session->isTrackerEnabled()); addRow(TRACKER_STATUS, tr("Enable embedded tracker"), &checkBoxTrackerStatus); diff --git a/src/gui/advancedsettings.h b/src/gui/advancedsettings.h index be3feffaf..b23318d7e 100644 --- a/src/gui/advancedsettings.h +++ b/src/gui/advancedsettings.h @@ -65,7 +65,7 @@ private: QCheckBox checkBoxOsCache, checkBoxRecheckCompleted, checkBoxResolveCountries, checkBoxResolveHosts, checkBoxSuperSeeding, checkBoxProgramNotifications, checkBoxTorrentAddedNotifications, checkBoxTrackerFavicon, checkBoxTrackerStatus, checkBoxConfirmTorrentRecheck, checkBoxConfirmRemoveAllTags, checkBoxListenIPv6, checkBoxAnnounceAllTrackers, checkBoxAnnounceAllTiers, - checkBoxGuidedReadCache, checkBoxMultiConnectionsPerIp, checkBoxSuggestMode, checkBoxCoalesceRW; + checkBoxGuidedReadCache, checkBoxMultiConnectionsPerIp, checkBoxSuggestMode, checkBoxCoalesceRW, checkBoxSpeedWidgetEnabled; QComboBox comboBoxInterface, comboBoxInterfaceAddress, comboBoxUtpMixedMode, comboBoxChokingAlgorithm, comboBoxSeedChokingAlgorithm; QLineEdit lineEditAnnounceIP; diff --git a/src/gui/properties/propertieswidget.cpp b/src/gui/properties/propertieswidget.cpp index 99dff149d..5e8e16dbb 100644 --- a/src/gui/properties/propertieswidget.cpp +++ b/src/gui/properties/propertieswidget.cpp @@ -140,9 +140,6 @@ PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow *mainWindow, Tran // Peers list m_peerList = new PeerListWidget(this); m_ui->vBoxLayoutPeerPage->addWidget(m_peerList); - // Speed widget - m_speedWidget = new SpeedWidget(this); - m_ui->speedLayout->addWidget(m_speedWidget); // Tab bar m_tabBar = new PropTabBar(); m_tabBar->setContentsMargins(0, 5, 0, 0); @@ -164,6 +161,9 @@ PropertiesWidget::PropertiesWidget(QWidget *parent, MainWindow *mainWindow, Tran connect(m_deleteHotkeyWeb, &QShortcut::activated, this, &PropertiesWidget::deleteSelectedUrlSeeds); m_openHotkeyFile = new QShortcut(Qt::Key_Return, m_ui->filesList, nullptr, nullptr, Qt::WidgetShortcut); connect(m_openHotkeyFile, &QShortcut::activated, this, &PropertiesWidget::openSelectedFile); + + configure(); + connect(Preferences::instance(), &Preferences::changed, this, &PropertiesWidget::configure); } PropertiesWidget::~PropertiesWidget() @@ -288,11 +288,6 @@ QTreeView *PropertiesWidget::getFilesList() const return m_ui->filesList; } -SpeedWidget *PropertiesWidget::getSpeedWidget() const -{ - return m_speedWidget; -} - void PropertiesWidget::updateSavePath(BitTorrent::TorrentHandle *const torrent) { if (torrent == m_torrent) @@ -800,6 +795,29 @@ void PropertiesWidget::openSelectedFile() openDoubleClickedFile(selectedIndexes.first()); } +void PropertiesWidget::configure() +{ + // Speed widget + if (Preferences::instance()->isSpeedWidgetEnabled()) { + if (!m_speedWidget || !qobject_cast(m_speedWidget)) { + m_ui->speedLayout->removeWidget(m_speedWidget); + delete m_speedWidget; + m_speedWidget = new SpeedWidget {this}; + m_ui->speedLayout->addWidget(m_speedWidget); + } + } + else { + if (!m_speedWidget || !qobject_cast(m_speedWidget)) { + m_ui->speedLayout->removeWidget(m_speedWidget); + delete m_speedWidget; + auto *label = new QLabel(tr("
Speed graphs are disabled

You may change this setting in Advanced Options

"), this); + label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter); + m_speedWidget = label; + m_ui->speedLayout->addWidget(m_speedWidget); + } + } +} + void PropertiesWidget::askWebSeed() { bool ok; diff --git a/src/gui/properties/propertieswidget.h b/src/gui/properties/propertieswidget.h index fc7ef72ac..0da16226d 100644 --- a/src/gui/properties/propertieswidget.h +++ b/src/gui/properties/propertieswidget.h @@ -75,7 +75,6 @@ public: TrackerListWidget *getTrackerList() const; PeerListWidget *getPeerList() const; QTreeView *getFilesList() const; - SpeedWidget *getSpeedWidget() const; public slots: void setVisibility(bool visible); @@ -108,6 +107,7 @@ protected slots: void openSelectedFile(); private slots: + void configure(); void filterText(const QString &filter); void updateSavePath(BitTorrent::TorrentHandle *const torrent); @@ -125,7 +125,7 @@ private: PropListDelegate *m_propListDelegate; PeerListWidget *m_peerList; TrackerListWidget *m_trackerList; - SpeedWidget *m_speedWidget; + QWidget *m_speedWidget = nullptr; QList m_slideSizes; DownloadedPiecesBar *m_downloadedPieces; PieceAvailabilityBar *m_piecesAvailability;