From 18508ea004a66cc30c42c43d14afdc16b2267666 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: Sun, 25 Sep 2022 10:55:36 +0800 Subject: Rename project to qinterchange --- CMakeLists.txt | 14 ++--- Doxyfile | 6 +- README.md | 6 +- admin.cxx | 22 +++---- catalog.cxx | 8 +-- client.cxx | 82 ------------------------- interchange.cxx | 82 +++++++++++++++++++++++++ interchange.hxx | 78 ++++++++++++++++++++++++ interchange/admin.hxx | 64 +++++++++++++++++++ interchange/catalog.hxx | 34 +++++++++++ interchange/member.hxx | 159 ++++++++++++++++++++++++++++++++++++++++++++++++ interchange/ord.hxx | 71 +++++++++++++++++++++ interchange/product.hxx | 63 +++++++++++++++++++ member.cxx | 20 +++--- ord.cxx | 8 +-- qicclient.hxx | 78 ------------------------ qicclient/admin.hxx | 64 ------------------- qicclient/catalog.hxx | 34 ----------- qicclient/member.hxx | 159 ------------------------------------------------ qicclient/ord.hxx | 71 --------------------- qicclient/product.hxx | 63 ------------------- 21 files changed, 593 insertions(+), 593 deletions(-) delete mode 100644 client.cxx create mode 100644 interchange.cxx create mode 100644 interchange.hxx create mode 100644 interchange/admin.hxx create mode 100644 interchange/catalog.hxx create mode 100644 interchange/member.hxx create mode 100644 interchange/ord.hxx create mode 100644 interchange/product.hxx delete mode 100644 qicclient.hxx delete mode 100644 qicclient/admin.hxx delete mode 100644 qicclient/catalog.hxx delete mode 100644 qicclient/member.hxx delete mode 100644 qicclient/ord.hxx delete mode 100644 qicclient/product.hxx diff --git a/CMakeLists.txt b/CMakeLists.txt index 0535438..a950ce7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.5) -project(qicclient) +project(interchange) set(CMAKE_AUTOMOC ON) find_package(Qt5Core) set(HDRS @@ -12,7 +12,7 @@ set(HDRS set(SRCS ${PROJECT_NAME}.hxx ${HDRS} - client.cxx + interchange.cxx catalog.cxx ord.cxx member.cxx @@ -23,15 +23,15 @@ if (CMAKE_SYSTEM_NAME MATCHES "FreeBSD") link_directories(/usr/local/lib) endif() if (EMSCRIPTEN OR IOS) - add_library(${PROJECT_NAME} STATIC ${SRCS}) + add_library(q${PROJECT_NAME} STATIC ${SRCS}) else() - add_library(${PROJECT_NAME} SHARED ${SRCS}) + add_library(q${PROJECT_NAME} SHARED ${SRCS}) endif() -target_link_libraries(${PROJECT_NAME} +target_link_libraries(q${PROJECT_NAME} Qt5::Core - icclient + interchange ) include(GNUInstallDirs) -install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}) +install(TARGETS q${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}) install(FILES ${PROJECT_NAME}.hxx DESTINATION include) install(FILES ${HDRS} DESTINATION include/${PROJECT_NAME}) diff --git a/Doxyfile b/Doxyfile index 7c08d38..5a2f2e7 100644 --- a/Doxyfile +++ b/Doxyfile @@ -32,7 +32,7 @@ DOXYFILE_ENCODING = UTF-8 # title of most generated pages and in a few other places. # The default value is: My Project. -PROJECT_NAME = qicclient +PROJECT_NAME = qinterchange # The PROJECT_NUMBER tag can be used to enter a project or revision number. This # could be handy for archiving the generated documentation or if some version @@ -829,8 +829,8 @@ WARN_LOGFILE = # spaces. See also FILE_PATTERNS and EXTENSION_MAPPING # Note: If this tag is empty the current directory is searched. -INPUT = qicclient.hxx \ - qicclient \ +INPUT = interchange.hxx \ + interchange \ README.md # This tag can be used to specify the character encoding of the source files diff --git a/README.md b/README.md index c90d9fe..da2655b 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -# Qt Core wrapper for [libicclient](http://darapsa.org/libicclient) +# Qt Core wrapper for [libinterchange](http://darapsa.org/libinterchange) # Building ## Getting ```sh -$ git clone git://darapsa.org/qicclient.git -$ cd qicclient +$ git clone git://darapsa.org/qinterchange.git +$ cd qinterchange $ mkdir build && cd build ``` diff --git a/admin.cxx b/admin.cxx index 2cbd7ae..48e64a1 100644 --- a/admin.cxx +++ b/admin.cxx @@ -1,8 +1,8 @@ -#include -#include -#include "qicclient/admin.hxx" +#include +#include +#include "interchange/admin.hxx" -namespace QICClient { +namespace Interchange { static char *unCopy, *pwCopy; @@ -14,10 +14,10 @@ namespace QICClient { auto pwData = password.toLatin1().constData(); pwCopy = (char*)malloc(strlen(pwData) + 1); strcpy(pwCopy, pwData); - icclient_admin_login(unCopy, pwCopy, [](icclient_response* response) { + interchange_admin_login(unCopy, pwCopy, [](interchange_response* response) { free(unCopy); free(pwCopy); - icclient_free_response(response); + interchange_free_response(response); }, nullptr); } @@ -50,7 +50,7 @@ namespace QICClient { } } - void Admin::setData(icclient_admin* data) + void Admin::setData(interchange_admin* data) { if (data && data->username && m_userName != data->username) { m_userName = QString{data->username}; @@ -74,22 +74,22 @@ namespace QICClient { } void Admin::newAdmin(QString const& userName, QString const& password, QString const& name, bool super, - enum icclient_admin_group group) + enum interchange_admin_group group) { - icclient_admin_new_admin(userName.toLatin1().constData(), password.toLatin1().constData(), + interchange_admin_new_admin(userName.toLatin1().constData(), password.toLatin1().constData(), name.toLatin1().constData(), super, group, nullptr); } void Admin::newItem(QString const& description, QString const& comment, QString const& price, QString const& imagePath) { - icclient_admin_new_item(description.toLatin1().constData(), comment.toLatin1().constData(), + interchange_admin_new_item(description.toLatin1().constData(), comment.toLatin1().constData(), price.toLatin1().constData(), imagePath.toLatin1().constData(), nullptr); } void Admin::logOut() { - icclient_admin_logout(m_data, nullptr); + interchange_admin_logout(m_data, nullptr); setData(nullptr); } diff --git a/catalog.cxx b/catalog.cxx index 2cee7c2..244544c 100644 --- a/catalog.cxx +++ b/catalog.cxx @@ -1,9 +1,9 @@ #include -#include "qicclient/catalog.hxx" +#include "interchange/catalog.hxx" -namespace QICClient { +namespace Interchange { - Catalog::Catalog(struct icclient_catalog* catalog, QObject* parent) : + Catalog::Catalog(struct interchange_catalog* catalog, QObject* parent) : QAbstractListModel{parent}, m_data{catalog} { @@ -12,7 +12,7 @@ namespace QICClient { Catalog::~Catalog() { - icclient_free_catalog(m_data); + interchange_free_catalog(m_data); } int Catalog::rowCount(QModelIndex const& parent) const diff --git a/client.cxx b/client.cxx deleted file mode 100644 index 28a97fb..0000000 --- a/client.cxx +++ /dev/null @@ -1,82 +0,0 @@ -#include "qicclient.hxx" -#include "qicclient/ord.hxx" - -namespace QICClient { - - static Client* client; - - Client::Client(char const* sampleURL, char const* image_Dir, char const* certificate) - { - client = this; - icclient_init(sampleURL, image_Dir, certificate); - } - - Client::~Client() - { - icclient_cleanup(); - } - - void Client::catalog(QString const& prodGroup) - { - icclient_catalog(prodGroup.toLatin1().constData(), [](icclient_response* response) { - client->emitCatalog(QString{response->data}); - icclient_free_response(response); - }, nullptr); - } - - void Client::allProducts() - { - catalog("All-Products"); - } - - void Client::product(QString const& sku) - { - icclient_product(sku.toLatin1().constData(), [](icclient_response* response) { - client->emitProduct(QString{response->data}); - icclient_free_response(response); - }, nullptr); - } - - void Client::page(QString const& path) - { - icclient_page(path.toLatin1().constData(), [](icclient_response* response) { - client->emitPage(QString{response->data}); - icclient_free_response(response); - }); - } - - void Client::defaultCatalog(QString const& prodGroup) - { - icclient_catalog(prodGroup.toLatin1().constData(), nullptr, [](struct icclient_catalog* catalog) { - icclient_free_catalog(catalog); - }); - } - - void Client::defaultAllProducts() - { - defaultCatalog("All-Products"); - } - - void Client::emitCatalog(QString const& response) - { - emit gotCatalog(response); - } - - void Client::emitProduct(QString const& response) - { - emit gotProduct(response); - } - - void Client::emitPage(QString const& response) - { - emit gotPage(response); - } - - 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); - order.setData(c_order); - } - -} 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); + } + +} diff --git a/interchange.hxx b/interchange.hxx new file mode 100644 index 0000000..e25a32c --- /dev/null +++ b/interchange.hxx @@ -0,0 +1,78 @@ +#ifndef INTERCHANGE_HXX +#define INTERCHANGE_HXX + +#include +#include "interchange/catalog.hxx" + +namespace Interchange { + + class Ord; + + class Interchange : public QObject + { + Q_OBJECT + + public: + /*! + * \brief Constructor. + * \param sampleURL The value of the SAMPLEURL setting in products/variable.txt. + * \param image_Dir The value of the IMAGE_DIR setting in products/variable.txt. + * \param certificate Path to the CA certificate file. + */ + Interchange(char const* sampleURL, char const* image_Dir, char const* certificate = nullptr); + /*! + * \brief Destructor. + */ + ~Interchange(); + /*! + * \brief For putting an item to a cart. + * \param sku The SKU of the item to order. + * \param catalog The catalog from which the item is. + * \param order The order. + */ + 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 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 data from a specific path. + * \param path The path. + */ + void page(QString const& path); + /*! + * \brief For fetching products that belong a specific group. + * \param prodGroup The name of the product group. + */ + void defaultCatalog(QString const& prodGroup); + /*! + * \brief For fetching data about all active products. + */ + void defaultAllProducts(); + + signals: + void gotCatalog(QString const& response); + void gotProduct(QString const& response); + void gotPage(QString const& response); + + protected: + void emitCatalog(QString const& response); + void emitProduct(QString const& response); + void emitPage(QString const& response); + }; + +} + +#endif diff --git a/interchange/admin.hxx b/interchange/admin.hxx new file mode 100644 index 0000000..3a800ac --- /dev/null +++ b/interchange/admin.hxx @@ -0,0 +1,64 @@ +#ifndef INTERCHANGE_ADMIN_HXX +#define INTERCHANGE_ADMIN_HXX + +#include +#include + +struct interchange_admin; + +namespace Interchange { + + class Admin : public QObject + { + Q_OBJECT + Q_PROPERTY(QString userName READ userName WRITE setUserName NOTIFY userNameChanged) + Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged) + Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) + Q_PROPERTY(bool super READ super WRITE setSuper NOTIFY superChanged) + + public: + explicit Admin(QObject* parent = nullptr) : + QObject{parent}, + m_userName{""}, + m_password{""}, + m_name{""}, + m_super{false}, + m_data{nullptr} + {} + ~Admin() {} + QString const& userName() const { return m_userName; } + QString const& password() const { return m_password; } + QString const& name() const { return m_name; } + bool super() { return m_super; } + + void setUserName(QString const& userName); + void setPassword(QString const& password); + void setName(QString const& name); + void setSuper(bool super); + + public slots: + void logIn(QString const& username, QString const& password); + void newAdmin(QString const& userName, QString const& password, QString const& name, bool super, + enum interchange_admin_group group); + void newItem(QString const& description, QString const& comment, QString const& price, + QString const& imagePath); + void logOut(); + + signals: + void userNameChanged(); + void passwordChanged(); + void nameChanged(); + void superChanged(); + + private: + QString m_userName; + QString m_password; + QString m_name; + bool m_super; + interchange_admin* m_data; + inline void setData(interchange_admin* data); + }; + +} + +#endif diff --git a/interchange/catalog.hxx b/interchange/catalog.hxx new file mode 100644 index 0000000..8946113 --- /dev/null +++ b/interchange/catalog.hxx @@ -0,0 +1,34 @@ +#ifndef INTERCHANGE_CATALOG_HXX +#define INTERCHANGE_CATALOG_HXX + +#include +#include "product.hxx" + +struct interchange_catalog; + +namespace Interchange { + + class Catalog : public QAbstractListModel + { + Q_OBJECT + + public: + Catalog(QObject* parent = nullptr) : QAbstractListModel{parent} {} + Catalog(struct interchange_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; + struct interchange_catalog const* constData() const { return m_data; } + + protected: + QHash roleNames() const Q_DECL_OVERRIDE; + + private: + void addProduct(Product const& product); + QList products; + struct interchange_catalog* m_data; + }; + +} + +#endif diff --git a/interchange/member.hxx b/interchange/member.hxx new file mode 100644 index 0000000..d4b1836 --- /dev/null +++ b/interchange/member.hxx @@ -0,0 +1,159 @@ +#ifndef INTERCHANGE_MEMBER_HXX +#define INTERCHANGE_MEMBER_HXX + +#include +#include + +struct interchange_member; + +namespace Interchange { + + class Member : public QObject + { + Q_OBJECT + Q_PROPERTY(QString userName READ userName WRITE setUserName NOTIFY userNameChanged) + Q_PROPERTY(QString userNick READ userNick WRITE setUserNick NOTIFY userNickChanged) + Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged) + Q_PROPERTY(QString expiration READ expiration WRITE setExpiration NOTIFY expirationChanged) + Q_PROPERTY(QString acl READ acl WRITE setAcl NOTIFY aclChanged) + Q_PROPERTY(QString modTime READ modTime WRITE setModTime NOTIFY modTimeChanged) + Q_PROPERTY(QString sNickName READ sNickName WRITE setSNickName NOTIFY sNickNameChanged) + Q_PROPERTY(QString company READ company WRITE setCompany NOTIFY companyChanged) + Q_PROPERTY(QString fName READ fName WRITE setFName NOTIFY fNameChanged) + Q_PROPERTY(QString lName READ lName WRITE setLName NOTIFY lNameChanged) + Q_PROPERTY(QString address1 READ address1 WRITE setAddress1 NOTIFY address1Changed) + Q_PROPERTY(QString address2 READ address2 WRITE setAddress2 NOTIFY address2Changed) + Q_PROPERTY(QString address3 READ address3 WRITE setAddress3 NOTIFY address3Changed) + Q_PROPERTY(QString city READ city WRITE setCity NOTIFY cityChanged) + Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged) + Q_PROPERTY(QString zip READ zip WRITE setZip NOTIFY zipChanged) + Q_PROPERTY(QString country READ country WRITE setCountry NOTIFY countryChanged) + Q_PROPERTY(QString phoneDay READ phoneDay WRITE setPhoneDay NOTIFY phoneDayChanged) + Q_PROPERTY(QString email READ email WRITE setEmail NOTIFY emailChanged) + + public: + explicit Member(QObject* parent = nullptr) : + QObject{parent}, + m_userName{""}, + m_userNick{""}, + m_password{""}, + m_expiration{""}, + m_acl{""}, + m_modTime{""}, + m_sNickName{""}, + m_company{""}, + m_fName{""}, + m_lName{""}, + m_address1{""}, + m_address2{""}, + m_address3{""}, + m_city{""}, + m_state{""}, + m_zip{""}, + m_country{""}, + m_phoneDay{""}, + m_email{""}, + m_data{nullptr} + {} + ~Member() {} + + QString const& userName() const { return m_userName; } + QString const& userNick() const { return m_userNick; } + QString const& password() const { return m_password; } + QString const& expiration() const { return m_expiration; } + QString const& acl() const { return m_acl; } + QString const& modTime() const { return m_modTime; } + QString const& sNickName() const { return m_sNickName; } + QString const& company() const { return m_company; } + QString const& fName() const { return m_fName; } + QString const& lName() const { return m_lName; } + QString const& address1() const { return m_address1; } + QString const& address2() const { return m_address2; } + QString const& address3() const { return m_address3; } + QString const& city() const { return m_city; } + QString const& state() const { return m_state; } + QString const& zip() const { return m_zip; } + QString const& country() const { return m_country; } + QString const& phoneDay() const { return m_phoneDay; } + QString const& email() const { return m_email; } + interchange_member* data() { return m_data; } + + void setUserName(QString const& userName); + void setUserNick(QString const& userNick); + void setPassword(QString const& password); + void setExpiration(QString const& expiration); + void setAcl(QString const& acl); + void setModTime(QString const& modTime); + void setSNickName(QString const& sNickName); + void setCompany(QString const& company); + void setFName(QString const& fName); + void setLName(QString const& lName); + void setAddress1(QString const& address1); + void setAddress2(QString const& address2); + void setAddress3(QString const& address3); + void setCity(QString const& city); + void setState(QString const& state); + void setZip(QString const& zip); + void setCountry(QString const& country); + void setPhoneDay(QString const& phoneDay); + void setEmail(QString const& email); + + public slots: + void logIn(QString const& username, QString const& password); + void account(QString const& firstName, QString const& lastName, + QString const& address1, QString const& address2, + QString const& city, QString const& state, + QString const& zip, QString const& email, + QString const& phoneDay); + void changePassword(QString const& passwordOld, + QString const& password, QString const& verify); + void logOut(); + + signals: + void userNameChanged(); + void userNickChanged(); + void passwordChanged(); + void expirationChanged(); + void aclChanged(); + void modTimeChanged(); + void sNickNameChanged(); + void companyChanged(); + void fNameChanged(); + void lNameChanged(); + void address1Changed(); + void address2Changed(); + void address3Changed(); + void cityChanged(); + void stateChanged(); + void zipChanged(); + void countryChanged(); + void phoneDayChanged(); + void emailChanged(); + + private: + QString m_userName; + QString m_userNick; + QString m_password; + QString m_expiration; + QString m_acl; + QString m_modTime; + QString m_sNickName; + QString m_company; + QString m_fName; + QString m_lName; + QString m_address1; + QString m_address2; + QString m_address3; + QString m_city; + QString m_state; + QString m_zip; + QString m_country; + QString m_phoneDay; + QString m_email; + interchange_member* m_data; + inline void setData(interchange_member* data); + }; + +} + +#endif diff --git a/interchange/ord.hxx b/interchange/ord.hxx new file mode 100644 index 0000000..afe77cc --- /dev/null +++ b/interchange/ord.hxx @@ -0,0 +1,71 @@ +#ifndef INTERCHANGE_ORD_HXX +#define INTERCHANGE_ORD_HXX + +#include +#include +#include "member.hxx" +#include "product.hxx" + +namespace Interchange { + + struct Item + { + enum ItemRoles { + QuantityRole = Product::PriceRole + 1 + }; + Item(interchange_ord_item* item) : + product{item->product}, + quantity{item->quantity} {} + Product product; + unsigned int quantity; + bool operator==(Item const& item) + { + return product.sku == item.product.sku; + } + }; + + class Ord : public QAbstractListModel + { + Q_OBJECT + Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged) + Q_PROPERTY(double subtotal READ subtotal NOTIFY subtotalChanged) + Q_PROPERTY(double shipping READ shipping NOTIFY shippingChanged) + Q_PROPERTY(double totalCost READ totalCost NOTIFY totalCostChanged) + + public: + explicit Ord(QObject* parent = nullptr) : + QAbstractListModel{parent}, + m_data{nullptr}, + m_subtotal{.0}, + m_shipping{.0}, + m_totalCost{.0} {} + int rowCount(QModelIndex const& parent = QModelIndex()) const Q_DECL_OVERRIDE; + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const + Q_DECL_OVERRIDE; + struct interchange_ord_order* data() { return m_data; } + void setData(struct interchange_ord_order* order); + double subtotal() const { return m_subtotal; } + double shipping() const { return m_shipping; } + double totalCost() const { return m_totalCost; } + public slots: +// void remove(unsigned int const& indices); + void checkout(Member& member); + signals: + void rowCountChanged(); + void subtotalChanged(); + void shippingChanged(); + void totalCostChanged(); + protected: + QHash roleNames() const Q_DECL_OVERRIDE; + private: + void addItem(Item const& item); + QList items; + struct interchange_ord_order* m_data; + double m_subtotal; + double m_shipping; + double m_totalCost; + }; + +} + +#endif diff --git a/interchange/product.hxx b/interchange/product.hxx new file mode 100644 index 0000000..a7f3587 --- /dev/null +++ b/interchange/product.hxx @@ -0,0 +1,63 @@ +#ifndef INTERCHANGE_PRODUCT_HXX +#define INTERCHANGE_PRODUCT_HXX + +#include + +namespace Interchange { + + struct Product + { + enum ProductRoles { + SkuRole = Qt::UserRole + 1, + DescriptionRole, + CommentRole, + ThumbRole, + ImageRole, + PriceRole, + ProdGroupRole, + WeightRole, + AuthorRole, + CrossSellRole + }; + + Product() {} + Product(struct interchange_product* product) : + price{product->price}, + weight{product->weight} + { + if (product->sku) + sku = QString{product->sku}; + if (product->description) + description = QString{product->description}; + if (product->comment) + comment = QString{product->comment}; + if (product->thumb) + thumb = QString{product->thumb}; + if (product->image) + image = QString{product->image}; + if (product->prod_group) + prodGroup = QString{product->prod_group}; + if (product->author) + author = QString{product->author}; + if (product->crosssell) { + auto crosssell = product->crosssell; + for (size_t i = 0; i < crosssell->length; i++) + crossSell << QString{crosssell->skus[i]}; + } + } + + QString sku; + QString description; + QString comment; + QString thumb; + QString image; + double price; + QString prodGroup; + double weight; + QString author; + QStringList crossSell; + }; + +} + +#endif diff --git a/member.cxx b/member.cxx index fb473ea..6b11d53 100644 --- a/member.cxx +++ b/member.cxx @@ -1,8 +1,8 @@ -#include -#include -#include "qicclient/member.hxx" +#include +#include +#include "interchange/member.hxx" -namespace QICClient { +namespace Interchange { static char *unCopy, *pwCopy; @@ -14,10 +14,10 @@ namespace QICClient { auto pwData = password.toLatin1().constData(); pwCopy = (char*)malloc(strlen(pwData) + 1); strcpy(pwCopy, pwData); - icclient_member_login(unCopy, pwCopy, [](icclient_response* response) { + interchange_member_login(unCopy, pwCopy, [](interchange_response* response) { free(unCopy); free(pwCopy); - icclient_free_response(response); + interchange_free_response(response); }, nullptr); } @@ -173,7 +173,7 @@ namespace QICClient { } } - void Member::setData(icclient_member* data) + void Member::setData(interchange_member* data) { if (data && data->username && m_userName != data->username) { m_userName = QString{data->username}; @@ -278,7 +278,7 @@ namespace QICClient { QString const& city, QString const& state, QString const& zip, QString const& email, QString const& phoneDay) { - icclient_member_account(firstName.toLatin1().constData(), + interchange_member_account(firstName.toLatin1().constData(), lastName.toLatin1().constData(), address1.toLatin1().constData(), address2.toLatin1().constData(), @@ -290,14 +290,14 @@ namespace QICClient { void Member::changePassword(QString const& passwordOld, QString const& password, QString const& verify) { - icclient_member_changepassword(passwordOld.toLatin1().constData(), + interchange_member_changepassword(passwordOld.toLatin1().constData(), password.toLatin1().constData(), verify.toLatin1().constData()); } void Member::logOut() { - icclient_member_logout(m_data); + interchange_member_logout(m_data); setData(nullptr); } diff --git a/ord.cxx b/ord.cxx index 1de7447..1c103e8 100644 --- a/ord.cxx +++ b/ord.cxx @@ -1,8 +1,8 @@ #include #include -#include "qicclient/ord.hxx" +#include "interchange/ord.hxx" -namespace QICClient { +namespace Interchange { int Ord::rowCount(QModelIndex const& parent) const { @@ -60,7 +60,7 @@ namespace QICClient { emit rowCountChanged(); } - void Ord::setData(struct icclient_ord_order* order) + void Ord::setData(struct interchange_ord_order* order) { if (!order) return; this->m_data = order; @@ -73,6 +73,6 @@ namespace QICClient { void Ord::checkout(Member& member) { - icclient_ord_checkout(m_data, member.data()); + interchange_ord_checkout(m_data, member.data()); } } diff --git a/qicclient.hxx b/qicclient.hxx deleted file mode 100644 index e52145e..0000000 --- a/qicclient.hxx +++ /dev/null @@ -1,78 +0,0 @@ -#ifndef QICCLIENT_HXX -#define QICCLIENT_HXX - -#include -#include "qicclient/catalog.hxx" - -namespace QICClient { - - class Ord; - - class Client : public QObject - { - Q_OBJECT - - public: - /*! - * \brief Constructor. - * \param sampleURL The value of the SAMPLEURL setting in products/variable.txt. - * \param image_Dir The value of the IMAGE_DIR setting in products/variable.txt. - * \param certificate Path to the CA certificate file. - */ - Client(char const* sampleURL, char const* image_Dir, char const* certificate = nullptr); - /*! - * \brief Destructor. - */ - ~Client(); - /*! - * \brief For putting an item to a cart. - * \param sku The SKU of the item to order. - * \param catalog The catalog from which the item is. - * \param order The order. - */ - 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 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 data from a specific path. - * \param path The path. - */ - void page(QString const& path); - /*! - * \brief For fetching products that belong a specific group. - * \param prodGroup The name of the product group. - */ - void defaultCatalog(QString const& prodGroup); - /*! - * \brief For fetching data about all active products. - */ - void defaultAllProducts(); - - signals: - void gotCatalog(QString const& response); - void gotProduct(QString const& response); - void gotPage(QString const& response); - - protected: - void emitCatalog(QString const& response); - void emitProduct(QString const& response); - void emitPage(QString const& response); - }; - -} - -#endif diff --git a/qicclient/admin.hxx b/qicclient/admin.hxx deleted file mode 100644 index 34202a4..0000000 --- a/qicclient/admin.hxx +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef QICCLIENT_ADMIN_HXX -#define QICCLIENT_ADMIN_HXX - -#include -#include - -struct icclient_admin; - -namespace QICClient { - - class Admin : public QObject - { - Q_OBJECT - Q_PROPERTY(QString userName READ userName WRITE setUserName NOTIFY userNameChanged) - Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged) - Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) - Q_PROPERTY(bool super READ super WRITE setSuper NOTIFY superChanged) - - public: - explicit Admin(QObject* parent = nullptr) : - QObject{parent}, - m_userName{""}, - m_password{""}, - m_name{""}, - m_super{false}, - m_data{nullptr} - {} - ~Admin() {} - QString const& userName() const { return m_userName; } - QString const& password() const { return m_password; } - QString const& name() const { return m_name; } - bool super() { return m_super; } - - void setUserName(QString const& userName); - void setPassword(QString const& password); - void setName(QString const& name); - void setSuper(bool super); - - public slots: - void logIn(QString const& username, QString const& password); - void newAdmin(QString const& userName, QString const& password, QString const& name, bool super, - enum icclient_admin_group group); - void newItem(QString const& description, QString const& comment, QString const& price, - QString const& imagePath); - void logOut(); - - signals: - void userNameChanged(); - void passwordChanged(); - void nameChanged(); - void superChanged(); - - private: - QString m_userName; - QString m_password; - QString m_name; - bool m_super; - icclient_admin* m_data; - inline void setData(icclient_admin* data); - }; - -} - -#endif diff --git a/qicclient/catalog.hxx b/qicclient/catalog.hxx deleted file mode 100644 index 2c7274c..0000000 --- a/qicclient/catalog.hxx +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef QICCLIENT_CATALOG_HXX -#define QICCLIENT_CATALOG_HXX - -#include -#include "product.hxx" - -struct icclient_catalog; - -namespace QICClient { - - class Catalog : public QAbstractListModel - { - Q_OBJECT - - public: - Catalog(QObject* parent = nullptr) : QAbstractListModel{parent} {} - 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; - struct icclient_catalog const* constData() const { return m_data; } - - protected: - QHash roleNames() const Q_DECL_OVERRIDE; - - private: - void addProduct(Product const& product); - QList products; - struct icclient_catalog* m_data; - }; - -} - -#endif diff --git a/qicclient/member.hxx b/qicclient/member.hxx deleted file mode 100644 index 3d0e45f..0000000 --- a/qicclient/member.hxx +++ /dev/null @@ -1,159 +0,0 @@ -#ifndef QICCLIENT_MEMBER_HXX -#define QICCLIENT_MEMBER_HXX - -#include -#include - -struct icclient_member; - -namespace QICClient { - - class Member : public QObject - { - Q_OBJECT - Q_PROPERTY(QString userName READ userName WRITE setUserName NOTIFY userNameChanged) - Q_PROPERTY(QString userNick READ userNick WRITE setUserNick NOTIFY userNickChanged) - Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged) - Q_PROPERTY(QString expiration READ expiration WRITE setExpiration NOTIFY expirationChanged) - Q_PROPERTY(QString acl READ acl WRITE setAcl NOTIFY aclChanged) - Q_PROPERTY(QString modTime READ modTime WRITE setModTime NOTIFY modTimeChanged) - Q_PROPERTY(QString sNickName READ sNickName WRITE setSNickName NOTIFY sNickNameChanged) - Q_PROPERTY(QString company READ company WRITE setCompany NOTIFY companyChanged) - Q_PROPERTY(QString fName READ fName WRITE setFName NOTIFY fNameChanged) - Q_PROPERTY(QString lName READ lName WRITE setLName NOTIFY lNameChanged) - Q_PROPERTY(QString address1 READ address1 WRITE setAddress1 NOTIFY address1Changed) - Q_PROPERTY(QString address2 READ address2 WRITE setAddress2 NOTIFY address2Changed) - Q_PROPERTY(QString address3 READ address3 WRITE setAddress3 NOTIFY address3Changed) - Q_PROPERTY(QString city READ city WRITE setCity NOTIFY cityChanged) - Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged) - Q_PROPERTY(QString zip READ zip WRITE setZip NOTIFY zipChanged) - Q_PROPERTY(QString country READ country WRITE setCountry NOTIFY countryChanged) - Q_PROPERTY(QString phoneDay READ phoneDay WRITE setPhoneDay NOTIFY phoneDayChanged) - Q_PROPERTY(QString email READ email WRITE setEmail NOTIFY emailChanged) - - public: - explicit Member(QObject* parent = nullptr) : - QObject{parent}, - m_userName{""}, - m_userNick{""}, - m_password{""}, - m_expiration{""}, - m_acl{""}, - m_modTime{""}, - m_sNickName{""}, - m_company{""}, - m_fName{""}, - m_lName{""}, - m_address1{""}, - m_address2{""}, - m_address3{""}, - m_city{""}, - m_state{""}, - m_zip{""}, - m_country{""}, - m_phoneDay{""}, - m_email{""}, - m_data{nullptr} - {} - ~Member() {} - - QString const& userName() const { return m_userName; } - QString const& userNick() const { return m_userNick; } - QString const& password() const { return m_password; } - QString const& expiration() const { return m_expiration; } - QString const& acl() const { return m_acl; } - QString const& modTime() const { return m_modTime; } - QString const& sNickName() const { return m_sNickName; } - QString const& company() const { return m_company; } - QString const& fName() const { return m_fName; } - QString const& lName() const { return m_lName; } - QString const& address1() const { return m_address1; } - QString const& address2() const { return m_address2; } - QString const& address3() const { return m_address3; } - QString const& city() const { return m_city; } - QString const& state() const { return m_state; } - QString const& zip() const { return m_zip; } - QString const& country() const { return m_country; } - QString const& phoneDay() const { return m_phoneDay; } - QString const& email() const { return m_email; } - icclient_member* data() { return m_data; } - - void setUserName(QString const& userName); - void setUserNick(QString const& userNick); - void setPassword(QString const& password); - void setExpiration(QString const& expiration); - void setAcl(QString const& acl); - void setModTime(QString const& modTime); - void setSNickName(QString const& sNickName); - void setCompany(QString const& company); - void setFName(QString const& fName); - void setLName(QString const& lName); - void setAddress1(QString const& address1); - void setAddress2(QString const& address2); - void setAddress3(QString const& address3); - void setCity(QString const& city); - void setState(QString const& state); - void setZip(QString const& zip); - void setCountry(QString const& country); - void setPhoneDay(QString const& phoneDay); - void setEmail(QString const& email); - - public slots: - void logIn(QString const& username, QString const& password); - void account(QString const& firstName, QString const& lastName, - QString const& address1, QString const& address2, - QString const& city, QString const& state, - QString const& zip, QString const& email, - QString const& phoneDay); - void changePassword(QString const& passwordOld, - QString const& password, QString const& verify); - void logOut(); - - signals: - void userNameChanged(); - void userNickChanged(); - void passwordChanged(); - void expirationChanged(); - void aclChanged(); - void modTimeChanged(); - void sNickNameChanged(); - void companyChanged(); - void fNameChanged(); - void lNameChanged(); - void address1Changed(); - void address2Changed(); - void address3Changed(); - void cityChanged(); - void stateChanged(); - void zipChanged(); - void countryChanged(); - void phoneDayChanged(); - void emailChanged(); - - private: - QString m_userName; - QString m_userNick; - QString m_password; - QString m_expiration; - QString m_acl; - QString m_modTime; - QString m_sNickName; - QString m_company; - QString m_fName; - QString m_lName; - QString m_address1; - QString m_address2; - QString m_address3; - QString m_city; - QString m_state; - QString m_zip; - QString m_country; - QString m_phoneDay; - QString m_email; - icclient_member* m_data; - inline void setData(icclient_member* data); - }; - -} - -#endif diff --git a/qicclient/ord.hxx b/qicclient/ord.hxx deleted file mode 100644 index 5ece6de..0000000 --- a/qicclient/ord.hxx +++ /dev/null @@ -1,71 +0,0 @@ -#ifndef QICCLIENT_ORD_HXX -#define QICCLIENT_ORD_HXX - -#include -#include -#include "member.hxx" -#include "product.hxx" - -namespace QICClient { - - struct Item - { - enum ItemRoles { - QuantityRole = Product::PriceRole + 1 - }; - Item(icclient_ord_item* item) : - product{item->product}, - quantity{item->quantity} {} - Product product; - unsigned int quantity; - bool operator==(Item const& item) - { - return product.sku == item.product.sku; - } - }; - - class Ord : public QAbstractListModel - { - Q_OBJECT - Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged) - Q_PROPERTY(double subtotal READ subtotal NOTIFY subtotalChanged) - Q_PROPERTY(double shipping READ shipping NOTIFY shippingChanged) - Q_PROPERTY(double totalCost READ totalCost NOTIFY totalCostChanged) - - public: - explicit Ord(QObject* parent = nullptr) : - QAbstractListModel{parent}, - m_data{nullptr}, - m_subtotal{.0}, - m_shipping{.0}, - m_totalCost{.0} {} - int rowCount(QModelIndex const& parent = QModelIndex()) const Q_DECL_OVERRIDE; - QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const - Q_DECL_OVERRIDE; - struct icclient_ord_order* data() { return m_data; } - void setData(struct icclient_ord_order* order); - double subtotal() const { return m_subtotal; } - double shipping() const { return m_shipping; } - double totalCost() const { return m_totalCost; } - public slots: -// void remove(unsigned int const& indices); - void checkout(Member& member); - signals: - void rowCountChanged(); - void subtotalChanged(); - void shippingChanged(); - void totalCostChanged(); - protected: - QHash roleNames() const Q_DECL_OVERRIDE; - private: - void addItem(Item const& item); - QList items; - struct icclient_ord_order* m_data; - double m_subtotal; - double m_shipping; - double m_totalCost; - }; - -} - -#endif diff --git a/qicclient/product.hxx b/qicclient/product.hxx deleted file mode 100644 index 57f9641..0000000 --- a/qicclient/product.hxx +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef QICCLIENT_PRODUCT_HXX -#define QICCLIENT_PRODUCT_HXX - -#include - -namespace QICClient { - - struct Product - { - enum ProductRoles { - SkuRole = Qt::UserRole + 1, - DescriptionRole, - CommentRole, - ThumbRole, - ImageRole, - PriceRole, - ProdGroupRole, - WeightRole, - AuthorRole, - CrossSellRole - }; - - Product() {} - Product(struct icclient_product* product) : - price{product->price}, - weight{product->weight} - { - if (product->sku) - sku = QString{product->sku}; - if (product->description) - description = QString{product->description}; - if (product->comment) - comment = QString{product->comment}; - if (product->thumb) - thumb = QString{product->thumb}; - if (product->image) - image = QString{product->image}; - if (product->prod_group) - prodGroup = QString{product->prod_group}; - if (product->author) - author = QString{product->author}; - if (product->crosssell) { - auto crosssell = product->crosssell; - for (size_t i = 0; i < crosssell->length; i++) - crossSell << QString{crosssell->skus[i]}; - } - } - - QString sku; - QString description; - QString comment; - QString thumb; - QString image; - double price; - QString prodGroup; - double weight; - QString author; - QStringList crossSell; - }; - -} - -#endif -- cgit v1.2.3