Disable various tabs when websocket is disabled

This commit is contained in:
tobtoht 2022-03-15 13:36:20 +01:00
parent 15bed134af
commit b8db796479
No known key found for this signature in database
GPG key ID: 1CADD27F41F45C3C
10 changed files with 52 additions and 9 deletions

View file

@ -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();
}

View file

@ -182,6 +182,7 @@ private slots:
void onUpdatesAvailable(const QJsonObject &updates);
void toggleSearchbar(bool enabled);
void tryStoreWallet();
void onWebsocketStatusChanged(bool enabled);
private:
friend WindowManager;

View file

@ -94,14 +94,6 @@ void Settings::setupGeneralTab() {
// [Balance display]
ui->comboBox_balanceDisplay->setCurrentIndex(config()->get(Config::balanceDisplay).toInt());
connect(ui->comboBox_balanceDisplay, QOverload<int>::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<int>::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;

View file

@ -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();

View file

@ -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;

View file

@ -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:

View file

@ -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);

View file

@ -33,6 +33,7 @@ public slots:
void onCustomAddClicked();
void onShowWSContextMenu(const QPoint &pos);
void onShowCustomContextMenu(const QPoint &pos);
void onWebsocketStatusChanged();
private slots:
void onContextConnect();

View file

@ -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();
}

View file

@ -26,6 +26,7 @@ public:
QStandardItemModel *model();
bool isMining();
void setDownloadsTabEnabled(bool enabled);
public slots:
void onWalletClosed();