Show syncing status in statusbar
This commit is contained in:
51
src/rpc.cpp
51
src/rpc.cpp
@@ -280,6 +280,7 @@ void RPC::refresh() {
|
|||||||
getInfoThenRefresh();
|
getInfoThenRefresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void RPC::getInfoThenRefresh() {
|
void RPC::getInfoThenRefresh() {
|
||||||
json payload = {
|
json payload = {
|
||||||
{"jsonrpc", "1.0"},
|
{"jsonrpc", "1.0"},
|
||||||
@@ -287,26 +288,40 @@ void RPC::getInfoThenRefresh() {
|
|||||||
{"method", "getinfo"}
|
{"method", "getinfo"}
|
||||||
};
|
};
|
||||||
|
|
||||||
doRPC(payload, [=] (const json& reply) {
|
doRPC(payload, [=] (const json& reply) {
|
||||||
// Testnet?
|
// Testnet?
|
||||||
if (reply.find("testnet") != reply.end()) {
|
if (reply.find("testnet") != reply.end()) {
|
||||||
Settings::getInstance()->setTestnet(reply["testnet"].get<json::boolean_t>());
|
Settings::getInstance()->setTestnet(reply["testnet"].get<json::boolean_t>());
|
||||||
};
|
};
|
||||||
|
|
||||||
// Connected?
|
// Connected, so display checkmark.
|
||||||
QString statusText = QString() %
|
QIcon i(":/icons/res/connected.png");
|
||||||
"Connected (" %
|
main->statusIcon->setPixmap(i.pixmap(16, 16));
|
||||||
(Settings::getInstance()->isTestnet() ? "testnet:" : "mainnet:") %
|
|
||||||
QString::number(reply["blocks"].get<json::number_unsigned_t>()) %
|
// Refresh everything.
|
||||||
")";
|
refreshBalances();
|
||||||
main->statusLabel->setText(statusText);
|
refreshTransactions();
|
||||||
QIcon i(":/icons/res/connected.png");
|
refreshAddresses();
|
||||||
main->statusIcon->setPixmap(i.pixmap(16, 16));
|
|
||||||
|
// Call to see if the blockchain is syncing.
|
||||||
|
json payload = {
|
||||||
|
{"jsonrpc", "1.0"},
|
||||||
|
{"id", "someid"},
|
||||||
|
{"method", "getblockchaininfo"}
|
||||||
|
};
|
||||||
|
|
||||||
|
doRPC(payload, [=](const json& reply) {
|
||||||
|
double progress = reply["verificationprogress"].get<double>();
|
||||||
|
QString statusText = QString() %
|
||||||
|
(progress < 0.99 ? "Syncing" : "Connected") %
|
||||||
|
" (" %
|
||||||
|
(Settings::getInstance()->isTestnet() ? "testnet:" : "") %
|
||||||
|
QString::number(reply["blocks"].get<json::number_unsigned_t>()) %
|
||||||
|
(progress < 0.99 ? ("/" % QString::number(progress*100, 'f', 0) % "%") : QString()) %
|
||||||
|
")";
|
||||||
|
main->statusLabel->setText(statusText);
|
||||||
|
});
|
||||||
|
|
||||||
// Refresh everything.
|
|
||||||
refreshBalances();
|
|
||||||
refreshTransactions();
|
|
||||||
refreshAddresses();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,9 +12,10 @@ Settings* Settings::init() {
|
|||||||
// Load from settings first, because if they are redefined in the zcash.conf file,
|
// Load from settings first, because if they are redefined in the zcash.conf file,
|
||||||
// we'll overwrite them.
|
// we'll overwrite them.
|
||||||
instance->loadFromSettings();
|
instance->loadFromSettings();
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
// Overwrite if any are defined in the zcash.conf
|
// Overwrite if any are defined in the zcash.conf
|
||||||
instance->loadFromFile();
|
instance->loadFromFile();
|
||||||
|
#endif
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,4 +98,12 @@ bool Settings::isTestnet() {
|
|||||||
|
|
||||||
void Settings::setTestnet(bool isTestnet) {
|
void Settings::setTestnet(bool isTestnet) {
|
||||||
this->_isTestnet = isTestnet;
|
this->_isTestnet = isTestnet;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Settings::isSyncing() {
|
||||||
|
return _isSyncing;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Settings::setSyncing(bool syncing) {
|
||||||
|
this->_isSyncing = syncing;
|
||||||
}
|
}
|
||||||
@@ -22,6 +22,9 @@ public:
|
|||||||
bool isTestnet();
|
bool isTestnet();
|
||||||
void setTestnet(bool isTestnet);
|
void setTestnet(bool isTestnet);
|
||||||
|
|
||||||
|
bool isSyncing();
|
||||||
|
void setSyncing(bool syncing);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// This class can only be accessed through Settings::getInstance()
|
// This class can only be accessed through Settings::getInstance()
|
||||||
Settings() = default;
|
Settings() = default;
|
||||||
@@ -36,6 +39,7 @@ private:
|
|||||||
QString overridePort;
|
QString overridePort;
|
||||||
|
|
||||||
bool _isTestnet = false;
|
bool _isTestnet = false;
|
||||||
|
bool _isSyncing = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SETTINGS_H
|
#endif // SETTINGS_H
|
||||||
Reference in New Issue
Block a user