summaryrefslogtreecommitdiff
path: root/controller.cxx
blob: 3b4b4deb3c9785d1271bc65f9a95a96a3f3452bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <QQmlApplicationEngine>
#include "worker.hxx"
#include "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 engine = dynamic_cast<QQmlApplicationEngine*>(parent);
	auto rootObjects = engine->rootObjects();
	auto appWindow = rootObjects[0];

	auto loginView = appWindow->findChild<QObject*>("login");
	connect(loginView, SIGNAL(logIn(QString, QString)),
			worker, SLOT(logIn(QString, QString)));

	auto user = engine->singletonInstance<User*>(User::typeId);
	connect(worker, SIGNAL(logged(rt_user*))
			, user, SLOT(update(rt_user*)));

	thread.start();
}

Controller::~Controller()
{
	thread.quit();
	thread.wait();
}