diff options
28 files changed, 695 insertions, 1143 deletions
diff --git a/configure.ac b/configure.ac index 1392772e..ebb02cd5 100644 --- a/configure.ac +++ b/configure.ac @@ -173,7 +173,7 @@ doc/Makefile liblightdm-gobject/liblightdm-gobject-1.pc liblightdm-gobject/Makefile liblightdm-qt/Makefile -liblightdm-qt/liblightdm-qt-1.pc +liblightdm-qt/liblightdm-qt-2.pc po/Makefile.in src/Makefile tests/Makefile diff --git a/liblightdm-gobject/lightdm.h b/liblightdm-gobject/lightdm.h index a23ecdfc..43603e22 100644 --- a/liblightdm-gobject/lightdm.h +++ b/liblightdm-gobject/lightdm.h @@ -20,6 +20,4 @@ #include "lightdm/system.h" #include "lightdm/user.h" -G_END_DECLS - #endif /* _LIGHTDM_H_ */ diff --git a/liblightdm-gobject/lightdm/power.h b/liblightdm-gobject/lightdm/power.h index 284382b2..c8d22198 100644 --- a/liblightdm-gobject/lightdm/power.h +++ b/liblightdm-gobject/lightdm/power.h @@ -12,6 +12,8 @@ #ifndef _LIGHTDM_POWER_H_ #define _LIGHTDM_POWER_H_ +G_BEGIN_DECLS + gboolean lightdm_get_can_suspend (void); gboolean lightdm_suspend (GError **error); diff --git a/liblightdm-gobject/lightdm/system.h b/liblightdm-gobject/lightdm/system.h index f070ec80..a5510403 100644 --- a/liblightdm-gobject/lightdm/system.h +++ b/liblightdm-gobject/lightdm/system.h @@ -14,6 +14,8 @@ #include <glib-object.h> +G_BEGIN_DECLS + const gchar *lightdm_get_hostname (void); G_END_DECLS diff --git a/liblightdm-qt/Makefile.am b/liblightdm-qt/Makefile.am index dbd8c3a5..eb92befa 100644 --- a/liblightdm-qt/Makefile.am +++ b/liblightdm-qt/Makefile.am @@ -1,46 +1,50 @@ -lib_LTLIBRARIES = liblightdm-qt-1.la +lib_LTLIBRARIES = liblightdm-qt-2.la -# Generate metadata for QObjects -MOC_FILES = \ - greeter_moc.cpp \ - session_moc.cpp \ - user_moc.cpp - -greeter_moc.cpp: QLightDM/Greeter - $(MOC) $< -o $@ -session_moc.cpp: QLightDM/Session - $(MOC) $< -o $@ -user_moc.cpp: QLightDM/User +%_moc.cpp: QLightDM/%.h $(MOC) $< -o $@ -liblightdm_qt_1_la_LIBADD = $(LIBLIGHTDM_QT_LIBS) -liblightdm_qt_1_la_CXXFLAGS = $(LIBLIGHTDM_QT_CFLAGS) \ +power.cpp: power_moc.cpp +greeter.cpp: greeter_moc.cpp +sessionsmodel.cpp: sessionsmodel_moc.cpp +usersmodel.cpp: usersmodel_moc.cpp + +liblightdm_qt_2_la_LIBADD = \ + $(LIBLIGHTDM_QT_LIBS) \ + -L$(top_builddir)/liblightdm-gobject \ + -llightdm-gobject-1 + +liblightdm_qt_2_la_CXXFLAGS = $(LIBLIGHTDM_QT_CFLAGS) \ + -I$(top_srcdir)/liblightdm-gobject \ + $(LIBLIGHTDM_GOBJECT_CFLAGS) \ -DXSESSIONS_DIR=\"$(datadir)/xsessions\" -liblightdm_qt_1include_HEADERS = \ +liblightdm_qt_2include_HEADERS = \ QLightDM/Greeter \ - QLightDM/Language \ QLightDM/Power \ - QLightDM/Session \ + QLightDM/SessionsModel \ QLightDM/System \ - QLightDM/User -liblightdm_qt_1includedir=$(includedir)/lightdm-qt-1/QLightDM + QLightDM/UsersModel \ + QLightDM/greeter.h \ + QLightDM/power.h \ + QLightDM/sessionsmodel.h \ + QLightDM/system.h \ + QLightDM/usersmodel.h + +liblightdm_qt_2includedir=$(includedir)/lightdm-qt-2/QLightDM -liblightdm_qt_1_la_SOURCES = \ +liblightdm_qt_2_la_SOURCES = \ greeter.cpp \ - language.cpp \ power.cpp \ - session.cpp \ + sessionsmodel.cpp \ system.cpp \ - user.cpp \ - $(MOC_FILES) \ - $(liblightdm_qt_1include_HEADERS) + usersmodel.cpp \ + $(liblightdm_qt_2include_HEADERS) pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = liblightdm-qt-1.pc +pkgconfig_DATA = liblightdm-qt-2.pc CLEANFILES = \ - $(MOC_FILES) + *_moc.cpp DISTCLEANFILES = \ Makefile.in \ diff --git a/liblightdm-qt/QLightDM/Greeter b/liblightdm-qt/QLightDM/Greeter index 5e892fd8..bcfa4a96 100644 --- a/liblightdm-qt/QLightDM/Greeter +++ b/liblightdm-qt/QLightDM/Greeter @@ -1,89 +1 @@ -/* - * 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; - void writeInt(int value); - void writeString(QString value); - void writeHeader(int id, int length); - void flush(); - char *readMessage(int *length, bool block); - }; -}; - -#endif // QLIGHTDM_GREETER_H +#include "QLightDM/greeter.h"
\ No newline at end of file diff --git a/liblightdm-qt/QLightDM/Language b/liblightdm-qt/QLightDM/Language index 5ba16c8b..68d5513f 100644 --- a/liblightdm-qt/QLightDM/Language +++ b/liblightdm-qt/QLightDM/Language @@ -1,36 +1 @@ -/* - * 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 +#include "QLightDM/language.h"
\ No newline at end of file diff --git a/liblightdm-qt/QLightDM/Power b/liblightdm-qt/QLightDM/Power index e3a0a12b..446eb11f 100644 --- a/liblightdm-qt/QLightDM/Power +++ b/liblightdm-qt/QLightDM/Power @@ -1,28 +1 @@ -/* - * 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 +#include "QLightDM/power.h"
\ No newline at end of file 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/System b/liblightdm-qt/QLightDM/System index 7958be09..3f9275fc 100644 --- a/liblightdm-qt/QLightDM/System +++ b/liblightdm-qt/QLightDM/System @@ -1,21 +1 @@ -/* - * 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 - -namespace QLightDM -{ - QString hostname(); -}; - -#endif // QLIGHTDM_SYSTEM_H +#include "QLightDM/system.h"
\ No newline at end of file diff --git a/liblightdm-qt/QLightDM/User b/liblightdm-qt/QLightDM/User deleted file mode 100644 index 08841fc1..00000000 --- a/liblightdm-qt/QLightDM/User +++ /dev/null @@ -1,92 +0,0 @@ -/* - * 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/QLightDM/UsersModel b/liblightdm-qt/QLightDM/UsersModel new file mode 100644 index 00000000..95f2cf3f --- /dev/null +++ b/liblightdm-qt/QLightDM/UsersModel @@ -0,0 +1 @@ +#include "QLightDM/usersmodel.h"
\ No newline at end of file diff --git a/liblightdm-qt/QLightDM/greeter.h b/liblightdm-qt/QLightDM/greeter.h new file mode 100644 index 00000000..7a1e00a9 --- /dev/null +++ b/liblightdm-qt/QLightDM/greeter.h @@ -0,0 +1,80 @@ +/* + * 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> + + +namespace QLightDM +{ + class GreeterPrivate; + +class Q_DECL_EXPORT Greeter : public QObject +{ + Q_OBJECT + + Q_PROPERTY(bool authenticated READ isAuthenticated ); //NOTFIY authenticationComplete + +public: + enum PromptType { + PromptTypeQuestion, + PromptTypeSecret + }; + + enum MessageType { + MessageTypeInfo, + MessageTypeError + }; + + explicit Greeter(QObject* parent=0); + virtual ~Greeter(); + + QString getHint(const 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 (const QString &language); + bool startSessionSync(const QString &session=QString()); + +signals: + void showMessage(QString text, QLightDM::Greeter::MessageType type); + void showPrompt(QString text, QLightDM::Greeter::PromptType type); + void authenticationComplete(); + void autologinTimerExpired(); + +private: + GreeterPrivate *d_ptr; + Q_DECLARE_PRIVATE(Greeter) + +}; +}; + +#endif // QLIGHTDM_GREETER_H diff --git a/liblightdm-qt/QLightDM/power.h b/liblightdm-qt/QLightDM/power.h new file mode 100644 index 00000000..5479ae99 --- /dev/null +++ b/liblightdm-qt/QLightDM/power.h @@ -0,0 +1,50 @@ +/* + * 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 + +#include <QObject> + +namespace QLightDM +{ + class PowerInterface : public QObject + { + Q_OBJECT + public: + Q_PROPERTY(bool canSuspend READ canSuspend() CONSTANT) + Q_PROPERTY(bool canHibernate READ canHibernate() CONSTANT) + Q_PROPERTY(bool canShutdown READ canShutdown() CONSTANT) + Q_PROPERTY(bool canRestart READ canRestart() CONSTANT) + + PowerInterface(QObject *parent); + virtual ~PowerInterface(); + + bool canSuspend(); + bool canHibernate(); + bool canShutdown(); + bool canRestart(); + + public Q_SLOTS: + void suspend(); + void hibernate(); + void shutdown(); + void restart(); + + private: + class PowerInterfacePrivate; + PowerInterfacePrivate * const d; + + }; +}; + +#endif // QLIGHTDM_POWER_H diff --git a/liblightdm-qt/QLightDM/Session b/liblightdm-qt/QLightDM/sessionsmodel.h index 83310bbc..92df0589 100644 --- a/liblightdm-qt/QLightDM/Session +++ b/liblightdm-qt/QLightDM/sessionsmodel.h @@ -9,8 +9,8 @@ * license. */ -#ifndef QLIGHTDM_SESSION_H -#define QLIGHTDM_SESSION_H +#ifndef QLIGHTDM_SESSIONS_MODEL_H +#define QLIGHTDM_SESSIONS_MODEL_H #include <QtCore/QAbstractListModel> @@ -21,19 +21,24 @@ namespace QLightDM { { Q_OBJECT public: + enum SessionModelRoles { + //name is exposed as Qt::DisplayRole + //comment is exposed as Qt::TooltipRole + IdRole = Qt::UserRole + }; + 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; + protected: + SessionsModelPrivate *d_ptr; + private: - SessionsModelPrivate *d; - void buildList(); //maybe make this a public slot, which apps can call only if they give a care about the session. + Q_DECLARE_PRIVATE(SessionsModel) }; - - 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/usersmodel.h b/liblightdm-qt/QLightDM/usersmodel.h new file mode 100644 index 00000000..39b94188 --- /dev/null +++ b/liblightdm-qt/QLightDM/usersmodel.h @@ -0,0 +1,49 @@ +/* + * 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> + + +namespace QLightDM +{ +class UsersModelPrivate; + +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; + +protected: + +private: + UsersModelPrivate * const d_ptr; + + Q_DECLARE_PRIVATE(UsersModel) + +}; + +}; + +#endif // QLIGHTDM_USER_H diff --git a/liblightdm-qt/greeter.cpp b/liblightdm-qt/greeter.cpp index bc8ec28a..8d6aaaff 100644 --- a/liblightdm-qt/greeter.cpp +++ b/liblightdm-qt/greeter.cpp @@ -10,482 +10,211 @@ * license. */ -#include "config.h" -#include "QLightDM/Greeter" +#include "QLightDM/greeter.h" -#include <security/pam_appl.h> #include <QtCore/QDebug> #include <QtCore/QDir> #include <QtCore/QVariant> #include <QtCore/QSettings> -#include <QtCore/QUrl> -#include <QtCore/QFile> -#include <QtCore/QHash> -#include <QtCore/QSocketNotifier> -#include <QtDBus/QDBusPendingReply> -#include <QtDBus/QDBusInterface> -#include <QtDBus/QDBusReply> - -/* Messages from the greeter to the server */ -typedef enum -{ - GREETER_MESSAGE_CONNECT = 0, - GREETER_MESSAGE_AUTHENTICATE, - GREETER_MESSAGE_AUTHENTICATE_AS_GUEST, - GREETER_MESSAGE_CONTINUE_AUTHENTICATION, - GREETER_MESSAGE_START_SESSION, - GREETER_MESSAGE_CANCEL_AUTHENTICATION, - GREETER_MESSAGE_SET_LANGUAGE -} GreeterMessage; - -/* Messages from the server to the greeter */ -typedef enum -{ - SERVER_MESSAGE_CONNECTED = 0, - SERVER_MESSAGE_PROMPT_AUTHENTICATION, - SERVER_MESSAGE_END_AUTHENTICATION, - SERVER_MESSAGE_SESSION_RESULT -} ServerMessage; -#define HEADER_SIZE 8 +#include <lightdm.h> using namespace QLightDM; -class GreeterPrivate +class QLightDM::GreeterPrivate { public: - QHash<QString, QString> hints; - - int toServerFd; - int fromServerFd; - QSocketNotifier *n; - char *readBuffer; - int nRead; - bool inAuthentication; - bool isAuthenticated; - QString authenticationUser; - int authenticateSequenceNumber; - bool cancellingAuthentication; + GreeterPrivate(Greeter *parent); + LightDMGreeter *ldmGreeter; +protected: + Greeter* q_ptr; + + static void cb_showPrompt(LightDMGreeter *greeter, const gchar *text, LightDMPromptType type, gpointer data); + static void cb_showMessage(LightDMGreeter *greeter, const gchar *text, LightDMMessageType type, gpointer data); + static void cb_authenticationComplete(LightDMGreeter *greeter, gpointer data); + static void cb_autoLoginExpired(LightDMGreeter *greeter, gpointer data); + +private: + Q_DECLARE_PUBLIC(Greeter) }; -Greeter::Greeter(QObject *parent) : - QObject(parent), - d(new GreeterPrivate) +GreeterPrivate::GreeterPrivate(Greeter *parent) : + q_ptr(parent) { - d->readBuffer = (char *)malloc(HEADER_SIZE); - d->nRead = 0; - d->authenticateSequenceNumber = 0; -} + g_type_init(); + ldmGreeter = lightdm_greeter_new(); -Greeter::~Greeter() -{ - delete d->readBuffer; - delete d; + g_signal_connect (ldmGreeter, "show-prompt", G_CALLBACK (cb_showPrompt), this); + g_signal_connect (ldmGreeter, "show-message", G_CALLBACK (cb_showMessage), this); + g_signal_connect (ldmGreeter, "authentication-complete", G_CALLBACK (cb_authenticationComplete), this); + g_signal_connect (ldmGreeter, "autologin-timer-expired", G_CALLBACK (cb_autoLoginExpired), this); } -static int intLength() +void GreeterPrivate::cb_showPrompt(LightDMGreeter *greeter, const gchar *text, LightDMPromptType type, gpointer data) { - return 4; -} + Q_UNUSED(greeter); + + GreeterPrivate *that = static_cast<GreeterPrivate*>(data); + QString message = QString::fromLocal8Bit(text); + + //FIXME prompt type -static int stringLength(QString value) -{ - QByteArray a = value.toUtf8(); - return intLength() + a.size(); + Q_EMIT that->q_func()->showPrompt(message, Greeter::PromptTypeSecret); } -void Greeter::writeInt(int value) +void GreeterPrivate::cb_showMessage(LightDMGreeter *greeter, const gchar *text, LightDMMessageType type, gpointer data) { - 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"; - } -} + Q_UNUSED(greeter); -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"; - } -} + GreeterPrivate *that = static_cast<GreeterPrivate*>(data); + QString message = QString::fromLocal8Bit(text); -void Greeter::writeHeader(int id, int length) -{ - writeInt(id); - writeInt(length); + //FIXME prompt type + + Q_EMIT that->q_func()->showMessage(message, Greeter::MessageTypeInfo); } -void Greeter::flush() +void GreeterPrivate::cb_authenticationComplete(LightDMGreeter *greeter, gpointer data) { - fsync(d->toServerFd); + Q_UNUSED(greeter); + GreeterPrivate *that = static_cast<GreeterPrivate*>(data); + Q_EMIT that->q_func()->authenticationComplete(); } -static int readInt(char *message, int messageLength, int *offset) +void GreeterPrivate::cb_autoLoginExpired(LightDMGreeter *greeter, gpointer data) { - if(messageLength - *offset < intLength()) { - qDebug() << "Not enough space for int, need " << intLength() << ", got " << (messageLength - *offset); - return 0; - } - - char *buffer = message + *offset; - int value = buffer[0] << 24 | buffer[1] << 16 | buffer[2] << 8 | buffer[3]; - *offset += intLength(); - return value; + Q_UNUSED(greeter); + GreeterPrivate *that = static_cast<GreeterPrivate*>(data); + Q_EMIT that->q_func()->autologinTimerExpired(); } -static int getMessageLength(char *message, int messageLength) +Greeter::Greeter(QObject *parent) : + QObject(parent), + d_ptr(new GreeterPrivate(this)) { - int offset = intLength(); - return readInt(message, messageLength, &offset); } -static QString readString(char *message, int messageLength, int *offset) +Greeter::~Greeter() { - int length = readInt(message, messageLength, offset); - if(messageLength - *offset < length) { - qDebug() << "Not enough space for string, need " << length << ", got " << (messageLength - *offset); - return ""; - } - char *start = message + *offset; - *offset += length; - return QString::fromUtf8(start, length); + delete d_ptr; } + bool Greeter::connectSync() { - QDBusConnection busType = QDBusConnection::systemBus(); - QString ldmBus(qgetenv("LIGHTDM_BUS")); - if(ldmBus == QLatin1String("SESSION")) { - busType = QDBusConnection::sessionBus(); - } - - char* fd = getenv("LIGHTDM_TO_SERVER_FD"); - if(!fd) { - qDebug() << "No LIGHTDM_TO_SERVER_FD environment variable"; - return false; - } - d->toServerFd = atoi(fd); - - qDebug() << "***connecting to server"; - QFile toServer; - qDebug() << toServer.open(d->toServerFd, QIODevice::WriteOnly); - - fd = getenv("LIGHTDM_FROM_SERVER_FD"); - if(!fd) { - qDebug() << "No LIGHTDM_FROM_SERVER_FD environment variable"; - return false; - } - 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, stringLength(VERSION)); - writeString(VERSION); - flush(); - - int responseLength; - char *response = readMessage(&responseLength, false); - if (!response) - return false; - - int offset = 0; - int id = readInt(response, responseLength, &offset); - int length = readInt(response, responseLength, &offset); - bool connected = false; - if (id == SERVER_MESSAGE_CONNECTED) - { - QString version = readString(response, responseLength, &offset); - QString hintString = ""; - while (offset < length) - { - QString name = readString(response, responseLength, &offset); - QString value = readString(response, responseLength, &offset); - hintString.append (" "); - hintString.append (name); - hintString.append ("="); - hintString.append (value); - } - - qDebug() << "Connected version=" << version << hintString; - connected = true; - } - else - qDebug() << "Expected CONNECTED message, got " << id; - free(response); - - return connected; + Q_D(Greeter); + return lightdm_greeter_connect_sync(d->ldmGreeter, NULL); } void Greeter::authenticate(const QString &username) { - d->inAuthentication = true; - d->isAuthenticated = false; - d->cancellingAuthentication = false; - d->authenticationUser = username; - qDebug() << "Starting authentication for user " << username << "..."; - writeHeader(GREETER_MESSAGE_AUTHENTICATE, intLength() + stringLength(username)); - d->authenticateSequenceNumber++; - writeInt(d->authenticateSequenceNumber); - writeString(username); - flush(); + Q_D(Greeter); + lightdm_greeter_authenticate(d->ldmGreeter, username.toLocal8Bit().data()); } void Greeter::authenticateAsGuest() { - d->authenticateSequenceNumber++; - d->inAuthentication = true; - d->isAuthenticated = false; - d->cancellingAuthentication = false; - d->authenticationUser = ""; - qDebug() << "Starting authentication for guest account"; - writeHeader(GREETER_MESSAGE_AUTHENTICATE_AS_GUEST, intLength()); - writeInt(d->authenticateSequenceNumber); - flush(); + Q_D(Greeter); + lightdm_greeter_authenticate_as_guest(d->ldmGreeter); + } void Greeter::respond(const QString &response) { - qDebug() << "Providing response to display manager"; - writeHeader(GREETER_MESSAGE_CONTINUE_AUTHENTICATION, intLength() + stringLength(response)); - // FIXME: Could be multiple response required - writeInt(1); - writeString(response); - flush(); + Q_D(Greeter); + lightdm_greeter_respond(d->ldmGreeter, response.toLocal8Bit().data()); } void Greeter::cancelAuthentication() { - qDebug() << "Cancelling authentication"; - d->cancellingAuthentication = true; - writeHeader(GREETER_MESSAGE_CANCEL_AUTHENTICATION, 0); - flush(); + Q_D(Greeter); + lightdm_greeter_cancel_authentication(d->ldmGreeter); } bool Greeter::inAuthentication() const { - return d->inAuthentication; + Q_D(const Greeter); + return lightdm_greeter_get_in_authentication(d->ldmGreeter); } bool Greeter::isAuthenticated() const { - return d->isAuthenticated; + Q_D(const Greeter); + return lightdm_greeter_get_is_authenticated(d->ldmGreeter); } QString Greeter::authenticationUser() const { - return d->authenticationUser; + Q_D(const Greeter); + return QString::fromLocal8Bit(lightdm_greeter_get_authentication_user(d->ldmGreeter)); } -void Greeter::setLanguage (QString language) +void Greeter::setLanguage (const QString &language) { - writeHeader(GREETER_MESSAGE_SET_LANGUAGE, stringLength(language)); - writeString (language); - flush(); + Q_D(Greeter); + lightdm_greeter_set_language(d->ldmGreeter, language.toLocal8Bit().constData()); } bool Greeter::startSessionSync(const QString &session) { - if (session == "") - qDebug() << "Starting default session"; - else - qDebug() << "Starting session " << session; - - writeHeader(GREETER_MESSAGE_START_SESSION, stringLength(session)); - writeString(session); - flush(); - - int responseLength; - char *response = readMessage(&responseLength, false); - if (!response) - return false; - - int offset = 0; - int id = readInt(response, responseLength, &offset); - readInt(response, responseLength, &offset); - int returnCode = -1; - if (id == SERVER_MESSAGE_SESSION_RESULT) - returnCode = readInt(response, responseLength, &offset); - else - qDebug() << "Expected SESSION_RESULT message, got " << id; - free(response); - - return returnCode == 0; + Q_D(Greeter); + return lightdm_greeter_start_session_sync(d->ldmGreeter, session.toLocal8Bit().constData(), NULL); } -char *Greeter::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); - - do - { - ssize_t nRead = read(d->fromServerFd, d->readBuffer + d->nRead, nToRead - d->nRead); - if(nRead < 0) - { - qDebug() << "Error reading from server"; - return NULL; - } - if (nRead == 0) - { - qDebug() << "EOF reading from server"; - return NULL; - } - - qDebug() << "Read " << nRead << " octets from daemon"; - d->nRead += nRead; - } while(d->nRead < nToRead && block); - - /* Stop if haven't got all the data we want */ - if(d->nRead != nToRead) - return NULL; - - /* If have header, rerun for content */ - if(d->nRead == HEADER_SIZE) - { - nToRead = getMessageLength(d->readBuffer, d->nRead); - if(nToRead > 0) - { - d->readBuffer = (char *)realloc(d->readBuffer, HEADER_SIZE + nToRead); - return readMessage(length, block); - } - } - - char *buffer = d->readBuffer; - *length = d->nRead; - - d->readBuffer = (char *)malloc(d->nRead); - d->nRead = 0; - - return buffer; -} - -void Greeter::onRead(int fd) -{ - qDebug() << "Reading from server"; - - int messageLength; - char *message = readMessage(&messageLength, false); - if (!message) - return; - - int offset = 0; - int id = readInt(message, messageLength, &offset); - int length = readInt(message, messageLength, &offset); - int nMessages, sequenceNumber, returnCode; - QString version, username; - switch(id) - { - case SERVER_MESSAGE_PROMPT_AUTHENTICATION: - sequenceNumber = readInt(message, messageLength, &offset); - username = readString(message, messageLength, &offset); - - d->authenticationUser = username; - - if (sequenceNumber == d->authenticateSequenceNumber && - !d->cancellingAuthentication) - { - nMessages = readInt(message, messageLength, &offset); - qDebug() << "Prompt user with " << nMessages << " message(s)"; - for(int i = 0; i < nMessages; i++) - { - int style = readInt(message, messageLength, &offset); - QString text = readString(message, messageLength, &offset); - - // FIXME: Should stop on prompts? - switch (style) - { - case PAM_PROMPT_ECHO_OFF: - emit showPrompt(text, PROMPT_TYPE_SECRET); - break; - case PAM_PROMPT_ECHO_ON: - emit showPrompt(text, PROMPT_TYPE_QUESTION); - break; - case PAM_ERROR_MSG: - emit showMessage(text, MESSAGE_TYPE_ERROR); - break; - case PAM_TEXT_INFO: - emit showMessage(text, MESSAGE_TYPE_INFO); - break; - } - } - } - break; - case SERVER_MESSAGE_END_AUTHENTICATION: - sequenceNumber = readInt(message, messageLength, &offset); - username = readString(message, messageLength, &offset); - returnCode = readInt(message, messageLength, &offset); - - if (sequenceNumber == d->authenticateSequenceNumber) - { - qDebug() << "Authentication complete with return code " << returnCode; - - d->cancellingAuthentication = false; - d->isAuthenticated = (returnCode == 0); - d->authenticationUser = username; - d->inAuthentication = false; - emit authenticationComplete(); - } - else - qDebug () << "Ignoring end authentication with invalid sequence number " << sequenceNumber; - break; - default: - qDebug() << "Unknown message from server: " << id; - } - free(message); -} -QString Greeter::getHint(QString name) const +QString Greeter::getHint(const QString &name) const { - return d->hints.value (name); + Q_D(const Greeter); + return lightdm_greeter_get_hint(d->ldmGreeter, name.toLocal8Bit().constData()); } QString Greeter::defaultSessionHint() const { - return getHint ("default-session"); + Q_D(const Greeter); + return QString::fromLocal8Bit(lightdm_greeter_get_default_session_hint(d->ldmGreeter)); } bool Greeter::hideUsersHint() const { - return d->hints.value ("hide-users", "true") == "true"; + Q_D(const Greeter); + return lightdm_greeter_get_hide_users_hint(d->ldmGreeter); } bool Greeter::hasGuestAccountHint() const { - return d->hints.value ("has-guest-account", "false") == "true"; + Q_D(const Greeter); + return lightdm_greeter_get_has_guest_account_hint(d->ldmGreeter); } QString Greeter::selectUserHint() const { - return getHint ("select-user"); + Q_D(const Greeter); + return QString::fromLocal8Bit(lightdm_greeter_get_select_user_hint(d->ldmGreeter)); } bool Greeter::selectGuestHint() const { - return d->hints.value ("select-guest", "false") == "true"; + Q_D(const Greeter); + return lightdm_greeter_get_select_guest_hint(d->ldmGreeter); } QString Greeter::autologinUserHint() const { - return getHint ("autologin-user"); + Q_D(const Greeter); + return QString::fromLocal8Bit(lightdm_greeter_get_autologin_user_hint(d->ldmGreeter)); } bool Greeter::autologinGuestHint() const { - return d->hints.value ("autologin-guest", "false") == "true"; + Q_D(const Greeter); + return lightdm_greeter_get_autologin_guest_hint(d->ldmGreeter); } int Greeter::autologinTimeoutHint() const { - return d->hints.value ("autologin-timeout", "0").toInt (); + Q_D(const Greeter); + return lightdm_greeter_get_autologin_timeout_hint(d->ldmGreeter); } + +#include "greeter_moc.cpp" diff --git a/liblightdm-qt/language.cpp b/liblightdm-qt/language.cpp deleted file mode 100644 index 8c087a80..00000000 --- a/liblightdm-qt/language.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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. - */ - -#include "QLightDM/Language" - -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/liblightdm-qt-1.pc.in b/liblightdm-qt/liblightdm-qt-2.pc.in index 1680dc70..2991bb2b 100644 --- a/liblightdm-qt/liblightdm-qt-1.pc.in +++ b/liblightdm-qt/liblightdm-qt-2.pc.in @@ -7,5 +7,5 @@ Name: liblightdm-qt Description: LightDM client library Version: @VERSION@ Requires: QtCore QtGui -Libs: -L${libdir} -llightdm-qt-1 -Cflags: -I${includedir}/lightdm-qt-1 +Libs: -L${libdir} -llightdm-qt-2 +Cflags: -I${includedir}/lightdm-qt-2 diff --git a/liblightdm-qt/power.cpp b/liblightdm-qt/power.cpp index 8656c247..46bd8312 100644 --- a/liblightdm-qt/power.cpp +++ b/liblightdm-qt/power.cpp @@ -10,101 +10,105 @@ * license. */ -#include "config.h" -#include "QLightDM/Power" +#include "QLightDM/power.h" #include <QtCore/QVariant> #include <QtDBus/QDBusInterface> #include <QtDBus/QDBusReply> -using namespace QLightDM; +#include "config.h" -static QDBusInterface* powerManagementInterface = NULL; -static QDBusInterface* consoleKitInterface = NULL; +using namespace QLightDM; -static bool setupPowerManagementInterface () +class PowerInterface::PowerInterfacePrivate +{ +public: + PowerInterfacePrivate(); + QScopedPointer<QDBusInterface> powerManagementInterface; + QScopedPointer<QDBusInterface> consoleKitInterface; +}; + +PowerInterface::PowerInterfacePrivate::PowerInterfacePrivate() : + powerManagementInterface(new QDBusInterface("org.freedesktop.UPower","/org/freedesktop/UPower", "org.freedesktop.UPower", QDBusConnection::systemBus())), + consoleKitInterface(new QDBusInterface("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager", QDBusConnection::systemBus())) { - if (!powerManagementInterface) - powerManagementInterface = new QDBusInterface("org.freedesktop.UPower","/org/freedesktop/UPower", "org.freedesktop.UPower", QDBusConnection::systemBus()); - return powerManagementInterface != NULL; } -static bool setupConsoleKitInterface () + +PowerInterface::PowerInterface(QObject *parent) + : QObject(parent), + d(new PowerInterfacePrivate) { - if (!consoleKitInterface) - consoleKitInterface = new QDBusInterface("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager", QDBusConnection::systemBus()); - return consoleKitInterface != NULL; } -bool QLightDM::canSuspend() +PowerInterface::~PowerInterface() { - if (!setupPowerManagementInterface()) - return false; + delete d; +} - QDBusReply<bool> reply = powerManagementInterface->call("SuspendAllowed"); - if (reply.isValid()) +bool PowerInterface::canSuspend() +{ + QDBusReply<bool> reply = d->powerManagementInterface->call("SuspendAllowed"); + if (reply.isValid()) { return reply.value(); - else + } + else { return false; + } } -void QLightDM::suspend() +void PowerInterface::suspend() { - if (setupPowerManagementInterface()) - powerManagementInterface->call("Suspend"); + d->powerManagementInterface->call("Suspend"); } -bool QLightDM::canHibernate() +bool PowerInterface::canHibernate() { - if (!setupPowerManagementInterface()) - return false; - - QDBusReply<bool> reply = powerManagementInterface->call("HibernateAllowed"); - if (reply.isValid()) + QDBusReply<bool> reply = d->powerManagementInterface->call("HibernateAllowed"); + if (reply.isValid()) { return reply.value(); - else + } + else { return false; + } } -void QLightDM::hibernate() +void PowerInterface::hibernate() { - if (setupConsoleKitInterface()) - powerManagementInterface->call("Hibernate"); + d->powerManagementInterface->call("Hibernate"); } -bool QLightDM::canShutdown() +bool PowerInterface::canShutdown() { - if (!setupConsoleKitInterface()) - return false; - - QDBusReply<bool> reply = consoleKitInterface->call("CanStop"); - if (reply.isValid()) + QDBusReply<bool> reply = d->consoleKitInterface->call("CanStop"); + if (reply.isValid()) { return reply.value(); - else + } + else { return false; + } } -void QLightDM::shutdown() +void PowerInterface::shutdown() { - if (setupConsoleKitInterface()) - consoleKitInterface->call("Stop"); + d->consoleKitInterface->call("Stop"); } -bool QLightDM::canRestart() +bool PowerInterface::canRestart() { - if (!setupConsoleKitInterface()) - return false; - - QDBusReply<bool> reply = consoleKitInterface->call("CanRestart"); - if (reply.isValid()) + QDBusReply<bool> reply = d->consoleKitInterface->call("CanRestart"); + if (reply.isValid()) { return reply.value(); - else + } + else { return false; + } } -void QLightDM::restart() +void PowerInterface::restart() { - if (setupConsoleKitInterface()) - consoleKitInterface->call("Restart"); + d->consoleKitInterface->call("Restart"); } + +#include "power_moc.cpp" diff --git a/liblightdm-qt/session.cpp b/liblightdm-qt/sessionsmodel.cpp index 7134d937..cd4b2a49 100644 --- a/liblightdm-qt/session.cpp +++ b/liblightdm-qt/sessionsmodel.cpp @@ -9,55 +9,85 @@ * license. */ -#include "QLightDM/Session" +#include "QLightDM/sessionsmodel.h" -#include <QtCore/QList> -#include <QtCore/QDir> #include <QtCore/QVariant> -#include <QtCore/QSettings> +#include <QtCore/QDebug> -using namespace QLightDM; - -class SessionItem; +#include <lightdm.h> -class SessionsModelPrivate -{ -public: - QList<SessionItem> items; -}; +using namespace QLightDM; class SessionItem { public: - //FIXME can I make these consts, if I set them in a lovely constructor? QString id; QString name; QString comment; }; -static SessionsModel *session_model = NULL; -SessionsModel *QLightDM::sessions() +class SessionsModelPrivate +{ +public: + SessionsModelPrivate(SessionsModel *parent); + QList<SessionItem> items; + + void loadSessions(); + +protected: + SessionsModel* q_ptr; + +private: + Q_DECLARE_PUBLIC(SessionsModel) + +}; + +SessionsModelPrivate::SessionsModelPrivate(SessionsModel *parent) : + q_ptr(parent) +{ + g_type_init(); + loadSessions(); +} + +void SessionsModelPrivate::loadSessions() { - if (!session_model) - session_model = new SessionsModel (); + qDebug() << "loading sessions"; + + GList *ldmSessions = lightdm_get_sessions(); + for (GList* item = ldmSessions; item; item = item->next) { + LightDMSession *ldmSession = static_cast<LightDMSession*>(item->data); + Q_ASSERT(ldmSession); + + SessionItem session; + session.id = QString::fromLocal8Bit(lightdm_session_get_key(ldmSession)); + session.name = QString::fromLocal8Bit(lightdm_session_get_name(ldmSession)); + session.comment = QString::fromLocal8Bit(lightdm_session_get_comment(ldmSession)); + + qDebug() << "adding session" << session.id; - return session_model; + items.append(session); + } + + //this happens in the constructor so we don't need beginInsertRows() etc. } + SessionsModel::SessionsModel(QObject *parent) : QAbstractListModel(parent), - d(new SessionsModelPrivate()) + d_ptr(new SessionsModelPrivate(this)) { - buildList(); } SessionsModel::~SessionsModel() { + delete d_ptr; } int SessionsModel::rowCount(const QModelIndex &parent) const { + Q_D(const SessionsModel); + if (parent == QModelIndex()) { //if top level return d->items.size(); } else { @@ -67,6 +97,8 @@ int SessionsModel::rowCount(const QModelIndex &parent) const QVariant SessionsModel::data(const QModelIndex &index, int role) const { + Q_D(const SessionsModel); + if (! index.isValid()) { return QVariant(); } @@ -85,29 +117,4 @@ QVariant SessionsModel::data(const QModelIndex &index, int role) const return QVariant(); } -void SessionsModel::buildList() -{ - //maybe clear first? - - //FIXME don't hardcode this! - QDir sessionDir("/usr/share/xsessions"); - sessionDir.setNameFilters(QStringList() << "*.desktop"); - - QList<SessionItem> 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(); -} +#include "sessionsmodel_moc.cpp" diff --git a/liblightdm-qt/system.cpp b/liblightdm-qt/system.cpp index 8c11e6eb..2461aaad 100644 --- a/liblightdm-qt/system.cpp +++ b/liblightdm-qt/system.cpp @@ -10,11 +10,13 @@ * license. */ +#include "QLightDM/system.h" + #include <QtNetwork/QHostInfo> -#include "QLightDM/System" +using namespace QLightDM; -QString QLightDM::hostname() +QString System::hostname() { return QHostInfo::localHostName(); } diff --git a/liblightdm-qt/user.cpp b/liblightdm-qt/user.cpp deleted file mode 100644 index 1f5cd5f4..00000000 --- a/liblightdm-qt/user.cpp +++ /dev/null @@ -1,303 +0,0 @@ -/* - * 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. - */ - -#include "QLightDM/User" - -#include <pwd.h> -#include <errno.h> -#include <QtCore/QSharedData> -#include <QtCore/QString> -#include <QtCore/QFileSystemWatcher> -#include <QtCore/QFile> -#include <QtCore/QDir> -#include <QtCore/QSettings> -#include <QtCore/QDebug> - -#include <QtGui/QPixmap> - -using namespace QLightDM; - -static UsersModel *user_model = NULL; - -UsersModel *QLightDM::users() -{ - if (!user_model) - user_model = new UsersModel (); - - return user_model; -} - -class UserPrivate : public QSharedData -{ -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(other.d) -{ -} - -User::~User() -{ -} - - -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; -} - -class UsersModelPrivate { -public: - QList<User> users; -}; - -UsersModel::UsersModel(QObject *parent) : - QAbstractListModel(parent), - d (new UsersModelPrivate()) -{ - //load users on startup and if the password file changes. - QFileSystemWatcher *watcher = new QFileSystemWatcher(this); - watcher->addPath("/etc/passwd"); //FIXME harcoded path - connect(watcher, SIGNAL(fileChanged(QString)), SLOT(loadUsers())); - - loadUsers(); -} - -UsersModel::~UsersModel() -{ - delete d; -} - - -int UsersModel::rowCount(const QModelIndex &parent) const -{ - return d->users.count(); -} - -QVariant UsersModel::data(const QModelIndex &index, int role) const -{ - if (!index.isValid()) { - return QVariant(); - } - - int row = index.row(); - switch (role) { - case Qt::DisplayRole: - return d->users[row].displayName(); - case Qt::DecorationRole: - return QPixmap(d->users[row].image()); - case UsersModel::NameRole: - return d->users[row].name(); - case UsersModel::RealNameRole: - return d->users[row].realName(); - case UsersModel::LoggedInRole: - return d->users[row].isLoggedIn(); - } - - return QVariant(); -} - - -QList<User> UsersModel::getUsers() -{ - QString file = "/etc/lightdm/users.conf"; - qDebug() << "Loading user configuration from " << file; - QSettings *settings = new QSettings(file, QSettings::IniFormat); - - int minimumUid = settings->value("UserAccounts/minimum-uid", QVariant(500)).toInt(); - QStringList hiddenShells; - if (settings->contains("UserAccounts/hidden-shells")) - hiddenShells = settings->value("UserAccounts/hidden-shells").toString().split(" "); - else - hiddenShells = QStringList() << "/bin/false" << "/usr/sbin/nologin"; - QStringList hiddenUsers; - if (settings->contains("UserAccounts/hidden-users")) - hiddenUsers = settings->value("UserAccounts/hidden-users").toString().split(" "); - else - hiddenUsers = QStringList() << "nobody" << "nobody4" << "noaccess"; - - QList<User> users; - - setpwent(); - while(TRUE) - { - errno = 0; - struct passwd *entry = getpwent(); - if(!entry) { - break; - } - - /* Ignore system users */ - if(entry->pw_uid < minimumUid) { - continue; - } - - /* Ignore users disabled by shell */ - if(entry->pw_shell) { - if (hiddenShells.contains(entry->pw_shell)) { - continue; - } - } - - if (hiddenUsers.contains(entry->pw_name)) { - continue; - } - - QStringList tokens = QString(entry->pw_gecos).split(","); - QString realName; - if(tokens.size() > 0 && tokens.at(0) != "") - realName = tokens.at(0); - - QDir homeDir(entry->pw_dir); - QString image = homeDir.filePath(".face"); - if(!QFile::exists (image)) { - image = homeDir.filePath(".face.icon"); - if(!QFile::exists (image)) - image = ""; - } - - User user(entry->pw_name, realName, entry->pw_dir, image, false); - users.append(user); - } - - if(errno != 0) { - qDebug() << "Failed to read password database: " << strerror(errno); - } - endpwent(); - - delete settings; - - return users; -} - -void UsersModel::loadUsers() -{ - QList<User> usersToAdd; - - //FIXME accidently not got the "if contact removed" code. Need to restore that. - //should call beginRemoveRows, and then remove the row from the model. - //might get rid of "User" object, keep as private object (like sessionsmodel) - or make it copyable. - - //loop through all the new list of users, if it's in the list already update it (or do nothing) otherwise append to list of new users - QList<User> newUserList = getUsers(); - - foreach(const User &user, newUserList) { - bool alreadyInList = false; - for(int i=0; i < d->users.size(); i++) { - if (user.name() == d->users[i].name()) { - alreadyInList = true; - d->users[i].update(user.name(), user.homeDirectory(), user.image(), user.isLoggedIn()); - QModelIndex index = createIndex(i,0); - dataChanged(index, index); - } - } - - if (!alreadyInList) { - usersToAdd.append(user); - } - } - - //loop through all the existing users, if they're not in the newly gathered list, remove them. - - //FIXME this isn't perfect, looping like this in a mutating list - use mutable iterator. - for (int i=0; i < d->users.size() ; i++) { - bool found = false; - foreach(const User &user, newUserList) { - if (d->users[i].name() == user.name()) { - found = true; - } - } - - if (!found) { - beginRemoveRows(QModelIndex(), i, i); - d->users.removeAt(i); - endRemoveRows(); - } - } - - //append new users - if (usersToAdd.size() > 0) { - beginInsertRows(QModelIndex(), d->users.size(), d->users.size() + usersToAdd.size() -1); - d->users.append(usersToAdd); - endInsertRows(); - } -} diff --git a/liblightdm-qt/usersmodel.cpp b/liblightdm-qt/usersmodel.cpp new file mode 100644 index 00000000..dcd3b58b --- /dev/null +++ b/liblightdm-qt/usersmodel.cpp @@ -0,0 +1,218 @@ +/* + * 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. + */ + +#include "QLightDM/usersmodel.h" + +#include <QtCore/QString> +#include <QtCore/QDebug> +#include <QtGui/QPixmap> + +#include <lightdm.h> + +using namespace QLightDM; + +class UserItem +{ +public: + QString name; + QString realName; + QString homeDirectory; + QString image; + bool isLoggedIn; + QString displayName() const; +}; + +QString UserItem::displayName() const { + if (realName.isEmpty()){ + return name; + } + else { + return realName; + } +} + +namespace QLightDM { +class UsersModelPrivate { +public: + UsersModelPrivate(UsersModel *parent); + virtual ~UsersModelPrivate(); + QList<UserItem> users; + + protected: + UsersModel * const q_ptr; + + void loadUsers(); + + static void cb_userAdded(LightDMUserList *user_list, LightDMUser *user, gpointer data); + static void cb_userChanged(LightDMUserList *user_list, LightDMUser *user, gpointer data); + static void cb_userRemoved(LightDMUserList *user_list, LightDMUser *user, gpointer data); + private: + Q_DECLARE_PUBLIC(UsersModel) +}; +} + +UsersModelPrivate::UsersModelPrivate(UsersModel* parent) : + q_ptr(parent) +{ + g_type_init(); +} + +UsersModelPrivate::~UsersModelPrivate() +{ + g_signal_handlers_disconnect_by_func(lightdm_user_list_get_instance(), NULL, this); +} + +void UsersModelPrivate::loadUsers() +{ + Q_Q(UsersModel); + + int rowCount = lightdm_user_list_get_length(lightdm_user_list_get_instance()); + + if (rowCount == 0) { + return; + } else { + q->beginInsertRows(QModelIndex(), 0, rowCount-1); + + const GList *items, *item; + items = lightdm_user_list_get_users(lightdm_user_list_get_instance()); + for (item = items; item; item = item->next) { + LightDMUser *ldmUser = static_cast<LightDMUser*>(item->data); + + UserItem user; + user.name = QString::fromLocal8Bit(lightdm_user_get_name(ldmUser)); + user.homeDirectory = QString::fromLocal8Bit(lightdm_user_get_home_directory(ldmUser)); + user.realName = QString::fromLocal8Bit(lightdm_user_get_real_name(ldmUser)); + user.image = QString::fromLocal8Bit(lightdm_user_get_image(ldmUser)); + user.isLoggedIn = lightdm_user_get_logged_in(ldmUser); + users.append(user); + } + + q->endInsertRows(); + } + g_signal_connect(lightdm_user_list_get_instance(), "user-added", G_CALLBACK (cb_userAdded), this); + g_signal_connect(lightdm_user_list_get_instance(), "user-changed", G_CALLBACK (cb_userChanged), this); + g_signal_connect(lightdm_user_list_get_instance(), "user-removed", G_CALLBACK (cb_userRemoved), this); +} + + + +void UsersModelPrivate::cb_userAdded(LightDMUserList *user_list, LightDMUser *ldmUser, gpointer data) +{ + Q_UNUSED(user_list) + UsersModelPrivate *that = static_cast<UsersModelPrivate*>(data); + + that->q_func()->beginInsertRows(QModelIndex(), that->users.size(), that->users.size()); + + UserItem user; + user.name = QString::fromLocal8Bit(lightdm_user_get_name(ldmUser)); + user.homeDirectory = QString::fromLocal8Bit(lightdm_user_get_home_directory(ldmUser)); + user.realName = QString::fromLocal8Bit(lightdm_user_get_real_name(ldmUser)); + user.image = QString::fromLocal8Bit(lightdm_user_get_image(ldmUser)); + user.isLoggedIn = lightdm_user_get_logged_in(ldmUser); + that->users.append(user); + + that->q_func()->endInsertRows(); + +} + +void UsersModelPrivate::cb_userChanged(LightDMUserList *user_list, LightDMUser *ldmUser, gpointer data) +{ + Q_UNUSED(user_list) + UsersModelPrivate *that = static_cast<UsersModelPrivate*>(data); + + QString userToChange = QString::fromLocal8Bit(lightdm_user_get_name(ldmUser)); + + for (int i=0;i<that->users.size();i++) { + if (that->users[i].name == userToChange) { + + that->users[i].homeDirectory = QString::fromLocal8Bit(lightdm_user_get_home_directory(ldmUser)); + that->users[i].realName = QString::fromLocal8Bit(lightdm_user_get_real_name(ldmUser)); + that->users[i].image = QString::fromLocal8Bit(lightdm_user_get_image(ldmUser)); + that->users[i].isLoggedIn = lightdm_user_get_logged_in(ldmUser); + + QModelIndex index = that->q_ptr->createIndex(i, 0); + that->q_ptr->dataChanged(index, index); + break; + } + } +} + + +void UsersModelPrivate::cb_userRemoved(LightDMUserList *user_list, LightDMUser *ldmUser, gpointer data) +{ + Q_UNUSED(user_list) + + UsersModelPrivate *that = static_cast<UsersModelPrivate*>(data); + QString userToRemove = QString::fromLocal8Bit(lightdm_user_get_name(ldmUser)); + + QList<UserItem>::iterator i; + for (int i=0;i<that->users.size();i++) { + if (that->users[i].name == userToRemove) { + that->q_ptr->beginRemoveRows(QModelIndex(), i, i); + that->users.removeAt(i); + that->q_ptr->endMoveRows(); + break; + } + } +} + +UsersModel::UsersModel(QObject *parent) : + QAbstractListModel(parent), + d_ptr(new UsersModelPrivate(this)) +{ + Q_D(UsersModel); + d->loadUsers(); + +} + +UsersModel::~UsersModel() +{ + delete d_ptr; +} + + +int UsersModel::rowCount(const QModelIndex &parent) const +{ + Q_D(const UsersModel); + if (parent == QModelIndex()) { + return d->users.size(); + } + + return 0; +} + +QVariant UsersModel::data(const QModelIndex &index, int role) const +{ + Q_D(const UsersModel); + + if (!index.isValid()) { + return QVariant(); + } + + int row = index.row(); + switch (role) { + case Qt::DisplayRole: + return d->users[row].displayName(); + case Qt::DecorationRole: + return QPixmap(d->users[row].image); + case UsersModel::NameRole: + return d->users[row].name; + case UsersModel::RealNameRole: + return d->users[row].realName; + case UsersModel::LoggedInRole: + return d->users[row].isLoggedIn; + } + + return QVariant(); +} + + +#include "usersmodel_moc.cpp" diff --git a/tests/src/Makefile.am b/tests/src/Makefile.am index 30f38013..44d32e4a 100644 --- a/tests/src/Makefile.am +++ b/tests/src/Makefile.am @@ -83,7 +83,7 @@ test_qt_greeter_CXXFLAGS = \ $(XCB_CFLAGS) test_qt_greeter_LDADD = \ -L$(top_builddir)/liblightdm-qt \ - -llightdm-qt-1 \ + -llightdm-qt-2 \ $(LIBLIGHTDM_QT_LIBS) \ $(XCB_LIBS) diff --git a/tests/src/test-qt-greeter.cpp b/tests/src/test-qt-greeter.cpp index 08817a9c..7380beaa 100644 --- a/tests/src/test-qt-greeter.cpp +++ b/tests/src/test-qt-greeter.cpp @@ -14,17 +14,17 @@ static QSettings *config = NULL; TestGreeter::TestGreeter () { - connect (this, SIGNAL(showMessage(QString, QLightDM::MessageType)), SLOT(showMessage(QString, QLightDM::MessageType))); - connect (this, SIGNAL(showPrompt(QString, QLightDM::PromptType)), SLOT(showPrompt(QString, QLightDM::PromptType))); + connect (this, SIGNAL(showMessage(QString, QLightDM::Greeter::MessageType)), SLOT(showMessage(QString, QLightDM::Greeter::MessageType))); + connect (this, SIGNAL(showPrompt(QString, QLightDM::Greeter::PromptType)), SLOT(showPrompt(QString, QLightDM::Greeter::PromptType))); connect (this, SIGNAL(authenticationComplete()), SLOT(authenticationComplete())); } -void TestGreeter::showMessage (QString text, QLightDM::MessageType type) +void TestGreeter::showMessage (QString text, QLightDM::Greeter::MessageType type) { notify_status ("GREETER SHOW-MESSAGE TEXT=\"%s\"", text.toAscii ().constData ()); } -void TestGreeter::showPrompt (QString text, QLightDM::PromptType type) +void TestGreeter::showPrompt (QString text, QLightDM::Greeter::PromptType type) { notify_status ("GREETER SHOW-PROMPT TEXT=\"%s\"", text.toAscii ().constData ()); diff --git a/tests/src/test-qt-greeter.h b/tests/src/test-qt-greeter.h index c224759f..16fd9b26 100644 --- a/tests/src/test-qt-greeter.h +++ b/tests/src/test-qt-greeter.h @@ -8,7 +8,7 @@ public: TestGreeter (); private slots: - void showMessage(QString text, QLightDM::MessageType type); - void showPrompt(QString text, QLightDM::PromptType type); + void showMessage(QString text, QLightDM::Greeter::MessageType type); + void showPrompt(QString text, QLightDM::Greeter::PromptType type); void authenticationComplete(); }; |