summaryrefslogtreecommitdiffstats
path: root/src/global.cpp
blob: 7039bc16cea2e9626e3abdeff27d9aecb2a44f1a (plain) (blame)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "global.h"
#include <QTimer>
#include <QModelIndex>
#include <QString>
#include <QEventLoop>
#include <QDebug>
#include <QCoreApplication>

bool Global::m_testMode = false;

QLightDM::Greeter* Global::m_Greeter = nullptr;
QLightDM::PowerInterface* Global::m_Power = nullptr;
QLightDM::SessionsModel* Global::m_Sessions = nullptr;

void Global::initGreeter()
{
	m_Greeter = new QLightDM::Greeter();
	if (!m_Greeter->connectSync()) {
		m_Greeter->deleteLater();
		m_Greeter = nullptr;
	}
}

bool Global::autoLoginGuest()
{
	GreeterCb *cb = new GreeterCb();
	GreeterCb::connect(greeter(), SIGNAL(authenticationComplete()), cb, SLOT(authenticationComplete()));
	GreeterCb::connect(greeter(), SIGNAL(autologinTimerExpired()), cb, SLOT(autologinTimerExpired()));
	GreeterCb::connect(greeter(), SIGNAL(reset()), cb, SLOT(reset()));
	qWarning() << "Trying to auth as guest";
	greeter()->authenticateAsGuest();
	QTimer::singleShot(3000, cb, SLOT(customTimeout()));
	while (!cb->authComplete && !cb->authError && greeter()->inAuthentication()) {
		QCoreApplication::instance()->processEvents(QEventLoop::AllEvents);
	}
	qWarning() << "Complete:" << cb->authComplete << "Error:"
			<< cb->authError << "InAuth:" << greeter()->inAuthentication() << "isAuthenticated" << greeter()->isAuthenticated();
	if (cb->authComplete && greeter()->isAuthenticated()) {
		cb->deleteLater();
		return startSession();
	}
	cb->deleteLater();
	return false;
}

bool Global::startSession()
{
	QModelIndex i = sessions()->index(0, 0);
	QString s = m_Sessions->data(i, QLightDM::SessionsModel::KeyRole).toString();
	return m_Greeter->startSessionSync(s);
}