diff --git a/.clang-format b/.clang-format index 5f2656813..20f071dc7 100644 --- a/.clang-format +++ b/.clang-format @@ -10,7 +10,7 @@ BasedOnStyle: WebKit TabWidth: 4 IndentWidth: 4 -UseTab: Always +UseTab: Never ColumnLimit: 120 # Other languages JavaScript, Proto diff --git a/src-cpp/app/boot/app_controller.cpp b/src-cpp/app/boot/app_controller.cpp index 624998389..ffe92e7f0 100644 --- a/src-cpp/app/boot/app_controller.cpp +++ b/src-cpp/app/boot/app_controller.cpp @@ -1,8 +1,8 @@ #include "app_controller.h" #include "accounts/service.h" #include "app_service.h" -#include "modules/startup/module.h" #include "modules/main/module.h" +#include "modules/startup/module.h" #include AppController::AppController() @@ -68,32 +68,32 @@ AppController::AppController() m_startupModule = new Modules::Startup::Module(this, /*keychainService,*/ m_accountsService); m_mainModulePtr = new Modules::Main::Module(m_walletServicePtr, this); - // statusFoundation.status.events, - // result.keychainService, - // result.accountsService, - // result.chatService, - // result.communityService, - // result.messageService, - // result.tokenService, - // result.transactionService, - // result.collectibleService, - // result.walletAccountService, - // result.bookmarkService, - // result.profileService, - // result.settingsService, - // result.contactsService, - // result.aboutService, - // result.dappPermissionsService, - // result.languageService, - // # result.mnemonicService, - // result.privacyService, - // result.providerService, - // result.stickersService, - // result.activityCenterService, - // result.savedAddressService, - // result.nodeConfigurationService, - // result.devicesService, - // result.mailserversService + // statusFoundation.status.events, + // result.keychainService, + // result.accountsService, + // result.chatService, + // result.communityService, + // result.messageService, + // result.tokenService, + // result.transactionService, + // result.collectibleService, + // result.walletAccountService, + // result.bookmarkService, + // result.profileService, + // result.settingsService, + // result.contactsService, + // result.aboutService, + // result.dappPermissionsService, + // result.languageService, + // # result.mnemonicService, + // result.privacyService, + // result.providerService, + // result.stickersService, + // result.activityCenterService, + // result.savedAddressService, + // result.nodeConfigurationService, + // result.devicesService, + // result.mailserversService // # Do connections connect(); @@ -174,13 +174,13 @@ void AppController::load() // # load main module m_mainModulePtr->load( - // self.statusFoundation.status.events, - // self.settingsService, - // self.contactsService, - // self.chatService, - // self.communityService, - // self.messageService - ); + // self.statusFoundation.status.events, + // self.settingsService, + // self.contactsService, + // self.chatService, + // self.communityService, + // self.messageService + ); } void AppController::userLoggedIn() diff --git a/src-cpp/app/boot/app_controller.h b/src-cpp/app/boot/app_controller.h index 3c2822834..6941c6119 100644 --- a/src-cpp/app/boot/app_controller.h +++ b/src-cpp/app/boot/app_controller.h @@ -3,12 +3,12 @@ #include -#include "accounts/service.h" -#include "wallet_accounts/service.h" #include "../modules/main/interfaces/module_access_interface.h" #include "../modules/startup/module_access_interface.h" +#include "accounts/service.h" #include "app_controller_delegate.h" #include "app_service.h" +#include "wallet_accounts/service.h" class AppController : public QObject, AppControllerDelegate { @@ -37,6 +37,7 @@ public: void start(); public slots: void mainDidLoad(); + private: void connect(); void startupDidLoad() override; diff --git a/src-cpp/app/boot/app_controller_delegate.h b/src-cpp/app/boot/app_controller_delegate.h index 2aee0fa82..378c42e3f 100644 --- a/src-cpp/app/boot/app_controller_delegate.h +++ b/src-cpp/app/boot/app_controller_delegate.h @@ -3,7 +3,7 @@ class AppControllerDelegate { public: - virtual void startupDidLoad() = 0; + virtual void startupDidLoad() = 0; - virtual void userLoggedIn() = 0; + virtual void userLoggedIn() = 0; }; diff --git a/src-cpp/app/core/signals/signals.cpp b/src-cpp/app/core/signals/signals.cpp index 5231f6473..de3fd2924 100644 --- a/src-cpp/app/core/signals/signals.cpp +++ b/src-cpp/app/core/signals/signals.cpp @@ -13,79 +13,79 @@ Manager* Manager::theInstance; Manager* Manager::instance() { - if(theInstance == 0) theInstance = new Manager(); - return theInstance; + if(theInstance == 0) theInstance = new Manager(); + return theInstance; } std::map Manager::signalMap; Manager::Manager(QObject* parent) - : QObject(parent) + : QObject(parent) { - SetSignalEventCallback((void*)&Manager::signalCallback); + SetSignalEventCallback((void*)&Manager::signalCallback); - signalMap = {{"node.ready", SignalType::NodeReady}, - {"node.started", SignalType::NodeStarted}, - {"node.stopped", SignalType::NodeStopped}, - {"node.login", SignalType::NodeLogin}, - {"node.crashed", SignalType::NodeCrashed}}; + signalMap = {{"node.ready", SignalType::NodeReady}, + {"node.started", SignalType::NodeStarted}, + {"node.stopped", SignalType::NodeStopped}, + {"node.login", SignalType::NodeLogin}, + {"node.crashed", SignalType::NodeCrashed}}; } void Manager::processSignal(QString statusSignal) { - try - { - QJsonParseError json_error; - const QJsonDocument signalEventDoc(QJsonDocument::fromJson(statusSignal.toUtf8(), &json_error)); - if(json_error.error != QJsonParseError::NoError) - { - qWarning() << "Invalid signal received"; - return; - } - decode(signalEventDoc.object()); - } - catch(const std::exception& e) - { - qWarning() << "Error decoding signal, err: ", e.what(); - return; - } + try + { + QJsonParseError json_error; + const QJsonDocument signalEventDoc(QJsonDocument::fromJson(statusSignal.toUtf8(), &json_error)); + if(json_error.error != QJsonParseError::NoError) + { + qWarning() << "Invalid signal received"; + return; + } + decode(signalEventDoc.object()); + } + catch(const std::exception& e) + { + qWarning() << "Error decoding signal, err: ", e.what(); + return; + } } void Manager::decode(const QJsonObject& signalEvent) { - SignalType signalType(Unknown); - if(!signalMap.count(signalEvent["type"].toString())) - { - qWarning() << "Unknown signal received: " << signalEvent["type"].toString(); - return; - } + SignalType signalType(Unknown); + if(!signalMap.count(signalEvent["type"].toString())) + { + qWarning() << "Unknown signal received: " << signalEvent["type"].toString(); + return; + } - signalType = signalMap[signalEvent["type"].toString()]; + signalType = signalMap[signalEvent["type"].toString()]; - switch(signalType) - { - // TODO: create extractor functions like in nim - case NodeLogin: emit instance()->nodeLogin(NodeSignal{signalType, signalEvent["event"]["error"].toString()}); break; - case NodeReady: emit instance()->nodeReady(NodeSignal{signalType, signalEvent["event"]["error"].toString()}); break; - case NodeStarted: - emit instance()->nodeStarted(NodeSignal{signalType, signalEvent["event"]["error"].toString()}); - break; - case NodeStopped: - emit instance()->nodeStopped(NodeSignal{signalType, signalEvent["event"]["error"].toString()}); - break; - case NodeCrashed: { - auto signal = NodeSignal{signalType, signalEvent["event"]["error"].toString()}; - qWarning() << "node.crashed, error: " << signal.error; - emit instance()->nodeCrashed(signal); - break; - } - default: qWarning() << "Signal decoding not implemented: " << signalEvent; break; - } + switch(signalType) + { + // TODO: create extractor functions like in nim + case NodeLogin: emit instance()->nodeLogin(NodeSignal{signalType, signalEvent["event"]["error"].toString()}); break; + case NodeReady: emit instance()->nodeReady(NodeSignal{signalType, signalEvent["event"]["error"].toString()}); break; + case NodeStarted: + emit instance()->nodeStarted(NodeSignal{signalType, signalEvent["event"]["error"].toString()}); + break; + case NodeStopped: + emit instance()->nodeStopped(NodeSignal{signalType, signalEvent["event"]["error"].toString()}); + break; + case NodeCrashed: { + auto signal = NodeSignal{signalType, signalEvent["event"]["error"].toString()}; + qWarning() << "node.crashed, error: " << signal.error; + emit instance()->nodeCrashed(signal); + break; + } + default: qWarning() << "Signal decoding not implemented: " << signalEvent; break; + } } void Manager::signalCallback(const char* data) { - QtConcurrent::run(instance(), &Manager::processSignal, QString(data)); + QtConcurrent::run(instance(), &Manager::processSignal, QString(data)); } -} // namespace Signals \ No newline at end of file +} // namespace Signals diff --git a/src-cpp/app/global/singleton.cpp b/src-cpp/app/global/singleton.cpp index 04dbf3b8d..26827fdd4 100644 --- a/src-cpp/app/global/singleton.cpp +++ b/src-cpp/app/global/singleton.cpp @@ -7,17 +7,17 @@ Singleton* Singleton::theInstance; Singleton* Singleton::instance() { - if(theInstance == 0) theInstance = new Singleton(); - return theInstance; + if(theInstance == 0) theInstance = new Singleton(); + return theInstance; } Singleton::Singleton() { - m_engine = new QQmlApplicationEngine(); + m_engine = new QQmlApplicationEngine(); } QQmlApplicationEngine* Singleton::engine() { - return m_engine; + return m_engine; } } // namespace Global diff --git a/src-cpp/app/include/signals.h b/src-cpp/app/include/signals.h index 9635fb84f..c1a715c23 100644 --- a/src-cpp/app/include/signals.h +++ b/src-cpp/app/include/signals.h @@ -11,52 +11,52 @@ Q_NAMESPACE enum SignalType { - Unknown, - NodeLogin, - NodeReady, - NodeStarted, - NodeStopped, - NodeCrashed + Unknown, + NodeLogin, + NodeReady, + NodeStarted, + NodeStopped, + NodeCrashed }; Q_ENUM_NS(SignalType) struct Signal { - SignalType signalType; + SignalType signalType; }; struct NodeSignal : Signal { - QString error; + QString error; }; class Manager : public QObject { - Q_OBJECT + Q_OBJECT public: - static Manager* instance(); + static Manager* instance(); signals: - void signal(SignalType signal); + void signal(SignalType signal); - void nodeReady(NodeSignal signal); - void nodeStarted(NodeSignal signal); - void nodeStopped(NodeSignal signal); - void nodeLogin(NodeSignal signal); - void nodeCrashed(NodeSignal signal); + void nodeReady(NodeSignal signal); + void nodeStarted(NodeSignal signal); + void nodeStopped(NodeSignal signal); + void nodeLogin(NodeSignal signal); + void nodeCrashed(NodeSignal signal); private: - static Manager* theInstance; - explicit Manager(QObject* parent = nullptr); - static std::map signalMap; - static void signalCallback(const char* data); - void processSignal(QString ev); - void decode(const QJsonObject& signalEvent); + static Manager* theInstance; + explicit Manager(QObject* parent = nullptr); + static std::map signalMap; + static void signalCallback(const char* data); + void processSignal(QString ev); + void decode(const QJsonObject& signalEvent); }; } // namespace Signals Q_DECLARE_METATYPE(Signals::Signal) -Q_DECLARE_METATYPE(Signals::NodeSignal) \ No newline at end of file +Q_DECLARE_METATYPE(Signals::NodeSignal) diff --git a/src-cpp/app/include/singleton.h b/src-cpp/app/include/singleton.h index b7c4d633c..bacc4f255 100644 --- a/src-cpp/app/include/singleton.h +++ b/src-cpp/app/include/singleton.h @@ -8,13 +8,13 @@ namespace Global class Singleton { public: - QQmlApplicationEngine* engine(); - static Singleton* instance(); + QQmlApplicationEngine* engine(); + static Singleton* instance(); private: - static Singleton* theInstance; - explicit Singleton(); - QQmlApplicationEngine* m_engine; + static Singleton* theInstance; + explicit Singleton(); + QQmlApplicationEngine* m_engine; }; -} // namespace Global \ No newline at end of file +} // namespace Global diff --git a/src-cpp/app/modules/main/controller.cpp b/src-cpp/app/modules/main/controller.cpp index 6f77584d7..facddf32b 100644 --- a/src-cpp/app/modules/main/controller.cpp +++ b/src-cpp/app/modules/main/controller.cpp @@ -2,7 +2,7 @@ #include "controller.h" -namespace Modules:: Main +namespace Modules::Main { Controller::Controller(QObject* parent) : QObject(parent) diff --git a/src-cpp/app/modules/main/controller.h b/src-cpp/app/modules/main/controller.h index 9c75f88dc..67eadb5b4 100644 --- a/src-cpp/app/modules/main/controller.h +++ b/src-cpp/app/modules/main/controller.h @@ -21,4 +21,3 @@ public: } // namespace Modules::Main #endif // CONTROLLER_H - diff --git a/src-cpp/app/modules/main/module.cpp b/src-cpp/app/modules/main/module.cpp index ede18fab6..a071c477e 100644 --- a/src-cpp/app/modules/main/module.cpp +++ b/src-cpp/app/modules/main/module.cpp @@ -1,14 +1,15 @@ #include #include -#include "module.h" -#include "singleton.h" -#include "modules/main/wallet/module.h" #include "../shared/section_item.h" +#include "module.h" +#include "modules/main/wallet/module.h" +#include "singleton.h" namespace Modules::Main { -Module::Module(std::shared_ptr walletsService, QObject* parent): QObject(parent) +Module::Module(std::shared_ptr walletsService, QObject* parent) + : QObject(parent) { m_controllerPtr = new Controller(this); m_viewPtr = new View(this); diff --git a/src-cpp/app/modules/main/view.cpp b/src-cpp/app/modules/main/view.cpp index 6876583ee..d7ac551b2 100644 --- a/src-cpp/app/modules/main/view.cpp +++ b/src-cpp/app/modules/main/view.cpp @@ -1,7 +1,6 @@ #include "view.h" #include "../global/app_sections_config.h" - namespace Modules::Main { View::View(QObject* parent) @@ -13,7 +12,15 @@ View::View(QObject* parent) void View::load() { // Add Wallet Section to Sections model - auto walletSectionItem = new Shared::Models::SectionItem(WALLET_SECTION_ID, Shared::Models::SectionType::Wallet, WALLET_SECTION_NAME, "", "", WALLET_SECTION_ICON, "", false, this); + auto walletSectionItem = new Shared::Models::SectionItem(WALLET_SECTION_ID, + Shared::Models::SectionType::Wallet, + WALLET_SECTION_NAME, + "", + "", + WALLET_SECTION_ICON, + "", + false, + this); addItem(walletSectionItem); setActiveSection(WALLET_SECTION_ID); @@ -36,7 +43,7 @@ Shared::Models::SectionItem* View::getActiveSection() return m_sectionModelPtr->getActiveItem(); } -void View::setActiveSection(const QString &Id) +void View::setActiveSection(const QString& Id) { if(m_sectionModelPtr->getActiveItem().isNull() || (m_sectionModelPtr->getActiveItem()->getId() != Id)) { diff --git a/src-cpp/app/modules/main/view.h b/src-cpp/app/modules/main/view.h index 93ad254ce..a5ba2fcfa 100644 --- a/src-cpp/app/modules/main/view.h +++ b/src-cpp/app/modules/main/view.h @@ -19,7 +19,7 @@ public: ~View() = default; void load(); - void addItem(Shared::Models::SectionItem *item); + void addItem(Shared::Models::SectionItem* item); Shared::Models::SectionModel* getSectionsModel(); Shared::Models::SectionItem* getActiveSection(); @@ -36,4 +36,3 @@ private: } // namespace Modules::Main #endif // VIEW_H - diff --git a/src-cpp/app/modules/main/wallet/accounts/controller.cpp b/src-cpp/app/modules/main/wallet/accounts/controller.cpp index 747523f16..ecc76c97e 100644 --- a/src-cpp/app/modules/main/wallet/accounts/controller.cpp +++ b/src-cpp/app/modules/main/wallet/accounts/controller.cpp @@ -4,21 +4,17 @@ namespace Modules::Main::Wallet::Accounts { -Controller::Controller(std::shared_ptr walletService, - QObject* parent) - : m_walletServicePtr(walletService), - QObject(parent) +Controller::Controller(std::shared_ptr walletService, QObject* parent) + : m_walletServicePtr(walletService) + , QObject(parent) { } -void Controller::init() -{ -} +void Controller::init() { } QList Controller::getWalletAccounts() { QList wallet_accounts; - if(nullptr != m_walletServicePtr) - wallet_accounts = m_walletServicePtr->getWalletAccounts(); + if(nullptr != m_walletServicePtr) wallet_accounts = m_walletServicePtr->getWalletAccounts(); return wallet_accounts; } diff --git a/src-cpp/app/modules/main/wallet/accounts/controller.h b/src-cpp/app/modules/main/wallet/accounts/controller.h index 1ad878bae..34ddafa68 100644 --- a/src-cpp/app/modules/main/wallet/accounts/controller.h +++ b/src-cpp/app/modules/main/wallet/accounts/controller.h @@ -3,10 +3,10 @@ #include -#include "wallet_accounts/wallet_account.h" -#include "wallet_accounts/service_interface.h" #include "interfaces/controller_interface.h" #include "signals.h" +#include "wallet_accounts/service_interface.h" +#include "wallet_accounts/wallet_account.h" namespace Modules::Main::Wallet::Accounts { diff --git a/src-cpp/app/modules/main/wallet/accounts/item.cpp b/src-cpp/app/modules/main/wallet/accounts/item.cpp index 06e66752d..6835d6d03 100644 --- a/src-cpp/app/modules/main/wallet/accounts/item.cpp +++ b/src-cpp/app/modules/main/wallet/accounts/item.cpp @@ -2,16 +2,24 @@ namespace Modules::Main::Wallet::Accounts { -Item::Item(QString name, QString address, QString path, QString color, QString publicKey, QString walletType, bool isWallet, bool isChat, float currencyBalance) - : m_name(name), - m_address(address), - m_path(path), - m_color(color), - m_publicKey(publicKey), - m_walletType(walletType), - m_isWallet(isWallet), - m_isChat(isChat), - m_currencyBalance(currencyBalance) +Item::Item(QString name, + QString address, + QString path, + QString color, + QString publicKey, + QString walletType, + bool isWallet, + bool isChat, + float currencyBalance) + : m_name(name) + , m_address(address) + , m_path(path) + , m_color(color) + , m_publicKey(publicKey) + , m_walletType(walletType) + , m_isWallet(isWallet) + , m_isChat(isChat) + , m_currencyBalance(currencyBalance) { } const QString& Item::getName() const @@ -54,7 +62,7 @@ bool Item::getIsChat() const return m_isChat; } -float Item::getCurrencyBalance() const +float Item::getCurrencyBalance() const { return m_currencyBalance; } diff --git a/src-cpp/app/modules/main/wallet/accounts/item.h b/src-cpp/app/modules/main/wallet/accounts/item.h index 58b1ea249..7e474b34d 100644 --- a/src-cpp/app/modules/main/wallet/accounts/item.h +++ b/src-cpp/app/modules/main/wallet/accounts/item.h @@ -19,7 +19,15 @@ private: float m_currencyBalance; public: - Item(QString name, QString address, QString path, QString color, QString publicKey, QString walletType, bool isWallet, bool isChat, float currencyBalance); + Item(QString name, + QString address, + QString path, + QString color, + QString publicKey, + QString walletType, + bool isWallet, + bool isChat, + float currencyBalance); ~Item() = default; const QString& getName() const; diff --git a/src-cpp/app/modules/main/wallet/accounts/model.cpp b/src-cpp/app/modules/main/wallet/accounts/model.cpp index affdf11b8..f254af124 100644 --- a/src-cpp/app/modules/main/wallet/accounts/model.cpp +++ b/src-cpp/app/modules/main/wallet/accounts/model.cpp @@ -50,7 +50,8 @@ QVariant Model::data(const QModelIndex& index, int role) const case PublicKey: return QVariant(item.getPublicKey()); case WalletType: return QVariant(item.getWalletType()); case IsWallet: return QVariant(item.getIsWallet()); - case IsChat: return QVariant(item.getIsChat()); + case IsChat: + return QVariant(item.getIsChat()); // case Assets: return QVariant(item.ge()); case CurrencyBalance: return QVariant(item.getCurrencyBalance()); } @@ -58,7 +59,7 @@ QVariant Model::data(const QModelIndex& index, int role) const return QVariant(); } -void Model::setItems(QVector &items) +void Model::setItems(QVector& items) { beginResetModel(); m_items = items; diff --git a/src-cpp/app/modules/main/wallet/accounts/model.h b/src-cpp/app/modules/main/wallet/accounts/model.h index d15827db3..a09b0739b 100644 --- a/src-cpp/app/modules/main/wallet/accounts/model.h +++ b/src-cpp/app/modules/main/wallet/accounts/model.h @@ -34,7 +34,7 @@ public: QHash roleNames() const override; int rowCount(const QModelIndex&) const override; QVariant data(const QModelIndex& index, int role) const override; - void setItems(QVector &items); + void setItems(QVector& items); private: QVector m_items; diff --git a/src-cpp/app/modules/main/wallet/accounts/module.cpp b/src-cpp/app/modules/main/wallet/accounts/module.cpp index 0fabcb12c..abcac902d 100644 --- a/src-cpp/app/modules/main/wallet/accounts/module.cpp +++ b/src-cpp/app/modules/main/wallet/accounts/module.cpp @@ -6,7 +6,8 @@ namespace Modules::Main::Wallet::Accounts { -Module::Module(std::shared_ptr walletsService, QObject *parent): QObject(parent) +Module::Module(std::shared_ptr walletsService, QObject* parent) + : QObject(parent) { m_controllerPtr = new Controller(walletsService, this); m_viewPtr = new View(this); @@ -49,14 +50,15 @@ void Module::refreshWalletAccounts() QVector 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); + 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!"; + qWarning() << "No accounts found!"; } } } // namespace Modules::Main::Wallet::Accounts diff --git a/src-cpp/app/modules/main/wallet/accounts/module.h b/src-cpp/app/modules/main/wallet/accounts/module.h index 0807bf805..bd1604fe0 100644 --- a/src-cpp/app/modules/main/wallet/accounts/module.h +++ b/src-cpp/app/modules/main/wallet/accounts/module.h @@ -3,10 +3,10 @@ #include -#include "wallet_accounts/service_interface.h" -#include "interfaces/module_access_interface.h" #include "controller.h" +#include "interfaces/module_access_interface.h" #include "view.h" +#include "wallet_accounts/service_interface.h" namespace Modules::Main::Wallet::Accounts { @@ -23,6 +23,7 @@ private: void connect(); void refreshWalletAccounts(); + public: explicit Module(std::shared_ptr walletsService, QObject* parent); ~Module() = default; diff --git a/src-cpp/app/modules/main/wallet/accounts/view.cpp b/src-cpp/app/modules/main/wallet/accounts/view.cpp index 628464271..6c85d0d46 100644 --- a/src-cpp/app/modules/main/wallet/accounts/view.cpp +++ b/src-cpp/app/modules/main/wallet/accounts/view.cpp @@ -20,7 +20,8 @@ Model* View::getModel() return m_modelPtr; } -void View::setModelItems(QVector &accounts) { +void View::setModelItems(QVector& accounts) +{ m_modelPtr->setItems(accounts); modelChanged(); } diff --git a/src-cpp/app/modules/main/wallet/accounts/view.h b/src-cpp/app/modules/main/wallet/accounts/view.h index 6196bf689..aedbedcd4 100644 --- a/src-cpp/app/modules/main/wallet/accounts/view.h +++ b/src-cpp/app/modules/main/wallet/accounts/view.h @@ -18,7 +18,7 @@ public: ~View() = default; void load(); - void setModelItems(QVector &accounts); + void setModelItems(QVector& accounts); private: Model* m_modelPtr; diff --git a/src-cpp/app/modules/main/wallet/controller.cpp b/src-cpp/app/modules/main/wallet/controller.cpp index 209fb551b..2ba69e10c 100644 --- a/src-cpp/app/modules/main/wallet/controller.cpp +++ b/src-cpp/app/modules/main/wallet/controller.cpp @@ -4,13 +4,10 @@ namespace Modules::Main::Wallet { -Controller::Controller(std::shared_ptr walletService, - QObject* parent) - : m_walletService(walletService), - QObject(parent) +Controller::Controller(std::shared_ptr walletService, QObject* parent) + : m_walletService(walletService) + , QObject(parent) { } -void Controller::init() -{ -} +void Controller::init() { } } // namespace Modules::Main::Wallet diff --git a/src-cpp/app/modules/main/wallet/controller.h b/src-cpp/app/modules/main/wallet/controller.h index b8aee2a86..813856f79 100644 --- a/src-cpp/app/modules/main/wallet/controller.h +++ b/src-cpp/app/modules/main/wallet/controller.h @@ -3,9 +3,9 @@ #include -#include "wallet_accounts/service_interface.h" #include "interfaces/controller_interface.h" #include "signals.h" +#include "wallet_accounts/service_interface.h" namespace Modules::Main::Wallet { diff --git a/src-cpp/app/modules/main/wallet/module.cpp b/src-cpp/app/modules/main/wallet/module.cpp index ccdb83060..35777c806 100644 --- a/src-cpp/app/modules/main/wallet/module.cpp +++ b/src-cpp/app/modules/main/wallet/module.cpp @@ -1,13 +1,14 @@ #include #include +#include "accounts/module.h" #include "module.h" #include "singleton.h" -#include "accounts/module.h" namespace Modules::Main::Wallet { -Module::Module(std::shared_ptr walletsService, QObject *parent): QObject(parent) +Module::Module(std::shared_ptr walletsService, QObject* parent) + : QObject(parent) { m_controllerPtr = new Controller(walletsService, this); m_viewPtr = new View(this); @@ -49,7 +50,7 @@ void Module::checkIfModuleDidLoad() } void Module::viewDidLoad() -{ +{ checkIfModuleDidLoad(); } diff --git a/src-cpp/app/modules/main/wallet/module.h b/src-cpp/app/modules/main/wallet/module.h index 99b18e945..53bd0ee7f 100644 --- a/src-cpp/app/modules/main/wallet/module.h +++ b/src-cpp/app/modules/main/wallet/module.h @@ -24,6 +24,7 @@ private: bool m_moduleLoaded; void connect(); + public: explicit Module(std::shared_ptr walletsService, QObject* parent); ~Module() = default; diff --git a/src-cpp/app/modules/main/wallet/view.cpp b/src-cpp/app/modules/main/wallet/view.cpp index f2eb94f3e..cfd8397fe 100644 --- a/src-cpp/app/modules/main/wallet/view.cpp +++ b/src-cpp/app/modules/main/wallet/view.cpp @@ -6,8 +6,7 @@ namespace Modules::Main::Wallet { View::View(QObject* parent) : QObject(parent) -{ -} +{ } void View::load() { diff --git a/src-cpp/app/modules/main/wallet/view.h b/src-cpp/app/modules/main/wallet/view.h index a03fe946f..d0d97c206 100644 --- a/src-cpp/app/modules/main/wallet/view.h +++ b/src-cpp/app/modules/main/wallet/view.h @@ -21,4 +21,3 @@ signals: } // namespace Modules::Main::Wallet #endif // WALLET_VIEW_H - diff --git a/src-cpp/app/modules/shared/section_item.cpp b/src-cpp/app/modules/shared/section_item.cpp index 895235c95..e2bb77399 100644 --- a/src-cpp/app/modules/shared/section_item.cpp +++ b/src-cpp/app/modules/shared/section_item.cpp @@ -23,41 +23,40 @@ SectionItem::SectionItem(QString id, bool canRequestAccess, int access, bool ensOnly, - QObject *parent): - QObject(parent), - m_id(id), - m_sectionType(sectionType) , - m_name(name), - m_amISectionAdmin(amISectionAdmin), - m_description(description), - m_image(image), - m_icon(icon), - m_color(color), - m_hasNotification(hasNotification), - m_notificationsCount(notificationsCount), - m_active(active), - m_enabled(enabled), - m_isMember(isMember), - m_joined(joined), - m_canJoin(canJoin), - m_canManageUsers(canManageUsers), - m_canRequestAccess(canRequestAccess), - m_access(access), - m_ensOnly(ensOnly) -{ -} + QObject* parent) + : QObject(parent) + , m_id(id) + , m_sectionType(sectionType) + , m_name(name) + , m_amISectionAdmin(amISectionAdmin) + , m_description(description) + , m_image(image) + , m_icon(icon) + , m_color(color) + , m_hasNotification(hasNotification) + , m_notificationsCount(notificationsCount) + , m_active(active) + , m_enabled(enabled) + , m_isMember(isMember) + , m_joined(joined) + , m_canJoin(canJoin) + , m_canManageUsers(canManageUsers) + , m_canRequestAccess(canRequestAccess) + , m_access(access) + , m_ensOnly(ensOnly) +{ } SectionType SectionItem::getSectionType() const { return m_sectionType; } - const QString& SectionItem::getId() const +const QString& SectionItem::getId() const { return m_id; } - const QString& SectionItem::getName() const +const QString& SectionItem::getName() const { return m_name; } @@ -67,22 +66,22 @@ bool SectionItem::getAmISectionAdmin() const return m_amISectionAdmin; } - const QString& SectionItem::getDescription() const +const QString& SectionItem::getDescription() const { return m_description; } - const QString& SectionItem::getImage() const +const QString& SectionItem::getImage() const { return m_image; } - const QString& SectionItem::getIcon() const +const QString& SectionItem::getIcon() const { return m_icon; } - const QString& SectionItem::getColor() const +const QString& SectionItem::getColor() const { return m_color; } diff --git a/src-cpp/app/modules/shared/section_item.h b/src-cpp/app/modules/shared/section_item.h index 538187fee..92178301b 100644 --- a/src-cpp/app/modules/shared/section_item.h +++ b/src-cpp/app/modules/shared/section_item.h @@ -15,7 +15,7 @@ enum SectionType ProfileSettings, NodeManagement }; -class SectionItem: public QObject +class SectionItem : public QObject { Q_OBJECT Q_PROPERTY(QString id READ getId) @@ -51,7 +51,7 @@ public: bool amISectionAdmin = false, bool hasNotification = false, int notificationsCount = 0, - bool isMember = false, + bool isMember = false, bool joined = false, bool canJoin = false, bool canManageUsers = false, diff --git a/src-cpp/app/modules/shared/section_model.cpp b/src-cpp/app/modules/shared/section_model.cpp index 131d6b4f7..3edb2faee 100644 --- a/src-cpp/app/modules/shared/section_model.cpp +++ b/src-cpp/app/modules/shared/section_model.cpp @@ -73,7 +73,8 @@ QVariant SectionModel::data(const QModelIndex& index, int role) const case CanManageUsers: return QVariant(item->getCanManageUsers()); case CanRequestAccess: return QVariant(item->getCanRequestAccess()); case Access: return QVariant(item->getAccess()); - case EnsOnly: return QVariant(item->getIsEnsOnly()); + case EnsOnly: + return QVariant(item->getIsEnsOnly()); // To Do case MembersModel: return QVariant(); case PendingRequestsToJoinModel: return QVariant(); @@ -89,18 +90,18 @@ void SectionModel::addItem(SectionItem* item) endInsertRows(); } -void SectionModel::setActiveSection(const QString &Id) +void SectionModel::setActiveSection(const QString& Id) { - for (int i = 0; i < m_items.size(); ++i) { + for(int i = 0; i < m_items.size(); ++i) + { auto newIndex = createIndex(i, 0, nullptr); if(m_items.at(i)->getIsActive()) { m_items.at(i)->setIsActive(false); dataChanged(newIndex, newIndex, QVector(ModelRole::Active)); - } - if (m_items.at(i)->getId() == Id) + if(m_items.at(i)->getId() == Id) { m_items.at(i)->setIsActive(true); dataChanged(newIndex, newIndex, QVector(ModelRole::Active)); @@ -115,10 +116,10 @@ QPointer SectionModel::getActiveItem() { if(item->getIsActive()) { - activeItem = item; - break; + activeItem = item; + break; } } - return activeItem; + return activeItem; } } // namespace Shared::Models diff --git a/src-cpp/app/modules/shared/section_model.h b/src-cpp/app/modules/shared/section_model.h index 82a3d15a9..7d291adac 100644 --- a/src-cpp/app/modules/shared/section_model.h +++ b/src-cpp/app/modules/shared/section_model.h @@ -3,9 +3,9 @@ #include #include +#include #include #include -#include #include "section_item.h" @@ -49,7 +49,7 @@ public: QVariant data(const QModelIndex& index, int role) const override; void addItem(SectionItem* item); - void setActiveSection(const QString &Id); + void setActiveSection(const QString& Id); QPointer getActiveItem(); // To add other api's later as needed diff --git a/src-cpp/app/modules/startup/controller.cpp b/src-cpp/app/modules/startup/controller.cpp index 5a3e28b1a..7950ac9c7 100644 --- a/src-cpp/app/modules/startup/controller.cpp +++ b/src-cpp/app/modules/startup/controller.cpp @@ -9,47 +9,47 @@ namespace Modules namespace Startup { Controller::Controller(ModuleControllerDelegateInterface* delegate, - Accounts::ServiceInterface* accountsService, - QObject* parent) - : QObject(parent) - , m_accountsService(accountsService) - , m_delegate(delegate) + Accounts::ServiceInterface* accountsService, + QObject* parent) + : QObject(parent) + , m_accountsService(accountsService) + , m_delegate(delegate) { } void Controller::init() { - QObject::connect(Signals::Manager::instance(), &Signals::Manager::nodeLogin, this, &Controller::onLogin); - QObject::connect(Signals::Manager::instance(), &Signals::Manager::nodeStopped, this, &Controller::onNodeStopped); - QObject::connect(Signals::Manager::instance(), &Signals::Manager::nodeReady, this, &Controller::onNodeReady); + QObject::connect(Signals::Manager::instance(), &Signals::Manager::nodeLogin, this, &Controller::onLogin); + QObject::connect(Signals::Manager::instance(), &Signals::Manager::nodeStopped, this, &Controller::onNodeStopped); + QObject::connect(Signals::Manager::instance(), &Signals::Manager::nodeReady, this, &Controller::onNodeReady); } void Controller::onLogin(Signals::NodeSignal signal) { - if(signal.error.isEmpty()) - { - m_delegate->userLoggedIn(); - } - else - { - qWarning() << "error: methodName=init, errDescription=login error " << signal.error; - } + if(signal.error.isEmpty()) + { + m_delegate->userLoggedIn(); + } + else + { + qWarning() << "error: methodName=init, errDescription=login error " << signal.error; + } } void Controller::onNodeStopped(Signals::NodeSignal signal) { - // self.events.emit("nodeStopped", Args()) - m_accountsService->clear(); - m_delegate->emitLogOut(); + // self.events.emit("nodeStopped", Args()) + m_accountsService->clear(); + m_delegate->emitLogOut(); } void Controller::onNodeReady(Signals::NodeSignal signal) { - // self.events.emit("nodeReady", Args()) + // self.events.emit("nodeReady", Args()) } bool Controller::shouldStartWithOnboardingScreen() { - return m_accountsService->openedAccounts().size() == 0; + return m_accountsService->openedAccounts().size() == 0; } } // namespace Startup -} // namespace Modules \ No newline at end of file +} // namespace Modules diff --git a/src-cpp/app/modules/startup/controller.h b/src-cpp/app/modules/startup/controller.h index b23660aa6..e89be2b03 100644 --- a/src-cpp/app/modules/startup/controller.h +++ b/src-cpp/app/modules/startup/controller.h @@ -14,19 +14,19 @@ namespace Startup class Controller : public QObject, ControllerInterface { public: - Controller(ModuleControllerDelegateInterface* delegate, - Accounts::ServiceInterface* accountsService, - QObject* parent = nullptr); - void init() override; - bool shouldStartWithOnboardingScreen() override; - void onLogin(Signals::NodeSignal signal); - void onNodeStopped(Signals::NodeSignal signal); - void onNodeReady(Signals::NodeSignal signal); + Controller(ModuleControllerDelegateInterface* delegate, + Accounts::ServiceInterface* accountsService, + QObject* parent = nullptr); + void init() override; + bool shouldStartWithOnboardingScreen() override; + void onLogin(Signals::NodeSignal signal); + void onNodeStopped(Signals::NodeSignal signal); + void onNodeReady(Signals::NodeSignal signal); private: - Accounts::ServiceInterface* m_accountsService; - ModuleControllerDelegateInterface* m_delegate; + Accounts::ServiceInterface* m_accountsService; + ModuleControllerDelegateInterface* m_delegate; }; } // namespace Startup -} // namespace Modules \ No newline at end of file +} // namespace Modules diff --git a/src-cpp/app/modules/startup/controller_interface.h b/src-cpp/app/modules/startup/controller_interface.h index bd8cd443d..4ab36bd49 100644 --- a/src-cpp/app/modules/startup/controller_interface.h +++ b/src-cpp/app/modules/startup/controller_interface.h @@ -10,9 +10,9 @@ namespace Startup class ControllerInterface { public: - virtual void init() = 0; + virtual void init() = 0; - virtual bool shouldStartWithOnboardingScreen() = 0; + virtual bool shouldStartWithOnboardingScreen() = 0; }; } // namespace Startup -} // namespace Modules \ No newline at end of file +} // namespace Modules diff --git a/src-cpp/app/modules/startup/interfaces/module_controller_delegate_interface.h b/src-cpp/app/modules/startup/interfaces/module_controller_delegate_interface.h index 9219eec45..4fcf55248 100644 --- a/src-cpp/app/modules/startup/interfaces/module_controller_delegate_interface.h +++ b/src-cpp/app/modules/startup/interfaces/module_controller_delegate_interface.h @@ -7,9 +7,9 @@ namespace Startup class ModuleControllerDelegateInterface { public: - virtual void userLoggedIn() = 0; + virtual void userLoggedIn() = 0; - virtual void emitLogOut() = 0; + virtual void emitLogOut() = 0; }; }; // namespace Startup -}; // namespace Modules \ No newline at end of file +}; // namespace Modules diff --git a/src-cpp/app/modules/startup/interfaces/module_login_delegate_interface.h b/src-cpp/app/modules/startup/interfaces/module_login_delegate_interface.h index 9888b3b55..1e09594f7 100644 --- a/src-cpp/app/modules/startup/interfaces/module_login_delegate_interface.h +++ b/src-cpp/app/modules/startup/interfaces/module_login_delegate_interface.h @@ -7,7 +7,7 @@ namespace Startup class ModuleLoginDelegateInterface { public: - virtual void loginDidLoad() = 0; + virtual void loginDidLoad() = 0; }; }; // namespace Startup -}; // namespace Modules \ No newline at end of file +}; // namespace Modules diff --git a/src-cpp/app/modules/startup/interfaces/module_onboarding_delegate_interface.h b/src-cpp/app/modules/startup/interfaces/module_onboarding_delegate_interface.h index 586ce7544..f7af38d5d 100644 --- a/src-cpp/app/modules/startup/interfaces/module_onboarding_delegate_interface.h +++ b/src-cpp/app/modules/startup/interfaces/module_onboarding_delegate_interface.h @@ -7,7 +7,7 @@ namespace Startup class ModuleOnboardingDelegateInterface { public: - virtual void onboardingDidLoad() = 0; + virtual void onboardingDidLoad() = 0; }; }; // namespace Startup -}; // namespace Modules \ No newline at end of file +}; // namespace Modules diff --git a/src-cpp/app/modules/startup/interfaces/module_view_delegate_interface.h b/src-cpp/app/modules/startup/interfaces/module_view_delegate_interface.h index 459ef5672..5ebfc4e06 100644 --- a/src-cpp/app/modules/startup/interfaces/module_view_delegate_interface.h +++ b/src-cpp/app/modules/startup/interfaces/module_view_delegate_interface.h @@ -7,7 +7,7 @@ namespace Startup class ModuleViewDelegateInterface { public: - virtual void viewDidLoad() = 0; + virtual void viewDidLoad() = 0; }; }; // namespace Startup -}; // namespace Modules \ No newline at end of file +}; // namespace Modules diff --git a/src-cpp/app/modules/startup/login/controller.cpp b/src-cpp/app/modules/startup/login/controller.cpp index dc1ca3f3f..3985c3294 100644 --- a/src-cpp/app/modules/startup/login/controller.cpp +++ b/src-cpp/app/modules/startup/login/controller.cpp @@ -14,77 +14,77 @@ namespace Startup namespace Login { Controller::Controller(ModuleControllerDelegateInterface* delegate, - // keychainService - Accounts::ServiceInterface* accountsService, - QObject* parent) - : QObject(parent) - , m_accountsService(accountsService) - , m_delegate(delegate) + // keychainService + Accounts::ServiceInterface* accountsService, + QObject* parent) + : QObject(parent) + , m_accountsService(accountsService) + , m_delegate(delegate) { } void Controller::init() { - QObject::connect(Signals::Manager::instance(), &Signals::Manager::nodeLogin, this, &Controller::onLogin); - // keychainServiceSuccess see src-cpp/app/modules/startup/login/controller.nim line 43 - // keychainServiceError see src-cpp/app/modules/startup/login/controller.nim line 47 + QObject::connect(Signals::Manager::instance(), &Signals::Manager::nodeLogin, this, &Controller::onLogin); + // keychainServiceSuccess see src-cpp/app/modules/startup/login/controller.nim line 43 + // keychainServiceError see src-cpp/app/modules/startup/login/controller.nim line 47 } void Controller::onLogin(Signals::NodeSignal signal) { - if(!signal.error.isEmpty()) - { - m_delegate->emitAccountLoginError(signal.error); - } + if(!signal.error.isEmpty()) + { + m_delegate->emitAccountLoginError(signal.error); + } } QVector Controller::getOpenedAccounts() { - return m_accountsService->openedAccounts(); + return m_accountsService->openedAccounts(); } Accounts::AccountDto Controller::getSelectedAccount() { - auto openedAccounts = Controller::getOpenedAccounts(); - foreach(const Accounts::AccountDto& acc, openedAccounts) - { - if(acc.keyUid == m_selectedAccountKeyUid) - { - return acc; - } - } + auto openedAccounts = Controller::getOpenedAccounts(); + foreach(const Accounts::AccountDto& acc, openedAccounts) + { + if(acc.keyUid == m_selectedAccountKeyUid) + { + return acc; + } + } - // TODO: For situations like this, should be better to return a std::optional instead? - return Accounts::AccountDto(); + // TODO: For situations like this, should be better to return a std::optional instead? + return Accounts::AccountDto(); } void Controller::setSelectedAccountKeyUid(QString keyUid) { - m_selectedAccountKeyUid = keyUid; + m_selectedAccountKeyUid = keyUid; - // Dealing with Keychain is the MacOS only feature - // if(not defined(macosx)): - // return + // Dealing with Keychain is the MacOS only feature + // if(not defined(macosx)): + // return - // let selectedAccount = self.getSelectedAccount() - // singletonInstance.localAccountSettings.setFileName(selectedAccount.name) + // let selectedAccount = self.getSelectedAccount() + // singletonInstance.localAccountSettings.setFileName(selectedAccount.name) - // let value = singletonInstance.localAccountSettings.getStoreToKeychainValue() - // if (value != LS_VALUE_STORE): - // return + // let value = singletonInstance.localAccountSettings.getStoreToKeychainValue() + // if (value != LS_VALUE_STORE): + // return - // self.keychainService.tryToObtainPassword(selectedAccount.name) + // self.keychainService.tryToObtainPassword(selectedAccount.name) } void Controller::login(QString password) { - auto selectedAccount = Controller::getSelectedAccount(); - auto error = m_accountsService->login(selectedAccount, password); - if(!error.isEmpty()) - { - m_delegate->emitAccountLoginError(error); - } + auto selectedAccount = Controller::getSelectedAccount(); + auto error = m_accountsService->login(selectedAccount, password); + if(!error.isEmpty()) + { + m_delegate->emitAccountLoginError(error); + } } } // namespace Login } // namespace Startup -} // namespace Modules \ No newline at end of file +} // namespace Modules diff --git a/src-cpp/app/modules/startup/login/controller.h b/src-cpp/app/modules/startup/login/controller.h index 05d69dbbe..e3da555da 100644 --- a/src-cpp/app/modules/startup/login/controller.h +++ b/src-cpp/app/modules/startup/login/controller.h @@ -16,26 +16,26 @@ namespace Login { class Controller : public QObject, ControllerInterface { - Q_OBJECT + Q_OBJECT public: - Controller(ModuleControllerDelegateInterface* delegate, - // keychainService, - Accounts::ServiceInterface* accountsService, - QObject* parent = nullptr); - void init() override; - QVector getOpenedAccounts() override; - Accounts::AccountDto getSelectedAccount(); - void setSelectedAccountKeyUid(QString keyUid) override; - void login(QString password) override; - void onLogin(Signals::NodeSignal signal); + Controller(ModuleControllerDelegateInterface* delegate, + // keychainService, + Accounts::ServiceInterface* accountsService, + QObject* parent = nullptr); + void init() override; + QVector getOpenedAccounts() override; + Accounts::AccountDto getSelectedAccount(); + void setSelectedAccountKeyUid(QString keyUid) override; + void login(QString password) override; + void onLogin(Signals::NodeSignal signal); private: - // Keychain::m_keychainService - Accounts::ServiceInterface* m_accountsService; - ModuleControllerDelegateInterface* m_delegate; - QString m_selectedAccountKeyUid; + // Keychain::m_keychainService + Accounts::ServiceInterface* m_accountsService; + ModuleControllerDelegateInterface* m_delegate; + QString m_selectedAccountKeyUid; }; } // namespace Login } // namespace Startup -} // namespace Modules \ No newline at end of file +} // namespace Modules diff --git a/src-cpp/app/modules/startup/login/controller_interface.h b/src-cpp/app/modules/startup/login/controller_interface.h index 47bd931d5..a7a51b513 100644 --- a/src-cpp/app/modules/startup/login/controller_interface.h +++ b/src-cpp/app/modules/startup/login/controller_interface.h @@ -14,13 +14,13 @@ namespace Login class ControllerInterface { public: - virtual void init() = 0; + virtual void init() = 0; - virtual QVector getOpenedAccounts() = 0; + virtual QVector getOpenedAccounts() = 0; - virtual void setSelectedAccountKeyUid(QString keyUid) = 0; + virtual void setSelectedAccountKeyUid(QString keyUid) = 0; - virtual void login(QString password) = 0; + virtual void login(QString password) = 0; }; } // namespace Login } // namespace Startup diff --git a/src-cpp/app/modules/startup/login/interfaces/module_controller_delegate_interface.h b/src-cpp/app/modules/startup/login/interfaces/module_controller_delegate_interface.h index f9d169f3d..6ef7ea8a8 100644 --- a/src-cpp/app/modules/startup/login/interfaces/module_controller_delegate_interface.h +++ b/src-cpp/app/modules/startup/login/interfaces/module_controller_delegate_interface.h @@ -9,12 +9,12 @@ namespace Login class ModuleControllerDelegateInterface { public: - virtual void emitAccountLoginError(QString error) = 0; + virtual void emitAccountLoginError(QString error) = 0; - virtual void emitObtainingPasswordError(QString errorDescription) = 0; + virtual void emitObtainingPasswordError(QString errorDescription) = 0; - virtual void emitObtainingPasswordSuccess(QString password) = 0; + virtual void emitObtainingPasswordSuccess(QString password) = 0; }; }; // namespace Login }; // namespace Startup -}; // namespace Modules \ No newline at end of file +}; // namespace Modules diff --git a/src-cpp/app/modules/startup/login/interfaces/module_view_delegate_interface.h b/src-cpp/app/modules/startup/login/interfaces/module_view_delegate_interface.h index 678df2d23..1a68c7052 100644 --- a/src-cpp/app/modules/startup/login/interfaces/module_view_delegate_interface.h +++ b/src-cpp/app/modules/startup/login/interfaces/module_view_delegate_interface.h @@ -11,12 +11,12 @@ namespace Login class ModuleViewDelegateInterface { public: - virtual void viewDidLoad() = 0; + virtual void viewDidLoad() = 0; - virtual void setSelectedAccount(Item item) = 0; + virtual void setSelectedAccount(Item item) = 0; - virtual void login(QString password) = 0; + virtual void login(QString password) = 0; }; }; // namespace Login }; // namespace Startup -}; // namespace Modules \ No newline at end of file +}; // namespace Modules diff --git a/src-cpp/app/modules/startup/login/item.cpp b/src-cpp/app/modules/startup/login/item.cpp index 249ac4a9a..1db1502de 100644 --- a/src-cpp/app/modules/startup/login/item.cpp +++ b/src-cpp/app/modules/startup/login/item.cpp @@ -10,32 +10,32 @@ namespace Login Item::Item() { } Item::Item(QString name, QString identicon, QString thumbnailImage, QString largeImage, QString keyUid) - : m_name(name) - , m_identicon(identicon) - , m_thumbnailImage(thumbnailImage) - , m_largeImage(largeImage) - , m_keyUid(keyUid) + : m_name(name) + , m_identicon(identicon) + , m_thumbnailImage(thumbnailImage) + , m_largeImage(largeImage) + , m_keyUid(keyUid) { } QString Item::getName() { - return m_name; + return m_name; } QString Item::getIdenticon() { - return m_identicon; + return m_identicon; } QString Item::getThumbnailImage() { - return m_thumbnailImage; + return m_thumbnailImage; } QString Item::getLargeImage() { - return m_largeImage; + return m_largeImage; } QString Item::getKeyUid() { - return m_keyUid; + return m_keyUid; } } // namespace Login } // namespace Startup -} // namespace Modules \ No newline at end of file +} // namespace Modules diff --git a/src-cpp/app/modules/startup/login/item.h b/src-cpp/app/modules/startup/login/item.h index 1c2fefd62..a2393a3aa 100644 --- a/src-cpp/app/modules/startup/login/item.h +++ b/src-cpp/app/modules/startup/login/item.h @@ -11,20 +11,20 @@ namespace Login class Item { private: - QString m_name; - QString m_identicon; - QString m_thumbnailImage; - QString m_largeImage; - QString m_keyUid; + QString m_name; + QString m_identicon; + QString m_thumbnailImage; + QString m_largeImage; + QString m_keyUid; public: - Item(); - Item(QString name, QString identicon, QString thumbnailImage, QString largeImage, QString keyUid); - QString getName(); - QString getIdenticon(); - QString getThumbnailImage(); - QString getLargeImage(); - QString getKeyUid(); + Item(); + Item(QString name, QString identicon, QString thumbnailImage, QString largeImage, QString keyUid); + QString getName(); + QString getIdenticon(); + QString getThumbnailImage(); + QString getLargeImage(); + QString getKeyUid(); }; } // namespace Login } // namespace Startup diff --git a/src-cpp/app/modules/startup/login/model.cpp b/src-cpp/app/modules/startup/login/model.cpp index c9cd8ed50..abe72a549 100644 --- a/src-cpp/app/modules/startup/login/model.cpp +++ b/src-cpp/app/modules/startup/login/model.cpp @@ -9,67 +9,67 @@ namespace Startup namespace Login { Model::Model(QObject* parent) - : QAbstractListModel(parent) + : QAbstractListModel(parent) { } QHash Model::roleNames() const { - QHash roles; - roles[Name] = "username"; - roles[Identicon] = "identicon"; - roles[ThumbnailImage] = "thumbnailImage"; - roles[LargeImage] = "largeImage"; - roles[KeyUid] = "keyUid"; - return roles; + QHash roles; + roles[Name] = "username"; + roles[Identicon] = "identicon"; + roles[ThumbnailImage] = "thumbnailImage"; + roles[LargeImage] = "largeImage"; + roles[KeyUid] = "keyUid"; + return roles; } int Model::rowCount(const QModelIndex& parent = QModelIndex()) const { - return m_items.size(); + return m_items.size(); } QVariant Model::data(const QModelIndex& index, int role) const { - if(!index.isValid()) - { - return QVariant(); - } + if(!index.isValid()) + { + return QVariant(); + } - if(index.row() < 0 || index.row() > m_items.size()) - { - return QVariant(); - } + if(index.row() < 0 || index.row() > m_items.size()) + { + return QVariant(); + } - Item item = m_items[index.row()]; + Item item = m_items[index.row()]; - switch(role) - { - case Name: return QVariant(item.getName()); - case Identicon: return QVariant(item.getIdenticon()); - case ThumbnailImage: return QVariant(item.getThumbnailImage()); - case LargeImage: return QVariant(item.getLargeImage()); - case KeyUid: return QVariant(item.getKeyUid()); - } + switch(role) + { + case Name: return QVariant(item.getName()); + case Identicon: return QVariant(item.getIdenticon()); + case ThumbnailImage: return QVariant(item.getThumbnailImage()); + case LargeImage: return QVariant(item.getLargeImage()); + case KeyUid: return QVariant(item.getKeyUid()); + } - return QVariant(); + return QVariant(); } void Model::setItems(QVector items) { - beginResetModel(); - m_items = items; - endResetModel(); + beginResetModel(); + m_items = items; + endResetModel(); } Item Model::getItemAtIndex(int index) { - if(index < 0 || index >= m_items.size()) - { - return Item(); - } + if(index < 0 || index >= m_items.size()) + { + return Item(); + } - return m_items[index]; + return m_items[index]; } } // namespace Login } // namespace Startup -} // namespace Modules \ No newline at end of file +} // namespace Modules diff --git a/src-cpp/app/modules/startup/login/model.h b/src-cpp/app/modules/startup/login/model.h index 44ac558d9..c0f5a5f55 100644 --- a/src-cpp/app/modules/startup/login/model.h +++ b/src-cpp/app/modules/startup/login/model.h @@ -13,29 +13,29 @@ namespace Login { class Model : public QAbstractListModel { - Q_OBJECT + Q_OBJECT public: - enum ModelRole - { - Name = Qt::UserRole + 1, - Identicon = Qt::UserRole + 2, - ThumbnailImage = Qt::UserRole + 3, - LargeImage = Qt::UserRole + 4, - KeyUid = Qt::UserRole + 5 - }; + enum ModelRole + { + Name = Qt::UserRole + 1, + Identicon = Qt::UserRole + 2, + ThumbnailImage = Qt::UserRole + 3, + LargeImage = Qt::UserRole + 4, + KeyUid = Qt::UserRole + 5 + }; - explicit Model(QObject* parent = nullptr); + explicit Model(QObject* parent = nullptr); - QHash roleNames() const; - virtual int rowCount(const QModelIndex&) const; - virtual QVariant data(const QModelIndex& index, int role) const; - void setItems(QVector items); - Item getItemAtIndex(int index); + QHash roleNames() const; + virtual int rowCount(const QModelIndex&) const; + virtual QVariant data(const QModelIndex& index, int role) const; + void setItems(QVector items); + Item getItemAtIndex(int index); private: - QVector m_items; + QVector m_items; }; } // namespace Login } // namespace Startup -} // namespace Modules \ No newline at end of file +} // namespace Modules diff --git a/src-cpp/app/modules/startup/login/module.cpp b/src-cpp/app/modules/startup/login/module.cpp index d042e1f15..b67a3c3c1 100644 --- a/src-cpp/app/modules/startup/login/module.cpp +++ b/src-cpp/app/modules/startup/login/module.cpp @@ -18,98 +18,98 @@ namespace Startup namespace Login { Module::Module(Modules::Startup::ModuleLoginDelegateInterface* delegate, - // keychainService - Accounts::ServiceInterface* accountsService) - : m_delegate(delegate) + // keychainService + Accounts::ServiceInterface* accountsService) + : m_delegate(delegate) { - m_controller = new Controller(this, accountsService); - m_view = new View(this); - m_moduleLoaded = false; + m_controller = new Controller(this, accountsService); + m_view = new View(this); + m_moduleLoaded = false; } Module::~Module() { - delete m_controller; - delete m_view; + delete m_controller; + delete m_view; } void Module::extractImages(Accounts::AccountDto account, QString& thumbnailImage, QString& largeImage) { - foreach(const Accounts::Image& img, account.images) - { - if(img.imgType == "thumbnail") - { - thumbnailImage = img.uri; - } - else if(img.imgType == "large") - { - largeImage = img.uri; - } - } + foreach(const Accounts::Image& img, account.images) + { + if(img.imgType == "thumbnail") + { + thumbnailImage = img.uri; + } + else if(img.imgType == "large") + { + largeImage = img.uri; + } + } } void Module::load() { - Global::Singleton::instance()->engine()->rootContext()->setContextProperty("loginModule", m_view); - m_controller->init(); - m_view->load(); + Global::Singleton::instance()->engine()->rootContext()->setContextProperty("loginModule", m_view); + m_controller->init(); + m_view->load(); - QVector openedAccounts = m_controller->getOpenedAccounts(); - if(openedAccounts.size() > 0) - { - QVector items; - foreach(const Accounts::AccountDto& acc, openedAccounts) - { - QString thumbnailImage; - QString largeImage; - Module::extractImages(acc, thumbnailImage, largeImage); - items << Item(acc.name, acc.identicon, thumbnailImage, largeImage, acc.keyUid); - } + QVector openedAccounts = m_controller->getOpenedAccounts(); + if(openedAccounts.size() > 0) + { + QVector items; + foreach(const Accounts::AccountDto& acc, openedAccounts) + { + QString thumbnailImage; + QString largeImage; + Module::extractImages(acc, thumbnailImage, largeImage); + items << Item(acc.name, acc.identicon, thumbnailImage, largeImage, acc.keyUid); + } - m_view->setModelItems(items); + m_view->setModelItems(items); - // set the first account as selected one - m_controller->setSelectedAccountKeyUid(items[0].getKeyUid()); - Module::setSelectedAccount(items[0]); - } + // set the first account as selected one + m_controller->setSelectedAccountKeyUid(items[0].getKeyUid()); + Module::setSelectedAccount(items[0]); + } } bool Module::isLoaded() { - return m_moduleLoaded; + return m_moduleLoaded; } void Module::viewDidLoad() { - m_moduleLoaded = true; - m_delegate->loginDidLoad(); + m_moduleLoaded = true; + m_delegate->loginDidLoad(); } void Module::setSelectedAccount(Item item) { - m_controller->setSelectedAccountKeyUid(item.getKeyUid()); - m_view->setSelectedAccount(item); + m_controller->setSelectedAccountKeyUid(item.getKeyUid()); + m_view->setSelectedAccount(item); } void Module::login(QString password) { - m_controller->login(password); + m_controller->login(password); } void Module::emitAccountLoginError(QString error) { - m_view->emitAccountLoginError(error); + m_view->emitAccountLoginError(error); } void Module::emitObtainingPasswordError(QString errorDescription) { - m_view->emitObtainingPasswordError(errorDescription); + m_view->emitObtainingPasswordError(errorDescription); } void Module::emitObtainingPasswordSuccess(QString password) { - m_view->emitObtainingPasswordSuccess(password); + m_view->emitObtainingPasswordSuccess(password); } } // namespace Login } // namespace Startup -} // namespace Modules \ No newline at end of file +} // namespace Modules diff --git a/src-cpp/app/modules/startup/login/module.h b/src-cpp/app/modules/startup/login/module.h index 06025002d..84e5704af 100644 --- a/src-cpp/app/modules/startup/login/module.h +++ b/src-cpp/app/modules/startup/login/module.h @@ -20,27 +20,27 @@ namespace Login class Module : public ModuleAccessInterface, ModuleControllerDelegateInterface, ModuleViewDelegateInterface { private: - Modules::Startup::ModuleLoginDelegateInterface* m_delegate; - View* m_view; - Controller* m_controller; - bool m_moduleLoaded; + Modules::Startup::ModuleLoginDelegateInterface* m_delegate; + View* m_view; + Controller* m_controller; + bool m_moduleLoaded; public: - Module(Modules::Startup::ModuleLoginDelegateInterface* delegate, - // keychainService - Accounts::ServiceInterface* accountsService); - ~Module(); - void extractImages(Accounts::AccountDto account, QString &thumbnailImage, QString &largeImage); - void load() override; - bool isLoaded() override; - void viewDidLoad() override; - void setSelectedAccount(Item item) override; - void login(QString password) override; - void setupAccountError(); - void emitAccountLoginError(QString error) override; - void emitObtainingPasswordError(QString errorDescription) override; - void emitObtainingPasswordSuccess(QString password) override; + Module(Modules::Startup::ModuleLoginDelegateInterface* delegate, + // keychainService + Accounts::ServiceInterface* accountsService); + ~Module(); + void extractImages(Accounts::AccountDto account, QString& thumbnailImage, QString& largeImage); + void load() override; + bool isLoaded() override; + void viewDidLoad() override; + void setSelectedAccount(Item item) override; + void login(QString password) override; + void setupAccountError(); + void emitAccountLoginError(QString error) override; + void emitObtainingPasswordError(QString errorDescription) override; + void emitObtainingPasswordSuccess(QString password) override; }; }; // namespace Login }; // namespace Startup -}; // namespace Modules \ No newline at end of file +}; // namespace Modules diff --git a/src-cpp/app/modules/startup/login/module_access_interface.h b/src-cpp/app/modules/startup/login/module_access_interface.h index 389a2cd7c..93635104c 100644 --- a/src-cpp/app/modules/startup/login/module_access_interface.h +++ b/src-cpp/app/modules/startup/login/module_access_interface.h @@ -9,9 +9,9 @@ namespace Login class ModuleAccessInterface { public: - virtual void load() = 0; + virtual void load() = 0; - virtual bool isLoaded() = 0; + virtual bool isLoaded() = 0; }; }; // namespace Login }; // namespace Startup diff --git a/src-cpp/app/modules/startup/login/selected_account.cpp b/src-cpp/app/modules/startup/login/selected_account.cpp index c3c27fb56..33a896e0a 100644 --- a/src-cpp/app/modules/startup/login/selected_account.cpp +++ b/src-cpp/app/modules/startup/login/selected_account.cpp @@ -9,36 +9,36 @@ namespace Startup namespace Login { SelectedAccount::SelectedAccount(QObject* parent) - : QObject(parent) + : QObject(parent) { } void SelectedAccount::setSelectedAccountData(Item item) { - m_item = item; + m_item = item; } QString SelectedAccount::getName() { - return m_item.getName(); + return m_item.getName(); } QString SelectedAccount::getIdenticon() { - return m_item.getIdenticon(); + return m_item.getIdenticon(); } QString SelectedAccount::getKeyUid() { - return m_item.getKeyUid(); + return m_item.getKeyUid(); } QString SelectedAccount::getThumbnailImage() { - return m_item.getThumbnailImage(); + return m_item.getThumbnailImage(); } QString SelectedAccount::getLargeImage() { - return m_item.getLargeImage(); + return m_item.getLargeImage(); } } // namespace Login } // namespace Startup -} // namespace Modules \ No newline at end of file +} // namespace Modules diff --git a/src-cpp/app/modules/startup/login/selected_account.h b/src-cpp/app/modules/startup/login/selected_account.h index 09a149ec8..88cd3525d 100644 --- a/src-cpp/app/modules/startup/login/selected_account.h +++ b/src-cpp/app/modules/startup/login/selected_account.h @@ -1,8 +1,8 @@ #pragma once +#include "item.h" #include #include -#include "item.h" namespace Modules { @@ -13,27 +13,27 @@ namespace Login class SelectedAccount : public QObject { - Q_OBJECT - Q_PROPERTY(QString username READ getName CONSTANT) - Q_PROPERTY(QString identicon READ getIdenticon CONSTANT) - Q_PROPERTY(QString keyUid READ getKeyUid CONSTANT) - Q_PROPERTY(QString thumbnailImage READ getThumbnailImage CONSTANT) - Q_PROPERTY(QString largeImage READ getLargeImage CONSTANT) + Q_OBJECT + Q_PROPERTY(QString username READ getName CONSTANT) + Q_PROPERTY(QString identicon READ getIdenticon CONSTANT) + Q_PROPERTY(QString keyUid READ getKeyUid CONSTANT) + Q_PROPERTY(QString thumbnailImage READ getThumbnailImage CONSTANT) + Q_PROPERTY(QString largeImage READ getLargeImage CONSTANT) public: - explicit SelectedAccount(QObject* parent = nullptr); + explicit SelectedAccount(QObject* parent = nullptr); private: - Item m_item; + Item m_item; public slots: - void setSelectedAccountData(Item item); - QString getName(); - QString getIdenticon(); - QString getKeyUid(); - QString getThumbnailImage(); - QString getLargeImage(); + void setSelectedAccountData(Item item); + QString getName(); + QString getIdenticon(); + QString getKeyUid(); + QString getThumbnailImage(); + QString getLargeImage(); }; } // namespace Login } // namespace Startup -} // namespace Modules \ No newline at end of file +} // namespace Modules diff --git a/src-cpp/app/modules/startup/login/view.cpp b/src-cpp/app/modules/startup/login/view.cpp index a3351962a..d6a500ded 100644 --- a/src-cpp/app/modules/startup/login/view.cpp +++ b/src-cpp/app/modules/startup/login/view.cpp @@ -12,72 +12,72 @@ namespace Startup namespace Login { View::View(ModuleViewDelegateInterface* delegate, QObject* parent) - : QObject(parent) - , m_delegate(delegate) + : QObject(parent) + , m_delegate(delegate) { - m_model = new Model(); - m_selectedAccount = new SelectedAccount(); + m_model = new Model(); + m_selectedAccount = new SelectedAccount(); } View::~View() { - delete m_model; - delete m_selectedAccount; + delete m_model; + delete m_selectedAccount; } void View::load() { - m_delegate->viewDidLoad(); + m_delegate->viewDidLoad(); } Model* View::getModel() { - return m_model; + return m_model; } SelectedAccount* View::getSelectedAccount() { - return m_selectedAccount; + return m_selectedAccount; } void View::setSelectedAccount(Item item) { - m_selectedAccount->setSelectedAccountData(item); - View::selectedAccountChanged(); + m_selectedAccount->setSelectedAccountData(item); + View::selectedAccountChanged(); } void View::setSelectedAccountByIndex(int index) { - Item item = m_model->getItemAtIndex(index); - m_delegate->setSelectedAccount(item); + Item item = m_model->getItemAtIndex(index); + m_delegate->setSelectedAccount(item); } void View::setModelItems(QVector accounts) { - m_model->setItems(accounts); - View::modelChanged(); + m_model->setItems(accounts); + View::modelChanged(); } void View::login(QString password) { - m_delegate->login(password); + m_delegate->login(password); } void View::emitAccountLoginError(QString error) { - emit View::accountLoginError(error); + emit View::accountLoginError(error); } void View::emitObtainingPasswordError(QString errorDescription) { - emit View::obtainingPasswordError(errorDescription); + emit View::obtainingPasswordError(errorDescription); } void View::emitObtainingPasswordSuccess(QString password) { - emit View::obtainingPasswordSuccess(password); + emit View::obtainingPasswordSuccess(password); } } // namespace Login } // namespace Startup -} // namespace Modules \ No newline at end of file +} // namespace Modules diff --git a/src-cpp/app/modules/startup/login/view.h b/src-cpp/app/modules/startup/login/view.h index ae749c0a1..8bfc0210e 100644 --- a/src-cpp/app/modules/startup/login/view.h +++ b/src-cpp/app/modules/startup/login/view.h @@ -16,38 +16,38 @@ namespace Login class View : public QObject { - Q_OBJECT - Q_PROPERTY(SelectedAccount* selectedAccount READ getSelectedAccount NOTIFY selectedAccountChanged) - Q_PROPERTY(Model* accountsModel READ getModel NOTIFY modelChanged) + Q_OBJECT + Q_PROPERTY(SelectedAccount* selectedAccount READ getSelectedAccount NOTIFY selectedAccountChanged) + Q_PROPERTY(Model* accountsModel READ getModel NOTIFY modelChanged) public: - explicit View(ModuleViewDelegateInterface* delegate, QObject* parent = nullptr); - ~View(); - void load(); + explicit View(ModuleViewDelegateInterface* delegate, QObject* parent = nullptr); + ~View(); + void load(); signals: - void selectedAccountChanged(); - void modelChanged(); - void accountLoginError(QString error); - void obtainingPasswordError(QString errorDescription); - void obtainingPasswordSuccess(QString password); + void selectedAccountChanged(); + void modelChanged(); + void accountLoginError(QString error); + void obtainingPasswordError(QString errorDescription); + void obtainingPasswordSuccess(QString password); private: - ModuleViewDelegateInterface* m_delegate; - Model* m_model; - SelectedAccount* m_selectedAccount; + ModuleViewDelegateInterface* m_delegate; + Model* m_model; + SelectedAccount* m_selectedAccount; public slots: - Model* getModel(); - SelectedAccount* getSelectedAccount(); - void setSelectedAccount(Item item); - void setSelectedAccountByIndex(int index); - void setModelItems(QVector accounts); - void login(QString password); - void emitAccountLoginError(QString error); - void emitObtainingPasswordError(QString errorDescription); - void emitObtainingPasswordSuccess(QString password); + Model* getModel(); + SelectedAccount* getSelectedAccount(); + void setSelectedAccount(Item item); + void setSelectedAccountByIndex(int index); + void setModelItems(QVector accounts); + void login(QString password); + void emitAccountLoginError(QString error); + void emitObtainingPasswordError(QString errorDescription); + void emitObtainingPasswordSuccess(QString password); }; } // namespace Login } // namespace Startup -} // namespace Modules \ No newline at end of file +} // namespace Modules diff --git a/src-cpp/app/modules/startup/module.cpp b/src-cpp/app/modules/startup/module.cpp index 35ff3b99a..6a25a8a4c 100644 --- a/src-cpp/app/modules/startup/module.cpp +++ b/src-cpp/app/modules/startup/module.cpp @@ -15,87 +15,87 @@ namespace Modules namespace Startup { Module::Module(AppControllerDelegate* delegate, - /*keychainService,*/ - Accounts::ServiceInterface* accountsService) - : m_delegate(delegate) + /*keychainService,*/ + Accounts::ServiceInterface* accountsService) + : m_delegate(delegate) { - m_controller = new Controller(this, accountsService); - m_view = new View(this); + m_controller = new Controller(this, accountsService); + m_view = new View(this); - // Submodules - m_onboardingModule = new Modules::Startup::Onboarding::Module(this, accountsService); - m_loginModule = new Modules::Startup::Login::Module(this, /*keychainService, */ accountsService); + // Submodules + m_onboardingModule = new Modules::Startup::Onboarding::Module(this, accountsService); + m_loginModule = new Modules::Startup::Login::Module(this, /*keychainService, */ accountsService); } Module::~Module() { - delete m_controller; - delete m_view; - delete m_onboardingModule; - delete m_loginModule; + delete m_controller; + delete m_view; + delete m_onboardingModule; + delete m_loginModule; } void Module::load() { - Global::Singleton::instance()->engine()->rootContext()->setContextProperty("startupModule", m_view); - m_controller->init(); - m_view->load(); + Global::Singleton::instance()->engine()->rootContext()->setContextProperty("startupModule", m_view); + m_controller->init(); + m_view->load(); - AppState initialAppState(AppState::OnboardingState); - if(!m_controller->shouldStartWithOnboardingScreen()) - { - initialAppState = AppState::LoginState; - } + AppState initialAppState(AppState::OnboardingState); + if(!m_controller->shouldStartWithOnboardingScreen()) + { + initialAppState = AppState::LoginState; + } - m_view->setAppState(initialAppState); + m_view->setAppState(initialAppState); - m_onboardingModule->load(); - m_loginModule->load(); + m_onboardingModule->load(); + m_loginModule->load(); } void Module::checkIfModuleDidLoad() { - if(!m_onboardingModule->isLoaded()) - { - return; - } + if(!m_onboardingModule->isLoaded()) + { + return; + } - if(!m_loginModule->isLoaded()) - { - return; - } + if(!m_loginModule->isLoaded()) + { + return; + } - m_delegate->startupDidLoad(); + m_delegate->startupDidLoad(); } void Module::viewDidLoad() { - Module::checkIfModuleDidLoad(); + Module::checkIfModuleDidLoad(); } void Module::onboardingDidLoad() { - Module::checkIfModuleDidLoad(); + Module::checkIfModuleDidLoad(); } void Module::loginDidLoad() { - Module::checkIfModuleDidLoad(); + Module::checkIfModuleDidLoad(); } void Module::userLoggedIn() { - m_delegate->userLoggedIn(); + m_delegate->userLoggedIn(); } void Module::moveToAppState() { - m_view->setAppState(AppState::MainAppState); + m_view->setAppState(AppState::MainAppState); } void Module::emitLogOut() { - m_view->emitLogOut(); + m_view->emitLogOut(); } } // namespace Startup -} // namespace Modules \ No newline at end of file +} // namespace Modules diff --git a/src-cpp/app/modules/startup/module.h b/src-cpp/app/modules/startup/module.h index 52ec026b2..62520c6af 100644 --- a/src-cpp/app/modules/startup/module.h +++ b/src-cpp/app/modules/startup/module.h @@ -18,31 +18,31 @@ namespace Modules namespace Startup { class Module : public ModuleAccessInterface, - ModuleOnboardingDelegateInterface, - ModuleLoginDelegateInterface, - ModuleControllerDelegateInterface, - ModuleViewDelegateInterface + ModuleOnboardingDelegateInterface, + ModuleLoginDelegateInterface, + ModuleControllerDelegateInterface, + ModuleViewDelegateInterface { private: - AppControllerDelegate* m_delegate; - View* m_view; - Controller* m_controller; + AppControllerDelegate* m_delegate; + View* m_view; + Controller* m_controller; - Modules::Startup::Onboarding::ModuleAccessInterface* m_onboardingModule; - Modules::Startup::Login::ModuleAccessInterface* m_loginModule; + Modules::Startup::Onboarding::ModuleAccessInterface* m_onboardingModule; + Modules::Startup::Login::ModuleAccessInterface* m_loginModule; public: - Module(AppControllerDelegate* delegate, - /*keychainService,*/ Accounts::ServiceInterface* accountsService); - ~Module(); - void load() override; - void checkIfModuleDidLoad(); - void viewDidLoad() override; - void onboardingDidLoad(); - void loginDidLoad(); - void userLoggedIn() override; - void moveToAppState() override; - void emitLogOut() override; + Module(AppControllerDelegate* delegate, + /*keychainService,*/ Accounts::ServiceInterface* accountsService); + ~Module(); + void load() override; + void checkIfModuleDidLoad(); + void viewDidLoad() override; + void onboardingDidLoad(); + void loginDidLoad(); + void userLoggedIn() override; + void moveToAppState() override; + void emitLogOut() override; }; }; // namespace Startup -}; // namespace Modules \ No newline at end of file +}; // namespace Modules diff --git a/src-cpp/app/modules/startup/module_access_interface.h b/src-cpp/app/modules/startup/module_access_interface.h index 1aec7bb40..d8d6f2e29 100644 --- a/src-cpp/app/modules/startup/module_access_interface.h +++ b/src-cpp/app/modules/startup/module_access_interface.h @@ -7,7 +7,7 @@ namespace Startup class ModuleAccessInterface { public: - virtual void load() = 0; + virtual void load() = 0; virtual void moveToAppState() = 0; }; diff --git a/src-cpp/app/modules/startup/onboarding/controller.cpp b/src-cpp/app/modules/startup/onboarding/controller.cpp index f66e12731..4f2c1a68c 100644 --- a/src-cpp/app/modules/startup/onboarding/controller.cpp +++ b/src-cpp/app/modules/startup/onboarding/controller.cpp @@ -14,67 +14,67 @@ namespace Startup namespace Onboarding { Controller::Controller(ModuleControllerDelegateInterface* delegate, - Accounts::ServiceInterface* accountsService, - QObject* parent) - : QObject(parent) - , m_accountsService(accountsService) - , m_delegate(delegate) + Accounts::ServiceInterface* accountsService, + QObject* parent) + : QObject(parent) + , m_accountsService(accountsService) + , m_delegate(delegate) { } void Controller::init() { - QObject::connect(Signals::Manager::instance(), &Signals::Manager::nodeLogin, this, &Controller::onLogin); + QObject::connect(Signals::Manager::instance(), &Signals::Manager::nodeLogin, this, &Controller::onLogin); } void Controller::onLogin(Signals::NodeSignal signal) { - if(!signal.error.isEmpty()) - { - m_delegate->setupAccountError(); - } + if(!signal.error.isEmpty()) + { + m_delegate->setupAccountError(); + } } QVector Controller::getGeneratedAccounts() { - return m_accountsService->generatedAccounts(); + return m_accountsService->generatedAccounts(); } Accounts::GeneratedAccountDto Controller::getImportedAccount() { - return m_accountsService->getImportedAccount(); + return m_accountsService->getImportedAccount(); } void Controller::setSelectedAccountByIndex(int index) { - auto accounts = Controller::getGeneratedAccounts(); - m_selectedAccountId = accounts[index].id; + auto accounts = Controller::getGeneratedAccounts(); + m_selectedAccountId = accounts[index].id; } void Controller::storeSelectedAccountAndLogin(QString password) { - if(!m_accountsService->setupAccount(m_selectedAccountId, password)) - { - m_delegate->setupAccountError(); - } + if(!m_accountsService->setupAccount(m_selectedAccountId, password)) + { + m_delegate->setupAccountError(); + } } QString Controller::validateMnemonic(QString mnemonic) { - return m_accountsService->validateMnemonic(mnemonic); + return m_accountsService->validateMnemonic(mnemonic); } void Controller::importMnemonic(QString mnemonic) { - if(m_accountsService->importMnemonic(mnemonic)) - { - m_selectedAccountId = Controller::getImportedAccount().id; - m_delegate->importAccountSuccess(); - } - else - { - m_delegate->importAccountError(); - } + if(m_accountsService->importMnemonic(mnemonic)) + { + m_selectedAccountId = Controller::getImportedAccount().id; + m_delegate->importAccountSuccess(); + } + else + { + m_delegate->importAccountError(); + } } } // namespace Onboarding } // namespace Startup -} // namespace Modules \ No newline at end of file +} // namespace Modules diff --git a/src-cpp/app/modules/startup/onboarding/controller.h b/src-cpp/app/modules/startup/onboarding/controller.h index cd9844c50..9f9ad3b63 100644 --- a/src-cpp/app/modules/startup/onboarding/controller.h +++ b/src-cpp/app/modules/startup/onboarding/controller.h @@ -16,26 +16,26 @@ namespace Onboarding { class Controller : public QObject, ControllerInterface { - Q_OBJECT + Q_OBJECT public: - Controller(ModuleControllerDelegateInterface* delegate, - Accounts::ServiceInterface* accountsService, - QObject* parent = nullptr); - void init() override; - QVector getGeneratedAccounts() override; - Accounts::GeneratedAccountDto getImportedAccount() override; - void setSelectedAccountByIndex(int index) override; - void storeSelectedAccountAndLogin(QString password) override; - QString validateMnemonic(QString mnemonic) override; - void importMnemonic(QString mnemonic) override; - void onLogin(Signals::NodeSignal signal); + Controller(ModuleControllerDelegateInterface* delegate, + Accounts::ServiceInterface* accountsService, + QObject* parent = nullptr); + void init() override; + QVector getGeneratedAccounts() override; + Accounts::GeneratedAccountDto getImportedAccount() override; + void setSelectedAccountByIndex(int index) override; + void storeSelectedAccountAndLogin(QString password) override; + QString validateMnemonic(QString mnemonic) override; + void importMnemonic(QString mnemonic) override; + void onLogin(Signals::NodeSignal signal); private: - Accounts::ServiceInterface* m_accountsService; - ModuleControllerDelegateInterface* m_delegate; - QString m_selectedAccountId; + Accounts::ServiceInterface* m_accountsService; + ModuleControllerDelegateInterface* m_delegate; + QString m_selectedAccountId; }; } // namespace Onboarding } // namespace Startup -} // namespace Modules \ No newline at end of file +} // namespace Modules diff --git a/src-cpp/app/modules/startup/onboarding/controller_interface.h b/src-cpp/app/modules/startup/onboarding/controller_interface.h index 3b01acffa..1df5bedc4 100644 --- a/src-cpp/app/modules/startup/onboarding/controller_interface.h +++ b/src-cpp/app/modules/startup/onboarding/controller_interface.h @@ -14,19 +14,19 @@ namespace Onboarding class ControllerInterface { public: - virtual void init() = 0; - - virtual QVector getGeneratedAccounts() = 0; - - virtual void setSelectedAccountByIndex(int index) = 0; - - virtual void storeSelectedAccountAndLogin(QString password) = 0; - - virtual Accounts::GeneratedAccountDto getImportedAccount() = 0; - - virtual QString validateMnemonic(QString mnemonic) = 0; - - virtual void importMnemonic(QString mnemonic) = 0; + virtual void init() = 0; + + virtual QVector getGeneratedAccounts() = 0; + + virtual void setSelectedAccountByIndex(int index) = 0; + + virtual void storeSelectedAccountAndLogin(QString password) = 0; + + virtual Accounts::GeneratedAccountDto getImportedAccount() = 0; + + virtual QString validateMnemonic(QString mnemonic) = 0; + + virtual void importMnemonic(QString mnemonic) = 0; }; } // namespace Onboarding } // namespace Startup diff --git a/src-cpp/app/modules/startup/onboarding/interfaces/module_controller_delegate_interface.h b/src-cpp/app/modules/startup/onboarding/interfaces/module_controller_delegate_interface.h index 340bf8793..e62d2c4db 100644 --- a/src-cpp/app/modules/startup/onboarding/interfaces/module_controller_delegate_interface.h +++ b/src-cpp/app/modules/startup/onboarding/interfaces/module_controller_delegate_interface.h @@ -9,12 +9,12 @@ namespace Onboarding class ModuleControllerDelegateInterface { public: - virtual void setupAccountError() = 0; + virtual void setupAccountError() = 0; - virtual void importAccountError() = 0; + virtual void importAccountError() = 0; - virtual void importAccountSuccess() = 0; + virtual void importAccountSuccess() = 0; }; }; // namespace Onboarding }; // namespace Startup -}; // namespace Modules \ No newline at end of file +}; // namespace Modules diff --git a/src-cpp/app/modules/startup/onboarding/interfaces/module_view_delegate_interface.h b/src-cpp/app/modules/startup/onboarding/interfaces/module_view_delegate_interface.h index efcb1579b..76f9d8d97 100644 --- a/src-cpp/app/modules/startup/onboarding/interfaces/module_view_delegate_interface.h +++ b/src-cpp/app/modules/startup/onboarding/interfaces/module_view_delegate_interface.h @@ -11,18 +11,18 @@ namespace Onboarding class ModuleViewDelegateInterface { public: - virtual void viewDidLoad() = 0; + virtual void viewDidLoad() = 0; - virtual void setSelectedAccountByIndex(int index) = 0; + virtual void setSelectedAccountByIndex(int index) = 0; - virtual void storeSelectedAccountAndLogin(QString password) = 0; + virtual void storeSelectedAccountAndLogin(QString password) = 0; - virtual Accounts::GeneratedAccountDto getImportedAccount() = 0; + virtual Accounts::GeneratedAccountDto getImportedAccount() = 0; - virtual QString validateMnemonic(QString mnemonic) = 0; + virtual QString validateMnemonic(QString mnemonic) = 0; - virtual void importMnemonic(QString mnemonic) = 0; + virtual void importMnemonic(QString mnemonic) = 0; }; }; // namespace Onboarding }; // namespace Startup -}; // namespace Modules \ No newline at end of file +}; // namespace Modules diff --git a/src-cpp/app/modules/startup/onboarding/item.cpp b/src-cpp/app/modules/startup/onboarding/item.cpp index 61e84de2f..7bebf211f 100644 --- a/src-cpp/app/modules/startup/onboarding/item.cpp +++ b/src-cpp/app/modules/startup/onboarding/item.cpp @@ -8,32 +8,32 @@ namespace Startup namespace Onboarding { Item::Item(QString id, QString alias, QString identicon, QString address, QString keyUid) - : m_id(id) - , m_alias(alias) - , m_identicon(identicon) - , m_address(address) - , m_keyUid(keyUid) + : m_id(id) + , m_alias(alias) + , m_identicon(identicon) + , m_address(address) + , m_keyUid(keyUid) { } QString Item::getId() { - return m_id; + return m_id; } QString Item::getAlias() { - return m_alias; + return m_alias; } QString Item::getIdenticon() { - return m_identicon; + return m_identicon; } QString Item::getAddress() { - return m_address; + return m_address; } QString Item::getKeyUid() { - return m_keyUid; + return m_keyUid; } } // namespace Onboarding } // namespace Startup -} // namespace Modules \ No newline at end of file +} // namespace Modules diff --git a/src-cpp/app/modules/startup/onboarding/item.h b/src-cpp/app/modules/startup/onboarding/item.h index 7e9c4a250..1100c84ab 100644 --- a/src-cpp/app/modules/startup/onboarding/item.h +++ b/src-cpp/app/modules/startup/onboarding/item.h @@ -11,19 +11,19 @@ namespace Onboarding class Item { private: - QString m_id; - QString m_alias; - QString m_identicon; - QString m_address; - QString m_keyUid; + QString m_id; + QString m_alias; + QString m_identicon; + QString m_address; + QString m_keyUid; public: - Item(QString id, QString alias, QString identicon, QString address, QString keyUid); - QString getId(); - QString getAlias(); - QString getIdenticon(); - QString getAddress(); - QString getKeyUid(); + Item(QString id, QString alias, QString identicon, QString address, QString keyUid); + QString getId(); + QString getAlias(); + QString getIdenticon(); + QString getAddress(); + QString getKeyUid(); }; } // namespace Onboarding } // namespace Startup diff --git a/src-cpp/app/modules/startup/onboarding/model.cpp b/src-cpp/app/modules/startup/onboarding/model.cpp index d27e1ab61..2d5b5d6c6 100644 --- a/src-cpp/app/modules/startup/onboarding/model.cpp +++ b/src-cpp/app/modules/startup/onboarding/model.cpp @@ -9,58 +9,58 @@ namespace Startup namespace Onboarding { Model::Model(QObject* parent) - : QAbstractListModel(parent) + : QAbstractListModel(parent) { } QHash Model::roleNames() const { - QHash roles; - roles[Id] = "accountId"; - roles[Alias] = "username"; - roles[Identicon] = "identicon"; - roles[Address] = "address"; - roles[KeyUid] = "keyUid"; - return roles; + QHash roles; + roles[Id] = "accountId"; + roles[Alias] = "username"; + roles[Identicon] = "identicon"; + roles[Address] = "address"; + roles[KeyUid] = "keyUid"; + return roles; } int Model::rowCount(const QModelIndex& parent = QModelIndex()) const { - return m_items.size(); + return m_items.size(); } QVariant Model::data(const QModelIndex& index, int role) const { - if(!index.isValid()) - { - return QVariant(); - } + if(!index.isValid()) + { + return QVariant(); + } - if(index.row() < 0 || index.row() > m_items.size()) - { - return QVariant(); - } + if(index.row() < 0 || index.row() > m_items.size()) + { + return QVariant(); + } - Item item = m_items[index.row()]; + Item item = m_items[index.row()]; - switch(role) - { - case Id: return QVariant(item.getId()); - case Alias: return QVariant(item.getAlias()); - case Identicon: return QVariant(item.getIdenticon()); - case Address: return QVariant(item.getAddress()); - case KeyUid: return QVariant(item.getKeyUid()); - } + switch(role) + { + case Id: return QVariant(item.getId()); + case Alias: return QVariant(item.getAlias()); + case Identicon: return QVariant(item.getIdenticon()); + case Address: return QVariant(item.getAddress()); + case KeyUid: return QVariant(item.getKeyUid()); + } - return QVariant(); + return QVariant(); } void Model::setItems(QVector items) { - beginResetModel(); - m_items = items; - endResetModel(); + beginResetModel(); + m_items = items; + endResetModel(); } } // namespace Onboarding } // namespace Startup -} // namespace Modules \ No newline at end of file +} // namespace Modules diff --git a/src-cpp/app/modules/startup/onboarding/model.h b/src-cpp/app/modules/startup/onboarding/model.h index edcd698db..e5ba6ebc8 100644 --- a/src-cpp/app/modules/startup/onboarding/model.h +++ b/src-cpp/app/modules/startup/onboarding/model.h @@ -1,9 +1,9 @@ #pragma once +#include "item.h" #include #include #include -#include "item.h" namespace Modules { @@ -13,28 +13,28 @@ namespace Onboarding { class Model : public QAbstractListModel { - Q_OBJECT + Q_OBJECT public: - enum ModelRole - { - Id = Qt::UserRole + 1, - Alias = Qt::UserRole + 2, - Identicon = Qt::UserRole + 3, - Address = Qt::UserRole + 4, - KeyUid = Qt::UserRole + 5 - }; + enum ModelRole + { + Id = Qt::UserRole + 1, + Alias = Qt::UserRole + 2, + Identicon = Qt::UserRole + 3, + Address = Qt::UserRole + 4, + KeyUid = Qt::UserRole + 5 + }; - explicit Model(QObject* parent = nullptr); + explicit Model(QObject* parent = nullptr); - QHash roleNames() const; - virtual int rowCount(const QModelIndex&) const; - virtual QVariant data(const QModelIndex& index, int role) const; - void setItems(QVector items); + QHash roleNames() const; + virtual int rowCount(const QModelIndex&) const; + virtual QVariant data(const QModelIndex& index, int role) const; + void setItems(QVector items); private: - QVector m_items; + QVector m_items; }; } // namespace Onboarding } // namespace Startup -} // namespace Modules \ No newline at end of file +} // namespace Modules diff --git a/src-cpp/app/modules/startup/onboarding/module.cpp b/src-cpp/app/modules/startup/onboarding/module.cpp index 6961bf54a..d2d1bacc5 100644 --- a/src-cpp/app/modules/startup/onboarding/module.cpp +++ b/src-cpp/app/modules/startup/onboarding/module.cpp @@ -18,85 +18,85 @@ namespace Startup namespace Onboarding { Module::Module(Modules::Startup::ModuleOnboardingDelegateInterface* delegate, - Accounts::ServiceInterface* accountsService) - : m_delegate(delegate) + Accounts::ServiceInterface* accountsService) + : m_delegate(delegate) { - m_controller = new Controller(this, accountsService); - m_view = new View(this); - m_moduleLoaded = false; + m_controller = new Controller(this, accountsService); + m_view = new View(this); + m_moduleLoaded = false; } Module::~Module() { - delete m_controller; - delete m_view; + delete m_controller; + delete m_view; } void Module::load() { - Global::Singleton::instance()->engine()->rootContext()->setContextProperty("onboardingModule", m_view); - m_controller->init(); - m_view->load(); + Global::Singleton::instance()->engine()->rootContext()->setContextProperty("onboardingModule", m_view); + m_controller->init(); + m_view->load(); - QVector gAcc = m_controller->getGeneratedAccounts(); - QVector accounts; - foreach(const Accounts::GeneratedAccountDto& acc, gAcc) - { - accounts << Item(acc.id, acc.alias, acc.identicon, acc.address, acc.keyUid); - } + QVector gAcc = m_controller->getGeneratedAccounts(); + QVector accounts; + foreach(const Accounts::GeneratedAccountDto& acc, gAcc) + { + accounts << Item(acc.id, acc.alias, acc.identicon, acc.address, acc.keyUid); + } - m_view->setAccountList(accounts); + m_view->setAccountList(accounts); } bool Module::isLoaded() { - return m_moduleLoaded; + return m_moduleLoaded; } void Module::viewDidLoad() { - m_moduleLoaded = true; - m_delegate->onboardingDidLoad(); + m_moduleLoaded = true; + m_delegate->onboardingDidLoad(); } void Module::setSelectedAccountByIndex(int index) { - m_controller->setSelectedAccountByIndex(index); + m_controller->setSelectedAccountByIndex(index); } void Module::storeSelectedAccountAndLogin(QString password) { - m_controller->storeSelectedAccountAndLogin(password); + m_controller->storeSelectedAccountAndLogin(password); } void Module::setupAccountError() { - m_view->setupAccountError(); + m_view->setupAccountError(); } Accounts::GeneratedAccountDto Module::getImportedAccount() { - return m_controller->getImportedAccount(); + return m_controller->getImportedAccount(); } QString Module::validateMnemonic(QString mnemonic) { - return m_controller->validateMnemonic(mnemonic); + return m_controller->validateMnemonic(mnemonic); } void Module::importMnemonic(QString mnemonic) { - m_controller->importMnemonic(mnemonic); + m_controller->importMnemonic(mnemonic); } void Module::importAccountError() { - m_view->importAccountError(); + m_view->importAccountError(); } void Module::importAccountSuccess() { - m_view->importAccountSuccess(); + m_view->importAccountSuccess(); } } // namespace Onboarding } // namespace Startup -} // namespace Modules \ No newline at end of file +} // namespace Modules diff --git a/src-cpp/app/modules/startup/onboarding/module.h b/src-cpp/app/modules/startup/onboarding/module.h index b054e544b..bef511e7f 100644 --- a/src-cpp/app/modules/startup/onboarding/module.h +++ b/src-cpp/app/modules/startup/onboarding/module.h @@ -19,26 +19,26 @@ namespace Onboarding class Module : public ModuleAccessInterface, ModuleControllerDelegateInterface, ModuleViewDelegateInterface { private: - Modules::Startup::ModuleOnboardingDelegateInterface* m_delegate; - View* m_view; - Controller* m_controller; - bool m_moduleLoaded; + Modules::Startup::ModuleOnboardingDelegateInterface* m_delegate; + View* m_view; + Controller* m_controller; + bool m_moduleLoaded; public: - Module(Modules::Startup::ModuleOnboardingDelegateInterface* delegate, Accounts::ServiceInterface* accountsService); - ~Module(); - void load() override; - bool isLoaded() override; - void viewDidLoad() override; - void setSelectedAccountByIndex(int index) override; - void storeSelectedAccountAndLogin(QString password) override; - void setupAccountError() override; - Accounts::GeneratedAccountDto getImportedAccount() override; - QString validateMnemonic(QString mnemonic) override; - void importMnemonic(QString mnemonic) override; - void importAccountError() override; - void importAccountSuccess() override; + Module(Modules::Startup::ModuleOnboardingDelegateInterface* delegate, Accounts::ServiceInterface* accountsService); + ~Module(); + void load() override; + bool isLoaded() override; + void viewDidLoad() override; + void setSelectedAccountByIndex(int index) override; + void storeSelectedAccountAndLogin(QString password) override; + void setupAccountError() override; + Accounts::GeneratedAccountDto getImportedAccount() override; + QString validateMnemonic(QString mnemonic) override; + void importMnemonic(QString mnemonic) override; + void importAccountError() override; + void importAccountSuccess() override; }; }; // namespace Onboarding }; // namespace Startup -}; // namespace Modules \ No newline at end of file +}; // namespace Modules diff --git a/src-cpp/app/modules/startup/onboarding/module_access_interface.h b/src-cpp/app/modules/startup/onboarding/module_access_interface.h index 22ef8cc13..6fa55aede 100644 --- a/src-cpp/app/modules/startup/onboarding/module_access_interface.h +++ b/src-cpp/app/modules/startup/onboarding/module_access_interface.h @@ -9,9 +9,9 @@ namespace Onboarding class ModuleAccessInterface { public: - virtual void load() = 0; + virtual void load() = 0; - virtual bool isLoaded() = 0; + virtual bool isLoaded() = 0; }; }; // namespace Onboarding }; // namespace Startup diff --git a/src-cpp/app/modules/startup/onboarding/view.cpp b/src-cpp/app/modules/startup/onboarding/view.cpp index 911452673..07d744764 100644 --- a/src-cpp/app/modules/startup/onboarding/view.cpp +++ b/src-cpp/app/modules/startup/onboarding/view.cpp @@ -10,84 +10,84 @@ namespace Startup namespace Onboarding { View::View(ModuleViewDelegateInterface* delegate, QObject* parent) - : QObject(parent) - , m_delegate(delegate) + : QObject(parent) + , m_delegate(delegate) { - m_model = new Model(); + m_model = new Model(); } View::~View() { - delete m_model; + delete m_model; } void View::load() { - m_delegate->viewDidLoad(); + m_delegate->viewDidLoad(); } Model* View::getModel() { - return m_model; + return m_model; } void View::setAccountList(QVector accounts) { - m_model->setItems(accounts); - View::modelChanged(); + m_model->setItems(accounts); + View::modelChanged(); } QString View::getImportedAccountIdenticon() { - return m_delegate->getImportedAccount().identicon; + return m_delegate->getImportedAccount().identicon; } QString View::getImportedAccountAlias() { - return m_delegate->getImportedAccount().alias; + return m_delegate->getImportedAccount().alias; } QString View::getImportedAccountAddress() { - return m_delegate->getImportedAccount().address; + return m_delegate->getImportedAccount().address; } void View::setSelectedAccountByIndex(int index) { - m_delegate->setSelectedAccountByIndex(index); + m_delegate->setSelectedAccountByIndex(index); } void View::storeSelectedAccountAndLogin(QString password) { - m_delegate->storeSelectedAccountAndLogin(password); + m_delegate->storeSelectedAccountAndLogin(password); } void View::setupAccountError() { - View::accountSetupError(); + View::accountSetupError(); } QString View::validateMnemonic(QString mnemonic) { - return m_delegate->validateMnemonic(mnemonic); + return m_delegate->validateMnemonic(mnemonic); } void View::importMnemonic(QString mnemonic) { - m_delegate->importMnemonic(mnemonic); + m_delegate->importMnemonic(mnemonic); } void View::importAccountError() { - // In QML we can connect to this signal and notify a user - // before refactoring we didn't have this signal - View::accountImportError(); + // In QML we can connect to this signal and notify a user + // before refactoring we didn't have this signal + View::accountImportError(); } void View::importAccountSuccess() { - View::importedAccountChanged(); + View::importedAccountChanged(); } } // namespace Onboarding } // namespace Startup -} // namespace Modules \ No newline at end of file +} // namespace Modules diff --git a/src-cpp/app/modules/startup/onboarding/view.h b/src-cpp/app/modules/startup/onboarding/view.h index 468b5221e..f6b8abe6c 100644 --- a/src-cpp/app/modules/startup/onboarding/view.h +++ b/src-cpp/app/modules/startup/onboarding/view.h @@ -15,41 +15,41 @@ namespace Onboarding class View : public QObject { - Q_OBJECT - Q_PROPERTY(Model* accountsModel READ getModel NOTIFY modelChanged) - Q_PROPERTY(QString importedAccountIdenticon READ getImportedAccountIdenticon NOTIFY importedAccountChanged) - Q_PROPERTY(QString importedAccountAlias READ getImportedAccountAlias NOTIFY importedAccountChanged) - Q_PROPERTY(QString importedAccountAddress READ getImportedAccountAddress NOTIFY importedAccountChanged) + Q_OBJECT + Q_PROPERTY(Model* accountsModel READ getModel NOTIFY modelChanged) + Q_PROPERTY(QString importedAccountIdenticon READ getImportedAccountIdenticon NOTIFY importedAccountChanged) + Q_PROPERTY(QString importedAccountAlias READ getImportedAccountAlias NOTIFY importedAccountChanged) + Q_PROPERTY(QString importedAccountAddress READ getImportedAccountAddress NOTIFY importedAccountChanged) public: - explicit View(ModuleViewDelegateInterface* delegate, QObject* parent = nullptr); - ~View(); - void load(); + explicit View(ModuleViewDelegateInterface* delegate, QObject* parent = nullptr); + ~View(); + void load(); signals: - void modelChanged(); - void importedAccountChanged(); - void accountSetupError(); - void accountImportError(); + void modelChanged(); + void importedAccountChanged(); + void accountSetupError(); + void accountImportError(); private: - ModuleViewDelegateInterface* m_delegate; - Model* m_model; + ModuleViewDelegateInterface* m_delegate; + Model* m_model; public slots: - Model* getModel(); - void setAccountList(QVector accounts); - QString getImportedAccountIdenticon(); - QString getImportedAccountAlias(); - QString getImportedAccountAddress(); - void setSelectedAccountByIndex(int index); - void storeSelectedAccountAndLogin(QString password); - QString validateMnemonic(QString mnemonic); - void importMnemonic(QString mnemonic); - void importAccountError(); - void setupAccountError(); - void importAccountSuccess(); + Model* getModel(); + void setAccountList(QVector accounts); + QString getImportedAccountIdenticon(); + QString getImportedAccountAlias(); + QString getImportedAccountAddress(); + void setSelectedAccountByIndex(int index); + void storeSelectedAccountAndLogin(QString password); + QString validateMnemonic(QString mnemonic); + void importMnemonic(QString mnemonic); + void importAccountError(); + void setupAccountError(); + void importAccountSuccess(); }; } // namespace Onboarding } // namespace Startup -} // namespace Modules \ No newline at end of file +} // namespace Modules diff --git a/src-cpp/app/modules/startup/view.cpp b/src-cpp/app/modules/startup/view.cpp index 8a385602c..8da173880 100644 --- a/src-cpp/app/modules/startup/view.cpp +++ b/src-cpp/app/modules/startup/view.cpp @@ -8,37 +8,37 @@ namespace Startup { View::View(ModuleViewDelegateInterface* delegate, QObject* parent) - : QObject(parent) - , m_appState(AppState::OnboardingState) - , m_delegate(delegate) + : QObject(parent) + , m_appState(AppState::OnboardingState) + , m_delegate(delegate) { } void View::load() { - // In some point, here, we will setup some exposed main module related things. - m_delegate->viewDidLoad(); + // In some point, here, we will setup some exposed main module related things. + m_delegate->viewDidLoad(); } int View::getAppState() { - return static_cast(m_appState); + return static_cast(m_appState); } void View::setAppState(AppState state) { - if(m_appState == state) - { - return; - } + if(m_appState == state) + { + return; + } - m_appState = state; - appStateChanged(static_cast(m_appState)); + m_appState = state; + appStateChanged(static_cast(m_appState)); } void View::emitLogOut() { - logOut(); + logOut(); } } // namespace Startup -} // namespace Modules \ No newline at end of file +} // namespace Modules diff --git a/src-cpp/app/modules/startup/view.h b/src-cpp/app/modules/startup/view.h index ba4fb43e2..297cd45bd 100644 --- a/src-cpp/app/modules/startup/view.h +++ b/src-cpp/app/modules/startup/view.h @@ -9,33 +9,33 @@ namespace Startup { enum AppState { - OnboardingState = 0, - LoginState = 1, - MainAppState = 2 - // TODO: is Pending + OnboardingState = 0, + LoginState = 1, + MainAppState = 2 + // TODO: is Pending }; class View : public QObject { - Q_OBJECT - Q_PROPERTY(int appState READ getAppState NOTIFY appStateChanged) + Q_OBJECT + Q_PROPERTY(int appState READ getAppState NOTIFY appStateChanged) public: - explicit View(ModuleViewDelegateInterface* delegate, QObject* parent = nullptr); - void emitLogOut(); - void setAppState(AppState state); - void load(); - + explicit View(ModuleViewDelegateInterface* delegate, QObject* parent = nullptr); + void emitLogOut(); + void setAppState(AppState state); + void load(); + signals: - void appStateChanged(int state); - void logOut(); + void appStateChanged(int state); + void logOut(); private: - ModuleViewDelegateInterface* m_delegate; - AppState m_appState; + ModuleViewDelegateInterface* m_delegate; + AppState m_appState; public slots: - int getAppState(); + int getAppState(); }; } // namespace Startup -} // namespace Modules \ No newline at end of file +} // namespace Modules diff --git a/src-cpp/app_service/constants.cpp b/src-cpp/app_service/constants.cpp index e4b5f8422..138929eec 100644 --- a/src-cpp/app_service/constants.cpp +++ b/src-cpp/app_service/constants.cpp @@ -6,19 +6,17 @@ // TODO: merge with constants from backend/ - QString Constants::applicationPath(QString path) { - return QFileInfo(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + path).absoluteFilePath(); + return QFileInfo(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + path).absoluteFilePath(); } QString Constants::tmpPath(QString path) { - return QFileInfo(QStandardPaths::writableLocation(QStandardPaths::TempLocation) + path).absoluteFilePath(); + return QFileInfo(QStandardPaths::writableLocation(QStandardPaths::TempLocation) + path).absoluteFilePath(); } QString Constants::cachePath(QString path) { - return QFileInfo(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + path).absoluteFilePath(); + return QFileInfo(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + path).absoluteFilePath(); } - diff --git a/src-cpp/app_service/include/accounts/account.h b/src-cpp/app_service/include/accounts/account.h index 209cc52e5..7a9478ec9 100644 --- a/src-cpp/app_service/include/accounts/account.h +++ b/src-cpp/app_service/include/accounts/account.h @@ -9,29 +9,29 @@ namespace Accounts class Image { public: - QString keyUid; - QString imgType; - QString uri; - int width; - int height; - int fileSize; - int resizeTarget; + QString keyUid; + QString imgType; + QString uri; + int width; + int height; + int fileSize; + int resizeTarget; }; class AccountDto { public: - QString name; - long timestamp; - QString identicon; - QString keycardPairing; - QString keyUid; - QVector images; + QString name; + long timestamp; + QString identicon; + QString keycardPairing; + QString keyUid; + QVector images; - bool isValid(); + bool isValid(); }; Image toImage(const QJsonValue jsonObj); AccountDto toAccountDto(const QJsonValue jsonObj); -} // namespace Accounts \ No newline at end of file +} // namespace Accounts diff --git a/src-cpp/app_service/include/accounts/generated_account.h b/src-cpp/app_service/include/accounts/generated_account.h index 9bb106aad..3abcf40eb 100644 --- a/src-cpp/app_service/include/accounts/generated_account.h +++ b/src-cpp/app_service/include/accounts/generated_account.h @@ -1,42 +1,42 @@ #pragma once -#include #include +#include namespace Accounts { class DerivedAccountDetails { public: - QString publicKey; - QString address; - QString derivationPath; + QString publicKey; + QString address; + QString derivationPath; }; class DerivedAccounts { public: - DerivedAccountDetails whisper; - DerivedAccountDetails walletRoot; - DerivedAccountDetails defaultWallet; - DerivedAccountDetails eip1581; + DerivedAccountDetails whisper; + DerivedAccountDetails walletRoot; + DerivedAccountDetails defaultWallet; + DerivedAccountDetails eip1581; }; class GeneratedAccountDto { public: - QString id; - QString publicKey; - QString address; - QString keyUid; - QString mnemonic; - DerivedAccounts derivedAccounts; + QString id; + QString publicKey; + QString address; + QString keyUid; + QString mnemonic; + DerivedAccounts derivedAccounts; - // The following two are set additionally. - QString alias; - QString identicon; + // The following two are set additionally. + QString alias; + QString identicon; - bool isValid(); + bool isValid(); }; DerivedAccountDetails toDerivedAccountDetails(const QJsonValue jsonObj, QString derivationPath); diff --git a/src-cpp/app_service/include/accounts/service.h b/src-cpp/app_service/include/accounts/service.h index b0feedba1..00965a9e7 100644 --- a/src-cpp/app_service/include/accounts/service.h +++ b/src-cpp/app_service/include/accounts/service.h @@ -12,61 +12,61 @@ namespace Accounts class Service : public ServiceInterface { private: - QVector m_generatedAccounts; + QVector m_generatedAccounts; - bool m_isFirstTimeAccountLogin; - AccountDto m_loggedInAccount; - GeneratedAccountDto m_importedAccount; + bool m_isFirstTimeAccountLogin; + AccountDto m_loggedInAccount; + GeneratedAccountDto m_importedAccount; public: - Service(); + Service(); - void init() override; + void init() override; - virtual QVector openedAccounts() override; + virtual QVector openedAccounts() override; - QVector generatedAccounts() override; + QVector generatedAccounts() override; - bool setupAccount(QString accountId, QString password) override; + bool setupAccount(QString accountId, QString password) override; - AccountDto getLoggedInAccount() override; + AccountDto getLoggedInAccount() override; - GeneratedAccountDto getImportedAccount() override; + GeneratedAccountDto getImportedAccount() override; - bool isFirstTimeAccountLogin() override; + bool isFirstTimeAccountLogin() override; - QString validateMnemonic(QString mnemonic) override; + QString validateMnemonic(QString mnemonic) override; - bool importMnemonic(QString mnemonic) override; + bool importMnemonic(QString mnemonic) override; - QString login(AccountDto account, QString password) override; + QString login(AccountDto account, QString password) override; - void clear() override; + void clear() override; - QString generateAlias(QString publicKey) override; + QString generateAlias(QString publicKey) override; - QString generateIdenticon(QString publicKey) override; + QString generateIdenticon(QString publicKey) override; - bool verifyAccountPassword(QString account, QString password) override; + bool verifyAccountPassword(QString account, QString password) override; - DerivedAccounts storeDerivedAccounts(QString accountId, QString hashedPassword, QVector paths); + DerivedAccounts storeDerivedAccounts(QString accountId, QString hashedPassword, QVector paths); - QJsonObject getAccountDataForAccountId(QString accountId); + QJsonObject getAccountDataForAccountId(QString accountId); - QJsonArray getSubaccountDataForAccountId(QString accountId); + QJsonArray getSubaccountDataForAccountId(QString accountId); - QJsonObject getAccountSettings(QString accountId, QString installationId); + QJsonObject getAccountSettings(QString accountId, QString installationId); - QJsonObject getDefaultNodeConfig(QString installationId); + QJsonObject getDefaultNodeConfig(QString installationId); - QJsonObject prepareAccountJsonObject(const GeneratedAccountDto account); + QJsonObject prepareAccountJsonObject(const GeneratedAccountDto account); - QJsonArray prepareSubaccountJsonObject(GeneratedAccountDto account); + QJsonArray prepareSubaccountJsonObject(GeneratedAccountDto account); - QJsonObject prepareAccountSettingsJsonObject(const GeneratedAccountDto account, QString installationId); + QJsonObject prepareAccountSettingsJsonObject(const GeneratedAccountDto account, QString installationId); - AccountDto saveAccountAndLogin( - QString hashedPassword, QJsonObject account, QJsonArray subaccounts, QJsonObject settings, QJsonObject config); + AccountDto saveAccountAndLogin( + QString hashedPassword, QJsonObject account, QJsonArray subaccounts, QJsonObject settings, QJsonObject config); }; -} // namespace Accounts \ No newline at end of file +} // namespace Accounts diff --git a/src-cpp/app_service/include/accounts/service_interface.h b/src-cpp/app_service/include/accounts/service_interface.h index 467cef37c..b5b29708c 100644 --- a/src-cpp/app_service/include/accounts/service_interface.h +++ b/src-cpp/app_service/include/accounts/service_interface.h @@ -13,31 +13,31 @@ namespace Accounts class ServiceInterface : public AppService { public: - virtual QVector openedAccounts() = 0; + virtual QVector openedAccounts() = 0; - virtual QVector generatedAccounts() = 0; + virtual QVector generatedAccounts() = 0; - virtual bool setupAccount(QString accountId, QString password) = 0; + virtual bool setupAccount(QString accountId, QString password) = 0; - virtual AccountDto getLoggedInAccount() = 0; + virtual AccountDto getLoggedInAccount() = 0; - virtual GeneratedAccountDto getImportedAccount() = 0; + virtual GeneratedAccountDto getImportedAccount() = 0; - virtual bool isFirstTimeAccountLogin() = 0; + virtual bool isFirstTimeAccountLogin() = 0; - virtual QString validateMnemonic(QString mnemonic) = 0; + virtual QString validateMnemonic(QString mnemonic) = 0; - virtual bool importMnemonic(QString mnemonic) = 0; + virtual bool importMnemonic(QString mnemonic) = 0; - virtual QString login(AccountDto account, QString password) = 0; + virtual QString login(AccountDto account, QString password) = 0; - virtual void clear() = 0; + virtual void clear() = 0; - virtual QString generateAlias(QString publicKey) = 0; + virtual QString generateAlias(QString publicKey) = 0; - virtual QString generateIdenticon(QString publicKey) = 0; + virtual QString generateIdenticon(QString publicKey) = 0; - virtual bool verifyAccountPassword(QString account, QString password) = 0; + virtual bool verifyAccountPassword(QString account, QString password) = 0; }; -} // namespace Accounts \ No newline at end of file +} // namespace Accounts diff --git a/src-cpp/app_service/include/app_service.h b/src-cpp/app_service/include/app_service.h index 36897216c..38ca35ed4 100644 --- a/src-cpp/app_service/include/app_service.h +++ b/src-cpp/app_service/include/app_service.h @@ -3,5 +3,5 @@ class AppService { public: - virtual void init() = 0; + virtual void init() = 0; }; diff --git a/src-cpp/app_service/include/constants.h b/src-cpp/app_service/include/constants.h index 50f2fa9a9..ac46332dd 100644 --- a/src-cpp/app_service/include/constants.h +++ b/src-cpp/app_service/include/constants.h @@ -28,7 +28,6 @@ const QString Websocket = "websocket"; const QString DefaultNetworkName = "mainnet_rpc"; //const DEFAULT_NETWORKS_IDS* = @["mainnet_rpc", "testnet_rpc", "rinkeby_rpc", "goerli_rpc", "xdai_rpc", "poa_rpc" ] - const QString DataDir = "/data"; const QString Keystore = "/data/keystore"; @@ -36,5 +35,4 @@ QString applicationPath(QString path = ""); QString tmpPath(QString path = ""); QString cachePath(QString path = ""); - } // namespace Constants diff --git a/src-cpp/app_service/include/signing-phrases.h b/src-cpp/app_service/include/signing-phrases.h index fb6194b41..c3cdfe437 100644 --- a/src-cpp/app_service/include/signing-phrases.h +++ b/src-cpp/app_service/include/signing-phrases.h @@ -2,38 +2,48 @@ #include const std::array phrases{ - "area", "army", "atom", "aunt", "babe", "baby", "back", "bail", "bait", "bake", "ball", "band", "bank", "barn", "base", "bass", "bath", "bead", - "beak", "beam", "bean", "bear", "beat", "beef", "beer", "beet", "bell", "belt", "bend", "bike", "bill", "bird", "bite", "blow", "blue", "boar", - "boat", "body", "bolt", "bomb", "bone", "book", "boot", "bore", "boss", "bowl", "brow", "bulb", "bull", "burn", "bush", "bust", "cafe", "cake", - "calf", "call", "calm", "camp", "cane", "cape", "card", "care", "carp", "cart", "case", "cash", "cast", "cave", "cell", "cent", "chap", "chef", - "chin", "chip", "chop", "chub", "chug", "city", "clam", "clef", "clip", "club", "clue", "coal", "coat", "code", "coil", "coin", "coke", "cold", - "colt", "comb", "cone", "cook", "cope", "copy", "cord", "cork", "corn", "cost", "crab", "craw", "crew", "crib", "crop", "crow", "curl", "cyst", - "dame", "dare", "dark", "dart", "dash", "data", "date", "dead", "deal", "dear", "debt", "deck", "deep", "deer", "desk", "dhow", "diet", "dill", - "dime", "dirt", "dish", "disk", "dock", "doll", "door", "dory", "drag", "draw", "drop", "drug", "drum", "duck", "dump", "dust", "duty", "ease", - "east", "eave", "eddy", "edge", "envy", "epee", "exam", "exit", "face", "fact", "fail", "fall", "fame", "fang", "farm", "fawn", "fear", "feed", - "feel", "feet", "file", "fill", "film", "find", "fine", "fire", "fish", "flag", "flat", "flax", "flow", "foam", "fold", "font", "food", "foot", - "fork", "form", "fort", "fowl", "frog", "fuel", "full", "gain", "gale", "galn", "game", "garb", "gate", "gear", "gene", "gift", "girl", "give", - "glad", "glen", "glue", "glut", "goal", "goat", "gold", "golf", "gong", "good", "gown", "grab", "gram", "gray", "grey", "grip", "grit", "gyro", - "hail", "hair", "half", "hall", "hand", "hang", "harm", "harp", "hate", "hawk", "head", "heat", "heel", "hell", "helo", "help", "hemp", "herb", - "hide", "high", "hill", "hire", "hive", "hold", "hole", "home", "hood", "hoof", "hook", "hope", "hops", "horn", "hose", "host", "hour", "hunt", - "hurt", "icon", "idea", "inch", "iris", "iron", "item", "jail", "jeep", "jeff", "joey", "join", "joke", "judo", "jump", "junk", "jury", "jute", - "kale", "keep", "kick", "kill", "kilt", "kind", "king", "kiss", "kite", "knee", "knot", "lace", "lack", "lady", "lake", "lamb", "lamp", "land", - "lark", "lava", "lawn", "lead", "leaf", "leek", "lier", "life", "lift", "lily", "limo", "line", "link", "lion", "lisa", "list", "load", "loaf", - "loan", "lock", "loft", "long", "look", "loss", "lout", "love", "luck", "lung", "lute", "lynx", "lyre", "maid", "mail", "main", "make", "male", - "mall", "manx", "many", "mare", "mark", "mask", "mass", "mate", "math", "meal", "meat", "meet", "menu", "mess", "mice", "midi", "mile", "milk", - "mime", "mind", "mine", "mini", "mint", "miss", "mist", "moat", "mode", "mole", "mood", "moon", "most", "moth", "move", "mule", "mutt", "nail", - "name", "neat", "neck", "need", "neon", "nest", "news", "node", "nose", "note", "oboe", "okra", "open", "oval", "oven", "oxen", "pace", "pack", - "page", "pail", "pain", "pair", "palm", "pard", "park", "part", "pass", "past", "path", "peak", "pear", "peen", "peer", "pelt", "perp", "pest", - "pick", "pier", "pike", "pile", "pimp", "pine", "ping", "pink", "pint", "pipe", "piss", "pith", "plan", "play", "plot", "plow", "poem", "poet", - "pole", "polo", "pond", "pony", "poof", "pool", "port", "post", "prow", "pull", "puma", "pump", "pupa", "push", "quit", "race", "rack", "raft", - "rage", "rail", "rain", "rake", "rank", "rate", "read", "rear", "reef", "rent", "rest", "rice", "rich", "ride", "ring", "rise", "risk", "road", - "robe", "rock", "role", "roll", "roof", "room", "root", "rope", "rose", "ruin", "rule", "rush", "ruth", "sack", "safe", "sage", "sail", "sale", - "salt", "sand", "sari", "sash", "save", "scow", "seal", "seat", "seed", "self", "sell", "shed", "shin", "ship", "shoe", "shop", "shot", "show", - "sick", "side", "sign", "silk", "sill", "silo", "sing", "sink", "site", "size", "skin", "sled", "slip", "smog", "snob", "snow", "soap", "sock", - "soda", "sofa", "soft", "soil", "song", "soot", "sort", "soup", "spot", "spur", "stag", "star", "stay", "stem", "step", "stew", "stop", "stud", - "suck", "suit", "swan", "swim", "tail", "tale", "talk", "tank", "tard", "task", "taxi", "team", "tear", "teen", "tell", "temp", "tent", "term", - "test", "text", "thaw", "tile", "till", "time", "tire", "toad", "toga", "togs", "tone", "tool", "toot", "tote", "tour", "town", "tram", "tray", - "tree", "trim", "trip", "tuba", "tube", "tuna", "tune", "turn", "tutu", "twig", "type", "unit", "user", "vane", "vase", "vast", "veal", "veil", - "vein", "vest", "vibe", "view", "vise", "wait", "wake", "walk", "wall", "wash", "wasp", "wave", "wear", "weed", "week", "well", "west", "whip", - "wife", "will", "wind", "wine", "wing", "wire", "wish", "wolf", "wood", "wool", "word", "work", "worm", "wrap", "wren", "yard", "yarn", "yawl", - "year", "yoga", "yoke", "yurt", "zinc", "zone"}; + "area", "army", "atom", "aunt", "babe", "baby", "back", "bail", "bait", "bake", "ball", "band", "bank", "barn", + "base", "bass", "bath", "bead", "beak", "beam", "bean", "bear", "beat", "beef", "beer", "beet", "bell", "belt", + "bend", "bike", "bill", "bird", "bite", "blow", "blue", "boar", "boat", "body", "bolt", "bomb", "bone", "book", + "boot", "bore", "boss", "bowl", "brow", "bulb", "bull", "burn", "bush", "bust", "cafe", "cake", "calf", "call", + "calm", "camp", "cane", "cape", "card", "care", "carp", "cart", "case", "cash", "cast", "cave", "cell", "cent", + "chap", "chef", "chin", "chip", "chop", "chub", "chug", "city", "clam", "clef", "clip", "club", "clue", "coal", + "coat", "code", "coil", "coin", "coke", "cold", "colt", "comb", "cone", "cook", "cope", "copy", "cord", "cork", + "corn", "cost", "crab", "craw", "crew", "crib", "crop", "crow", "curl", "cyst", "dame", "dare", "dark", "dart", + "dash", "data", "date", "dead", "deal", "dear", "debt", "deck", "deep", "deer", "desk", "dhow", "diet", "dill", + "dime", "dirt", "dish", "disk", "dock", "doll", "door", "dory", "drag", "draw", "drop", "drug", "drum", "duck", + "dump", "dust", "duty", "ease", "east", "eave", "eddy", "edge", "envy", "epee", "exam", "exit", "face", "fact", + "fail", "fall", "fame", "fang", "farm", "fawn", "fear", "feed", "feel", "feet", "file", "fill", "film", "find", + "fine", "fire", "fish", "flag", "flat", "flax", "flow", "foam", "fold", "font", "food", "foot", "fork", "form", + "fort", "fowl", "frog", "fuel", "full", "gain", "gale", "galn", "game", "garb", "gate", "gear", "gene", "gift", + "girl", "give", "glad", "glen", "glue", "glut", "goal", "goat", "gold", "golf", "gong", "good", "gown", "grab", + "gram", "gray", "grey", "grip", "grit", "gyro", "hail", "hair", "half", "hall", "hand", "hang", "harm", "harp", + "hate", "hawk", "head", "heat", "heel", "hell", "helo", "help", "hemp", "herb", "hide", "high", "hill", "hire", + "hive", "hold", "hole", "home", "hood", "hoof", "hook", "hope", "hops", "horn", "hose", "host", "hour", "hunt", + "hurt", "icon", "idea", "inch", "iris", "iron", "item", "jail", "jeep", "jeff", "joey", "join", "joke", "judo", + "jump", "junk", "jury", "jute", "kale", "keep", "kick", "kill", "kilt", "kind", "king", "kiss", "kite", "knee", + "knot", "lace", "lack", "lady", "lake", "lamb", "lamp", "land", "lark", "lava", "lawn", "lead", "leaf", "leek", + "lier", "life", "lift", "lily", "limo", "line", "link", "lion", "lisa", "list", "load", "loaf", "loan", "lock", + "loft", "long", "look", "loss", "lout", "love", "luck", "lung", "lute", "lynx", "lyre", "maid", "mail", "main", + "make", "male", "mall", "manx", "many", "mare", "mark", "mask", "mass", "mate", "math", "meal", "meat", "meet", + "menu", "mess", "mice", "midi", "mile", "milk", "mime", "mind", "mine", "mini", "mint", "miss", "mist", "moat", + "mode", "mole", "mood", "moon", "most", "moth", "move", "mule", "mutt", "nail", "name", "neat", "neck", "need", + "neon", "nest", "news", "node", "nose", "note", "oboe", "okra", "open", "oval", "oven", "oxen", "pace", "pack", + "page", "pail", "pain", "pair", "palm", "pard", "park", "part", "pass", "past", "path", "peak", "pear", "peen", + "peer", "pelt", "perp", "pest", "pick", "pier", "pike", "pile", "pimp", "pine", "ping", "pink", "pint", "pipe", + "piss", "pith", "plan", "play", "plot", "plow", "poem", "poet", "pole", "polo", "pond", "pony", "poof", "pool", + "port", "post", "prow", "pull", "puma", "pump", "pupa", "push", "quit", "race", "rack", "raft", "rage", "rail", + "rain", "rake", "rank", "rate", "read", "rear", "reef", "rent", "rest", "rice", "rich", "ride", "ring", "rise", + "risk", "road", "robe", "rock", "role", "roll", "roof", "room", "root", "rope", "rose", "ruin", "rule", "rush", + "ruth", "sack", "safe", "sage", "sail", "sale", "salt", "sand", "sari", "sash", "save", "scow", "seal", "seat", + "seed", "self", "sell", "shed", "shin", "ship", "shoe", "shop", "shot", "show", "sick", "side", "sign", "silk", + "sill", "silo", "sing", "sink", "site", "size", "skin", "sled", "slip", "smog", "snob", "snow", "soap", "sock", + "soda", "sofa", "soft", "soil", "song", "soot", "sort", "soup", "spot", "spur", "stag", "star", "stay", "stem", + "step", "stew", "stop", "stud", "suck", "suit", "swan", "swim", "tail", "tale", "talk", "tank", "tard", "task", + "taxi", "team", "tear", "teen", "tell", "temp", "tent", "term", "test", "text", "thaw", "tile", "till", "time", + "tire", "toad", "toga", "togs", "tone", "tool", "toot", "tote", "tour", "town", "tram", "tray", "tree", "trim", + "trip", "tuba", "tube", "tuna", "tune", "turn", "tutu", "twig", "type", "unit", "user", "vane", "vase", "vast", + "veal", "veil", "vein", "vest", "vibe", "view", "vise", "wait", "wake", "walk", "wall", "wash", "wasp", "wave", + "wear", "weed", "week", "well", "west", "whip", "wife", "will", "wind", "wine", "wing", "wire", "wish", "wolf", + "wood", "wool", "word", "work", "worm", "wrap", "wren", "yard", "yarn", "yawl", "year", "yoga", "yoke", "yurt", + "zinc", "zone"}; diff --git a/src-cpp/app_service/include/wallet_accounts/service.h b/src-cpp/app_service/include/wallet_accounts/service.h index 1aea0b8a2..cad3404dc 100644 --- a/src-cpp/app_service/include/wallet_accounts/service.h +++ b/src-cpp/app_service/include/wallet_accounts/service.h @@ -1,11 +1,11 @@ #ifndef WALLETACCOUNTSSERVICE_H #define WALLETACCOUNTSSERVICE_H -#include #include +#include -#include "wallet_account.h" #include "service_interface.h" +#include "wallet_account.h" namespace Wallets { diff --git a/src-cpp/app_service/include/wallet_accounts/wallet_account.h b/src-cpp/app_service/include/wallet_accounts/wallet_account.h index cd391f799..a5335c39d 100644 --- a/src-cpp/app_service/include/wallet_accounts/wallet_account.h +++ b/src-cpp/app_service/include/wallet_accounts/wallet_account.h @@ -1,10 +1,10 @@ #ifndef WALLETACCOUNTDTO_H #define WALLETACCOUNTDTO_H +#include "wallet_token.h" #include #include #include -#include "wallet_token.h" namespace Wallets { @@ -27,6 +27,6 @@ WalletAccountDto toWalletAccountDto(const QJsonValue jsonObj); //WalletAccountDto getCurrencyBalance*(): float = // return self.tokens.map(t => t.currencyBalance).foldl(a + b, 0.0) -} // namespace Wallet +} // namespace Wallets #endif // WALLETACCOUNTDTO_H diff --git a/src-cpp/app_service/include/wallet_accounts/wallet_token.h b/src-cpp/app_service/include/wallet_accounts/wallet_token.h index 9918e8a52..adbd256ed 100644 --- a/src-cpp/app_service/include/wallet_accounts/wallet_token.h +++ b/src-cpp/app_service/include/wallet_accounts/wallet_token.h @@ -21,6 +21,6 @@ public: float currencyBalance; }; -} // namespace Wallet +} // namespace Wallets #endif // WALLETTOKENDTO_H diff --git a/src-cpp/app_service/service/accounts/dto/account.cpp b/src-cpp/app_service/service/accounts/dto/account.cpp index 3bc0a5470..2b1f34d5d 100644 --- a/src-cpp/app_service/service/accounts/dto/account.cpp +++ b/src-cpp/app_service/service/accounts/dto/account.cpp @@ -7,38 +7,38 @@ bool Accounts::AccountDto::isValid() { - return name.length() > 0 && keyUid.length() > 0; + return name.length() > 0 && keyUid.length() > 0; } Accounts::Image Accounts::toImage(const QJsonValue jsonObj) { - auto result = Accounts::Image(); + auto result = Accounts::Image(); - result.keyUid = jsonObj["keyUid"].toString(); - result.imgType = jsonObj["type"].toString(); - result.uri = jsonObj["uri"].toString(); - result.width = jsonObj["width"].toInt(); - result.height = jsonObj["height"].toInt(); - result.fileSize = jsonObj["fileSize"].toInt(); - result.resizeTarget = jsonObj["resizeTarget"].toInt(); + result.keyUid = jsonObj["keyUid"].toString(); + result.imgType = jsonObj["type"].toString(); + result.uri = jsonObj["uri"].toString(); + result.width = jsonObj["width"].toInt(); + result.height = jsonObj["height"].toInt(); + result.fileSize = jsonObj["fileSize"].toInt(); + result.resizeTarget = jsonObj["resizeTarget"].toInt(); - return result; + return result; } Accounts::AccountDto Accounts::toAccountDto(const QJsonValue jsonObj) { - auto result = Accounts::AccountDto(); + auto result = Accounts::AccountDto(); - result.name = jsonObj["name"].toString(); - result.timestamp = jsonObj["timestamp"].toInt(); - result.identicon = jsonObj["identicon"].toString(); - result.keycardPairing = jsonObj["keycard-pairing"].toString(); - result.keyUid = jsonObj["key-uid"].toString(); + result.name = jsonObj["name"].toString(); + result.timestamp = jsonObj["timestamp"].toInt(); + result.identicon = jsonObj["identicon"].toString(); + result.keycardPairing = jsonObj["keycard-pairing"].toString(); + result.keyUid = jsonObj["key-uid"].toString(); - foreach(const QJsonValue& value, jsonObj["images"].toArray()) - { - result.images << Accounts::toImage(value); - } + foreach(const QJsonValue& value, jsonObj["images"].toArray()) + { + result.images << Accounts::toImage(value); + } - return result; + return result; } diff --git a/src-cpp/app_service/service/accounts/dto/generated_account.cpp b/src-cpp/app_service/service/accounts/dto/generated_account.cpp index ac31e37c1..93fb82207 100644 --- a/src-cpp/app_service/service/accounts/dto/generated_account.cpp +++ b/src-cpp/app_service/service/accounts/dto/generated_account.cpp @@ -8,62 +8,62 @@ bool Accounts::GeneratedAccountDto::isValid() { - return id.length() > 0 && publicKey.length() > 0 && address.length() > 0 && keyUid.length() > 0; + return id.length() > 0 && publicKey.length() > 0 && address.length() > 0 && keyUid.length() > 0; } Accounts::DerivedAccountDetails Accounts::toDerivedAccountDetails(const QJsonValue jsonObj, QString derivationPath) { - // Mapping this DTO is not strightforward since only keys are used for id. We - // handle it a bit different. - auto result = Accounts::DerivedAccountDetails(); + // Mapping this DTO is not strightforward since only keys are used for id. We + // handle it a bit different. + auto result = Accounts::DerivedAccountDetails(); - result.derivationPath = derivationPath; - result.publicKey = jsonObj["publicKey"].toString(); - result.address = jsonObj["address"].toString(); + result.derivationPath = derivationPath; + result.publicKey = jsonObj["publicKey"].toString(); + result.address = jsonObj["address"].toString(); - return result; + return result; } Accounts::DerivedAccounts Accounts::toDerivedAccounts(const QJsonObject jsonObj) { - auto result = Accounts::DerivedAccounts(); - foreach(const QString& derivationPath, jsonObj.keys()) - { - QJsonValue derivedObj = jsonObj.value(derivationPath); - if(derivationPath == Backend::Accounts::PATH_WHISPER) - { - result.whisper = Accounts::toDerivedAccountDetails(derivedObj, derivationPath); - } - else if(derivationPath == Backend::Accounts::PATH_WALLET_ROOT) - { - result.walletRoot = Accounts::toDerivedAccountDetails(derivedObj, derivationPath); - } - else if(derivationPath == Backend::Accounts::PATH_DEFAULT_WALLET) - { - result.defaultWallet = Accounts::toDerivedAccountDetails(derivedObj, derivationPath); - } - else if(derivationPath == Backend::Accounts::PATH_EIP_1581) - { - result.eip1581 = Accounts::toDerivedAccountDetails(derivedObj, derivationPath); - } - } + auto result = Accounts::DerivedAccounts(); + foreach(const QString& derivationPath, jsonObj.keys()) + { + QJsonValue derivedObj = jsonObj.value(derivationPath); + if(derivationPath == Backend::Accounts::PATH_WHISPER) + { + result.whisper = Accounts::toDerivedAccountDetails(derivedObj, derivationPath); + } + else if(derivationPath == Backend::Accounts::PATH_WALLET_ROOT) + { + result.walletRoot = Accounts::toDerivedAccountDetails(derivedObj, derivationPath); + } + else if(derivationPath == Backend::Accounts::PATH_DEFAULT_WALLET) + { + result.defaultWallet = Accounts::toDerivedAccountDetails(derivedObj, derivationPath); + } + else if(derivationPath == Backend::Accounts::PATH_EIP_1581) + { + result.eip1581 = Accounts::toDerivedAccountDetails(derivedObj, derivationPath); + } + } - return result; + return result; } Accounts::GeneratedAccountDto Accounts::toGeneratedAccountDto(const QJsonValue jsonObj) { - auto result = GeneratedAccountDto(); + auto result = GeneratedAccountDto(); - result.id = jsonObj["id"].toString(); - result.address = jsonObj["address"].toString(); - result.keyUid = jsonObj["keyUid"].toString(); - result.mnemonic = jsonObj["mnemonic"].toString(); - result.publicKey = jsonObj["publicKey"].toString(); - if(!jsonObj["derived"].isUndefined()) - { - result.derivedAccounts = Accounts::toDerivedAccounts(jsonObj["derived"].toObject()); - } + result.id = jsonObj["id"].toString(); + result.address = jsonObj["address"].toString(); + result.keyUid = jsonObj["keyUid"].toString(); + result.mnemonic = jsonObj["mnemonic"].toString(); + result.publicKey = jsonObj["publicKey"].toString(); + if(!jsonObj["derived"].isUndefined()) + { + result.derivedAccounts = Accounts::toDerivedAccounts(jsonObj["derived"].toObject()); + } - return result; -} \ No newline at end of file + return result; +} diff --git a/src-cpp/app_service/service/accounts/service.cpp b/src-cpp/app_service/service/accounts/service.cpp index 858ef3c14..42d5f6d5e 100644 --- a/src-cpp/app_service/service/accounts/service.cpp +++ b/src-cpp/app_service/service/accounts/service.cpp @@ -18,380 +18,380 @@ namespace Accounts { Service::Service() - : m_isFirstTimeAccountLogin(false) + : m_isFirstTimeAccountLogin(false) { } const QVector PATHS{Backend::Accounts::PATH_WALLET_ROOT, - Backend::Accounts::PATH_EIP_1581, - Backend::Accounts::PATH_WHISPER, - Backend::Accounts::PATH_DEFAULT_WALLET}; + Backend::Accounts::PATH_EIP_1581, + Backend::Accounts::PATH_WHISPER, + Backend::Accounts::PATH_DEFAULT_WALLET}; void Service::init() { - auto response = Backend::Accounts::generateAddresses(Accounts::PATHS); - foreach(QJsonValue generatedAddressJson, response.m_result) - { - auto gAcc = toGeneratedAccountDto(generatedAddressJson); - gAcc.alias = generateAlias(gAcc.derivedAccounts.whisper.publicKey); - gAcc.identicon = generateIdenticon(gAcc.derivedAccounts.whisper.publicKey); - m_generatedAccounts << gAcc; - } + auto response = Backend::Accounts::generateAddresses(Accounts::PATHS); + foreach(QJsonValue generatedAddressJson, response.m_result) + { + auto gAcc = toGeneratedAccountDto(generatedAddressJson); + gAcc.alias = generateAlias(gAcc.derivedAccounts.whisper.publicKey); + gAcc.identicon = generateIdenticon(gAcc.derivedAccounts.whisper.publicKey); + m_generatedAccounts << gAcc; + } } QVector Service::openedAccounts() { - // TODO: if there's an exception, should we return an empty result? or should we look into using - // std::expected or std::optional or boost outcome https://www.boost.org/doc/libs/1_75_0/libs/outcome/doc/html/index.html - try - { - auto response = Backend::Accounts::openAccounts(Constants::applicationPath(Constants::DataDir)); - QJsonArray multiAccounts = response.m_result; - QVector result; - foreach(const QJsonValue& value, multiAccounts) - { - result << toAccountDto(value); - } - return result; - } - catch(Backend::RpcException& e) - { - qWarning() << "error: methodName=openedAccounts, errDescription=" << e.what(); - return QVector(); - } + // TODO: if there's an exception, should we return an empty result? or should we look into using + // std::expected or std::optional or boost outcome https://www.boost.org/doc/libs/1_75_0/libs/outcome/doc/html/index.html + try + { + auto response = Backend::Accounts::openAccounts(Constants::applicationPath(Constants::DataDir)); + QJsonArray multiAccounts = response.m_result; + QVector result; + foreach(const QJsonValue& value, multiAccounts) + { + result << toAccountDto(value); + } + return result; + } + catch(Backend::RpcException& e) + { + qWarning() << "error: methodName=openedAccounts, errDescription=" << e.what(); + return QVector(); + } } QVector Service::generatedAccounts() { - if(m_generatedAccounts.length() == 0) - { - qWarning("There was some issue initiating account service"); - return QVector(); - } + if(m_generatedAccounts.length() == 0) + { + qWarning("There was some issue initiating account service"); + return QVector(); + } - return m_generatedAccounts; + return m_generatedAccounts; } bool Service::setupAccount(QString accountId, QString password) { - // TODO: would it make sense to use std::expected or std::optional or boost outcome https://www.boost.org/doc/libs/1_75_0/libs/outcome/doc/html/index.html - try - { - QString installationId(QUuid::createUuid().toString(QUuid::WithoutBraces)); - QJsonObject accountData(Service::getAccountDataForAccountId(accountId)); - QJsonArray subAccountData(Service::getSubaccountDataForAccountId(accountId)); - QJsonObject settings(Service::getAccountSettings(accountId, installationId)); - QJsonObject nodeConfig(Service::getDefaultNodeConfig(installationId)); + // TODO: would it make sense to use std::expected or std::optional or boost outcome https://www.boost.org/doc/libs/1_75_0/libs/outcome/doc/html/index.html + try + { + QString installationId(QUuid::createUuid().toString(QUuid::WithoutBraces)); + QJsonObject accountData(Service::getAccountDataForAccountId(accountId)); + QJsonArray subAccountData(Service::getSubaccountDataForAccountId(accountId)); + QJsonObject settings(Service::getAccountSettings(accountId, installationId)); + QJsonObject nodeConfig(Service::getDefaultNodeConfig(installationId)); - QString hashedPassword(Backend::Utils::hashString(password)); + QString hashedPassword(Backend::Utils::hashString(password)); - Service::storeDerivedAccounts(accountId, hashedPassword, PATHS); + Service::storeDerivedAccounts(accountId, hashedPassword, PATHS); - m_loggedInAccount = - Service::saveAccountAndLogin(hashedPassword, accountData, subAccountData, settings, nodeConfig); + m_loggedInAccount = + Service::saveAccountAndLogin(hashedPassword, accountData, subAccountData, settings, nodeConfig); - return Service::getLoggedInAccount().isValid(); - } - catch(exception& e) - { - qWarning() << "error: methodName=setupAccount, errDescription=" << e.what(); - return false; - } + return Service::getLoggedInAccount().isValid(); + } + catch(exception& e) + { + qWarning() << "error: methodName=setupAccount, errDescription=" << e.what(); + return false; + } } AccountDto Service::getLoggedInAccount() { - return m_loggedInAccount; + return m_loggedInAccount; } GeneratedAccountDto Service::getImportedAccount() { - return m_importedAccount; + return m_importedAccount; } bool Service::isFirstTimeAccountLogin() { - return m_isFirstTimeAccountLogin; + return m_isFirstTimeAccountLogin; } QString Service::validateMnemonic(QString mnemonic) { - // TODO: - return ""; + // TODO: + return ""; } bool Service::importMnemonic(QString mnemonic) { - // TODO: - return false; + // TODO: + return false; } QString Service::login(AccountDto account, QString password) { - // TODO: would it make sense to use std::expected or std::optional or boost outcome https://www.boost.org/doc/libs/1_75_0/libs/outcome/doc/html/index.html - try - { - QString hashedPassword(Backend::Utils::hashString(password)); + // TODO: would it make sense to use std::expected or std::optional or boost outcome https://www.boost.org/doc/libs/1_75_0/libs/outcome/doc/html/index.html + try + { + QString hashedPassword(Backend::Utils::hashString(password)); - QString thumbnailImage; - QString largeImage; + QString thumbnailImage; + QString largeImage; - foreach(const Accounts::Image& img, account.images) - { - if(img.imgType == "thumbnail") - { - thumbnailImage = img.uri; - } - else if(img.imgType == "large") - { - largeImage = img.uri; - } - } + foreach(const Accounts::Image& img, account.images) + { + if(img.imgType == "thumbnail") + { + thumbnailImage = img.uri; + } + else if(img.imgType == "large") + { + largeImage = img.uri; + } + } - auto response = Backend::Accounts::login( - account.name, account.keyUid, hashedPassword, account.identicon, thumbnailImage, largeImage); - // TODO: check response for errors + auto response = Backend::Accounts::login( + account.name, account.keyUid, hashedPassword, account.identicon, thumbnailImage, largeImage); + // TODO: check response for errors - qDebug() << "Account logged in"; + qDebug() << "Account logged in"; - m_loggedInAccount = account; + m_loggedInAccount = account; - return ""; - } - catch(exception& e) - { - qWarning() << "error: methodName=login, errDescription=" << e.what(); - return e.what(); - } + return ""; + } + catch(exception& e) + { + qWarning() << "error: methodName=login, errDescription=" << e.what(); + return e.what(); + } } void Service::clear() { - m_generatedAccounts.clear(); - m_loggedInAccount = Accounts::AccountDto(); - m_importedAccount = Accounts::GeneratedAccountDto(); - m_isFirstTimeAccountLogin = false; + m_generatedAccounts.clear(); + m_loggedInAccount = Accounts::AccountDto(); + m_importedAccount = Accounts::GeneratedAccountDto(); + m_isFirstTimeAccountLogin = false; } QString Service::generateAlias(QString publicKey) { - return Backend::Accounts::generateAlias(publicKey).m_result; + return Backend::Accounts::generateAlias(publicKey).m_result; } QString Service::generateIdenticon(QString publicKey) { - return Backend::Accounts::generateIdenticon(publicKey).m_result; + return Backend::Accounts::generateIdenticon(publicKey).m_result; } bool Service::verifyAccountPassword(QString account, QString password) { - // TODO: - return false; + // TODO: + return false; } DerivedAccounts Service::storeDerivedAccounts(QString accountId, QString hashedPassword, QVector paths) { - try - { - auto response = Backend::Accounts::storeDerivedAccounts(accountId, hashedPassword, paths); - return toDerivedAccounts(response.m_result); - } - catch(Backend::RpcException& e) - { - qWarning() << e.what(); - return DerivedAccounts(); // TODO: should it return empty? - } + try + { + auto response = Backend::Accounts::storeDerivedAccounts(accountId, hashedPassword, paths); + return toDerivedAccounts(response.m_result); + } + catch(Backend::RpcException& e) + { + qWarning() << e.what(); + return DerivedAccounts(); // TODO: should it return empty? + } } Accounts::AccountDto Service::saveAccountAndLogin( - QString hashedPassword, QJsonObject account, QJsonArray subaccounts, QJsonObject settings, QJsonObject config) + QString hashedPassword, QJsonObject account, QJsonArray subaccounts, QJsonObject settings, QJsonObject config) { - // TODO: would it make sense to use std::expected or std::optional or boost outcome https://www.boost.org/doc/libs/1_75_0/libs/outcome/doc/html/index.html - try - { - auto response = Backend::Accounts::saveAccountAndLogin(hashedPassword, account, subaccounts, settings, config); + // TODO: would it make sense to use std::expected or std::optional or boost outcome https://www.boost.org/doc/libs/1_75_0/libs/outcome/doc/html/index.html + try + { + auto response = Backend::Accounts::saveAccountAndLogin(hashedPassword, account, subaccounts, settings, config); - m_isFirstTimeAccountLogin = true; - return toAccountDto(account); - } - catch(exception& e) - { - qWarning() << "error: methodName=saveAccountAndLogin, errDescription=" << e.what(); - return Accounts::AccountDto(); - } + m_isFirstTimeAccountLogin = true; + return toAccountDto(account); + } + catch(exception& e) + { + qWarning() << "error: methodName=saveAccountAndLogin, errDescription=" << e.what(); + return Accounts::AccountDto(); + } } QJsonObject Service::prepareAccountJsonObject(const GeneratedAccountDto account) { - return QJsonObject{{"name", account.alias}, - {"address", account.address}, - {"photo-path", account.identicon}, - {"identicon", account.identicon}, - {"key-uid", account.keyUid}, - {"keycard-pairing", QJsonValue()}}; + return QJsonObject{{"name", account.alias}, + {"address", account.address}, + {"photo-path", account.identicon}, + {"identicon", account.identicon}, + {"key-uid", account.keyUid}, + {"keycard-pairing", QJsonValue()}}; } QJsonObject Service::getAccountDataForAccountId(QString accountId) { - foreach(const GeneratedAccountDto& acc, m_generatedAccounts) - { - if(acc.id == accountId) - { - return Service::prepareAccountJsonObject(acc); - } - } + foreach(const GeneratedAccountDto& acc, m_generatedAccounts) + { + if(acc.id == accountId) + { + return Service::prepareAccountJsonObject(acc); + } + } - if(m_importedAccount.isValid()) - { - if(m_importedAccount.id == accountId) - { - return Service::prepareAccountJsonObject(m_importedAccount); - } - } + if(m_importedAccount.isValid()) + { + if(m_importedAccount.id == accountId) + { + return Service::prepareAccountJsonObject(m_importedAccount); + } + } - // TODO: Should we use instead a std::optional? - throw std::runtime_error("account not found"); + // TODO: Should we use instead a std::optional? + throw std::runtime_error("account not found"); } QJsonArray Service::prepareSubaccountJsonObject(GeneratedAccountDto account) { - return QJsonArray{QJsonObject{{"public-key", account.derivedAccounts.defaultWallet.publicKey}, - {"address", account.derivedAccounts.defaultWallet.address}, - {"color", "#4360df"}, - {"wallet", true}, - {"path", Backend::Accounts::PATH_DEFAULT_WALLET}, - {"name", "Status account"}}, - QJsonObject{{"public-key", account.derivedAccounts.whisper.publicKey}, - {"address", account.derivedAccounts.whisper.address}, - {"path", Backend::Accounts::PATH_WHISPER}, - {"name", account.alias}, - {"identicon", account.identicon}, - {"chat", true}}}; + return QJsonArray{QJsonObject{{"public-key", account.derivedAccounts.defaultWallet.publicKey}, + {"address", account.derivedAccounts.defaultWallet.address}, + {"color", "#4360df"}, + {"wallet", true}, + {"path", Backend::Accounts::PATH_DEFAULT_WALLET}, + {"name", "Status account"}}, + QJsonObject{{"public-key", account.derivedAccounts.whisper.publicKey}, + {"address", account.derivedAccounts.whisper.address}, + {"path", Backend::Accounts::PATH_WHISPER}, + {"name", account.alias}, + {"identicon", account.identicon}, + {"chat", true}}}; } QJsonArray Service::getSubaccountDataForAccountId(QString accountId) { - foreach(const GeneratedAccountDto& acc, m_generatedAccounts) - { - if(acc.id == accountId) - { - return prepareSubaccountJsonObject(acc); - } - } - if(m_importedAccount.isValid()) - { - if(m_importedAccount.id == accountId) - { - return prepareSubaccountJsonObject(m_importedAccount); - } - } + foreach(const GeneratedAccountDto& acc, m_generatedAccounts) + { + if(acc.id == accountId) + { + return prepareSubaccountJsonObject(acc); + } + } + if(m_importedAccount.isValid()) + { + if(m_importedAccount.id == accountId) + { + return prepareSubaccountJsonObject(m_importedAccount); + } + } - // TODO: Should we use instead a std::optional? - throw std::runtime_error("account not found"); + // TODO: Should we use instead a std::optional? + throw std::runtime_error("account not found"); } QString generateSigningPhrase(int count) { - QStringList words; - for(int i = 0; i < count; i++) - { - words.append(phrases[QRandomGenerator::global()->bounded(static_cast(phrases.size()))]); - } - return words.join(" "); + QStringList words; + for(int i = 0; i < count; i++) + { + words.append(phrases[QRandomGenerator::global()->bounded(static_cast(phrases.size()))]); + } + return words.join(" "); } QJsonObject Service::prepareAccountSettingsJsonObject(const GeneratedAccountDto account, QString installationId) { - QFile defaultNetworks(":/resources/default-networks.json"); - defaultNetworks.open(QIODevice::ReadOnly); + QFile defaultNetworks(":/resources/default-networks.json"); + defaultNetworks.open(QIODevice::ReadOnly); - QString defaultNetworksContent = defaultNetworks.readAll().replace("%INFURA_KEY%", INFURA_KEY); - QJsonArray defaultNetworksJson = QJsonDocument::fromJson(defaultNetworksContent.toUtf8()).array(); + QString defaultNetworksContent = defaultNetworks.readAll().replace("%INFURA_KEY%", INFURA_KEY); + QJsonArray defaultNetworksJson = QJsonDocument::fromJson(defaultNetworksContent.toUtf8()).array(); - return QJsonObject{{"key-uid", account.keyUid}, - {"mnemonic", account.mnemonic}, - {"public-key", account.derivedAccounts.whisper.publicKey}, - {"name", account.alias}, - {"address", account.address}, - {"eip1581-address", account.derivedAccounts.eip1581.address}, - {"dapps-address", account.derivedAccounts.defaultWallet.address}, - {"wallet-root-address", account.derivedAccounts.walletRoot.address}, - {"preview-privacy?", true}, - {"signing-phrase", generateSigningPhrase(3)}, - {"log-level", "INFO"}, - {"latest-derived-path", 0}, - {"networks/networks", defaultNetworksJson}, - {"currency", "usd"}, - {"identicon", account.identicon}, - {"waku-enabled", true}, - {"wallet/visible-tokens", {{Constants::DefaultNetworkName, QJsonArray{"SNT"}}}}, - {"appearance", 0}, - {"networks/current-network", Constants::DefaultNetworkName}, - {"installation-id", installationId}}; + return QJsonObject{{"key-uid", account.keyUid}, + {"mnemonic", account.mnemonic}, + {"public-key", account.derivedAccounts.whisper.publicKey}, + {"name", account.alias}, + {"address", account.address}, + {"eip1581-address", account.derivedAccounts.eip1581.address}, + {"dapps-address", account.derivedAccounts.defaultWallet.address}, + {"wallet-root-address", account.derivedAccounts.walletRoot.address}, + {"preview-privacy?", true}, + {"signing-phrase", generateSigningPhrase(3)}, + {"log-level", "INFO"}, + {"latest-derived-path", 0}, + {"networks/networks", defaultNetworksJson}, + {"currency", "usd"}, + {"identicon", account.identicon}, + {"waku-enabled", true}, + {"wallet/visible-tokens", {{Constants::DefaultNetworkName, QJsonArray{"SNT"}}}}, + {"appearance", 0}, + {"networks/current-network", Constants::DefaultNetworkName}, + {"installation-id", installationId}}; } QJsonObject Service::getAccountSettings(QString accountId, QString installationId) { - foreach(const GeneratedAccountDto& acc, m_generatedAccounts) + foreach(const GeneratedAccountDto& acc, m_generatedAccounts) - if(acc.id == accountId) - { - return Service::prepareAccountSettingsJsonObject(acc, installationId); - } + if(acc.id == accountId) + { + return Service::prepareAccountSettingsJsonObject(acc, installationId); + } - if(m_importedAccount.isValid()) - { - if(m_importedAccount.id == accountId) - { - return Service::prepareAccountSettingsJsonObject(m_importedAccount, installationId); - } - } + if(m_importedAccount.isValid()) + { + if(m_importedAccount.id == accountId) + { + return Service::prepareAccountSettingsJsonObject(m_importedAccount, installationId); + } + } - // TODO: Should we use instead a std::optional? - throw std::runtime_error("account not found"); + // TODO: Should we use instead a std::optional? + throw std::runtime_error("account not found"); } QJsonArray getNodes(const QJsonObject fleet, QString nodeType) { - auto nodes = fleet[nodeType].toObject(); - QJsonArray result; - for(auto it = nodes.begin(); it != nodes.end(); ++it) - result << *it; - return result; + auto nodes = fleet[nodeType].toObject(); + QJsonArray result; + for(auto it = nodes.begin(); it != nodes.end(); ++it) + result << *it; + return result; } QJsonObject Service::getDefaultNodeConfig(QString installationId) { - QFile nodeConfig(":/resources/node-config.json"); - nodeConfig.open(QIODevice::ReadOnly); + QFile nodeConfig(":/resources/node-config.json"); + nodeConfig.open(QIODevice::ReadOnly); - QString nodeConfigContent = nodeConfig.readAll(); + QString nodeConfigContent = nodeConfig.readAll(); - nodeConfigContent = nodeConfigContent.replace("%INSTALLATIONID%", installationId); - nodeConfigContent = nodeConfigContent.replace("%INFURA_KEY%", INFURA_KEY); + nodeConfigContent = nodeConfigContent.replace("%INSTALLATIONID%", installationId); + nodeConfigContent = nodeConfigContent.replace("%INFURA_KEY%", INFURA_KEY); - QJsonObject nodeConfigJson = QJsonDocument::fromJson(nodeConfigContent.toUtf8()).object(); + QJsonObject nodeConfigJson = QJsonDocument::fromJson(nodeConfigContent.toUtf8()).object(); - QFile fleets(":/resources/fleets.json"); - fleets.open(QIODevice::ReadOnly); - QJsonObject fleetsJson = QJsonDocument::fromJson(fleets.readAll()).object()["fleets"].toObject(); + QFile fleets(":/resources/fleets.json"); + fleets.open(QIODevice::ReadOnly); + QJsonObject fleetsJson = QJsonDocument::fromJson(fleets.readAll()).object()["fleets"].toObject(); - auto fleet = fleetsJson[Constants::Fleet::Prod].toObject(); + auto fleet = fleetsJson[Constants::Fleet::Prod].toObject(); - QJsonObject clusterConfig = nodeConfigJson["ClusterConfig"].toObject(); + QJsonObject clusterConfig = nodeConfigJson["ClusterConfig"].toObject(); - clusterConfig["Fleet"] = Constants::Fleet::Prod; - clusterConfig["BootNodes"] = getNodes(fleet, Constants::FleetNodes::Bootnodes); - clusterConfig["TrustedMailServers"] = getNodes(fleet, Constants::FleetNodes::Mailservers); - clusterConfig["StaticNodes"] = getNodes(fleet, Constants::FleetNodes::Whisper); - clusterConfig["RendezvousNodes"] = getNodes(fleet, Constants::FleetNodes::Rendezvous); - clusterConfig["RelayNodes"] = getNodes(fleet, Constants::FleetNodes::Waku); - clusterConfig["StoreNodes"] = getNodes(fleet, Constants::FleetNodes::Waku); - clusterConfig["FilterNodes"] = getNodes(fleet, Constants::FleetNodes::Waku); - clusterConfig["LightpushNodes"] = getNodes(fleet, Constants::FleetNodes::Waku); + clusterConfig["Fleet"] = Constants::Fleet::Prod; + clusterConfig["BootNodes"] = getNodes(fleet, Constants::FleetNodes::Bootnodes); + clusterConfig["TrustedMailServers"] = getNodes(fleet, Constants::FleetNodes::Mailservers); + clusterConfig["StaticNodes"] = getNodes(fleet, Constants::FleetNodes::Whisper); + clusterConfig["RendezvousNodes"] = getNodes(fleet, Constants::FleetNodes::Rendezvous); + clusterConfig["RelayNodes"] = getNodes(fleet, Constants::FleetNodes::Waku); + clusterConfig["StoreNodes"] = getNodes(fleet, Constants::FleetNodes::Waku); + clusterConfig["FilterNodes"] = getNodes(fleet, Constants::FleetNodes::Waku); + clusterConfig["LightpushNodes"] = getNodes(fleet, Constants::FleetNodes::Waku); - nodeConfigJson["ClusterConfig"] = clusterConfig; + nodeConfigJson["ClusterConfig"] = clusterConfig; - return nodeConfigJson; + return nodeConfigJson; } } // namespace Accounts diff --git a/src-cpp/app_service/service/wallet_accounts/service.cpp b/src-cpp/app_service/service/wallet_accounts/service.cpp index caa43f597..b6a8bfc78 100644 --- a/src-cpp/app_service/service/wallet_accounts/service.cpp +++ b/src-cpp/app_service/service/wallet_accounts/service.cpp @@ -26,8 +26,7 @@ void Service::fetchAccounts() foreach(const QJsonValue& value, response.m_result) { auto account = toWalletAccountDto(value); - if(!account.isChat) - m_walletAccounts[account.address] = account; + if(!account.isChat) m_walletAccounts[account.address] = account; } } catch(Backend::RpcException& e) diff --git a/src-cpp/backend/accounts.cpp b/src-cpp/backend/accounts.cpp index d021824a5..ec08d6c39 100644 --- a/src-cpp/backend/accounts.cpp +++ b/src-cpp/backend/accounts.cpp @@ -1,97 +1,97 @@ #include "backend/accounts.h" #include "backend/types.h" #include "backend/utils.h" +#include "libstatus.h" #include #include #include #include #include #include -#include "libstatus.h" const int NUMBER_OF_ADDRESSES_TO_GENERATE = 5; const int MNEMONIC_PHRASE_LENGTH = 12; Backend::RpcResponse Backend::Accounts::generateAddresses(QVector paths) { - QJsonObject payload{{"n", NUMBER_OF_ADDRESSES_TO_GENERATE}, - {"mnemonicPhraseLength", MNEMONIC_PHRASE_LENGTH}, - {"bip32Passphrase", ""}, - {"paths", Utils::toJsonArray(paths)} + QJsonObject payload{{"n", NUMBER_OF_ADDRESSES_TO_GENERATE}, + {"mnemonicPhraseLength", MNEMONIC_PHRASE_LENGTH}, + {"bip32Passphrase", ""}, + {"paths", Utils::toJsonArray(paths)} - }; - const char* result = MultiAccountGenerateAndDeriveAddresses(Utils::jsonToStr(payload).toUtf8().data()); - return Backend::RpcResponse(result, QJsonDocument::fromJson(result).array()); + }; + const char* result = MultiAccountGenerateAndDeriveAddresses(Utils::jsonToStr(payload).toUtf8().data()); + return Backend::RpcResponse(result, QJsonDocument::fromJson(result).array()); } Backend::RpcResponse Backend::Accounts::generateIdenticon(QString publicKey) { - if(!publicKey.isEmpty()) - { - auto identicon = QString(Identicon(publicKey.toUtf8().data())); - return Backend::RpcResponse(identicon, identicon); - } - else - { - throw Backend::RpcException("publicKey can't be empty1"); - } + if(!publicKey.isEmpty()) + { + auto identicon = QString(Identicon(publicKey.toUtf8().data())); + return Backend::RpcResponse(identicon, identicon); + } + else + { + throw Backend::RpcException("publicKey can't be empty1"); + } } Backend::RpcResponse Backend::Accounts::generateAlias(QString publicKey) { - if(!publicKey.isEmpty()) - { - auto alias = QString(GenerateAlias(publicKey.toUtf8().data())); - return Backend::RpcResponse(alias, alias); - } - else - { - throw Backend::RpcException("publicKey can't be empty2"); - } + if(!publicKey.isEmpty()) + { + auto alias = QString(GenerateAlias(publicKey.toUtf8().data())); + return Backend::RpcResponse(alias, alias); + } + else + { + throw Backend::RpcException("publicKey can't be empty2"); + } } Backend::RpcResponse Backend::Accounts::storeDerivedAccounts(QString id, QString hashedPassword, QVector paths) { - QJsonObject payload{{"accountID", id}, {"paths", Utils::toJsonArray(paths)}, {"password", hashedPassword}}; - auto result = MultiAccountStoreDerivedAccounts(Utils::jsonToStr(payload).toUtf8().data()); - auto obj = QJsonDocument::fromJson(result).object(); - Backend::Utils::throwOnError(obj); - return Backend::RpcResponse(result, obj); + QJsonObject payload{{"accountID", id}, {"paths", Utils::toJsonArray(paths)}, {"password", hashedPassword}}; + auto result = MultiAccountStoreDerivedAccounts(Utils::jsonToStr(payload).toUtf8().data()); + auto obj = QJsonDocument::fromJson(result).object(); + Backend::Utils::throwOnError(obj); + return Backend::RpcResponse(result, obj); } Backend::RpcResponse Backend::Accounts::saveAccountAndLogin( - QString hashedPassword, QJsonObject account, QJsonArray subaccounts, QJsonObject settings, QJsonObject nodeConfig) + QString hashedPassword, QJsonObject account, QJsonArray subaccounts, QJsonObject settings, QJsonObject nodeConfig) { - auto result = SaveAccountAndLogin(Utils::jsonToStr(account).toUtf8().data(), - hashedPassword.toUtf8().data(), - Utils::jsonToStr(settings).toUtf8().data(), - Utils::jsonToStr(nodeConfig).toUtf8().data(), - Utils::jsonToStr(subaccounts).toUtf8().data()); - auto obj = QJsonDocument::fromJson(result).object(); - Backend::Utils::throwOnError(obj); - return Backend::RpcResponse(result, obj); + auto result = SaveAccountAndLogin(Utils::jsonToStr(account).toUtf8().data(), + hashedPassword.toUtf8().data(), + Utils::jsonToStr(settings).toUtf8().data(), + Utils::jsonToStr(nodeConfig).toUtf8().data(), + Utils::jsonToStr(subaccounts).toUtf8().data()); + auto obj = QJsonDocument::fromJson(result).object(); + Backend::Utils::throwOnError(obj); + return Backend::RpcResponse(result, obj); } Backend::RpcResponse Backend::Accounts::openAccounts(QString path) { - const char* result = OpenAccounts(path.toUtf8().data()); - auto resp = Backend::RpcResponse(result, QJsonDocument::fromJson(result).array()); - return resp; + const char* result = OpenAccounts(path.toUtf8().data()); + auto resp = Backend::RpcResponse(result, QJsonDocument::fromJson(result).array()); + return resp; } Backend::RpcResponse Backend::Accounts::login( - QString name, QString keyUid, QString hashedPassword, QString identicon, QString thumbnail, QString large) + QString name, QString keyUid, QString hashedPassword, QString identicon, QString thumbnail, QString large) { - QJsonObject payload{{"name", name}, {"key-uid", keyUid}, {"identityImage", QJsonValue()}, {"identicon", identicon}}; + QJsonObject payload{{"name", name}, {"key-uid", keyUid}, {"identityImage", QJsonValue()}, {"identicon", identicon}}; - if(!thumbnail.isEmpty() && !large.isEmpty()) - { - payload["identityImage"] = QJsonObject{{"thumbnail", thumbnail}, {"large", large}}; - } + if(!thumbnail.isEmpty() && !large.isEmpty()) + { + payload["identityImage"] = QJsonObject{{"thumbnail", thumbnail}, {"large", large}}; + } - auto result = Login(Utils::jsonToStr(payload).toUtf8().data(), hashedPassword.toUtf8().data()); - auto obj = QJsonDocument::fromJson(result).object(); - Backend::Utils::throwOnError(obj); - return Backend::RpcResponse(result, obj); -} \ No newline at end of file + auto result = Login(Utils::jsonToStr(payload).toUtf8().data(), hashedPassword.toUtf8().data()); + auto obj = QJsonDocument::fromJson(result).object(); + Backend::Utils::throwOnError(obj); + return Backend::RpcResponse(result, obj); +} diff --git a/src-cpp/backend/include/backend/accounts.h b/src-cpp/backend/include/backend/accounts.h index 945931e06..8623cc1ae 100644 --- a/src-cpp/backend/include/backend/accounts.h +++ b/src-cpp/backend/include/backend/accounts.h @@ -28,7 +28,7 @@ RpcResponse generateAlias(QString publicKey); RpcResponse storeDerivedAccounts(QString accountId, QString hashedPassword, QVector paths); RpcResponse saveAccountAndLogin( - QString hashedPassword, QJsonObject account, QJsonArray subaccounts, QJsonObject settings, QJsonObject nodeConfig); + QString hashedPassword, QJsonObject account, QJsonArray subaccounts, QJsonObject settings, QJsonObject nodeConfig); RpcResponse openAccounts(QString path); @@ -36,4 +36,4 @@ RpcResponse login(QString name, QString keyUid, QString hashedPassword, QString identicon, QString thumbnail, QString large); } // namespace Accounts -} // namespace Backend \ No newline at end of file +} // namespace Backend diff --git a/src-cpp/backend/include/backend/types.h b/src-cpp/backend/include/backend/types.h index 27892cd77..c8072dc95 100644 --- a/src-cpp/backend/include/backend/types.h +++ b/src-cpp/backend/include/backend/types.h @@ -16,18 +16,19 @@ struct RpcException : public std::exception { private: std::string m_message; + public: - explicit RpcException(const std::string& message); - const char* what() const throw(); + explicit RpcException(const std::string& message); + const char* what() const throw(); }; class RpcError { public: - int m_code; - QString m_message; + int m_code; + QString m_message; - friend ostream& operator<<(ostream& os, Backend::RpcError& r); + friend ostream& operator<<(ostream& os, Backend::RpcError& r); }; template @@ -35,16 +36,16 @@ template class RpcResponse { public: - QString m_jsonrpc; - T m_result; - int m_id; - RpcError m_error; + QString m_jsonrpc; + T m_result; + int m_id; + RpcError m_error; public: - RpcResponse(QString jsonrpc, T result) - : m_jsonrpc(jsonrpc) - , m_result(result) - { } + RpcResponse(QString jsonrpc, T result) + : m_jsonrpc(jsonrpc) + , m_result(result) + { } }; } // namespace Backend diff --git a/src-cpp/backend/include/backend/utils.h b/src-cpp/backend/include/backend/utils.h index cbeddd7eb..09217187e 100644 --- a/src-cpp/backend/include/backend/utils.h +++ b/src-cpp/backend/include/backend/utils.h @@ -10,11 +10,11 @@ namespace Backend class Utils { public: - static QString hashString(QString str); - static QString jsonToStr(QJsonObject obj); - static QString jsonToStr(QJsonArray arr); - static QJsonArray toJsonArray(const QVector& value); - static QVector toStringVector(const QJsonArray& arr); - static void throwOnError(QJsonObject response); + static QString hashString(QString str); + static QString jsonToStr(QJsonObject obj); + static QString jsonToStr(QJsonArray arr); + static QJsonArray toJsonArray(const QVector& value); + static QVector toStringVector(const QJsonArray& arr); + static void throwOnError(QJsonObject response); }; } // namespace Backend diff --git a/src-cpp/backend/include/backend/wallet_accounts.h b/src-cpp/backend/include/backend/wallet_accounts.h index 435702725..4f3727523 100644 --- a/src-cpp/backend/include/backend/wallet_accounts.h +++ b/src-cpp/backend/include/backend/wallet_accounts.h @@ -8,6 +8,6 @@ namespace Backend::Wallet::Accounts { Backend::RpcResponse getAccounts(); -} // Backend::Wallet::Accounts +} // namespace Backend::Wallet::Accounts #endif // WALLETACCOUNT_BACKEND_H diff --git a/src-cpp/backend/types.cpp b/src-cpp/backend/types.cpp index 412cec0cb..6c826764c 100644 --- a/src-cpp/backend/types.cpp +++ b/src-cpp/backend/types.cpp @@ -5,15 +5,15 @@ using namespace std; ostream& operator<<(ostream& os, const Backend::RpcError& r) { - return (os << "RpcError(\n code: " << r.m_code << "\n message: " << r.m_message.toStdString() << "\n)" - << std::endl); + return (os << "RpcError(\n code: " << r.m_code << "\n message: " << r.m_message.toStdString() << "\n)" + << std::endl); } Backend::RpcException::RpcException(const std::string& message) - : m_message(message) + : m_message(message) { } const char* Backend::RpcException::what() const throw() { - return m_message.c_str(); -} \ No newline at end of file + return m_message.c_str(); +} diff --git a/src-cpp/backend/utils.cpp b/src-cpp/backend/utils.cpp index 5c696bbbf..3c7624e9e 100644 --- a/src-cpp/backend/utils.cpp +++ b/src-cpp/backend/utils.cpp @@ -1,51 +1,53 @@ #include "backend/utils.h" #include "backend/types.h" #include +#include #include #include #include #include #include -#include QJsonArray Backend::Utils::toJsonArray(const QVector& value) { - QJsonArray array; - for(auto& v : value) - array << v; - return array; + QJsonArray array; + for(auto& v : value) + array << v; + return array; } QString Backend::Utils::jsonToStr(QJsonObject obj) { - QJsonDocument doc(obj); - return QString::fromUtf8(doc.toJson()); + QJsonDocument doc(obj); + return QString::fromUtf8(doc.toJson()); } QString Backend::Utils::jsonToStr(QJsonArray arr) { - QJsonDocument doc(arr); - return QString::fromUtf8(doc.toJson()); + QJsonDocument doc(arr); + return QString::fromUtf8(doc.toJson()); } QVector Backend::Utils::toStringVector(const QJsonArray& arr) { - QVector result; - foreach(const QJsonValue& value, arr) - { - result << value.toString(); - } - return result; + QVector result; + foreach(const QJsonValue& value, arr) + { + result << value.toString(); + } + return result; } QString Backend::Utils::hashString(QString str) { - return "0x" + QString::fromUtf8(QCryptographicHash::hash(str.toUtf8(), QCryptographicHash::Keccak_256).toHex()); + return "0x" + QString::fromUtf8(QCryptographicHash::hash(str.toUtf8(), QCryptographicHash::Keccak_256).toHex()); } -void Backend::Utils::throwOnError(QJsonObject response) { - if(!response["error"].isUndefined() && !response["error"].toString().isEmpty()){ - qWarning() << "RpcException: " << response["error"].toString(); - throw Backend::RpcException(response["error"].toString().toStdString()); - } -} \ No newline at end of file +void Backend::Utils::throwOnError(QJsonObject response) +{ + if(!response["error"].isUndefined() && !response["error"].toString().isEmpty()) + { + qWarning() << "RpcException: " << response["error"].toString(); + throw Backend::RpcException(response["error"].toString().toStdString()); + } +} diff --git a/src-cpp/backend/wallet_accounts.cpp b/src-cpp/backend/wallet_accounts.cpp index 5acd467a9..06674efaa 100644 --- a/src-cpp/backend/wallet_accounts.cpp +++ b/src-cpp/backend/wallet_accounts.cpp @@ -2,9 +2,9 @@ #include #include -#include "backend/wallet_accounts.h" #include "backend/types.h" #include "backend/utils.h" +#include "backend/wallet_accounts.h" #include "libstatus.h" namespace Backend::Wallet::Accounts @@ -16,6 +16,4 @@ RpcResponse getAccounts() return RpcResponse(result, QJsonDocument::fromJson(result)["result"].toArray()); } - } // namespace Backend::Wallet::Accounts - diff --git a/src-cpp/constants.cpp b/src-cpp/constants.cpp index 65ef470c6..fe24b78cc 100644 --- a/src-cpp/constants.cpp +++ b/src-cpp/constants.cpp @@ -7,35 +7,34 @@ // TODO: merge with constants from backend/ - QString Constants::applicationPath(QString path) { - return QFileInfo(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + path).absoluteFilePath(); + return QFileInfo(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + path).absoluteFilePath(); } QString Constants::tmpPath(QString path) { - return QFileInfo(QStandardPaths::writableLocation(QStandardPaths::TempLocation) + path).absoluteFilePath(); + return QFileInfo(QStandardPaths::writableLocation(QStandardPaths::TempLocation) + path).absoluteFilePath(); } QString Constants::cachePath(QString path) { - return QFileInfo(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + path).absoluteFilePath(); + return QFileInfo(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + path).absoluteFilePath(); } bool Constants::ensureDirectories() { - if(Constants::applicationPath().isEmpty()) - { - QDir d{Constants::applicationPath()}; - if(!d.mkpath(d.absolutePath())) - { - QMessageBox msgBox; - msgBox.setIcon(QMessageBox::Warning); - msgBox.setText("Cannot determine storage location"); - msgBox.exec(); - return false; - } - } - return true; + if(Constants::applicationPath().isEmpty()) + { + QDir d{Constants::applicationPath()}; + if(!d.mkpath(d.absolutePath())) + { + QMessageBox msgBox; + msgBox.setIcon(QMessageBox::Warning); + msgBox.setText("Cannot determine storage location"); + msgBox.exec(); + return false; + } + } + return true; } diff --git a/src-cpp/dotherside/DOtherSide.cpp b/src-cpp/dotherside/DOtherSide.cpp index 214bcf60b..26958a633 100644 --- a/src-cpp/dotherside/DOtherSide.cpp +++ b/src-cpp/dotherside/DOtherSide.cpp @@ -5,8 +5,8 @@ void DOtherSide::registerMetaTypes() { - qRegisterMetaType>(); - qmlRegisterType("DotherSide", 0, 1, "StatusWindow"); - qmlRegisterType("DotherSide", 0, 1, "StatusSyntaxHighlighter"); - qmlRegisterType("DotherSide", 0, 1, "SpellChecker"); + qRegisterMetaType>(); + qmlRegisterType("DotherSide", 0, 1, "StatusWindow"); + qmlRegisterType("DotherSide", 0, 1, "StatusSyntaxHighlighter"); + qmlRegisterType("DotherSide", 0, 1, "SpellChecker"); } diff --git a/src-cpp/dotherside/DOtherSide.h b/src-cpp/dotherside/DOtherSide.h index 9301ec12f..21dfea46c 100644 --- a/src-cpp/dotherside/DOtherSide.h +++ b/src-cpp/dotherside/DOtherSide.h @@ -1,6 +1,7 @@ #pragma once -class DOtherSide { - public: - static void registerMetaTypes(); +class DOtherSide +{ +public: + static void registerMetaTypes(); }; diff --git a/src-cpp/dotherside/DOtherSideSingleInstance.h b/src-cpp/dotherside/DOtherSideSingleInstance.h index f958036da..adec6cef5 100644 --- a/src-cpp/dotherside/DOtherSideSingleInstance.h +++ b/src-cpp/dotherside/DOtherSideSingleInstance.h @@ -12,21 +12,20 @@ class SingleInstance : public QObject public: // uniqueName - the name of named pipe // eventStr - optional event to send if another instance is detected - explicit SingleInstance(const QString &uniqueName, const QString &eventStr, QObject *parent = nullptr); + explicit SingleInstance(const QString& uniqueName, const QString& eventStr, QObject* parent = nullptr); ~SingleInstance() override; bool isFirstInstance() const; signals: void secondInstanceDetected(); - void eventReceived(const QString &eventStr); + void eventReceived(const QString& eventStr); private slots: void handleNewConnection(); private: - QLocalServer *m_localServer; + QLocalServer* m_localServer; }; - #endif // SINGLEINSTANCE_H diff --git a/src-cpp/dotherside/SpellChecker.cpp b/src-cpp/dotherside/SpellChecker.cpp index 54f9fa1be..a501aac02 100644 --- a/src-cpp/dotherside/SpellChecker.cpp +++ b/src-cpp/dotherside/SpellChecker.cpp @@ -1,29 +1,27 @@ #include "SpellChecker.h" #ifdef Q_OS_MACOS - #include "hunspell/hunspell.hxx" +# include "hunspell/hunspell.hxx" #endif -#include -#include #include +#include #include +#include -#include -#include #include +#include +#include #include -SpellChecker::SpellChecker(QObject *parent) +SpellChecker::SpellChecker(QObject* parent) : QObject(parent) #ifdef Q_OS_MACOS , m_hunspell(nullptr) #endif , m_userDict("userDict_") -{ - -} +{ } SpellChecker::~SpellChecker() { @@ -32,7 +30,7 @@ SpellChecker::~SpellChecker() #endif } -bool SpellChecker::spell(const QString &word) +bool SpellChecker::spell(const QString& word) { #ifdef Q_OS_MACOS return m_hunspell->spell(m_codec->fromUnicode(word).toStdString()); @@ -53,63 +51,71 @@ bool SpellChecker::isInit() const void SpellChecker::initHunspell() { #ifdef Q_OS_MACOS - if (m_hunspell) { + if(m_hunspell) + { delete m_hunspell; } - QString dictFile = QGuiApplication::applicationDirPath() + "/dictionaries/" + m_lang + "/index.dic"; - QString affixFile = QGuiApplication::applicationDirPath() + "/dictionaries/" + m_lang + "/index.aff"; + QString dictFile = QGuiApplication::applicationDirPath() + "/dictionaries/" + m_lang + "/index.dic"; + QString affixFile = QGuiApplication::applicationDirPath() + "/dictionaries/" + m_lang + "/index.aff"; QByteArray dictFilePathBA = dictFile.toLocal8Bit(); QByteArray affixFilePathBA = affixFile.toLocal8Bit(); - m_hunspell = new Hunspell(affixFilePathBA.constData(), - dictFilePathBA.constData()); + m_hunspell = new Hunspell(affixFilePathBA.constData(), dictFilePathBA.constData()); // detect encoding analyzing the SET option in the affix file auto encoding = QStringLiteral("ISO8859-15"); QFile _affixFile(affixFile); - if (_affixFile.open(QIODevice::ReadOnly)) { - QTextStream stream(&_affixFile); - QRegularExpression enc_detector( - QStringLiteral("^\\s*SET\\s+([A-Z0-9\\-]+)\\s*"), - QRegularExpression::CaseInsensitiveOption); - QString sLine; - QRegularExpressionMatch match; - while (!stream.atEnd()) { - sLine = stream.readLine(); - if (sLine.isEmpty()) { continue; } - match = enc_detector.match(sLine); - if (match.hasMatch()) { - encoding = match.captured(1); - qDebug() << "Encoding set to " + encoding; - break; + if(_affixFile.open(QIODevice::ReadOnly)) + { + QTextStream stream(&_affixFile); + QRegularExpression enc_detector(QStringLiteral("^\\s*SET\\s+([A-Z0-9\\-]+)\\s*"), + QRegularExpression::CaseInsensitiveOption); + QString sLine; + QRegularExpressionMatch match; + while(!stream.atEnd()) + { + sLine = stream.readLine(); + if(sLine.isEmpty()) + { + continue; + } + match = enc_detector.match(sLine); + if(match.hasMatch()) + { + encoding = match.captured(1); + qDebug() << "Encoding set to " + encoding; + break; + } } - } - _affixFile.close(); + _affixFile.close(); } m_codec = QTextCodec::codecForName(encoding.toLatin1().constData()); QString userDict = m_userDict + m_lang + ".txt"; - if (!userDict.isEmpty()) { - QFile userDictonaryFile(userDict); - if (userDictonaryFile.open(QIODevice::ReadOnly)) { - QTextStream stream(&userDictonaryFile); - for (QString word = stream.readLine(); - !word.isEmpty(); - word = stream.readLine()) - ignoreWord(word); - userDictonaryFile.close(); - } else { - qWarning() << "User dictionary in " << userDict - << "could not be opened"; - } - } else { - qDebug() << "User dictionary not set."; + if(!userDict.isEmpty()) + { + QFile userDictonaryFile(userDict); + if(userDictonaryFile.open(QIODevice::ReadOnly)) + { + QTextStream stream(&userDictonaryFile); + for(QString word = stream.readLine(); !word.isEmpty(); word = stream.readLine()) + ignoreWord(word); + userDictonaryFile.close(); + } + else + { + qWarning() << "User dictionary in " << userDict << "could not be opened"; + } + } + else + { + qDebug() << "User dictionary not set."; } #endif } -QVariantList SpellChecker::suggest(const QString &word) +QVariantList SpellChecker::suggest(const QString& word) { int numSuggestions = 0; QVariantList suggestions; @@ -118,11 +124,12 @@ QVariantList SpellChecker::suggest(const QString &word) wordlist = m_hunspell->suggest(m_codec->fromUnicode(word).toStdString()); numSuggestions = static_cast(wordlist.size()); - if (numSuggestions > 0) { + if(numSuggestions > 0) + { suggestions.reserve(numSuggestions); - for (int i = 0; i < numSuggestions; i++) { - suggestions << m_codec->toUnicode( - QByteArray::fromStdString(wordlist[i])); + for(int i = 0; i < numSuggestions; i++) + { + suggestions << m_codec->toUnicode(QByteArray::fromStdString(wordlist[i])); } } #endif @@ -130,28 +137,33 @@ QVariantList SpellChecker::suggest(const QString &word) return suggestions; } -void SpellChecker::ignoreWord(const QString &word) +void SpellChecker::ignoreWord(const QString& word) { #ifdef Q_OS_MACOS m_hunspell->add(m_codec->fromUnicode(word).constData()); #endif } -void SpellChecker::addToUserWordlist(const QString &word) +void SpellChecker::addToUserWordlist(const QString& word) { #ifdef Q_OS_MACOS QString userDict = m_userDict + m_lang + ".txt"; - if (!userDict.isEmpty()) { + if(!userDict.isEmpty()) + { QFile userDictonaryFile(userDict); - if (userDictonaryFile.open(QIODevice::Append)) { + if(userDictonaryFile.open(QIODevice::Append)) + { QTextStream stream(&userDictonaryFile); stream << word << "\n"; userDictonaryFile.close(); - } else { - qWarning() << "User dictionary in " << userDict - << "could not be opened for appending a new word"; } - } else { + else + { + qWarning() << "User dictionary in " << userDict << "could not be opened for appending a new word"; + } + } + else + { qDebug() << "User dictionary not set."; } #endif @@ -164,7 +176,8 @@ const QString& SpellChecker::lang() const void SpellChecker::setLang(const QString& lang) { - if (m_lang != lang) { + if(m_lang != lang) + { m_lang = lang; initHunspell(); emit langChanged(); @@ -178,7 +191,8 @@ const QString& SpellChecker::userDict() const void SpellChecker::setUserDict(const QString& userDict) { - if (m_userDict != userDict) { + if(m_userDict != userDict) + { m_userDict = userDict; emit userDictChanged(); } diff --git a/src-cpp/dotherside/SpellChecker.h b/src-cpp/dotherside/SpellChecker.h index 3c425f5dd..1e751c290 100644 --- a/src-cpp/dotherside/SpellChecker.h +++ b/src-cpp/dotherside/SpellChecker.h @@ -1,9 +1,9 @@ #pragma once #include -#include #include #include +#include #ifdef Q_OS_MACOS class Hunspell; @@ -17,13 +17,13 @@ class SpellChecker : public QObject Q_PROPERTY(QString userDict READ userDict WRITE setUserDict NOTIFY userDictChanged) public: - explicit SpellChecker(QObject *parent = nullptr); + explicit SpellChecker(QObject* parent = nullptr); ~SpellChecker(); Q_INVOKABLE bool spell(const QString& word); - Q_INVOKABLE QVariantList suggest(const QString &word); - Q_INVOKABLE void ignoreWord(const QString &word); - Q_INVOKABLE void addToUserWordlist(const QString &word); + Q_INVOKABLE QVariantList suggest(const QString& word); + Q_INVOKABLE void ignoreWord(const QString& word); + Q_INVOKABLE void addToUserWordlist(const QString& word); Q_INVOKABLE bool isInit() const; const QString& lang() const; @@ -43,9 +43,9 @@ private: QString m_lang; QString m_userDict; - QQuickTextDocument *m_document; + QQuickTextDocument* m_document; #ifdef Q_OS_MACOS - Hunspell *m_hunspell; + Hunspell* m_hunspell; #endif - QTextCodec *m_codec; + QTextCodec* m_codec; }; diff --git a/src-cpp/dotherside/StatusSyntaxHighlighter.cpp b/src-cpp/dotherside/StatusSyntaxHighlighter.cpp index 8ceedd98c..3e68f197d 100644 --- a/src-cpp/dotherside/StatusSyntaxHighlighter.cpp +++ b/src-cpp/dotherside/StatusSyntaxHighlighter.cpp @@ -1,52 +1,54 @@ #include "StatusSyntaxHighlighter.h" #include -StatusSyntaxHighlighter::StatusSyntaxHighlighter(QTextDocument *parent) +StatusSyntaxHighlighter::StatusSyntaxHighlighter(QTextDocument* parent) : QSyntaxHighlighter(parent) { HighlightingRule rule; -//BOLD + //BOLD singlelineBoldFormat.setFontWeight(QFont::Bold); rule.pattern = QRegularExpression(QStringLiteral("\\*\\*(.*?)\\*\\*")); rule.format = singlelineBoldFormat; highlightingRules.append(rule); -//BOLD + //BOLD -//ITALIC + //ITALIC singleLineItalicFormat.setFontItalic(true); rule.pattern = QRegularExpression(QStringLiteral("\\*(.*?)\\*")); rule.format = singleLineItalicFormat; highlightingRules.append(rule); -//ITALIC + //ITALIC -//CODE + //CODE singlelineCodeBlockFormat.setFontFamily("Roboto Mono"); rule.pattern = QRegularExpression(QStringLiteral("\\`(.*?)\\`")); rule.format = singlelineCodeBlockFormat; highlightingRules.append(rule); -//CODE + //CODE -//STRIKETHROUGH + //STRIKETHROUGH singleLineStrikeThroughFormat.setFontStrikeOut(true); rule.pattern = QRegularExpression(QStringLiteral("\\~+(.*?)\\~+")); rule.format = singleLineStrikeThroughFormat; highlightingRules.append(rule); -//STRIKETHROUGH + //STRIKETHROUGH -//CODE BLOCK + //CODE BLOCK multiLineCodeBlockFormat.setFontFamily("Roboto Mono"); rule.pattern = QRegularExpression(QStringLiteral("\\`\\`\\`(.*?)\\`\\`\\`")); rule.format = multiLineCodeBlockFormat; highlightingRules.append(rule); -//CODE BLOCK + //CODE BLOCK } -void StatusSyntaxHighlighter::highlightBlock(const QString &text) +void StatusSyntaxHighlighter::highlightBlock(const QString& text) { - for (const HighlightingRule &rule : qAsConst(highlightingRules)) { + for(const HighlightingRule& rule : qAsConst(highlightingRules)) + { QRegularExpressionMatchIterator matchIterator = rule.pattern.globalMatch(text); - while (matchIterator.hasNext()) { + while(matchIterator.hasNext()) + { QRegularExpressionMatch match = matchIterator.next(); setFormat(match.capturedStart(), match.capturedLength(), rule.format); } @@ -54,14 +56,16 @@ void StatusSyntaxHighlighter::highlightBlock(const QString &text) setCurrentBlockState(0); } -QQuickTextDocument *StatusSyntaxHighlighterHelper::quickTextDocument() const { +QQuickTextDocument* StatusSyntaxHighlighterHelper::quickTextDocument() const +{ return m_quicktextdocument; } -void StatusSyntaxHighlighterHelper::setQuickTextDocument( - QQuickTextDocument *quickTextDocument) { +void StatusSyntaxHighlighterHelper::setQuickTextDocument(QQuickTextDocument* quickTextDocument) +{ m_quicktextdocument = quickTextDocument; - if (m_quicktextdocument) { + if(m_quicktextdocument) + { new StatusSyntaxHighlighter(m_quicktextdocument->textDocument()); } } diff --git a/src-cpp/dotherside/StatusSyntaxHighlighter.h b/src-cpp/dotherside/StatusSyntaxHighlighter.h index 681256ddb..5643a21fc 100644 --- a/src-cpp/dotherside/StatusSyntaxHighlighter.h +++ b/src-cpp/dotherside/StatusSyntaxHighlighter.h @@ -1,8 +1,8 @@ #pragma once +#include #include #include -#include class QQuickTextDocument; @@ -11,10 +11,10 @@ class StatusSyntaxHighlighter : public QSyntaxHighlighter Q_OBJECT public: - StatusSyntaxHighlighter(QTextDocument *parent = nullptr); + StatusSyntaxHighlighter(QTextDocument* parent = nullptr); protected: - void highlightBlock(const QString &text) override; + void highlightBlock(const QString& text) override; private: struct HighlightingRule @@ -31,18 +31,21 @@ private: QTextCharFormat multiLineCodeBlockFormat; }; -class StatusSyntaxHighlighterHelper : public QObject { - Q_OBJECT - Q_PROPERTY(QQuickTextDocument *quickTextDocument READ quickTextDocument WRITE - setQuickTextDocument NOTIFY quickTextDocumentChanged) +class StatusSyntaxHighlighterHelper : public QObject +{ + Q_OBJECT + Q_PROPERTY(QQuickTextDocument* quickTextDocument READ quickTextDocument WRITE setQuickTextDocument NOTIFY + quickTextDocumentChanged) public: - StatusSyntaxHighlighterHelper(QObject *parent = nullptr) - : QObject(parent), m_quicktextdocument(nullptr) {} - QQuickTextDocument *quickTextDocument() const; - void setQuickTextDocument(QQuickTextDocument *quickTextDocument); + StatusSyntaxHighlighterHelper(QObject* parent = nullptr) + : QObject(parent) + , m_quicktextdocument(nullptr) + { } + QQuickTextDocument* quickTextDocument() const; + void setQuickTextDocument(QQuickTextDocument* quickTextDocument); signals: - void quickTextDocumentChanged(); + void quickTextDocumentChanged(); private: - QQuickTextDocument *m_quicktextdocument; + QQuickTextDocument* m_quicktextdocument; }; diff --git a/src-cpp/dotherside/StatusWindow.cpp b/src-cpp/dotherside/StatusWindow.cpp index f13b861d6..1e1d594db 100644 --- a/src-cpp/dotherside/StatusWindow.cpp +++ b/src-cpp/dotherside/StatusWindow.cpp @@ -1,17 +1,20 @@ #include "StatusWindow.h" -StatusWindow::StatusWindow(QWindow *parent) -: QQuickWindow(parent), - m_isFullScreen(false) +StatusWindow::StatusWindow(QWindow* parent) + : QQuickWindow(parent) + , m_isFullScreen(false) { removeTitleBar(); connect(this, &QQuickWindow::windowStateChanged, [&](Qt::WindowState windowState) { - if (windowState == Qt::WindowNoState) { + if(windowState == Qt::WindowNoState) + { removeTitleBar(); m_isFullScreen = false; emit isFullScreenChanged(); - } else if (windowState == Qt::WindowFullScreen) { + } + else if(windowState == Qt::WindowFullScreen) + { m_isFullScreen = true; emit isFullScreenChanged(); showTitleBar(); @@ -21,14 +24,17 @@ StatusWindow::StatusWindow(QWindow *parent) void StatusWindow::toggleFullScreen() { - if (m_isFullScreen) { + if(m_isFullScreen) + { showNormal(); - } else { + } + else + { showFullScreen(); } } bool StatusWindow::isFullScreen() const { - return m_isFullScreen; + return m_isFullScreen; } diff --git a/src-cpp/dotherside/StatusWindow.h b/src-cpp/dotherside/StatusWindow.h index 9fce57fa8..d480825df 100644 --- a/src-cpp/dotherside/StatusWindow.h +++ b/src-cpp/dotherside/StatusWindow.h @@ -3,23 +3,25 @@ #include #include -class StatusWindow: public QQuickWindow +class StatusWindow : public QQuickWindow { Q_OBJECT Q_PROPERTY(bool isFullScreen READ isFullScreen NOTIFY isFullScreenChanged) public: - - explicit StatusWindow(QWindow *parent = nullptr); + explicit StatusWindow(QWindow* parent = nullptr); Q_INVOKABLE void toggleFullScreen(); bool isFullScreen() const; - Q_INVOKABLE void updatePosition() { - auto point = QPoint(screen()->geometry().center().x() - geometry().width() / 2, screen()->geometry().center().y() - geometry().height() / 2); - if (point != this->position()) { + Q_INVOKABLE void updatePosition() + { + auto point = QPoint(screen()->geometry().center().x() - geometry().width() / 2, + screen()->geometry().center().y() - geometry().height() / 2); + if(point != this->position()) + { this->setPosition(point); } } @@ -36,4 +38,3 @@ private: private: bool m_isFullScreen; }; - diff --git a/src-cpp/dotherside/StatusWindow_other.cpp b/src-cpp/dotherside/StatusWindow_other.cpp index 164b6f3db..cf82d74b6 100644 --- a/src-cpp/dotherside/StatusWindow_other.cpp +++ b/src-cpp/dotherside/StatusWindow_other.cpp @@ -1,11 +1,5 @@ #include "StatusWindow.h" -void StatusWindow::removeTitleBar() -{ +void StatusWindow::removeTitleBar() { } -} - -void StatusWindow::showTitleBar() -{ - -} +void StatusWindow::showTitleBar() { } diff --git a/src-cpp/logs.cpp b/src-cpp/logs.cpp index a5d1a621c..2804feab6 100644 --- a/src-cpp/logs.cpp +++ b/src-cpp/logs.cpp @@ -4,21 +4,23 @@ void logFormatter(QtMsgType type, const QMessageLogContext& context, const QString& msg) { - QByteArray localMsg = msg.toLocal8Bit(); - const char* file = context.file ? context.file : ""; - QByteArray function = context.function ? (QString(QStringLiteral("\033[0;33mfunction=\033[94m") + QString(context.function)).toLocal8Bit()) - : QString("").toLocal8Bit(); - QByteArray timestamp = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz").toLocal8Bit(); + QByteArray localMsg = msg.toLocal8Bit(); + const char* file = context.file ? context.file : ""; + QByteArray function = + context.function + ? (QString(QStringLiteral("\033[0;33mfunction=\033[94m") + QString(context.function)).toLocal8Bit()) + : QString("").toLocal8Bit(); + QByteArray timestamp = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz").toLocal8Bit(); - const char* log; + const char* log; - switch(type) - { - case QtDebugMsg: log = "\033[0;90mDBG \033[0m%s \033[1m%s \033[0;33mfile=\033[94m%s:%u %s\n"; break; - case QtInfoMsg: log = "\033[0;36mINF \033[0m%s \033[1m%s \033[0;33mfile=\033[94m%s:%u %s\n"; break; - case QtWarningMsg: log = "\033[0;33mWRN \033[0m%s \033[1m%s \033[0;33mfile=\033[94m%s:%u %s\n"; break; - case QtCriticalMsg: log = "\033[0;91mCRT \033[0m%s \033[1;91m%s \033[0;33mfile=\033[94m%s:%u %s\n"; break; - case QtFatalMsg: log = "\033[0;31m!!! \033[0m%s \033[1m%s \033[0;33mfile=\033[94m%s:%u %s\n"; break; - } - fprintf(stderr, log, timestamp.constData(), localMsg.constData(), file, context.line, function.constData()); -} \ No newline at end of file + switch(type) + { + case QtDebugMsg: log = "\033[0;90mDBG \033[0m%s \033[1m%s \033[0;33mfile=\033[94m%s:%u %s\n"; break; + case QtInfoMsg: log = "\033[0;36mINF \033[0m%s \033[1m%s \033[0;33mfile=\033[94m%s:%u %s\n"; break; + case QtWarningMsg: log = "\033[0;33mWRN \033[0m%s \033[1m%s \033[0;33mfile=\033[94m%s:%u %s\n"; break; + case QtCriticalMsg: log = "\033[0;91mCRT \033[0m%s \033[1;91m%s \033[0;33mfile=\033[94m%s:%u %s\n"; break; + case QtFatalMsg: log = "\033[0;31m!!! \033[0m%s \033[1m%s \033[0;33mfile=\033[94m%s:%u %s\n"; break; + } + fprintf(stderr, log, timestamp.constData(), localMsg.constData(), file, context.line, function.constData()); +} diff --git a/src-cpp/main.cpp b/src-cpp/main.cpp index 3f42ec22b..c23064448 100644 --- a/src-cpp/main.cpp +++ b/src-cpp/main.cpp @@ -16,63 +16,62 @@ int main(int argc, char* argv[]) { - qInstallMessageHandler(logFormatter); + qInstallMessageHandler(logFormatter); - QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts); + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts); #endif - QGuiApplication app(argc, argv); - app.setOrganizationName("Status"); - app.setOrganizationDomain("status.im"); - app.setApplicationName("Status Desktop"); + QGuiApplication app(argc, argv); + app.setOrganizationName("Status"); + app.setOrganizationDomain("status.im"); + app.setApplicationName("Status Desktop"); - if(!Constants::ensureDirectories()) return 1; + if(!Constants::ensureDirectories()) return 1; - // Init keystore - const char* initKeystoreResult = InitKeystore(Constants::applicationPath(Constants::Keystore).toUtf8().data()); - QJsonObject initKeystoreJson = QJsonDocument::fromJson(initKeystoreResult).object(); - if(initKeystoreJson["error"].toString() != "") - { - QMessageBox msgBox; - msgBox.setIcon(QMessageBox::Critical); - msgBox.setText("Could not open keystore: " + initKeystoreJson["error"].toString()); - msgBox.exec(); - return 1; - } + // Init keystore + const char* initKeystoreResult = InitKeystore(Constants::applicationPath(Constants::Keystore).toUtf8().data()); + QJsonObject initKeystoreJson = QJsonDocument::fromJson(initKeystoreResult).object(); + if(initKeystoreJson["error"].toString() != "") + { + QMessageBox msgBox; + msgBox.setIcon(QMessageBox::Critical); + msgBox.setText("Could not open keystore: " + initKeystoreJson["error"].toString()); + msgBox.exec(); + return 1; + } - QScopedPointer signalManager(Signals::Manager::instance()); + QScopedPointer signalManager(Signals::Manager::instance()); - // Registering metatypes - qRegisterMetaType("Signal"); - qRegisterMetaType("NodeSignal"); + // Registering metatypes + qRegisterMetaType("Signal"); + qRegisterMetaType("NodeSignal"); + qInfo("starting application controller..."); + AppController appController = AppController(); + appController.start(); - qInfo("starting application controller..."); - AppController appController = AppController(); - appController.start(); + QResource::registerResource("../resources.rcc"); - QResource::registerResource("../resources.rcc"); + DOtherSide::registerMetaTypes(); - DOtherSide::registerMetaTypes(); + Global::Singleton::instance()->engine()->addImportPath("qrc:/./StatusQ/src"); + Global::Singleton::instance()->engine()->addImportPath("qrc:/./imports"); - Global::Singleton::instance()->engine()->addImportPath("qrc:/./StatusQ/src"); - Global::Singleton::instance()->engine()->addImportPath("qrc:/./imports"); + const QUrl url(QStringLiteral("qrc:/main.qml")); + QObject::connect( + Global::Singleton::instance()->engine(), + &QQmlApplicationEngine::objectCreated, + &app, + [url](QObject* obj, const QUrl& objUrl) { + if(!obj && url == objUrl) QCoreApplication::exit(-1); + }, + Qt::QueuedConnection); - const QUrl url(QStringLiteral("qrc:/main.qml")); - QObject::connect( - Global::Singleton::instance()->engine(), - &QQmlApplicationEngine::objectCreated, - &app, - [url](QObject* obj, const QUrl& objUrl) { - if(!obj && url == objUrl) QCoreApplication::exit(-1); - }, - Qt::QueuedConnection); + Global::Singleton::instance()->engine()->load(url); - Global::Singleton::instance()->engine()->load(url); - - qInfo("starting application..."); - return app.exec(); + qInfo("starting application..."); + return app.exec(); }