From 01549a3040da4c4e6931654ab91017283f0552a7 Mon Sep 17 00:00:00 2001 From: Jaquee Date: Sun, 27 Nov 2016 00:16:09 +0100 Subject: [PATCH] walletManager: coding conventions Signed-off-by: Jaquee --- main.cpp | 6 ++---- src/daemon/DaemonManager.cpp | 27 +++++++++++++-------------- src/daemon/DaemonManager.h | 4 ++-- src/libwalletqt/Wallet.cpp | 6 +++--- src/libwalletqt/Wallet.h | 8 ++++---- 5 files changed, 24 insertions(+), 27 deletions(-) diff --git a/main.cpp b/main.cpp index 4bc71a53..e9ea5a56 100644 --- a/main.cpp +++ b/main.cpp @@ -108,10 +108,8 @@ int main(int argc, char *argv[]) engine.rootContext()->setContextProperty("translationManager", TranslationManager::instance()); engine.addImageProvider(QLatin1String("qrcode"), new QRCodeImageProvider()); - - engine.rootContext()->setContextProperty("daemonManager", DaemonManager::instance(QCoreApplication::arguments())); - - DaemonManager * daemonManager = DaemonManager::instance(QCoreApplication::arguments()); + const QStringList arguments = QCoreApplication::arguments(); + DaemonManager * daemonManager = DaemonManager::instance(&arguments); QObject::connect(&app, SIGNAL(aboutToQuit()), daemonManager, SLOT(closing())); engine.rootContext()->setContextProperty("daemonManager", daemonManager); diff --git a/src/daemon/DaemonManager.cpp b/src/daemon/DaemonManager.cpp index b84a0fa2..185cde1e 100644 --- a/src/daemon/DaemonManager.cpp +++ b/src/daemon/DaemonManager.cpp @@ -9,15 +9,15 @@ #include DaemonManager * DaemonManager::m_instance = nullptr; -QStringList DaemonManager::clArgs; +QStringList DaemonManager::m_clArgs; -DaemonManager *DaemonManager::instance(QStringList args) +DaemonManager *DaemonManager::instance(const QStringList *args) { if (!m_instance) { m_instance = new DaemonManager; // store command line arguments for later use - clArgs = args; - clArgs.removeFirst(); + m_clArgs = *args; + m_clArgs.removeFirst(); } return m_instance; @@ -25,7 +25,6 @@ DaemonManager *DaemonManager::instance(QStringList args) bool DaemonManager::start() { - // QString process; #ifdef Q_OS_WIN @@ -34,7 +33,7 @@ bool DaemonManager::start() process = QApplication::applicationDirPath() + "/monerod"; #endif - if(process.length() == 0) { + if (process.length() == 0) { qDebug() << "no daemon binary defined for current platform"; return false; } @@ -42,7 +41,7 @@ bool DaemonManager::start() // prepare command line arguments and pass to monerod QStringList arguments; - foreach (const QString &str, clArgs) { + foreach (const QString &str, m_clArgs) { qDebug() << QString(" [%1] ").arg(str); arguments << str; } @@ -64,7 +63,7 @@ bool DaemonManager::start() // add state changed listener connect(m_daemon,SIGNAL(stateChanged(QProcess::ProcessState)),this,SLOT(stateChanged(QProcess::ProcessState))); - if(!started){ + if (!started) { qDebug() << "Daemon start error: " + m_daemon->errorString(); } else { emit daemonStarted(); @@ -75,7 +74,7 @@ bool DaemonManager::start() bool DaemonManager::stop() { - if(initialized){ + if (initialized) { qDebug() << "stopping daemon"; // we can't use QProcess::terminate() on windows console process // write exit command to stdin @@ -88,7 +87,7 @@ bool DaemonManager::stop() void DaemonManager::stateChanged(QProcess::ProcessState state) { qDebug() << "STATE CHANGED: " << state; - if(state == QProcess::NotRunning) { + if (state == QProcess::NotRunning) { emit daemonStopped(); } } @@ -98,7 +97,7 @@ void DaemonManager::printOutput() QByteArray byteArray = m_daemon->readAllStandardOutput(); QStringList strLines = QString(byteArray).split("\n"); - foreach (QString line, strLines){ + foreach (QString line, strLines) { emit daemonConsoleUpdated(line); qDebug() << "Daemon: " + line; } @@ -109,7 +108,7 @@ void DaemonManager::printError() QByteArray byteArray = m_daemon->readAllStandardError(); QStringList strLines = QString(byteArray).split("\n"); - foreach (QString line, strLines){ + foreach (QString line, strLines) { emit daemonConsoleUpdated(line); qDebug() << "Daemon ERROR: " + line; } @@ -117,7 +116,7 @@ void DaemonManager::printError() bool DaemonManager::running() const { - if(initialized){ + if (initialized) { qDebug() << m_daemon->state(); qDebug() << QProcess::NotRunning; // m_daemon->write("status\n"); @@ -137,7 +136,7 @@ void DaemonManager::closing() qDebug() << __FUNCTION__; stop(); // Wait for daemon to stop before exiting (max 10 secs) - if(initialized){ + if (initialized) { m_daemon->waitForFinished(10000); } } diff --git a/src/daemon/DaemonManager.h b/src/daemon/DaemonManager.h index 1c4ae8ad..8f425fd5 100644 --- a/src/daemon/DaemonManager.h +++ b/src/daemon/DaemonManager.h @@ -11,7 +11,7 @@ class DaemonManager : public QObject public: - static DaemonManager * instance(QStringList args); + static DaemonManager * instance(const QStringList *args); Q_INVOKABLE bool start(); Q_INVOKABLE bool stop(); @@ -34,7 +34,7 @@ private: explicit DaemonManager(QObject *parent = 0); static DaemonManager * m_instance; - static QStringList clArgs; + static QStringList m_clArgs; QProcess *m_daemon; bool initialized = false; diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index c1c1b8e8..bc72cc1a 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -88,13 +88,13 @@ Wallet::Status Wallet::status() const return static_cast(m_walletImpl->status()); } -Wallet::ConnectionStatus Wallet::connected() +Wallet::ConnectionStatus Wallet::connected() const { // cache connection status - if(!m_initialized || m_connectionStatusTime.elapsed() / 1000 > m_connectionStatusTtl){ + if (!m_initialized || m_connectionStatusTime.elapsed() / 1000 > m_connectionStatusTtl) { m_initialized = true; ConnectionStatus newStatus = static_cast(m_walletImpl->connected()); - if(newStatus != m_connectionStatus) { + if (newStatus != m_connectionStatus) { m_connectionStatus = newStatus; emit connectionStatusChanged(); } diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index 8b1d7525..3289bb37 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -63,7 +63,7 @@ public: Status status() const; //! returns whether the wallet is connected, and version status - ConnectionStatus connected(); + ConnectionStatus connected() const; //! returns true if wallet was ever synchronized bool synchronized() const; @@ -196,7 +196,7 @@ signals: // emitted when transaction is created async void transactionCreated(PendingTransaction * transaction, QString address, QString paymentId, quint32 mixinCount); - void connectionStatusChanged(); + void connectionStatusChanged() const; private: Wallet(QObject * parent = nullptr); @@ -219,10 +219,10 @@ private: mutable QTime m_daemonBlockChainTargetHeightTime; mutable quint64 m_daemonBlockChainTargetHeight; int m_daemonBlockChainTargetHeightTtl; - ConnectionStatus m_connectionStatus; + mutable ConnectionStatus m_connectionStatus; int m_connectionStatusTtl; mutable QTime m_connectionStatusTime; - bool m_initialized; + mutable bool m_initialized; };