From b8db796479c7becd1987299993b47161666f5cf9 Mon Sep 17 00:00:00 2001 From: tobtoht Date: Tue, 15 Mar 2022 13:36:20 +0100 Subject: [PATCH] Disable various tabs when websocket is disabled --- src/MainWindow.cpp | 18 ++++++++++++++++++ src/MainWindow.h | 1 + src/SettingsDialog.cpp | 20 +++++++++++--------- src/SettingsDialog.h | 1 + src/WindowManager.cpp | 4 ++++ src/WindowManager.h | 2 ++ src/widgets/NodeWidget.cpp | 9 +++++++++ src/widgets/NodeWidget.h | 1 + src/widgets/XMRigWidget.cpp | 4 ++++ src/widgets/XMRigWidget.h | 1 + 10 files changed, 52 insertions(+), 9 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index ab75aec..f509cc7 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -68,6 +68,9 @@ MainWindow::MainWindow(WindowManager *windowManager, Wallet *wallet, QWidget *pa #endif websocketNotifier()->emitCache(); // Get cached data + connect(m_windowManager, &WindowManager::websocketStatusChanged, this, &MainWindow::onWebsocketStatusChanged); + this->onWebsocketStatusChanged(!config()->get(Config::disableWebsocket).toBool()); + connect(m_windowManager, &WindowManager::torSettingsChanged, m_ctx.get(), &AppContext::onTorSettingsChanged); connect(torManager(), &TorManager::connectionStateChanged, this, &MainWindow::onTorConnectionStateChanged); this->onTorConnectionStateChanged(torManager()->torConnected); @@ -540,6 +543,20 @@ void MainWindow::tryStoreWallet() { m_ctx->wallet->store(); } +void MainWindow::onWebsocketStatusChanged(bool enabled) { + ui->actionShow_Home->setVisible(enabled); + ui->actionShow_calc->setVisible(enabled); + ui->actionShow_Exchange->setVisible(enabled); + + ui->tabWidget->setTabVisible(Tabs::HOME, enabled && config()->get(Config::showTabHome).toBool()); + ui->tabWidget->setTabVisible(Tabs::CALC, enabled && config()->get(Config::showTabCalc).toBool()); + ui->tabWidget->setTabVisible(Tabs::EXCHANGES, enabled && config()->get(Config::showTabExchange).toBool()); + +#ifdef HAS_XMRIG + m_xmrig->setDownloadsTabEnabled(enabled); +#endif +} + void MainWindow::onSynchronized() { this->updateNetStats(); this->setStatusText("Synchronized"); @@ -828,6 +845,7 @@ void MainWindow::menuSettingsClicked() { connect(&settings, &Settings::preferredFiatCurrencyChanged, m_balanceTickerWidget, &BalanceTickerWidget::updateDisplay); connect(&settings, &Settings::preferredFiatCurrencyChanged, m_sendWidget, QOverload<>::of(&SendWidget::onPreferredFiatCurrencyChanged)); connect(&settings, &Settings::skinChanged, this, &MainWindow::skinChanged); + connect(&settings, &Settings::websocketStatusChanged, m_windowManager, &WindowManager::onWebsocketStatusChanged); settings.exec(); } diff --git a/src/MainWindow.h b/src/MainWindow.h index 49c668a..a8b3464 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -182,6 +182,7 @@ private slots: void onUpdatesAvailable(const QJsonObject &updates); void toggleSearchbar(bool enabled); void tryStoreWallet(); + void onWebsocketStatusChanged(bool enabled); private: friend WindowManager; diff --git a/src/SettingsDialog.cpp b/src/SettingsDialog.cpp index c4f244d..569f13f 100644 --- a/src/SettingsDialog.cpp +++ b/src/SettingsDialog.cpp @@ -94,14 +94,6 @@ void Settings::setupGeneralTab() { // [Balance display] ui->comboBox_balanceDisplay->setCurrentIndex(config()->get(Config::balanceDisplay).toInt()); connect(ui->comboBox_balanceDisplay, QOverload::of(&QComboBox::currentIndexChanged), this, &Settings::comboBox_balanceDisplayChanged); - - // [Offline mode] - ui->checkBox_offlineMode->setChecked(config()->get(Config::offlineMode).toBool()); - connect(ui->checkBox_offlineMode, &QCheckBox::toggled, [this](bool checked){ - config()->set(Config::offlineMode, checked); - m_ctx->wallet->setOffline(checked); - this->enableWebsocket(checked); - }); } void Settings::setupPrivacyTab() { @@ -129,7 +121,7 @@ void Settings::setupPrivacyTab() { ui->checkBox_disableWebsocket->setChecked(config()->get(Config::disableWebsocket).toBool()); connect(ui->checkBox_disableWebsocket, &QCheckBox::toggled, [this](bool checked){ config()->set(Config::disableWebsocket, checked); - this->enableWebsocket(checked); + this->enableWebsocket(!checked); }); // [Do not write log files to disk] @@ -148,6 +140,14 @@ void Settings::setupPrivacyTab() { connect(ui->spinBox_inactivityLockTimeout, QOverload::of(&QSpinBox::valueChanged), [](int value){ config()->set(Config::inactivityLockTimeout, value); }); + + // [Offline mode] + ui->checkBox_offlineMode->setChecked(config()->get(Config::offlineMode).toBool()); + connect(ui->checkBox_offlineMode, &QCheckBox::toggled, [this](bool checked){ + config()->set(Config::offlineMode, checked); + m_ctx->wallet->setOffline(checked); + this->enableWebsocket(!checked); + }); } void Settings::setupNodeTab() { @@ -261,6 +261,8 @@ void Settings::enableWebsocket(bool enabled) { } else { websocketNotifier()->websocketClient.stop(); } + ui->nodeWidget->onWebsocketStatusChanged(); + emit websocketStatusChanged(enabled); } Settings::~Settings() = default; \ No newline at end of file diff --git a/src/SettingsDialog.h b/src/SettingsDialog.h index 2997b28..d6342f8 100644 --- a/src/SettingsDialog.h +++ b/src/SettingsDialog.h @@ -28,6 +28,7 @@ signals: void skinChanged(QString skinName); void blockExplorerChanged(QString blockExplorer); void amountPrecisionChanged(int precision); + void websocketStatusChanged(bool enabled); public slots: void checkboxExternalLinkWarn(); diff --git a/src/WindowManager.cpp b/src/WindowManager.cpp index a76c130..3cede76 100644 --- a/src/WindowManager.cpp +++ b/src/WindowManager.cpp @@ -522,6 +522,10 @@ void WindowManager::onTorSettingsChanged() { emit torSettingsChanged(); } +void WindowManager::onWebsocketStatusChanged(bool enabled) { + emit websocketStatusChanged(enabled); +} + void WindowManager::initWS() { if (config()->get(Config::offlineMode).toBool()) { return; diff --git a/src/WindowManager.h b/src/WindowManager.h index d7a0ee2..3eca7f3 100644 --- a/src/WindowManager.h +++ b/src/WindowManager.h @@ -32,9 +32,11 @@ public: signals: void torSettingsChanged(); + void websocketStatusChanged(bool enabled); public slots: void onTorSettingsChanged(); + void onWebsocketStatusChanged(bool enabled); void tryOpenWallet(const QString &path, const QString &password); private slots: diff --git a/src/widgets/NodeWidget.cpp b/src/widgets/NodeWidget.cpp index 4371786..3b99b7a 100644 --- a/src/widgets/NodeWidget.cpp +++ b/src/widgets/NodeWidget.cpp @@ -47,6 +47,8 @@ NodeWidget::NodeWidget(QWidget *parent) connect(ui->customView, &QTreeView::doubleClicked, this, &NodeWidget::onContextConnect); connect(ui->wsView, &QTreeView::doubleClicked, this, &NodeWidget::onContextConnect); + + this->onWebsocketStatusChanged(); } void NodeWidget::onShowWSContextMenu(const QPoint &pos) { @@ -65,6 +67,13 @@ void NodeWidget::onShowCustomContextMenu(const QPoint &pos) { this->showContextMenu(pos, node); } +void NodeWidget::onWebsocketStatusChanged() { + bool disabled = config()->get(Config::disableWebsocket).toBool() || config()->get(Config::offlineMode).toBool(); + QString labelText = disabled ? "From cached list" : "From websocket (recommended)"; + ui->radioButton_websocket->setText(labelText); + ui->wsView->setColumnHidden(1, disabled); +} + void NodeWidget::showContextMenu(const QPoint &pos, const FeatherNode &node) { QMenu menu(this); diff --git a/src/widgets/NodeWidget.h b/src/widgets/NodeWidget.h index a851b31..b667cc2 100644 --- a/src/widgets/NodeWidget.h +++ b/src/widgets/NodeWidget.h @@ -33,6 +33,7 @@ public slots: void onCustomAddClicked(); void onShowWSContextMenu(const QPoint &pos); void onShowCustomContextMenu(const QPoint &pos); + void onWebsocketStatusChanged(); private slots: void onContextConnect(); diff --git a/src/widgets/XMRigWidget.cpp b/src/widgets/XMRigWidget.cpp index 400f043..22d9ef1 100644 --- a/src/widgets/XMRigWidget.cpp +++ b/src/widgets/XMRigWidget.cpp @@ -134,6 +134,10 @@ bool XMRigWidget::isMining() { return m_isMining; } +void XMRigWidget::setDownloadsTabEnabled(bool enabled) { + ui->tabWidget->setTabVisible(2, enabled); +} + void XMRigWidget::onWalletClosed() { this->onStopClicked(); } diff --git a/src/widgets/XMRigWidget.h b/src/widgets/XMRigWidget.h index c04c276..aa69d9d 100644 --- a/src/widgets/XMRigWidget.h +++ b/src/widgets/XMRigWidget.h @@ -26,6 +26,7 @@ public: QStandardItemModel *model(); bool isMining(); + void setDownloadsTabEnabled(bool enabled); public slots: void onWalletClosed();