Browse Source

Show syncing status in statusbar

import_zecw
bdr 6 years ago
parent
commit
5859c3669b
  1. 55
      src/rpc.cpp
  2. 11
      src/settings.cpp
  3. 4
      src/settings.h

55
src/rpc.cpp

@ -280,6 +280,7 @@ void RPC::refresh() {
getInfoThenRefresh();
}
void RPC::getInfoThenRefresh() {
json payload = {
{"jsonrpc", "1.0"},
@ -287,26 +288,40 @@ void RPC::getInfoThenRefresh() {
{"method", "getinfo"}
};
doRPC(payload, [=] (const json& reply) {
// Testnet?
if (reply.find("testnet") != reply.end()) {
Settings::getInstance()->setTestnet(reply["testnet"].get<json::boolean_t>());
};
// Connected?
QString statusText = QString() %
"Connected (" %
(Settings::getInstance()->isTestnet() ? "testnet:" : "mainnet:") %
QString::number(reply["blocks"].get<json::number_unsigned_t>()) %
")";
main->statusLabel->setText(statusText);
QIcon i(":/icons/res/connected.png");
main->statusIcon->setPixmap(i.pixmap(16, 16));
// Refresh everything.
refreshBalances();
refreshTransactions();
refreshAddresses();
doRPC(payload, [=] (const json& reply) {
// Testnet?
if (reply.find("testnet") != reply.end()) {
Settings::getInstance()->setTestnet(reply["testnet"].get<json::boolean_t>());
};
// Connected, so display checkmark.
QIcon i(":/icons/res/connected.png");
main->statusIcon->setPixmap(i.pixmap(16, 16));
// Refresh everything.
refreshBalances();
refreshTransactions();
refreshAddresses();
// 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);
});
});
}

11
src/settings.cpp

@ -12,9 +12,10 @@ Settings* Settings::init() {
// Load from settings first, because if they are redefined in the zcash.conf file,
// we'll overwrite them.
instance->loadFromSettings();
#ifdef Q_OS_LINUX
// Overwrite if any are defined in the zcash.conf
instance->loadFromFile();
#endif
return instance;
}
@ -97,4 +98,12 @@ bool Settings::isTestnet() {
void Settings::setTestnet(bool isTestnet) {
this->_isTestnet = isTestnet;
}
bool Settings::isSyncing() {
return _isSyncing;
}
void Settings::setSyncing(bool syncing) {
this->_isSyncing = syncing;
}

4
src/settings.h

@ -22,6 +22,9 @@ public:
bool isTestnet();
void setTestnet(bool isTestnet);
bool isSyncing();
void setSyncing(bool syncing);
private:
// This class can only be accessed through Settings::getInstance()
Settings() = default;
@ -36,6 +39,7 @@ private:
QString overridePort;
bool _isTestnet = false;
bool _isSyncing = false;
};
#endif // SETTINGS_H
Loading…
Cancel
Save