mirror of
https://github.com/monero-project/monero-gui.git
synced 2025-01-10 21:04:32 +00:00
integrating cpp wallet mockups with QML
This commit is contained in:
parent
1195a89d06
commit
625041df18
11 changed files with 172 additions and 36 deletions
27
Wallet.cpp
27
Wallet.cpp
|
@ -1,6 +1,31 @@
|
||||||
#include "Wallet.h"
|
#include "Wallet.h"
|
||||||
|
|
||||||
Wallet::Wallet(QObject *parent) : QObject(parent)
|
struct WalletImpl
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Wallet::Wallet(QObject *parent)
|
||||||
|
: QObject(parent)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString Wallet::getSeed() const
|
||||||
|
{
|
||||||
|
return "bound class paint gasp task soul forgot past pleasure physical circle "
|
||||||
|
" appear shore bathroom glove women crap busy beauty bliss idea give needle burden";
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Wallet::getSeedLanguage() const
|
||||||
|
{
|
||||||
|
return "English";
|
||||||
|
}
|
||||||
|
|
||||||
|
void Wallet::setSeedLaguage(const QString &lang)
|
||||||
|
{
|
||||||
|
// TODO;
|
||||||
|
}
|
||||||
|
|
16
Wallet.h
16
Wallet.h
|
@ -3,15 +3,27 @@
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
struct WalletImpl;
|
||||||
|
|
||||||
class Wallet : public QObject
|
class Wallet : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QString seed READ getSeed)
|
||||||
public:
|
public:
|
||||||
explicit Wallet(QObject *parent = 0);
|
explicit Wallet(QObject *parent = 0);
|
||||||
|
QString getSeed() const;
|
||||||
|
QString getSeedLanguage() const;
|
||||||
|
void setSeedLaguage(const QString &lang);
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
|
||||||
|
friend class WalletManager;
|
||||||
|
WalletImpl * m_pimpl;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WALLET_H
|
#endif // WALLET_H
|
|
@ -1,6 +0,0 @@
|
||||||
#include "Wallet2Service.h"
|
|
||||||
|
|
||||||
Wallet2Service::Wallet2Service(QObject *parent) : QObject(parent)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
#ifndef WALLET2SERVICE_H
|
|
||||||
#define WALLET2SERVICE_H
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
class Wallet2Service : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit Wallet2Service(QObject *parent = 0);
|
|
||||||
|
|
||||||
signals:
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // WALLET2SERVICE_H
|
|
|
@ -1,6 +1,93 @@
|
||||||
#include "WalletManager.h"
|
#include "WalletManager.h"
|
||||||
|
#include "Wallet.h"
|
||||||
|
#include <QFile>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
|
WalletManager * WalletManager::m_instance = nullptr;
|
||||||
|
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
bool createFileWrapper(const QString &filename)
|
||||||
|
{
|
||||||
|
QFile file(filename);
|
||||||
|
// qDebug("%s: about to create file: %s", __FUNCTION__, qPrintable(filename));
|
||||||
|
bool result = file.open(QIODevice::WriteOnly);
|
||||||
|
if (!result ){
|
||||||
|
qWarning("%s: error creating file '%s' : '%s'",
|
||||||
|
__FUNCTION__,
|
||||||
|
qPrintable(filename),
|
||||||
|
qPrintable(file.errorString()));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
WalletManager *WalletManager::instance()
|
||||||
|
{
|
||||||
|
if (!m_instance) {
|
||||||
|
m_instance = new WalletManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
Wallet *WalletManager::createWallet(const QString &path, const QString &password,
|
||||||
|
const QString &language)
|
||||||
|
{
|
||||||
|
Wallet * wallet = new Wallet(this);
|
||||||
|
// Create dummy files for testing
|
||||||
|
QFileInfo fi(path);
|
||||||
|
QDir tempDir;
|
||||||
|
tempDir.mkpath(fi.absolutePath());
|
||||||
|
createFileWrapper(path);
|
||||||
|
createFileWrapper(path + ".keys");
|
||||||
|
createFileWrapper(path + ".address.txt");
|
||||||
|
return wallet;
|
||||||
|
}
|
||||||
|
|
||||||
|
Wallet *WalletManager::openWallet(const QString &path, const QString &language)
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WalletManager::moveWallet(const QString &src, const QString &dst_)
|
||||||
|
{
|
||||||
|
QFile walletFile(src);
|
||||||
|
if (!walletFile.exists()) {
|
||||||
|
qWarning("%s: source file [%s] doesn't exits", __FUNCTION__,
|
||||||
|
qPrintable(src));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
QString dst = QUrl(dst_).toLocalFile();
|
||||||
|
QString walletKeysFile = src + ".keys";
|
||||||
|
QString walletAddressFile = src + ".address.txt";
|
||||||
|
|
||||||
|
QString dstWalletKeysFile = dst + ".keys";
|
||||||
|
QString dstWalletAddressFile = dst + ".address.txt";
|
||||||
|
|
||||||
|
if (!walletFile.rename(dst)) {
|
||||||
|
qWarning("Error renaming file: '%s' to '%s' : (%s)",
|
||||||
|
qPrintable(src),
|
||||||
|
qPrintable(dst),
|
||||||
|
qPrintable(walletFile.errorString()));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
QFile::rename(walletKeysFile, dstWalletKeysFile);
|
||||||
|
QFile::rename(walletAddressFile, dstWalletAddressFile);
|
||||||
|
|
||||||
|
return QFile::exists(dst) && QFile::exists(dstWalletKeysFile)
|
||||||
|
&& QFile::exists(dstWalletAddressFile);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
WalletManager::WalletManager(QObject *parent) : QObject(parent)
|
WalletManager::WalletManager(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,15 +3,26 @@
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
class Wallet;
|
||||||
|
|
||||||
class WalletManager : public QObject
|
class WalletManager : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit WalletManager(QObject *parent = 0);
|
static WalletManager * instance();
|
||||||
|
Q_INVOKABLE Wallet * createWallet(const QString &path, const QString &password,
|
||||||
|
const QString &language);
|
||||||
|
Q_INVOKABLE Wallet * openWallet(const QString &path, const QString &language);
|
||||||
|
Q_INVOKABLE bool moveWallet(const QString &src, const QString &dst);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
|
private:
|
||||||
|
explicit WalletManager(QObject *parent = 0);
|
||||||
|
static WalletManager * m_instance;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // WALLETMANAGER_H
|
#endif // WALLETMANAGER_H
|
7
main.cpp
7
main.cpp
|
@ -57,13 +57,18 @@ int main(int argc, char *argv[])
|
||||||
// to save the wallet file (.keys, .bin), they have to be user-accessible for
|
// to save the wallet file (.keys, .bin), they have to be user-accessible for
|
||||||
// backups - I reckon we save that in My Documents\Monero Accounts\ on
|
// backups - I reckon we save that in My Documents\Monero Accounts\ on
|
||||||
// Windows, ~/Monero Accounts/ on nix / osx
|
// Windows, ~/Monero Accounts/ on nix / osx
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
QStringList moneroAccountsRootDir = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation);
|
QStringList moneroAccountsRootDir = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation);
|
||||||
#elif defined(Q_OS_UNIX)
|
#elif defined(Q_OS_UNIX)
|
||||||
QStringList moneroAccountsRootDir = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
|
QStringList moneroAccountsRootDir = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!moneroAccountsRootDir.empty()) {
|
if (!moneroAccountsRootDir.empty()) {
|
||||||
engine.rootContext()->setContextProperty("moneroAccountsDir", moneroAccountsRootDir.at(0) + "/Monero Accounts");
|
QString moneroAccountsDir = moneroAccountsRootDir.at(0) + "/Monero Accounts";
|
||||||
|
QDir tempDir;
|
||||||
|
tempDir.mkpath(moneroAccountsDir);
|
||||||
|
engine.rootContext()->setContextProperty("moneroAccountsDir", moneroAccountsDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
engine.rootContext()->setContextProperty("applicationDirectory", QApplication::applicationDirPath());
|
engine.rootContext()->setContextProperty("applicationDirectory", QApplication::applicationDirPath());
|
||||||
|
|
|
@ -7,7 +7,6 @@ HEADERS += \
|
||||||
filter.h \
|
filter.h \
|
||||||
clipboardAdapter.h \
|
clipboardAdapter.h \
|
||||||
oscursor.h \
|
oscursor.h \
|
||||||
Wallet2Adaptor.h \
|
|
||||||
WalletManager.h \
|
WalletManager.h \
|
||||||
Wallet.h
|
Wallet.h
|
||||||
|
|
||||||
|
|
|
@ -44,12 +44,29 @@ Item {
|
||||||
settingsObject['account_name'] = uiItem.accountNameText
|
settingsObject['account_name'] = uiItem.accountNameText
|
||||||
settingsObject['words'] = uiItem.wordsTexttext
|
settingsObject['words'] = uiItem.wordsTexttext
|
||||||
settingsObject['wallet_path'] = uiItem.walletPath
|
settingsObject['wallet_path'] = uiItem.walletPath
|
||||||
|
|
||||||
|
|
||||||
|
var new_wallet_filename = settingsObject.wallet_path + "/"
|
||||||
|
+ settingsObject.account_name;
|
||||||
|
|
||||||
|
// moving wallet files to the new destination, if user changed it
|
||||||
|
if (new_wallet_filename !== settingsObject.wallet_filename) {
|
||||||
|
walletManager.moveWallet(settingsObject.wallet_filename, new_wallet_filename);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function createWallet(settingsObject) {
|
function createWallet(settingsObject) {
|
||||||
// print ("Language: " + settingsObject.language);
|
var wallet_filename = uiItem.walletPath + "/" + uiItem.accountNameText
|
||||||
var wallet = walletManager.createWallet(uiItem.accountNameText, "", settingsObject.language);
|
if (typeof settingsObject.wallet === 'undefined') {
|
||||||
|
var wallet = walletManager.createWallet(wallet_filename, "", settingsObject.language)
|
||||||
uiItem.wordsTextItem.memoText = wallet.seed
|
uiItem.wordsTextItem.memoText = wallet.seed
|
||||||
|
// saving wallet in "global" settings object
|
||||||
|
// TODO: wallet should have a property pointing to the file where it stored or loaded from
|
||||||
|
settingsObject.wallet = wallet
|
||||||
|
} else {
|
||||||
|
print("wallet already created. we just stepping back");
|
||||||
|
}
|
||||||
|
settingsObject.wallet_filename = wallet_filename
|
||||||
}
|
}
|
||||||
|
|
||||||
WizardManageWalletUI {
|
WizardManageWalletUI {
|
||||||
|
|
|
@ -67,6 +67,7 @@ Rectangle {
|
||||||
function handlePageChanged() {
|
function handlePageChanged() {
|
||||||
var nextButtonVisible = pages[currentPage] !== optionsPage;
|
var nextButtonVisible = pages[currentPage] !== optionsPage;
|
||||||
nextButton.visible = nextButtonVisible;
|
nextButton.visible = nextButtonVisible;
|
||||||
|
print ("next button visible: " + nextButtonVisible);
|
||||||
switch (pages[currentPage]) {
|
switch (pages[currentPage]) {
|
||||||
case passwordPage:
|
case passwordPage:
|
||||||
// disable "next" button until passwords match
|
// disable "next" button until passwords match
|
||||||
|
@ -87,6 +88,7 @@ Rectangle {
|
||||||
// nextButton.enabled = false;
|
// nextButton.enabled = false;
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
|
nextButton.enabled = true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -183,9 +183,10 @@ Item {
|
||||||
FileDialog {
|
FileDialog {
|
||||||
id: fileDialog
|
id: fileDialog
|
||||||
selectMultiple: false
|
selectMultiple: false
|
||||||
title: "Please choose a file"
|
selectFolder: true
|
||||||
|
title: "Please choose a directory"
|
||||||
onAccepted: {
|
onAccepted: {
|
||||||
fileUrlInput.text = fileDialog.fileUrl
|
fileUrlInput.text = fileDialog.folder
|
||||||
fileDialog.visible = false
|
fileDialog.visible = false
|
||||||
}
|
}
|
||||||
onRejected: {
|
onRejected: {
|
||||||
|
|
Loading…
Reference in a new issue