mirror of
https://github.com/monero-project/monero-gui.git
synced 2024-12-13 11:56:32 +02:00
WalletManager: basic functionality
This commit is contained in:
parent
26abdee5c4
commit
4cdc258b15
87
src/daemon/DaemonManager.cpp
Normal file
87
src/daemon/DaemonManager.cpp
Normal file
@ -0,0 +1,87 @@
|
||||
#include "DaemonManager.h"
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
#include <QUrl>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
#include <QApplication>
|
||||
#include <QProcess>
|
||||
|
||||
DaemonManager * DaemonManager::m_instance = nullptr;
|
||||
|
||||
DaemonManager *DaemonManager::instance()
|
||||
{
|
||||
if (!m_instance) {
|
||||
m_instance = new DaemonManager;
|
||||
}
|
||||
|
||||
return m_instance;
|
||||
}
|
||||
|
||||
bool DaemonManager::start()
|
||||
{
|
||||
QString program = QApplication::applicationDirPath() + "/monerod";
|
||||
qDebug() << "starting monerod " + program;
|
||||
QStringList arguments;
|
||||
|
||||
m_daemon = new QProcess();
|
||||
|
||||
connect (m_daemon, SIGNAL(readyReadStandardOutput()), this, SLOT(printOutput()));
|
||||
connect (m_daemon, SIGNAL(readyReadStandardError()), this, SLOT(printError()));
|
||||
|
||||
|
||||
m_daemon->start(program);
|
||||
bool started = m_daemon->waitForStarted();
|
||||
|
||||
if(!started){
|
||||
qDebug() << "Daemon start error: " + m_daemon->errorString();
|
||||
}
|
||||
|
||||
return started;
|
||||
}
|
||||
|
||||
bool DaemonManager::stop()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void DaemonManager::printOutput()
|
||||
{
|
||||
QByteArray byteArray = m_daemon->readAllStandardOutput();
|
||||
QStringList strLines = QString(byteArray).split("\n");
|
||||
|
||||
foreach (QString line, strLines){
|
||||
// dConsole.append(line+"\n");
|
||||
qDebug() << "Daemon: " + line;
|
||||
}
|
||||
}
|
||||
|
||||
void DaemonManager::printError()
|
||||
{
|
||||
QByteArray byteArray = m_daemon->readAllStandardError();
|
||||
QStringList strLines = QString(byteArray).split("\n");
|
||||
|
||||
foreach (QString line, strLines){
|
||||
// dConsole.append(line+"\n");
|
||||
qDebug() << "Daemon ERROR: " + line;
|
||||
}
|
||||
}
|
||||
|
||||
bool DaemonManager::running() const
|
||||
{
|
||||
return m_daemon && m_daemon->state() > QProcess::NotRunning;
|
||||
}
|
||||
|
||||
QString DaemonManager::console() const
|
||||
{
|
||||
return dConsole;
|
||||
}
|
||||
|
||||
|
||||
DaemonManager::DaemonManager(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
41
src/daemon/DaemonManager.h
Normal file
41
src/daemon/DaemonManager.h
Normal file
@ -0,0 +1,41 @@
|
||||
#ifndef DAEMONMANAGER_H
|
||||
#define DAEMONMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QUrl>
|
||||
#include <QProcess>
|
||||
|
||||
class DaemonManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
static DaemonManager * instance();
|
||||
|
||||
Q_INVOKABLE bool start();
|
||||
Q_INVOKABLE bool stop();
|
||||
Q_INVOKABLE QString console() const;
|
||||
|
||||
// return true if daemon process is started
|
||||
Q_INVOKABLE bool running() const;
|
||||
|
||||
signals:
|
||||
|
||||
void daemonStarted(const QProcess &d);
|
||||
void daemonStopped();
|
||||
|
||||
public slots:
|
||||
void printOutput();
|
||||
void printError();
|
||||
|
||||
private:
|
||||
|
||||
explicit DaemonManager(QObject *parent = 0);
|
||||
static DaemonManager * m_instance;
|
||||
QProcess *m_daemon;
|
||||
QString dConsole;
|
||||
|
||||
};
|
||||
|
||||
#endif // DAEMONMANAGER_H
|
Loading…
Reference in New Issue
Block a user