summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id>2019-09-15 20:05:18 +0800
committerꦌ ꦫꦶ ꦏ꧀ꦦꦿ ꦧ ꦮ ꦑ ꦩ ꦭ꧀ <erik@darapsa.co.id>2019-09-15 20:05:18 +0800
commit41bfcb06c9c0ff97ab69f323e96117b46529828b (patch)
treee5138b70ea8b481f1409b2831d6177f1ebc0ed55
parent45515cb4f2831ed1fb7081f8f55d7aacb2b3ab62 (diff)
qrtclient as submodule instead
while librtclient has become qrtclient's submodule
-rw-r--r--.gitmodules6
-rw-r--r--controller.cxx23
-rw-r--r--controller.hxx4
-rw-r--r--kelakon.pro18
m---------librtclient0
m---------qrtclient0
-rw-r--r--tasklist.cxx45
-rw-r--r--tasklist.hxx48
-rw-r--r--user.cxx221
-rw-r--r--user.hxx159
-rw-r--r--worker.cxx30
-rw-r--r--worker.hxx23
12 files changed, 23 insertions, 554 deletions
diff --git a/.gitmodules b/.gitmodules
index 8a122f9..24679ea 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +1,3 @@
-[submodule "librtclient"]
- path = librtclient
- url = git@github.com:darapsa/librtclient.git
+[submodule "qrtclient"]
+ path = qrtclient
+ url = git@github.com:darapsa/qrtclient.git
diff --git a/controller.cxx b/controller.cxx
index 2e562bf..47656e4 100644
--- a/controller.cxx
+++ b/controller.cxx
@@ -1,15 +1,13 @@
#include <QQmlApplicationEngine>
#include <QtQml>
-#include "worker.hxx"
-#include "user.hxx"
-#include "tasklist.hxx"
+#include <qrtclient/user.hxx>
#include "controller.hxx"
Controller::Controller(QObject* parent) : QObject{parent}
{
- auto worker = new Worker;
- worker->moveToThread(&thread);
- connect(&thread, &QThread::finished, worker, &QObject::deleteLater);
+ auto client = new RTClient::Client{"https://darapsa.co.id/rt"};
+ client->moveToThread(&thread);
+ connect(&thread, &QThread::finished, client, &QObject::deleteLater);
auto engine = static_cast<QQmlApplicationEngine*>(parent);
auto rootObjects = engine->rootObjects();
@@ -17,10 +15,11 @@ Controller::Controller(QObject* parent) : QObject{parent}
auto loginView = appWindow->findChild<QObject*>("login");
connect(loginView, SIGNAL(logIn(QString, QString)),
- worker, SLOT(logIn(QString, QString)));
- connect(worker, SIGNAL(logged(rt_user*)), loginView, SLOT(pushProfile()));
- connect(loginView, SIGNAL(search(QString)), worker, SLOT(search(QString)));
+ client, SLOT(logIn(QString, QString)));
+ connect(client, SIGNAL(logged(rt_user*)), loginView, SLOT(pushProfile()));
+ connect(loginView, SIGNAL(search(QString)), client, SLOT(search(QString)));
+ using RTClient::User;
auto typeId = qmlRegisterSingletonType<User>("KelakonUser", 0, 1, "User"
, [](QQmlEngine *engine,
QJSEngine *scriptEngine) -> QObject* {
@@ -29,11 +28,11 @@ Controller::Controller(QObject* parent) : QObject{parent}
return new User;
});
auto user = engine->singletonInstance<User*>(typeId);
- connect(worker, SIGNAL(logged(rt_user*)), user, SLOT(update(rt_user*)));
+ connect(client, SIGNAL(logged(rt_user*)), user, SLOT(update(rt_user*)));
- taskList = new TaskList;
+ taskList = new RTClient::TicketList;
engine->rootContext()->setContextProperty("taskList", taskList);
- connect(worker, SIGNAL(foundTasks(rt_ticketlist*))
+ connect(client, SIGNAL(foundTasks(rt_ticketlist*))
, taskList, SLOT(addTasks(rt_ticketlist*)));
thread.start();
diff --git a/controller.hxx b/controller.hxx
index 5d4ef89..a3df9a9 100644
--- a/controller.hxx
+++ b/controller.hxx
@@ -2,6 +2,8 @@
#define CONTROLLER_HXX
#include <QThread>
+#include <qrtclient/ticket.hxx>
+#include <qrtclient/client.hxx>
class Controller : public QObject
{
@@ -13,7 +15,7 @@ class Controller : public QObject
private:
QThread thread;
- class TaskList* taskList;
+ class RTClient::TicketList* taskList;
};
#endif // CONTROLLER_HXX
diff --git a/kelakon.pro b/kelakon.pro
index 8a025a9..c40abd4 100644
--- a/kelakon.pro
+++ b/kelakon.pro
@@ -1,26 +1,18 @@
QT += quickcontrols2
-debug: DEFINES += DEBUG
-
-HEADERS += \
- user.hxx \
- worker.hxx \
- controller.hxx \
- tasklist.hxx
+HEADERS += controller.hxx
SOURCES += \
- user.cxx \
- worker.cxx \
controller.cxx \
- tasklist.cxx \
main.cxx
RESOURCES += kelakon.qrc
-INCLUDEPATH += $$PWD/librtclient
+INCLUDEPATH += $$PWD/qrtclient
LIBS += \
- $$PWD/librtclient/librtclient.a \
+ $$PWD/qrtclient/libqrtclient.a \
+ $$PWD/qrtclient/librtclient/librtclient.a \
-lcurl
contains(ANDROID_TARGET_ARCH,arm64-v8a) {
@@ -46,3 +38,5 @@ android {
DISTFILES += android/AndroidManifest.xml
ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
}
+
+debug: DEFINES += DEBUG
diff --git a/librtclient b/librtclient
deleted file mode 160000
-Subproject cb9020218b20470b483197dd6662c0fae3237e3
diff --git a/qrtclient b/qrtclient
new file mode 160000
+Subproject 70565512f20febb7a2e47ea6efde61a31aa7c57
diff --git a/tasklist.cxx b/tasklist.cxx
deleted file mode 100644
index d972773..0000000
--- a/tasklist.cxx
+++ /dev/null
@@ -1,45 +0,0 @@
-#include <rtclient/rtclient.h>
-#include "tasklist.hxx"
-
-int TaskList::rowCount(QModelIndex const& parent) const
-{
- Q_UNUSED(parent)
- return tasks.count();
-}
-
-QVariant TaskList::data(QModelIndex const& index, int role) const
-{
- auto row = index.row();
-
- if (row < 0 || row >= tasks.count()) return QVariant();
-
- auto task = tasks[row];
- switch (role) {
- case SubjectRole:
- return task.subject();
- default:
- return QVariant();
- }
-}
-
-QHash<int, QByteArray> TaskList::roleNames() const
-{
- return QHash<int, QByteArray>{
- {SubjectRole, "subject"}
- };
-}
-
-void TaskList::addTask(Task const& task)
-{
- beginInsertRows(QModelIndex(), rowCount(), rowCount());
- tasks << task;
- endInsertRows();
- emit rowCountChanged();
-}
-
-void TaskList::addTasks(rt_ticketlist* taskList)
-{
- for (unsigned int i = 0; i < taskList->length; i++)
- addTask(Task{taskList->tickets[i]});
- rtclient_ticket_freelist(taskList);
-}
diff --git a/tasklist.hxx b/tasklist.hxx
deleted file mode 100644
index 20b2220..0000000
--- a/tasklist.hxx
+++ /dev/null
@@ -1,48 +0,0 @@
-#ifndef TASKLIST_HXX
-#define TASKLIST_HXX
-
-#include <QAbstractListModel>
-
-class Task
-{
- public:
- Task(QString subject) : m_subject{subject}
- {}
- QString const& subject() const { return m_subject; }
-
- private:
- QString m_subject;
-};
-
-class TaskList : public QAbstractListModel
-{
- Q_OBJECT
- Q_PROPERTY(int rowCount READ rowCount NOTIFY rowCountChanged)
-
- public:
- enum TaskRoles {
- SubjectRole = Qt::UserRole + 1,
- };
-
- explicit TaskList(QObject* parent = nullptr)
- : QAbstractListModel{parent} {}
- ~TaskList() {}
-
- int rowCount(QModelIndex const& parent = QModelIndex()) const Q_DECL_OVERRIDE;
- QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
-
- protected:
- QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
-
- signals:
- void rowCountChanged();
-
- private:
- QList<Task> tasks;
- void addTask(Task const& task);
-
- private slots:
- void addTasks(struct rt_ticketlist* taskList);
-};
-
-#endif // TASKLIST_HXX
diff --git a/user.cxx b/user.cxx
deleted file mode 100644
index fc4f4ed..0000000
--- a/user.cxx
+++ /dev/null
@@ -1,221 +0,0 @@
-#include <rtclient/rtclient.h>
-#include "user.hxx"
-
-void User::setId(QString const& id)
-{
- if (m_id != id) {
- m_id = id;
- emit idChanged();
- }
-}
-
-void User::setName(QString const& name)
-{
- if (m_name != name) {
- m_name = name;
- emit nameChanged();
- }
-}
-
-void User::setPassword(QString const& password)
-{
- if (m_password != password) {
- m_password = password;
- emit passwordChanged();
- }
-}
-
-void User::setEmailAddress(QString const& emailAddress)
-{
- if (m_emailAddress != emailAddress) {
- m_emailAddress = emailAddress;
- emit emailAddressChanged();
- }
-}
-
-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::setOrganization(QString const& organization)
-{
- if (m_organization != organization) {
- m_organization = organization;
- emit organizationChanged();
- }
-}
-
-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::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::setLang(QString const& lang)
-{
- if (m_lang != lang) {
- m_lang = lang;
- emit langChanged();
- }
-}
-
-void User::setPrivileged(bool privileged)
-{
- if (m_privileged != privileged) {
- m_privileged = privileged;
- emit privilegedChanged();
- }
-}
-
-void User::setDisabled(bool disabled)
-{
- if (m_disabled != disabled) {
- m_disabled = disabled;
- emit disabledChanged();
- }
-}
-
-void User::setLoggedIn(bool loggedIn)
-{
- if (m_loggedIn != loggedIn) {
- m_loggedIn = loggedIn;
- emit loggedInChanged();
- }
-}
-
-void User::update(rt_user* user)
-{
- if (user) {
- m_id = user->id;
- m_emailAddress = user->emailaddress;
- emit emailAddressChanged();
- m_realName = user->realname;
- emit realNameChanged();
- m_nickName = user->nickname;
- m_gecos = user->gecos;
- m_organization = user->organization;
- m_address1 = user->address1;
- m_address2 = user->address2;
- m_city = user->city;
- m_state = user->state;
- m_zip = user->zip;
- m_country = user->country;
- m_homePhone = user->homephone;
- m_workPhone = user->workphone;
- m_mobilePhone = user->mobilephone;
- m_pagerPhone = user->pagerphone;
- m_lang = user->lang;
- m_privileged = user->privileged;
- m_disabled = user->disabled;
- m_loggedIn = true;
- rtclient_user_free(user);
- } else {
- m_id = "";
- m_name = "";
- m_password = "";
- m_emailAddress = "";
- m_realName = "";
- m_nickName = "";
- m_organization = "";
- m_address1 = "";
- m_address2 = "";
- m_city = "";
- m_state = "";
- m_zip = "";
- m_country = "";
- m_homePhone = "";
- m_workPhone = "";
- m_mobilePhone = "";
- m_pagerPhone = "";
- m_lang = "";
- m_privileged = false;
- m_disabled = true;
- m_loggedIn = false;
- }
-}
diff --git a/user.hxx b/user.hxx
deleted file mode 100644
index 2b9a356..0000000
--- a/user.hxx
+++ /dev/null
@@ -1,159 +0,0 @@
-#ifndef USER_HXX
-#define USER_HXX
-
-#include <QObject>
-
-class User : public QObject
-{
- Q_OBJECT
- Q_PROPERTY(QString id READ id WRITE setId NOTIFY idChanged)
- Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
- Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged)
- Q_PROPERTY(QString emailAddress READ emailAddress WRITE setEmailAddress NOTIFY emailAddressChanged)
- Q_PROPERTY(QString realName READ realName WRITE setRealName NOTIFY realNameChanged)
- Q_PROPERTY(QString nickName READ nickName WRITE setNickName NOTIFY nickNameChanged)
- Q_PROPERTY(QString organization READ organization WRITE setOrganization NOTIFY organizationChanged)
- 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 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 lang READ lang WRITE setLang NOTIFY langChanged)
- Q_PROPERTY(bool privileged READ privileged WRITE setPrivileged NOTIFY privilegedChanged)
- Q_PROPERTY(bool disabled READ disabled WRITE setDisabled NOTIFY disabledChanged)
- Q_PROPERTY(bool loggedIn READ loggedIn WRITE setLoggedIn NOTIFY loggedInChanged)
-
- public:
- explicit User(QObject* parent = nullptr)
- : QObject{parent}
- , m_id{""}
- , m_name{""}
- , m_password{""}
- , m_emailAddress{""}
- , m_realName{""}
- , m_nickName{""}
- , m_organization{""}
- , m_gecos{""}
- , m_address1{""}
- , m_address2{""}
- , m_city{""}
- , m_state{""}
- , m_zip{""}
- , m_country{""}
- , m_homePhone{""}
- , m_workPhone{""}
- , m_mobilePhone{""}
- , m_pagerPhone{""}
- , m_contactInfo{""}
- , m_comments{""}
- , m_lang{""}
- , m_privileged{false}
- , m_disabled{true}
- , m_loggedIn{false}
- {}
- ~User() {}
-
- QString const& id() const { return m_id; }
- QString const& name() const { return m_name; }
- QString const& password() const { return m_password; }
- QString const& emailAddress() const { return m_emailAddress; }
- QString const& realName() const { return m_realName; }
- QString const& nickName() const { return m_nickName; }
- QString const& organization() const { return m_organization; }
- 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& 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& lang() const { return m_lang; }
- bool privileged() const { return m_privileged; }
- bool disabled() const { return m_disabled; }
- bool loggedIn() const { return m_loggedIn; }
-
- void setId(QString const& id);
- void setName(QString const& name);
- void setPassword(QString const& password);
- void setEmailAddress(QString const& emailAddress);
- void setRealName(QString const& realName);
- void setNickName(QString const& nickName);
- void setOrganization(QString const& organization);
- 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 setHomePhone(QString const& homePhone);
- void setWorkPhone(QString const& workPhone);
- void setMobilePhone(QString const& mobilePhone);
- void setPagerPhone(QString const& pagerPhone);
- void setLang(QString const& lang);
- void setPrivileged(bool privileged);
- void setDisabled(bool disabled);
- void setLoggedIn(bool loggedIn);
-
- signals:
- void idChanged();
- void nameChanged();
- void passwordChanged();
- void emailAddressChanged();
- void realNameChanged();
- void nickNameChanged();
- void organizationChanged();
- void gecosChanged();
- void address1Changed();
- void address2Changed();
- void cityChanged();
- void stateChanged();
- void zipChanged();
- void countryChanged();
- void homePhoneChanged();
- void workPhoneChanged();
- void mobilePhoneChanged();
- void pagerPhoneChanged();
- void langChanged();
- void privilegedChanged();
- void disabledChanged();
- void loggedInChanged();
-
- private slots:
- void update(struct rt_user* user);
-
- private:
- QString m_id;
- QString m_name;
- QString m_password;
- QString m_emailAddress;
- QString m_realName;
- QString m_nickName;
- QString m_organization;
- QString m_gecos;
- QString m_address1;
- QString m_address2;
- QString m_city;
- QString m_state;
- QString m_zip;
- QString m_country;
- QString m_homePhone;
- QString m_workPhone;
- QString m_mobilePhone;
- QString m_pagerPhone;
- QString m_contactInfo;
- QString m_comments;
- QString m_lang;
- bool m_privileged;
- bool m_disabled;
- bool m_loggedIn;
-};
-
-#endif // USER_HXX
diff --git a/worker.cxx b/worker.cxx
deleted file mode 100644
index f01ca50..0000000
--- a/worker.cxx
+++ /dev/null
@@ -1,30 +0,0 @@
-#include <rtclient/rtclient.h>
-#include "worker.hxx"
-
-Worker::Worker()
-{
- rtclient_init("https://darapsa.co.id/rt");
-}
-
-void Worker::logIn(QString const& name, QString const& password)
-{
- rtclient_login(name.toLatin1().constData(), password.toLatin1().constData());
- struct rt_user* user = NULL;
- rtclient_user_show(&user, name.toLatin1().constData());
- if (user) emit logged(user);
-}
-
-void Worker::search(QString const& owner)
-{
- QString query{"Owner='"};
- query.append(owner);
- query.append("'");
- rt_ticketlist* taskList = NULL;
- rtclient_ticket_search(&taskList, query.toLatin1().constData());
- if (taskList) emit foundTasks(taskList);
-}
-
-Worker::~Worker()
-{
- rtclient_cleanup();
-}
diff --git a/worker.hxx b/worker.hxx
deleted file mode 100644
index 878c2ba..0000000
--- a/worker.hxx
+++ /dev/null
@@ -1,23 +0,0 @@
-#ifndef WORKER_HXX
-#define WORKER_HXX
-
-#include <QObject>
-
-class Worker : public QObject
-{
- Q_OBJECT
-
- public:
- Worker();
- ~Worker();
-
- public slots:
- void logIn(QString const& name, QString const& password);
- void search(QString const& owner);
-
- signals:
- void logged(struct rt_user* user);
- void foundTasks(struct rt_ticketlist* list);
-};
-
-#endif // WORKER_HXX