diff --git a/CellFrameDashboardGUI/CellFrameDashboardGUI.pro b/CellFrameDashboardGUI/CellFrameDashboardGUI.pro index 22052a2d7b1ec6dc927d7a4c09831e9cecbec75b..acf01a80ef664f12d7f63cba3a8c1a19f86714a8 100755 --- a/CellFrameDashboardGUI/CellFrameDashboardGUI.pro +++ b/CellFrameDashboardGUI/CellFrameDashboardGUI.pro @@ -70,6 +70,7 @@ SOURCES += \ $$PWD/DapServiceClientNativeLinux.cpp \ $$PWD/DapServiceClientNativeWin.cpp \ $$PWD/DapServiceClientNativeMacOS.cpp \ + $$PWD/Factory.cpp RESOURCES += $$PWD/qml.qrc @@ -84,6 +85,7 @@ HEADERS += \ $$PWD/DapServiceClientNativeAbstract.h \ $$PWD/DapServiceClientNativeLinux.h \ $$PWD/DapServiceClientNativeWin.h \ + $$PWD/Factory.h include (../libdap/libdap.pri) include (../libdap-crypto/libdap-crypto.pri) diff --git a/CellFrameDashboardGUI/DapServiceController.cpp b/CellFrameDashboardGUI/DapServiceController.cpp index b2bfb7d51d757c0e1d27a2a3fb2a92fcdbefd109..f8c3ceea65ab60f7a618fc2a78c018689a7ab6d6 100644 --- a/CellFrameDashboardGUI/DapServiceController.cpp +++ b/CellFrameDashboardGUI/DapServiceController.cpp @@ -87,6 +87,12 @@ void DapServiceController::registerCommand() m_transceivers.append(qMakePair(dynamic_cast<DapAbstractCommand*>(m_DAPRpcSocket->addService(new DapGetListWalletsCommand("DapGetListWalletsCommand", m_DAPRpcSocket))), QString("walletsListReceived"))); // Command to save data from the Logs tab m_transceivers.append(qMakePair(dynamic_cast<DapAbstractCommand*>(m_DAPRpcSocket->addService(new DapExportLogCommand("DapExportLogCommand",m_DAPRpcSocket))), QString("exportLogs"))); + // The command to get a list of available networks + m_transceivers.append(qMakePair(dynamic_cast<DapAbstractCommand*>(m_DAPRpcSocket->addService(new DapGetListNetworksCommand("DapGetListNetworksCommand", m_DAPRpcSocket))), QString("networksListReceived"))); + + m_transceivers.append(qMakePair(dynamic_cast<DapAbstractCommand*>(m_DAPRpcSocket->addService(new DapGetWalletAddressesCommand("DapGetWalletAddressesCommand", m_DAPRpcSocket))), QString("walletAddressesReceived"))); + + m_transceivers.append(qMakePair(dynamic_cast<DapAbstractCommand*>(m_DAPRpcSocket->addService(new DapGetWalletTokenInfoCommand("DapGetWalletTokenInfoCommand", m_DAPRpcSocket))), QString("walletTokensReceived"))); registerEmmitedSignal(); } diff --git a/CellFrameDashboardGUI/DapServiceController.h b/CellFrameDashboardGUI/DapServiceController.h index 7866c5735c139175ca486a93ce6250a9f45dc977..98d19eb7fe87e1d8c31a71a9fafdca382140004d 100644 --- a/CellFrameDashboardGUI/DapServiceController.h +++ b/CellFrameDashboardGUI/DapServiceController.h @@ -17,7 +17,11 @@ #include "Handlers/DapUpdateLogsCommand.h" #include "Handlers/DapAddWalletCommand.h" #include "Handlers/DapGetListWalletsCommand.h" +#include "Handlers/DapGetListNetworksCommand.h" #include "Handlers/DapExportLogCommand.h" +#include "Handlers/DapGetWalletAddressesCommand.h" +#include "Handlers/DapGetWalletTokenInfoCommand.h" +#include "Models/DapWalletModel.h" class DapServiceController : public QObject { @@ -95,7 +99,13 @@ signals: void walletCreated(const QVariant& wallet); - void walletsListReceived(const QVariant& wallet); + void walletsListReceived(const QVariant& walletList); + + void networksListReceived(const QVariant& networkList); + + void walletAddressesReceived(const QVariant& walletAddresses); + + void walletTokensReceived(const QVariant& walletTokens); private slots: /// Register command. diff --git a/CellFrameDashboardGUI/Factory.cpp b/CellFrameDashboardGUI/Factory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5a892ccb7ed7cdb8d4a7d015e0db3845f2ce4ceb --- /dev/null +++ b/CellFrameDashboardGUI/Factory.cpp @@ -0,0 +1,28 @@ +#include "Factory.h" + +Factory::Factory(QObject *parent) : QObject(parent) +{ + +} + +QObject *Factory::createStructure() +{ + DapWallet * wallet = new DapWallet(); + wallet->setName("MyWallet5"); + wallet->setBalance(1548745354574); + wallet->addNetwork("Kelvin-testnet"); + wallet->addNetwork("Private"); + wallet->addAddress("ar4th4t4j6tyj7utjk45u654kuj4kl6ui4l54k5lu5u4il5i34l35", "Kelvin-testnet"); + wallet->addAddress("ar4th4t4j6tyj7utjk45u654kuj4kl6ui4l54k5lu5u4il5i34l35", "Private"); + DapWalletToken * token1 = new DapWalletToken("KLV", wallet); + token1->setBalance(5.5); + token1->setNetwork("Kelvin-testnet"); + token1->setEmission(464645646546); + DapWalletToken * token2 = new DapWalletToken("CELL", wallet); + token2->setBalance(100); + token2->setNetwork("Private"); + token2->setEmission(121212121); + wallet->addToken(token1); + wallet->addToken(token2); + return wallet; +} diff --git a/CellFrameDashboardGUI/Factory.h b/CellFrameDashboardGUI/Factory.h new file mode 100644 index 0000000000000000000000000000000000000000..3ac934b464a80e2bc6c6006934045950093d26fd --- /dev/null +++ b/CellFrameDashboardGUI/Factory.h @@ -0,0 +1,18 @@ +#ifndef FACTORY_H +#define FACTORY_H + +#include <QObject> + +#include "DapWallet.h" + +class Factory : public QObject +{ + Q_OBJECT +public: + explicit Factory(QObject *parent = nullptr); + + Q_INVOKABLE QObject* createStructure(); // Ð”Ð»Ñ ÑÐ¾Ð·Ð´Ð°Ð½Ð¸Ñ Ñтруктур + +}; + +#endif // FACTORY_H diff --git a/CellFrameDashboardGUI/main.cpp b/CellFrameDashboardGUI/main.cpp index 3784484798731e5548ae77dcc42276cd9caf0e64..a4e8dff96ec9b0c8dc0e5b467ba49ee78b206112 100644 --- a/CellFrameDashboardGUI/main.cpp +++ b/CellFrameDashboardGUI/main.cpp @@ -13,6 +13,8 @@ #include "DapServiceController.h" #include "DapLogger.h" #include "DapLogMessage.h" +#include "DapWallet.h" +#include "Factory.h" #include <sys/stat.h> @@ -40,7 +42,7 @@ int main(int argc, char *argv[]) #endif //#endif - qRegisterMetaType<DapWallet>(); + /// Local client. DapServiceClient dapServiceClient; @@ -51,8 +53,11 @@ int main(int argc, char *argv[]) qmlRegisterType<DapLogMessage>("Demlabs", 1, 0, "DapLogMessage"); qmlRegisterType<DapWallet>("Demlabs", 1, 0, "DapWallet"); qmlRegisterType<DapWalletToken>("Demlabs", 1, 0, "DapWalletToken"); - + qRegisterMetaType<DapWallet>(); + qRegisterMetaType<DapWalletToken>(); QQmlApplicationEngine engine; + Factory factory; + engine.rootContext()->setContextProperty("factory", &factory); engine.rootContext()->setContextProperty("dapServiceController", &DapServiceController::getInstance()); engine.rootContext()->setContextProperty("pt", 1); engine.load(QUrl("qrc:/main.qml")); diff --git a/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardScreen.qml b/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardScreen.qml index 59be756ba5724d5fc967e083edc79d803a125b2a..d38bc0e7a9168e7d6ed07f83a5a2bf92a5937b24 100644 --- a/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardScreen.qml +++ b/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardScreen.qml @@ -2,7 +2,5 @@ import QtQuick 2.4 DapDashboardScreenForm { - buttonTest.onClicked: textTest.text = "DESKTOP " + textTest.font.pointSize + " " + textTest.font.pixelSize - } diff --git a/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardScreenForm.ui.qml b/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardScreenForm.ui.qml index 522ea2bf833277b100aad6cdbb3092d2406d5063..6dce4c8afdb642d71a54a80d2fce80aaccf4a5bc 100644 --- a/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardScreenForm.ui.qml +++ b/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardScreenForm.ui.qml @@ -86,73 +86,42 @@ DapAbstractScreen ListView { + id: listViewWallets anchors.top: titleBlock.bottom anchors.topMargin: 20 * pt anchors.bottom: parent.bottom width: parent.width spacing: 5 * pt clip: true - model: - ListModel - { - ListElement - { - name: "Kelvin Testnet" - address: "KLJHuhlkjshfausdh7865lksfahHKLUIHKJFHKLUESAHFILKUHEWKUAFHjkhfdkslusfkhgs" - money: [ - ListElement - { - type: "bitCoin" - sum: 3487256 - eq: "$ 3498750" - }, - ListElement - { - type: "ether" - sum: 67896 - eq: "$ 78687" - }, - ListElement - { - type: "newGold" - sum: 675573 - eq: "$ 987978" - } - ] - } - ListElement - { - name: "Marketnet" - address: "lkajdsfeislsaIJEUfesIJEFHJISEFIsdfLIJFEISHFUSKEIEWEQLIJSlijfsfjlijeIEJJE" - money: [ - ListElement - { - type: "bitCoin" - sum: 3487256 - eq: "$ 3498750" - }, - ListElement - { - type: "ether" - sum: 67896 - eq: "$ 78687" - }, - ListElement - { - type: "newGold" - sum: 675573 - eq: "$ 987978" - }, - ListElement - { - type: "ether" - sum: 6743896 - eq: "$ 7843687" - } - ] - } - } +// ListModel +// { +// ListElement +// { +// name: "Kelvin Testnet" +// address: "KLJHuhlkjshfausdh7865lksfahHKLUIHKJFHKLUESAHFILKUHEWKUAFHjkhfdkslusfkhgs" +// money: [ +// ListElement +// { +// type: "bitCoin" +// sum: 3487256 +// eq: "$ 3498750" +// }, +// ListElement +// { +// type: "ether" +// sum: 67896 +// eq: "$ 78687" +// }, +// ListElement +// { +// type: "newGold" +// sum: 675573 +// eq: "$ 987978" +// } +// ] +// } +// } delegate: Column @@ -249,7 +218,7 @@ DapAbstractScreen Repeater { width: parent.width - model: money + model: tokens Rectangle { @@ -298,7 +267,7 @@ DapAbstractScreen font.styleName: "Normal" font.weight: Font.Normal color: "#070023" - text: type + text: name } // Delimiters - see design Item @@ -329,7 +298,7 @@ DapAbstractScreen font.styleName: "Normal" font.weight: Font.Normal color: "#070023" - text: sum + text: balance } Text @@ -357,7 +326,7 @@ DapAbstractScreen font.styleName: "Normal" font.weight: Font.Normal color: "#070023" - text: eq + text: emission } } } diff --git a/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTab.qml b/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTab.qml index 197d76d99dd353cb9b7370a970971ef8bfaf5d72..9a490287f05b0fb1ab636eaac4572a1acb0ab892 100644 --- a/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTab.qml +++ b/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTab.qml @@ -14,4 +14,14 @@ DapDashboardTabForm readonly property string lastActionsWallet: "qrc:/screen/" + device + "/Dashboard/RightPanel/DapLastActionsRightPanel.qml" dapDashboardRightPanel.source: Qt.resolvedUrl(lastActionsWallet) + + dapDashboardTopPanel.dapComboboxWallet.onCurrentIndexChanged: + { + dapDashboardScreen.dapListViewWallets.model = modelWallets.get(dapDashboardTopPanel.dapComboboxWallet.currentIndex).networks + } + + ListModel + { + id: modelWallets + } } diff --git a/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTabForm.ui.qml b/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTabForm.ui.qml index 58011df9a412dab28a49d757eb1ef4f063363db4..2ec47ae43bc9074a1dc9a99e2cad8a61b4959751 100644 --- a/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTabForm.ui.qml +++ b/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTabForm.ui.qml @@ -9,6 +9,7 @@ DapAbstractTab property alias dapDashboardRightPanel: rightPanelLoader property alias dapDashboardTopPanel: dashboardTopPanel + property alias dapDashboardScreen: dashboardScreen dapTopPanel: DapDashboardTopPanel @@ -16,7 +17,11 @@ DapAbstractTab id: dashboardTopPanel } - dapScreen: DapDashboardScreen { } + dapScreen: + DapDashboardScreen + { + id: dashboardScreen + } dapRightPanel: Loader diff --git a/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTopPanel.qml b/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTopPanel.qml index 69912e4283fc90127fc451449d872c164bda14b9..facd4f4e6b7567d7fc68326ac71666472c67dd1e 100644 --- a/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTopPanel.qml +++ b/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTopPanel.qml @@ -3,21 +3,9 @@ import Demlabs 1.0 DapDashboardTopPanelForm { - DapWallet - { - id: wal - } property var objectsArray: [] - ListModel - { - id: modelWallets - } - ListModel - { - id: modelTokens - } Connections { @@ -31,20 +19,35 @@ DapDashboardTopPanelForm } onWalletsListReceived: { - objectsArray.push(wal.fromVariant(wallet)) + objectsArray.push(factory.createStructure()) for (var i = 0; i < objectsArray.length; ++i) { -// var str = objectsArray[i].Name + objectsArray[i].Networks + objectsArray[i].getTokens("private").Balance + "\n" - modelWallets.append({ "name" : objectsArray[i].Name}) + modelWallets.append({ "name" : objectsArray[i].Name, + "balance" : objectsArray[i].Balance, + "icon" : objectsArray[i].Icon, + "address" : objectsArray[i].Address, + "networks" : []}) + for (var n = 0; n < Object.keys(objectsArray[i].Networks).length; ++n) + { + modelWallets.get(i).networks.append({"name": objectsArray[i].Networks[n], + "address": objectsArray[i].findAddress(objectsArray[i].Networks[n]), + "tokens": []}) + for (var t = 0; t < Object.keys(objectsArray[i].Tokens).length; ++t) + { + if(objectsArray[i].Tokens[t].Network === objectsArray[i].Networks[n]) + { + modelWallets.get(i).networks.get(n).tokens.append({"name": objectsArray[i].Tokens[t].Name, + "balance": objectsArray[i].Tokens[t].Balance, + "emission": objectsArray[i].Tokens[t].Emission, + "network": objectsArray[i].Tokens[t].Network}) + } + } + + } + } } } - - function updateModel(nameWallet) - { - console.log(nameWallet) - modelWallets.append({ "name" : nameWallet}) - } dapAddWalletButton.onClicked: { diff --git a/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTopPanelForm.ui.qml b/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTopPanelForm.ui.qml index 1a41f58423b1775a93834dfd3c54a0d4276f4405..1a973278bb5ecc845e7714d435dbefd36b93d31f 100644 --- a/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTopPanelForm.ui.qml +++ b/CellFrameDashboardGUI/screen/desktop/Dashboard/DapDashboardTopPanelForm.ui.qml @@ -6,7 +6,7 @@ import "../../" DapAbstractTopPanel { property alias dapAddWalletButton: addWalletButton - + property alias dapComboboxWallet: comboboxWallet anchors.fill: parent // Static text "Wallet" @@ -37,6 +37,7 @@ DapAbstractTopPanel { id: comboboxWallet model: modelWallets + textRole: "name" mainLineText: "all wallets" indicatorImageNormal: "qrc:/res/icons/ic_arrow_drop_down.png" indicatorImageActive: "qrc:/res/icons/ic_arrow_drop_up.png" diff --git a/CellFrameDashboardService/DapServiceController.cpp b/CellFrameDashboardService/DapServiceController.cpp index 51ecd629d00f6750f1dd656e6887dea879ff51ee..4d00cc5622736eeef00986520da763d882eb0ae6 100755 --- a/CellFrameDashboardService/DapServiceController.cpp +++ b/CellFrameDashboardService/DapServiceController.cpp @@ -54,8 +54,14 @@ void DapServiceController::registerCommand() m_pServer->addService(new DapAddWalletCommand("DapAddWalletCommand", m_pServer)); // The command to get a list of available wallets m_pServer->addService(new DapGetListWalletsCommand("DapGetListWalletsCommand", m_pServer)); + // The command to get a list of available networks + m_pServer->addService(new DapGetListNetworksCommand("DapGetListNetworksCommand", m_pServer)); // Saving the file with the logs m_pServer->addService(new DapExportLogCommand("DapExportLogCommand", m_pServer)); + + m_pServer->addService(new DapGetWalletAddressesCommand("DapGetWalletAddressesCommand", m_pServer)); + + m_pServer->addService(new DapGetWalletTokenInfoCommand("DapGetWalletTokenInfoCommand", m_pServer)); } /// Initialize system tray. diff --git a/CellFrameDashboardService/DapServiceController.h b/CellFrameDashboardService/DapServiceController.h index 230f0967c3a262aecd727508e66d070ca08ead04..47fc55c6815714047963932c876692ab25cedf67 100755 --- a/CellFrameDashboardService/DapServiceController.h +++ b/CellFrameDashboardService/DapServiceController.h @@ -29,7 +29,10 @@ typedef class DapRpcLocalServer DapUiService; #include "Handlers/DapUpdateLogsCommand.h" #include "Handlers/DapAddWalletCommand.h" #include "Handlers/DapGetListWalletsCommand.h" +#include "Handlers/DapGetListNetworksCommand.h" +#include "Handlers/DapGetWalletAddressesCommand.h" #include "Handlers/DapExportLogCommand.h" +#include "Handlers/DapGetWalletTokenInfoCommand.h" #include "DapSystemTrayIcon.h" #include "DapToolTipWidget.h" diff --git a/libCellFrameDashboardCommon/DapWallet.cpp b/libCellFrameDashboardCommon/DapWallet.cpp index d29cfc78696e70c736ca119c3a277dcce440b569..33299386a21187102ace835e3ab048b2d141b36e 100644 --- a/libCellFrameDashboardCommon/DapWallet.cpp +++ b/libCellFrameDashboardCommon/DapWallet.cpp @@ -1,25 +1,27 @@ #include "DapWallet.h" -DapWallet::DapWallet(const QString &asName, QObject * parent) - : QObject(parent), m_sName(asName) +DapWallet::DapWallet(QObject * parent) + : QObject(parent) { } -DapWallet::DapWallet(const DapWallet &aToken) - : QObject(parent()), m_sName(aToken.m_sName), m_aNetworks(aToken.m_aNetworks), - m_aAddress(aToken.m_aAddress), m_aTokens(aToken.m_aTokens) +DapWallet::DapWallet(const DapWallet &aWallet) + : m_sName(aWallet.m_sName), m_aNetworks(aWallet.m_aNetworks), + m_aAddresses(aWallet.m_aAddresses), m_aTokens(aWallet.m_aTokens) { } -DapWallet &DapWallet::operator=(const DapWallet &aToken) +DapWallet &DapWallet::operator=(const DapWallet &aWallet) { QObject(parent()); - m_sName = aToken.m_sName; - m_aNetworks = aToken.m_aNetworks; - m_aAddress = aToken.m_aAddress; - m_aTokens = aToken.m_aTokens; + m_sName = aWallet.m_sName; + m_dBalance = aWallet.m_dBalance; + m_sIcon = aWallet.m_sIcon; + m_aNetworks = aWallet.m_aNetworks; + m_aAddresses = aWallet.m_aAddresses; + m_aTokens = aWallet.m_aTokens; return (*this); } @@ -28,76 +30,165 @@ QString DapWallet::getName() const return m_sName; } -void DapWallet::setName(const QString &sName) +void DapWallet::setName(const QString &asName) { - m_sName = sName; + m_sName = asName; emit nameChanged(m_sName); } +double DapWallet::getBalance() const +{ + return m_dBalance; +} + +void DapWallet::setBalance(const double& adBalance) +{ + m_dBalance = adBalance; + + emit balanceChanged(m_dBalance); +} + +QString DapWallet::getIcon() const +{ + return m_sIcon; +} + +void DapWallet::setIcon(const QString &sIcon) +{ + m_sIcon = sIcon; + + emit iconChanged(m_sIcon); +} + void DapWallet::addNetwork(const QString &asNetwork) { m_aNetworks.append(asNetwork); + + emit networkAdded(asNetwork); + emit networksChanged(m_aNetworks); } -QList<QString> &DapWallet::getNetworks() +QStringList DapWallet::getNetworks() const { return m_aNetworks; } -void DapWallet::setAddress(const QString& aiAddress, const QString &asNetwork) +void DapWallet::setAddress(const QString &asNetwork) +{ + m_sAddress = m_aAddresses.find(asNetwork).value(); + + emit addressChanged(m_sAddress); +} + +QString DapWallet::getAddress() const +{ + return m_sAddress; +} + +void DapWallet::addAddress(const QString& aiAddress, const QString &asNetwork) +{ + m_aAddresses.insert(asNetwork, aiAddress); +} + +QString DapWallet::findAddress(const QString &asNetwork) const { - m_aAddress.insert(asNetwork, aiAddress); + return m_aAddresses.find(asNetwork).value(); } -QString DapWallet::getAddress(const QString &asNetwork) +QMap<QString, QString> DapWallet::getAddresses() const { - return m_aAddress.find(asNetwork).value(); + return m_aAddresses; } -void DapWallet::addToken(DapWalletToken aToken) +void DapWallet::addToken(DapWalletToken *asToken) { - m_aTokens.append(aToken); + m_aTokens.append(asToken); + + emit tokenAdded(*asToken); + + QList<QObject*> tokens; + auto begin = m_aTokens.begin(); + auto end = m_aTokens.end(); + for(;begin != end; ++begin) + { + tokens.append(*begin); + } + emit tokensChanged(tokens); } -QList<DapWalletToken *> DapWallet::getTokens(const QString &asNetwork) +QList<DapWalletToken*> DapWallet::findTokens(const QString &asNetwork) { - QList<DapWalletToken *> tokens; + QList<DapWalletToken*> tokens; auto begin = m_aTokens.begin(); auto end = m_aTokens.end(); for(;begin != end; ++begin) { - if(begin->getNetwork() == asNetwork) + if((*begin)->getNetwork() == asNetwork) { - tokens.append(&(*begin)); + tokens.append(*begin); } } return tokens; } -QObject* DapWallet::fromVariant(const QVariant &aWallet) +QList<QObject *> DapWallet::getTokens() const +{ + QList<QObject*> tokens; + auto begin = m_aTokens.begin(); + auto end = m_aTokens.end(); + for(;begin != end; ++begin) + { + tokens.append(*begin); + } + return tokens; +} + +DapWallet DapWallet::fromVariant(const QVariant &aWallet) { - DapWallet * wallet = new DapWallet(); + DapWallet wallet; QByteArray data = QByteArray::fromStdString(aWallet.toString().toStdString()); QDataStream in(&data, QIODevice::ReadOnly); - in >> *wallet; + in >> wallet; return wallet; } QDataStream& operator << (QDataStream& aOut, const DapWallet& aWallet) { - aOut << aWallet.m_sName + QList<DapWalletToken> tokens; + auto begin = aWallet.m_aTokens.begin(); + auto end = aWallet.m_aTokens.end(); + for(;begin != end; ++begin) + tokens.append(**begin); + + QString balance; + balance.setNum(aWallet.m_dBalance); + aOut << aWallet.m_sIcon + << aWallet.m_sAddress << aWallet.m_aNetworks - << aWallet.m_aAddress - << aWallet.m_aTokens; + << aWallet.m_aAddresses + << tokens; return aOut; } -QDataStream& operator >> (QDataStream& aOut, DapWallet& aWallet) +QDataStream& operator >> (QDataStream& aIn, DapWallet& aWallet) { - aOut >> aWallet.m_sName + QString balance; + QList<DapWalletToken> tokens; + aIn >> aWallet.m_sIcon + >> aWallet.m_sAddress >> aWallet.m_aNetworks - >> aWallet.m_aAddress - >> aWallet.m_aTokens; - return aOut; + >> aWallet.m_aAddresses + >> tokens; + aWallet.m_dBalance = balance.toDouble(); + auto begin = tokens.begin(); + auto end = tokens.end(); + for(;begin != end; ++begin) + aWallet.addToken(&(*begin)); + return aIn; +} + +bool operator ==(const DapWallet &aTokenFirst, const DapWallet &aTokenSecond) +{ + return aTokenFirst.m_sName == aTokenSecond.m_sName; } diff --git a/libCellFrameDashboardCommon/DapWallet.h b/libCellFrameDashboardCommon/DapWallet.h index 88a19ac517803ffe34a3ca39fb5e27c078243b01..51c14b6c056d4b2d60f91f90fb394b75cf9be3af 100644 --- a/libCellFrameDashboardCommon/DapWallet.h +++ b/libCellFrameDashboardCommon/DapWallet.h @@ -13,41 +13,61 @@ class DapWallet : public QObject Q_OBJECT QString m_sName; - QList<QString> m_aNetworks; - QMap<QString, QString> m_aAddress; - QList<DapWalletToken> m_aTokens; + double m_dBalance; + QString m_sIcon; + QString m_sAddress = "KLJHuhlkjshfausdh7865lksfahHKLUIHKJFHKLUESAHFILKUHEWKUAFHjkhfdkslusfkhgs"; + QStringList m_aNetworks; + QMap<QString, QString> m_aAddresses; + mutable QList<DapWalletToken*> m_aTokens; public: - Q_INVOKABLE explicit DapWallet(const QString& asName = QString(), QObject * parent = nullptr); - Q_INVOKABLE DapWallet(const DapWallet& aToken); + Q_INVOKABLE explicit DapWallet(QObject * parent = nullptr); + Q_INVOKABLE DapWallet(const DapWallet& aWallet); Q_INVOKABLE DapWallet& operator=(const DapWallet& aToken); + Q_PROPERTY(QString Name MEMBER m_sName READ getName WRITE setName NOTIFY nameChanged) - Q_PROPERTY(QList<QString> Networks MEMBER m_aNetworks READ getNetworks NOTIFY networkAdded) + Q_PROPERTY(double Balance MEMBER m_dBalance READ getBalance WRITE setBalance NOTIFY balanceChanged) + Q_PROPERTY(QString Icon MEMBER m_sIcon READ getIcon WRITE setIcon NOTIFY iconChanged) + Q_PROPERTY(QString Address MEMBER m_sAddress READ getAddress NOTIFY addressChanged) + Q_PROPERTY(QStringList Networks MEMBER m_aNetworks READ getNetworks NOTIFY networksChanged) + Q_PROPERTY(QList<QObject*> Tokens READ getTokens NOTIFY tokensChanged) friend QDataStream& operator << (QDataStream& aOut, const DapWallet& aToken); friend QDataStream& operator >> (QDataStream& aOut, DapWallet& aToken); + friend bool operator == (const DapWallet& aTokenFirst, const DapWallet& aTokenSecond); - Q_INVOKABLE QObject* fromVariant(const QVariant& aWallet); + static DapWallet fromVariant(const QVariant& aWallet); signals: void nameChanged(const QString& asName); - void networkAdded(const QString& asName); + void balanceChanged(const double& adBalance); + void iconChanged(const QString &asIcon); + void addressChanged(const QString& asAddress); + void networkAdded(const QString& asNetwork); + void networksChanged(const QStringList& asNetworks); + void tokensChanged(const QList<QObject*> asTokens); + void tokenAdded(const DapWalletToken& asNetwork); public slots: QString getName() const; - void setName(const QString &sName); + void setName(const QString &asName); + double getBalance() const; + void setBalance(const double& adBalance); + QString getIcon() const; + void setIcon(const QString &sIcon); void addNetwork(const QString& asNetwork); - QList<QString>& getNetworks(); - void setAddress(const QString &aiAddress, const QString& asNetwork); - QString getAddress(const QString& asNetwork); - void addToken(DapWalletToken asName); - QList<DapWalletToken*> getTokens(const QString& asNetwork); - - - + QStringList getNetworks() const; + Q_INVOKABLE void setAddress(const QString& asNetwork); + QString getAddress() const; + void addAddress(const QString &aiAddress, const QString& asNetwork); + Q_INVOKABLE QString findAddress(const QString &asNetwork) const; + QMap<QString, QString> getAddresses() const; + void addToken(DapWalletToken *asToken); + Q_INVOKABLE QList<DapWalletToken*> findTokens(const QString& asNetwork); + Q_INVOKABLE QList<QObject*> getTokens() const; }; Q_DECLARE_METATYPE(DapWallet) diff --git a/libCellFrameDashboardCommon/DapWalletToken.cpp b/libCellFrameDashboardCommon/DapWalletToken.cpp index 3298206e1e33ecbdde71873363df89d6ec05d35d..58f3d998ccf6825f676d3c98bb4ae81bfc5a0268 100644 --- a/libCellFrameDashboardCommon/DapWalletToken.cpp +++ b/libCellFrameDashboardCommon/DapWalletToken.cpp @@ -3,7 +3,7 @@ DapWalletToken::DapWalletToken(const QString &asName, QObject *parent) : QObject(parent), m_sName(asName) { - + } DapWalletToken::DapWalletToken(const DapWalletToken &aToken) @@ -79,6 +79,18 @@ void DapWalletToken::setNetwork(const QString &sNetwork) emit networkChanged(m_sNetwork); } +QString DapWalletToken::getIcon() const +{ + return m_sIcon; +} + +void DapWalletToken::setIcon(const QString &sIcon) +{ + m_sIcon = sIcon; + + emit iconChanged(m_sIcon); +} + QDataStream& operator << (QDataStream& aOut, const DapWalletToken& aToken) { QString balance; diff --git a/libCellFrameDashboardCommon/DapWalletToken.h b/libCellFrameDashboardCommon/DapWalletToken.h index 92e9e6d7d5af5be9d0d2e02cc260a8a91716afe9..5de45c4f30422415184db6f5d4c373205c62bd54 100644 --- a/libCellFrameDashboardCommon/DapWalletToken.h +++ b/libCellFrameDashboardCommon/DapWalletToken.h @@ -17,6 +17,8 @@ class DapWalletToken : public QObject quint64 m_iEmission {0}; /// Network. QString m_sNetwork; + /// Icon path. + QString m_sIcon; public: explicit DapWalletToken(const QString& asName = QString(), QObject *parent = nullptr); @@ -28,6 +30,7 @@ public: Q_PROPERTY(double Balance MEMBER m_dBalance READ getBalance WRITE setBalance NOTIFY balanceChanged) Q_PROPERTY(quint64 Emission MEMBER m_iEmission READ getEmission WRITE setEmission NOTIFY emissionChanged) Q_PROPERTY(QString Network MEMBER m_sNetwork READ getNetwork WRITE setNetwork NOTIFY networkChanged) + Q_PROPERTY(QString Icon MEMBER m_sIcon READ getIcon WRITE setIcon NOTIFY iconChanged) friend QDataStream& operator << (QDataStream& aOut, const DapWalletToken& aToken); @@ -38,6 +41,7 @@ signals: void balanceChanged(const double & adBalance); void emissionChanged(const qint64& aiEmission); void networkChanged(const QString &asNetwork); + void iconChanged(const QString &asIcon); public slots: QString getName() const; @@ -48,6 +52,8 @@ public slots: void setEmission(const quint64 &iEmission); QString getNetwork() const; void setNetwork(const QString &sNetwork); + QString getIcon() const; + void setIcon(const QString &sIcon); }; Q_DECLARE_METATYPE(DapWalletToken) diff --git a/libCellFrameDashboardCommon/Handlers/DapAbstractCommand.cpp b/libCellFrameDashboardCommon/Handlers/DapAbstractCommand.cpp index ce4185bd718c52bad0b0088c16a20e0609945ab2..ad310790a8605a7d228d1be2e5c1b0fafe69e804 100644 --- a/libCellFrameDashboardCommon/Handlers/DapAbstractCommand.cpp +++ b/libCellFrameDashboardCommon/Handlers/DapAbstractCommand.cpp @@ -221,8 +221,11 @@ QVariant DapAbstractCommand::respondToClient(const QVariant &arg1, const QVarian /// Reply from service. /// @details Performed on the service side. /// @return Service reply. -void DapAbstractCommand::replyFromService() +QVariant DapAbstractCommand::replyFromService() { DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender()); + emit serviceResponded(reply->response().toJsonValue().toVariant()); + + return reply->response().toJsonValue().toVariant(); } diff --git a/libCellFrameDashboardCommon/Handlers/DapAbstractCommand.h b/libCellFrameDashboardCommon/Handlers/DapAbstractCommand.h index aabd1cccc8f887212d7e3d44a780dde1aa6de23f..d0a46e9061e84015199c01441c7c03044508f4cb 100644 --- a/libCellFrameDashboardCommon/Handlers/DapAbstractCommand.h +++ b/libCellFrameDashboardCommon/Handlers/DapAbstractCommand.h @@ -24,8 +24,6 @@ class DapAbstractCommand : public DapCommand protected: /// Parent. QObject * m_parent {nullptr}; - -public: /// Overloaded constructor. /// @param asServiceName Service name. /// @param parent Parent. @@ -131,7 +129,7 @@ public slots: /// Reply from service. /// @details Performed on the service side. /// @return Service reply. - virtual void replyFromService(); + virtual QVariant replyFromService(); }; #endif // DAPABSTRACTCOMMAND_H diff --git a/libCellFrameDashboardCommon/Handlers/DapGetListNetworksCommand.cpp b/libCellFrameDashboardCommon/Handlers/DapGetListNetworksCommand.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8498b3a238aa7d96af4b49aa7c5d6e233366c62f --- /dev/null +++ b/libCellFrameDashboardCommon/Handlers/DapGetListNetworksCommand.cpp @@ -0,0 +1,42 @@ +#include "DapGetListNetworksCommand.h" + +/// Overloaded constructor. +/// @param asServiceName Service name. +/// @param parent Parent. +/// @details The parent must be either DapRPCSocket or DapRPCLocalServer. +DapGetListNetworksCommand::DapGetListNetworksCommand(const QString &asServicename, QObject *parent) + : DapAbstractCommand(asServicename, parent) +{ + +} + +/// Send a response to the client. +/// @details Performed on the service side. +/// @param arg1...arg10 Parameters. +/// @return Reply to client. +QVariant DapGetListNetworksCommand::respondToClient(const QVariant &arg1, const QVariant &arg2, const QVariant &arg3, const QVariant &arg4, const QVariant &arg5, const QVariant &arg6, const QVariant &arg7, const QVariant &arg8, const QVariant &arg9, const QVariant &arg10) +{ + Q_UNUSED(arg1) + Q_UNUSED(arg2) + Q_UNUSED(arg3) + Q_UNUSED(arg4) + Q_UNUSED(arg5) + Q_UNUSED(arg6) + Q_UNUSED(arg7) + Q_UNUSED(arg8) + Q_UNUSED(arg9) + Q_UNUSED(arg10) + + QStringList networkList; + QProcess process; + process.start(QString("%1 net list").arg(CLI_PATH)); + process.waitForFinished(-1); + QString result = QString::fromLatin1(process.readAll()); + result.remove(' '); + if(!(result.isEmpty() || result.isNull())) + { + QStringList str = result.remove("\n").remove("\r").split(":").at(1).split(","); + return str; + } + return QString(); +} diff --git a/libCellFrameDashboardCommon/Handlers/DapGetListNetworksCommand.h b/libCellFrameDashboardCommon/Handlers/DapGetListNetworksCommand.h new file mode 100644 index 0000000000000000000000000000000000000000..b02d43f8865d7192e2e8d1d918971418c0360a41 --- /dev/null +++ b/libCellFrameDashboardCommon/Handlers/DapGetListNetworksCommand.h @@ -0,0 +1,29 @@ +#ifndef DAPGETLISTNETWORKSCOMMAND_H +#define DAPGETLISTNETWORKSCOMMAND_H + +#include <QProcess> + +#include "DapAbstractCommand.h" + +class DapGetListNetworksCommand : public DapAbstractCommand +{ +public: + /// Overloaded constructor. + /// @param asServiceName Service name. + /// @param parent Parent. + /// @details The parent must be either DapRPCSocket or DapRPCLocalServer. + DapGetListNetworksCommand(const QString &asServicename, QObject *parent = nullptr); + +public slots: + /// Send a response to the client. + /// @details Performed on the service side. + /// @param arg1...arg10 Parameters. + /// @return Reply to client. + QVariant respondToClient(const QVariant &arg1 = QVariant(), const QVariant &arg2 = QVariant(), + const QVariant &arg3 = QVariant(), const QVariant &arg4 = QVariant(), + const QVariant &arg5 = QVariant(), const QVariant &arg6 = QVariant(), + const QVariant &arg7 = QVariant(), const QVariant &arg8 = QVariant(), + const QVariant &arg9 = QVariant(), const QVariant &arg10 = QVariant()) override; +}; + +#endif // DAPGETLISTNETWORKSCOMMAND_H diff --git a/libCellFrameDashboardCommon/Handlers/DapGetListWalletsCommand.cpp b/libCellFrameDashboardCommon/Handlers/DapGetListWalletsCommand.cpp index 65e3211e4b3a406fabda00a6c0dc96b08fade8da..737c03a8041d4cdf23f2015fa32a390a377d723d 100644 --- a/libCellFrameDashboardCommon/Handlers/DapGetListWalletsCommand.cpp +++ b/libCellFrameDashboardCommon/Handlers/DapGetListWalletsCommand.cpp @@ -30,11 +30,12 @@ QVariant DapGetListWalletsCommand::respondToClient(const QVariant &arg1, const Q Q_UNUSED(arg9) Q_UNUSED(arg10) - DapWallet wallet("MyWallet5"); + DapWallet wallet; + wallet.setName("MyWallet5"); wallet.addNetwork("Kelvin-testnet"); wallet.addNetwork("Private"); - wallet.setAddress("ar4th4t4j6tyj7utjk45u654kuj4kl6ui4l54k5lu5u4il5i34l35", "Kelvin-testnet"); - wallet.setAddress("ar4th4t4j6tyj7utjk45u654kuj4kl6ui4l54k5lu5u4il5i34l35", "Private"); + wallet.addAddress("ar4th4t4j6tyj7utjk45u654kuj4kl6ui4l54k5lu5u4il5i34l35", "Kelvin-testnet"); + wallet.addAddress("ar4th4t4j6tyj7utjk45u654kuj4kl6ui4l54k5lu5u4il5i34l35", "Private"); DapWalletToken token1("KLV", &wallet); token1.setBalance(5.5); token1.setNetwork("Kelvin-testnet"); @@ -43,8 +44,8 @@ QVariant DapGetListWalletsCommand::respondToClient(const QVariant &arg1, const Q token2.setBalance(100); token2.setNetwork("Private"); token2.setEmission(121212121); - wallet.addToken(token1); - wallet.addToken(token2); + wallet.addToken(&token1); + wallet.addToken(&token2); QByteArray datas; QDataStream out(&datas, QIODevice::WriteOnly); diff --git a/libCellFrameDashboardCommon/Handlers/DapGetWalletAddressesCommand.cpp b/libCellFrameDashboardCommon/Handlers/DapGetWalletAddressesCommand.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cc42b0be9a084eda789e2ceacef1dae432c33c5d --- /dev/null +++ b/libCellFrameDashboardCommon/Handlers/DapGetWalletAddressesCommand.cpp @@ -0,0 +1,68 @@ +#include "DapGetWalletAddressesCommand.h" + +/// Overloaded constructor. +/// @param asServiceName Service name. +/// @param parent Parent. +/// @details The parent must be either DapRPCSocket or DapRPCLocalServer. +DapGetWalletAddressesCommand::DapGetWalletAddressesCommand(const QString &asServicename, QObject *parent) + : DapAbstractCommand(asServicename, parent) +{ + +} + +/// Send request to service. +/// @details Performed on the client side. +/// @param arg1...arg10 Parameters. +void DapGetWalletAddressesCommand::requestToService(const QVariant &arg1, const QVariant &arg2, const QVariant &arg3, + const QVariant &arg4, const QVariant &arg5, + const QVariant &arg6, const QVariant &arg7, + const QVariant &arg8, const QVariant &arg9, + const QVariant &arg10) +{ + + DapAbstractCommand::requestToService(arg1, arg2.toStringList(), arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); +} + +/// Send a response to the client. +/// @details Performed on the service side. +/// @param arg1...arg10 Parameters. +/// @return Reply to client. +QVariant DapGetWalletAddressesCommand::respondToClient(const QVariant &arg1, const QVariant &arg2, const QVariant &arg3, const QVariant &arg4, const QVariant &arg5, const QVariant &arg6, const QVariant &arg7, const QVariant &arg8, const QVariant &arg9, const QVariant &arg10) +{ + Q_UNUSED(arg2) + Q_UNUSED(arg3) + Q_UNUSED(arg4) + Q_UNUSED(arg5) + Q_UNUSED(arg6) + Q_UNUSED(arg7) + Q_UNUSED(arg8) + Q_UNUSED(arg9) + Q_UNUSED(arg10) + + QStringList walletAddress; + QStringList networkList = arg2.toStringList(); + if(!networkList.isEmpty()) + { + for(int i{0}; i < networkList.count(); ++i) + { + QProcess process; + process.start(QString("%1 wallet info -w %2 -net %3").arg(CLI_PATH).arg(arg1.toString()).arg(networkList[i])); + process.waitForFinished(-1); + QByteArray result = process.readAll(); + QRegExp regex("wallet: (.+)\\s+addr:\\s+(.+)\\s+(balance)|(\\d+.\\d+)\\s\\((\\d+)\\)\\s(\\w+)"); + + int pos = 0; + while((pos = regex.indexIn(result, pos)) != -1) + { + if(!regex.cap(2).isEmpty()) + { + walletAddress.append(networkList[i]); + walletAddress.append(regex.cap(2)); + } + pos += regex.matchedLength(); + } + } + } + + return walletAddress; +} diff --git a/libCellFrameDashboardCommon/Handlers/DapGetWalletAddressesCommand.h b/libCellFrameDashboardCommon/Handlers/DapGetWalletAddressesCommand.h new file mode 100644 index 0000000000000000000000000000000000000000..adb8541f0be4b76ad7bdeef41de8f7a51fa55607 --- /dev/null +++ b/libCellFrameDashboardCommon/Handlers/DapGetWalletAddressesCommand.h @@ -0,0 +1,38 @@ +#ifndef DAPGETWALLETADDRESSESCOMMAND_H +#define DAPGETWALLETADDRESSESCOMMAND_H + +#include <QProcess> + +#include "DapAbstractCommand.h" + +class DapGetWalletAddressesCommand : public DapAbstractCommand +{ +public: + /// Overloaded constructor. + /// @param asServiceName Service name. + /// @param parent Parent. + /// @details The parent must be either DapRPCSocket or DapRPCLocalServer. + DapGetWalletAddressesCommand(const QString &asServicename, QObject *parent = nullptr); + +public slots: + /// Send request to service. + /// @details Performed on the client side. + /// @param arg1...arg10 Parameters. + Q_INVOKABLE virtual void requestToService(const QVariant &arg1 = QVariant(), + const QVariant &arg2 = QVariant(), const QVariant &arg3 = QVariant(), + const QVariant &arg4 = QVariant(), const QVariant &arg5 = QVariant(), + const QVariant &arg6 = QVariant(), const QVariant &arg7 = QVariant(), + const QVariant &arg8 = QVariant(), const QVariant &arg9 = QVariant(), + const QVariant &arg10 = QVariant()) override; + /// Send a response to the client. + /// @details Performed on the service side. + /// @param arg1...arg10 Parameters. + /// @return Reply to client. + QVariant respondToClient(const QVariant &arg1 = QVariant(), const QVariant &arg2 = QVariant(), + const QVariant &arg3 = QVariant(), const QVariant &arg4 = QVariant(), + const QVariant &arg5 = QVariant(), const QVariant &arg6 = QVariant(), + const QVariant &arg7 = QVariant(), const QVariant &arg8 = QVariant(), + const QVariant &arg9 = QVariant(), const QVariant &arg10 = QVariant()) override; +}; + +#endif // DAPGETWALLETADDRESSESCOMMAND_H diff --git a/libCellFrameDashboardCommon/Handlers/DapGetWalletTokenInfoCommand.cpp b/libCellFrameDashboardCommon/Handlers/DapGetWalletTokenInfoCommand.cpp new file mode 100644 index 0000000000000000000000000000000000000000..276ce00443d300e8b39d6cf662efab5761a39be7 --- /dev/null +++ b/libCellFrameDashboardCommon/Handlers/DapGetWalletTokenInfoCommand.cpp @@ -0,0 +1,53 @@ +#include "DapGetWalletTokenInfoCommand.h" + +/// Overloaded constructor. +/// @param asServiceName Service name. +/// @param parent Parent. +/// @details The parent must be either DapRPCSocket or DapRPCLocalServer. +DapGetWalletTokenInfoCommand::DapGetWalletTokenInfoCommand(const QString &asServicename, QObject *parent) + : DapAbstractCommand(asServicename, parent) +{ + +} + +/// Send a response to the client. +/// @details Performed on the service side. +/// @param arg1...arg10 Parameters. +/// @return Reply to client. +QVariant DapGetWalletTokenInfoCommand::respondToClient(const QVariant &arg1, const QVariant &arg2, const QVariant &arg3, const QVariant &arg4, const QVariant &arg5, const QVariant &arg6, const QVariant &arg7, const QVariant &arg8, const QVariant &arg9, const QVariant &arg10) +{ + Q_UNUSED(arg2) + Q_UNUSED(arg3) + Q_UNUSED(arg4) + Q_UNUSED(arg5) + Q_UNUSED(arg6) + Q_UNUSED(arg7) + Q_UNUSED(arg8) + Q_UNUSED(arg9) + Q_UNUSED(arg10) + + QStringList token; + if(!(arg1.toString().isEmpty() || arg1.toString().isNull() + || arg2.toString().isEmpty() || arg2.toString().isNull())) + { + QProcess process; + process.start(QString("%1 wallet info -w %2 -net %3").arg(CLI_PATH).arg(arg1.toString()).arg(arg2.toString())); + process.waitForFinished(-1); + QByteArray result = process.readAll(); + QRegExp regex("wallet: (.+)\\s+addr:\\s+(.+)\\s+(balance)|(\\d+.\\d+)\\s\\((\\d+)\\)\\s(\\w+)"); + + int pos = 0; + while((pos = regex.indexIn(result, pos)) != -1) + { + if(regex.cap(2).isEmpty()) + { + token.append(regex.cap(6)); + token.append(regex.cap(4)); + token.append(regex.cap(5)); + } + pos += regex.matchedLength(); + } + } + + return token; +} diff --git a/libCellFrameDashboardCommon/Handlers/DapGetWalletTokenInfoCommand.h b/libCellFrameDashboardCommon/Handlers/DapGetWalletTokenInfoCommand.h new file mode 100644 index 0000000000000000000000000000000000000000..2ceaf209e90e25d93924d28e09ac1157dfc08059 --- /dev/null +++ b/libCellFrameDashboardCommon/Handlers/DapGetWalletTokenInfoCommand.h @@ -0,0 +1,30 @@ +#ifndef DAPGETWALLETTOKENINFOCOMMAND_H +#define DAPGETWALLETTOKENINFOCOMMAND_H + +#include <QProcess> +#include <QRegExp> + +#include "DapAbstractCommand.h" + +class DapGetWalletTokenInfoCommand : public DapAbstractCommand +{ +public: + /// Overloaded constructor. + /// @param asServiceName Service name. + /// @param parent Parent. + /// @details The parent must be either DapRPCSocket or DapRPCLocalServer. + DapGetWalletTokenInfoCommand(const QString &asServicename, QObject *parent = nullptr); + +public slots: + /// Send a response to the client. + /// @details Performed on the service side. + /// @param arg1...arg10 Parameters. + /// @return Reply to client. + QVariant respondToClient(const QVariant &arg1 = QVariant(), const QVariant &arg2 = QVariant(), + const QVariant &arg3 = QVariant(), const QVariant &arg4 = QVariant(), + const QVariant &arg5 = QVariant(), const QVariant &arg6 = QVariant(), + const QVariant &arg7 = QVariant(), const QVariant &arg8 = QVariant(), + const QVariant &arg9 = QVariant(), const QVariant &arg10 = QVariant()) override; +}; + +#endif // DAPGETWALLETTOKENINFOCOMMAND_H diff --git a/libCellFrameDashboardCommon/Handlers/DapUpdateLogsCommand.cpp b/libCellFrameDashboardCommon/Handlers/DapUpdateLogsCommand.cpp index e4ffd9a3c644e602ad9d038fd5f1d8923fb9bc41..bbd3e08859fb0cd0fb0afcb8496307bfe896a190 100644 --- a/libCellFrameDashboardCommon/Handlers/DapUpdateLogsCommand.cpp +++ b/libCellFrameDashboardCommon/Handlers/DapUpdateLogsCommand.cpp @@ -125,8 +125,11 @@ void DapUpdateLogsCommand::dapGetLog() /// Reply from service. /// @details Performed on the service side. /// @return Service reply. -void DapUpdateLogsCommand::replyFromService() +QVariant DapUpdateLogsCommand::replyFromService() { DapRpcServiceReply *reply = static_cast<DapRpcServiceReply *>(sender()); + emit serviceResponded(reply->response().toJsonValue()); + + return reply->response().toJsonValue(); } diff --git a/libCellFrameDashboardCommon/Handlers/DapUpdateLogsCommand.h b/libCellFrameDashboardCommon/Handlers/DapUpdateLogsCommand.h index 37d93fa8ea35c7796f5e6b378d0d37569e993951..8cd0223db0d85127329da7ee8276deebb1b41e82 100644 --- a/libCellFrameDashboardCommon/Handlers/DapUpdateLogsCommand.h +++ b/libCellFrameDashboardCommon/Handlers/DapUpdateLogsCommand.h @@ -63,7 +63,7 @@ public slots: /// Reply from service. /// @details Performed on the service side. /// @return Service reply. - virtual void replyFromService(); + virtual QVariant replyFromService(); }; #endif // DAPUPDATELOGSCOMMAND_H diff --git a/libCellFrameDashboardCommon/Models/DapWalletModel.cpp b/libCellFrameDashboardCommon/Models/DapWalletModel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b794f8f0ff592c076a3103ca8012f573c9a1683e --- /dev/null +++ b/libCellFrameDashboardCommon/Models/DapWalletModel.cpp @@ -0,0 +1,129 @@ +#include "DapWalletModel.h" + +DapWalletModel::DapWalletModel(QObject *parent) + : QAbstractListModel(parent) +{ + +} + +DapWalletModel &DapWalletModel::getInstance() +{ + static DapWalletModel instance; + return instance; +} + +int DapWalletModel::rowCount(const QModelIndex &parent) const +{ + Q_UNUSED(parent); + + return m_aWallets.count(); +} + +QVariant DapWalletModel::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + return QVariant(); + + switch (role) + { + case NameDisplayRole: return m_aWallets[index.row()].getName(); + case BalanceDisplayRole: return m_aWallets[index.row()].getBalance(); + case AddressDisplayRole: return m_aWallets[index.row()].getAddress(); + case IconDisplayRole: return m_aWallets[index.row()].getIcon(); + case NetworksDisplayRole: return m_aWallets[index.row()].getNetworks(); + case TokensDisplayRole: + return QVariant::fromValue<QList<QObject*>>(getTokens(index.row())); + case WalletsDisplayRole: return getWalletList(); + default: break; + } + + return QVariant(); +} + +QList<QObject*> DapWalletModel::getTokens(const int aIndex) const +{ + QList<QObject*> tokens; + auto cbegin = m_aWallets[aIndex].getTokens().cbegin(); + auto cend = m_aWallets[aIndex].getTokens().cend(); + for(; cbegin != cend; ++ cbegin) + tokens.append(*cbegin); + + return tokens; +} + +QStringList DapWalletModel::getWalletList() const +{ + QStringList walletList; + foreach (auto wallet, m_aWallets) + { + walletList.append(wallet.getName()); + } + return walletList; +} + +void DapWalletModel::appendWallet(const DapWallet &aWallet) +{ + m_aWallets.append(aWallet); + + emit walletListChanged(getWalletList()); + + int lastIndex = m_aWallets.count() - 1; + beginInsertRows(QModelIndex(), lastIndex, lastIndex); + endInsertRows(); +} + +void DapWalletModel::appendToken(const QString &asWalletAddress, DapWalletToken* aToken) +{ + auto wallet = std::find_if(m_aWallets.begin(), m_aWallets.end(), [=] (const DapWallet& aWallet) + { + return aWallet.getAddresses().values().contains(asWalletAddress); + }); + + return wallet->addToken(aToken); +} + +void DapWalletModel::removeWallet(const QString &asWalletAddress) +{ + int removeIndex = -1; + auto wallet = std::find_if(m_aWallets.cbegin(), m_aWallets.cend(), [=] (const DapWallet& aWallet) + { + return aWallet.getAddresses().values().contains(asWalletAddress); + }); + removeIndex = m_aWallets.indexOf(*wallet); + m_aWallets.removeAt(removeIndex); + + emit walletListChanged(getWalletList()); + + if(removeIndex == -1) + return; + beginRemoveRows(QModelIndex(), removeIndex, removeIndex); + endRemoveRows(); +} + +void DapWalletModel::removeWallet(const int aWalletIndex) +{ + if(aWalletIndex >= m_aWallets.count() || m_aWallets.count() < aWalletIndex) + return; + beginRemoveRows(QModelIndex(), aWalletIndex, aWalletIndex); + m_aWallets.removeAt(aWalletIndex); + + emit walletListChanged(getWalletList()); + + endRemoveRows(); +} + +QHash<int, QByteArray> DapWalletModel::roleNames() const +{ + static const QHash<int, QByteArray> roles + { + { NameDisplayRole, "name" }, + { BalanceDisplayRole, "balance" }, + { AddressDisplayRole, "address" }, + { IconDisplayRole, "iconPath" }, + { NetworksDisplayRole, "networks" }, + { TokensDisplayRole, "tokens" }, + { WalletsDisplayRole, "walletList" } + }; + + return roles; +} diff --git a/libCellFrameDashboardCommon/Models/DapWalletModel.h b/libCellFrameDashboardCommon/Models/DapWalletModel.h new file mode 100644 index 0000000000000000000000000000000000000000..5819271bb2aca1f2abd8fa7760be84f64248ae79 --- /dev/null +++ b/libCellFrameDashboardCommon/Models/DapWalletModel.h @@ -0,0 +1,57 @@ +#ifndef DAPWALLETMODEL_H +#define DAPWALLETMODEL_H + +#include <QObject> +#include <QAbstractListModel> +#include <algorithm> +#include <QList> + +#include "DapWallet.h" + +class DapWalletModel : public QAbstractListModel +{ + Q_OBJECT + + QList<DapWallet> m_aWallets; + + explicit DapWalletModel(QObject *parent = nullptr); + +public: + Q_PROPERTY(QStringList WalletList READ getWalletList NOTIFY walletListChanged) + + enum DapWalletRole + { + NameDisplayRole = Qt::UserRole, + AddressDisplayRole, + BalanceDisplayRole, + IconDisplayRole, + NetworksDisplayRole, + TokensDisplayRole, + WalletsDisplayRole + }; + Q_ENUM(DapWalletRole) + + static DapWalletModel& getInstance(); + + int rowCount(const QModelIndex &parent = QModelIndex()) const override; + + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + + QHash<int, QByteArray> roleNames() const override; + + QList<QObject*> getTokens(const int aIndex) const; + + QStringList getWalletList() const; + +signals: + void walletListChanged(const QStringList& aWalletList); + +public slots: + + Q_INVOKABLE void appendWallet(const DapWallet& aWallet); + Q_INVOKABLE void appendToken(const QString& asWalletAddress, DapWalletToken* aToken); + Q_INVOKABLE void removeWallet(const QString& asWalletAddress); + Q_INVOKABLE void removeWallet(const int aWalletIndex); +}; + +#endif // DAPWALLETMODEL_H diff --git a/libCellFrameDashboardCommon/libCellFrameDashboardCommon.pri b/libCellFrameDashboardCommon/libCellFrameDashboardCommon.pri index ad96da03d85a27c1b35e36bb198c4d1ae9c43d51..6425cb345fd2cdc472cfd491b843c491048d45ab 100755 --- a/libCellFrameDashboardCommon/libCellFrameDashboardCommon.pri +++ b/libCellFrameDashboardCommon/libCellFrameDashboardCommon.pri @@ -23,11 +23,15 @@ SOURCES +=\ $$PWD/DapWalletToken.cpp \ $$PWD/Handlers/DapAbstractCommand.cpp \ $$PWD/Handlers/DapActivateClientCommand.cpp \ + $$PWD/Handlers/DapGetListNetworksCommand.cpp \ $$PWD/Handlers/DapGetListWalletsCommand.cpp \ $$PWD/Handlers/DapExportLogCommand.cpp \ + $$PWD/Handlers/DapGetWalletAddressesCommand.cpp \ + $$PWD/Handlers/DapGetWalletTokenInfoCommand.cpp \ $$PWD/Handlers/DapQuitApplicationCommand.cpp \ $$PWD/Handlers/DapAddWalletCommand.cpp \ - $$PWD/Handlers/DapUpdateLogsCommand.cpp + $$PWD/Handlers/DapUpdateLogsCommand.cpp \ + $$PWD/Models/DapWalletModel.cpp HEADERS +=\ $$PWD/DapChainConvertor.h \ @@ -41,8 +45,12 @@ HEADERS +=\ $$PWD/DapWalletToken.h \ $$PWD/Handlers/DapAbstractCommand.h \ $$PWD/Handlers/DapActivateClientCommand.h \ + $$PWD/Handlers/DapGetListNetworksCommand.h \ $$PWD/Handlers/DapGetListWalletsCommand.h \ $$PWD/Handlers/DapExportLogCommand.h \ + $$PWD/Handlers/DapGetWalletAddressesCommand.h \ + $$PWD/Handlers/DapGetWalletTokenInfoCommand.h \ $$PWD/Handlers/DapQuitApplicationCommand.h \ $$PWD/Handlers/DapAddWalletCommand.h \ - $$PWD/Handlers/DapUpdateLogsCommand.h + $$PWD/Handlers/DapUpdateLogsCommand.h \ + $$PWD/Models/DapWalletModel.h