summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Catalog.qml5
-rw-r--r--Link.qml30
-rw-r--r--controller.cxx82
-rw-r--r--controller.hxx5
-rw-r--r--handler.c7
-rw-r--r--images/2be179c1-b901-4db5-b9ab-81327a450ee5.pngbin0 -> 34477 bytes
-rw-r--r--main.qml9
-rw-r--r--namatoko.qrc2
8 files changed, 96 insertions, 44 deletions
diff --git a/Catalog.qml b/Catalog.qml
index a004ee9..46923ce 100644
--- a/Catalog.qml
+++ b/Catalog.qml
@@ -3,10 +3,11 @@ import QtQuick.Controls 2.15
import "qicpos"
Rectangle {
+ property string arg
color: "#0a0a0a"
ListView {
- anchors.fill: parent
objectName: "catalog"
+ anchors.fill: parent
model: catalog
spacing: 16
delegate: ProductForm {
@@ -17,7 +18,7 @@ Rectangle {
previewImage {
width: 64
height: 64
- source: imageBase + "thumb/" + image
+ source: arg + "items/" + image
}
nameLabel.text: description
priceLabel.text: price
diff --git a/Link.qml b/Link.qml
new file mode 100644
index 0000000..199d552
--- /dev/null
+++ b/Link.qml
@@ -0,0 +1,30 @@
+import QtQuick 2.15
+import QtQuick.Controls 2.15
+import QtQuick.Layouts 1.15
+
+Rectangle {
+ property string arg
+ color: "#2a2a2a"
+ ColumnLayout {
+ anchors.centerIn: parent
+ Image {
+ Layout.alignment: Qt.AlignCenter
+ source: "images/2be179c1-b901-4db5-b9ab-81327a450ee5.png"
+ }
+ Text {
+ objectName: "link"
+ signal catalog(string brand)
+ function push(view, arg) {
+ stack.push(view + ".qml", {
+ "arg": arg
+ })
+ pushed()
+ }
+ signal pushed()
+ Layout.alignment: Qt.AlignCenter
+ text: "<a href=\"https://darapsa.com/" + arg + "\">https://darapsa.com/" + arg + "</a>"
+ linkColor: "#ffffff"
+ onLinkActivated: catalog(arg)
+ }
+ }
+}
diff --git a/controller.cxx b/controller.cxx
index aa676af..c1dd2ca 100644
--- a/controller.cxx
+++ b/controller.cxx
@@ -11,57 +11,67 @@ static Client* shop = nullptr;
static Catalog* allProducts = nullptr;
extern "C" {
- void sign_up(char const*, char const*, void (*)(icclient_response*));
+ 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;
- engine = static_cast<QQmlApplicationEngine*>(parent);
+ engine = qobject_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) {
+ connect(window, SIGNAL(signUp(QString)), this, SLOT(signUp(QString)));
+}
+
+void Controller::signUp(QString const& brand)
+{
#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);
+ 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) {
- const_cast<char*>(response->data)[response->numBytes] = '\0';
- QString brand{response->data};
- icclient_free_response(response);
- QString sampleUrl{QString{SECURE_SERVER} % "/" % brand};
- QString imageDir{"/" % brand % "/images"};
- shop = new Client{
- sampleUrl.toLatin1().constData(),
- imageDir.toLatin1().constData(),
- certFile ? certFile->toLatin1().constData() : nullptr
- };
- if (certFile) delete certFile;
- auto window = engine->rootObjects()[0];
- 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",
- allProducts);
- QMetaObject::invokeMethod(window, "pushCatalog");
- });
- shop->allProducts();
- }
- );
+ sign_up(brand.toLatin1().constData(), certFile ? certFile->toLatin1().constData() : nullptr,
+ [](icclient_response* response) {
+ const_cast<char*>(response->data)[response->numBytes] = '\0';
+ QString brand{response->data};
+ icclient_free_response(response);
+ auto window = engine->rootObjects()[0];
+ QMetaObject::invokeMethod(window, "push", Q_ARG(QVariant, "Link"), Q_ARG(QVariant, brand));
+ controller->connect(window, SIGNAL(pushed()), controller, SIGNAL(pushed()));
+ controller->connect(controller, &Controller::pushed, [window]() {
+ controller->connect(window->findChild<QObject*>("link"), SIGNAL(catalog(QString)),
+ controller, SLOT(catalog(QString)));
+ });
+ });
+}
+
+void Controller::catalog(QString const& brand)
+{
+ QString sampleUrl{QString{SECURE_SERVER} % "/" % brand};
+ QString imageDir{"/" % brand % "/images"};
+ shop = new Client{sampleUrl.toLatin1().constData(), imageDir.toLatin1().constData(),
+ certFile ? certFile->toLatin1().constData() : nullptr};
+ if (certFile) {
+ delete certFile;
+ certFile = nullptr;
+ }
+ connect(shop, &Client::gotCatalog, [sampleUrl,imageDir](QString const& response) {
+ allProducts = new Catalog{::catalog(response.toLatin1().constData(),
+ imageDir.toLatin1().constData())};
+ engine->rootContext()->setContextProperty("catalog", allProducts);
+ QMetaObject::invokeMethod(engine->rootObjects()[0]->findChild<QObject*>("link"), "push",
+ Q_ARG(QVariant, "Catalog"),
+ Q_ARG(QVariant, QString{sampleUrl % "/images/"}));
});
+ shop->allProducts();
}
Controller::~Controller()
{
+ if (certFile) delete certFile;
if (allProducts) delete allProducts;
if (shop) delete shop;
}
diff --git a/controller.hxx b/controller.hxx
index b2733fc..f0f3a1f 100644
--- a/controller.hxx
+++ b/controller.hxx
@@ -9,8 +9,11 @@ class Controller : public QObject
public:
Controller(QObject* parent = nullptr);
~Controller();
- signals:
+ public slots:
void signUp(QString const& brand);
+ void catalog(QString const& brand);
+ signals:
+ void pushed();
};
#endif
diff --git a/handler.c b/handler.c
index 118519d..37469ba 100644
--- a/handler.c
+++ b/handler.c
@@ -1,8 +1,11 @@
+#include <stdio.h>
#include <stdbool.h>
#include <tidy.h>
#include <tidybuffio.h>
#include <icclient.h>
+#define SUBDIR "/items"
+
static void recurse_catalog(TidyDoc doc, TidyNode tnod, const char *image_dir,
struct icclient_catalog **catalog)
{
@@ -14,8 +17,8 @@ static void recurse_catalog(TidyDoc doc, TidyNode tnod, const char *image_dir,
recurse_catalog(doc, child, image_dir, catalog);
continue;
}
- static const char *subdir = "/thumb/";
- char prefix[strlen(image_dir) + strlen(subdir) + 1];
+ char prefix[strlen(image_dir) + strlen(SUBDIR) + 1];
+ sprintf(prefix, "%s%s", image_dir, SUBDIR);
size_t prefix_len = strlen(prefix);
bool bail = false;
for (TidyAttr attr = tidyAttrFirst(child); attr; attr = tidyAttrNext(attr))
diff --git a/images/2be179c1-b901-4db5-b9ab-81327a450ee5.png b/images/2be179c1-b901-4db5-b9ab-81327a450ee5.png
new file mode 100644
index 0000000..639a644
--- /dev/null
+++ b/images/2be179c1-b901-4db5-b9ab-81327a450ee5.png
Binary files differ
diff --git a/main.qml b/main.qml
index 304bfe0..0da014f 100644
--- a/main.qml
+++ b/main.qml
@@ -3,13 +3,16 @@ import QtQuick.Controls 2.15
import "larva/features"
ApplicationWindow {
- property string imageBase
signal signUp(string brand)
- function pushCatalog() {
+ function push(view, arg) {
busy.visible = false
busy.running = false
- stack.push("Catalog.qml")
+ stack.push(view + ".qml", {
+ "arg": arg
+ })
+ pushed()
}
+ signal pushed()
id: window
width: 360
height: 640
diff --git a/namatoko.qrc b/namatoko.qrc
index bcb5510..0f950da 100644
--- a/namatoko.qrc
+++ b/namatoko.qrc
@@ -3,6 +3,8 @@
<file>qtquickcontrols2.conf</file>
<file>main.qml</file>
<file>images/onboarding-illustration-1.png</file>
+ <file>Link.qml</file>
+ <file>images/2be179c1-b901-4db5-b9ab-81327a450ee5.png</file>
<file>Catalog.qml</file>
</qresource>
</RCC>