From 48471f3407b8263f66254a39d693604de8894a38 Mon Sep 17 00:00:00 2001 From: Jaquee Date: Fri, 25 Nov 2016 21:09:32 +0100 Subject: [PATCH] onDaemonStarted/stopped signals/slots --- main.qml | 31 ++++++++++++++++++------------- src/daemon/DaemonManager.cpp | 11 +++++++++++ src/daemon/DaemonManager.h | 3 +-- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/main.qml b/main.qml index af027f5e..e9a36684 100644 --- a/main.qml +++ b/main.qml @@ -59,6 +59,7 @@ ApplicationWindow { property int restoreHeight:0 property bool daemonSynced: false property int maxWindowHeight: (Screen.height < 900)? 720 : 800; + property bool daemonRunning: false // true if wallet ever synchronized property bool walletInitialized : false @@ -292,6 +293,10 @@ ApplicationWindow { // TODO: implement onDaemonSynced or similar in wallet API and don't start refresh thread before daemon is synced daemonSynced = (currentWallet.connected != Wallet.ConnectionStatus_Disconnected && dCurrentBlock >= dTargetBlock) + // If wallet isnt connected and no daemon is running - Ask + if(!currentWallet.connected && !daemonManager.running() && !walletInitialized){ + daemonManagerDialog.open(); + } // Refresh is succesfull if blockchain height > 1 if (currentWallet.blockChainHeight() > 1){ @@ -317,22 +322,19 @@ ApplicationWindow { walletInitialized = true } - - - - // daemonManager.daemonConsole(); - // console.log("Daemon runnnig: ",daemonManager.running()); - - if(!daemonManager.running()){ - daemonManagerDialog.open(); - } - - - - onWalletUpdate(); } + function onDaemonStarted(){ + console.log("daemon started"); + daemonRunning = true; + } + function onDaemonStopped(){ + console.log("daemon stopped"); + daemonRunning = false; + } + + function onWalletNewBlock(blockHeight) { if (splash.visible) { var currHeight = blockHeight @@ -645,6 +647,9 @@ ApplicationWindow { walletManager.walletOpened.connect(onWalletOpened); walletManager.walletClosed.connect(onWalletClosed); + daemonManager.daemonStarted.connect(onDaemonStarted); + daemonManager.daemonStopped.connect(onDaemonStopped); + if(!walletsFound()) { rootItem.state = "wizard" } else { diff --git a/src/daemon/DaemonManager.cpp b/src/daemon/DaemonManager.cpp index 30ae06cd..a637d281 100644 --- a/src/daemon/DaemonManager.cpp +++ b/src/daemon/DaemonManager.cpp @@ -36,6 +36,8 @@ bool DaemonManager::start() if(!started){ qDebug() << "Daemon start error: " + m_daemon->errorString(); + } else { + emit daemonStarted(); } return started; @@ -43,6 +45,15 @@ bool DaemonManager::start() bool DaemonManager::stop() { + if(m_daemon){ + qDebug() << "stopping daemon"; + m_daemon->terminate(); + // Wait until stopped. Max 30 seconds + bool stopped = m_daemon->waitForFinished(30000); + if(stopped) emit daemonStopped(); + return stopped; + } + return true; } diff --git a/src/daemon/DaemonManager.h b/src/daemon/DaemonManager.h index 669f9119..b4170047 100644 --- a/src/daemon/DaemonManager.h +++ b/src/daemon/DaemonManager.h @@ -21,8 +21,7 @@ public: Q_INVOKABLE bool running() const; signals: - - void daemonStarted(const QProcess &d); + void daemonStarted(); void daemonStopped(); public slots: