summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2017-11-12 13:04:26 +0100
committerSimon Rettberg2017-11-12 13:04:26 +0100
commit542b440ad64b50f265b72246981d5e9d655eb4d4 (patch)
treeeecc5cca04dc8643662cdb1415ceeb03cc97a9c9
parentWORK IN PROGRESS! Add bwlp logo, banner support, log message window (diff)
downloadslxgreeter-542b440ad64b50f265b72246981d5e9d655eb4d4.tar.gz
slxgreeter-542b440ad64b50f265b72246981d5e9d655eb4d4.tar.xz
slxgreeter-542b440ad64b50f265b72246981d5e9d655eb4d4.zip
Fix banner display, gradient parsing, add test mode (--test)
-rw-r--r--src/loginform.cpp75
-rw-r--r--src/loginform.h10
-rw-r--r--src/main.cpp8
-rw-r--r--src/mainwindow.cpp25
-rw-r--r--src/mainwindow.h3
-rw-r--r--src/settings.h2
6 files changed, 70 insertions, 53 deletions
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();
diff --git a/src/loginform.h b/src/loginform.h
index b4dde7c..5e6f870 100644
--- a/src/loginform.h
+++ b/src/loginform.h
@@ -30,10 +30,8 @@ class LoginForm : public QWidget
{
Q_OBJECT
-friend class DecoratedUsersModel;
-
public:
- explicit LoginForm(QWidget *parent = 0);
+ explicit LoginForm(bool testMode, QWidget *parent = 0);
~LoginForm();
virtual void setFocus(Qt::FocusReason reason);
@@ -58,9 +56,9 @@ private:
Ui::LoginForm *ui;
- QLightDM::Greeter m_Greeter;
- QLightDM::PowerInterface power;
- QLightDM::SessionsModel sessionsModel;
+ QLightDM::Greeter *m_Greeter;
+ QLightDM::PowerInterface *power;
+ QLightDM::SessionsModel *sessionsModel;
QMap<int, void (QLightDM::PowerInterface::*)()> powerSlots;
diff --git a/src/main.cpp b/src/main.cpp
index b1c7962..769c570 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -14,7 +14,6 @@
#include <QPainter>
#include <QMap>
-#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <fcntl.h> /* Obtain O_* constant definitions */
#include <unistd.h>
@@ -36,7 +35,7 @@ static inline int size(const QRect& r)
int main(int argc, char *argv[])
{
- dup2(2, 1);
+ //dup2(2, 1)
// I have no idea why, but Qt's stock qDebug() output never makes it
// to /var/log/lightdm/x-0-greeter.log, so we use std::cerr instead..
qInstallMessageHandler(messageHandler);
@@ -52,7 +51,7 @@ int main(int argc, char *argv[])
// black
QImage entire;
QSize desktopSize = QApplication::desktop()->size();
- qDebug() << "Desktop full size is " << desktopSize;
+ qWarning() << "Desktop full size is " << desktopSize;
entire = QImage(desktopSize, QImage::Format_RGB32);
QPainter painter(&entire);
@@ -89,11 +88,12 @@ int main(int argc, char *argv[])
}
// Now set up all the screens
+ bool testMode = argc > 1 && QString(argv[1]) == QString("--test");
MainWindow *focusWindow = 0;
QMapIterator<int, QRect> it(screens);
while (it.hasNext()) {
it.next();
- MainWindow *w = new MainWindow(primary == it.key(), it.key(), it.value());
+ MainWindow *w = new MainWindow(primary == it.key(), it.key(), it.value(), testMode);
w->show();
if (w->showLoginForm()) {
focusWindow = w;
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index c578c43..f5bd274 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -10,7 +10,7 @@
#include <QDesktopWidget>
#include <QPalette>
#include <QString>
-#include <QDebug>
+#include <QtDebug>
#include <QTextEdit>
#include <QStyleFactory>
#include <QSvgWidget>
@@ -21,7 +21,7 @@
static const Settings _settings;
-MainWindow::MainWindow(bool primary, int screen, const QRect &screenRect, QWidget *parent) :
+MainWindow::MainWindow(bool primary, int screen, const QRect &screenRect, bool testMode, QWidget *parent) :
QWidget(parent),
m_Screen(screen),
m_Primary(primary)
@@ -37,7 +37,7 @@ MainWindow::MainWindow(bool primary, int screen, const QRect &screenRect, QWidge
int spaceY = screenRect.height() / 2;
if (showLoginForm()) {
- m_LoginForm = new LoginForm(this);
+ m_LoginForm = new LoginForm(testMode, this);
spaceY -= m_LoginForm->height() / 2;
int maxX = screenRect.width() - m_LoginForm->width();
@@ -71,13 +71,16 @@ MainWindow::MainWindow(bool primary, int screen, const QRect &screenRect, QWidge
p.setColor(QPalette::Base, QColor(0,0,0,0)); // r,g,b,A
QPalette::Light;
m_messages->setPalette(p);
- //m_messages->setText("TODO\nLogmessages\n\nWarnings\netc.");
+ m_messages->setFontPointSize(16);
+ //m_messages->setText("TODO\nLogmessages\n\nWarnings\netc."); TODO
m_messages->setReadOnly(true);
- this->setStyle(QStyleFactory::create("#m_messages, QTextEdit { border: none; }")); // TODO: Get rid of black 1px border
+ m_messages->setStyleSheet("border:none;");
// Banner
- if (_settings.bannerImagePath().isEmpty()) {
+ if (!_settings.bannerImagePath().isEmpty()) {
+ qWarning() << "Have banner " << _settings.bannerImagePath();
QSvgWidget *banner = new QSvgWidget(_settings.bannerImagePath(), this);
+ qWarning() << banner->sizeHint();
if (banner->sizeHint().height() > 0) {
int bw, bh;
QSize sh = banner->sizeHint();
@@ -154,15 +157,19 @@ void MainWindow::setBackground()
if (m_background.isNull()) {
arMode = Qt::IgnoreAspectRatio;
QStringList cols = _settings.gradientColors();
+ qWarning() << "Got list: " << cols;
if (cols.length() == 4 || cols.length() == 2) {
bool ok = true;
uint a, b, c, d;
- if (ok) c = a = cols.at(0).toUInt(&ok, 16) | 0xff000000;
- if (ok) d = b = cols.at(1).toUInt(&ok, 16) | 0xff000000;
+ 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 {
+ c = b;
}
+ qWarning() << a << b << c << d;
if (ok) {
m_background = QImage(cols.length() / 2, 2, QImage::Format_RGB32);
m_background.setPixel(0, 0, a);
@@ -178,7 +185,7 @@ void MainWindow::setBackground()
// Hard-coded default: Gradient
m_background = QImage(2, 2, QImage::Format_RGB32);
m_background.setPixel(0, 0, 0xffffffff);
- m_background.setPixel(1, 0, 0xff888687);
+ m_background.setPixel(1, 0, 0xffffffff);
m_background.setPixel(0, 1, 0xff888687);
m_background.setPixel(1, 1, 0xfff9a72b);
}
diff --git a/src/mainwindow.h b/src/mainwindow.h
index c2d7cad..a6d8196 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -10,7 +10,6 @@
#include <QWidget>
-#include <QLightDM/Greeter>
#include <QImage>
#include <QRect>
@@ -27,7 +26,7 @@ class MainWindow : public QWidget
Q_OBJECT
public:
- explicit MainWindow(bool primary, int screen, const QRect &rect, QWidget *parent = 0);
+ explicit MainWindow(bool primary, int screen, const QRect &rect, bool testMode, QWidget *parent = 0);
~MainWindow();
void setFocus(Qt::FocusReason reason);
diff --git a/src/settings.h b/src/settings.h
index 7ae3211..544adcd 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -15,7 +15,7 @@ public:
QString offsetY() const { return value("loginform-offset-y").toString(); }
QString miniIconPath() const { return value("loginform-mini-icon").toString(); }
QString bannerImagePath() const { return value("greeter-banner-image").toString(); }
- QStringList gradientColors() const { return value("greeter-background-gradient").toString().split("\\s", QString::SkipEmptyParts); }
+ QStringList gradientColors() const { return value("greeter-background-gradient").toString().split(QRegExp("\\s"), QString::SkipEmptyParts); }
};