mirror of
https://github.com/sddm/sddm.git
synced 2024-11-27 03:54:04 +08:00
Provide a user model to the themes.
This commit is contained in:
parent
0ea7025f62
commit
4410a93d3c
@ -31,6 +31,7 @@ set(SOURCES
|
||||
src/LockFile.cpp
|
||||
src/Main.cpp
|
||||
src/SessionManager.cpp
|
||||
src/UserModel.cpp
|
||||
src/Util.cpp
|
||||
)
|
||||
|
||||
|
@ -4,7 +4,7 @@ SDDM is a new lightweight display manager for X11 aiming to be fast, simple and
|
||||
|
||||
One of the distinctive features of SDDM is the ability to use QML for user interface creation. QML is a JavaScript-based, declarative language for designing user interface–centric applications. It is designed to provide highly customizable user interfaces with fluid animations. It supports images, gradients, color/size/opacity/property animations, hardware acceleration and lots of other stuff needed to create beatiful interfaces by today's standards.
|
||||
|
||||
SDDM's code base is tiny: under 1000 lines of code.
|
||||
SDDM has a small, simple and hackable codebase.
|
||||
|
||||
__Dependencies__
|
||||
|
||||
|
1
TODO
1
TODO
@ -1,5 +1,4 @@
|
||||
* Investigate suspend/hibernate.
|
||||
* List of available users with pictures, names etc.
|
||||
* Remembering last username, last session should be configurable.
|
||||
* Create a component library, to be used by themes.
|
||||
* Enable creation of configurable themes. Themes may provide a
|
||||
|
@ -39,6 +39,10 @@ ThemesDir=/usr/share/apps/sddm/themes
|
||||
# Name of the current theme
|
||||
CurrentTheme=${THEME}
|
||||
|
||||
# Minimum user id of the users to be listed in the
|
||||
# user interface
|
||||
MinimumUid=1000
|
||||
|
||||
# Name of last logged-in user. This username will be
|
||||
# preselected/shown when the login screen shows up.
|
||||
LastUser=
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "DisplayManager.h"
|
||||
#include "LockFile.h"
|
||||
#include "SessionManager.h"
|
||||
#include "UserModel.h"
|
||||
#include "Util.h"
|
||||
|
||||
#include <QDebug>
|
||||
@ -104,13 +105,17 @@ namespace SDE {
|
||||
QDeclarativeView view;
|
||||
view.setResizeMode(QDeclarativeView::SizeRootObjectToView);
|
||||
#endif
|
||||
// add session manager to context
|
||||
// create session manager
|
||||
SessionManager sessionManager;
|
||||
// create user model
|
||||
UserModel userModel;
|
||||
// set context properties
|
||||
view.rootContext()->setContextProperty("sessionManager", &sessionManager);
|
||||
view.rootContext()->setContextProperty("userModel", &userModel);
|
||||
// load theme
|
||||
view.setSource(QUrl::fromLocalFile(main));
|
||||
// show application
|
||||
view.show();
|
||||
view.showFullScreen();
|
||||
// execute application
|
||||
app.exec();
|
||||
}
|
||||
@ -171,6 +176,9 @@ namespace SDE {
|
||||
continue;
|
||||
}
|
||||
|
||||
// create user model
|
||||
UserModel userModel;
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
// execute user interface in a seperate process
|
||||
// this is needed because apperantly we can't create multiple
|
||||
@ -182,8 +190,9 @@ namespace SDE {
|
||||
// create view
|
||||
QQuickView view;
|
||||
view.setResizeMode(QQuickView::SizeRootObjectToView);
|
||||
// add session manager to context
|
||||
// set context properties
|
||||
view.rootContext()->setContextProperty("sessionManager", &sessionManager);
|
||||
view.rootContext()->setContextProperty("userModel", &userModel);
|
||||
// load qml file
|
||||
view.setSource(QUrl::fromLocalFile(main));
|
||||
// close view on successful login
|
||||
@ -202,8 +211,9 @@ namespace SDE {
|
||||
// create view
|
||||
QDeclarativeView view;
|
||||
view.setResizeMode(QDeclarativeView::SizeRootObjectToView);
|
||||
// add session manager to context
|
||||
// set context properties
|
||||
view.rootContext()->setContextProperty("sessionManager", &sessionManager);
|
||||
view.rootContext()->setContextProperty("userModel", &userModel);
|
||||
// load qml file
|
||||
view.setSource(QUrl::fromLocalFile(main));
|
||||
// close view on successful login
|
||||
|
@ -48,6 +48,8 @@ namespace SDE {
|
||||
QString themesDir { "" };
|
||||
QString currentTheme { "" };
|
||||
|
||||
int minimumUid { 0 };
|
||||
|
||||
QString lastUser { "" };
|
||||
QString autoUser { "" };
|
||||
};
|
||||
@ -84,6 +86,7 @@ namespace SDE {
|
||||
d->sessionCommand = settings.value("SessionCommand", "").toString();
|
||||
d->themesDir = settings.value("ThemesDir", "").toString();
|
||||
d->currentTheme = settings.value("CurrentTheme", "").toString();
|
||||
d->minimumUid = settings.value("MinimumUid", "0").toInt();
|
||||
d->lastUser = settings.value("LastUser", "").toString();
|
||||
d->autoUser = settings.value("AutoUser", "").toString();
|
||||
}
|
||||
@ -105,6 +108,7 @@ namespace SDE {
|
||||
settings.setValue("SessionCommand", d->sessionCommand);
|
||||
settings.setValue("ThemesDir", d->themesDir);
|
||||
settings.setValue("CurrentTheme", d->currentTheme);
|
||||
settings.setValue("MinimumUid", d->minimumUid);
|
||||
settings.setValue("LastUser", d->lastUser);
|
||||
settings.setValue("AutoUser", d->autoUser);
|
||||
}
|
||||
@ -169,6 +173,10 @@ namespace SDE {
|
||||
return d->currentTheme;
|
||||
}
|
||||
|
||||
const int Configuration::minimumUid() const {
|
||||
return d->minimumUid;
|
||||
}
|
||||
|
||||
const QString &Configuration::lastUser() const {
|
||||
return d->lastUser;
|
||||
}
|
||||
|
@ -59,6 +59,8 @@ namespace SDE {
|
||||
const QString &themesDir() const;
|
||||
const QString ¤tTheme() const;
|
||||
|
||||
const int minimumUid() const;
|
||||
|
||||
const QString &lastUser() const;
|
||||
void setLastUser(const QString &lastUser);
|
||||
|
||||
|
139
src/UserModel.cpp
Normal file
139
src/UserModel.cpp
Normal file
@ -0,0 +1,139 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Abdurrahman AVCI <abdurrahmanavci@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
***************************************************************************/
|
||||
|
||||
#include "UserModel.h"
|
||||
|
||||
#include "Configuration.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QList>
|
||||
#include <QTextStream>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace SDE {
|
||||
class User {
|
||||
public:
|
||||
QString userName { "" };
|
||||
QString realName { "" };
|
||||
QString icon { "" };
|
||||
int uid { 0 };
|
||||
int gid { 0 };
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<User> UserPtr;
|
||||
|
||||
class UserModelPrivate {
|
||||
public:
|
||||
QList<UserPtr> users;
|
||||
};
|
||||
|
||||
UserModel::UserModel(QObject *parent) : QAbstractListModel(parent), d(new UserModelPrivate()) {
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
||||
// set role names
|
||||
QHash<int, QByteArray> roleNames;
|
||||
roleNames[Qt::UserRole + 1] = "userName";
|
||||
roleNames[Qt::UserRole + 2] = "realName";
|
||||
roleNames[Qt::UserRole + 3] = "icon";
|
||||
// set role names
|
||||
setRoleNames(roleNames);
|
||||
#endif
|
||||
|
||||
// create file object
|
||||
QFile file("/etc/passwd");
|
||||
// open file
|
||||
if (!file.open(QIODevice::ReadOnly))
|
||||
return;
|
||||
|
||||
// create text stream
|
||||
QTextStream in(&file);
|
||||
|
||||
// process lines
|
||||
while (!in.atEnd()) {
|
||||
|
||||
// read line
|
||||
QString line = in.readLine();
|
||||
|
||||
// split line into fields
|
||||
QStringList fields = line.split(":", QString::KeepEmptyParts);
|
||||
|
||||
// there should be exactly 7 fields
|
||||
if (fields.length() != 7)
|
||||
continue;
|
||||
|
||||
// skip entries with uids smaller than minimum uid
|
||||
if (fields.at(2).toInt() < Configuration::instance()->minimumUid())
|
||||
continue;
|
||||
|
||||
UserPtr user { new User() };
|
||||
user->userName = fields.at(0);
|
||||
user->realName = fields.at(4).split(",").first();
|
||||
user->uid = fields.at(2).toInt();
|
||||
user->gid = fields.at(3).toInt();
|
||||
// TODO: set user icon
|
||||
user->icon = "/usr/share/apps/kdm/faces/root.face.icon";
|
||||
// add user
|
||||
beginInsertRows(QModelIndex(), rowCount(), rowCount());
|
||||
d->users << user;
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
// close file
|
||||
file.close();
|
||||
}
|
||||
|
||||
UserModel::~UserModel() {
|
||||
delete d;
|
||||
}
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
QHash<int, QByteArray> UserModel::roleNames() const {
|
||||
// set role names
|
||||
QHash<int, QByteArray> roleNames;
|
||||
roleNames[Qt::UserRole + 1] = "userName";
|
||||
roleNames[Qt::UserRole + 2] = "realName";
|
||||
roleNames[Qt::UserRole + 3] = "icon";
|
||||
|
||||
return roleNames;
|
||||
}
|
||||
#endif
|
||||
|
||||
int UserModel::rowCount(const QModelIndex &parent) const {
|
||||
return d->users.length();
|
||||
}
|
||||
|
||||
QVariant UserModel::data(const QModelIndex &index, int role) const {
|
||||
if (index.row() < 0 || index.row() > d->users.count())
|
||||
return QVariant();
|
||||
|
||||
// get user
|
||||
UserPtr user = d->users[index.row()];
|
||||
|
||||
// return correct value
|
||||
if (role == (Qt::UserRole + 1))
|
||||
return user->userName;
|
||||
else if (role == (Qt::UserRole + 2))
|
||||
return user->realName;
|
||||
else if (role == (Qt::UserRole + 3))
|
||||
return user->icon;
|
||||
|
||||
// return empty value
|
||||
return QVariant();
|
||||
}
|
||||
}
|
47
src/UserModel.h
Normal file
47
src/UserModel.h
Normal file
@ -0,0 +1,47 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2013 Abdurrahman AVCI <abdurrahmanavci@gmail.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef USERMODEL_H
|
||||
#define USERMODEL_H
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QHash>
|
||||
|
||||
namespace SDE {
|
||||
class UserModelPrivate;
|
||||
|
||||
class UserModel : public QAbstractListModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
UserModel(QObject *parent = 0);
|
||||
~UserModel();
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
#endif
|
||||
|
||||
int rowCount(const QModelIndex & parent = QModelIndex()) const override;
|
||||
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
private:
|
||||
UserModelPrivate *d { nullptr };
|
||||
};
|
||||
}
|
||||
|
||||
#endif // USERMODEL_H
|
Loading…
Reference in New Issue
Block a user