forked from Public/monero-gui
WalletManager::openWalletAsync in progress
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
#include <QUrl>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
|
||||
|
||||
|
||||
@@ -42,6 +43,20 @@ Wallet *WalletManager::openWallet(const QString &path, const QString &password,
|
||||
return wallet;
|
||||
}
|
||||
|
||||
void WalletManager::openWalletAsync(const QString &path, const QString &password, bool testnet)
|
||||
{
|
||||
QFuture<Wallet*> future = QtConcurrent::run(this, &WalletManager::openWallet,
|
||||
path, password, testnet);
|
||||
QFutureWatcher<Wallet*> * watcher = new QFutureWatcher<Wallet*>();
|
||||
watcher->setFuture(future);
|
||||
connect(watcher, &QFutureWatcher<Wallet*>::finished,
|
||||
this, [this, watcher]() {
|
||||
QFuture<Wallet*> future = watcher->future();
|
||||
watcher->deleteLater();
|
||||
emit walletOpened(future.result());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Wallet *WalletManager::recoveryWallet(const QString &path, const QString &memo, bool testnet)
|
||||
{
|
||||
@@ -51,9 +66,26 @@ Wallet *WalletManager::recoveryWallet(const QString &path, const QString &memo,
|
||||
}
|
||||
|
||||
|
||||
void WalletManager::closeWallet(Wallet *wallet)
|
||||
QString WalletManager::closeWallet(Wallet *wallet)
|
||||
{
|
||||
QString result = wallet->address();
|
||||
delete wallet;
|
||||
return result;
|
||||
}
|
||||
|
||||
void WalletManager::closeWalletAsync(Wallet *wallet)
|
||||
{
|
||||
QFuture<QString> future = QtConcurrent::run(this, &WalletManager::closeWallet,
|
||||
wallet);
|
||||
QFutureWatcher<QString> * watcher = new QFutureWatcher<QString>();
|
||||
watcher->setFuture(future);
|
||||
|
||||
connect(watcher, &QFutureWatcher<QString>::finished,
|
||||
this, [this, watcher]() {
|
||||
QFuture<QString> future = watcher->future();
|
||||
watcher->deleteLater();
|
||||
emit future.result();
|
||||
});
|
||||
}
|
||||
|
||||
bool WalletManager::walletExists(const QString &path) const
|
||||
|
||||
@@ -16,15 +16,38 @@ public:
|
||||
// wizard: createWallet path;
|
||||
Q_INVOKABLE Wallet * createWallet(const QString &path, const QString &password,
|
||||
const QString &language, bool testnet = false);
|
||||
// just for future use
|
||||
|
||||
/*!
|
||||
* \brief openWallet - opens wallet by given path
|
||||
* \param path - wallet filename
|
||||
* \param password - wallet password. Empty string in wallet isn't password protected
|
||||
* \param testnet - determines if we running testnet
|
||||
* \return wallet object pointer
|
||||
*/
|
||||
Q_INVOKABLE Wallet * openWallet(const QString &path, const QString &password, bool testnet = false);
|
||||
|
||||
/*!
|
||||
* \brief openWalletAsync - asynchronous version of "openWallet". Returns immediately. "walletOpened" signal
|
||||
* emitted when wallet opened;
|
||||
*/
|
||||
Q_INVOKABLE void openWalletAsync(const QString &path, const QString &password, bool testnet = false);
|
||||
|
||||
// wizard: recoveryWallet path; hint: internally it recorvers wallet and set password = ""
|
||||
Q_INVOKABLE Wallet * recoveryWallet(const QString &path, const QString &memo,
|
||||
bool testnet = false);
|
||||
|
||||
//! utils: close wallet to free memory
|
||||
Q_INVOKABLE void closeWallet(Wallet * wallet);
|
||||
/*!
|
||||
* \brief closeWallet - closes wallet and frees memory
|
||||
* \param wallet
|
||||
* \return wallet address
|
||||
*/
|
||||
Q_INVOKABLE QString closeWallet(Wallet * wallet);
|
||||
|
||||
/*!
|
||||
* \brief closeWalletAsync - asynchronous version of "closeWallet"
|
||||
* \param wallet - wallet pointer;
|
||||
*/
|
||||
Q_INVOKABLE void closeWalletAsync(Wallet * wallet);
|
||||
|
||||
//! checks is given filename is a wallet;
|
||||
Q_INVOKABLE bool walletExists(const QString &path) const;
|
||||
@@ -50,8 +73,10 @@ public:
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
void walletOpened(Wallet * wallet);
|
||||
void walletClosed(const QString &walletAddress);
|
||||
|
||||
public slots:
|
||||
private:
|
||||
|
||||
explicit WalletManager(QObject *parent = 0);
|
||||
|
||||
Reference in New Issue
Block a user