diff options
Diffstat (limited to 'controller.cxx')
| -rw-r--r-- | controller.cxx | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/controller.cxx b/controller.cxx new file mode 100644 index 0000000..2e95c09 --- /dev/null +++ b/controller.cxx @@ -0,0 +1,55 @@ +#include <QtQml> +#include <qicclient/admin.hxx> +#include "controller.hxx" + +extern "C" { + void sign_up(char const*, char const*); + struct icclient_catalog* catalog_data(char const*); +} + +Controller::Controller(QObject* parent) : + QObject{parent}, + catalog{nullptr} +{ +#ifdef __ANDROID__ + QString cert{CA_BUNDLE}; + QString path{QDir{QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)}.absolutePath() + % cert.remove(0, cert.lastIndexOf("/"))}; + QFile{"assets:" % cert}.copy(path); +#endif + interchange = new Client{SAMPLEURL, IMAGE_DIR +#ifdef __ANDROID__ + , path.toLatin1().constData() +#endif + }; + auto engine = static_cast<QQmlApplicationEngine*>(parent); + engine->load(QUrl{QStringLiteral("qrc:/main.qml")}); + auto window = engine->rootObjects()[0]; + window->setProperty("imageDir", SAMPLEURL"/images/"); + connect(window, SIGNAL(signUp(QString)), this, SIGNAL(signUp(QString))); + connect(this, &Controller::signUp, [/*this,*/ +#ifdef __ANDROID__ + &path +#endif + ](QString const& brand) { + sign_up(brand.toLatin1().constData(), +#ifdef __ANDROID__ + path.toLatin1().constData() +#else + nullptr +#endif + ); +// interchange->catalog(brand); + }); + connect(interchange, &Client::gotCatalog, [this,engine,window](QString const& response) { + catalog = new Catalog{catalog_data(response.toLatin1().constData())}; + engine->rootContext()->setContextProperty("catalog", catalog); + QMetaObject::invokeMethod(window, "pushCatalog"); + }); +} + +Controller::~Controller() +{ + if (catalog) delete catalog; + delete interchange; +} |