#include "global.h" #include "settings.h" #include #include #include #include #include #include #include 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); } QImage Global::getConfigGradient() { QImage img; const QStringList cols = Settings::gradientColors(); qWarning() << "Got gradient color list: " << cols; if (cols.length() == 4 || cols.length() == 2) { bool ok = true; uint a, b, c, d; if (ok) a = cols.at(0).toUInt(&ok, 16) | 0xff000000; if (ok) b = cols.at(1).toUInt(&ok, 16) | 0xff000000; if (cols.length() == 4) { if (ok) c = cols.at(2).toUInt(&ok, 16) | 0xff000000; if (ok) d = cols.at(3).toUInt(&ok, 16) | 0xff000000; } else if (ok) { c = b; } if (ok) { img = QImage(cols.length() / 2, 2, QImage::Format_RGB32); img.setPixel(0, 0, a); img.setPixel(0, 1, c); if (cols.length() == 4) { img.setPixel(1, 0, b); img.setPixel(1, 1, d); } } } return img; }