summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2021-06-13 17:49:57 +0800
committerꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id>2021-06-13 17:49:57 +0800
commitd6e1d66de6b539b6af4a7f517d84a07f17e75c2f (patch)
treece226a5aacb0de6cdee4494e60cfe5b888f96bba
parentf91691a987aaca4a16a2ffe8d4ad3b6c6b8c8059 (diff)
gotResults now passes icclient_fetch_t*
so the signal can be connected to some slot.
-rw-r--r--admin.cxx2
-rw-r--r--client.cxx27
-rw-r--r--member.cxx2
-rw-r--r--qicclient.hxx38
-rw-r--r--qicclient/admin.hxx2
-rw-r--r--qicclient/member.hxx2
6 files changed, 35 insertions, 38 deletions
diff --git a/admin.cxx b/admin.cxx
index 6ff1566..5b0d468 100644
--- a/admin.cxx
+++ b/admin.cxx
@@ -8,7 +8,7 @@ namespace QICClient {
std::shared_ptr<Admin> Admin::logIn(QString const& username,
QString const& password, QString const& successPage,
QString const& nextPage, QString const& failPage,
- icclient_handler handler)
+ void (*handler)(icclient_fetch_t *))
{
auto admin = new Admin{};
admin->setData(icclient_admin_login(username.toLatin1().constData(),
diff --git a/client.cxx b/client.cxx
index 4321726..7b91e2d 100644
--- a/client.cxx
+++ b/client.cxx
@@ -1,15 +1,14 @@
+#include <cstddef>
#include <memory>
#include <QObject>
-#include <icclient/typedefs.h>
#include "qicclient.hxx"
#include "qicclient/ord.hxx"
-static QICClient::Client *client;
+static QICClient::Client* client;
-static void callback(icclient_catalog* catalog)
+static void handle_results(icclient_fetch_t* fetch)
{
- client->emitCatalog(catalog);
- icclient_free_catalog(catalog);
+ client->emitResults(fetch);
}
namespace QICClient {
@@ -25,22 +24,26 @@ namespace QICClient {
icclient_cleanup();
}
- void Client::results(QString const& prodGroup, icclient_handler handler)
+ void Client::results(QString const& prodGroup)
{
- icclient_results(prodGroup.toLatin1().constData(), callback, handler);
+ icclient_results(prodGroup.toLatin1().constData(), [](icclient_catalog* catalog) {
+ icclient_free_catalog(catalog);
+ }, handle_results);
}
- void Client::allProducts(icclient_handler handler)
+ void Client::allProducts()
{
- icclient_allproducts(callback, handler);
+ icclient_allproducts([](icclient_catalog* catalog) {
+ icclient_free_catalog(catalog);
+ }, handle_results);
}
- void Client::emitCatalog(icclient_catalog* catalog)
+ void Client::emitResults(icclient_fetch_t* fetch)
{
- emit gotResults(new Catalog{catalog});
+ emit gotResults(fetch);
}
- void Client::flyPage(QString const& sku,icclient_handler handler)
+ void Client::flyPage(QString const& sku,void (*handler)(icclient_fetch_t*))
{
icclient_product* product = nullptr;
icclient_flypage(sku.toLatin1().constData(), handler, &product);
diff --git a/member.cxx b/member.cxx
index 1b40a00..75114f7 100644
--- a/member.cxx
+++ b/member.cxx
@@ -8,7 +8,7 @@ namespace QICClient {
std::shared_ptr<Member> Member::logIn(QString const& username,
QString const& password, QString const& successPage,
QString const& nextPage, QString const& failPage,
- icclient_handler handler)
+ void (*handler)(icclient_fetch_t *))
{
auto member = new Member{};
member->setData(icclient_member_login(username.toLatin1().constData(),
diff --git a/qicclient.hxx b/qicclient.hxx
index aa8bca9..a3cc6d0 100644
--- a/qicclient.hxx
+++ b/qicclient.hxx
@@ -1,5 +1,5 @@
-#ifndef QICCLIENT_CLIENT_HXX
-#define QICCLIENT_CLIENT_HXX
+#ifndef QICCLIENT_HXX
+#define QICCLIENT_HXX
#include <QObject>
#include <qicclient/catalog.hxx>
@@ -8,7 +8,6 @@
namespace QICClient {
using std::shared_ptr;
- class Catalog;
class Ord;
class Client : public QObject
@@ -23,29 +22,13 @@ namespace QICClient {
*/
Client(char const* url, char const* certificate = nullptr);
~Client();
-
- /*!
- * \brief For fetching products that belong a specific group.
- * \param prodGroup The name of the product group.
- * \param handler A pointer to a cURL write function callback.
- */
- void results(QString const& prodGroup, icclient_handler handler = nullptr);
-
- /*!
- * \brief For fetching data about all active products.
- * \param handler A pointer to a cURL write function callback.
- */
- void allProducts(icclient_handler handler = nullptr);
-
- void emitCatalog(icclient_catalog *catalog);
-
+ void emitResults(icclient_fetch_t* fetch);
/*!
* \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, icclient_handler handler);
-
+ void flyPage(QString const& sku, void (*handler)(icclient_fetch_t*));
/*!
* \brief For putting an item to a cart.
* \param sku The SKU of the item to order.
@@ -54,8 +37,19 @@ namespace QICClient {
*/
void order(QString const& sku, Catalog const& catalog, Ord& order);
+ public slots:
+ /*!
+ * \brief For fetching products that belong a specific group.
+ * \param prodGroup The name of the product group.
+ */
+ void results(QString const& prodGroup);
+ /*!
+ * \brief For fetching data about all active products.
+ */
+ void allProducts();
+
signals:
- void gotResults(Catalog* catalog);
+ void gotResults(icclient_fetch_t* fetch);
void gotFlyPage(shared_ptr<Product> product);
};
diff --git a/qicclient/admin.hxx b/qicclient/admin.hxx
index c123a2d..f242227 100644
--- a/qicclient/admin.hxx
+++ b/qicclient/admin.hxx
@@ -32,7 +32,7 @@ namespace QICClient {
QString const& successPage = nullptr,
QString const& nextPage = nullptr,
QString const& failPage = nullptr,
- icclient_handler handler = nullptr);
+ void (*handler)(icclient_fetch_t *) = nullptr);
QString const& userName() const { return m_userName; }
QString const& password() const { return m_password; }
diff --git a/qicclient/member.hxx b/qicclient/member.hxx
index 4e8010f..e2a3dcb 100644
--- a/qicclient/member.hxx
+++ b/qicclient/member.hxx
@@ -62,7 +62,7 @@ namespace QICClient {
QString const& successPage = nullptr,
QString const& nextPage = nullptr,
QString const& failPage = nullptr,
- icclient_handler handler = nullptr);
+ void (*handler)(icclient_fetch_t *) = nullptr);
QString const& userName() const { return m_userName; }
QString const& userNick() const { return m_userNick; }