summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client.cxx21
-rw-r--r--qicclient/client.hxx2
2 files changed, 19 insertions, 4 deletions
diff --git a/client.cxx b/client.cxx
index ff28eaa..6e4a3f4 100644
--- a/client.cxx
+++ b/client.cxx
@@ -2,6 +2,7 @@
#include <memory>
#include <QObject>
#include <icclient/typedefs.h>
+#include <icclient/catalog.h>
#include <icclient/client.h>
#include "qicclient/catalog.hxx"
#ifndef __EMSCRIPTEN__
@@ -9,10 +10,19 @@
#endif
#include "qicclient/client.hxx"
+static QICClient::Client *client;
+
+static void callback(icclient_catalog* catalog)
+{
+ client->emitCatalog(catalog);
+ icclient_catalog_free(catalog);
+}
+
namespace QICClient {
Client::Client(char const* url, char const* certificate)
{
+ client = this;
icclient_init(url, certificate);
}
@@ -24,15 +34,18 @@ namespace QICClient {
void Client::results(QString const& prodGroup, icclient_handler handler)
{
icclient_catalog* catalog = nullptr;
- icclient_results(prodGroup.toLatin1().constData(), handler, &catalog);
- if (catalog) emit gotResults(new Catalog{catalog});
+ icclient_results(prodGroup.toLatin1().constData(), callback, &catalog, handler);
}
void Client::allProducts(icclient_handler handler)
{
icclient_catalog* catalog = nullptr;
- icclient_allproducts(handler, &catalog);
- if (catalog) emit gotResults(new Catalog{catalog});
+ icclient_allproducts(callback, &catalog, handler);
+ }
+
+ void Client::emitCatalog(icclient_catalog* catalog)
+ {
+ emit gotResults(new Catalog{catalog});
}
void Client::flyPage(QString const& sku,icclient_handler handler)
diff --git a/qicclient/client.hxx b/qicclient/client.hxx
index dfe1888..d508b16 100644
--- a/qicclient/client.hxx
+++ b/qicclient/client.hxx
@@ -38,6 +38,8 @@ namespace QICClient {
*/
void allProducts(icclient_handler handler);
+ void emitCatalog(icclient_catalog *catalog);
+
/*!
* \brief For fetching data about a specific product.
* \param sku The SKU of the item to order.