diff options
author | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2023-03-13 13:17:33 +0800 |
---|---|---|
committer | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2023-03-13 13:17:33 +0800 |
commit | 76e22f15b9f7eb9227d6ba32198ea1f5464664e5 (patch) | |
tree | dc01ee71aff3542ee2b2a608fa32e763c75c8278 | |
parent | 3bb1e0c14ac7adccadfb71aba33cf2fb54e91850 (diff) |
Member data init from C struct is at constructor
with a copy, and the need to keep a pointer to the C struct is no
more.
-rw-r--r-- | interchange/member.hxx | 6 | ||||
-rw-r--r-- | interchange/ord.hxx | 2 | ||||
-rw-r--r-- | member.cxx | 169 | ||||
-rw-r--r-- | ord.cxx | 46 |
4 files changed, 112 insertions, 111 deletions
diff --git a/interchange/member.hxx b/interchange/member.hxx index 897b086..3f00dba 100644 --- a/interchange/member.hxx +++ b/interchange/member.hxx @@ -33,6 +33,8 @@ namespace QInterchange { public: explicit Member(QObject* parent = nullptr); + explicit Member(struct interchange_member member, + QObject* parent = nullptr); ~Member() {} QString const& userName() const { return m_userName; } @@ -54,7 +56,6 @@ namespace QInterchange { 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); @@ -75,7 +76,6 @@ namespace QInterchange { void setCountry(QString const& country); void setPhoneDay(QString const& phoneDay); void setEmail(QString const& email); - void setData(interchange_member* data); public slots: void newAccount(QString const& username, @@ -151,9 +151,7 @@ namespace QInterchange { QString m_country; QString m_phoneDay; QString m_email; - interchange_member* m_data; }; - } #endif diff --git a/interchange/ord.hxx b/interchange/ord.hxx index 4ec06b4..985f923 100644 --- a/interchange/ord.hxx +++ b/interchange/ord.hxx @@ -45,7 +45,7 @@ namespace QInterchange { void setProfile(QString const& profile); public slots: // void remove(unsigned int const& indices); - void checkout(Member& member); + void checkout(const Member& member); signals: void rowCountChanged(); void subtotalChanged(); @@ -8,6 +8,69 @@ namespace QInterchange { static char *unCopy, *pwCopy, *vCopy, *npCopy, *fpCopy; static interchange_member* mPtr; + Member::Member(interchange_member data, QObject* parent) : + QObject{parent} + { + member = this; + + if (data.username) m_userName = QString{data.username}; + else setUserName(""); + + if (data.usernick) m_userNick = QString{data.usernick}; + else setUserNick(""); + + if (data.password) m_password = QString{data.password}; + else setPassword(""); + + if (data.expiration) m_expiration = QString{data.expiration}; + else setExpiration(""); + + if (data.acl) m_acl = QString{data.acl}; + else setAcl(""); + + if (data.mod_time) m_modTime = QString{data.mod_time}; + else setModTime(""); + + if (data.s_nickname) m_sNickName = QString{data.s_nickname}; + else setSNickName(""); + + if (data.company) m_company = QString{data.company}; + else setCompany(""); + + if (data.fname) m_fName = QString{data.fname}; + else setFName(""); + + if (data.lname) m_lName = QString{data.lname}; + else setLName(""); + + if (data.address1) m_address1 = QString{data.address1}; + else setAddress1(""); + + if (data.address2) m_address2 = QString{data.address2}; + else setAddress2(""); + + if (data.address3) m_address3 = QString{data.address3}; + else setAddress3(""); + + if (data.city) m_city = QString{data.city}; + else setCity(""); + + if (data.state) m_state = QString{data.state}; + else setState(""); + + if (data.zip) m_zip = QString{data.zip}; + else setZip(""); + + if (data.country) m_country = QString{data.country}; + else setCountry(""); + + if (data.phone_day) m_phoneDay = QString{data.phone_day}; + else setPhoneDay(""); + + if (data.email) m_email = QString{data.email}; + else setEmail(""); + } + Member::Member(QObject* parent) : QObject{parent}, m_userName{""}, @@ -28,8 +91,7 @@ namespace QInterchange { m_zip{""}, m_country{""}, m_phoneDay{""}, - m_email{""}, - m_data{nullptr} + m_email{""} { member = this; } @@ -300,106 +362,6 @@ namespace QInterchange { } } - void Member::setData(interchange_member* data) - { - if (data && data->username && m_userName != data->username) { - m_userName = QString{data->username}; - emit userNameChanged(); - } else setUserName(""); - - if (data && data->usernick && m_userNick != data->usernick) { - m_userNick = QString{data->usernick}; - emit userNickChanged(); - } else setUserNick(""); - - if (data && data->password && m_password != data->password) { - m_password = QString{data->password}; - emit passwordChanged(); - } else setPassword(""); - - if (data && data->expiration && m_expiration != data->expiration) { - m_expiration = QString{data->expiration}; - emit expirationChanged(); - } else setExpiration(""); - - if (data && data->acl && m_acl != data->acl) { - m_acl = QString{data->acl}; - emit aclChanged(); - } else setAcl(""); - - if (data && data->mod_time && m_modTime != data->mod_time) { - m_modTime = QString{data->mod_time}; - emit modTimeChanged(); - } else setModTime(""); - - if (data && data->s_nickname && m_sNickName != data->s_nickname) { - m_sNickName = QString{data->s_nickname}; - emit sNickNameChanged(); - } else setSNickName(""); - - if (data && data->company && m_company != data->company) { - m_company = QString{data->company}; - emit companyChanged(); - } else setCompany(""); - - if (data && data->fname && m_fName != data->fname) { - m_fName = QString{data->fname}; - emit fNameChanged(); - } else setFName(""); - - if (data && data->lname && m_lName != data->lname) { - m_lName = QString{data->lname}; - emit lNameChanged(); - } else setLName(""); - - if (data && data->address1 && m_address1 != data->address1) { - m_address1 = QString{data->address1}; - emit address1Changed(); - } else setAddress1(""); - - if (data && data->address2 && m_address2 != data->address2) { - m_address2 = QString{data->address2}; - emit address2Changed(); - } else setAddress2(""); - - if (data && data->address3 && m_address3 != data->address3) { - m_address3 = QString{data->address3}; - emit address3Changed(); - } else setAddress3(""); - - if (data && data->city && m_city != data->city) { - m_city = QString{data->city}; - emit cityChanged(); - } else setCity(""); - - if (data && data->state && m_state != data->state) { - m_state = QString{data->state}; - emit stateChanged(); - } else setState(""); - - if (data && data->zip && m_zip != data->zip) { - m_zip = QString{data->zip}; - emit zipChanged(); - } else setZip(""); - - if (data && data->country && m_country != data->country) { - m_country = QString{data->country}; - emit countryChanged(); - } else setCountry(""); - - if (data && data->phone_day && m_phoneDay != data->phone_day) { - m_phoneDay = QString{data->phone_day}; - emit phoneDayChanged(); - } else setPhoneDay(""); - - if (data && data->email && m_email != data->email) { - m_email = QString{data->email}; - emit emailChanged(); - } else setEmail(""); - - if (m_data != data) m_data = data; - } - void Member::account() { interchange_member_account([](interchange_response* response) { @@ -418,8 +380,7 @@ namespace QInterchange { void Member::logOut() { - interchange_member_logout(m_data); - setData(nullptr); + interchange_member_logout(); } void Member::emitCreation(QString const& response) @@ -7,6 +7,7 @@ namespace QInterchange { static Ord* ord; static char* order_profile; + static interchange_member* mPtr; Ord::Ord(struct interchange_ord_order order, QObject* parent) : QAbstractListModel{parent} @@ -83,12 +84,53 @@ namespace QInterchange { if (this->profile != profile) this->profile = profile; } - void Ord::checkout(Member& member) + void Ord::checkout(const Member& member) { order_profile = (char*)malloc(profile.size() + 1); strcpy(order_profile, profile.toLatin1().constData()); - interchange_ord_checkout(order_profile, member.data(), + + auto fname = (char*)malloc(member.fName().size() + 1); + strcpy(fname, member.fName().toLatin1().constData()); + auto lname = (char*)malloc(member.lName().size() + 1); + strcpy(lname, member.lName().toLatin1().constData()); + auto address1 = (char*)malloc(member.address1().size() + 1); + strcpy(address1, member.address1().toLatin1().constData()); + auto address2 = (char*)malloc(member.address2().size() + 1); + strcpy(address2, member.address1().toLatin1().constData()); + auto city = (char*)malloc(member.city().size() + 1); + strcpy(city, member.city().toLatin1().constData()); + auto state = (char*)malloc(member.state().size() + 1); + strcpy(state, member.state().toLatin1().constData()); + auto zip = (char*)malloc(member.zip().size() + 1); + strcpy(zip, member.zip().toLatin1().constData()); + auto phone_day = (char*)malloc(member.phoneDay().size() + 1); + strcpy(phone_day, member.phoneDay().toLatin1().constData()); + auto email = (char*)malloc(member.email().size() + 1); + strcpy(email, member.email().toLatin1().constData()); + interchange_member m { + .fname = fname, + .lname = lname, + .address1 = address1, + .address2 = address2, + .city = city, + .state = state, + .zip = zip, + .phone_day = phone_day, + .email = email + }; + mPtr = &m; + + interchange_ord_checkout(order_profile, mPtr, [](interchange_response* response) { + free(mPtr->fname); + free(mPtr->lname); + free(mPtr->address1); + free(mPtr->address2); + free(mPtr->city); + free(mPtr->state); + free(mPtr->zip); + free(mPtr->phone_day); + free(mPtr->email); free(order_profile); ord->emitTransaction(QString{response->data}); interchange_free_response(response); |