diff options
author | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2022-09-25 10:55:36 +0800 |
---|---|---|
committer | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2022-09-25 10:55:36 +0800 |
commit | 18508ea004a66cc30c42c43d14afdc16b2267666 (patch) | |
tree | 1171e1d6c8259bb3446b229e298243bb33d47a04 /interchange.cxx | |
parent | 91bffad1e8afef36eedf51b50a80a7edf6400f7d (diff) |
Rename project to qinterchange
Diffstat (limited to 'interchange.cxx')
-rw-r--r-- | interchange.cxx | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/interchange.cxx b/interchange.cxx new file mode 100644 index 0000000..6886ba9 --- /dev/null +++ b/interchange.cxx @@ -0,0 +1,82 @@ +#include "interchange.hxx" +#include "interchange/ord.hxx" + +namespace Interchange { + + static Interchange* interchange; + + Interchange::Interchange(char const* sampleURL, char const* image_Dir, char const* certificate) + { + interchange = this; + interchange_init(sampleURL, image_Dir, certificate); + } + + Interchange::~Interchange() + { + interchange_cleanup(); + } + + void Interchange::catalog(QString const& prodGroup) + { + interchange_catalog(prodGroup.toLatin1().constData(), [](interchange_response* response) { + interchange->emitCatalog(QString{response->data}); + interchange_free_response(response); + }, nullptr); + } + + void Interchange::allProducts() + { + catalog("All-Products"); + } + + void Interchange::product(QString const& sku) + { + interchange_product(sku.toLatin1().constData(), [](interchange_response* response) { + interchange->emitProduct(QString{response->data}); + interchange_free_response(response); + }, nullptr); + } + + void Interchange::page(QString const& path) + { + interchange_page(path.toLatin1().constData(), [](interchange_response* response) { + interchange->emitPage(QString{response->data}); + interchange_free_response(response); + }); + } + + void Interchange::defaultCatalog(QString const& prodGroup) + { + interchange_catalog(prodGroup.toLatin1().constData(), nullptr, [](struct interchange_catalog* catalog) { + interchange_free_catalog(catalog); + }); + } + + void Interchange::defaultAllProducts() + { + defaultCatalog("All-Products"); + } + + void Interchange::emitCatalog(QString const& response) + { + emit gotCatalog(response); + } + + void Interchange::emitProduct(QString const& response) + { + emit gotProduct(response); + } + + void Interchange::emitPage(QString const& response) + { + emit gotPage(response); + } + + void Interchange::order(QString const& sku, Catalog const& catalog, Ord& order) + { + auto c_order = order.data(); + interchange_ord_order(sku.toLatin1().constData(), catalog.constData(), &c_order); + order.setData(c_order); + } + +} |