aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoão Barbosa <joao.paulo.barbosa@gmail.com>2019-01-21 16:58:20 +0000
committerJoão Barbosa <joao.paulo.barbosa@gmail.com>2019-02-04 12:23:40 +0000
commit8847cdaaaeb45c1ddee89f43ac4b8fafb20e5c0d (patch)
tree321d97f44c2168eef5725b5e2528de375d96dbaf /src
parent4c8982a88e3d9fae4f8fc147a2d9f9650a493da7 (diff)
gui: Add OpenWalletActivity
Diffstat (limited to 'src')
-rw-r--r--src/qt/bitcoin.cpp2
-rw-r--r--src/qt/bitcoingui.cpp4
-rw-r--r--src/qt/walletcontroller.cpp36
-rw-r--r--src/qt/walletcontroller.h27
4 files changed, 56 insertions, 13 deletions
diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp
index 85d79ee26c..d6c6fd6e98 100644
--- a/src/qt/bitcoin.cpp
+++ b/src/qt/bitcoin.cpp
@@ -456,7 +456,7 @@ int GuiMain(int argc, char* argv[])
// IMPORTANT if it is no longer a typedef use the normal variant above
qRegisterMetaType< CAmount >("CAmount");
qRegisterMetaType< std::function<void()> >("std::function<void()>");
-
+ qRegisterMetaType<QMessageBox::Icon>("QMessageBox::Icon");
/// 2. Parse command-line options. We do this after qt in order to show an error if there are problems parsing these
// Command-line options take precedence:
node->setupServerArgs();
diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp
index e7279e1229..3622bd5657 100644
--- a/src/qt/bitcoingui.cpp
+++ b/src/qt/bitcoingui.cpp
@@ -371,7 +371,9 @@ void BitcoinGUI::createActions()
QString name = path.empty() ? QString("["+tr("default wallet")+"]") : QString::fromStdString(path);
QAction* action = m_open_wallet_action->menu()->addAction(name);
connect(action, &QAction::triggered, [this, path] {
- setCurrentWallet(m_wallet_controller->openWallet(path));
+ OpenWalletActivity* activity = m_wallet_controller->openWallet(path);
+ connect(activity, &OpenWalletActivity::opened, this, &BitcoinGUI::setCurrentWallet);
+ connect(activity, &OpenWalletActivity::finished, activity, &QObject::deleteLater);
});
}
});
diff --git a/src/qt/walletcontroller.cpp b/src/qt/walletcontroller.cpp
index a103f4c89b..3483c75970 100644
--- a/src/qt/walletcontroller.cpp
+++ b/src/qt/walletcontroller.cpp
@@ -55,17 +55,12 @@ std::vector<std::string> WalletController::getWalletsAvailableToOpen() const
return wallets;
}
-WalletModel* WalletController::openWallet(const std::string& name, QWidget* parent)
+OpenWalletActivity* WalletController::openWallet(const std::string& name, QWidget* parent)
{
- std::string error, warning;
- WalletModel* wallet_model = getOrCreateWallet(m_node.loadWallet(name, error, warning));
- if (!wallet_model) {
- QMessageBox::warning(parent, tr("Open Wallet"), QString::fromStdString(error));
- }
- if (!warning.empty()) {
- QMessageBox::information(parent, tr("Open Wallet"), QString::fromStdString(warning));
- }
- return wallet_model;
+ OpenWalletActivity* activity = new OpenWalletActivity(this, name);
+ activity->moveToThread(&m_activity_thread);
+ QMetaObject::invokeMethod(activity, "open", Qt::QueuedConnection);
+ return activity;
}
WalletModel* WalletController::getOrCreateWallet(std::unique_ptr<interfaces::Wallet> wallet)
@@ -124,3 +119,24 @@ void WalletController::removeAndDeleteWallet(WalletModel* wallet_model)
// CWallet shared pointer.
delete wallet_model;
}
+
+
+OpenWalletActivity::OpenWalletActivity(WalletController* wallet_controller, const std::string& name)
+ : m_wallet_controller(wallet_controller)
+ , m_name(name)
+{}
+
+void OpenWalletActivity::open()
+{
+ std::string error, warning;
+ std::unique_ptr<interfaces::Wallet> wallet = m_wallet_controller->m_node.loadWallet(m_name, error, warning);
+ if (!warning.empty()) {
+ Q_EMIT message(QMessageBox::Warning, QString::fromStdString(warning));
+ }
+ if (wallet) {
+ Q_EMIT opened(m_wallet_controller->getOrCreateWallet(std::move(wallet)));
+ } else {
+ Q_EMIT message(QMessageBox::Critical, QString::fromStdString(error));
+ }
+ Q_EMIT finished();
+}
diff --git a/src/qt/walletcontroller.h b/src/qt/walletcontroller.h
index 1664fa6f3f..f19c0e1f3d 100644
--- a/src/qt/walletcontroller.h
+++ b/src/qt/walletcontroller.h
@@ -12,6 +12,7 @@
#include <memory>
#include <vector>
+#include <QMessageBox>
#include <QMutex>
#include <QThread>
@@ -23,6 +24,8 @@ class Handler;
class Node;
} // namespace interfaces
+class OpenWalletActivity;
+
/**
* Controller between interfaces::Node, WalletModel instances and the GUI.
*/
@@ -40,7 +43,7 @@ public:
std::vector<WalletModel*> getWallets() const;
std::vector<std::string> getWalletsAvailableToOpen() const;
- WalletModel* openWallet(const std::string& name, QWidget* parent = nullptr);
+ OpenWalletActivity* openWallet(const std::string& name, QWidget* parent = nullptr);
private Q_SLOTS:
void addWallet(WalletModel* wallet_model);
@@ -59,6 +62,28 @@ private:
mutable QMutex m_mutex;
std::vector<WalletModel*> m_wallets;
std::unique_ptr<interfaces::Handler> m_handler_load_wallet;
+
+ friend class OpenWalletActivity;
+};
+
+class OpenWalletActivity : public QObject
+{
+ Q_OBJECT
+
+public:
+ OpenWalletActivity(WalletController* wallet_controller, const std::string& name);
+
+public Q_SLOTS:
+ void open();
+
+Q_SIGNALS:
+ void message(QMessageBox::Icon icon, const QString text);
+ void finished();
+ void opened(WalletModel* wallet_model);
+
+private:
+ WalletController* const m_wallet_controller;
+ std::string const m_name;
};
#endif // BITCOIN_QT_WALLETCONTROLLER_H