From 42b6dc18c1fd71d28d95fa52b78d6084f6831c46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=20=EA=A6=AB=EA=A6=B6=20=EA=A6=8F=EA=A7=80?= =?UTF-8?q?=EA=A6=A6=EA=A6=BF=20=EA=A6=A7=20=EA=A6=AE=20=EA=A6=91=20?= =?UTF-8?q?=EA=A6=A9=20=EA=A6=AD=EA=A7=80?= Date: Wed, 25 Sep 2019 21:26:33 +0800 Subject: Simplify project file --- qicclient.pro | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/qicclient.pro b/qicclient.pro index 40b180a..35d02f8 100644 --- a/qicclient.pro +++ b/qicclient.pro @@ -7,18 +7,6 @@ HEADERS += \ SOURCES += \ client.cxx INCLUDEPATH += $$PWD/libicclient -LIBS += \ - $$PWD/libicclient/libicclient.a \ - -lcurl - -contains(ANDROID_TARGET_ARCH,arm64-v8a) { - QMAKE_CFLAGS += -I/usr/local/aarch64-linux-android/sysroot/usr/include - LIBS += -L/usr/local/aarch64-linux-android/sysroot/usr/lib -} - -contains(ANDROID_TARGET_ARCH,armeabi-v7a) { - QMAKE_CFLAGS += -I/usr/local/arm-linux-androideabi/sysroot/usr/include - LIBS += -L/usr/local/arm-linux-androideabi/sysroot/usr/lib -} +LIBS += $$PWD/libicclient/libicclient.a debug: DEFINES += DEBUG -- cgit v1.2.3 From 7974deaf50967b36f2312a484431b2c2dca4dfc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=20=EA=A6=AB=EA=A6=B6=20=EA=A6=8F=EA=A7=80?= =?UTF-8?q?=EA=A6=A6=EA=A6=BF=20=EA=A6=A7=20=EA=A6=AE=20=EA=A6=91=20?= =?UTF-8?q?=EA=A6=A9=20=EA=A6=AD=EA=A7=80?= Date: Wed, 25 Sep 2019 21:30:43 +0800 Subject: libicclient fix --- libicclient | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libicclient b/libicclient index 57bb4f2..2126086 160000 --- a/libicclient +++ b/libicclient @@ -1 +1 @@ -Subproject commit 57bb4f20c1cf737b49eac2a8be108a9ffbde60ce +Subproject commit 212608669c44c24462d803dc238ed21e899c2b9f -- cgit v1.2.3 From d614c6c8bd12c2a01ab5ef90e34f068bfb019e25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=20=EA=A6=AB=EA=A6=B6=20=EA=A6=8F=EA=A7=80?= =?UTF-8?q?=EA=A6=A6=EA=A6=BF=20=EA=A6=A7=20=EA=A6=AE=20=EA=A6=91=20?= =?UTF-8?q?=EA=A6=A9=20=EA=A6=AD=EA=A7=80?= Date: Thu, 26 Sep 2019 11:53:13 +0800 Subject: Catalog class --- catalog.cxx | 62 +++++++++++++++++++++++++++++++++++++++ libicclient | 2 +- qicclient.pro | 2 ++ qicclient/catalog.hxx | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 catalog.cxx create mode 100644 qicclient/catalog.hxx diff --git a/catalog.cxx b/catalog.cxx new file mode 100644 index 0000000..17702bc --- /dev/null +++ b/catalog.cxx @@ -0,0 +1,62 @@ +#include "qicclient/catalog.hxx" + +namespace ICClient { + + int Catalog::rowCount(QModelIndex const& parent) const + { + Q_UNUSED(parent) + return products.count(); + } + + QVariant Catalog::data(QModelIndex const& index, int role) const + { + auto row = index.row(); + + if (row < 0 || row >= products.count()) return QVariant(); + + auto product = products[row]; + switch (role) { + case SkuRole: + return product.sku(); + case DescriptionRole: + return product.description(); + case CommentRole: + return product.comment(); + case ImageRole: + return product.image(); + case PriceRole: + return product.price(); + default: + return QVariant(); + } + } + + QHash Catalog::roleNames() const + { + return QHash{ + {SkuRole, "sku"} + , {DescriptionRole, "description"} + , {CommentRole, "comment"} + , {ImageRole, "image"} + , {PriceRole, "price"} + }; + } + + void Catalog::addProduct(Product const& product) + { + beginInsertRows(QModelIndex(), rowCount(), rowCount()); + products << product; + endInsertRows(); + } + + void Catalog::update(icclient_catalog* catalog) + { + if (catalog) { + for (size_t i = 0; i < catalog->length; i++) + addProduct(Product{catalog->products[i]}); + icclient_product_freecatalog(catalog); + } + emit updated(); + } + +} diff --git a/libicclient b/libicclient index 2126086..8b8fcdd 160000 --- a/libicclient +++ b/libicclient @@ -1 +1 @@ -Subproject commit 212608669c44c24462d803dc238ed21e899c2b9f +Subproject commit 8b8fcdd17bf243440f52bd74e447afcface8b107 diff --git a/qicclient.pro b/qicclient.pro index 35d02f8..7adb82e 100644 --- a/qicclient.pro +++ b/qicclient.pro @@ -3,8 +3,10 @@ TEMPLATE = lib CONFIG += staticlib HEADERS += \ + qicclient/catalog.hxx \ qicclient/client.hxx SOURCES += \ + catalog.cxx \ client.cxx INCLUDEPATH += $$PWD/libicclient LIBS += $$PWD/libicclient/libicclient.a diff --git a/qicclient/catalog.hxx b/qicclient/catalog.hxx new file mode 100644 index 0000000..07b4c81 --- /dev/null +++ b/qicclient/catalog.hxx @@ -0,0 +1,81 @@ +#ifndef QICCLIENT_CATALOG_HXX +#define QICCLIENT_CATALOG_HXX + +#include +#include +#include + +struct icclient_catalog; + +namespace ICClient { + + class Product + { + public: + Product(icclient_product* product) : m_sku{product->sku} + { + if (product->description) + m_description + = QString{product->description}; + if (product->comment) + m_comment = QString{product->comment}; + if (product->image) + m_image = QString{product->image}; + QLocale locale; + if (product->price) + m_price = locale.toCurrencyString + (product->price, "Rp"); + } + QString const& sku() const { return m_sku; } + QString const& description() const { return m_description; } + QString const& comment() const { return m_comment; } + QString const& image() const { return m_image; } + QString const& price() const { return m_price; } + + private: + QString m_sku; + QString m_description; + QString m_comment; + QString m_image; + QString m_price; + }; + + class Catalog : public QAbstractListModel + { + Q_OBJECT + + public: + enum ProductRoles { + SkuRole = Qt::UserRole + 1, + DescriptionRole, + CommentRole, + ImageRole, + PriceRole + }; + + explicit Catalog(QObject* parent = nullptr) + : QAbstractListModel{parent} {} + + int rowCount(QModelIndex const& parent + = QModelIndex()) const Q_DECL_OVERRIDE; + QVariant data(const QModelIndex& index + , int role = Qt::DisplayRole + ) const Q_DECL_OVERRIDE; + + signals: + void updated(); + + protected: + QHash roleNames() const Q_DECL_OVERRIDE; + + private slots: + void update(icclient_catalog* catalog); + + private: + QList products; + void addProduct(Product const& product); + }; + +} + +#endif // QICCLIENT_CATALOG_HXX -- cgit v1.2.3 From 3fdde5e115af1edf084a81ead04adbca49d39e88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=20=EA=A6=AB=EA=A6=B6=20=EA=A6=8F=EA=A7=80?= =?UTF-8?q?=EA=A6=A6=EA=A6=BF=20=EA=A6=A7=20=EA=A6=AE=20=EA=A6=91=20?= =?UTF-8?q?=EA=A6=A9=20=EA=A6=AD=EA=A7=80?= Date: Thu, 26 Sep 2019 22:04:11 +0800 Subject: All products related signal and slot --- client.cxx | 9 +++++++++ qicclient/client.hxx | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/client.cxx b/client.cxx index f9cf9b2..00f0712 100644 --- a/client.cxx +++ b/client.cxx @@ -13,6 +13,15 @@ namespace ICClient { icclient_cleanup(); } + void productAll(icclient_catalog** catalogptr + , size_t (*callback)(void* contents + , size_t size, size_t nmemb + , void* userdata)) + { + icclient_product_all(catalogptr, callback); + emit gotProductAll(*catalogptr); + } + void Client::logIn(QString const& username, QString const& password) { icclient_login(username.toLatin1().constData() diff --git a/qicclient/client.hxx b/qicclient/client.hxx index 14c3652..481f9bb 100644 --- a/qicclient/client.hxx +++ b/qicclient/client.hxx @@ -2,6 +2,9 @@ #define QRTCLIENT_CLIENT_HXX #include +#include + +struct icclient_catalog; namespace ICClient { @@ -13,11 +16,17 @@ namespace ICClient { Client(char const* url, char const* certificate = nullptr); ~Client(); + void productAll(icclient_catalog** catalogptr + , size_t (*callback)(void* contents + , size_t size, size_t nmemb + , void* userdata)); + public slots: void logIn(QString const& username, QString const& password); void logOut(); signals: + void gotProductAll(icclient_catalog*); void loggedIn(QString const& username); void loggedOut(); }; -- cgit v1.2.3 From 721cffc4488b27497b94d8e5bdaf84510f5cfa2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=20=EA=A6=AB=EA=A6=B6=20=EA=A6=8F=EA=A7=80?= =?UTF-8?q?=EA=A6=A6=EA=A6=BF=20=EA=A6=A7=20=EA=A6=AE=20=EA=A6=91=20?= =?UTF-8?q?=EA=A6=A9=20=EA=A6=AD=EA=A7=80?= Date: Thu, 26 Sep 2019 22:12:53 +0800 Subject: Fix scope --- client.cxx | 6 ++---- qicclient/client.hxx | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/client.cxx b/client.cxx index 00f0712..0443ce3 100644 --- a/client.cxx +++ b/client.cxx @@ -13,10 +13,8 @@ namespace ICClient { icclient_cleanup(); } - void productAll(icclient_catalog** catalogptr - , size_t (*callback)(void* contents - , size_t size, size_t nmemb - , void* userdata)) + void Client::productAll(icclient_catalog** catalogptr + , size_t (*callback)(void*, size_t, size_t, void*)) { icclient_product_all(catalogptr, callback); emit gotProductAll(*catalogptr); diff --git a/qicclient/client.hxx b/qicclient/client.hxx index 481f9bb..27ba2af 100644 --- a/qicclient/client.hxx +++ b/qicclient/client.hxx @@ -26,7 +26,7 @@ namespace ICClient { void logOut(); signals: - void gotProductAll(icclient_catalog*); + void gotProductAll(icclient_catalog* catalog); void loggedIn(QString const& username); void loggedOut(); }; -- cgit v1.2.3 From a1892e161693409406d7ce06c977699a06e61920 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=20=EA=A6=AB=EA=A6=B6=20=EA=A6=8F=EA=A7=80?= =?UTF-8?q?=EA=A6=A6=EA=A6=BF=20=EA=A6=A7=20=EA=A6=AE=20=EA=A6=91=20?= =?UTF-8?q?=EA=A6=A9=20=EA=A6=AD=EA=A7=80?= Date: Thu, 26 Sep 2019 22:13:22 +0800 Subject: More specific on ignored files --- .gitignore | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 7e40417..19963cb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,7 @@ -*.a -*.pro.user -*.o -*.qmake.stash -*.so* -*.swp +libqicclient.a Makefile moc_* +*.o +qicclient.pro.user +.qmake.stash +*.swp -- cgit v1.2.3