From b1a5d6ec696b5da4370f649f9d984dd95e8a2fb9 Mon Sep 17 00:00:00 2001 From: adityapk Date: Thu, 8 Nov 2018 14:05:59 -0800 Subject: [PATCH] Make startup window modal, other small fixes --- src/connection.cpp | 29 +++++++++++++++-------------- src/connection.h | 2 +- src/mainwindow.cpp | 14 +++++++------- src/mainwindow.ui | 12 ++++++------ src/rpc.cpp | 27 +++++++++++++-------------- src/rpc.h | 4 +--- 6 files changed, 43 insertions(+), 45 deletions(-) diff --git a/src/connection.cpp b/src/connection.cpp index 67bf1c1..527d517 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -16,13 +16,6 @@ ConnectionLoader::ConnectionLoader(MainWindow* main, RPC* rpc) { connD = new Ui_ConnectionDialog(); connD->setupUi(d); connD->topIcon->setBasePixmap(QIcon(":/icons/res/icon.ico").pixmap(256, 256)); - - // Center on screen - QRect screenGeometry = QApplication::desktop()->screenGeometry(d); - int x = (screenGeometry.width() - d->width()) / 2; - int y = (screenGeometry.height() - d->height()) / 2; - d->move(x, y); - } ConnectionLoader::~ConnectionLoader() { @@ -31,7 +24,11 @@ ConnectionLoader::~ConnectionLoader() { } void ConnectionLoader::loadConnection() { - d->show(); + QTimer::singleShot(1, [=]() { this->doAutoConnect(); }); + d->exec(); +} + +void ConnectionLoader::doAutoConnect() { // Priority 1: Try to connect to detect zcash.conf and connect to it. auto config = autoDetectZcashConf(); @@ -44,7 +41,7 @@ void ConnectionLoader::loadConnection() { this->showInformation("Starting Embedded zcashd"); if (this->startEmbeddedZcashd()) { // Embedded zcashd started up. Wait a second and then refresh the connection - QTimer::singleShot(1000, [=]() { loadConnection(); } ); + QTimer::singleShot(1000, [=]() { doAutoConnect(); } ); } else { // Errored out, show error and exit QString explanation = QString() % "Couldn't start the embedded zcashd.\n\n" % @@ -113,7 +110,7 @@ void ConnectionLoader::createZcashConf() { out << "rpcpassword=" % randomPassword() << "\n"; file.close(); - this->loadConnection(); + this->doAutoConnect(); }); } @@ -294,11 +291,13 @@ void ConnectionLoader::doManualConnect() { } void ConnectionLoader::doRPCSetConnection(Connection* conn) { - if (ezcashd != nullptr) { + if (ezcashd) { rpc->setEZcashd(ezcashd); } rpc->setConnection(conn); + d->accept(); + delete this; } @@ -367,10 +366,12 @@ void ConnectionLoader::showInformation(QString info, QString detail) { /** * Show error will close the loading dialog and show an error. */ -void ConnectionLoader::showError(QString explanation) { - d->hide(); - main->ui->statusBar->showMessage("Connection Error"); +void ConnectionLoader::showError(QString explanation) { + rpc->setEZcashd(nullptr); + rpc->noConnection(); + QMessageBox::critical(main, "Connection Error", explanation, QMessageBox::Ok); + d->close(); } QString ConnectionLoader::locateZcashConfFile() { diff --git a/src/connection.h b/src/connection.h index 95e157f..f416653 100644 --- a/src/connection.h +++ b/src/connection.h @@ -41,6 +41,7 @@ private: Connection* makeConnection(std::shared_ptr config); + void doAutoConnect(); void doManualConnect(); void createZcashConf(); @@ -53,7 +54,6 @@ private: bool startEmbeddedZcashd(); void refreshZcashdState(Connection* connection, std::function refused); - int getProgressFromStatus(QString status); void showError(QString explanation); void showInformation(QString info, QString detail = ""); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index fd489dd..505f209 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -373,13 +373,6 @@ void MainWindow::setupSettingsModal() { QIntValidator validator(0, 65535); settings.port->setValidator(&validator); - // Load current values into the dialog - auto conf = Settings::getInstance()->getSettings(); - settings.hostname->setText(conf.host); - settings.port->setText(conf.port); - settings.rpcuser->setText(conf.rpcuser); - settings.rpcpassword->setText(conf.rpcpassword); - // If values are coming from zcash.conf, then disable all the fields auto zcashConfLocation = Settings::getInstance()->getZcashdConfLocation(); if (!zcashConfLocation.isEmpty()) { @@ -390,6 +383,13 @@ void MainWindow::setupSettingsModal() { settings.rpcpassword->setEnabled(false); } else { + // Load current values into the dialog + auto conf = Settings::getInstance()->getSettings(); + settings.hostname->setText(conf.host); + settings.port->setText(conf.port); + settings.rpcuser->setText(conf.rpcuser); + settings.rpcpassword->setText(conf.rpcpassword); + settings.confMsg->setText("No local zcash.conf found. Please configure connection manually."); settings.hostname->setEnabled(true); settings.port->setEnabled(true); diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 3fc26f4..0a4aacd 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -316,8 +316,8 @@ 0 0 - 920 - 334 + 922 + 376 @@ -767,7 +767,7 @@ - TextLabel + Loading... @@ -781,7 +781,7 @@ - TextLabel + Loading... @@ -802,7 +802,7 @@ - TextLabel + Loading... @@ -864,7 +864,7 @@ 0 0 968 - 22 + 21 diff --git a/src/rpc.cpp b/src/rpc.cpp index 91d7876..20b521e 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp @@ -9,8 +9,8 @@ using json = nlohmann::json; RPC::RPC(MainWindow* main) { auto cl = new ConnectionLoader(main, this); - // Show a default no connection message until we can connect. - cl->loadConnection(); + // Execute the load connection async, so we can set up the rest of RPC properly. + QTimer::singleShot(1, [=]() {cl->loadConnection(); }); this->main = main; this->ui = main->ui; @@ -66,6 +66,9 @@ RPC::~RPC() { void RPC::setEZcashd(QProcess* p) { ezcashd = p; + + if (ezcashd == nullptr) + ui->tabWidget->removeTab(4); } void RPC::setConnection(Connection* c) { @@ -326,8 +329,10 @@ void RPC::fillTxJsonParams(json& params, Tx tx) { } -void RPC::noConnection() { - ui->statusBar->showMessage("No Connection to zcashd"); +void RPC::noConnection() { + QIcon i = QApplication::style()->standardIcon(QStyle::SP_MessageBoxCritical); + main->statusIcon->setPixmap(i.pixmap(16, 16)); + main->statusLabel->setText("No Connection"); } // Refresh received z txs by calling z_listreceivedbyaddress/gettransaction @@ -439,7 +444,6 @@ void RPC::refreshReceivedZTrans(QList zaddrs) { ); } - /// This will refresh all the balance data from zcashd void RPC::refresh(bool force) { if (conn == nullptr) @@ -482,7 +486,7 @@ void RPC::getInfoThenRefresh(bool force) { } // Get network sol/s - if (ezcashd != nullptr) { + if (ezcashd) { int conns = reply["connections"].get(); json payload = { @@ -498,11 +502,7 @@ void RPC::getInfoThenRefresh(bool force) { ui->numconnections->setText(QString::number(conns)); ui->solrate->setText(QString::number(solrate) % " Sol/s"); }); - } else { - qDebug() << "removing tab!"; - ui->tabWidget->removeTab(4); - } - + } // Call to see if the blockchain is syncing. json payload = { @@ -526,7 +526,7 @@ void RPC::getInfoThenRefresh(bool force) { qint64 estBlocks = (QDateTime::currentMSecsSinceEpoch() - genisisTimeMSec) / 2.5 / 60 / 1000; // Round to nearest 10 estBlocks = ((estBlocks + 5) / 10) * 10; - ui->blockheight->setText(ui->blockheight->text() % " / ~" % QString::number(estBlocks) % + ui->blockheight->setText(ui->blockheight->text() % /*" / ~" % QString::number(estBlocks) % */ " ( " % QString::number(progress * 100, 'f', 0) % "% )"); } @@ -871,11 +871,10 @@ void RPC::shutdownZcashd() { conn->doRPCWithDefaultErrorHandling(payload, [=](auto) {}); conn->shutdown(); - QMessageBox d(main); d.setIcon(QMessageBox::Icon::Information); d.setWindowTitle("Waiting for zcashd to exit"); - d.setText("Please wait for zcashd to exit. Don't click OK!"); + d.setText("Please wait for zcashd to exit."); d.setStandardButtons(QMessageBox::NoButton); QTimer waiter(main); diff --git a/src/rpc.h b/src/rpc.h index 6d2d8e9..958a733 100644 --- a/src/rpc.h +++ b/src/rpc.h @@ -59,16 +59,14 @@ public: void importTPrivKey(QString addr, bool rescan, const std::function& cb); void shutdownZcashd(); + void noConnection(); void getAllPrivKeys(const std::function>)>); Turnstile* getTurnstile() { return turnstile; } Connection* getConnection() { return conn; } - private: - void noConnection(); - void refreshBalances(); void refreshTransactions();