diff --git a/src/rpc.cpp b/src/rpc.cpp index 06ef8b5..7b7a62a 100644 --- a/src/rpc.cpp +++ b/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()); - }; + doRPC(payload, [=] (const json& reply) { + // Testnet? + if (reply.find("testnet") != reply.end()) { + Settings::getInstance()->setTestnet(reply["testnet"].get()); + }; - // Connected? - QString statusText = QString() % - "Connected (" % - (Settings::getInstance()->isTestnet() ? "testnet:" : "mainnet:") % - QString::number(reply["blocks"].get()) % - ")"; - main->statusLabel->setText(statusText); - QIcon i(":/icons/res/connected.png"); - main->statusIcon->setPixmap(i.pixmap(16, 16)); + // 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(); + QString statusText = QString() % + (progress < 0.99 ? "Syncing" : "Connected") % + " (" % + (Settings::getInstance()->isTestnet() ? "testnet:" : "") % + QString::number(reply["blocks"].get()) % + (progress < 0.99 ? ("/" % QString::number(progress*100, 'f', 0) % "%") : QString()) % + ")"; + main->statusLabel->setText(statusText); + }); - // Refresh everything. - refreshBalances(); - refreshTransactions(); - refreshAddresses(); }); } diff --git a/src/settings.cpp b/src/settings.cpp index 350c421..f638726 100644 --- a/src/settings.cpp +++ b/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; } \ No newline at end of file diff --git a/src/settings.h b/src/settings.h index 58e97a5..41d6625 100644 --- a/src/settings.h +++ b/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 \ No newline at end of file