Skip to content

Commit

Permalink
Merge pull request #194 from justusranvier/develop
Browse files Browse the repository at this point in the history
make common classes more customizable
  • Loading branch information
justusranvier authored Feb 7, 2024
2 parents f169b67 + e1a8e97 commit f942c05
Show file tree
Hide file tree
Showing 19 changed files with 284 additions and 223 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ project(metier)

find_package(
otcommon
2
3
CONFIG
REQUIRED
)
Expand Down
4 changes: 3 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}
},
{
Expand Down
1 change: 1 addition & 0 deletions src/metier/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
37 changes: 22 additions & 15 deletions src/metier/common/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
#include <QUrl>
#include <QtLogging>
#include <algorithm>
#include <atomic>
#include <chrono>
#include <compare>
#include <cstddef>
#include <iterator>
#include <span>
#include <utility>

#include "metier/common/api.imp.hpp"
#include "metier/common/convertblockchain.hpp"
Expand All @@ -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> imp)
: QObject(&parent)
, imp_p_(std::make_unique<Imp>(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);
Expand Down Expand Up @@ -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();
Expand All @@ -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{});
Expand All @@ -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;
Expand All @@ -152,23 +153,23 @@ 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;
case Imp::State::have_seed: {
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 {
if (false == imp_.validateNym()) {
qFatal("Unable to initialize identity");
}

imp_.state_.store(Imp::State::have_nym);
imp_.state(Imp::State::have_nym);
Q_EMIT checkStartupConditions();
}
} break;
Expand All @@ -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();

Expand All @@ -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;
Expand All @@ -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<int>(imp_.enabled_chains_.count());
return static_cast<int>(imp_.enabledChainCount());
}

auto Api::Factory(QGuiApplication& parent, App& app, int& argc, char** argv)
-> std::shared_ptr<Imp>
{
return std::make_shared<Imp>(parent, app, argc, argv);
}

auto Api::getQRcodeBase64(const QString input_string) -> QString
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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(); }

Expand Down
126 changes: 71 additions & 55 deletions src/metier/common/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<int>;

static auto Factory(
QGuiApplication& parent,
App& app,
int& argc,
char** argv) -> std::shared_ptr<Imp>;

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> 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> imp_p_;
Imp& imp_;
~Api() override;

Api() = delete;
protected:
std::shared_ptr<Imp> imp_p_;
Imp& imp_;
};
} // namespace metier::common
Loading

0 comments on commit f942c05

Please sign in to comment.