Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/qt/clientmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions src/qt/clientmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 20 additions & 1 deletion src/qt/pivx/settings/settingsinformationwidget.cpp
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -14,6 +14,8 @@

#include <QDir>

#define REQUEST_UPDATE_MN_COUNT 0

SettingsInformationWidget::SettingsInformationWidget(PIVXGUI* _window,QWidget *parent) :
PWidget(_window,parent),
ui(new Ui::SettingsInformationWidget)
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions src/qt/pivx/settings/settingsinformationwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down