summaryrefslogtreecommitdiff
path: root/liblightdm-qt
diff options
context:
space:
mode:
authorDavid Edmundson <david@davidedmundson.co.uk>2011-11-11 00:48:24 +0000
committerDavid Edmundson <david@davidedmundson.co.uk>2011-11-11 00:48:24 +0000
commit2ee6ad80d08a408919d3035d87a952d194259fab (patch)
treec1049e8a609b73d36b20d4a02e9a03264b5f7fe2 /liblightdm-qt
parentc022466de7aeee9a2d1893e5d356b1fcf3300d62 (diff)
downloadlightdm-2ee6ad80d08a408919d3035d87a952d194259fab.tar.gz
Move private methods from Greeter to GreeterPrivate
Diffstat (limited to 'liblightdm-qt')
-rw-r--r--liblightdm-qt/QLightDM/greeter.h84
-rw-r--r--liblightdm-qt/QLightDM/language.h36
-rw-r--r--liblightdm-qt/QLightDM/power.h28
-rw-r--r--liblightdm-qt/QLightDM/session.h39
-rw-r--r--liblightdm-qt/QLightDM/system.h27
-rw-r--r--liblightdm-qt/QLightDM/user.h92
-rw-r--r--liblightdm-qt/greeter.cpp101
7 files changed, 359 insertions, 48 deletions
diff --git a/liblightdm-qt/QLightDM/greeter.h b/liblightdm-qt/QLightDM/greeter.h
new file mode 100644
index 00000000..6dfdf152
--- /dev/null
+++ b/liblightdm-qt/QLightDM/greeter.h
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2010-2011 David Edmundson.
+ * Copyright (C) 2010-2011 Robert Ancell
+ * Author: David Edmundson <kde@davidedmundson.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your option) any
+ * later version. See http://www.gnu.org/copyleft/lgpl.html the full text of the
+ * license.
+ */
+
+#ifndef QLIGHTDM_GREETER_H
+#define QLIGHTDM_GREETER_H
+
+#include <QtCore/QObject>
+#include <QtCore/QVariant>
+#include "QLightDM/User"
+#include "QLightDM/Language"
+
+class GreeterPrivate;
+
+namespace QLightDM
+{
+ typedef enum
+ {
+ PROMPT_TYPE_QUESTION,
+ PROMPT_TYPE_SECRET
+ } PromptType;
+
+ typedef enum
+ {
+ MESSAGE_TYPE_INFO,
+ MESSAGE_TYPE_ERROR
+ } MessageType;
+
+ class Q_DECL_EXPORT Greeter : public QObject
+ {
+ Q_OBJECT
+ public:
+ explicit Greeter(QObject* parent=0);
+ virtual ~Greeter();
+
+ QString timedLoginUser() const;
+ int timedLoginDelay() const;
+
+ QString getHint(QString name) const;
+ QString defaultSessionHint() const;
+ bool hideUsersHint() const;
+ bool hasGuestAccountHint() const;
+ QString selectUserHint() const;
+ bool selectGuestHint() const;
+ QString autologinUserHint() const;
+ bool autologinGuestHint() const;
+ int autologinTimeoutHint() const;
+ bool inAuthentication() const;
+ bool isAuthenticated() const;
+ QString authenticationUser() const;
+
+ public slots:
+ bool connectSync();
+ void authenticate(const QString &username=QString());
+ void authenticateAsGuest();
+ void respond(const QString &response);
+ void cancelAuthentication();
+ void setLanguage (QString language);
+ bool startSessionSync(const QString &session=QString());
+
+ signals:
+ void showMessage(QString text, QLightDM::MessageType type);
+ void showPrompt(QString text, QLightDM::PromptType type);
+ void authenticationComplete();
+ void autologinTimerExpired();
+
+ private slots:
+ void onRead(int fd);
+
+ private:
+ GreeterPrivate *d;
+
+ };
+};
+
+#endif // QLIGHTDM_GREETER_H
diff --git a/liblightdm-qt/QLightDM/language.h b/liblightdm-qt/QLightDM/language.h
new file mode 100644
index 00000000..5ba16c8b
--- /dev/null
+++ b/liblightdm-qt/QLightDM/language.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2010-2011 David Edmundson.
+ * Author: David Edmundson <kde@davidedmundson.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your option) any
+ * later version. See http://www.gnu.org/copyleft/lgpl.html the full text of the
+ * license.
+ */
+
+#ifndef QLIGHTDM_LANGUAGE_H
+#define QLIGHTDM_LANGUAGE_H
+
+#include <QString>
+
+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 // QLIGHTDM_LANGUAGE_H
diff --git a/liblightdm-qt/QLightDM/power.h b/liblightdm-qt/QLightDM/power.h
new file mode 100644
index 00000000..e3a0a12b
--- /dev/null
+++ b/liblightdm-qt/QLightDM/power.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2010-2011 David Edmundson.
+ * Copyright (C) 2010-2011 Robert Ancell
+ * Author: David Edmundson <kde@davidedmundson.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your option) any
+ * later version. See http://www.gnu.org/copyleft/lgpl.html the full text of the
+ * license.
+ */
+
+#ifndef QLIGHTDM_POWER_H
+#define QLIGHTDM_POWER_H
+
+namespace QLightDM
+{
+ bool canSuspend();
+ bool canHibernate();
+ bool canShutdown();
+ bool canRestart();
+ void suspend();
+ void hibernate();
+ void shutdown();
+ void restart();
+};
+
+#endif // QLIGHTDM_POWER_H
diff --git a/liblightdm-qt/QLightDM/session.h b/liblightdm-qt/QLightDM/session.h
new file mode 100644
index 00000000..83310bbc
--- /dev/null
+++ b/liblightdm-qt/QLightDM/session.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2010-2011 David Edmundson.
+ * Author: David Edmundson <kde@davidedmundson.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your option) any
+ * later version. See http://www.gnu.org/copyleft/lgpl.html the full text of the
+ * license.
+ */
+
+#ifndef QLIGHTDM_SESSION_H
+#define QLIGHTDM_SESSION_H
+
+#include <QtCore/QAbstractListModel>
+
+class SessionsModelPrivate;
+
+namespace QLightDM {
+ class Q_DECL_EXPORT SessionsModel : public QAbstractListModel
+ {
+ Q_OBJECT
+ public:
+ explicit SessionsModel(QObject *parent = 0);
+ virtual ~SessionsModel();
+
+ enum SessionModelRoles {IdRole = Qt::UserRole};
+ 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.
+ };
+
+ SessionsModel *sessions();
+};
+
+#endif // QLIGHTDM_SESSION_H
diff --git a/liblightdm-qt/QLightDM/system.h b/liblightdm-qt/QLightDM/system.h
new file mode 100644
index 00000000..534925b3
--- /dev/null
+++ b/liblightdm-qt/QLightDM/system.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2010-2011 David Edmundson.
+ * Copyright (C) 2010-2011 Robert Ancell
+ * Author: David Edmundson <kde@davidedmundson.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your option) any
+ * later version. See http://www.gnu.org/copyleft/lgpl.html the full text of the
+ * license.
+ */
+
+#ifndef QLIGHTDM_SYSTEM_H
+#define QLIGHTDM_SYSTEM_H
+
+#include <QtCore/QString>
+
+namespace QLightDM
+{
+ class System
+ {
+ public:
+ static QString hostname();
+ };
+};
+
+#endif // QLIGHTDM_SYSTEM_H
diff --git a/liblightdm-qt/QLightDM/user.h b/liblightdm-qt/QLightDM/user.h
new file mode 100644
index 00000000..08841fc1
--- /dev/null
+++ b/liblightdm-qt/QLightDM/user.h
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2010-2011 David Edmundson.
+ * Author: David Edmundson <kde@davidedmundson.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your option) any
+ * later version. See http://www.gnu.org/copyleft/lgpl.html the full text of the
+ * license.
+ */
+
+#ifndef QLIGHTDM_USER_H
+#define QLIGHTDM_USER_H
+
+#include <QtCore/QString>
+#include <QtCore/QSharedDataPointer>
+#include <QAbstractListModel>
+
+class UserPrivate;
+class UsersModelPrivate;
+
+namespace QLightDM
+{
+ //public facing User class
+ /** Class storing user information.
+ This is an implicitly shared 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:
+ QSharedDataPointer<UserPrivate> d;
+ };
+
+ class Q_DECL_EXPORT UsersModel : public QAbstractListModel
+ {
+ Q_OBJECT
+ public:
+ explicit UsersModel(QObject *parent = 0);
+ ~UsersModel();
+
+ enum UserModelRoles {NameRole = Qt::UserRole,
+ RealNameRole,
+ LoggedInRole};
+
+ int rowCount(const QModelIndex &parent) const;
+ QVariant data(const QModelIndex &index, int role) const;
+
+ signals:
+
+ public slots:
+
+ private slots:
+ /** Updates the model with new changes in the password file*/
+ void loadUsers();
+
+ private:
+ /** Returns a list of all users in the password file*/
+ QList<User> getUsers();
+ UsersModelPrivate *d;
+ };
+
+ UsersModel *users();
+}
+
+#endif // QLIGHTDM_USER_H
diff --git a/liblightdm-qt/greeter.cpp b/liblightdm-qt/greeter.cpp
index 9c062336..9f8add3f 100644
--- a/liblightdm-qt/greeter.cpp
+++ b/liblightdm-qt/greeter.cpp
@@ -59,7 +59,6 @@ class GreeterPrivate
{
public:
QHash<QString, QString> hints;
-
int toServerFd;
int fromServerFd;
QSocketNotifier *n;
@@ -70,6 +69,12 @@ public:
QString authenticationUser;
int authenticateSequenceNumber;
bool cancellingAuthentication;
+
+ void writeInt(int value);
+ void writeString(QString value);
+ void writeHeader(int id, int length);
+ void flush();
+ char *readMessage(int *length, bool block);
};
Greeter::Greeter(QObject *parent) :
@@ -98,36 +103,36 @@ static int stringLength(QString value)
return intLength() + a.size();
}
-void Greeter::writeInt(int value)
+void GreeterPrivate::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()) {
+ if (write(toServerFd, buffer, intLength()) != intLength()) {
qDebug() << "Error writing to server";
}
}
-void Greeter::writeString(QString value)
+void GreeterPrivate::writeString(QString value)
{
QByteArray a = value.toUtf8();
writeInt(a.size());
- if (write(d->toServerFd, a.data(), a.size()) != a.size()) {
+ if (write(toServerFd, a.data(), a.size()) != a.size()) {
qDebug() << "Error writing to server";
}
}
-void Greeter::writeHeader(int id, int length)
+void GreeterPrivate::writeHeader(int id, int length)
{
writeInt(id);
writeInt(length);
}
-void Greeter::flush()
+void GreeterPrivate::flush()
{
- fsync(d->toServerFd);
+ fsync(toServerFd);
}
static int readInt(char *message, int messageLength, int *offset)
@@ -191,12 +196,12 @@ bool Greeter::connectSync()
connect(d->n, SIGNAL(activated(int)), this, SLOT(onRead(int)));
qDebug() << "Connecting to display manager...";
- writeHeader(GREETER_MESSAGE_CONNECT, stringLength(VERSION));
- writeString(VERSION);
- flush();
+ d->writeHeader(GREETER_MESSAGE_CONNECT, stringLength(VERSION));
+ d->writeString(VERSION);
+ d->flush();
int responseLength;
- char *response = readMessage(&responseLength, false);
+ char *response = d->readMessage(&responseLength, false);
if (!response)
return false;
@@ -235,11 +240,11 @@ void Greeter::authenticate(const QString &username)
d->cancellingAuthentication = false;
d->authenticationUser = username;
qDebug() << "Starting authentication for user " << username << "...";
- writeHeader(GREETER_MESSAGE_AUTHENTICATE, intLength() + stringLength(username));
+ d->writeHeader(GREETER_MESSAGE_AUTHENTICATE, intLength() + stringLength(username));
d->authenticateSequenceNumber++;
- writeInt(d->authenticateSequenceNumber);
- writeString(username);
- flush();
+ d->writeInt(d->authenticateSequenceNumber);
+ d->writeString(username);
+ d->flush();
}
void Greeter::authenticateAsGuest()
@@ -250,27 +255,27 @@ void Greeter::authenticateAsGuest()
d->cancellingAuthentication = false;
d->authenticationUser = "";
qDebug() << "Starting authentication for guest account";
- writeHeader(GREETER_MESSAGE_AUTHENTICATE_AS_GUEST, intLength());
- writeInt(d->authenticateSequenceNumber);
- flush();
+ d->writeHeader(GREETER_MESSAGE_AUTHENTICATE_AS_GUEST, intLength());
+ d->writeInt(d->authenticateSequenceNumber);
+ d->flush();
}
void Greeter::respond(const QString &response)
{
qDebug() << "Providing response to display manager";
- writeHeader(GREETER_MESSAGE_CONTINUE_AUTHENTICATION, intLength() + stringLength(response));
+ d->writeHeader(GREETER_MESSAGE_CONTINUE_AUTHENTICATION, intLength() + stringLength(response));
// FIXME: Could be multiple response required
- writeInt(1);
- writeString(response);
- flush();
+ d->writeInt(1);
+ d->writeString(response);
+ d->flush();
}
void Greeter::cancelAuthentication()
{
qDebug() << "Cancelling authentication";
d->cancellingAuthentication = true;
- writeHeader(GREETER_MESSAGE_CANCEL_AUTHENTICATION, 0);
- flush();
+ d->writeHeader(GREETER_MESSAGE_CANCEL_AUTHENTICATION, 0);
+ d->flush();
}
bool Greeter::inAuthentication() const
@@ -290,9 +295,9 @@ QString Greeter::authenticationUser() const
void Greeter::setLanguage (QString language)
{
- writeHeader(GREETER_MESSAGE_SET_LANGUAGE, stringLength(language));
- writeString (language);
- flush();
+ d->writeHeader(GREETER_MESSAGE_SET_LANGUAGE, stringLength(language));
+ d->writeString (language);
+ d->flush();
}
bool Greeter::startSessionSync(const QString &session)
@@ -302,12 +307,12 @@ bool Greeter::startSessionSync(const QString &session)
else
qDebug() << "Starting session " << session;
- writeHeader(GREETER_MESSAGE_START_SESSION, stringLength(session));
- writeString(session);
- flush();
+ d->writeHeader(GREETER_MESSAGE_START_SESSION, stringLength(session));
+ d->writeString(session);
+ d->flush();
int responseLength;
- char *response = readMessage(&responseLength, false);
+ char *response = d->readMessage(&responseLength, false);
if (!response)
return false;
@@ -324,16 +329,16 @@ bool Greeter::startSessionSync(const QString &session)
return returnCode == 0;
}
-char *Greeter::readMessage(int *length, bool block)
+char* GreeterPrivate::readMessage(int *length, bool block)
{
/* Read the header, or the whole message if we already have that */
int nToRead = HEADER_SIZE;
- if(d->nRead >= HEADER_SIZE)
- nToRead += getMessageLength(d->readBuffer, d->nRead);
+ if(nRead >= HEADER_SIZE)
+ nToRead += getMessageLength(readBuffer, nRead);
do
{
- ssize_t nRead = read(d->fromServerFd, d->readBuffer + d->nRead, nToRead - d->nRead);
+ ssize_t nRead = read(fromServerFd, readBuffer + nRead, nToRead - nRead);
if(nRead < 0)
{
qDebug() << "Error reading from server";
@@ -346,29 +351,29 @@ char *Greeter::readMessage(int *length, bool block)
}
qDebug() << "Read " << nRead << " octets from daemon";
- d->nRead += nRead;
- } while(d->nRead < nToRead && block);
+ nRead += nRead;
+ } while(nRead < nToRead && block);
/* Stop if haven't got all the data we want */
- if(d->nRead != nToRead)
+ if(nRead != nToRead)
return NULL;
/* If have header, rerun for content */
- if(d->nRead == HEADER_SIZE)
+ if(nRead == HEADER_SIZE)
{
- nToRead = getMessageLength(d->readBuffer, d->nRead);
+ nToRead = getMessageLength(readBuffer, nRead);
if(nToRead > 0)
{
- d->readBuffer = (char *)realloc(d->readBuffer, HEADER_SIZE + nToRead);
+ readBuffer = (char *)realloc(readBuffer, HEADER_SIZE + nToRead);
return readMessage(length, block);
}
}
- char *buffer = d->readBuffer;
- *length = d->nRead;
+ char *buffer = readBuffer;
+ *length = nRead;
- d->readBuffer = (char *)malloc(d->nRead);
- d->nRead = 0;
+ readBuffer = (char *)malloc(nRead);
+ nRead = 0;
return buffer;
}
@@ -378,7 +383,7 @@ void Greeter::onRead(int fd)
qDebug() << "Reading from server";
int messageLength;
- char *message = readMessage(&messageLength, false);
+ char *message = d->readMessage(&messageLength, false);
if (!message)
return;
@@ -493,4 +498,4 @@ int Greeter::autologinTimeoutHint() const
return d->hints.value ("autologin-timeout", "0").toInt ();
}
-#include "greeter_moc.cpp" \ No newline at end of file
+#include "greeter_moc.cpp"