From bce496b8d13c6a303d8e20ffbf2497cf9e532430 Mon Sep 17 00:00:00 2001 From: Jaquee Date: Wed, 1 Mar 2017 22:03:50 +0100 Subject: [PATCH] confirm daemon running on exit --- MainApp.cpp | 14 ++++++++++++++ MainApp.h | 18 ++++++++++++++++++ components/StandardDialog.qml | 3 +++ main.cpp | 6 ++++-- main.qml | 33 +++++++++++++++++++++++++++++++++ monero-wallet-gui.pro | 6 ++++-- 6 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 MainApp.cpp create mode 100644 MainApp.h diff --git a/MainApp.cpp b/MainApp.cpp new file mode 100644 index 00000000..4c10cad0 --- /dev/null +++ b/MainApp.cpp @@ -0,0 +1,14 @@ +#include "MainApp.h" +#include + +bool MainApp::event (QEvent *event) +{ + // Catch application exit event and signal to qml app to handle exit + if(event->type() == QEvent::Close) { + event->ignore(); + emit closing(); + return true; + } + + return false; +} diff --git a/MainApp.h b/MainApp.h new file mode 100644 index 00000000..95bfb5dc --- /dev/null +++ b/MainApp.h @@ -0,0 +1,18 @@ +#ifndef MAINAPP_H +#define MAINAPP_H +#include + +class MainApp : public QApplication +{ + Q_OBJECT +public: + MainApp(int &argc, char** argv) : QApplication(argc, argv) {}; +private: + bool event(QEvent *e); +signals: + void closing(); +}; + +#endif // MAINAPP_H + + diff --git a/components/StandardDialog.qml b/components/StandardDialog.qml index 03c64a64..3546de24 100644 --- a/components/StandardDialog.qml +++ b/components/StandardDialog.qml @@ -45,6 +45,9 @@ Window { property alias cancelVisible: cancelButton.visible property alias okVisible: okButton.visible property alias textArea: dialogContent + property alias okText: okButton.text + property alias cancelText: cancelButton.text + property var icon // same signals as Dialog has diff --git a/main.cpp b/main.cpp index 53ab4752..ed0da185 100644 --- a/main.cpp +++ b/main.cpp @@ -50,6 +50,7 @@ #include "AddressBook.h" #include "model/AddressBookModel.h" #include "wallet/wallet2_api.h" +#include "MainApp.h" // IOS exclusions #ifndef Q_OS_IOS @@ -74,7 +75,7 @@ int main(int argc, char *argv[]) Monero::Wallet::init(argv[0], "monero-wallet-gui"); qInstallMessageHandler(messageHandler); - QApplication app(argc, argv); + MainApp app(argc, argv); qDebug() << "app startd"; @@ -146,6 +147,8 @@ int main(int argc, char *argv[]) engine.addImageProvider(QLatin1String("qrcode"), new QRCodeImageProvider()); const QStringList arguments = QCoreApplication::arguments(); + engine.rootContext()->setContextProperty("mainApp", &app); + // Exclude daemon manager from IOS #ifndef Q_OS_IOS DaemonManager * daemonManager = DaemonManager::instance(&arguments); @@ -210,4 +213,3 @@ int main(int argc, char *argv[]) return app.exec(); } - diff --git a/main.qml b/main.qml index 2713fb23..94a099ac 100644 --- a/main.qml +++ b/main.qml @@ -686,6 +686,7 @@ ApplicationWindow { informationPopup.title = qsTr("Error") + translationManager.emptyString; informationPopup.text = "internal error"; informationPopup.icon = StandardIcon.Critical + informationPopup.onCloseCallback = null informationPopup.open() return } @@ -792,6 +793,9 @@ ApplicationWindow { daemonManager.daemonStartFailure.connect(onDaemonStartFailure); daemonManager.daemonStopped.connect(onDaemonStopped); + // Connect app exit to qml window exit handling + mainApp.closing.connect(appWindow.close); + if(!walletsFound()) { rootItem.state = "wizard" } else { @@ -1249,10 +1253,39 @@ ApplicationWindow { id: notifier } } + onClosing: { + + // If daemon is running - prompt user before exiting + if(typeof daemonManager != undefined && daemonManager.running(persistentSettings.testnet)) { + close.accepted = false; + + // Show confirmation dialog + confirmationDialog.title = qsTr("Daemon is running") + translationManager.emptyString; + confirmationDialog.text = qsTr("Daemon will still be running in background when GUI is closed."); + confirmationDialog.icon = StandardIcon.Question + confirmationDialog.cancelText = qsTr("Stop daemon") + confirmationDialog.onAcceptedCallback = function() { + closeAccepted(); + } + + confirmationDialog.onRejectedCallback = function() { + daemonManager.stop(persistentSettings.testnet); + closeAccepted(); + }; + + confirmationDialog.open() + + } else { + closeAccepted(); + } + } + + function closeAccepted(){ // Close wallet non async on exit daemonManager.exit(); walletManager.closeWallet(); + Qt.quit(); } function checkUpdates() { diff --git a/monero-wallet-gui.pro b/monero-wallet-gui.pro index 8990b69e..533ed087 100644 --- a/monero-wallet-gui.pro +++ b/monero-wallet-gui.pro @@ -38,7 +38,8 @@ HEADERS += \ src/libwalletqt/AddressBook.h \ src/zxcvbn-c/zxcvbn.h \ src/libwalletqt/UnsignedTransaction.h \ - src/QR-Code-scanner/QrCodeScanner.h + src/QR-Code-scanner/QrCodeScanner.h \ + MainApp.h SOURCES += main.cpp \ filter.cpp \ @@ -61,7 +62,8 @@ SOURCES += main.cpp \ src/libwalletqt/AddressBook.cpp \ src/zxcvbn-c/zxcvbn.c \ src/libwalletqt/UnsignedTransaction.cpp \ - src/QR-Code-scanner/QrCodeScanner.cpp + src/QR-Code-scanner/QrCodeScanner.cpp \ + MainApp.cpp !ios { HEADERS += src/daemon/DaemonManager.h