gui: Refactor OpenWalletActivity

This commit is contained in:
João Barbosa
2019-06-21 15:13:15 +01:00
parent 5e202382a9
commit bc6d8a3662
3 changed files with 103 additions and 61 deletions

View File

@@ -10,10 +10,13 @@
#include <map>
#include <memory>
#include <string>
#include <vector>
#include <QMessageBox>
#include <QMutex>
#include <QProgressDialog>
#include <QString>
#include <QThread>
class OptionsModel;
@@ -25,6 +28,7 @@ class Node;
} // namespace interfaces
class OpenWalletActivity;
class WalletControllerActivity;
/**
* Controller between interfaces::Node, WalletModel instances and the GUI.
@@ -33,7 +37,6 @@ class WalletController : public QObject
{
Q_OBJECT
WalletModel* getOrCreateWallet(std::unique_ptr<interfaces::Wallet> wallet);
void removeAndDeleteWallet(WalletModel* wallet_model);
public:
@@ -43,11 +46,12 @@ public:
//! Returns wallet models currently open.
std::vector<WalletModel*> getOpenWallets() const;
WalletModel* getOrCreateWallet(std::unique_ptr<interfaces::Wallet> wallet);
//! Returns all wallet names in the wallet dir mapped to whether the wallet
//! is loaded.
std::map<std::string, bool> listWalletDir() const;
OpenWalletActivity* openWallet(const std::string& name, QWidget* parent = nullptr);
void closeWallet(WalletModel* wallet_model, QWidget* parent = nullptr);
Q_SIGNALS:
@@ -57,7 +61,8 @@ Q_SIGNALS:
void coinsSent(WalletModel* wallet_model, SendCoinsRecipient recipient, QByteArray transaction);
private:
QThread m_activity_thread;
QThread* const m_activity_thread;
QObject* const m_activity_worker;
interfaces::Node& m_node;
const PlatformStyle* const m_platform_style;
OptionsModel* const m_options_model;
@@ -65,27 +70,48 @@ private:
std::vector<WalletModel*> m_wallets;
std::unique_ptr<interfaces::Handler> m_handler_load_wallet;
friend class OpenWalletActivity;
friend class WalletControllerActivity;
};
class OpenWalletActivity : public QObject
class WalletControllerActivity : public QObject
{
Q_OBJECT
public:
OpenWalletActivity(WalletController* wallet_controller, const std::string& name);
public Q_SLOTS:
void open();
WalletControllerActivity(WalletController* wallet_controller, QWidget* parent_widget);
virtual ~WalletControllerActivity();
Q_SIGNALS:
void message(QMessageBox::Icon icon, const QString text);
void finished();
protected:
interfaces::Node& node() const { return m_wallet_controller->m_node; }
QObject* worker() const { return m_wallet_controller->m_activity_worker; }
void showProgressDialog(const QString& label_text);
WalletController* const m_wallet_controller;
QWidget* const m_parent_widget;
QProgressDialog* m_progress_dialog{nullptr};
WalletModel* m_wallet_model{nullptr};
std::string m_error_message;
std::string m_warning_message;
};
class OpenWalletActivity : public WalletControllerActivity
{
Q_OBJECT
public:
OpenWalletActivity(WalletController* wallet_controller, QWidget* parent_widget);
void open(const std::string& path);
Q_SIGNALS:
void opened(WalletModel* wallet_model);
private:
WalletController* const m_wallet_controller;
std::string const m_name;
void finish();
};
#endif // BITCOIN_QT_WALLETCONTROLLER_H