summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Prabowo Kamal <erik@darapsa.co.id>2019-08-27 09:39:14 +0800
committerErik Prabowo Kamal <erik@darapsa.co.id>2019-08-27 09:39:14 +0800
commit0ede7b58b82b0f75369a42fa90c2d8d1f36ad763 (patch)
treec71ebaca2c18a1e65bac9d7f1895b4a1000351df
parentafdab77790e8db165b43e9ab34cb26313b067856 (diff)
User class
Qt wrapper on rt_user, plus the loggedIn attribute.
-rw-r--r--user.cxx187
-rw-r--r--user.hxx118
2 files changed, 305 insertions, 0 deletions
diff --git a/user.cxx b/user.cxx
new file mode 100644
index 0000000..0983874
--- /dev/null
+++ b/user.cxx
@@ -0,0 +1,187 @@
+#include "rtuser.h"
+#include "user.hxx"
+
+void User::update(rt_user* user)
+{
+ if (m_isLoggedIn) {
+ setName(QString{user->name});
+ setEmailAddress(QString{user->emailaddress});
+ setOrganization(QString{user->organization});
+ setRealName(QString{user->realname});
+ setNickName(QString{user->nickname});
+ setLang(QString{user->lang});
+ setHomePhone(QString{user->homephone});
+ setWorkPhone(QString{user->workphone});
+ setMobilePhone(QString{user->mobilephone});
+ setPagerPhone(QString{user->pagerphone});
+ setAddress1(QString{user->address1});
+ setAddress2(QString{user->address2});
+ setCity(QString{user->city});
+ setState(QString{user->state});
+ setZip(QString{user->zip});
+ setCountry(QString{user->country});
+ setTimeZone(QString{user->timezone});
+ } else {
+ setName("");
+ setEmailAddress("");
+ setOrganization("");
+ setRealName("");
+ setNickName("");
+ setLang("");
+ setHomePhone("");
+ setWorkPhone("");
+ setMobilePhone("");
+ setPagerPhone("");
+ setAddress1("");
+ setAddress2("");
+ setCity("");
+ setState("");
+ setZip("");
+ setCountry("");
+ setTimeZone("");
+ }
+}
+
+void User::setName(QString const& name)
+{
+ if (m_name != name) {
+ m_name = name;
+ emit nameChanged();
+ }
+}
+
+void User::setEmailAddress(QString const& emailAddress)
+{
+ if (m_emailAddress != emailAddress) {
+ m_emailAddress = emailAddress;
+ emit emailAddressChanged();
+ }
+}
+
+void User::setOrganization(QString const& organization)
+{
+ if (m_organization != organization) {
+ m_organization = organization;
+ emit organizationChanged();
+ }
+}
+
+void User::setRealName(QString const& realName)
+{
+ if (m_realName != realName) {
+ m_realName = realName;
+ emit realNameChanged();
+ }
+}
+
+void User::setNickName(QString const& nickName)
+{
+ if (m_nickName != nickName) {
+ m_nickName = nickName;
+ emit nickNameChanged();
+ }
+}
+
+void User::setLang(QString const& lang)
+{
+ if (m_lang != lang) {
+ m_lang = lang;
+ emit langChanged();
+ }
+}
+
+void User::setHomePhone(QString const& homePhone)
+{
+ if (m_homePhone != homePhone) {
+ m_homePhone = homePhone;
+ emit homePhoneChanged();
+ }
+}
+
+void User::setWorkPhone(QString const& workPhone)
+{
+ if (m_workPhone != workPhone) {
+ m_workPhone = workPhone;
+ emit workPhoneChanged();
+ }
+}
+
+void User::setMobilePhone(QString const& mobilePhone)
+{
+ if (m_mobilePhone != mobilePhone) {
+ m_mobilePhone = mobilePhone;
+ emit mobilePhoneChanged();
+ }
+}
+
+void User::setPagerPhone(QString const& pagerPhone)
+{
+ if (m_pagerPhone != pagerPhone) {
+ m_pagerPhone = pagerPhone;
+ emit pagerPhoneChanged();
+ }
+}
+
+void User::setAddress1(QString const& address1)
+{
+ if (m_address1 != address1) {
+ m_address1 = address1;
+ emit address1Changed();
+ }
+}
+
+void User::setAddress2(QString const& address2)
+{
+ if (m_address2 != address2) {
+ m_address2 = address2;
+ emit address2Changed();
+ }
+}
+
+void User::setCity(QString const& city)
+{
+ if (m_city != city) {
+ m_city = city;
+ emit cityChanged();
+ }
+}
+
+void User::setState(QString const& state)
+{
+ if (m_state != state) {
+ m_state = state;
+ emit stateChanged();
+ }
+}
+
+void User::setZip(QString const& zip)
+{
+ if (m_zip != zip) {
+ m_zip = zip;
+ emit zipChanged();
+ }
+}
+
+void User::setCountry(QString const& country)
+{
+ if (m_country != country) {
+ m_country = country;
+ emit countryChanged();
+ }
+}
+
+void User::setTimeZone(QString const& timeZone)
+{
+ if (m_timeZone != timeZone) {
+ m_timeZone = timeZone;
+ emit timeZoneChanged();
+ }
+}
+
+void User::setLoggedIn(bool isLoggedIn)
+{
+ if (m_isLoggedIn != isLoggedIn) {
+ m_isLoggedIn = isLoggedIn;
+ emit loggedInChanged();
+ }
+}
diff --git a/user.hxx b/user.hxx
new file mode 100644
index 0000000..1cac5fe
--- /dev/null
+++ b/user.hxx
@@ -0,0 +1,118 @@
+#ifndef USER_HXX
+#define USER_HXX
+
+#include <QObject>
+
+struct rt_user;
+
+class User : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(QString name READ name)
+ Q_PROPERTY(QString emailAddress READ emailAddress WRITE setEmailAddress NOTIFY emailAddressChanged)
+ Q_PROPERTY(QString organization READ organization WRITE setOrganization NOTIFY organizationChanged)
+ Q_PROPERTY(QString realName READ realName WRITE setRealName NOTIFY realNameChanged)
+ Q_PROPERTY(QString nickName READ nickName WRITE setNickName NOTIFY nickNameChanged)
+ Q_PROPERTY(QString lang READ lang WRITE setLang NOTIFY langChanged)
+ Q_PROPERTY(QString homePhone READ homePhone WRITE setHomePhone NOTIFY homePhoneChanged)
+ Q_PROPERTY(QString workPhone READ workPhone WRITE setWorkPhone NOTIFY workPhoneChanged)
+ Q_PROPERTY(QString mobilePhone READ mobilePhone WRITE setMobilePhone NOTIFY mobilePhoneChanged)
+ Q_PROPERTY(QString pagerPhone READ pagerPhone WRITE setPagerPhone NOTIFY pagerPhoneChanged)
+ Q_PROPERTY(QString address1 READ address1 WRITE setAddress1 NOTIFY address1Changed)
+ Q_PROPERTY(QString address2 READ address2 WRITE setAddress2 NOTIFY address2Changed)
+ 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 timeZone READ timeZone WRITE setTimeZone NOTIFY timeZoneChanged)
+ Q_PROPERTY(bool isLoggedIn READ isLoggedIn WRITE setLoggedIn NOTIFY loggedInChanged)
+
+ public:
+ explicit User(bool isLoggedIn = false, QObject* parent = nullptr) :
+ QObject{parent},
+ m_isLoggedIn{isLoggedIn}
+ {}
+ ~User() {}
+
+ Q_INVOKABLE void update(rt_user* user);
+
+ QString const& name() const { return m_name; }
+ QString const& emailAddress() const { return m_emailAddress; }
+ QString const& organization() const { return m_organization; }
+ QString const& realName() const { return m_realName; }
+ QString const& nickName() const { return m_nickName; }
+ QString const& lang() const { return m_lang; }
+ QString const& homePhone() const { return m_homePhone; }
+ QString const& workPhone() const { return m_workPhone; }
+ QString const& mobilePhone() const { return m_mobilePhone; }
+ QString const& pagerPhone() const { return m_pagerPhone; }
+ QString const& address1() const { return m_address1; }
+ QString const& address2() const { return m_address2; }
+ 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& timeZone() const { return m_timeZone; }
+ bool isLoggedIn() const { return m_isLoggedIn; }
+
+ void setName(QString const& name);
+ void setEmailAddress(QString const& emailAddress);
+ void setOrganization(QString const& organization);
+ void setRealName(QString const& realName);
+ void setNickName(QString const& nickName);
+ void setLang(QString const& lang);
+ void setHomePhone(QString const& homePhone);
+ void setWorkPhone(QString const& workPhone);
+ void setMobilePhone(QString const& mobilePhone);
+ void setPagerPhone(QString const& pagerPhone);
+ void setAddress1(QString const& address1);
+ void setAddress2(QString const& address2);
+ void setCity(QString const& city);
+ void setState(QString const& state);
+ void setZip(QString const& zip);
+ void setCountry(QString const& country);
+ void setTimeZone(QString const& timeZone);
+ void setLoggedIn(bool isLoggedIn);
+
+ signals:
+ void nameChanged();
+ void emailAddressChanged();
+ void organizationChanged();
+ void realNameChanged();
+ void nickNameChanged();
+ void langChanged();
+ void homePhoneChanged();
+ void workPhoneChanged();
+ void mobilePhoneChanged();
+ void pagerPhoneChanged();
+ void address1Changed();
+ void address2Changed();
+ void cityChanged();
+ void stateChanged();
+ void zipChanged();
+ void countryChanged();
+ void timeZoneChanged();
+ void loggedInChanged();
+
+ private:
+ QString m_name;
+ QString m_emailAddress;
+ QString m_organization;
+ QString m_realName;
+ QString m_nickName;
+ QString m_lang;
+ QString m_homePhone;
+ QString m_workPhone;
+ QString m_mobilePhone;
+ QString m_pagerPhone;
+ QString m_address1;
+ QString m_address2;
+ QString m_city;
+ QString m_state;
+ QString m_zip;
+ QString m_country;
+ QString m_timeZone;
+ bool m_isLoggedIn;
+};
+
+#endif // USER_HXX