Permalink
Browse files

Added razorqt-lightdm-greeter - a razor frontend to lightdm

  • Loading branch information...
1 parent 60df890 commit 922f71a451ceee7ea650f4b8aedc4e0e804a03de @surlykke surlykke committed Mar 4, 2012
View
@@ -68,7 +68,7 @@ add_subdirectory( razorqt-runner )
add_subdirectory( razorqt-config )
add_subdirectory( razorqt-power )
add_subdirectory( razorqt-policykit )
-
+add_subdirectory( razorqt-lightdm-greeter )
########### Add uninstall target ###############
CONFIGURE_FILE(
@@ -0,0 +1,75 @@
+set(PROJECT razor-lightdm-greeter)
+project($PROJECT)
+
+include(FindPkgConfig)
+pkg_check_modules(LIGHTDM_QT liblightdm-qt-1)
+
+
+if(NOT LIGHTDM_QT_INCLUDE_DIRS)
+ message(STATUS "Qt bindings for liblightdm not found. Razor-lightdm-greeter won't be built")
+ message(STATUS "Hint: On debian or debian-derived distributions you could probably do: sudo apt-get liblightdm-qt-1-dev")
+elseif(NOT LIGHTDM_QT_LIBRARIES)
+ message(STATUS "lightdm-qt library not found. Razor-lightdm-greeter won't be built")
+ message(STATUS "Hint: On debian or debian-derived distributions the package would be something like: liblightdm-qt-1-0")
+else()
+
+ ############### Patch #############################################################
+ # liblightdm-qt-1.pc (pkg-config file) erroneously reports includedir as
+ # /usr/include/lightdm-qt-0 and the library as lightdm-qt-0. So we have to patch
+ # Bug filed: https://bugs.launchpad.net/ubuntu/+source/lightdm/+bug/943914
+
+ foreach(INCLUDEDIR ${LIGHTDM_QT_INCLUDE_DIRS})
+ string(REPLACE "-qt-0" "-qt-1" INCLUDEDIR ${INCLUDEDIR})
+ list(APPEND TMP1 ${INCLUDEDIR})
+ endforeach()
+ set(LIGHTDM_QT_INCLUDE_DIRS ${TMP1})
+
+ foreach(LIBRARY ${LIGHTDM_QT_LIBRARIES})
+ string(REPLACE "-qt-0" "-qt-1" LIBRARY ${LIBRARY})
+ list(APPEND TMP2 ${LIBRARY})
+ endforeach()
+ set(LIGHTDM_QT_LIBRARIES ${TMP2})
+ ############## End patch #########################################################
+
+ include_directories (
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${CMAKE_SOURCE_DIR}/libraries/
+ ${CMAKE_SOURCE_DIR}/libraries/razorqt
+ ${LIGHTDM_QT_INCLUDE_DIRS}
+ )
+
+ set ( razor-lightdm-greeter_SRCS
+ main.cpp
+ mainwindow.cpp
+ loginform.cpp
+ )
+
+ set ( razor-lightdm-greeter_UIS
+ loginform.ui
+ )
+ QT4_WRAP_UI(UIS ${razor-lightdm-greeter_UIS})
+
+ set ( razor-lightdm-greeter_RSCS )
+ QT4_ADD_RESOURCES(RSCS ${razor-lightdm-greeter_RSCS})
+
+ set ( razor-lightdm-greeter_MOCS
+ mainwindow.h
+ loginform.h
+ )
+ QT4_WRAP_CPP(MOCS ${razor-lightdm-greeter_MOCS})
+
+ if(CMAKE_BUILD_TYPE MATCHES [Dd]ebug)
+ configure_file(test/test.sh test/test.sh)
+ configure_file(test/lightdm-razor-greeter.desktop test/lightdm-razor-greeter.desktop)
+ configure_file(test/lightdm.conf test/lightdm.conf)
+ endif()
+
+ add_executable ( razor-lightdm-greeter ${razor-lightdm-greeter_SRCS} ${UIS} ${RSCS} ${TRS} ${MOCS} )
+ target_link_libraries ( razor-lightdm-greeter razorqt ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTDBUS_LIBRARY} ${LIGHTDM_QT_LIBRARIES})
+
+ file(GLOB DESKTOP_FILES resources/*.desktop)
+
+ install(TARGETS ${PROJECT} RUNTIME DESTINATION bin)
+ install(FILES ${DESKTOP_FILES} DESTINATION /usr/share/xgreeters)
+endif()
@@ -0,0 +1,117 @@
+#include "loginform.h"
+#include "ui_loginform.h"
+#include <QDebug>
+#include <QLightDM/Session>
+#include <QLightDM/User>
+#include <QLightDM/System>
+#include <QCompleter>
+#include <QAbstractListModel>
+#include <QModelIndex>
+#include <QFile>
+#include <QTextStream>
+#include <QStringList>
+#include <QPixmap>
+#include <QMessageBox>
+#include <QModelIndex>
+#include <QMenu>
+#include <QProcess>
+#include <razorqt/razorsettings.h>
+
+LoginForm::LoginForm(QWidget *parent) : QWidget(parent), ui(new Ui::LoginForm)
+{
+ if (! m_Greeter.connectSync())
+ {
+ close();
+ }
+
+ ui->setupUi(this);
+ setStyleSheet(razorTheme->qss("razor-lightdm-greeter/razor-lightdm-greeter"));
+ ui->hostnameLabel->setFocus();
+
+ // Setup users
+ QLightDM::UsersModel *model = QLightDM::users();
+ QStringList userIds;
+ for (int i = 0; i < model->rowCount(QModelIndex()); i++)
+ {
+ QModelIndex index = model->index(i);
+ QString userId = model->data(index, Qt::UserRole).toString();
+ userIds << userId;
+ }
+ QCompleter *completer = new QCompleter(userIds);
+ completer->setCompletionMode(QCompleter::InlineCompletion);
+ ui->userIdInput->setCompleter(completer);
+
+
+ // Setup sessions
+ ui->sessionCombo->setModel(QLightDM::sessions());
+ for (int row = 0; row < ui->sessionCombo->model()->rowCount(); row++)
+ {
+ QModelIndex index = ui->sessionCombo->model()->index(row, 0);
+ if (QString("Razor Desktop") == ui->sessionCombo->model()->data(index, Qt::DisplayRole).toString())
+ {
+ ui->sessionCombo->setCurrentIndex(row);
+ break;
+ }
+ }
+
+ QPixmap icon(QString(SHARE_DIR) + "/graphics/rqt-2.svg");
+ ui->iconLabel->setPixmap(icon.scaled(ui->iconLabel->size()));
+
+ ui->hostnameLabel->setText(QLightDM::hostname());
+
+ connect(ui->loginButton, SIGNAL(clicked()), SLOT(doLogin()));
+ connect(ui->cancelButton, SIGNAL(clicked()), SLOT(doCancel()));
+ connect(&m_Greeter, SIGNAL(showPrompt(QString,QLightDM::PromptType)), this, SLOT(onPrompt(QString,QLightDM::PromptType)));
+ connect(&m_Greeter, SIGNAL(authenticationComplete()), this, SLOT(authenticationDone()));
+
+
+ connect(ui->leaveButton, SIGNAL(clicked()), SLOT(doLeave()));
+ connect(&m_razorPowerProcess, SIGNAL(finished(int)), this, SLOT(razorPowerDone()));
+}
+
+
+
+
+LoginForm::~LoginForm()
+{
+ delete ui;
+}
+
+void LoginForm::doLogin()
+{
+ m_Greeter.authenticate(ui->userIdInput->text());
+}
+
+void LoginForm::onPrompt(QString prompt, QLightDM::PromptType promptType)
+{
+ // We only handle password prompt
+ m_Greeter.respond(ui->passwordInput->text());
+}
+
+void LoginForm::authenticationDone()
+{
+ if (m_Greeter.isAuthenticated()) {
+ QString session = ui->sessionCombo->itemData(ui->sessionCombo->currentIndex(), QLightDM::SessionsModel::IdRole).toString();
+ m_Greeter.startSessionSync(session);
+ }
+ else {
+ doCancel();
+ }
+}
+
+
+void LoginForm::doCancel()
+{
+ ui->userIdInput->setText("");
+ ui->passwordInput->setText("");
+}
+
+void LoginForm::doLeave()
+{
+ m_razorPowerProcess.start("razor-power");
+ setEnabled(false);
+}
+
+void LoginForm::razorPowerDone() {
+ setEnabled(true);
+}
@@ -0,0 +1,36 @@
+#ifndef LOGINFORM_H
+#define LOGINFORM_H
+
+#include <QWidget>
+#include <QLightDM/Greeter>
+#include <QProcess>
+
+namespace Ui {
+class LoginForm;
+}
+
+class LoginForm : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit LoginForm(QWidget *parent = 0);
+ ~LoginForm();
+
+public slots:
+ void doLogin();
+ void doCancel();
+ void doLeave();
+ void razorPowerDone();
+ void onPrompt(QString prompt, QLightDM::PromptType promptType);
+ void authenticationDone();
+
+private:
+ Ui::LoginForm *ui;
+
+ QLightDM::Greeter m_Greeter;
+
+ QProcess m_razorPowerProcess;
+};
+
+#endif // LOGINFORM_H
Oops, something went wrong.

0 comments on commit 922f71a

Please sign in to comment.