From 89bff3fa5d58aeb0d507d633aa058d781f06a8c0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=EA=A6=8C=20=EA=A6=AB=EA=A6=B6=20=EA=A6=8F=EA=A7=80?=
 =?UTF-8?q?=EA=A6=A6=EA=A6=BF=20=EA=A6=A7=20=EA=A6=AE=20=EA=A6=91=20?=
 =?UTF-8?q?=EA=A6=A9=20=EA=A6=AD=EA=A7=80?= <erik@darapsa.co.id>
Date: Thu, 5 Sep 2019 21:21:52 +0800
Subject: Connected a more straightforward signal to login

---
 controller.cxx            | 11 ++++-------
 controller.hxx            |  6 +-----
 main.cxx                  | 15 +++++++--------
 main.qml                  | 32 ++++++++++++++++----------------
 pages/ConfirmPassword.qml |  3 +--
 5 files changed, 29 insertions(+), 38 deletions(-)

diff --git a/controller.cxx b/controller.cxx
index 015d4ac..4e518f4 100644
--- a/controller.cxx
+++ b/controller.cxx
@@ -1,20 +1,17 @@
 #include "worker.hxx"
 #include "controller.hxx"
 
-Controller::Controller()
+Controller::Controller(QObject* parent) :
+	QObject{parent}
 {
 	Worker* worker = new Worker{};
 	worker->moveToThread(&thread);
 	connect(&thread, &QThread::finished, worker, &QObject::deleteLater);
-	connect(this, &Controller::credentialsObtained, worker, &Worker::logIn);
+	connect(parent, SIGNAL(logIn(QString, QString)),
+			worker, SLOT(logIn(QString, QString)));
 	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 8b98328..d98a735 100644
--- a/controller.hxx
+++ b/controller.hxx
@@ -8,12 +8,8 @@ class Controller : public QObject
 	Q_OBJECT
 
 	public:
-		Controller();
+		Controller(QObject* parent = nullptr);
 		~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 222a8b1..db21e08 100644
--- a/main.cxx
+++ b/main.cxx
@@ -7,21 +7,20 @@ int main(int argc, char* argv[])
 {
 	QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
 	QGuiApplication app(argc, argv);
-
 	QQmlApplicationEngine engine;
+
 	qmlRegisterSingletonType<User>("id.co.darapsa.kelakon.user", 0, 1, "User", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject* {
 		Q_UNUSED(engine)
 		Q_UNUSED(scriptEngine)
 		return new User{};
 	});
-	auto typeId = qmlRegisterSingletonType<User>("id.co.darapsa.kelakon.rtclient", 0, 1, "RTClient", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject* {
-		Q_UNUSED(engine)
-		Q_UNUSED(scriptEngine)
-		return new Controller{};
-	});
-	auto controller = engine.singletonInstance<Controller*>(typeId);
-	Q_UNUSED(controller)
+
 	engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
+	auto rootObjects = engine.rootObjects();
+	if (rootObjects.isEmpty()) return -1;
+
+	auto appWindow = rootObjects[0];
+	Controller controller{appWindow};
 
 	return app.exec();
 }
diff --git a/main.qml b/main.qml
index b432dd5..5449a2f 100644
--- a/main.qml
+++ b/main.qml
@@ -1,26 +1,26 @@
 import QtQuick 2.12
 import QtQuick.Controls 2.12
 import QtQuick.Controls.Material 2.12
-import QtQuick.Layouts 1.12
 
 ApplicationWindow {
-    id: appWindow
-    width: 360
-    height: 640
-    visible: true
+	id: appWindow
+	width: 360
+	height: 640
+	visible: true
+	Material.accent: Material.DeepPurple
 
-    Material.accent: Material.DeepPurple
+	signal logIn(string emailAddress, string password)
 
-    Drawer {
-        id: drawer
-        width: 0.8 * appWindow.width
-        height: appWindow.height
-    }
+	Drawer {
+		id: drawer
+		width: 0.8 * appWindow.width
+		height: appWindow.height
+	}
 
-    StackView {
-        id: stackView
-        anchors.fill : parent
+	StackView {
+		id: stackView
+		anchors.fill : parent
 
-        initialItem: Login {}
-    }
+		initialItem: Login {}
+	}
 }
diff --git a/pages/ConfirmPassword.qml b/pages/ConfirmPassword.qml
index 4b6d587..b7fdc3a 100644
--- a/pages/ConfirmPassword.qml
+++ b/pages/ConfirmPassword.qml
@@ -1,6 +1,5 @@
 import QtQuick 2.12
 import id.co.darapsa.kelakon.user 0.1
-import id.co.darapsa.kelakon.rtclient 0.1
 
 PasswordForm {
 	width: stackView.width
@@ -20,7 +19,7 @@ PasswordForm {
 	createPassButton {
 		text: qsTr("Confirm password")
 		onClicked: {
-			RTClient.logIn(User.emailAddress, User.password)
+			appWindow.logIn(User.emailAddress, User.password)
 			stackView.push("qrc:/pages/CreateProfile.qml")
 		}
 	}
-- 
cgit v1.2.3