From 9a4c8c6d7165552d0b9a33cb886bca63d1046b6c Mon Sep 17 00:00:00 2001 From: Justus Ranvier Date: Wed, 7 Feb 2024 12:41:33 -0600 Subject: [PATCH 1/2] upgrade otcommon and vcpkg --- CMakeLists.txt | 2 +- CMakePresets.json | 4 +++- tools/cmake/metier-configure-target.cmake | 2 +- tools/cmake/metier-generate-cmrc-target.cmake | 12 +----------- vcpkg-configuration.json | 2 +- vcpkg.json | 2 +- 6 files changed, 8 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 412fbd0..05a3089 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,7 +30,7 @@ project(metier) find_package( otcommon - 2 + 3 CONFIG REQUIRED ) diff --git a/CMakePresets.json b/CMakePresets.json index ee9f787..42dc49b 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -26,8 +26,10 @@ "hidden": true, "inherits": "vcpkg", "cacheVariables": { + "VCPKG_INSTALLED_DIR": + "$env{VCPKG_WINDOWS_MAX_PATH_HACK}/ot/i/${presetName}", "VCPKG_INSTALL_OPTIONS": - "--x-buildtrees-root=$env{VCPKG_WINDOWS_MAX_PATH_HACK}" + "--x-buildtrees-root=$env{VCPKG_WINDOWS_MAX_PATH_HACK}/ot/b/${presetName};--x-packages-root=$env{VCPKG_WINDOWS_MAX_PATH_HACK}/ot/p/${presetName}" } }, { diff --git a/tools/cmake/metier-configure-target.cmake b/tools/cmake/metier-configure-target.cmake index 2c41cc0..8500b36 100644 --- a/tools/cmake/metier-configure-target.cmake +++ b/tools/cmake/metier-configure-target.cmake @@ -7,7 +7,7 @@ include(otcommon-configure-target) include(otcommon-define-signed-overflow) function(metier_configure_cxx_target target_name) - otcommon_configure_cxx_target(${target_name}) + otcommon_configure_target_cxx(${target_name}) otcommon_define_signed_overflow(${target_name}) target_compile_definitions(metier-common PUBLIC "${QT_DEFINITIONS}") diff --git a/tools/cmake/metier-generate-cmrc-target.cmake b/tools/cmake/metier-generate-cmrc-target.cmake index dd7f35b..79c2c4f 100644 --- a/tools/cmake/metier-generate-cmrc-target.cmake +++ b/tools/cmake/metier-generate-cmrc-target.cmake @@ -31,17 +31,7 @@ function(metier_generate_cmrc_target) "license/metier" "LICENSE" ) - set_target_properties( - metier-cmrc - PROPERTIES - CXX_INCLUDE_WHAT_YOU_USE "" - CXX_CLANG_TIDY "" - CXX_STANDARD 20 - CXX_EXTENSIONS OFF - CXX_STANDARD_REQUIRED ON - POSITION_INDEPENDENT_CODE ON - UNITY_BUILD OFF - ) + otcommon_configure_target_external(metier-cmrc) target_link_libraries(metier-common PUBLIC metier-cmrc) target_sources(metier-common PUBLIC $) endfunction() diff --git a/vcpkg-configuration.json b/vcpkg-configuration.json index c925fb3..71e9a06 100644 --- a/vcpkg-configuration.json +++ b/vcpkg-configuration.json @@ -8,7 +8,7 @@ { "kind": "git", "repository": "https://github.com/Open-Transactions/vcpkg-registry", - "baseline": "8cf52482da31f31cf86588f09e1e10af834439bd", + "baseline": "c1136b72f6a429acea4ed598bf84881f83d18f7c", "packages": [ "opentxs", "otcommon" diff --git a/vcpkg.json b/vcpkg.json index 1246b9b..add3cc9 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -2,7 +2,7 @@ "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg/master/scripts/vcpkg.schema.json", "name": "metier", - "version": "23.2.4", + "version": "24.2.0", "features": { "qt": { "description": "Use Qt provided by vcpkg", From e1a8e9725fcc8365dd8df3b253057de36a9e5bd4 Mon Sep 17 00:00:00 2001 From: Justus Ranvier Date: Wed, 7 Feb 2024 13:00:40 -0600 Subject: [PATCH 2/2] make common classes more customizable --- src/metier/common/CMakeLists.txt | 1 + src/metier/common/api.cpp | 37 ++--- src/metier/common/api.hpp | 126 ++++++++++-------- src/metier/common/api.imp.cpp | 64 ++++++--- src/metier/common/api.imp.hpp | 122 +++++++++-------- src/metier/common/app.imp.cpp | 48 +++++++ src/metier/common/app.imp.hpp | 4 +- src/metier/skins/metier/CMakeLists.txt | 6 +- .../skins/metier/skin/app.imp.factory.cpp | 54 -------- ...dgets.cpp => app.imp.factory_advanced.cpp} | 5 +- ...pp => app.imp.factory_standard.no-qml.cpp} | 2 +- ...l.cpp => app.imp.factory_standard.qml.cpp} | 9 +- tools/cmake/metier-generate-target-gui.cmake | 5 +- 13 files changed, 276 insertions(+), 207 deletions(-) delete mode 100644 src/metier/skins/metier/skin/app.imp.factory.cpp rename src/metier/skins/metier/skin/{app.imp.widgets.cpp => app.imp.factory_advanced.cpp} (96%) rename src/metier/skins/metier/skin/{app.imp.no-qml.cpp => app.imp.factory_standard.no-qml.cpp} (91%) rename src/metier/skins/metier/skin/{app.imp.qml.cpp => app.imp.factory_standard.qml.cpp} (95%) diff --git a/src/metier/common/CMakeLists.txt b/src/metier/common/CMakeLists.txt index d7f796b..4fe3178 100644 --- a/src/metier/common/CMakeLists.txt +++ b/src/metier/common/CMakeLists.txt @@ -33,6 +33,7 @@ metier_add_source_file("${CMAKE_CURRENT_BINARY_DIR}/app.version.cpp") metier_add_source_file("api.cpp") metier_add_source_file("api.imp.cpp") metier_add_source_file("app.cpp") +metier_add_source_file("app.imp.cpp") metier_add_source_file("claim.cpp") metier_add_source_file("convertblockchain.cpp") metier_add_source_file("license.cpp") diff --git a/src/metier/common/api.cpp b/src/metier/common/api.cpp index 6b97181..aa1dd72 100644 --- a/src/metier/common/api.cpp +++ b/src/metier/common/api.cpp @@ -17,12 +17,12 @@ #include #include #include -#include #include #include #include #include #include +#include #include "metier/common/api.imp.hpp" #include "metier/common/convertblockchain.hpp" @@ -34,11 +34,12 @@ namespace qr = qrcodegen; namespace metier::common { -Api::Api(QGuiApplication& parent, App& app, int& argc, char** argv) +Api::Api(QGuiApplication& parent, std::shared_ptr imp) : QObject(&parent) - , imp_p_(std::make_unique(parent, app, *this, argc, argv)) + , imp_p_(std::move(imp)) , imp_(*imp_p_) { + imp_.init(this); using Seed = opentxs::ui::SeedTreeQt; auto* seed = imp_.seedManager(); connect(seed, &Seed::defaultSeedChanged, this, &Api::doNeedSeed); @@ -99,7 +100,7 @@ auto Api::checkChains(int chain) -> void { imp_.check_chains(chain); } auto Api::checkStartupConditions() -> void { - switch (imp_.state_.load()) { + switch (imp_.state()) { case Imp::State::init: case Imp::State::have_seed: { imp_.seedManager()->check(); @@ -118,7 +119,7 @@ auto Api::checkStartupConditions() -> void } } - imp_.state_.store(Imp::State::run); + imp_.state(Imp::State::run); Q_EMIT privateReadyForMainWindow(QPrivateSignal{}); } else if (1 > model->enabledCount()) { Q_EMIT privateNeedBlockchain(QPrivateSignal{}); @@ -127,7 +128,7 @@ auto Api::checkStartupConditions() -> void qFatal("Unable to initialize blockchains"); } - imp_.state_.store(Imp::State::run); + imp_.state(Imp::State::run); Q_EMIT privateReadyForMainWindow(QPrivateSignal{}); } } break; @@ -152,7 +153,7 @@ auto Api::createNym(QString alias) -> void { imp_.createNym(alias); } auto Api::doNeedNym() -> void { - switch (imp_.state_.load()) { + switch (imp_.state()) { case Imp::State::init: { doNeedSeed(); } break; @@ -160,7 +161,7 @@ auto Api::doNeedNym() -> void const auto [nym, count] = imp_.api_.Wallet().DefaultNym(); if (nym.empty()) { - if (false == imp_.wait_for_seed_backup_) { + if (false == imp_.waitForSeedBackup()) { Q_EMIT privateNeedProfileName(QPrivateSignal{}); } } else { @@ -168,7 +169,7 @@ auto Api::doNeedNym() -> void qFatal("Unable to initialize identity"); } - imp_.state_.store(Imp::State::have_nym); + imp_.state(Imp::State::have_nym); Q_EMIT checkStartupConditions(); } } break; @@ -181,7 +182,7 @@ auto Api::doNeedNym() -> void auto Api::doNeedSeed() -> void { - switch (imp_.state_.load()) { + switch (imp_.state()) { case Imp::State::init: { const auto [seed, count] = imp_.api_.Crypto().Seed().DefaultSeed(); @@ -192,7 +193,7 @@ auto Api::doNeedSeed() -> void qFatal("Unable to initialize wallet seed"); } - imp_.state_.store(Imp::State::have_seed); + imp_.state(Imp::State::have_seed); Q_EMIT checkStartupConditions(); } } break; @@ -206,12 +207,18 @@ auto Api::doNeedSeed() -> void auto Api::enabledBlockchains() -> BlockchainList { - return imp_.enabled_chains_.get(); + return imp_.enabledChainList(); } auto Api::enabledCurrencyCount() -> int { - return static_cast(imp_.enabled_chains_.count()); + return static_cast(imp_.enabledChainCount()); +} + +auto Api::Factory(QGuiApplication& parent, App& app, int& argc, char** argv) + -> std::shared_ptr +{ + return std::make_shared(parent, app, argc, argv); } auto Api::getQRcodeBase64(const QString input_string) -> QString @@ -265,7 +272,7 @@ auto Api::rescanBlockchain(int chain) -> void { imp_.rescanBlockchain(chain); } auto Api::seedBackupFinished() -> void { - imp_.wait_for_seed_backup_ = false; + imp_.waitForSeedBackup(false); Q_EMIT checkStartupConditions(); } @@ -296,7 +303,7 @@ auto Api::seedSizeModelQML(const int type) -> QObject* return seedSizeModel(type); } -auto Api::seedTypeModel() -> model::SeedType* { return imp_.seed_type_.get(); } +auto Api::seedTypeModel() -> model::SeedType* { return imp_.seedTypeModel(); } auto Api::seedTypeModelQML() -> QObject* { return seedTypeModel(); } diff --git a/src/metier/common/api.hpp b/src/metier/common/api.hpp index 36e8005..c0252f5 100644 --- a/src/metier/common/api.hpp +++ b/src/metier/common/api.hpp @@ -41,7 +41,7 @@ class App; namespace metier::common { -class Api final : public QObject +class Api : public QObject { Q_OBJECT Q_PROPERTY(int enabledCurrencyCount READ enabledCurrencyCount) @@ -62,74 +62,90 @@ class Api final : public QObject void privateReadyForMainWindow(QPrivateSignal); public Q_SLOTS: - void checkAccounts(); - void checkStartupConditions(); - void createNym(QString alias); - void importSeed(int type, int lang, QString words, QString password); - void quit(); - void rescanBlockchain(int chain); - void seedBackupFinished(); + virtual void checkAccounts(); + virtual void checkStartupConditions(); + virtual void createNym(QString alias); + virtual void importSeed( + int type, + int lang, + QString words, + QString password); + virtual void quit(); + virtual void rescanBlockchain(int chain); + virtual void seedBackupFinished(); private Q_SLOTS: - void chainIsDisabled(int chain); - void chainIsEnabled(int chain); - void checkChains(int chain); - void doNeedNym(); - void doNeedSeed(); + virtual void chainIsDisabled(int chain); + virtual void chainIsEnabled(int chain); + virtual void checkChains(int chain); + virtual void doNeedNym(); + virtual void doNeedSeed(); public: + struct Imp; + using BlockchainList = QVector; + static auto Factory( + QGuiApplication& parent, + App& app, + int& argc, + char** argv) -> std::shared_ptr; + static auto Cleanup() noexcept -> void; static auto Domain() noexcept -> QString; static auto Name() noexcept -> QString; static auto Title() noexcept -> QString; - auto blockchainChooserModel(const bool testnet) -> QAbstractItemModel*; - auto blockchainStatisticsModel() -> QAbstractItemModel*; - auto identityManager() noexcept -> opentxs::ui::IdentityManagerQt*; - auto seedLanguageModel(const int type) -> model::SeedLanguage*; - auto seedManager() noexcept -> opentxs::ui::SeedTreeQt*; - auto seedSizeModel(const int type) -> model::SeedSize*; - auto seedTypeModel() -> model::SeedType*; - auto seedWordValidator(const int type, const int lang) + virtual auto blockchainChooserModel(const bool testnet) + -> QAbstractItemModel*; + virtual auto blockchainStatisticsModel() -> QAbstractItemModel*; + virtual auto identityManager() noexcept -> opentxs::ui::IdentityManagerQt*; + virtual auto seedLanguageModel(const int type) -> model::SeedLanguage*; + virtual auto seedManager() noexcept -> opentxs::ui::SeedTreeQt*; + virtual auto seedSizeModel(const int type) -> model::SeedSize*; + virtual auto seedTypeModel() -> model::SeedType*; + virtual auto seedWordValidator(const int type, const int lang) -> const opentxs::ui::SeedValidator*; - - Q_INVOKABLE QObject* blockchainChooserModelQML(bool testnet); - Q_INVOKABLE QObject* blockchainStatisticsModelQML(); - Q_INVOKABLE QObject* identityManagerQML(); - Q_INVOKABLE QObject* seedLanguageModelQML(const int type); - Q_INVOKABLE QObject* seedManagerQML(); - Q_INVOKABLE QObject* seedSizeModelQML(const int type); - Q_INVOKABLE QObject* seedTypeModelQML(); - Q_INVOKABLE QObject* seedWordValidatorQML(const int type, const int lang); - - Q_INVOKABLE int accountIDtoBlockchainType(const QString& id); - Q_INVOKABLE QString addContact(QString label, QString id); - Q_INVOKABLE QString blockchainTypeToAccountID(int type); - Q_INVOKABLE QStringList + virtual auto enabledBlockchains() -> BlockchainList; + virtual auto validBlockchains() -> BlockchainList; + + virtual Q_INVOKABLE QObject* blockchainChooserModelQML(bool testnet); + virtual Q_INVOKABLE QObject* blockchainStatisticsModelQML(); + virtual Q_INVOKABLE QObject* identityManagerQML(); + virtual Q_INVOKABLE QObject* seedLanguageModelQML(const int type); + virtual Q_INVOKABLE QObject* seedManagerQML(); + virtual Q_INVOKABLE QObject* seedSizeModelQML(const int type); + virtual Q_INVOKABLE QObject* seedTypeModelQML(); + virtual Q_INVOKABLE QObject* seedWordValidatorQML( + const int type, + const int lang); + + virtual Q_INVOKABLE int accountIDtoBlockchainType(const QString& id); + virtual Q_INVOKABLE QString addContact(QString label, QString id); + virtual Q_INVOKABLE QString blockchainTypeToAccountID(int type); + virtual Q_INVOKABLE QStringList createNewSeed(const int type, const int lang, const int strength); - Q_INVOKABLE QStringList getRecoveryWords(); - Q_INVOKABLE int wordCount(const int type, const int strength); - Q_INVOKABLE int enabledCurrencyCount(); - BlockchainList enabledBlockchains(); - Q_INVOKABLE QString getQRcodeBase64(const QString input_string); - Q_INVOKABLE int longestBlockchainName(); - Q_INVOKABLE int longestSeedWord(); - Q_INVOKABLE void openSystemBrowserLink(QString url_link); - BlockchainList validBlockchains(); - Q_INVOKABLE QString versionString(int suffix = 0); - - explicit Api(QGuiApplication& parent, App& app, int& argc, char** argv); - - ~Api() final; - -private: - struct Imp; + virtual Q_INVOKABLE QStringList getRecoveryWords(); + virtual Q_INVOKABLE int wordCount(const int type, const int strength); + virtual Q_INVOKABLE int enabledCurrencyCount(); + virtual Q_INVOKABLE QString getQRcodeBase64(const QString input_string); + virtual Q_INVOKABLE int longestBlockchainName(); + virtual Q_INVOKABLE int longestSeedWord(); + virtual Q_INVOKABLE void openSystemBrowserLink(QString url_link); + virtual Q_INVOKABLE QString versionString(int suffix = 0); + + explicit Api(QGuiApplication& parent, std::shared_ptr imp); + Api() = delete; + Api(const Api&) = delete; + Api(Api&&) = delete; + auto operator=(const Api&) -> Api& = delete; + auto operator=(Api&&) -> Api& = delete; - std::unique_ptr imp_p_; - Imp& imp_; + ~Api() override; - Api() = delete; +protected: + std::shared_ptr imp_p_; + Imp& imp_; }; } // namespace metier::common diff --git a/src/metier/common/api.imp.cpp b/src/metier/common/api.imp.cpp index 206af67..b2322a3 100644 --- a/src/metier/common/api.imp.cpp +++ b/src/metier/common/api.imp.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -121,13 +120,8 @@ auto Api::Imp::transform(const InputType& data) noexcept -> OutputType namespace metier::common { -Api::Imp::Imp( - QGuiApplication& parent, - App& app, - Api& me, - int& argc, - char** argv) - : parent_(me) +Api::Imp::Imp(QGuiApplication& parent, App& app, int& argc, char** argv) + : parent_(nullptr) , qt_parent_(parent) , callback_(app) , caller_() @@ -211,11 +205,6 @@ Api::Imp::Imp( assert(nullptr != main); assert(nullptr != test); - using Model = ot::ui::BlockchainSelectionQt; - connect(full, &Model::enabledChanged, &parent_, &Api::checkChains); - connect(full, &Model::chainEnabled, &parent_, &Api::chainIsEnabled); - connect(full, &Model::chainDisabled, &parent_, &Api::chainIsDisabled); - return api_.Network().Blockchain().EnabledChains(); }()) , seed_type_(std::make_unique( @@ -260,7 +249,7 @@ auto Api::Imp::chain_is_enabled(int chain) noexcept -> void auto Api::Imp::check_chains(int count) const noexcept -> void { validateBlockchains(); - Q_EMIT parent_.chainsChanged(count); + Q_EMIT parent_->chainsChanged(count); } auto Api::Imp::createNym(QString alias) noexcept -> void @@ -342,6 +331,16 @@ auto Api::Imp::createNewSeed( return words.split(' ', Qt::SkipEmptyParts); } +auto Api::Imp::enabledChainCount() const noexcept -> std::size_t +{ + return enabled_chains_.count(); +} + +auto Api::Imp::enabledChainList() const noexcept -> BlockchainList +{ + return enabled_chains_.get(); +} + auto Api::Imp::getRecoveryWords() -> QStringList { ready().get(); @@ -418,6 +417,19 @@ auto Api::Imp::identityManager() const noexcept -> ot::ui::IdentityManagerQt* return model; } +auto Api::Imp::init(Api* me) -> void +{ + parent_ = me; + auto* full = api_.UI().BlockchainSelectionQt(ot::ui::Blockchains::All); + + assert(nullptr != full); + + using Model = ot::ui::BlockchainSelectionQt; + connect(full, &Model::enabledChanged, parent_, &Api::checkChains); + connect(full, &Model::chainEnabled, parent_, &Api::chainIsEnabled); + connect(full, &Model::chainDisabled, parent_, &Api::chainIsDisabled); +} + auto Api::Imp::make_accounts(const ot::blockchain::Type chain) const noexcept -> bool { @@ -483,7 +495,7 @@ auto Api::Imp::make_accounts(const ot::blockchain::Type chain) const noexcept return true; } -auto Api::Imp::needNym() const noexcept +auto Api::Imp::needNym() const noexcept -> bool { ready().get(); @@ -687,6 +699,11 @@ auto Api::Imp::seedSizeModel(const int type) -> model::SeedSize* } } +auto Api::Imp::seedTypeModel() const -> model::SeedType* +{ + return seed_type_.get(); +} + auto Api::Imp::seedWordValidator(const int type, const int lang) -> const opentxs::ui::SeedValidator* { @@ -699,6 +716,13 @@ auto Api::Imp::seedWordValidator(const int type, const int lang) return api_.UI().SeedValidator(style, language); } +auto Api::Imp::state(State value) noexcept -> void +{ + return state_.store(value); +} + +auto Api::Imp::state() const noexcept -> State { return state_.load(); } + auto Api::Imp::validateBlockchains() const noexcept -> bool { ready().get(); @@ -797,6 +821,16 @@ auto Api::Imp::validateSeed() const noexcept -> bool return false; } +auto Api::Imp::waitForSeedBackup() const noexcept -> bool +{ + return wait_for_seed_backup_; +} + +auto Api::Imp::waitForSeedBackup(bool value) noexcept -> void +{ + wait_for_seed_backup_.store(value); +} + auto Api::Imp::wordCount(const int type, const int strength) -> int { ready().get(); diff --git a/src/metier/common/api.imp.hpp b/src/metier/common/api.imp.hpp index d8c7e32..db17933 100644 --- a/src/metier/common/api.imp.hpp +++ b/src/metier/common/api.imp.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -69,12 +70,75 @@ namespace zmq = opentxs::network::zeromq; struct Api::Imp { private: - Api& parent_; + Api* parent_; QGuiApplication& qt_parent_; + PasswordCallback callback_; + opentxs::PasswordCaller caller_; public: enum class State { init, have_seed, have_nym, run }; + using SeedLanguageMap = + std::map>; + using SeedSizeMap = + std::map>; + + const opentxs::api::Context& ot_; + const opentxs::api::session::Client& api_; + const opentxs::crypto::SeedID seed_id_; + const int longest_seed_word_; + const SeedLanguageMap seed_language_; + const SeedSizeMap seed_size_; + + virtual auto check_chains(int count) const noexcept -> void; + virtual auto enableDefaultChain() const noexcept -> bool; + virtual auto enabledChainCount() const noexcept -> std::size_t; + virtual auto enabledChainList() const noexcept -> BlockchainList; + virtual auto identityManager() const noexcept -> ot::ui::IdentityManagerQt*; + virtual auto needNym() const noexcept -> bool; + virtual auto rescanBlockchain(int chain) -> void; + virtual auto seedManager() const noexcept -> ot::ui::SeedTreeQt*; + virtual auto seedTypeModel() const -> model::SeedType*; + virtual auto state(State value) noexcept -> void; + virtual auto validateBlockchains() const noexcept -> bool; + virtual auto validateNym() const noexcept -> bool; + virtual auto validateSeed() const noexcept -> bool; + virtual auto waitForSeedBackup() const noexcept -> bool; + + virtual auto blockchainTypeToAccountID(int chain) noexcept -> QString; + virtual auto chain_is_disabled(int chain) noexcept -> void; + virtual auto chain_is_enabled(int chain) noexcept -> void; + virtual auto createNym(QString alias) noexcept -> void; + virtual auto createNewSeed( + const int type, + const int lang, + const int strength) noexcept -> QStringList; + virtual auto getRecoveryWords() -> QStringList; + virtual auto importSeed( + int type, + int lang, + const QString& input, + const QString& password) -> void; + virtual auto init(Api* me) -> void; + virtual auto seedLanguageModel(const int type) -> model::SeedLanguage*; + virtual auto seedSizeModel(const int type) -> model::SeedSize*; + virtual auto seedWordValidator(const int type, const int lang) + -> const opentxs::ui::SeedValidator*; + virtual auto state() const noexcept -> State; + virtual auto waitForSeedBackup(bool value) noexcept -> void; + virtual auto wordCount(const int type, const int strength) -> int; + + Imp(QGuiApplication& parent, App& app, int& argc, char** argv); + Imp(const Imp&) = delete; + Imp(Imp&&) = delete; + auto operator=(const Imp&) -> Imp& = delete; + auto operator=(Imp&&) -> Imp& = delete; + + virtual ~Imp(); + +private: + using Lock = std::unique_lock; + struct EnabledChains { using Vector = opentxs::Set; using Lock = std::unique_lock; @@ -128,20 +192,6 @@ struct Api::Imp { Vector enabled_{}; }; - using SeedLanguageMap = - std::map>; - using SeedSizeMap = - std::map>; - using Lock = std::unique_lock; - - PasswordCallback callback_; - opentxs::PasswordCaller caller_; - const opentxs::api::Context& ot_; - const opentxs::api::session::Client& api_; - const opentxs::crypto::SeedID seed_id_; - const int longest_seed_word_; - const SeedLanguageMap seed_language_; - const SeedSizeMap seed_size_; mutable std::mutex lock_; mutable std::atomic_bool have_nym_; mutable std::atomic_bool wait_for_seed_backup_; @@ -155,46 +205,8 @@ struct Api::Imp { template static auto transform(const InputType& data) noexcept -> OutputType; - auto check_chains(int count) const noexcept -> void; - auto enableDefaultChain() const noexcept -> bool; - auto identityManager() const noexcept -> ot::ui::IdentityManagerQt*; - auto needNym() const noexcept; - auto rescanBlockchain(int chain) -> void; - auto seedManager() const noexcept -> ot::ui::SeedTreeQt*; - auto validateBlockchains() const noexcept -> bool; - auto validateNym() const noexcept -> bool; - auto validateSeed() const noexcept -> bool; - - auto blockchainTypeToAccountID(int chain) noexcept -> QString; - auto chain_is_disabled(int chain) noexcept -> void; - auto chain_is_enabled(int chain) noexcept -> void; - auto createNym(QString alias) noexcept -> void; - auto createNewSeed( - const int type, - const int lang, - const int strength) noexcept -> QStringList; - auto getRecoveryWords() -> QStringList; - auto importSeed( - int type, - int lang, - const QString& input, - const QString& password) -> void; - auto seedLanguageModel(const int type) -> model::SeedLanguage*; - auto seedSizeModel(const int type) -> model::SeedSize*; - auto seedWordValidator(const int type, const int lang) - -> const opentxs::ui::SeedValidator*; - auto wordCount(const int type, const int strength) -> int; - - Imp(QGuiApplication& parent, App& app, Api& me, int& argc, char** argv); - Imp(const Imp&) = delete; - Imp(Imp&&) = delete; - auto operator=(const Imp&) -> Imp& = delete; - auto operator=(Imp&&) -> Imp& = delete; - - ~Imp(); - -private: - auto make_accounts(const ot::blockchain::Type chain) const noexcept -> bool; + virtual auto make_accounts(const ot::blockchain::Type chain) const noexcept + -> bool; auto receive_message( void* socket, ot::network::zeromq::Message& message) noexcept -> bool; diff --git a/src/metier/common/app.imp.cpp b/src/metier/common/app.imp.cpp index 184ff60..55063ec 100644 --- a/src/metier/common/app.imp.cpp +++ b/src/metier/common/app.imp.cpp @@ -4,3 +4,51 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. #include "metier/common/app.imp.hpp" // IWYU pragma: associated + +#include + +#include "metier/common/api.hpp" + +namespace po = boost::program_options; + +namespace metier::common +{ +auto App::Imp::factory(App& parent, int& argc, char** argv) noexcept + -> std::unique_ptr +{ + static constexpr auto advanced{"advanced"}; + auto use_advanced{false}; + const auto options = [] { + const auto text = Api::Name().toStdString() + " options"; + auto out = po::options_description{text}; + out.add_options()( + advanced, + po::value()->implicit_value(true), + "Use advanced gui"); + + return out; + }(); + auto variables = po::variables_map{}; + + try { + auto parsed = po::command_line_parser(argc, argv) + .options(options) + .allow_unregistered() + .run(); + po::store(parsed, variables); + po::notify(variables); + } catch (po::error&) { + } + + for (const auto& [name, value] : variables) { + if (name == advanced) { + try { + use_advanced = value.as(); + } catch (...) { + } + } + } + + return choose_interface(parent, argc, argv, use_advanced); +} +} // namespace metier::common diff --git a/src/metier/common/app.imp.hpp b/src/metier/common/app.imp.hpp index d088cf5..14dc971 100644 --- a/src/metier/common/app.imp.hpp +++ b/src/metier/common/app.imp.hpp @@ -33,9 +33,9 @@ struct App::Imp { bool advanced) noexcept -> std::unique_ptr; static auto factory(App& parent, int& argc, char** argv) noexcept -> std::unique_ptr; - static auto factory_qml(App& parent, int& argc, char** argv) noexcept + static auto factory_standard(App& parent, int& argc, char** argv) noexcept -> std::unique_ptr; - static auto factory_widgets(App& parent, int& argc, char** argv) noexcept + static auto factory_advanced(App& parent, int& argc, char** argv) noexcept -> std::unique_ptr; virtual auto displayBlockchainChooser() -> void = 0; diff --git a/src/metier/skins/metier/CMakeLists.txt b/src/metier/skins/metier/CMakeLists.txt index e8b6f66..b249911 100644 --- a/src/metier/skins/metier/CMakeLists.txt +++ b/src/metier/skins/metier/CMakeLists.txt @@ -47,7 +47,7 @@ set_target_properties( metier PROPERTIES AUTOUIC_SEARCH_PATHS "${CMAKE_CURRENT_SOURCE_DIR}/ui" ) -target_sources(metier PRIVATE "skin/app.imp.widgets.cpp") +target_sources(metier PRIVATE "skin/app.imp.factory_advanced.cpp") if(METIER_QML_INTERFACE) metier_link_external_target(metier Qt::Qml) @@ -64,9 +64,9 @@ if(METIER_QML_INTERFACE) endif() qt_import_qml_plugins("${METIER_BASE_NAME}") - target_sources(metier PRIVATE "skin/app.imp.qml.cpp") + target_sources(metier PRIVATE "skin/app.imp.factory_standard.qml.cpp") else() - target_sources(metier PRIVATE "skin/app.imp.no-qml.cpp") + target_sources(metier PRIVATE "skin/app.imp.factory_standard.no-qml.cpp") endif() if(APPLE) diff --git a/src/metier/skins/metier/skin/app.imp.factory.cpp b/src/metier/skins/metier/skin/app.imp.factory.cpp deleted file mode 100644 index 55063ec..0000000 --- a/src/metier/skins/metier/skin/app.imp.factory.cpp +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) 2019-2024 The Open-Transactions developers -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. - -#include "metier/common/app.imp.hpp" // IWYU pragma: associated - -#include - -#include "metier/common/api.hpp" - -namespace po = boost::program_options; - -namespace metier::common -{ -auto App::Imp::factory(App& parent, int& argc, char** argv) noexcept - -> std::unique_ptr -{ - static constexpr auto advanced{"advanced"}; - auto use_advanced{false}; - const auto options = [] { - const auto text = Api::Name().toStdString() + " options"; - auto out = po::options_description{text}; - out.add_options()( - advanced, - po::value()->implicit_value(true), - "Use advanced gui"); - - return out; - }(); - auto variables = po::variables_map{}; - - try { - auto parsed = po::command_line_parser(argc, argv) - .options(options) - .allow_unregistered() - .run(); - po::store(parsed, variables); - po::notify(variables); - } catch (po::error&) { - } - - for (const auto& [name, value] : variables) { - if (name == advanced) { - try { - use_advanced = value.as(); - } catch (...) { - } - } - } - - return choose_interface(parent, argc, argv, use_advanced); -} -} // namespace metier::common diff --git a/src/metier/skins/metier/skin/app.imp.widgets.cpp b/src/metier/skins/metier/skin/app.imp.factory_advanced.cpp similarity index 96% rename from src/metier/skins/metier/skin/app.imp.widgets.cpp rename to src/metier/skins/metier/skin/app.imp.factory_advanced.cpp index bd4ebfc..0ff42c6 100644 --- a/src/metier/skins/metier/skin/app.imp.widgets.cpp +++ b/src/metier/skins/metier/skin/app.imp.factory_advanced.cpp @@ -108,7 +108,8 @@ struct LegacyApp final : public common::App::Imp, public QApplication { auto init(int& argc, char** argv) noexcept -> void final { - ot_ = std::make_unique(*this, parent_, argc, argv); + auto api = common::Api::Factory(*this, parent_, argc, argv); + ot_ = std::make_unique(*this, api); first_run_ = std::make_unique(this); new_seed_ = std::make_unique(this, *ot_); recover_wallet_ = std::make_unique(this, *ot_); @@ -169,7 +170,7 @@ struct LegacyApp final : public common::App::Imp, public QApplication { namespace metier::common { -auto App::Imp::factory_widgets(App& parent, int& argc, char** argv) noexcept +auto App::Imp::factory_advanced(App& parent, int& argc, char** argv) noexcept -> std::unique_ptr { return std::make_unique(parent, argc, argv); diff --git a/src/metier/skins/metier/skin/app.imp.no-qml.cpp b/src/metier/skins/metier/skin/app.imp.factory_standard.no-qml.cpp similarity index 91% rename from src/metier/skins/metier/skin/app.imp.no-qml.cpp rename to src/metier/skins/metier/skin/app.imp.factory_standard.no-qml.cpp index b510c05..a850903 100644 --- a/src/metier/skins/metier/skin/app.imp.no-qml.cpp +++ b/src/metier/skins/metier/skin/app.imp.factory_standard.no-qml.cpp @@ -13,6 +13,6 @@ auto App::Imp::choose_interface( char** argv, bool) noexcept -> std::unique_ptr { - return factory_widgets(parent, argc, argv); + return factory_advanced(parent, argc, argv); } } // namespace metier::common diff --git a/src/metier/skins/metier/skin/app.imp.qml.cpp b/src/metier/skins/metier/skin/app.imp.factory_standard.qml.cpp similarity index 95% rename from src/metier/skins/metier/skin/app.imp.qml.cpp rename to src/metier/skins/metier/skin/app.imp.factory_standard.qml.cpp index d3cb62b..7ca18bd 100644 --- a/src/metier/skins/metier/skin/app.imp.qml.cpp +++ b/src/metier/skins/metier/skin/app.imp.factory_standard.qml.cpp @@ -108,7 +108,8 @@ struct QmlApp final : public common::App::Imp, public QApplication { auto init(int& argc, char** argv) noexcept -> void final { - ot_ = std::make_unique(*this, parent_, argc, argv); + auto api = common::Api::Factory(*this, parent_, argc, argv); + ot_ = std::make_unique(*this, api); { auto* ot = ot_.get(); @@ -194,7 +195,7 @@ struct QmlApp final : public common::App::Imp, public QApplication { namespace metier::common { -auto App::Imp::factory_qml(App& parent, int& argc, char** argv) noexcept +auto App::Imp::factory_standard(App& parent, int& argc, char** argv) noexcept -> std::unique_ptr { return std::make_unique(parent, argc, argv); @@ -208,10 +209,10 @@ auto App::Imp::choose_interface( { if (advanced) { - return factory_widgets(parent, argc, argv); + return factory_advanced(parent, argc, argv); } else { - return factory_qml(parent, argc, argv); + return factory_standard(parent, argc, argv); } } } // namespace metier::common diff --git a/tools/cmake/metier-generate-target-gui.cmake b/tools/cmake/metier-generate-target-gui.cmake index 1e362b4..184287b 100644 --- a/tools/cmake/metier-generate-target-gui.cmake +++ b/tools/cmake/metier-generate-target-gui.cmake @@ -36,8 +36,11 @@ function( "${target_name}" PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/skin/app.skin.cpp" - "skin/app.imp.factory.cpp" "skin/custom.cpp" "skin/size.cpp" ) + + if(EXISTS "skin/app.imp.choose_interface.cpp") + target_sources("${target_name}" PRIVATE "skin/app.imp.choose_interface.cpp") + endif() endfunction()