diff options
Diffstat (limited to 'controller.cxx')
-rw-r--r-- | controller.cxx | 75 |
1 files changed, 37 insertions, 38 deletions
diff --git a/controller.cxx b/controller.cxx index 6f7759f..8354974 100644 --- a/controller.cxx +++ b/controller.cxx @@ -1,67 +1,66 @@ -#include <icclient.h> #include <QtQml> -#include <qicclient/admin.hxx> +#include <icclient.h> +#include <qicclient.hxx> #include "controller.hxx" -extern "C" { - void sign_up(char const*, char const*, void (*)(icclient_response *)); - struct icclient_catalog* catalog_data(char const*, char const*); -} - static Controller* controller; static QQmlApplicationEngine* engine; -static QICClient::Client* interchange = nullptr; -static QString* path = nullptr; -static QString* imageDir = nullptr; -static Catalog* catalog = nullptr; +static QString* certFile = nullptr; +using namespace QICClient; +static Client* shop = nullptr; +static Catalog* allProducts = nullptr; + +extern "C" { + void sign_up(char const*, char const*, void (*)(icclient_response*)); + struct icclient_catalog* catalog(char const*, char const*); +} Controller::Controller(QObject* parent) : QObject{parent} { controller = this; -#ifdef __ANDROID__ - QString cert{CA_BUNDLE}; - path = new QString{QDir{ - QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)}.absolutePath() - % cert.remove(0, cert.lastIndexOf("/"))}; - QFile{"assets:" % cert}.copy(*path); -#endif engine = static_cast<QQmlApplicationEngine*>(parent); engine->load(QUrl{QStringLiteral("qrc:/main.qml")}); auto window = engine->rootObjects()[0]; connect(window, SIGNAL(signUp(QString)), this, SIGNAL(signUp(QString))); connect(this, &Controller::signUp, [](QString const& brand) { - sign_up(brand.toLatin1().constData(), path ? path->toLatin1().constData() : nullptr, +#ifdef __ANDROID__ + QString certAsset{CA_BUNDLE}; + certFile = new QString{QDir{ + QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + }.absolutePath() % certAsset.remove(0, certAsset.lastIndexOf("/"))}; + QFile{"assets:" % certAsset}.copy(*certFile); +#endif + sign_up(brand.toLatin1().constData(), certFile ? certFile->toLatin1().constData() : nullptr, [](icclient_response* response) { QString brand{response->data}; icclient_free_response(response); QString sampleUrl{QString{SECURE_SERVER} % "/" % brand}; - imageDir = new QString{"/" % brand % "/images"}; - interchange = new Client{sampleUrl.toLatin1().constData(), - imageDir->toLatin1().constData() -#ifdef __ANDROID__ - , path->toLatin1().constData() -#endif + QString imageDir{"/" % brand % "/images"}; + shop = new Client{ + sampleUrl.toLatin1().constData(), + imageDir.toLatin1().constData(), + certFile ? certFile->toLatin1().constData() : nullptr }; - delete path; + if (certFile) delete certFile; auto window = engine->rootObjects()[0]; - window->setProperty("imageDir", QString{sampleUrl % "/images/"}); - controller->connect(interchange, &Client::gotCatalog, - [window](QString const& response) { - catalog = new Catalog{ - catalog_data(response.toLatin1().constData(), - imageDir->toLatin1().constData())}; + window->setProperty("imageBase", QString{sampleUrl % "/images/"}); + controller->connect(shop, &Client::gotCatalog, + [imageDir,window](QString const& response) { + allProducts = new Catalog{catalog( + response.toLatin1().constData(), + imageDir.toLatin1().constData())}; engine->rootContext()->setContextProperty("catalog", - catalog); + allProducts); QMetaObject::invokeMethod(window, "pushCatalog"); }); - interchange->allProducts(); - }); + shop->allProducts(); + } + ); }); } Controller::~Controller() { - if (catalog) delete catalog; - if (imageDir) delete imageDir; - if (interchange) delete interchange; + if (allProducts) delete allProducts; + if (shop) delete shop; } |