summaryrefslogtreecommitdiff
path: root/controller.cxx
diff options
context:
space:
mode:
authorꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2021-07-10 23:21:25 +0800
committerꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2021-07-10 23:21:25 +0800
commit5d0a833af478b87f4fb815e37da0beb5a09c6067 (patch)
tree00a1e021aea50625d0c57ddeb4321af47a3c0641 /controller.cxx
parent873f8a55d01ecbd11c957d140eaf2a0bb30ae51f (diff)
Use the response data to initiate client
It's correct now, but the problem is, the client pushes the catalog page faster than the web server can reload to make the newly built sample URL valid.
Diffstat (limited to 'controller.cxx')
-rw-r--r--controller.cxx76
1 files changed, 44 insertions, 32 deletions
diff --git a/controller.cxx b/controller.cxx
index e70a66d..6f7759f 100644
--- a/controller.cxx
+++ b/controller.cxx
@@ -1,55 +1,67 @@
+#include <icclient.h>
#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*);
+ void sign_up(char const*, char const*, void (*)(icclient_response *));
+ struct icclient_catalog* catalog_data(char const*, char const*);
}
-Controller::Controller(QObject* parent) :
- QObject{parent},
- catalog{nullptr}
+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};
- 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()
+ path = new QString{QDir{
+ QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)}.absolutePath()
+ % cert.remove(0, cert.lastIndexOf("/"))};
+ QFile{"assets:" % cert}.copy(*path);
#endif
- };
- auto engine = static_cast<QQmlApplicationEngine*>(parent);
+ 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,*/
+ 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
+ , path->toLatin1().constData()
#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");
+ };
+ 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;
- delete interchange;
+ if (imageDir) delete imageDir;
+ if (interchange) delete interchange;
}