#include #include #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(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; }