From 164d6aa7ce3946e34f00d8993da81a3e6cd81953 Mon Sep 17 00:00:00 2001 From: furszy Date: Fri, 18 Dec 2020 11:26:14 -0300 Subject: [PATCH] GUI: settings information, fix missing initial masternodes count value. The count isn't updated on every widget show, only via the event. --- src/qt/clientmodel.cpp | 19 +++++++++++------ src/qt/clientmodel.h | 3 +++ .../settings/settingsinformationwidget.cpp | 21 ++++++++++++++++++- .../pivx/settings/settingsinformationwidget.h | 7 +++++-- 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp index 6756008e4a22..699a004ed5f6 100644 --- a/src/qt/clientmodel.cpp +++ b/src/qt/clientmodel.cpp @@ -83,6 +83,17 @@ QString ClientModel::getMasternodeCountString() const return tr("Total: %1 (IPv4: %2 / IPv6: %3 / Tor: %4 / Unknown: %5)").arg(QString::number(total)).arg(QString::number((int)ipv4)).arg(QString::number((int)ipv6)).arg(QString::number((int)onion)).arg(QString::number((int)nUnknown)); } +QString ClientModel::getMasternodesCount() +{ + if (!cachedMasternodeCountString.isEmpty()) { + return cachedMasternodeCountString; + } + + // Force an update + cachedMasternodeCountString = getMasternodeCountString(); + return cachedMasternodeCountString; +} + int ClientModel::getNumBlocks() { if (!cacheTip) { @@ -139,12 +150,8 @@ void ClientModel::updateTimer() void ClientModel::updateMnTimer() { - // Get required lock upfront. This avoids the GUI from getting stuck on - // periodical polls if the core is holding the locks for a longer time - - // for example, during a wallet rescan. - TRY_LOCK(cs_main, lockMain); - if (!lockMain) - return; + // Following method is locking the mnmanager mutex for now, + // future: move to an event based update. QString newMasternodeCountString = getMasternodeCountString(); if (cachedMasternodeCountString != newMasternodeCountString) { diff --git a/src/qt/clientmodel.h b/src/qt/clientmodel.h index 9940aeb40605..cc495f65b6ce 100644 --- a/src/qt/clientmodel.h +++ b/src/qt/clientmodel.h @@ -89,6 +89,9 @@ class ClientModel : public QObject // Start/Stop the masternode polling timer void startMasternodesTimer(); void stopMasternodesTimer(); + // Force a MN count update calling mnmanager directly locking its internal mutex. + // Future todo: implement an event based update and remove the lock requirement. + QString getMasternodesCount(); private: QString getMasternodeCountString() const; diff --git a/src/qt/pivx/settings/settingsinformationwidget.cpp b/src/qt/pivx/settings/settingsinformationwidget.cpp index 458d0441412c..af536782402e 100644 --- a/src/qt/pivx/settings/settingsinformationwidget.cpp +++ b/src/qt/pivx/settings/settingsinformationwidget.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2019-2020 The PIVX developers // Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. +// file COPYING or https://www.opensource.org/licenses/mit-license.php. #include "qt/pivx/settings/settingsinformationwidget.h" #include "qt/pivx/settings/forms/ui_settingsinformationwidget.h" @@ -14,6 +14,8 @@ #include +#define REQUEST_UPDATE_MN_COUNT 0 + SettingsInformationWidget::SettingsInformationWidget(PIVXGUI* _window,QWidget *parent) : PWidget(_window,parent), ui(new Ui::SettingsInformationWidget) @@ -165,6 +167,8 @@ void SettingsInformationWidget::showEvent(QShowEvent *event) QWidget::showEvent(event); if (clientModel) { clientModel->startMasternodesTimer(); + // Initial masternodes count value, running in a worker thread to not lock mnmanager mutex in the main thread. + execute(REQUEST_UPDATE_MN_COUNT); } } @@ -175,6 +179,21 @@ void SettingsInformationWidget::hideEvent(QHideEvent *event) { } } +void SettingsInformationWidget::run(int type) +{ + if (type == REQUEST_UPDATE_MN_COUNT) { + QMetaObject::invokeMethod(this, "setMasternodeCount", + Qt::QueuedConnection, Q_ARG(QString, clientModel->getMasternodesCount())); + } +} + +void SettingsInformationWidget::onError(QString error, int type) +{ + if (type == REQUEST_UPDATE_MN_COUNT) { + setMasternodeCount(tr("No available data")); + } +} + SettingsInformationWidget::~SettingsInformationWidget() { delete ui; diff --git a/src/qt/pivx/settings/settingsinformationwidget.h b/src/qt/pivx/settings/settingsinformationwidget.h index 5e071b9bdea4..c29caf8aed13 100644 --- a/src/qt/pivx/settings/settingsinformationwidget.h +++ b/src/qt/pivx/settings/settingsinformationwidget.h @@ -19,19 +19,22 @@ class SettingsInformationWidget : public PWidget public: explicit SettingsInformationWidget(PIVXGUI* _window, QWidget *parent = nullptr); - ~SettingsInformationWidget(); + ~SettingsInformationWidget() override; void loadClientModel() override; + void run(int type) override; + void onError(QString error, int type) override; + private Q_SLOTS: void setNumConnections(int count); void setNumBlocks(int count); - void setMasternodeCount(const QString& strMasternodes); void showEvent(QShowEvent* event) override; void hideEvent(QHideEvent* event) override; public Q_SLOTS: void openNetworkMonitor(); + void setMasternodeCount(const QString& strMasternodes); private: Ui::SettingsInformationWidget *ui;