2022-02-14 14:38:41 +00:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QQmlContext>
|
|
|
|
|
|
|
|
#include "module.h"
|
|
|
|
#include "singleton.h"
|
|
|
|
|
2022-02-16 21:51:04 +00:00
|
|
|
namespace Modules::Main::Wallet::Accounts
|
2022-02-14 14:38:41 +00:00
|
|
|
{
|
2022-02-16 21:51:04 +00:00
|
|
|
Module::Module(std::shared_ptr<Wallets::ServiceInterface> walletsService, QObject *parent): QObject(parent)
|
2022-02-14 14:38:41 +00:00
|
|
|
{
|
2022-02-16 21:51:04 +00:00
|
|
|
m_controllerPtr = new Controller(walletsService, this);
|
|
|
|
m_viewPtr = new View(this);
|
2022-02-14 14:38:41 +00:00
|
|
|
|
|
|
|
m_moduleLoaded = false;
|
|
|
|
|
|
|
|
connect();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Module::connect()
|
|
|
|
{
|
2022-02-16 21:51:04 +00:00
|
|
|
QObject::connect(m_viewPtr, &View::viewLoaded, this, &Module::viewDidLoad);
|
2022-02-14 14:38:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Module::load()
|
|
|
|
{
|
2022-02-16 21:51:04 +00:00
|
|
|
Global::Singleton::instance()->engine()->rootContext()->setContextProperty("walletSectionAccounts", m_viewPtr);
|
2022-02-14 14:38:41 +00:00
|
|
|
m_controllerPtr->init();
|
|
|
|
m_viewPtr->load();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Module::isLoaded()
|
|
|
|
{
|
|
|
|
return m_moduleLoaded;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Module::viewDidLoad()
|
|
|
|
{
|
|
|
|
refreshWalletAccounts();
|
|
|
|
m_moduleLoaded = true;
|
|
|
|
emit loaded();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Module::refreshWalletAccounts()
|
|
|
|
{
|
|
|
|
auto walletAccounts = m_controllerPtr->getWalletAccounts();
|
|
|
|
|
|
|
|
if(walletAccounts.size() > 0)
|
|
|
|
{
|
|
|
|
QVector<Item> items;
|
|
|
|
foreach(const auto& acc, walletAccounts)
|
|
|
|
{
|
|
|
|
items << Item(acc.name, acc.address, acc.path, acc.color, acc.publicKey, acc.walletType, acc.isWallet, acc.isChat, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_viewPtr->setModelItems(items);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qWarning()<<"No accounts found!";
|
|
|
|
}
|
|
|
|
}
|
2022-02-16 21:51:04 +00:00
|
|
|
} // namespace Modules::Main::Wallet::Accounts
|