summaryrefslogtreecommitdiffstats
path: root/src/loginform.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/loginform.cpp')
-rw-r--r--src/loginform.cpp65
1 files changed, 23 insertions, 42 deletions
diff --git a/src/loginform.cpp b/src/loginform.cpp
index 2fb09df..c070f92 100644
--- a/src/loginform.cpp
+++ b/src/loginform.cpp
@@ -19,26 +19,13 @@
#include "loginform.h"
#include "ui_loginform.h"
#include "settings.h"
+#include "global.h"
-LoginForm::LoginForm(bool testMode, QWidget *parent) :
+LoginForm::LoginForm(QWidget *parent) :
QWidget(parent),
ui(new Ui::LoginForm),
- m_Greeter(nullptr),
- power(nullptr),
- sessionsModel(nullptr),
clearMsg(false)
{
- if (!testMode) {
- m_Greeter = new QLightDM::Greeter(this);
- power = new QLightDM::PowerInterface(this);
- sessionsModel = new QLightDM::SessionsModel(this);
- }
-
- if (m_Greeter != nullptr && !m_Greeter->connectSync()) {
- exit(0);
- return;
- }
-
ui->setupUi(this);
initialize();
}
@@ -64,9 +51,7 @@ void LoginForm::initialize()
QPixmap icon(":/resources/bwlp.svg"); // This project came from Razor-qt
ui->iconLabel->setPixmap(icon.scaled(ui->iconLabel->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
- ui->leaveComboBox->setView(new QListView());
- //addLeaveEntry(power->canHibernate(), "system-suspend-hibernate", tr("Hibernate"), "hibernate");
- //addLeaveEntry(power->canSuspend(), "system-suspend", tr("Suspend"), "suspend");
+ ui->leaveComboBox->setView(new QListView()); // This is required to get the stylesheet to apply
cancelLoginTimer.setInterval(10000);
cancelLoginTimer.setSingleShot(true);
@@ -76,17 +61,16 @@ void LoginForm::initialize()
hideMessageTimer.setSingleShot(true);
connect(&hideMessageTimer, SIGNAL(timeout()), this, SLOT(hideMessage()));
- if (m_Greeter != nullptr) {
- ui->hostnameLabel->setText(m_Greeter->hostname());
+ if (!Global::testMode()) {
+ ui->hostnameLabel->setText(Global::greeter()->hostname());
- addLeaveEntry(power->canShutdown(), "system-shutdown", tr("Shutdown"), "shutdown");
- addLeaveEntry(power->canRestart(), "system-reboot", tr("Restart"), "restart");
+ addLeaveEntry(Global::power()->canShutdown(), "system-shutdown", tr("Shutdown"), "shutdown");
+ addLeaveEntry(Global::power()->canRestart(), "system-reboot", tr("Restart"), "restart");
- //connect(ui->userInput, SIGNAL(editingFinished()), this, SLOT(userChanged()));
connect(ui->leaveComboBox, SIGNAL(activated(int)), this, SLOT(leaveDropDownActivated(int)));
- connect(m_Greeter, SIGNAL(showPrompt(QString, QLightDM::Greeter::PromptType)), this, SLOT(onPrompt(QString, QLightDM::Greeter::PromptType)));
- connect(m_Greeter, SIGNAL(showMessage(QString, QLightDM::Greeter::MessageType)), this, SLOT(onMessage(QString, QLightDM::Greeter::MessageType)));
- connect(m_Greeter, SIGNAL(authenticationComplete()), this, SLOT(onAuthenticationComplete()));
+ connect(Global::greeter(), SIGNAL(showPrompt(QString, QLightDM::Greeter::PromptType)), this, SLOT(onPrompt(QString, QLightDM::Greeter::PromptType)));
+ connect(Global::greeter(), SIGNAL(showMessage(QString, QLightDM::Greeter::MessageType)), this, SLOT(onMessage(QString, QLightDM::Greeter::MessageType)));
+ connect(Global::greeter(), SIGNAL(authenticationComplete()), this, SLOT(onAuthenticationComplete()));
}
ui->leaveComboBox->setDisabled(ui->leaveComboBox->count() <= 1);
@@ -95,11 +79,11 @@ void LoginForm::initialize()
void LoginForm::startAuthentication()
{
- if (m_Greeter == nullptr) {
+ if (Global::testMode()) {
return;
}
- if (m_Greeter->inAuthentication()) {
- m_Greeter->cancelAuthentication();
+ if (Global::greeter()->inAuthentication()) {
+ Global::greeter()->cancelAuthentication();
}
if (ui->userInput->text().isEmpty()) {
ui->userInput->setFocus();
@@ -115,23 +99,23 @@ void LoginForm::startAuthentication()
ui->userInput->setEnabled(false);
ui->passwordInput->setEnabled(false);
cancelLoginTimer.start();
- m_Greeter->authenticate(ui->userInput->text());
+ Global::greeter()->authenticate(ui->userInput->text());
}
void LoginForm::onPrompt(QString prompt, QLightDM::Greeter::PromptType promptType)
{
std::cerr << "Prompt: " << prompt.toStdString() << std::endl;
- m_Greeter->respond(ui->passwordInput->text());
+ Global::greeter()->respond(ui->passwordInput->text());
ui->passwordInput->clear();
}
void LoginForm::leaveDropDownActivated(int index)
{
QString actionName = ui->leaveComboBox->itemData(index).toString();
- if (actionName == "shutdown") power->shutdown();
- else if (actionName == "restart") power->restart();
- else if (actionName == "hibernate") power->hibernate();
- else if (actionName == "suspend") power->suspend();
+ if (actionName == "shutdown") Global::power()->shutdown();
+ else if (actionName == "restart") Global::power()->restart();
+ else if (actionName == "hibernate") Global::power()->hibernate();
+ else if (actionName == "suspend") Global::power()->suspend();
}
void LoginForm::onMessage(QString message, QLightDM::Greeter::MessageType type)
@@ -150,13 +134,10 @@ void LoginForm::addLeaveEntry(bool canDo, QString iconName, QString text, QStrin
void LoginForm::onAuthenticationComplete()
{
- if (m_Greeter->isAuthenticated()) {
+ if (Global::greeter()->isAuthenticated()) {
std::cerr << "Auth complete, start session" << std::endl;
showMessage(tr("Starting session..."), false);
- QModelIndex i = sessionsModel->index(0, 0);
- QString s = sessionsModel->data(i, QLightDM::SessionsModel::KeyRole).toString();
- std::cerr << s.toStdString() << std::endl;
- if (m_Greeter->startSessionSync(s)) {
+ if (Global::startSession()) {
cancelLoginTimer.stop();
} else {
showMessage(tr("Cannot open session"), true);
@@ -171,9 +152,9 @@ void LoginForm::onAuthenticationComplete()
void LoginForm::cancelLogin()
{
std::cerr << "Cancel login" << std::endl;
- if (m_Greeter->inAuthentication()) {
+ if (Global::greeter()->inAuthentication()) {
std::cerr << "Was in authentication" << std::endl;
- m_Greeter->cancelAuthentication();
+ Global::greeter()->cancelAuthentication();
}
cancelLoginTimer.stop();
ui->passwordInput->clear();