From 542b440ad64b50f265b72246981d5e9d655eb4d4 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Sun, 12 Nov 2017 13:04:26 +0100 Subject: Fix banner display, gradient parsing, add test mode (--test) --- src/loginform.cpp | 75 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 31 deletions(-) (limited to 'src/loginform.cpp') diff --git a/src/loginform.cpp b/src/loginform.cpp index ac3eaf2..3b86830 100644 --- a/src/loginform.cpp +++ b/src/loginform.cpp @@ -20,15 +20,21 @@ #include "ui_loginform.h" #include "settings.h" -LoginForm::LoginForm(QWidget *parent) : +LoginForm::LoginForm(bool testMode, QWidget *parent) : QWidget(parent), ui(new Ui::LoginForm), - m_Greeter(), - power(this), - sessionsModel(), + m_Greeter(nullptr), + power(nullptr), + sessionsModel(nullptr), clearMsg(false) { - if (!m_Greeter.connectSync()) { + 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; } @@ -55,15 +61,11 @@ void LoginForm::setFocus(Qt::FocusReason reason) void LoginForm::initialize() { - QPixmap icon(":/resources/rqt-2.png"); // This project came from Razor-qt + QPixmap icon(":/resources/bwlp.svg"); // This project came from Razor-qt ui->iconLabel->setPixmap(icon.scaled(ui->iconLabel->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); - ui->hostnameLabel->setText(m_Greeter.hostname()); - addLeaveEntry(power.canShutdown(), "system-shutdown", tr("Shutdown"), "shutdown"); - addLeaveEntry(power.canRestart(), "system-reboot", tr("Restart"), "restart"); - //addLeaveEntry(power.canHibernate(), "system-suspend-hibernate", tr("Hibernate"), "hibernate"); - //addLeaveEntry(power.canSuspend(), "system-suspend", tr("Suspend"), "suspend"); - ui->leaveComboBox->setDisabled(ui->leaveComboBox->count() <= 1); + //addLeaveEntry(power->canHibernate(), "system-suspend-hibernate", tr("Hibernate"), "hibernate"); + //addLeaveEntry(power->canSuspend(), "system-suspend", tr("Suspend"), "suspend"); cancelLoginTimer.setInterval(10000); cancelLoginTimer.setSingleShot(true); @@ -73,19 +75,30 @@ void LoginForm::initialize() hideMessageTimer.setSingleShot(true); connect(&hideMessageTimer, SIGNAL(timeout()), this, SLOT(hideMessage())); - //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())); + if (m_Greeter != nullptr) { + ui->hostnameLabel->setText(m_Greeter->hostname()); + addLeaveEntry(power->canShutdown(), "system-shutdown", tr("Shutdown"), "shutdown"); + addLeaveEntry(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())); + } + + ui->leaveComboBox->setDisabled(ui->leaveComboBox->count() <= 1); ui->passwordInput->clear(); } void LoginForm::startAuthentication() { - if (m_Greeter.inAuthentication()) { - m_Greeter.cancelAuthentication(); + if (m_Greeter == nullptr) { + return; + } + if (m_Greeter->inAuthentication()) { + m_Greeter->cancelAuthentication(); } if (ui->userInput->text().isEmpty()) { ui->userInput->setFocus(); @@ -101,23 +114,23 @@ void LoginForm::startAuthentication() ui->userInput->setEnabled(false); ui->passwordInput->setEnabled(false); cancelLoginTimer.start(); - m_Greeter.authenticate(ui->userInput->text()); + m_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()); + m_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") power->shutdown(); + else if (actionName == "restart") power->restart(); + else if (actionName == "hibernate") power->hibernate(); + else if (actionName == "suspend") power->suspend(); } void LoginForm::onMessage(QString message, QLightDM::Greeter::MessageType type) @@ -136,14 +149,14 @@ void LoginForm::addLeaveEntry(bool canDo, QString iconName, QString text, QStrin void LoginForm::onAuthenticationComplete() { - if (m_Greeter.isAuthenticated()) { + if (m_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(); + QModelIndex i = sessionsModel->index(0, 0); + QString s = sessionsModel->data(i, QLightDM::SessionsModel::KeyRole).toString(); s = "i3"; std::cerr << s.toStdString() << std::endl; - if (m_Greeter.startSessionSync(s)) { + if (m_Greeter->startSessionSync(s)) { cancelLoginTimer.stop(); } else { showMessage(tr("Cannot open session"), true); @@ -158,9 +171,9 @@ void LoginForm::onAuthenticationComplete() void LoginForm::cancelLogin() { std::cerr << "Cancel login" << std::endl; - if (m_Greeter.inAuthentication()) { + if (m_Greeter->inAuthentication()) { std::cerr << "Was in authentication" << std::endl; - m_Greeter.cancelAuthentication(); + m_Greeter->cancelAuthentication(); } cancelLoginTimer.stop(); ui->passwordInput->clear(); -- cgit v1.2.3-55-g7522