From 582ad4435408bdc19a007315e2c41770174cd606 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=EA=A6=AB=EA=A6=B6=EA=A6=8F=EA=A7=80=EA=A6=A6?= =?UTF-8?q?=EA=A6=BF=EA=A6=A7=EA=A6=AE=EA=A6=91=EA=A6=A9=EA=A6=AD=EA=A7=80?= Date: Fri, 18 Jun 2021 21:31:37 +0800 Subject: Conform to updated libicclient function names --- admin.cxx | 1 - catalog.cxx | 3 +-- client.cxx | 59 +++++++++++++++++++++++++-------------------------- member.cxx | 1 - qicclient.hxx | 29 +++++++++++-------------- qicclient/catalog.hxx | 6 +++--- qicclient/product.hxx | 2 +- 7 files changed, 46 insertions(+), 55 deletions(-) diff --git a/admin.cxx b/admin.cxx index c15b3c5..bd8a391 100644 --- a/admin.cxx +++ b/admin.cxx @@ -1,4 +1,3 @@ -#include #include #include #include "qicclient/admin.hxx" diff --git a/catalog.cxx b/catalog.cxx index e978858..2cee7c2 100644 --- a/catalog.cxx +++ b/catalog.cxx @@ -1,10 +1,9 @@ #include -#include #include "qicclient/catalog.hxx" namespace QICClient { - Catalog::Catalog(icclient_catalog* catalog, QObject* parent) : + Catalog::Catalog(struct icclient_catalog* catalog, QObject* parent) : QAbstractListModel{parent}, m_data{catalog} { diff --git a/client.cxx b/client.cxx index c4e574b..40aa342 100644 --- a/client.cxx +++ b/client.cxx @@ -1,6 +1,3 @@ -#include -#include -#include #include "qicclient.hxx" #include "qicclient/ord.hxx" @@ -8,71 +5,73 @@ namespace QICClient { static Client* client; - static void resultsHandler(icclient_response* response) + Client::Client(char const* sampleURL, char const* image_Dir, char const* certificate) { - client->emitResults(QString{response->data}); - icclient_free_response(response); + client = this; + icclient_init(sampleURL, image_Dir, certificate); } - static void catalogCallback(icclient_catalog* catalog) + Client::~Client() { - client->emitCatalog(new Catalog{catalog}); - icclient_free_catalog(catalog); + icclient_cleanup(); } - Client::Client(char const* sampleURL, char const* image_Dir, char const* certificate) + static void catalogHandler(icclient_response* response) { - client = this; - icclient_init(sampleURL, image_Dir, certificate); + client->emitCatalog(QString{response->data}); + icclient_free_response(response); } - Client::~Client() + static void catalogCallback(struct icclient_catalog* catalog) { - icclient_cleanup(); + icclient_free_catalog(catalog); } - void Client::results(QString const& prodGroup) + void Client::catalog(QString const& prodGroup) { - icclient_results(prodGroup.toLatin1().constData(), resultsHandler, nullptr); + icclient_catalog(prodGroup.toLatin1().constData(), catalogHandler, nullptr); } void Client::allProducts() { - icclient_allproducts(resultsHandler, nullptr); + icclient_allproducts(catalogHandler, nullptr); + } + + static void productHandler(icclient_response* response) + { + client->emitProduct(QString{response->data}); + icclient_free_response(response); } - void Client::strapResults(QString const& prodGroup) + void Client::product(QString const& sku) { - icclient_results(prodGroup.toLatin1().constData(), nullptr, catalogCallback); + icclient_product(sku.toLatin1().constData(), productHandler, nullptr); } - void Client::strapAllProducts() + void Client::defaultCatalog(QString const& prodGroup) { - icclient_allproducts(nullptr, catalogCallback); + icclient_catalog(prodGroup.toLatin1().constData(), nullptr, catalogCallback); } - void Client::emitResults(QString const& results) + void Client::defaultAllProducts() { - emit gotResults(results); + icclient_allproducts(nullptr, catalogCallback); } - void Client::emitCatalog(Catalog* catalog) + void Client::emitCatalog(QString const& catalog) { emit gotCatalog(catalog); } - void Client::flyPage(QString const& sku,void (*handler)(icclient_response*)) + void Client::emitProduct(QString const& product) { - icclient_product* product = nullptr; - icclient_flypage(sku.toLatin1().constData(), handler, &product); - if (product) emit gotFlyPage(shared_ptr{new Product{product}}); + emit gotProduct(product); } void Client::order(QString const& sku, Catalog const& catalog, Ord& order) { auto c_order = order.data(); - icclient_ord_order(sku.toLatin1().constData(), catalog.constData(), - &c_order); + icclient_ord_order(sku.toLatin1().constData(), catalog.constData(), &c_order); order.setData(c_order); } diff --git a/member.cxx b/member.cxx index 4498bcc..cc6bdad 100644 --- a/member.cxx +++ b/member.cxx @@ -1,4 +1,3 @@ -#include #include #include #include "qicclient/member.hxx" diff --git a/qicclient.hxx b/qicclient.hxx index 3b7f0d5..da1fa61 100644 --- a/qicclient.hxx +++ b/qicclient.hxx @@ -3,11 +3,9 @@ #include #include "qicclient/catalog.hxx" -#include namespace QICClient { - using std::shared_ptr; class Ord; class Client : public QObject @@ -26,12 +24,6 @@ namespace QICClient { * \brief Destructor. */ ~Client(); - /*! - * \brief For fetching data about a specific product. - * \param sku The SKU of the item to order. - * \param handler A pointer to a cURL write function callback. - */ - void flyPage(QString const& sku, void (*handler)(icclient_response*)); /*! * \brief For putting an item to a cart. * \param sku The SKU of the item to order. @@ -39,34 +31,37 @@ namespace QICClient { * \param order The order. */ void order(QString const& sku, Catalog const& catalog, Ord& order); - void emitResults(QString const& response); - void emitCatalog(Catalog* catalog); + void emitCatalog(QString const& response); + void emitProduct(QString const& response); public slots: /*! * \brief For fetching products that belong a specific group. * \param prodGroup The name of the product group. */ - void results(QString const& prodGroup); + void catalog(QString const& prodGroup); /*! * \brief For fetching data about all active products. */ void allProducts(); + /*! + * \brief For fetching data about a specific product. + * \param sku The SKU of the item to order. + */ + void product(QString const& sku); /*! * \brief For fetching products that belong a specific group. * \param prodGroup The name of the product group. - * \param handler A C style pointer to function for custom handling. */ - void strapResults(QString const& prodGroup); + void defaultCatalog(QString const& prodGroup); /*! * \brief For fetching data about all active products. */ - void strapAllProducts(); + void defaultAllProducts(); signals: - void gotResults(QString const& results); - void gotCatalog(Catalog* catalog); - void gotFlyPage(shared_ptr product); + void gotCatalog(QString const& response); + void gotProduct(QString const& response); }; } diff --git a/qicclient/catalog.hxx b/qicclient/catalog.hxx index 244f4f0..4deeff3 100644 --- a/qicclient/catalog.hxx +++ b/qicclient/catalog.hxx @@ -13,11 +13,11 @@ namespace QICClient { Q_OBJECT public: - Catalog(icclient_catalog* catalog, QObject* parent = nullptr); + Catalog(struct icclient_catalog* catalog, QObject* parent = nullptr); ~Catalog(); int rowCount(QModelIndex const& parent = QModelIndex()) const Q_DECL_OVERRIDE; QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; - icclient_catalog const* constData() const { return m_data; } + struct icclient_catalog const* constData() const { return m_data; } protected: QHash roleNames() const Q_DECL_OVERRIDE; @@ -25,7 +25,7 @@ namespace QICClient { private: void addProduct(Product const& product); QList products; - icclient_catalog* m_data; + struct icclient_catalog* m_data; }; } diff --git a/qicclient/product.hxx b/qicclient/product.hxx index 18b850a..980132b 100644 --- a/qicclient/product.hxx +++ b/qicclient/product.hxx @@ -20,7 +20,7 @@ namespace QICClient { CrossSellRole }; - Product(icclient_product* product) : + Product(struct icclient_product* product) : price{product->price}, weight{product->weight} { -- cgit v1.2.3