summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id>2020-09-03 19:12:17 +0800
committerꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id>2020-09-03 19:12:17 +0800
commitbaa0e6cbb67912530d80d218712e6ca1e423f4dc (patch)
treebe1abc1a2f543d8f639c2a4e3d84d238620c9c2b
parent8ebcf88c02932f93ede84bc016aedb5d55dc19a7 (diff)
logIn as static member functions
-rw-r--r--admin.cxx32
-rw-r--r--member.cxx29
-rw-r--r--qicclient/admin.hxx19
-rw-r--r--qicclient/member.hxx16
4 files changed, 50 insertions, 46 deletions
diff --git a/admin.cxx b/admin.cxx
index b01fc2e..f59082f 100644
--- a/admin.cxx
+++ b/admin.cxx
@@ -1,9 +1,25 @@
#include <cstddef>
+#include <memory>
#include <icclient/admin.h>
#include "qicclient/admin.hxx"
namespace QICClient {
+ std::shared_ptr<Admin> Admin::logIn(QString const& username,
+ QString const& password, QString const& successPage,
+ QString const& nextPage, QString const& failPage,
+ size_t (*handler)(void*, size_t, size_t, void*))
+ {
+ auto admin = new Admin{};
+ admin->setData(icclient_admin_login(username.toLatin1().constData(),
+ password.toLatin1().constData(),
+ successPage.toLatin1().constData(),
+ nextPage.toLatin1().constData(),
+ failPage.toLatin1().constData(),
+ handler));
+ return std::shared_ptr<Admin>{admin};
+ }
+
void Admin::setUserName(QString const& userName)
{
if (m_userName != userName) {
@@ -11,7 +27,6 @@ namespace QICClient {
emit userNameChanged();
}
}
-
void Admin::setPassword(QString const& password)
{
if (m_password != password) {
@@ -19,7 +34,6 @@ namespace QICClient {
emit passwordChanged();
}
}
-
void Admin::setName(QString const& name)
{
if (m_name != name) {
@@ -27,7 +41,6 @@ namespace QICClient {
emit nameChanged();
}
}
-
void Admin::setSuper(bool super)
{
if (m_super != super) {
@@ -59,19 +72,6 @@ namespace QICClient {
if (m_data != data) m_data = data;
}
- void Admin::logIn(QString const& username, QString const& password,
- QString const& successPage, QString const& nextPage,
- QString const& failPage,
- size_t (*handler)(void*, size_t, size_t, void*))
- {
- setData(icclient_admin_login(username.toLatin1().constData(),
- password.toLatin1().constData(),
- successPage.toLatin1().constData(),
- nextPage.toLatin1().constData(),
- failPage.toLatin1().constData(),
- handler));
- }
-
void Admin::newItem(QString const& description, QString const& comment,
QString const& price, QString const& imagePath)
{
diff --git a/member.cxx b/member.cxx
index 7a9d66e..82222bb 100644
--- a/member.cxx
+++ b/member.cxx
@@ -1,9 +1,25 @@
#include <cstddef>
+#include <memory>
#include <icclient/member.h>
#include "qicclient/member.hxx"
namespace QICClient {
+ std::shared_ptr<Member> Member::logIn(QString const& username,
+ QString const& password, QString const& successPage,
+ QString const& nextPage, QString const& failPage,
+ size_t (*handler)(void*, size_t, size_t, void*))
+ {
+ auto member = new Member{};
+ member->setData(icclient_member_login(username.toLatin1().constData(),
+ password.toLatin1().constData(),
+ successPage.toLatin1().constData(),
+ nextPage.toLatin1().constData(),
+ failPage.toLatin1().constData(),
+ handler));
+ return std::shared_ptr<Member>{member};
+ }
+
void Member::setUserName(QString const& userName)
{
if (m_userName != userName) {
@@ -256,19 +272,6 @@ namespace QICClient {
if (m_data != data) m_data = data;
}
- void Member::logIn(QString const& username, QString const& password,
- QString const& successPage, QString const& nextPage,
- QString const& failPage,
- size_t (*handler)(void*, size_t, size_t, void*))
- {
- setData(icclient_member_login(username.toLatin1().constData(),
- password.toLatin1().constData(),
- successPage.toLatin1().constData(),
- nextPage.toLatin1().constData(),
- failPage.toLatin1().constData(),
- handler));
- }
-
void Member::account(QString const& firstName, QString const& lastName,
QString const& address1, QString const& address2,
QString const& city, QString const& state, QString const& zip,
diff --git a/qicclient/admin.hxx b/qicclient/admin.hxx
index 1e728cb..f19f167 100644
--- a/qicclient/admin.hxx
+++ b/qicclient/admin.hxx
@@ -22,9 +22,17 @@ namespace QICClient {
m_userName{""},
m_password{""},
m_name{""},
- m_super{false}
+ m_super{false},
+ m_data{nullptr}
{}
~Admin() {}
+ static std::shared_ptr<Admin> logIn(QString const& username,
+ QString const& password,
+ QString const& successPage = nullptr,
+ QString const& nextPage = nullptr,
+ QString const& failPage = nullptr,
+ size_t (*handler)(void*, size_t, size_t,
+ void*) = nullptr);
QString const& userName() const { return m_userName; }
QString const& password() const { return m_password; }
@@ -36,13 +44,6 @@ namespace QICClient {
void setName(QString const& name);
void setSuper(bool super);
- void logIn(QString const& username, QString const& password,
- QString const& successPage = nullptr,
- QString const& nextPage = nullptr,
- QString const& failPage = nullptr,
- size_t (*handler)(void*, size_t, size_t,
- void*) = nullptr);
-
public slots:
void newItem(QString const& description, QString const& comment,
QString const& price, QString const& imagePath);
@@ -60,7 +61,7 @@ namespace QICClient {
QString m_name;
bool m_super;
icclient_admin* m_data;
- void setData(icclient_admin* data);
+ inline void setData(icclient_admin* data);
};
}
diff --git a/qicclient/member.hxx b/qicclient/member.hxx
index 86289c0..864d353 100644
--- a/qicclient/member.hxx
+++ b/qicclient/member.hxx
@@ -56,6 +56,13 @@ namespace QICClient {
m_data{nullptr}
{}
~Member() {}
+ static std::shared_ptr<Member> logIn(QString const& username,
+ QString const& password,
+ QString const& successPage = nullptr,
+ QString const& nextPage = nullptr,
+ QString const& failPage = nullptr,
+ size_t (*handler)(void*, size_t, size_t,
+ void*) = nullptr);
QString const& userName() const { return m_userName; }
QString const& userNick() const { return m_userNick; }
@@ -97,13 +104,6 @@ namespace QICClient {
void setPhoneDay(QString const& phoneDay);
void setEmail(QString const& email);
- void logIn(QString const& username, QString const& password,
- QString const& successPage = nullptr,
- QString const& nextPage = nullptr,
- QString const& failPage = nullptr,
- size_t (*handler)(void*, size_t, size_t,
- void*) = nullptr);
-
public slots:
void account(QString const& firstName, QString const& lastName,
QString const& address1, QString const& address2,
@@ -156,7 +156,7 @@ namespace QICClient {
QString m_phoneDay;
QString m_email;
icclient_member* m_data;
- void setData(icclient_member* data);
+ inline void setData(icclient_member* data);
};
}