From a84c640e8430216a71bf6085a22971a525f931d8 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Sat, 21 May 2011 20:15:11 +0100 Subject: Move library into a folder which matches it's namespace --- liblightdm-qt/Makefile.am | 43 -- liblightdm-qt/QLightDM/AuthRequest | 1 + liblightdm-qt/QLightDM/Greeter | 1 + liblightdm-qt/QLightDM/Language | 1 + liblightdm-qt/QLightDM/Makefile.am | 43 ++ liblightdm-qt/QLightDM/SessionsModel | 1 + liblightdm-qt/QLightDM/User | 1 + liblightdm-qt/QLightDM/greeter.cpp | 650 +++++++++++++++++++++++++++++++ liblightdm-qt/QLightDM/greeter.h | 107 +++++ liblightdm-qt/QLightDM/language.cpp | 53 +++ liblightdm-qt/QLightDM/language.h | 24 ++ liblightdm-qt/QLightDM/sessionsmodel.cpp | 91 +++++ liblightdm-qt/QLightDM/sessionsmodel.h | 27 ++ liblightdm-qt/QLightDM/user.cpp | 95 +++++ liblightdm-qt/QLightDM/user.h | 49 +++ liblightdm-qt/greeter.cpp | 650 ------------------------------- liblightdm-qt/greeter.h | 107 ----- liblightdm-qt/include/AuthRequest | 1 - liblightdm-qt/include/Greeter | 1 - liblightdm-qt/include/Language | 1 - liblightdm-qt/include/SessionsModel | 1 - liblightdm-qt/include/User | 1 - liblightdm-qt/language.cpp | 53 --- liblightdm-qt/language.h | 24 -- liblightdm-qt/sessionsmodel.cpp | 91 ----- liblightdm-qt/sessionsmodel.h | 27 -- liblightdm-qt/user.cpp | 95 ----- liblightdm-qt/user.h | 49 --- 28 files changed, 1144 insertions(+), 1144 deletions(-) delete mode 100644 liblightdm-qt/Makefile.am create mode 100644 liblightdm-qt/QLightDM/AuthRequest create mode 100644 liblightdm-qt/QLightDM/Greeter create mode 100644 liblightdm-qt/QLightDM/Language create mode 100644 liblightdm-qt/QLightDM/Makefile.am create mode 100644 liblightdm-qt/QLightDM/SessionsModel create mode 100644 liblightdm-qt/QLightDM/User create mode 100644 liblightdm-qt/QLightDM/greeter.cpp create mode 100644 liblightdm-qt/QLightDM/greeter.h create mode 100644 liblightdm-qt/QLightDM/language.cpp create mode 100644 liblightdm-qt/QLightDM/language.h create mode 100644 liblightdm-qt/QLightDM/sessionsmodel.cpp create mode 100644 liblightdm-qt/QLightDM/sessionsmodel.h create mode 100644 liblightdm-qt/QLightDM/user.cpp create mode 100644 liblightdm-qt/QLightDM/user.h delete mode 100644 liblightdm-qt/greeter.cpp delete mode 100644 liblightdm-qt/greeter.h delete mode 100644 liblightdm-qt/include/AuthRequest delete mode 100644 liblightdm-qt/include/Greeter delete mode 100644 liblightdm-qt/include/Language delete mode 100644 liblightdm-qt/include/SessionsModel delete mode 100644 liblightdm-qt/include/User delete mode 100644 liblightdm-qt/language.cpp delete mode 100644 liblightdm-qt/language.h delete mode 100644 liblightdm-qt/sessionsmodel.cpp delete mode 100644 liblightdm-qt/sessionsmodel.h delete mode 100644 liblightdm-qt/user.cpp delete mode 100644 liblightdm-qt/user.h (limited to 'liblightdm-qt') diff --git a/liblightdm-qt/Makefile.am b/liblightdm-qt/Makefile.am deleted file mode 100644 index f24b1592..00000000 --- a/liblightdm-qt/Makefile.am +++ /dev/null @@ -1,43 +0,0 @@ -lib_LTLIBRARIES = liblightdm-qt-0.la - -# Generate metadata for QObjects -MOC_FILES = \ - greeter_moc.cpp \ - sessionsmodel_moc.cpp - -greeter_moc.cpp: greeter.h - moc $< -o $@ -sessionsmodel_moc.cpp: sessionsmodel.h - moc $< -o $@ - -liblightdm_qt_0include_HEADERS = \ - greeter.h \ - language.h \ - sessionsmodel.h \ - user.h \ - include/Greeter \ - include/Language \ - include/SessionsModel \ - include/User -liblightdm_qt_0includedir=$(includedir)/lightdm-qt-0/lightdm - -liblightdm_qt_0_la_LIBADD = $(LIBLIGHTDM_QT_LIBS) -liblightdm_qt_0_la_CXXFLAGS = $(LIBLIGHTDM_QT_CFLAGS) \ - -DXSESSIONS_DIR=\"$(XSESSIONS_DIR)\" - -liblightdm_qt_0_la_SOURCES = \ - greeter.cpp \ - language.cpp \ - sessionsmodel.cpp \ - user.cpp \ - $(MOC_FILES) - -pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = liblightdm-qt-0.pc - -CLEANFILES = \ - $(MOC_FILES) - -DISTCLEANFILES = \ - Makefile.in \ - $(pkgconfig_DATA) diff --git a/liblightdm-qt/QLightDM/AuthRequest b/liblightdm-qt/QLightDM/AuthRequest new file mode 100644 index 00000000..1dd008ca --- /dev/null +++ b/liblightdm-qt/QLightDM/AuthRequest @@ -0,0 +1 @@ +#include "QLightDM/authrequest.h" \ No newline at end of file diff --git a/liblightdm-qt/QLightDM/Greeter b/liblightdm-qt/QLightDM/Greeter new file mode 100644 index 00000000..bcfa4a96 --- /dev/null +++ b/liblightdm-qt/QLightDM/Greeter @@ -0,0 +1 @@ +#include "QLightDM/greeter.h" \ No newline at end of file diff --git a/liblightdm-qt/QLightDM/Language b/liblightdm-qt/QLightDM/Language new file mode 100644 index 00000000..68d5513f --- /dev/null +++ b/liblightdm-qt/QLightDM/Language @@ -0,0 +1 @@ +#include "QLightDM/language.h" \ No newline at end of file diff --git a/liblightdm-qt/QLightDM/Makefile.am b/liblightdm-qt/QLightDM/Makefile.am new file mode 100644 index 00000000..61d1cba8 --- /dev/null +++ b/liblightdm-qt/QLightDM/Makefile.am @@ -0,0 +1,43 @@ +lib_LTLIBRARIES = liblightdm-qt-0.la + +# Generate metadata for QObjects +MOC_FILES = \ + greeter_moc.cpp \ + sessionsmodel_moc.cpp + +greeter_moc.cpp: greeter.h + moc $< -o $@ +sessionsmodel_moc.cpp: sessionsmodel.h + moc $< -o $@ + +liblightdm_qt_0include_HEADERS = \ + greeter.h \ + language.h \ + sessionsmodel.h \ + user.h \ + QLightDM/Greeter \ + QLightDM/Language \ + QLightDM/SessionsModel \ + QLightDM/User +liblightdm_qt_0includedir=$(includedir)/lightdm-qt-0/lightdm + +liblightdm_qt_0_la_LIBADD = $(LIBLIGHTDM_QT_LIBS) +liblightdm_qt_0_la_CXXFLAGS = $(LIBLIGHTDM_QT_CFLAGS) \ + -DXSESSIONS_DIR=\"$(XSESSIONS_DIR)\" + +liblightdm_qt_0_la_SOURCES = \ + greeter.cpp \ + language.cpp \ + sessionsmodel.cpp \ + user.cpp \ + $(MOC_FILES) + +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = liblightdm-qt-0.pc + +CLEANFILES = \ + $(MOC_FILES) + +DISTCLEANFILES = \ + Makefile.in \ + $(pkgconfig_DATA) diff --git a/liblightdm-qt/QLightDM/SessionsModel b/liblightdm-qt/QLightDM/SessionsModel new file mode 100644 index 00000000..7fe68741 --- /dev/null +++ b/liblightdm-qt/QLightDM/SessionsModel @@ -0,0 +1 @@ +#include "QLightDM/sessionsmodel.h" \ No newline at end of file diff --git a/liblightdm-qt/QLightDM/User b/liblightdm-qt/QLightDM/User new file mode 100644 index 00000000..968058f5 --- /dev/null +++ b/liblightdm-qt/QLightDM/User @@ -0,0 +1 @@ +#include "QLightDM/user.h" \ No newline at end of file diff --git a/liblightdm-qt/QLightDM/greeter.cpp b/liblightdm-qt/QLightDM/greeter.cpp new file mode 100644 index 00000000..607e50f2 --- /dev/null +++ b/liblightdm-qt/QLightDM/greeter.cpp @@ -0,0 +1,650 @@ +#include "greeter.h" + +#include "user.h" +#include "sessionsmodel.h" + +#include +#include +#include + +#include //needed for localHostName +#include +#include +#include +#include +#include + + +typedef enum +{ + /* Messages from the greeter to the server */ + GREETER_MESSAGE_CONNECT = 1, + GREETER_MESSAGE_START_AUTHENTICATION = 2, + GREETER_MESSAGE_CONTINUE_AUTHENTICATION = 3, + GREETER_MESSAGE_LOGIN = 4, + GREETER_MESSAGE_CANCEL_AUTHENTICATION = 5, + + /* Messages from the server to the greeter */ + GREETER_MESSAGE_CONNECTED = 101, + GREETER_MESSAGE_QUIT = 102, + GREETER_MESSAGE_PROMPT_AUTHENTICATION = 103, + GREETER_MESSAGE_END_AUTHENTICATION = 104 +} GreeterMessage; + +#define HEADER_SIZE 8 + +using namespace QLightDM; + +class GreeterPrivate +{ +public: + QString theme; + QString defaultLayout; + QString defaultSession; + QString timedUser; + int loginDelay; + + SessionsModel *sessionsModel; + + QSettings *config; + bool haveConfig; + + QList users; + bool haveUsers; + + QDBusInterface* lightdmInterface; + QDBusInterface* powerManagementInterface; + QDBusInterface* consoleKitInterface; + + int toServerFd; + int fromServerFd; + QSocketNotifier *n; + char *readBuffer; + int nRead; + bool inAuthentication; + bool isAuthenticated; + QString authenticationUser; +}; + + +Greeter::Greeter(QObject *parent) : + QObject(parent), + d(new GreeterPrivate) +{ + d->readBuffer = (char *)malloc (HEADER_SIZE); + d->nRead = 0; + d->haveConfig = false; + d->haveUsers = false; + + d->sessionsModel = new SessionsModel(this); +} + +Greeter::~Greeter() +{ + delete d->readBuffer; + delete d; +} + +static int intLength() +{ + return 4; +} + +static int stringLength(QString value) +{ + QByteArray a = value.toUtf8(); + return intLength() + a.size(); +} + +void Greeter::writeInt(int value) +{ + char buffer[4]; + buffer[0] = value >> 24; + buffer[1] = (value >> 16) & 0xFF; + buffer[2] = (value >> 8) & 0xFF; + buffer[3] = value & 0xFF; + if (write(d->toServerFd, buffer, intLength()) != intLength()) { + qDebug() << "Error writing to server"; + } +} + +void Greeter::writeString(QString value) +{ + QByteArray a = value.toUtf8(); + writeInt(a.size()); + if (write(d->toServerFd, a.data(), a.size()) != a.size()) { + qDebug() << "Error writing to server"; + } +} + +void Greeter::writeHeader(int id, int length) +{ + writeInt(id); + writeInt(length); +} + +void Greeter::flush() +{ + fsync(d->toServerFd); +} + +int Greeter::getPacketLength() +{ + int offset = intLength(); + return readInt(&offset); +} + +int Greeter::readInt(int *offset) +{ + if(d->nRead - *offset < intLength()) { + qDebug() << "Not enough space for int, need " << intLength() << ", got " << (d->nRead - *offset); + return 0; + } + + char *buffer = d->readBuffer + *offset; + int value = buffer[0] << 24 | buffer[1] << 16 | buffer[2] << 8 | buffer[3]; + *offset += intLength(); + return value; +} + +QString Greeter::readString(int *offset) +{ + int length = readInt(offset); + if(d->nRead - *offset < length) { + qDebug() << "Not enough space for string, need " << length << ", got " << (d->nRead - *offset); + return ""; + } + char *start = d->readBuffer + *offset; + *offset += length; + return QString::fromUtf8(start, length); +} + +void Greeter::connectToServer() +{ + QDBusConnection busType = QDBusConnection::systemBus(); + QString ldmBus(qgetenv("LDM_BUS")); + if(ldmBus == QLatin1String("SESSION")) { + busType = QDBusConnection::sessionBus(); + } + + + d->lightdmInterface = new QDBusInterface("org.lightdm.LightDisplayManager", "/org/lightdm/LightDisplayManager", "org.lightdm.LightDisplayManager", busType); + d->powerManagementInterface = new QDBusInterface("org.freedesktop.PowerManagement","/org/freedesktop/PowerManagement", "org.freedesktop.PowerManagement"); + d->consoleKitInterface = new QDBusInterface("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit"); + + char* fd = getenv("LDM_TO_SERVER_FD"); + if(!fd) { + qDebug() << "No LDM_TO_SERVER_FD environment variable"; + return; + } + d->toServerFd = atoi(fd); + + + qDebug() << "***connecting to server"; + QFile toServer; + qDebug() << toServer.open(d->toServerFd, QIODevice::WriteOnly); + + fd = getenv("LDM_FROM_SERVER_FD"); + if(!fd) { + qDebug() << "No LDM_FROM_SERVER_FD environment variable"; + return; + } + d->fromServerFd = atoi(fd); + + d->n = new QSocketNotifier(d->fromServerFd, QSocketNotifier::Read); + connect(d->n, SIGNAL(activated(int)), this, SLOT(onRead(int))); + + qDebug() << "Connecting to display manager..."; + writeHeader(GREETER_MESSAGE_CONNECT, 0); + flush(); +} + +void Greeter::startAuthentication(const QString &username) +{ + d->inAuthentication = true; + d->isAuthenticated = false; + d->authenticationUser = username; + qDebug() << "Starting authentication for user " << username << "..."; + writeHeader(GREETER_MESSAGE_START_AUTHENTICATION, stringLength(username)); + writeString(username); + flush(); +} + +void Greeter::provideSecret(const QString &secret) +{ + qDebug() << "Providing secret to display manager"; + writeHeader(GREETER_MESSAGE_CONTINUE_AUTHENTICATION, intLength() + stringLength(secret)); + // FIXME: Could be multiple secrets required + writeInt(1); + writeString(secret); + flush(); +} + +void Greeter::cancelAuthentication() +{ + qDebug() << "Cancelling authentication"; + writeHeader(GREETER_MESSAGE_CANCEL_AUTHENTICATION, 0); + flush(); +} + +bool Greeter::inAuthentication() const +{ + return d->inAuthentication; +} + +bool Greeter::isAuthenticated() const +{ + return d->isAuthenticated; +} + +QString Greeter::authenticationUser() const +{ + return d->authenticationUser; +} + +void Greeter::login(const QString &username, const QString &session, const QString &language) +{ + qDebug() << "Logging in as " << username << " for session " << session << " with language " << language; + writeHeader(GREETER_MESSAGE_LOGIN, stringLength(username) + stringLength(session) + stringLength(language)); + writeString(username); + writeString(session); + writeString(language); + flush(); +} + +void Greeter::loginWithDefaults(const QString &username) +{ + login(username, NULL, NULL); +} + +void Greeter::onRead(int fd) +{ + //qDebug() << "Reading from server"; + + int nToRead = HEADER_SIZE; + if(d->nRead >= HEADER_SIZE) + nToRead += getPacketLength(); + + ssize_t nRead; + nRead = read(fd, d->readBuffer + d->nRead, nToRead - d->nRead); + if(nRead < 0) + { + qDebug() << "Error reading from server"; + return; + } + if (nRead == 0) + { + qDebug() << "EOF reading from server"; + return; + } + + //qDebug() << "Read " << nRead << "octets"; + d->nRead += nRead; + if(d->nRead != nToRead) + return; + + /* If have header, rerun for content */ + if(d->nRead == HEADER_SIZE) + { + nToRead = getPacketLength(); + if(nToRead > 0) + { + d->readBuffer = (char *)realloc(d->readBuffer, HEADER_SIZE + nToRead); + onRead(fd); + return; + } + } + + int offset = 0; + int id = readInt(&offset); + readInt(&offset); + int nMessages, returnCode; + switch(id) + { + case GREETER_MESSAGE_CONNECTED: + d->theme = readString(&offset); + d->defaultLayout = readString(&offset); + d->defaultSession = readString(&offset); + d->timedUser = readString(&offset); + d->loginDelay = readInt(&offset); + qDebug() << "Connected theme=" << d->theme << " default-layout=" << d->defaultLayout << " default-session=" << d->defaultSession << " timed-user=" << d->timedUser << " login-delay" << d->loginDelay; + + /* Set timeout for default login */ + if(d->timedUser != "" && d->loginDelay > 0) + { + qDebug() << "Logging in as " << d->timedUser << " in " << d->loginDelay << " seconds"; + //FIXME: d->login_timeout = g_timeout_add (d->login_delay * 1000, timed_login_cb, greeter); + } + emit connected(); + break; + case GREETER_MESSAGE_QUIT: + qDebug() << "Got quit request from server"; + emit quit(); + break; + case GREETER_MESSAGE_PROMPT_AUTHENTICATION: + nMessages = readInt(&offset); + qDebug() << "Prompt user with " << nMessages << " message(s)"; + for(int i = 0; i < nMessages; i++) + { + int msg_style = readInt (&offset); + QString msg = readString (&offset); + + // FIXME: Should stop on prompts? + switch (msg_style) + { + case PAM_PROMPT_ECHO_OFF: + case PAM_PROMPT_ECHO_ON: + emit showPrompt(msg); + break; + case PAM_ERROR_MSG: + emit showError(msg); + break; + case PAM_TEXT_INFO: + emit showMessage(msg); + break; + } + } + break; + case GREETER_MESSAGE_END_AUTHENTICATION: + returnCode = readInt(&offset); + qDebug() << "Authentication complete with return code " << returnCode; + d->isAuthenticated = (returnCode == 0); + if(!d->isAuthenticated) { + d->authenticationUser = ""; + } + emit authenticationComplete(d->isAuthenticated); + d->inAuthentication = false; + break; + default: + qDebug() << "Unknown message from server: " << id; + } + + d->nRead = 0; +} + +QString Greeter::hostname() const +{ + return QHostInfo::localHostName(); +} + +QString Greeter::theme() const +{ + return d->theme; +} + +QVariant Greeter::getProperty(const QString &name) const +{ + return QVariant(); //FIXME TODO +} + +QString Greeter::defaultLanguage() const +{ + return getenv("LANG"); +} + +QString Greeter::defaultLayout() const +{ + return d->defaultLayout; +} + +QString Greeter::defaultSession() const +{ + return d->defaultSession; +} + +QString Greeter::timedLoginUser() const +{ + return d->timedUser; +} + +int Greeter::timedLoginDelay() const +{ + return d->loginDelay; +} + +void Greeter::loadConfig() +{ + if(d->haveConfig) + return; + + QString file; + if(false) + file = d->lightdmInterface->property("ConfigFile").toString(); + qDebug() << "Loading configuration from " << file; + d->config = new QSettings(file, QSettings::IniFormat); + + d->haveConfig = true; +} + +void Greeter::loadUsers() +{ + QStringList hiddenUsers, hiddenShells; + int minimumUid; + QList users, oldUsers, newUsers, changedUsers; + + loadConfig(); + + if(d->config->contains("UserManager/minimum-uid")) + minimumUid = d->config->value("UserManager/minimum-uid").toInt(); + else + minimumUid = 500; + + if (d->config->contains("UserManager/hidden-shells")) + hiddenUsers = d->config->value("UserManager/hidden-shells").toString().split(" "); + else + hiddenUsers << "nobody" << "nobody4" << "noaccess"; + + if (d->config->contains("UserManager/hidden-shells")) + hiddenShells = d->config->value("UserManager/hidden-shells").toString().split(" "); + else + hiddenShells << "/bin/false" << "/usr/sbin/nologin"; + + setpwent(); + + while(TRUE) + { + struct passwd *entry; + User *user; + QStringList tokens; + QString realName, image; + QFile *imageFile; + int i; + + errno = 0; + entry = getpwent(); + if(!entry) + break; + + /* Ignore system users */ + if(entry->pw_uid < minimumUid) + continue; + + /* Ignore users disabled by shell */ + if(entry->pw_shell) + { + for(i = 0; i < hiddenShells.size(); i++) + if(entry->pw_shell == hiddenShells.at(i)) + break; + if(i < hiddenShells.size()) + continue; + } + + /* Ignore certain users */ + for(i = 0; i < hiddenUsers.size(); i++) + if(entry->pw_name == hiddenUsers.at(i)) + break; + if(i < hiddenUsers.size()) + continue; + + tokens = QString(entry->pw_gecos).split(","); + if(tokens.size() > 0 && tokens.at(i) != "") + realName = tokens.at(i); + + QDir homeDir(entry->pw_dir); + imageFile = new QFile(homeDir.filePath(".face")); + if(!imageFile->exists()) + { + delete imageFile; + imageFile = new QFile(homeDir.filePath(".face.icon")); + } + if(imageFile->exists()) + image = "file://" + imageFile->fileName(); + delete imageFile; + + user = new User(entry->pw_name, realName, entry->pw_dir, image, FALSE); + + /* Update existing users if have them */ + bool matchedUser = false; + foreach(User *info, d->users) + { + if(info->name() == user->name()) + { + matchedUser = true; + if(info->update(user->realName(), user->homeDirectory(), user->image(), user->isLoggedIn())) + changedUsers.append(user); + delete user; + user = info; + break; + } + } + if(!matchedUser) + { + /* Only notify once we have loaded the user list */ + if(d->haveUsers) + newUsers.append(user); + } + users.append(user); + } + + if(errno != 0) + qDebug() << "Failed to read password database: " << strerror(errno); + + endpwent(); + + /* Use new user list */ + oldUsers = d->users; + d->users = users; + + /* Notify of changes */ + foreach(User *user, newUsers) + { + qDebug() << "User " << user->name() << " added"; + emit userAdded(user); + } + + foreach(User *user, changedUsers) + { + qDebug() << "User " << user->name() << " changed"; + emit userChanged(user); + } + + foreach(User *user, oldUsers) + { + /* See if this user is in the current list */ + bool existing = false; + foreach(User *new_user, d->users) + { + if (new_user == user) + { + existing = true; + break; + } + } + + if(!existing) + { + qDebug() << "User " << user->name() << " removed"; + emit userRemoved(user); + delete user; + } + } +} + +void Greeter::updateUsers() +{ + if (d->haveUsers) { + return; + } + + loadConfig(); + + /* User listing is disabled */ + if (d->config->contains("UserManager/load-users") && + !d->config->value("UserManager/load-users").toBool()) + { + d->haveUsers = true; + return; + } + + loadUsers(); + + d->haveUsers = true; +} + +QList Greeter::users() +{ + updateUsers(); + return d->users; +} + +SessionsModel* Greeter::sessionsModel() const +{ + return d->sessionsModel; +} + + +bool Greeter::canSuspend() const +{ + QDBusReply reply = d->powerManagementInterface->call("CanSuspend"); + if (reply.isValid()) + return reply.value(); + else + return false; +} + +void Greeter::suspend() +{ + d->powerManagementInterface->call("Suspend"); +} + +bool Greeter::canHibernate() const +{ + QDBusReply reply = d->powerManagementInterface->call("CanHibernate"); + if (reply.isValid()) + return reply.value(); + else + return false; +} + +void Greeter::hibernate() +{ + d->powerManagementInterface->call("Hibernate"); +} + +bool Greeter::canShutdown() const +{ + QDBusReply reply = d->consoleKitInterface->call("CanStop"); + if (reply.isValid()) + return reply.value(); + else + return false; +} + +void Greeter::shutdown() +{ + d->consoleKitInterface->call("stop"); +} + +bool Greeter::canRestart() const +{ + QDBusReply reply = d->consoleKitInterface->call("CanRestart"); + if (reply.isValid()) + return reply.value(); + else + return false; +} + +void Greeter::restart() +{ + d->consoleKitInterface->call("Restart"); +} diff --git a/liblightdm-qt/QLightDM/greeter.h b/liblightdm-qt/QLightDM/greeter.h new file mode 100644 index 00000000..743cbc13 --- /dev/null +++ b/liblightdm-qt/QLightDM/greeter.h @@ -0,0 +1,107 @@ +#ifndef QLIGTHDM_GREETER_H +#define QLIGTHDM_GREETER_H + +#include +class GreeterPrivate; + +#include "user.h" +#include "language.h" +//#include "ldmlayout.h" + +class GreeterPrivate; + +namespace QLightDM +{ + class SessionsModel; + + class Q_DECL_EXPORT Greeter : public QObject + { + Q_OBJECT + public: + explicit Greeter(QObject* parent=0); + virtual ~Greeter(); + + Q_PROPERTY(bool canSuspend READ canSuspend); + Q_PROPERTY(bool canHibernate READ canHibernate); + Q_PROPERTY(bool canShutdown READ canShutdown); + Q_PROPERTY(bool canRestart READ canRestart); + + Q_PROPERTY(QString hostname READ hostname); + + /** The hostname of the machine */ + QString hostname() const; + QString theme() const; + + QVariant getProperty(const QString &name) const; + + QString timedLoginUser() const; + int timedLoginDelay() const; + + QList users(); + void getUserDefaults(const QString &name, const QString &language, const QString &layout, const QString &session); + + QList languages() const; + QString defaultLanguage() const; + + //QList layouts() const; + QString defaultLayout() const; + QString layout() const; + + QLightDM::SessionsModel *sessionsModel() const; + QString defaultSession() const; + + bool inAuthentication() const; + bool isAuthenticated() const; + QString authenticationUser() const; + + void connectToServer(); + void cancelTimedLogin(); + void startAuthentication(const QString &username); + void provideSecret(const QString &secret); + void cancelAuthentication(); + void login(const QString &username, const QString &session, const QString &language); + void loginWithDefaults(const QString &username); + + bool canSuspend() const; + bool canHibernate() const; + bool canShutdown() const; + bool canRestart() const; + + public slots: + void suspend(); + void hibernate(); + void shutdown(); + void restart(); + + signals: + void connected(); + void showPrompt(QString prompt); + void showMessage(QString message); + void showError(QString message); + void authenticationComplete(bool isAuthenticated); + void timedLogin(QString username); + void userAdded(User *user); + void userChanged(User *user); + void userRemoved(User *user); + void quit(); + + private slots: + void onRead(int fd); + + private: + GreeterPrivate *d; + void writeInt(int value); + void writeString(QString value); + void writeHeader(int id, int length); + void flush(); + int getPacketLength(); + int readInt(int *offset); + QString readString(int *offset); + void loadConfig(); + void loadUsers(); + void updateUsers(); + }; + +};//end namespace + +#endif // LDMGREETER_H diff --git a/liblightdm-qt/QLightDM/language.cpp b/liblightdm-qt/QLightDM/language.cpp new file mode 100644 index 00000000..e160d19e --- /dev/null +++ b/liblightdm-qt/QLightDM/language.cpp @@ -0,0 +1,53 @@ +#include "language.h" + +using namespace QLightDM; + +class LanguagePrivate +{ +public: + QString code; + QString name; + QString territory; +}; + +Language::Language(QString &code, QString &name, QString &territory) + : d(new LanguagePrivate) +{ + d->code = code; + d->name = name; + d->territory = territory; +} + +Language::Language(const Language &other) + :d(new LanguagePrivate(*other.d)) +{ +} + +Language::~Language() +{ + delete d; +} + +Language& Language::operator=(const Language& other) +{ + *d = *other.d; + return *this; +} + + +QString Language::code() const +{ + return d->code; +} + +QString Language::name() const +{ + return d->name; +} + +QString Language::territory() const +{ + return d->territory; +} + + diff --git a/liblightdm-qt/QLightDM/language.h b/liblightdm-qt/QLightDM/language.h new file mode 100644 index 00000000..3b239086 --- /dev/null +++ b/liblightdm-qt/QLightDM/language.h @@ -0,0 +1,24 @@ +#ifndef QLIGTHDM_LANGUAGE_H +#define QLIGTHDM_LANGUAGE_H +#include + +class LanguagePrivate; + +namespace QLightDM { + class Language + { + public: + Language(QString &code, QString &name, QString &territory); + ~Language(); + Language(const Language& other); + Language &operator=(const Language& other); + + QString code() const; + QString name() const; + QString territory() const; + private: + LanguagePrivate* d; + }; +}; + +#endif // LDMLANGUAGE_H diff --git a/liblightdm-qt/QLightDM/sessionsmodel.cpp b/liblightdm-qt/QLightDM/sessionsmodel.cpp new file mode 100644 index 00000000..f8aaa332 --- /dev/null +++ b/liblightdm-qt/QLightDM/sessionsmodel.cpp @@ -0,0 +1,91 @@ +#include "sessionsmodel.h" + +#include +#include +#include +#include + +using namespace QLightDM; + +class SessionItem; + +class SessionsModelPrivate +{ +public: + QList items; +}; + +class SessionItem +{ +public: + //FIXME can I make these consts, if I set them in a lovely constructor? + QString id; + QString name; + QString comment; +}; + +SessionsModel::SessionsModel(QObject *parent) : + QAbstractListModel(parent), + d(new SessionsModelPrivate()) +{ + buildList(); +} + +SessionsModel::~SessionsModel() +{ +} + +int SessionsModel::rowCount(const QModelIndex &parent) const +{ + if (parent == QModelIndex()) { //if top level + return d->items.size(); + } else { + return 0; // no child elements. + } +} + +QVariant SessionsModel::data(const QModelIndex &index, int role) const +{ + if (! index.isValid()) { + return QVariant(); + } + + int row = index.row(); + + switch (role) { + case Qt::DisplayRole: + return d->items[row].name; + case Qt::ToolTipRole: + return d->items[row].comment; + + } + return QVariant(); +} + +void SessionsModel::buildList() +{ + //maybe clear first? + + //FIXME don't hardcode this! + QDir sessionDir("/usr/share/xsessions"); + sessionDir.setNameFilters(QStringList() << "*.desktop"); + + QList items; + + foreach(QString sessionFileName, sessionDir.entryList()) { + QSettings sessionData(sessionDir.filePath(sessionFileName), QSettings::IniFormat); + sessionData.beginGroup("Desktop Entry"); + sessionFileName.chop(8);// chop(8) removes '.desktop' + + SessionItem item; + item.id = sessionFileName; + item.name = sessionData.value("Name").toString(); + item.comment = sessionData.value("Comment").toString(); + items.append(item); + } + + beginInsertRows(QModelIndex(), 0, items.size()); + d->items.append(items); + endInsertRows(); +} + diff --git a/liblightdm-qt/QLightDM/sessionsmodel.h b/liblightdm-qt/QLightDM/sessionsmodel.h new file mode 100644 index 00000000..c93f8e8e --- /dev/null +++ b/liblightdm-qt/QLightDM/sessionsmodel.h @@ -0,0 +1,27 @@ +#ifndef QLIGTHDM_SESSIONSMODEL_H +#define QLIGTHDM_SESSIONSMODEL_H + +#include + +class SessionsModelPrivate; + +namespace QLightDM { + class Q_DECL_EXPORT SessionsModel : public QAbstractListModel + { + Q_OBJECT + public: + enum SessionModelRoles {IdRole = Qt::UserRole}; + + explicit SessionsModel(QObject *parent = 0); + virtual ~SessionsModel(); + + int rowCount(const QModelIndex &parent) const; + QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const; + + private: + SessionsModelPrivate *d; + void buildList(); //maybe make this a public slot, which apps can call only if they give a care about the session. + }; +}; + +#endif // LDMSESSIONSMODEL_H diff --git a/liblightdm-qt/QLightDM/user.cpp b/liblightdm-qt/QLightDM/user.cpp new file mode 100644 index 00000000..3a9d68e3 --- /dev/null +++ b/liblightdm-qt/QLightDM/user.cpp @@ -0,0 +1,95 @@ +#include "user.h" + +using namespace QLightDM; + +class UserPrivate +{ +public: + QString name; + QString realName; + QString homeDirectory; + QString image; + bool isLoggedIn; +}; + +User::User(): + d(new UserPrivate) +{ +} + +User::User(const QString& name, const QString& realName, const QString& homeDirectory, const QString& image, bool isLoggedIn) : + d(new UserPrivate) +{ + d->name = name; + d->realName = realName; + d->homeDirectory = homeDirectory; + d->image = image; + d->isLoggedIn = isLoggedIn; +} + +User::User(const User &other) + :d(new UserPrivate(*other.d)) +{ +} + +User::~User() +{ + delete d; +} + + +User& User::operator=(const User& other) +{ + *d = *other.d; + return *this; +} + +bool User::update(const QString& realName, const QString& homeDirectory, const QString& image, bool isLoggedIn) +{ + if (d->realName == realName && d->homeDirectory == homeDirectory && d->image == image && d->isLoggedIn == isLoggedIn) + return false; + + d->realName = realName; + d->homeDirectory = homeDirectory; + d->image = image; + d->isLoggedIn = isLoggedIn; + + return true; +} + +QString User::displayName() const +{ + if (!d->realName.isEmpty()) + { + return d->realName; + } + else + { + return d->name; + } +} + +QString User::name() const +{ + return d->name; +} + +QString User::realName() const +{ + return d->realName; +} + +QString User::homeDirectory() const +{ + return d->homeDirectory; +} + +QString User::image() const +{ + return d->image; +} + +bool User::isLoggedIn() const +{ + return d->isLoggedIn; +} diff --git a/liblightdm-qt/QLightDM/user.h b/liblightdm-qt/QLightDM/user.h new file mode 100644 index 00000000..f17211b3 --- /dev/null +++ b/liblightdm-qt/QLightDM/user.h @@ -0,0 +1,49 @@ +#ifndef QLIGTHDM_USER_H +#define QLIGTHDM_USER_H + +#include +#include + +class UserPrivate; + +namespace QLightDM +{ + //public facing User class + class Q_DECL_EXPORT User + { + public: + explicit User(); + User(const QString &name, const QString &realName, const QString &homeDirectory, const QString &image, bool isLoggedIn); + User(const User& other); + ~User(); + User &operator=(const User& other); + + bool update(const QString &realName, const QString &homeDirectory, const QString &image, bool isLoggedIn); + + /** The name to display (the real name if available, otherwise use the username */ + QString displayName() const; + + /** The username of the user*/ + QString name() const; + /** The user's real name, use this for displaying*/ + QString realName() const; + + /** Returns the home directory of this user*/ + QString homeDirectory() const; + + /** Returns the path to an avatar of this user*/ + QString image() const; + + /** Returns true if this user is already logged in on another session*/ + bool isLoggedIn() const; + + // LdmUser &operator=(const LdmUser user); + private: + UserPrivate* d; + }; +} + +Q_DECLARE_METATYPE(QLightDM::User); +Q_DECLARE_METATYPE(QList); + +#endif // LDMUSER_H diff --git a/liblightdm-qt/greeter.cpp b/liblightdm-qt/greeter.cpp deleted file mode 100644 index 607e50f2..00000000 --- a/liblightdm-qt/greeter.cpp +++ /dev/null @@ -1,650 +0,0 @@ -#include "greeter.h" - -#include "user.h" -#include "sessionsmodel.h" - -#include -#include -#include - -#include //needed for localHostName -#include -#include -#include -#include -#include - - -typedef enum -{ - /* Messages from the greeter to the server */ - GREETER_MESSAGE_CONNECT = 1, - GREETER_MESSAGE_START_AUTHENTICATION = 2, - GREETER_MESSAGE_CONTINUE_AUTHENTICATION = 3, - GREETER_MESSAGE_LOGIN = 4, - GREETER_MESSAGE_CANCEL_AUTHENTICATION = 5, - - /* Messages from the server to the greeter */ - GREETER_MESSAGE_CONNECTED = 101, - GREETER_MESSAGE_QUIT = 102, - GREETER_MESSAGE_PROMPT_AUTHENTICATION = 103, - GREETER_MESSAGE_END_AUTHENTICATION = 104 -} GreeterMessage; - -#define HEADER_SIZE 8 - -using namespace QLightDM; - -class GreeterPrivate -{ -public: - QString theme; - QString defaultLayout; - QString defaultSession; - QString timedUser; - int loginDelay; - - SessionsModel *sessionsModel; - - QSettings *config; - bool haveConfig; - - QList users; - bool haveUsers; - - QDBusInterface* lightdmInterface; - QDBusInterface* powerManagementInterface; - QDBusInterface* consoleKitInterface; - - int toServerFd; - int fromServerFd; - QSocketNotifier *n; - char *readBuffer; - int nRead; - bool inAuthentication; - bool isAuthenticated; - QString authenticationUser; -}; - - -Greeter::Greeter(QObject *parent) : - QObject(parent), - d(new GreeterPrivate) -{ - d->readBuffer = (char *)malloc (HEADER_SIZE); - d->nRead = 0; - d->haveConfig = false; - d->haveUsers = false; - - d->sessionsModel = new SessionsModel(this); -} - -Greeter::~Greeter() -{ - delete d->readBuffer; - delete d; -} - -static int intLength() -{ - return 4; -} - -static int stringLength(QString value) -{ - QByteArray a = value.toUtf8(); - return intLength() + a.size(); -} - -void Greeter::writeInt(int value) -{ - char buffer[4]; - buffer[0] = value >> 24; - buffer[1] = (value >> 16) & 0xFF; - buffer[2] = (value >> 8) & 0xFF; - buffer[3] = value & 0xFF; - if (write(d->toServerFd, buffer, intLength()) != intLength()) { - qDebug() << "Error writing to server"; - } -} - -void Greeter::writeString(QString value) -{ - QByteArray a = value.toUtf8(); - writeInt(a.size()); - if (write(d->toServerFd, a.data(), a.size()) != a.size()) { - qDebug() << "Error writing to server"; - } -} - -void Greeter::writeHeader(int id, int length) -{ - writeInt(id); - writeInt(length); -} - -void Greeter::flush() -{ - fsync(d->toServerFd); -} - -int Greeter::getPacketLength() -{ - int offset = intLength(); - return readInt(&offset); -} - -int Greeter::readInt(int *offset) -{ - if(d->nRead - *offset < intLength()) { - qDebug() << "Not enough space for int, need " << intLength() << ", got " << (d->nRead - *offset); - return 0; - } - - char *buffer = d->readBuffer + *offset; - int value = buffer[0] << 24 | buffer[1] << 16 | buffer[2] << 8 | buffer[3]; - *offset += intLength(); - return value; -} - -QString Greeter::readString(int *offset) -{ - int length = readInt(offset); - if(d->nRead - *offset < length) { - qDebug() << "Not enough space for string, need " << length << ", got " << (d->nRead - *offset); - return ""; - } - char *start = d->readBuffer + *offset; - *offset += length; - return QString::fromUtf8(start, length); -} - -void Greeter::connectToServer() -{ - QDBusConnection busType = QDBusConnection::systemBus(); - QString ldmBus(qgetenv("LDM_BUS")); - if(ldmBus == QLatin1String("SESSION")) { - busType = QDBusConnection::sessionBus(); - } - - - d->lightdmInterface = new QDBusInterface("org.lightdm.LightDisplayManager", "/org/lightdm/LightDisplayManager", "org.lightdm.LightDisplayManager", busType); - d->powerManagementInterface = new QDBusInterface("org.freedesktop.PowerManagement","/org/freedesktop/PowerManagement", "org.freedesktop.PowerManagement"); - d->consoleKitInterface = new QDBusInterface("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit"); - - char* fd = getenv("LDM_TO_SERVER_FD"); - if(!fd) { - qDebug() << "No LDM_TO_SERVER_FD environment variable"; - return; - } - d->toServerFd = atoi(fd); - - - qDebug() << "***connecting to server"; - QFile toServer; - qDebug() << toServer.open(d->toServerFd, QIODevice::WriteOnly); - - fd = getenv("LDM_FROM_SERVER_FD"); - if(!fd) { - qDebug() << "No LDM_FROM_SERVER_FD environment variable"; - return; - } - d->fromServerFd = atoi(fd); - - d->n = new QSocketNotifier(d->fromServerFd, QSocketNotifier::Read); - connect(d->n, SIGNAL(activated(int)), this, SLOT(onRead(int))); - - qDebug() << "Connecting to display manager..."; - writeHeader(GREETER_MESSAGE_CONNECT, 0); - flush(); -} - -void Greeter::startAuthentication(const QString &username) -{ - d->inAuthentication = true; - d->isAuthenticated = false; - d->authenticationUser = username; - qDebug() << "Starting authentication for user " << username << "..."; - writeHeader(GREETER_MESSAGE_START_AUTHENTICATION, stringLength(username)); - writeString(username); - flush(); -} - -void Greeter::provideSecret(const QString &secret) -{ - qDebug() << "Providing secret to display manager"; - writeHeader(GREETER_MESSAGE_CONTINUE_AUTHENTICATION, intLength() + stringLength(secret)); - // FIXME: Could be multiple secrets required - writeInt(1); - writeString(secret); - flush(); -} - -void Greeter::cancelAuthentication() -{ - qDebug() << "Cancelling authentication"; - writeHeader(GREETER_MESSAGE_CANCEL_AUTHENTICATION, 0); - flush(); -} - -bool Greeter::inAuthentication() const -{ - return d->inAuthentication; -} - -bool Greeter::isAuthenticated() const -{ - return d->isAuthenticated; -} - -QString Greeter::authenticationUser() const -{ - return d->authenticationUser; -} - -void Greeter::login(const QString &username, const QString &session, const QString &language) -{ - qDebug() << "Logging in as " << username << " for session " << session << " with language " << language; - writeHeader(GREETER_MESSAGE_LOGIN, stringLength(username) + stringLength(session) + stringLength(language)); - writeString(username); - writeString(session); - writeString(language); - flush(); -} - -void Greeter::loginWithDefaults(const QString &username) -{ - login(username, NULL, NULL); -} - -void Greeter::onRead(int fd) -{ - //qDebug() << "Reading from server"; - - int nToRead = HEADER_SIZE; - if(d->nRead >= HEADER_SIZE) - nToRead += getPacketLength(); - - ssize_t nRead; - nRead = read(fd, d->readBuffer + d->nRead, nToRead - d->nRead); - if(nRead < 0) - { - qDebug() << "Error reading from server"; - return; - } - if (nRead == 0) - { - qDebug() << "EOF reading from server"; - return; - } - - //qDebug() << "Read " << nRead << "octets"; - d->nRead += nRead; - if(d->nRead != nToRead) - return; - - /* If have header, rerun for content */ - if(d->nRead == HEADER_SIZE) - { - nToRead = getPacketLength(); - if(nToRead > 0) - { - d->readBuffer = (char *)realloc(d->readBuffer, HEADER_SIZE + nToRead); - onRead(fd); - return; - } - } - - int offset = 0; - int id = readInt(&offset); - readInt(&offset); - int nMessages, returnCode; - switch(id) - { - case GREETER_MESSAGE_CONNECTED: - d->theme = readString(&offset); - d->defaultLayout = readString(&offset); - d->defaultSession = readString(&offset); - d->timedUser = readString(&offset); - d->loginDelay = readInt(&offset); - qDebug() << "Connected theme=" << d->theme << " default-layout=" << d->defaultLayout << " default-session=" << d->defaultSession << " timed-user=" << d->timedUser << " login-delay" << d->loginDelay; - - /* Set timeout for default login */ - if(d->timedUser != "" && d->loginDelay > 0) - { - qDebug() << "Logging in as " << d->timedUser << " in " << d->loginDelay << " seconds"; - //FIXME: d->login_timeout = g_timeout_add (d->login_delay * 1000, timed_login_cb, greeter); - } - emit connected(); - break; - case GREETER_MESSAGE_QUIT: - qDebug() << "Got quit request from server"; - emit quit(); - break; - case GREETER_MESSAGE_PROMPT_AUTHENTICATION: - nMessages = readInt(&offset); - qDebug() << "Prompt user with " << nMessages << " message(s)"; - for(int i = 0; i < nMessages; i++) - { - int msg_style = readInt (&offset); - QString msg = readString (&offset); - - // FIXME: Should stop on prompts? - switch (msg_style) - { - case PAM_PROMPT_ECHO_OFF: - case PAM_PROMPT_ECHO_ON: - emit showPrompt(msg); - break; - case PAM_ERROR_MSG: - emit showError(msg); - break; - case PAM_TEXT_INFO: - emit showMessage(msg); - break; - } - } - break; - case GREETER_MESSAGE_END_AUTHENTICATION: - returnCode = readInt(&offset); - qDebug() << "Authentication complete with return code " << returnCode; - d->isAuthenticated = (returnCode == 0); - if(!d->isAuthenticated) { - d->authenticationUser = ""; - } - emit authenticationComplete(d->isAuthenticated); - d->inAuthentication = false; - break; - default: - qDebug() << "Unknown message from server: " << id; - } - - d->nRead = 0; -} - -QString Greeter::hostname() const -{ - return QHostInfo::localHostName(); -} - -QString Greeter::theme() const -{ - return d->theme; -} - -QVariant Greeter::getProperty(const QString &name) const -{ - return QVariant(); //FIXME TODO -} - -QString Greeter::defaultLanguage() const -{ - return getenv("LANG"); -} - -QString Greeter::defaultLayout() const -{ - return d->defaultLayout; -} - -QString Greeter::defaultSession() const -{ - return d->defaultSession; -} - -QString Greeter::timedLoginUser() const -{ - return d->timedUser; -} - -int Greeter::timedLoginDelay() const -{ - return d->loginDelay; -} - -void Greeter::loadConfig() -{ - if(d->haveConfig) - return; - - QString file; - if(false) - file = d->lightdmInterface->property("ConfigFile").toString(); - qDebug() << "Loading configuration from " << file; - d->config = new QSettings(file, QSettings::IniFormat); - - d->haveConfig = true; -} - -void Greeter::loadUsers() -{ - QStringList hiddenUsers, hiddenShells; - int minimumUid; - QList users, oldUsers, newUsers, changedUsers; - - loadConfig(); - - if(d->config->contains("UserManager/minimum-uid")) - minimumUid = d->config->value("UserManager/minimum-uid").toInt(); - else - minimumUid = 500; - - if (d->config->contains("UserManager/hidden-shells")) - hiddenUsers = d->config->value("UserManager/hidden-shells").toString().split(" "); - else - hiddenUsers << "nobody" << "nobody4" << "noaccess"; - - if (d->config->contains("UserManager/hidden-shells")) - hiddenShells = d->config->value("UserManager/hidden-shells").toString().split(" "); - else - hiddenShells << "/bin/false" << "/usr/sbin/nologin"; - - setpwent(); - - while(TRUE) - { - struct passwd *entry; - User *user; - QStringList tokens; - QString realName, image; - QFile *imageFile; - int i; - - errno = 0; - entry = getpwent(); - if(!entry) - break; - - /* Ignore system users */ - if(entry->pw_uid < minimumUid) - continue; - - /* Ignore users disabled by shell */ - if(entry->pw_shell) - { - for(i = 0; i < hiddenShells.size(); i++) - if(entry->pw_shell == hiddenShells.at(i)) - break; - if(i < hiddenShells.size()) - continue; - } - - /* Ignore certain users */ - for(i = 0; i < hiddenUsers.size(); i++) - if(entry->pw_name == hiddenUsers.at(i)) - break; - if(i < hiddenUsers.size()) - continue; - - tokens = QString(entry->pw_gecos).split(","); - if(tokens.size() > 0 && tokens.at(i) != "") - realName = tokens.at(i); - - QDir homeDir(entry->pw_dir); - imageFile = new QFile(homeDir.filePath(".face")); - if(!imageFile->exists()) - { - delete imageFile; - imageFile = new QFile(homeDir.filePath(".face.icon")); - } - if(imageFile->exists()) - image = "file://" + imageFile->fileName(); - delete imageFile; - - user = new User(entry->pw_name, realName, entry->pw_dir, image, FALSE); - - /* Update existing users if have them */ - bool matchedUser = false; - foreach(User *info, d->users) - { - if(info->name() == user->name()) - { - matchedUser = true; - if(info->update(user->realName(), user->homeDirectory(), user->image(), user->isLoggedIn())) - changedUsers.append(user); - delete user; - user = info; - break; - } - } - if(!matchedUser) - { - /* Only notify once we have loaded the user list */ - if(d->haveUsers) - newUsers.append(user); - } - users.append(user); - } - - if(errno != 0) - qDebug() << "Failed to read password database: " << strerror(errno); - - endpwent(); - - /* Use new user list */ - oldUsers = d->users; - d->users = users; - - /* Notify of changes */ - foreach(User *user, newUsers) - { - qDebug() << "User " << user->name() << " added"; - emit userAdded(user); - } - - foreach(User *user, changedUsers) - { - qDebug() << "User " << user->name() << " changed"; - emit userChanged(user); - } - - foreach(User *user, oldUsers) - { - /* See if this user is in the current list */ - bool existing = false; - foreach(User *new_user, d->users) - { - if (new_user == user) - { - existing = true; - break; - } - } - - if(!existing) - { - qDebug() << "User " << user->name() << " removed"; - emit userRemoved(user); - delete user; - } - } -} - -void Greeter::updateUsers() -{ - if (d->haveUsers) { - return; - } - - loadConfig(); - - /* User listing is disabled */ - if (d->config->contains("UserManager/load-users") && - !d->config->value("UserManager/load-users").toBool()) - { - d->haveUsers = true; - return; - } - - loadUsers(); - - d->haveUsers = true; -} - -QList Greeter::users() -{ - updateUsers(); - return d->users; -} - -SessionsModel* Greeter::sessionsModel() const -{ - return d->sessionsModel; -} - - -bool Greeter::canSuspend() const -{ - QDBusReply reply = d->powerManagementInterface->call("CanSuspend"); - if (reply.isValid()) - return reply.value(); - else - return false; -} - -void Greeter::suspend() -{ - d->powerManagementInterface->call("Suspend"); -} - -bool Greeter::canHibernate() const -{ - QDBusReply reply = d->powerManagementInterface->call("CanHibernate"); - if (reply.isValid()) - return reply.value(); - else - return false; -} - -void Greeter::hibernate() -{ - d->powerManagementInterface->call("Hibernate"); -} - -bool Greeter::canShutdown() const -{ - QDBusReply reply = d->consoleKitInterface->call("CanStop"); - if (reply.isValid()) - return reply.value(); - else - return false; -} - -void Greeter::shutdown() -{ - d->consoleKitInterface->call("stop"); -} - -bool Greeter::canRestart() const -{ - QDBusReply reply = d->consoleKitInterface->call("CanRestart"); - if (reply.isValid()) - return reply.value(); - else - return false; -} - -void Greeter::restart() -{ - d->consoleKitInterface->call("Restart"); -} diff --git a/liblightdm-qt/greeter.h b/liblightdm-qt/greeter.h deleted file mode 100644 index dab0df33..00000000 --- a/liblightdm-qt/greeter.h +++ /dev/null @@ -1,107 +0,0 @@ -#ifndef LDMGREETER_H -#define LDMGREETER_H - -#include -class GreeterPrivate; - -#include "user.h" -#include "language.h" -//#include "ldmlayout.h" - -class GreeterPrivate; - -namespace QLightDM -{ - class SessionsModel; - - class Q_DECL_EXPORT Greeter : public QObject - { - Q_OBJECT - public: - explicit Greeter(QObject* parent=0); - virtual ~Greeter(); - - Q_PROPERTY(bool canSuspend READ canSuspend); - Q_PROPERTY(bool canHibernate READ canHibernate); - Q_PROPERTY(bool canShutdown READ canShutdown); - Q_PROPERTY(bool canRestart READ canRestart); - - Q_PROPERTY(QString hostname READ hostname); - - /** The hostname of the machine */ - QString hostname() const; - QString theme() const; - - QVariant getProperty(const QString &name) const; - - QString timedLoginUser() const; - int timedLoginDelay() const; - - QList users(); - void getUserDefaults(const QString &name, const QString &language, const QString &layout, const QString &session); - - QList languages() const; - QString defaultLanguage() const; - - //QList layouts() const; - QString defaultLayout() const; - QString layout() const; - - QLightDM::SessionsModel *sessionsModel() const; - QString defaultSession() const; - - bool inAuthentication() const; - bool isAuthenticated() const; - QString authenticationUser() const; - - void connectToServer(); - void cancelTimedLogin(); - void startAuthentication(const QString &username); - void provideSecret(const QString &secret); - void cancelAuthentication(); - void login(const QString &username, const QString &session, const QString &language); - void loginWithDefaults(const QString &username); - - bool canSuspend() const; - bool canHibernate() const; - bool canShutdown() const; - bool canRestart() const; - - public slots: - void suspend(); - void hibernate(); - void shutdown(); - void restart(); - - signals: - void connected(); - void showPrompt(QString prompt); - void showMessage(QString message); - void showError(QString message); - void authenticationComplete(bool isAuthenticated); - void timedLogin(QString username); - void userAdded(User *user); - void userChanged(User *user); - void userRemoved(User *user); - void quit(); - - private slots: - void onRead(int fd); - - private: - GreeterPrivate *d; - void writeInt(int value); - void writeString(QString value); - void writeHeader(int id, int length); - void flush(); - int getPacketLength(); - int readInt(int *offset); - QString readString(int *offset); - void loadConfig(); - void loadUsers(); - void updateUsers(); - }; - -};//end namespace - -#endif // LDMGREETER_H diff --git a/liblightdm-qt/include/AuthRequest b/liblightdm-qt/include/AuthRequest deleted file mode 100644 index 664516db..00000000 --- a/liblightdm-qt/include/AuthRequest +++ /dev/null @@ -1 +0,0 @@ -#include "authrequest.h" \ No newline at end of file diff --git a/liblightdm-qt/include/Greeter b/liblightdm-qt/include/Greeter deleted file mode 100644 index 3b3fbf61..00000000 --- a/liblightdm-qt/include/Greeter +++ /dev/null @@ -1 +0,0 @@ -#include "greeter.h" \ No newline at end of file diff --git a/liblightdm-qt/include/Language b/liblightdm-qt/include/Language deleted file mode 100644 index 31cb90fa..00000000 --- a/liblightdm-qt/include/Language +++ /dev/null @@ -1 +0,0 @@ -#include "language.h" \ No newline at end of file diff --git a/liblightdm-qt/include/SessionsModel b/liblightdm-qt/include/SessionsModel deleted file mode 100644 index 7928d2d2..00000000 --- a/liblightdm-qt/include/SessionsModel +++ /dev/null @@ -1 +0,0 @@ -#include "sessionsmodel.h" \ No newline at end of file diff --git a/liblightdm-qt/include/User b/liblightdm-qt/include/User deleted file mode 100644 index 790df279..00000000 --- a/liblightdm-qt/include/User +++ /dev/null @@ -1 +0,0 @@ -#include "user.h" \ No newline at end of file diff --git a/liblightdm-qt/language.cpp b/liblightdm-qt/language.cpp deleted file mode 100644 index e160d19e..00000000 --- a/liblightdm-qt/language.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include "language.h" - -using namespace QLightDM; - -class LanguagePrivate -{ -public: - QString code; - QString name; - QString territory; -}; - -Language::Language(QString &code, QString &name, QString &territory) - : d(new LanguagePrivate) -{ - d->code = code; - d->name = name; - d->territory = territory; -} - -Language::Language(const Language &other) - :d(new LanguagePrivate(*other.d)) -{ -} - -Language::~Language() -{ - delete d; -} - -Language& Language::operator=(const Language& other) -{ - *d = *other.d; - return *this; -} - - -QString Language::code() const -{ - return d->code; -} - -QString Language::name() const -{ - return d->name; -} - -QString Language::territory() const -{ - return d->territory; -} - - diff --git a/liblightdm-qt/language.h b/liblightdm-qt/language.h deleted file mode 100644 index 46934495..00000000 --- a/liblightdm-qt/language.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef LDMLANGUAGE_H -#define LDMLANGUAGE_H -#include - -class LanguagePrivate; - -namespace QLightDM { - class Language - { - public: - Language(QString &code, QString &name, QString &territory); - ~Language(); - Language(const Language& other); - Language &operator=(const Language& other); - - QString code() const; - QString name() const; - QString territory() const; - private: - LanguagePrivate* d; - }; -}; - -#endif // LDMLANGUAGE_H diff --git a/liblightdm-qt/sessionsmodel.cpp b/liblightdm-qt/sessionsmodel.cpp deleted file mode 100644 index f8aaa332..00000000 --- a/liblightdm-qt/sessionsmodel.cpp +++ /dev/null @@ -1,91 +0,0 @@ -#include "sessionsmodel.h" - -#include -#include -#include -#include - -using namespace QLightDM; - -class SessionItem; - -class SessionsModelPrivate -{ -public: - QList items; -}; - -class SessionItem -{ -public: - //FIXME can I make these consts, if I set them in a lovely constructor? - QString id; - QString name; - QString comment; -}; - -SessionsModel::SessionsModel(QObject *parent) : - QAbstractListModel(parent), - d(new SessionsModelPrivate()) -{ - buildList(); -} - -SessionsModel::~SessionsModel() -{ -} - -int SessionsModel::rowCount(const QModelIndex &parent) const -{ - if (parent == QModelIndex()) { //if top level - return d->items.size(); - } else { - return 0; // no child elements. - } -} - -QVariant SessionsModel::data(const QModelIndex &index, int role) const -{ - if (! index.isValid()) { - return QVariant(); - } - - int row = index.row(); - - switch (role) { - case Qt::DisplayRole: - return d->items[row].name; - case Qt::ToolTipRole: - return d->items[row].comment; - - } - return QVariant(); -} - -void SessionsModel::buildList() -{ - //maybe clear first? - - //FIXME don't hardcode this! - QDir sessionDir("/usr/share/xsessions"); - sessionDir.setNameFilters(QStringList() << "*.desktop"); - - QList items; - - foreach(QString sessionFileName, sessionDir.entryList()) { - QSettings sessionData(sessionDir.filePath(sessionFileName), QSettings::IniFormat); - sessionData.beginGroup("Desktop Entry"); - sessionFileName.chop(8);// chop(8) removes '.desktop' - - SessionItem item; - item.id = sessionFileName; - item.name = sessionData.value("Name").toString(); - item.comment = sessionData.value("Comment").toString(); - items.append(item); - } - - beginInsertRows(QModelIndex(), 0, items.size()); - d->items.append(items); - endInsertRows(); -} - diff --git a/liblightdm-qt/sessionsmodel.h b/liblightdm-qt/sessionsmodel.h deleted file mode 100644 index a57820c9..00000000 --- a/liblightdm-qt/sessionsmodel.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef LDMSESSIONSMODEL_H -#define LDMSESSIONSMODEL_H - -#include - -class SessionsModelPrivate; - -namespace QLightDM { - class Q_DECL_EXPORT SessionsModel : public QAbstractListModel - { - Q_OBJECT - public: - enum SessionModelRoles {IdRole = Qt::UserRole}; - - explicit SessionsModel(QObject *parent = 0); - virtual ~SessionsModel(); - - int rowCount(const QModelIndex &parent) const; - QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const; - - private: - SessionsModelPrivate *d; - void buildList(); //maybe make this a public slot, which apps can call only if they give a care about the session. - }; -}; - -#endif // LDMSESSIONSMODEL_H diff --git a/liblightdm-qt/user.cpp b/liblightdm-qt/user.cpp deleted file mode 100644 index 3a9d68e3..00000000 --- a/liblightdm-qt/user.cpp +++ /dev/null @@ -1,95 +0,0 @@ -#include "user.h" - -using namespace QLightDM; - -class UserPrivate -{ -public: - QString name; - QString realName; - QString homeDirectory; - QString image; - bool isLoggedIn; -}; - -User::User(): - d(new UserPrivate) -{ -} - -User::User(const QString& name, const QString& realName, const QString& homeDirectory, const QString& image, bool isLoggedIn) : - d(new UserPrivate) -{ - d->name = name; - d->realName = realName; - d->homeDirectory = homeDirectory; - d->image = image; - d->isLoggedIn = isLoggedIn; -} - -User::User(const User &other) - :d(new UserPrivate(*other.d)) -{ -} - -User::~User() -{ - delete d; -} - - -User& User::operator=(const User& other) -{ - *d = *other.d; - return *this; -} - -bool User::update(const QString& realName, const QString& homeDirectory, const QString& image, bool isLoggedIn) -{ - if (d->realName == realName && d->homeDirectory == homeDirectory && d->image == image && d->isLoggedIn == isLoggedIn) - return false; - - d->realName = realName; - d->homeDirectory = homeDirectory; - d->image = image; - d->isLoggedIn = isLoggedIn; - - return true; -} - -QString User::displayName() const -{ - if (!d->realName.isEmpty()) - { - return d->realName; - } - else - { - return d->name; - } -} - -QString User::name() const -{ - return d->name; -} - -QString User::realName() const -{ - return d->realName; -} - -QString User::homeDirectory() const -{ - return d->homeDirectory; -} - -QString User::image() const -{ - return d->image; -} - -bool User::isLoggedIn() const -{ - return d->isLoggedIn; -} diff --git a/liblightdm-qt/user.h b/liblightdm-qt/user.h deleted file mode 100644 index f3d89ba7..00000000 --- a/liblightdm-qt/user.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef LDMUSER_H -#define LDMUSER_H - -#include -#include - -class UserPrivate; - -namespace QLightDM -{ - //public facing User class - class Q_DECL_EXPORT User - { - public: - explicit User(); - User(const QString &name, const QString &realName, const QString &homeDirectory, const QString &image, bool isLoggedIn); - User(const User& other); - ~User(); - User &operator=(const User& other); - - bool update(const QString &realName, const QString &homeDirectory, const QString &image, bool isLoggedIn); - - /** The name to display (the real name if available, otherwise use the username */ - QString displayName() const; - - /** The username of the user*/ - QString name() const; - /** The user's real name, use this for displaying*/ - QString realName() const; - - /** Returns the home directory of this user*/ - QString homeDirectory() const; - - /** Returns the path to an avatar of this user*/ - QString image() const; - - /** Returns true if this user is already logged in on another session*/ - bool isLoggedIn() const; - - // LdmUser &operator=(const LdmUser user); - private: - UserPrivate* d; - }; -} - -Q_DECLARE_METATYPE(QLightDM::User); -Q_DECLARE_METATYPE(QList); - -#endif // LDMUSER_H -- cgit v1.2.1