From 07c432faf992781868f4d24b417c9cabb52a33d5 Mon Sep 17 00:00:00 2001 From: Erik Prabowo Kamal Date: Fri, 30 Aug 2019 18:53:52 +0800 Subject: Managed to post login credentials to the RT server For now, it's just to get a response --- controller.cxx | 6 ++++++ controller.hxx | 4 ++++ main.cxx | 11 ++++++----- pages/Password.qml | 2 ++ rtclient | 2 +- worker.cxx | 5 +++++ worker.hxx | 4 ++++ 7 files changed, 28 insertions(+), 6 deletions(-) diff --git a/controller.cxx b/controller.cxx index d1271b9..015d4ac 100644 --- a/controller.cxx +++ b/controller.cxx @@ -6,9 +6,15 @@ Controller::Controller() Worker* worker = new Worker{}; worker->moveToThread(&thread); connect(&thread, &QThread::finished, worker, &QObject::deleteLater); + connect(this, &Controller::credentialsObtained, worker, &Worker::logIn); thread.start(); } +void Controller::logIn(QString const& name, QString const& password) +{ + emit credentialsObtained(name, password); +} + Controller::~Controller() { thread.quit(); diff --git a/controller.hxx b/controller.hxx index e293ec4..8b98328 100644 --- a/controller.hxx +++ b/controller.hxx @@ -10,6 +10,10 @@ class Controller : public QObject public: Controller(); ~Controller(); + Q_INVOKABLE void logIn(QString const& name, QString const& password); + + signals: + void credentialsObtained(QString const& name, QString const& password); private: QThread thread; diff --git a/main.cxx b/main.cxx index 0b52736..a29e917 100644 --- a/main.cxx +++ b/main.cxx @@ -12,13 +12,14 @@ int main(int argc, char* argv[]) qmlRegisterSingletonType("id.co.darapsa.kelakon.user", 0, 1, "User", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject* { Q_UNUSED(engine) Q_UNUSED(scriptEngine) - - User* user = new User{}; - return user; + return new User{}; + }); + qmlRegisterSingletonType("id.co.darapsa.kelakon.rtclient", 0, 1, "RTClient", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject* { + Q_UNUSED(engine) + Q_UNUSED(scriptEngine) + return new Controller{}; }); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); - Controller controller{}; - return app.exec(); } diff --git a/pages/Password.qml b/pages/Password.qml index 0edb294..a499a65 100644 --- a/pages/Password.qml +++ b/pages/Password.qml @@ -1,5 +1,6 @@ import QtQuick 2.12 import id.co.darapsa.kelakon.user 0.1 +import id.co.darapsa.kelakon.rtclient 0.1 PasswordForm { width: stackView.width @@ -13,6 +14,7 @@ PasswordForm { createPassButton { onClicked: { User.password = passTextField.text + RTClient.logIn(User.emailAddress, User.password) } } } diff --git a/rtclient b/rtclient index 89cd9ab..16b8e66 160000 --- a/rtclient +++ b/rtclient @@ -1 +1 @@ -Subproject commit 89cd9ab12cb2aa09f92e312cd0418a036dc0ed8d +Subproject commit 16b8e66c64ee8acd6ea2ce34372e52406a990d2a diff --git a/worker.cxx b/worker.cxx index 8c915f8..19ae358 100644 --- a/worker.cxx +++ b/worker.cxx @@ -7,6 +7,11 @@ Worker::Worker(QObject* parent) : rtclient_init(); } +void Worker::logIn(QString const& name, QString const& password) +{ + rtclient_login(name.toLatin1().constData(), password.toLatin1().constData()); +} + Worker::~Worker() { rtclient_cleanup(); diff --git a/worker.hxx b/worker.hxx index cdb2811..660361e 100644 --- a/worker.hxx +++ b/worker.hxx @@ -6,9 +6,13 @@ class Worker : public QObject { Q_OBJECT + public: explicit Worker(QObject* parent = nullptr); virtual ~Worker(); + + public slots: + void logIn(QString const& name, QString const& password); }; #endif // WORKER_HXX -- cgit v1.2.3