summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2017-08-11 17:53:29 +0200
committerSimon Rettberg2017-08-11 17:53:29 +0200
commit1a32f34505fd7960304e15e5ca539be877d06c24 (patch)
tree2e825bb8e77033193777207343c6ffa7a52075b7
parentMove code to src/, tweak CMakeLists.txt (diff)
downloadslxgreeter-1a32f34505fd7960304e15e5ca539be877d06c24.tar.gz
slxgreeter-1a32f34505fd7960304e15e5ca539be877d06c24.tar.xz
slxgreeter-1a32f34505fd7960304e15e5ca539be877d06c24.zip
Strip unneeded stuff, simplify pam dialog handling, add safety timeout of 10 seconds
-rw-r--r--src/loginform.cpp173
-rw-r--r--src/loginform.h12
-rw-r--r--src/loginform.ui99
-rw-r--r--src/mainwindow.cpp5
4 files changed, 146 insertions, 143 deletions
diff --git a/src/loginform.cpp b/src/loginform.cpp
index 3f40e81..07d4094 100644
--- a/src/loginform.cpp
+++ b/src/loginform.cpp
@@ -23,27 +23,21 @@
#include "ui_loginform.h"
#include "settings.h"
-const int KeyRole = QLightDM::SessionsModel::KeyRole;
-
int rows(QAbstractItemModel& model) {
return model.rowCount(QModelIndex());
}
-QString displayData(QAbstractItemModel& model, int row, int role)
-{
- QModelIndex modelIndex = model.index(row, 0);
- return model.data(modelIndex, role).toString();
-}
-
LoginForm::LoginForm(QWidget *parent) :
QWidget(parent),
ui(new Ui::LoginForm),
m_Greeter(),
power(this),
- sessionsModel()
+ sessionsModel(),
+ clearMsg(false)
{
if (!m_Greeter.connectSync()) {
- close();
+ exit(0);
+ return;
}
ui->setupUi(this);
@@ -71,57 +65,55 @@ void LoginForm::initialize()
ui->iconLabel->setPixmap(icon.scaled(ui->iconLabel->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
ui->hostnameLabel->setText(m_Greeter.hostname());
- ui->sessionCombo->setModel(&sessionsModel);
-
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");
+ //addLeaveEntry(power.canHibernate(), "system-suspend-hibernate", tr("Hibernate"), "hibernate");
+ //addLeaveEntry(power.canSuspend(), "system-suspend", tr("Suspend"), "suspend");
ui->leaveComboBox->setDisabled(ui->leaveComboBox->count() <= 1);
- ui->sessionCombo->setCurrentIndex(0);
- setCurrentSession(m_Greeter.defaultSessionHint());
+ cancelLoginTimer.setInterval(10000);
+ cancelLoginTimer.setSingleShot(true);
+ connect(&cancelLoginTimer, SIGNAL(timeout()), this, SLOT(cancelLogin()));
- connect(ui->userInput, SIGNAL(editingFinished()), this, SLOT(userChanged()));
+ //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(authenticationComplete()), this, SLOT(authenticationComplete()));
+ 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->passwordInput->setEnabled(false);
ui->passwordInput->clear();
-
- if (! m_Greeter.hideUsersHint()) {
- QStringList knownUsers;
- QLightDM::UsersModel usersModel;
- for (int i = 0; i < usersModel.rowCount(QModelIndex()); i++) {
- knownUsers << usersModel.data(usersModel.index(i, 0), QLightDM::UsersModel::NameRole).toString();
- }
- ui->userInput->setCompleter(new QCompleter(knownUsers));
- ui->userInput->completer()->setCompletionMode(QCompleter::InlineCompletion);
- }
-
- QString user = Cache().getLastUser();
- if (user.isEmpty()) {
- user = m_Greeter.selectUserHint();
- }
- ui->userInput->setText(user);
- userChanged();
}
-void LoginForm::userChanged()
+void LoginForm::startAuthentication()
{
- setCurrentSession(Cache().getLastSession(ui->userInput->text()));
+ qDebug() << "Start auth";
+ //setCurrentSession(Cache().getLastSession(ui->userInput->text()));
- if (m_Greeter.inAuthentication()) {
- m_Greeter.cancelAuthentication();
- }
- if (! ui->userInput->text().isEmpty()) {
- m_Greeter.authenticate(ui->userInput->text());
- ui->passwordInput->setFocus();
+ if (m_Greeter.inAuthentication()) {
+ m_Greeter.cancelAuthentication();
+ }
+ if (ui->userInput->text().isEmpty()) {
+ ui->userInput->setFocus();
+ return;
}
- else {
- ui->userInput->setFocus();
+ if (ui->passwordInput->text().isEmpty()) {
+ ui->passwordInput->setFocus();
+ return;
}
+
+ ui->messageLabel->setText(tr("Logging in..."));
+ clearMsg = false;
+ ui->userInput->setEnabled(false);
+ ui->passwordInput->setEnabled(false);
+ cancelLoginTimer.start();
+ m_Greeter.authenticate(ui->userInput->text());
+}
+
+void LoginForm::onPrompt(QString prompt, QLightDM::Greeter::PromptType promptType)
+{
+ qDebug() << "Prompt: " << prompt;
+ m_Greeter.respond(ui->passwordInput->text());
+ ui->passwordInput->clear();
}
void LoginForm::leaveDropDownActivated(int index)
@@ -133,20 +125,13 @@ void LoginForm::leaveDropDownActivated(int index)
else if (actionName == "suspend") power.suspend();
}
-void LoginForm::respond()
+void LoginForm::onMessage(QString message, QLightDM::Greeter::MessageType type)
{
- m_Greeter.respond(ui->passwordInput->text().trimmed());
- ui->passwordInput->clear();
- ui->passwordInput->setEnabled(false);
-}
-
-void LoginForm::onPrompt(QString prompt, QLightDM::Greeter::PromptType promptType)
-{
- ui->passwordInput->setEnabled(true);
- ui->passwordInput->setFocus();
+ qDebug() << "Message: " << message;
+ ui->messageLabel->setText(message);
+ clearMsg = true;
}
-
void LoginForm::addLeaveEntry(bool canDo, QString iconName, QString text, QString actionName)
{
if (canDo) {
@@ -154,44 +139,64 @@ void LoginForm::addLeaveEntry(bool canDo, QString iconName, QString text, QStrin
}
}
-QString LoginForm::currentSession()
-{
- QModelIndex index = sessionsModel.index(ui->sessionCombo->currentIndex(), 0, QModelIndex());
- return sessionsModel.data(index, QLightDM::SessionsModel::KeyRole).toString();
-}
-
-void LoginForm::setCurrentSession(QString session)
+void LoginForm::onAuthenticationComplete()
{
- for (int i = 0; i < ui->sessionCombo->count(); i++) {
- if (session == sessionsModel.data(sessionsModel.index(i, 0), KeyRole).toString()) {
- ui->sessionCombo->setCurrentIndex(i);
- return;
+ if (m_Greeter.isAuthenticated()) {
+ qDebug() << "Auth complete, start session";
+ ui->messageLabel->setText(tr("Starting session..."));
+ QModelIndex i = sessionsModel.index(0, 0);
+ if (m_Greeter.startSessionSync(sessionsModel.data(i, QLightDM::SessionsModel::KeyRole).toString())) {
+ cancelLoginTimer.stop();
+ } else {
+ ui->messageLabel->setText(tr("Cannot open session"));
+ clearMsg = true;
}
+ } else {
+ qDebug() << "Auth failed, cancelling...";
+ cancelLogin();
}
}
-
-void LoginForm::authenticationComplete()
+void LoginForm::cancelLogin()
{
- if (m_Greeter.isAuthenticated()) {
- Cache().setLastUser(ui->userInput->text());
- Cache().setLastSession(ui->userInput->text(), currentSession());
- Cache().sync();
- m_Greeter.startSessionSync(currentSession());
- }
- else {
- ui->passwordInput->clear();
- userChanged();
- }
+ qDebug() << "Cancel login";
+ if (m_Greeter.inAuthentication()) {
+ qDebug() << "Was in authentication";
+ m_Greeter.cancelAuthentication();
+ }
+ cancelLoginTimer.stop();
+ ui->passwordInput->clear();
+ ui->userInput->setEnabled(true);
+ ui->passwordInput->setEnabled(true);
+ if (!clearMsg) {
+ ui->messageLabel->setText(tr("Login failed"));
+ }
+ ui->userInput->setFocus();
+ ui->userInput->selectAll();
+ clearMsg = true;
}
void LoginForm::keyPressEvent(QKeyEvent *event)
{
+ if (clearMsg) {
+ clearMsg = false;
+ ui->messageLabel->clear();
+ }
if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) {
- respond();
- }
- else {
- QWidget::keyPressEvent(event);
+ if (!ui->userInput->isEnabled()) {
+ // Ignore if auth in progress
+ return;
+ }
+ if (ui->userInput->hasFocus()) {
+ ui->passwordInput->setFocus();
+ return;
+ }
+ if (ui->passwordInput->hasFocus()) {
+ startAuthentication();
+ return;
+ }
}
+ // Fallback: Passthrough
+ QWidget::keyPressEvent(event);
}
diff --git a/src/loginform.h b/src/loginform.h
index 8346a58..6dfc390 100644
--- a/src/loginform.h
+++ b/src/loginform.h
@@ -14,6 +14,7 @@
#include <QKeyEvent>
#include <QGraphicsOpacityEffect>
#include <QMap>
+#include <QTimer>
#include <QLightDM/Power>
#include <QLightDM/Greeter>
@@ -37,11 +38,12 @@ public:
virtual void setFocus(Qt::FocusReason reason);
public slots:
- void userChanged();
+ void startAuthentication();
void leaveDropDownActivated(int index);
- void respond();
void onPrompt(QString prompt, QLightDM::Greeter::PromptType promptType);
- void authenticationComplete();
+ void onMessage(QString prompt, QLightDM::Greeter::MessageType messageType);
+ void onAuthenticationComplete();
+ void cancelLogin();
protected:
virtual void keyPressEvent(QKeyEvent *event);
@@ -59,6 +61,10 @@ private:
QLightDM::SessionsModel sessionsModel;
QMap<int, void (QLightDM::PowerInterface::*)()> powerSlots;
+
+ QTimer cancelLoginTimer;
+
+ bool clearMsg;
};
#endif // LOGINFORM_H
diff --git a/src/loginform.ui b/src/loginform.ui
index 3525a9d..b4c4cd5 100644
--- a/src/loginform.ui
+++ b/src/loginform.ui
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>350</width>
- <height>325</height>
+ <height>354</height>
</rect>
</property>
<property name="font">
@@ -34,7 +34,8 @@
}
QComboBox,
-QPushButton {
+QPushButton,
+#messageLabel {
border: 1px solid silver;
background-color: rgb(200, 200, 200);
}
@@ -103,32 +104,29 @@ QComboBox::down-arrow {
</property>
</widget>
</item>
- <item row="0" column="1">
- <widget class="QLabel" name="iconLabel">
+ <item row="5" column="1">
+ <widget class="QComboBox" name="leaveComboBox">
<property name="minimumSize">
<size>
- <width>50</width>
- <height>50</height>
+ <width>80</width>
+ <height>60</height>
</size>
</property>
<property name="maximumSize">
<size>
- <width>50</width>
- <height>50</height>
+ <width>80</width>
+ <height>60</height>
</size>
</property>
- <property name="text">
- <string/>
- </property>
- <property name="pixmap">
- <pixmap resource="qt-lightdm-greeter.qrc">:/resources/rqt-2.png</pixmap>
- </property>
- <property name="scaledContents">
- <bool>true</bool>
- </property>
- <property name="alignment">
- <set>Qt::AlignCenter</set>
- </property>
+ <item>
+ <property name="text">
+ <string/>
+ </property>
+ <property name="icon">
+ <iconset resource="../qt-lightdm-greeter.qrc">
+ <normaloff>:/resources/leaveIcon.svg</normaloff>:/resources/leaveIcon.svg</iconset>
+ </property>
+ </item>
</widget>
</item>
<item row="1" column="0" colspan="2">
@@ -160,7 +158,7 @@ QComboBox::down-arrow {
</property>
</widget>
</item>
- <item row="2" column="0" colspan="2">
+ <item row="3" column="0" colspan="2">
<widget class="QLineEdit" name="passwordInput">
<property name="minimumSize">
<size>
@@ -201,58 +199,48 @@ QComboBox::down-arrow {
</property>
</widget>
</item>
- <item row="3" column="0">
- <widget class="QComboBox" name="sessionCombo">
+ <item row="0" column="1">
+ <widget class="QLabel" name="iconLabel">
<property name="minimumSize">
<size>
- <width>200</width>
- <height>60</height>
+ <width>50</width>
+ <height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
- <width>10000</width>
- <height>60</height>
+ <width>50</width>
+ <height>50</height>
</size>
</property>
- <property name="font">
- <font>
- <family>Bitstream Vera Sans</family>
- <weight>50</weight>
- <bold>false</bold>
- </font>
+ <property name="text">
+ <string/>
</property>
- <property name="sizeAdjustPolicy">
- <enum>QComboBox::AdjustToContents</enum>
+ <property name="pixmap">
+ <pixmap resource="../qt-lightdm-greeter.qrc">:/resources/rqt-2.png</pixmap>
</property>
- <property name="frame">
+ <property name="scaledContents">
<bool>true</bool>
</property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
</widget>
</item>
- <item row="3" column="1">
- <widget class="QComboBox" name="leaveComboBox">
+ <item row="6" column="0" rowspan="2" colspan="2">
+ <widget class="QLabel" name="messageLabel">
<property name="minimumSize">
<size>
- <width>80</width>
- <height>60</height>
+ <width>200</width>
+ <height>30</height>
</size>
</property>
- <property name="maximumSize">
- <size>
- <width>80</width>
- <height>60</height>
- </size>
+ <property name="autoFillBackground">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string notr="true"/>
</property>
- <item>
- <property name="text">
- <string/>
- </property>
- <property name="icon">
- <iconset resource="qt-lightdm-greeter.qrc">
- <normaloff>:/resources/leaveIcon.svg</normaloff>:/resources/leaveIcon.svg</iconset>
- </property>
- </item>
</widget>
</item>
</layout>
@@ -261,7 +249,8 @@ QComboBox::down-arrow {
</layout>
</widget>
<resources>
- <include location="qt-lightdm-greeter.qrc"/>
+ <include location="../qt-lightdm-greeter.qrc"/>
+ <include location="../qt-lightdm-greeter.qrc"/>
</resources>
<connections/>
</ui>
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index a8dbd21..56f927f 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -117,7 +117,10 @@ void MainWindow::setBackground()
palette.setColor(QPalette::Background, Qt::black);
}
else {
- QBrush brush(backgroundImage.scaled(rect.width(), rect.height()));
+ backgroundImage = backgroundImage.scaled(rect.width(), rect.height(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
+ int xoff = (backgroundImage.width() - rect.width()) / 2;
+ int yoff = (backgroundImage.height() - rect.height()) / 2;
+ QBrush brush(backgroundImage.copy(xoff, yoff, backgroundImage.width(), backgroundImage.height()));
palette.setBrush(this->backgroundRole(), brush);
}
this->setPalette(palette);