#include #include #include #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; 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(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, [](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 }; delete path; 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())}; engine->rootContext()->setContextProperty("catalog", catalog); QMetaObject::invokeMethod(window, "pushCatalog"); }); interchange->allProducts(); }); }); } Controller::~Controller() { if (catalog) delete catalog; if (imageDir) delete imageDir; if (interchange) delete interchange; }