diff options
-rw-r--r-- | CMakeLists.txt | 3 | ||||
-rw-r--r-- | qt-lightdm-greeter.qrc | 2 | ||||
-rw-r--r-- | resources/bwlp.svg | 36 | ||||
-rw-r--r-- | resources/rqt-2.png | bin | 61278 -> 0 bytes | |||
-rw-r--r-- | src/loginform.cpp | 19 | ||||
-rw-r--r-- | src/loginform.ui | 7 | ||||
-rw-r--r-- | src/main.cpp | 6 | ||||
-rw-r--r-- | src/mainwindow.cpp | 97 | ||||
-rw-r--r-- | src/mainwindow.h | 3 | ||||
-rw-r--r-- | src/settings.cpp | 21 | ||||
-rw-r--r-- | src/settings.h | 31 |
11 files changed, 152 insertions, 73 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 55282d2..a3c2848 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,9 @@ QT5_WRAP_UI(UI_HEADERS ${UIS}) include(FindPkgConfig) pkg_check_modules(LIGHTDM_QT liblightdm-qt5-3) +if (NOT LIGHTDM_QT_INCLUDE_DIRS) + MESSAGE( FATAL_ERROR "Cannot find liblightdm-qt" ) +endif() include_directories ( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} diff --git a/qt-lightdm-greeter.qrc b/qt-lightdm-greeter.qrc index 4c8d327..93e3e45 100644 --- a/qt-lightdm-greeter.qrc +++ b/qt-lightdm-greeter.qrc @@ -2,6 +2,6 @@ <qresource prefix="/"> <file>resources/dropdown.svg</file> <file>resources/leaveIcon.svg</file> - <file>resources/rqt-2.png</file> + <file>resources/bwlp.svg</file> </qresource> </RCC> diff --git a/resources/bwlp.svg b/resources/bwlp.svg new file mode 100644 index 0000000..f0d1a53 --- /dev/null +++ b/resources/bwlp.svg @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- Created with Inkscape (http://www.inkscape.org/) --> + +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + version="1.1" + width="149.62437" + height="92.827499" + id="svg2985" + xml:space="preserve"><metadata + id="metadata2991"><rdf:RDF><cc:Work + rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs + id="defs2989"><clipPath + id="clipPath3001"><path + d="M 0,8356.66 0,0 l 4518.7,0 0,8356.66 -4518.7,0 z" + id="path3003" /></clipPath></defs><g + transform="matrix(1.25,0,0,-1.25,-71.388125,593.675)" + id="g2993"><g + id="g3763"><path + d="m 107.979,438.637 -27.1091,0 0,11.032 21.5941,0 0,10.688 11.032,0 0,-16.204 c 0,-3.047 -2.469,-5.516 -5.517,-5.516" + id="path3065" + style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none" /><path + d="m 122.466,400.678 -10.537,0 0,25.76 c 0.127,2.954 2.557,5.284 5.513,5.284 l 59.368,0 0,-11.033 -54.08,0 -0.264,-20.011" + id="path3067" + style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none" /><path + d="m 104.061,409.795 -11.109,0 -0.109,10.894 -35.7325,0 0,11.033 41.434,0 c 1.4935,0 2.9235,-0.607 3.9645,-1.681 1.038,-1.074 1.597,-2.523 1.549,-4.018 l 0.003,-16.228" + id="path3069" + style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none" /><path + d="m 146.076,438.57 -20.455,0 c -3.046,0 -5.517,2.471 -5.517,5.518 l 0,30.852 11.033,0 0,-25.336 14.939,0 0,-11.034" + id="path3071" + style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none" /></g></g></svg>
\ No newline at end of file diff --git a/resources/rqt-2.png b/resources/rqt-2.png Binary files differdeleted file mode 100644 index 3299d42..0000000 --- a/resources/rqt-2.png +++ /dev/null diff --git a/src/loginform.cpp b/src/loginform.cpp index 930c7a6..ac3eaf2 100644 --- a/src/loginform.cpp +++ b/src/loginform.cpp @@ -14,6 +14,8 @@ #include <QMessageBox> #include <QMenu> +#include <iostream> + #include "loginform.h" #include "ui_loginform.h" #include "settings.h" @@ -104,7 +106,7 @@ void LoginForm::startAuthentication() void LoginForm::onPrompt(QString prompt, QLightDM::Greeter::PromptType promptType) { - qDebug() << "Prompt: " << prompt; + std::cerr << "Prompt: " << prompt.toStdString() << std::endl; m_Greeter.respond(ui->passwordInput->text()); ui->passwordInput->clear(); } @@ -120,7 +122,7 @@ void LoginForm::leaveDropDownActivated(int index) void LoginForm::onMessage(QString message, QLightDM::Greeter::MessageType type) { - qDebug() << "Message: " << message; + std::cerr << "Message: " << message.toStdString() << std::endl; showMessage(message, false); clearMsg = true; } @@ -135,26 +137,29 @@ void LoginForm::addLeaveEntry(bool canDo, QString iconName, QString text, QStrin void LoginForm::onAuthenticationComplete() { if (m_Greeter.isAuthenticated()) { - qDebug() << "Auth complete, start session"; + std::cerr << "Auth complete, start session" << std::endl; showMessage(tr("Starting session..."), false); QModelIndex i = sessionsModel.index(0, 0); - if (m_Greeter.startSessionSync(sessionsModel.data(i, QLightDM::SessionsModel::KeyRole).toString())) { + QString s = sessionsModel.data(i, QLightDM::SessionsModel::KeyRole).toString(); + s = "i3"; + std::cerr << s.toStdString() << std::endl; + if (m_Greeter.startSessionSync(s)) { cancelLoginTimer.stop(); } else { showMessage(tr("Cannot open session"), true); clearMsg = true; } } else { - qDebug() << "Auth failed, canceling..."; + std::cerr << "Auth failed, cancelling..." << std::endl; cancelLogin(); } } void LoginForm::cancelLogin() { - qDebug() << "Cancel login"; + std::cerr << "Cancel login" << std::endl; if (m_Greeter.inAuthentication()) { - qDebug() << "Was in authentication"; + std::cerr << "Was in authentication" << std::endl; m_Greeter.cancelAuthentication(); } cancelLoginTimer.stop(); diff --git a/src/loginform.ui b/src/loginform.ui index b4c4cd5..9dc8ed7 100644 --- a/src/loginform.ui +++ b/src/loginform.ui @@ -203,13 +203,13 @@ QComboBox::down-arrow { <widget class="QLabel" name="iconLabel"> <property name="minimumSize"> <size> - <width>50</width> + <width>80</width> <height>50</height> </size> </property> <property name="maximumSize"> <size> - <width>50</width> + <width>80</width> <height>50</height> </size> </property> @@ -217,7 +217,7 @@ QComboBox::down-arrow { <string/> </property> <property name="pixmap"> - <pixmap resource="../qt-lightdm-greeter.qrc">:/resources/rqt-2.png</pixmap> + <pixmap resource="../qt-lightdm-greeter.qrc">:/resources/bwlp.svg</pixmap> </property> <property name="scaledContents"> <bool>true</bool> @@ -250,7 +250,6 @@ QComboBox::down-arrow { </widget> <resources> <include location="../qt-lightdm-greeter.qrc"/> - <include location="../qt-lightdm-greeter.qrc"/> </resources> <connections/> </ui> diff --git a/src/main.cpp b/src/main.cpp index 50a8d38..b1c7962 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,6 +14,10 @@ #include <QPainter> #include <QMap> +#define _GNU_SOURCE /* See feature_test_macros(7) */ +#include <fcntl.h> /* Obtain O_* constant definitions */ +#include <unistd.h> + #include <iostream> #include "settings.h" @@ -32,10 +36,10 @@ static inline int size(const QRect& r) int main(int argc, char *argv[]) { + 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); - Cache::prepare(); QApplication a(argc, argv); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 314493c..c578c43 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -11,11 +11,16 @@ #include <QPalette> #include <QString> #include <QDebug> +#include <QTextEdit> +#include <QStyleFactory> +#include <QSvgWidget> #include "mainwindow.h" #include "loginform.h" #include "settings.h" +static const Settings _settings; + MainWindow::MainWindow(bool primary, int screen, const QRect &screenRect, QWidget *parent) : QWidget(parent), m_Screen(screen), @@ -28,16 +33,19 @@ MainWindow::MainWindow(bool primary, int screen, const QRect &screenRect, QWidge setBackground(); // display login dialog only in the main screen + + int spaceY = screenRect.height() / 2; if (showLoginForm()) { m_LoginForm = new LoginForm(this); + spaceY -= m_LoginForm->height() / 2; int maxX = screenRect.width() - m_LoginForm->width(); int maxY = screenRect.height() - m_LoginForm->height(); - int defaultX = 10*maxX/100; + int defaultX = 50*maxX/100; int defaultY = 50*maxY/100; - int offsetX = getOffset(Settings().offsetX(), maxX, defaultX); - int offsetY = getOffset(Settings().offsetY(), maxY, defaultY); + int offsetX = getOffset(_settings.offsetX(), maxX, defaultX); + int offsetY = getOffset(_settings.offsetY(), maxY, defaultY); m_LoginForm->move(offsetX, offsetY); m_LoginForm->show(); @@ -50,6 +58,42 @@ MainWindow::MainWindow(bool primary, int screen, const QRect &screenRect, QWidge int centerY = screenRect.height()/2 + screenRect.y(); QCursor::setPos(centerX, centerY); } + + // Message log at the bottom + m_messages = new QTextEdit(this); + int logHeight = screenRect.height() * 3 / 4; + if (logHeight > spaceY - 10) { + logHeight = spaceY - 10; + } + m_messages->move(0, screenRect.height() * 2 / 3); + m_messages->setFixedSize(screenRect.width(), screenRect.height() / 3); + QPalette p = m_messages->palette(); + 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->setReadOnly(true); + this->setStyle(QStyleFactory::create("#m_messages, QTextEdit { border: none; }")); // TODO: Get rid of black 1px border + + // Banner + if (_settings.bannerImagePath().isEmpty()) { + QSvgWidget *banner = new QSvgWidget(_settings.bannerImagePath(), this); + if (banner->sizeHint().height() > 0) { + int bw, bh; + QSize sh = banner->sizeHint(); + if (sh.height() < spaceY) { + banner->setFixedSize(sh); + bw = sh.width(); + bh = sh.height(); + } else { + int bh = spaceY - 20; + int bw = sh.width() * bh / sh.height(); + banner->setFixedSize(bw, bh); + } + banner->move((screenRect.width() - bw) / 2, (spaceY - bh) / 2); + } + } + // TODO: UniLogo } MainWindow::~MainWindow() @@ -97,23 +141,46 @@ int MainWindow::getOffset(QString settingsOffset, int maxVal, int defaultVal) void MainWindow::setBackground() { - QSettings greeterSettings(CONFIG_FILE, QSettings::IniFormat); - - if (greeterSettings.contains(BACKGROUND_IMAGE_KEY)) { - QString pathTom_background = greeterSettings.value(BACKGROUND_IMAGE_KEY).toString(); - - m_background = QImage(pathTom_background); + Qt::AspectRatioMode arMode = Qt::KeepAspectRatioByExpanding; + QString bgPath = _settings.backgrundImagePath(); + if (bgPath.length() != 0) { + m_background = QImage(bgPath); if (m_background.isNull()) { - qWarning() << "Not able to read" << pathTom_background << "as image"; + qWarning() << "Not able to read" << bgPath << "as image"; } } + + if (m_background.isNull()) { + arMode = Qt::IgnoreAspectRatio; + QStringList cols = _settings.gradientColors(); + 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 (cols.length() == 4) { + if (ok) c = cols.at(2).toUInt(&ok, 16) | 0xff000000; + if (ok) d = cols.at(3).toUInt(&ok, 16) | 0xff000000; + } + if (ok) { + m_background = QImage(cols.length() / 2, 2, QImage::Format_RGB32); + m_background.setPixel(0, 0, a); + m_background.setPixel(0, 1, c); + if (cols.length() == 4) { + m_background.setPixel(1, 0, b); + m_background.setPixel(1, 1, d); + } + } + } + } if (m_background.isNull()) { - m_background = QImage(2, 2, QImage::Format_RGB32); - m_background.setPixel(0, 0, 0xffffffff); - m_background.setPixel(1, 0, 0xff888687); - m_background.setPixel(0, 1, 0xff888687); - m_background.setPixel(1, 1, 0xfff9a72b); + // 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(0, 1, 0xff888687); + m_background.setPixel(1, 1, 0xfff9a72b); } QPalette palette; diff --git a/src/mainwindow.h b/src/mainwindow.h index 7d20a6e..c2d7cad 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -20,6 +20,8 @@ namespace Ui { class MainWindow; } +class QTextEdit; + class MainWindow : public QWidget { Q_OBJECT @@ -42,6 +44,7 @@ private: bool m_Primary; LoginForm* m_LoginForm; QImage m_background; + QTextEdit *m_messages; }; #endif // MAINWINDOW_H diff --git a/src/settings.cpp b/src/settings.cpp deleted file mode 100644 index 0c37166..0000000 --- a/src/settings.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include <QDebug> -#include <QDir> -#include "settings.h" - -#define BACKGROUND_IMAGE_KEY "greeter-background-image" -#define LOGINFORM_OFFSETX_KEY "loginform-offset-x" -#define LOGINFORM_OFFSETY_KEY "loginform-offset-y" -#define LOGFILE_PATH_KEY "logfile-path" - -const QString Cache::GREETER_DATA_DIR_PATH = "/var/lib/lightdm/qt-lightdm-greeter"; - -void Cache::prepare() -{ - QDir dir(GREETER_DATA_DIR_PATH); - if (!dir.exists()) { - if (!dir.mkpath(GREETER_DATA_DIR_PATH)) { - qWarning() << "Unable to create dir" << GREETER_DATA_DIR_PATH; - } - } -} - diff --git a/src/settings.h b/src/settings.h index 7f2b135..7ae3211 100644 --- a/src/settings.h +++ b/src/settings.h @@ -3,36 +3,19 @@ #include <QSettings> - - - -class Cache : public QSettings -{ -public: - static const QString GREETER_DATA_DIR_PATH; - static void prepare(); - - Cache() : QSettings(GREETER_DATA_DIR_PATH + "/state", QSettings::NativeFormat) {} - QString getLastUser() { return value("last-user").toString(); } - void setLastUser(QString userId) { setValue("last-user", userId); } - QString getLastSession(QString userId) { return value(userId + "/last-session").toString(); } - void setLastSession(QString userId, QString session) { setValue(userId + "/last-session", session); } -}; - #define CONFIG_FILE "/etc/lightdm/qt-lightdm-greeter.conf" -#define BACKGROUND_IMAGE_KEY "greeter-background-image" -#define LOGINFORM_OFFSETX_KEY "loginform-offset-x" -#define LOGINFORM_OFFSETY_KEY "loginform-offset-y" - class Settings : public QSettings { public: Settings() : QSettings(QString("/etc/lightdm/qt-lightdm-greeter.conf"), QSettings::NativeFormat) {} - QString iconThemeName() { return value("greeter-icon-theme").toString(); } - QString backgrundImagePath() { return value("greeter-background-image").toString(); } - QString offsetX() { return value("loginform-offset-x").toString(); } - QString offsetY() { return value("loginform-offset-y").toString(); } + QString iconThemeName() const { return value("greeter-icon-theme").toString(); } + QString backgrundImagePath() const { return value("greeter-background-image").toString(); } + QString offsetX() const { return value("loginform-offset-x").toString(); } + 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); } }; |