mirror of
https://github.com/monero-project/monero-gui.git
synced 2024-12-23 20:20:02 +00:00
walletManager: coding conventions
Signed-off-by: Jaquee <jaquee.monero@gmail.com>
This commit is contained in:
parent
0ae3d67750
commit
01549a3040
5 changed files with 24 additions and 27 deletions
6
main.cpp
6
main.cpp
|
@ -108,10 +108,8 @@ int main(int argc, char *argv[])
|
||||||
engine.rootContext()->setContextProperty("translationManager", TranslationManager::instance());
|
engine.rootContext()->setContextProperty("translationManager", TranslationManager::instance());
|
||||||
|
|
||||||
engine.addImageProvider(QLatin1String("qrcode"), new QRCodeImageProvider());
|
engine.addImageProvider(QLatin1String("qrcode"), new QRCodeImageProvider());
|
||||||
|
const QStringList arguments = QCoreApplication::arguments();
|
||||||
engine.rootContext()->setContextProperty("daemonManager", DaemonManager::instance(QCoreApplication::arguments()));
|
DaemonManager * daemonManager = DaemonManager::instance(&arguments);
|
||||||
|
|
||||||
DaemonManager * daemonManager = DaemonManager::instance(QCoreApplication::arguments());
|
|
||||||
QObject::connect(&app, SIGNAL(aboutToQuit()), daemonManager, SLOT(closing()));
|
QObject::connect(&app, SIGNAL(aboutToQuit()), daemonManager, SLOT(closing()));
|
||||||
engine.rootContext()->setContextProperty("daemonManager", daemonManager);
|
engine.rootContext()->setContextProperty("daemonManager", daemonManager);
|
||||||
|
|
||||||
|
|
|
@ -9,15 +9,15 @@
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
|
||||||
DaemonManager * DaemonManager::m_instance = nullptr;
|
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) {
|
if (!m_instance) {
|
||||||
m_instance = new DaemonManager;
|
m_instance = new DaemonManager;
|
||||||
// store command line arguments for later use
|
// store command line arguments for later use
|
||||||
clArgs = args;
|
m_clArgs = *args;
|
||||||
clArgs.removeFirst();
|
m_clArgs.removeFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_instance;
|
return m_instance;
|
||||||
|
@ -25,7 +25,6 @@ DaemonManager *DaemonManager::instance(QStringList args)
|
||||||
|
|
||||||
bool DaemonManager::start()
|
bool DaemonManager::start()
|
||||||
{
|
{
|
||||||
|
|
||||||
//
|
//
|
||||||
QString process;
|
QString process;
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
|
@ -34,7 +33,7 @@ bool DaemonManager::start()
|
||||||
process = QApplication::applicationDirPath() + "/monerod";
|
process = QApplication::applicationDirPath() + "/monerod";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(process.length() == 0) {
|
if (process.length() == 0) {
|
||||||
qDebug() << "no daemon binary defined for current platform";
|
qDebug() << "no daemon binary defined for current platform";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -42,7 +41,7 @@ bool DaemonManager::start()
|
||||||
|
|
||||||
// prepare command line arguments and pass to monerod
|
// prepare command line arguments and pass to monerod
|
||||||
QStringList arguments;
|
QStringList arguments;
|
||||||
foreach (const QString &str, clArgs) {
|
foreach (const QString &str, m_clArgs) {
|
||||||
qDebug() << QString(" [%1] ").arg(str);
|
qDebug() << QString(" [%1] ").arg(str);
|
||||||
arguments << str;
|
arguments << str;
|
||||||
}
|
}
|
||||||
|
@ -64,7 +63,7 @@ bool DaemonManager::start()
|
||||||
// add state changed listener
|
// add state changed listener
|
||||||
connect(m_daemon,SIGNAL(stateChanged(QProcess::ProcessState)),this,SLOT(stateChanged(QProcess::ProcessState)));
|
connect(m_daemon,SIGNAL(stateChanged(QProcess::ProcessState)),this,SLOT(stateChanged(QProcess::ProcessState)));
|
||||||
|
|
||||||
if(!started){
|
if (!started) {
|
||||||
qDebug() << "Daemon start error: " + m_daemon->errorString();
|
qDebug() << "Daemon start error: " + m_daemon->errorString();
|
||||||
} else {
|
} else {
|
||||||
emit daemonStarted();
|
emit daemonStarted();
|
||||||
|
@ -75,7 +74,7 @@ bool DaemonManager::start()
|
||||||
|
|
||||||
bool DaemonManager::stop()
|
bool DaemonManager::stop()
|
||||||
{
|
{
|
||||||
if(initialized){
|
if (initialized) {
|
||||||
qDebug() << "stopping daemon";
|
qDebug() << "stopping daemon";
|
||||||
// we can't use QProcess::terminate() on windows console process
|
// we can't use QProcess::terminate() on windows console process
|
||||||
// write exit command to stdin
|
// write exit command to stdin
|
||||||
|
@ -88,7 +87,7 @@ bool DaemonManager::stop()
|
||||||
void DaemonManager::stateChanged(QProcess::ProcessState state)
|
void DaemonManager::stateChanged(QProcess::ProcessState state)
|
||||||
{
|
{
|
||||||
qDebug() << "STATE CHANGED: " << state;
|
qDebug() << "STATE CHANGED: " << state;
|
||||||
if(state == QProcess::NotRunning) {
|
if (state == QProcess::NotRunning) {
|
||||||
emit daemonStopped();
|
emit daemonStopped();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,7 +97,7 @@ void DaemonManager::printOutput()
|
||||||
QByteArray byteArray = m_daemon->readAllStandardOutput();
|
QByteArray byteArray = m_daemon->readAllStandardOutput();
|
||||||
QStringList strLines = QString(byteArray).split("\n");
|
QStringList strLines = QString(byteArray).split("\n");
|
||||||
|
|
||||||
foreach (QString line, strLines){
|
foreach (QString line, strLines) {
|
||||||
emit daemonConsoleUpdated(line);
|
emit daemonConsoleUpdated(line);
|
||||||
qDebug() << "Daemon: " + line;
|
qDebug() << "Daemon: " + line;
|
||||||
}
|
}
|
||||||
|
@ -109,7 +108,7 @@ void DaemonManager::printError()
|
||||||
QByteArray byteArray = m_daemon->readAllStandardError();
|
QByteArray byteArray = m_daemon->readAllStandardError();
|
||||||
QStringList strLines = QString(byteArray).split("\n");
|
QStringList strLines = QString(byteArray).split("\n");
|
||||||
|
|
||||||
foreach (QString line, strLines){
|
foreach (QString line, strLines) {
|
||||||
emit daemonConsoleUpdated(line);
|
emit daemonConsoleUpdated(line);
|
||||||
qDebug() << "Daemon ERROR: " + line;
|
qDebug() << "Daemon ERROR: " + line;
|
||||||
}
|
}
|
||||||
|
@ -117,7 +116,7 @@ void DaemonManager::printError()
|
||||||
|
|
||||||
bool DaemonManager::running() const
|
bool DaemonManager::running() const
|
||||||
{
|
{
|
||||||
if(initialized){
|
if (initialized) {
|
||||||
qDebug() << m_daemon->state();
|
qDebug() << m_daemon->state();
|
||||||
qDebug() << QProcess::NotRunning;
|
qDebug() << QProcess::NotRunning;
|
||||||
// m_daemon->write("status\n");
|
// m_daemon->write("status\n");
|
||||||
|
@ -137,7 +136,7 @@ void DaemonManager::closing()
|
||||||
qDebug() << __FUNCTION__;
|
qDebug() << __FUNCTION__;
|
||||||
stop();
|
stop();
|
||||||
// Wait for daemon to stop before exiting (max 10 secs)
|
// Wait for daemon to stop before exiting (max 10 secs)
|
||||||
if(initialized){
|
if (initialized) {
|
||||||
m_daemon->waitForFinished(10000);
|
m_daemon->waitForFinished(10000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ class DaemonManager : public QObject
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static DaemonManager * instance(QStringList args);
|
static DaemonManager * instance(const QStringList *args);
|
||||||
|
|
||||||
Q_INVOKABLE bool start();
|
Q_INVOKABLE bool start();
|
||||||
Q_INVOKABLE bool stop();
|
Q_INVOKABLE bool stop();
|
||||||
|
@ -34,7 +34,7 @@ private:
|
||||||
|
|
||||||
explicit DaemonManager(QObject *parent = 0);
|
explicit DaemonManager(QObject *parent = 0);
|
||||||
static DaemonManager * m_instance;
|
static DaemonManager * m_instance;
|
||||||
static QStringList clArgs;
|
static QStringList m_clArgs;
|
||||||
QProcess *m_daemon;
|
QProcess *m_daemon;
|
||||||
bool initialized = false;
|
bool initialized = false;
|
||||||
|
|
||||||
|
|
|
@ -88,13 +88,13 @@ Wallet::Status Wallet::status() const
|
||||||
return static_cast<Status>(m_walletImpl->status());
|
return static_cast<Status>(m_walletImpl->status());
|
||||||
}
|
}
|
||||||
|
|
||||||
Wallet::ConnectionStatus Wallet::connected()
|
Wallet::ConnectionStatus Wallet::connected() const
|
||||||
{
|
{
|
||||||
// cache connection status
|
// cache connection status
|
||||||
if(!m_initialized || m_connectionStatusTime.elapsed() / 1000 > m_connectionStatusTtl){
|
if (!m_initialized || m_connectionStatusTime.elapsed() / 1000 > m_connectionStatusTtl) {
|
||||||
m_initialized = true;
|
m_initialized = true;
|
||||||
ConnectionStatus newStatus = static_cast<ConnectionStatus>(m_walletImpl->connected());
|
ConnectionStatus newStatus = static_cast<ConnectionStatus>(m_walletImpl->connected());
|
||||||
if(newStatus != m_connectionStatus) {
|
if (newStatus != m_connectionStatus) {
|
||||||
m_connectionStatus = newStatus;
|
m_connectionStatus = newStatus;
|
||||||
emit connectionStatusChanged();
|
emit connectionStatusChanged();
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ public:
|
||||||
Status status() const;
|
Status status() const;
|
||||||
|
|
||||||
//! returns whether the wallet is connected, and version status
|
//! returns whether the wallet is connected, and version status
|
||||||
ConnectionStatus connected();
|
ConnectionStatus connected() const;
|
||||||
|
|
||||||
//! returns true if wallet was ever synchronized
|
//! returns true if wallet was ever synchronized
|
||||||
bool synchronized() const;
|
bool synchronized() const;
|
||||||
|
@ -196,7 +196,7 @@ signals:
|
||||||
// emitted when transaction is created async
|
// emitted when transaction is created async
|
||||||
void transactionCreated(PendingTransaction * transaction, QString address, QString paymentId, quint32 mixinCount);
|
void transactionCreated(PendingTransaction * transaction, QString address, QString paymentId, quint32 mixinCount);
|
||||||
|
|
||||||
void connectionStatusChanged();
|
void connectionStatusChanged() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Wallet(QObject * parent = nullptr);
|
Wallet(QObject * parent = nullptr);
|
||||||
|
@ -219,10 +219,10 @@ private:
|
||||||
mutable QTime m_daemonBlockChainTargetHeightTime;
|
mutable QTime m_daemonBlockChainTargetHeightTime;
|
||||||
mutable quint64 m_daemonBlockChainTargetHeight;
|
mutable quint64 m_daemonBlockChainTargetHeight;
|
||||||
int m_daemonBlockChainTargetHeightTtl;
|
int m_daemonBlockChainTargetHeightTtl;
|
||||||
ConnectionStatus m_connectionStatus;
|
mutable ConnectionStatus m_connectionStatus;
|
||||||
int m_connectionStatusTtl;
|
int m_connectionStatusTtl;
|
||||||
mutable QTime m_connectionStatusTime;
|
mutable QTime m_connectionStatusTime;
|
||||||
bool m_initialized;
|
mutable bool m_initialized;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue