You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
133 lines
5.9 KiB
133 lines
5.9 KiB
From 668f7c9c08ce4aeee7cc4d2d3386522bfae32cfb Mon Sep 17 00:00:00 2001
|
|
From: Antonio Larrosa <larrosa@kde.org>
|
|
Date: Wed, 11 Nov 2015 19:05:36 +0100
|
|
Subject: [PATCH 22/34] Defines a users threshold to disable avatars
|
|
|
|
Defines a new config setting DisableAvatarsThreshold.
|
|
If the number of users in the system is greater than
|
|
DisableAvatarsThreshold then avatars are disabled unless
|
|
explicitly enabled with EnableAvatars. Also, UserModel
|
|
adds a new disableAvatarsThreshold property so themes can
|
|
decide if using that config setting to do further optimizations
|
|
if there's a large number of users (like for example,
|
|
not show a user list, but username/password editlines).
|
|
---
|
|
src/common/Configuration.h | 3 +++
|
|
src/greeter/UserModel.cpp | 43 +++++++++++++++++++++++++------------------
|
|
src/greeter/UserModel.h | 2 ++
|
|
3 files changed, 30 insertions(+), 18 deletions(-)
|
|
|
|
diff --git a/src/common/Configuration.h b/src/common/Configuration.h
|
|
index 5bd5296..10310c3 100644
|
|
--- a/src/common/Configuration.h
|
|
+++ b/src/common/Configuration.h
|
|
@@ -50,6 +50,9 @@ namespace SDDM {
|
|
"The files should be named <username>.face.icon"));
|
|
Entry(CursorTheme, QString, QString(), _S("Cursor theme used in the greeter"));
|
|
Entry(EnableAvatars, bool, true, _S("Enable display of custom user avatars"));
|
|
+ Entry(DisableAvatarsThreshold,int, 7, _S("Number of users to use as threshold\n"
|
|
+ "above which avatars are disabled\n"
|
|
+ "unless explicitly enabled with EnableAvatars"));
|
|
);
|
|
|
|
// TODO: Not absolutely sure if everything belongs here. Xsessions, VT and probably some more seem universal
|
|
diff --git a/src/greeter/UserModel.cpp b/src/greeter/UserModel.cpp
|
|
index f56c67a..ba2a9db 100644
|
|
--- a/src/greeter/UserModel.cpp
|
|
+++ b/src/greeter/UserModel.cpp
|
|
@@ -51,6 +51,9 @@ namespace SDDM {
|
|
};
|
|
|
|
UserModel::UserModel(QObject *parent) : QAbstractListModel(parent), d(new UserModelPrivate()) {
|
|
+ const QString facesDir = mainConfig.Theme.FacesDir.get();
|
|
+ const QString defaultFace = QStringLiteral("%1/.face.icon").arg(facesDir);
|
|
+
|
|
struct passwd *current_pw;
|
|
while ((current_pw = getpwent()) != nullptr) {
|
|
|
|
@@ -81,23 +84,7 @@ namespace SDDM {
|
|
user->needsPassword = strcmp(current_pw->pw_passwd, "") != 0;
|
|
|
|
// search for face icon
|
|
- QString facesDir = mainConfig.Theme.FacesDir.get();
|
|
- QString defaultFace = QStringLiteral("%1/.face.icon").arg(facesDir);
|
|
- bool avatarsEnabled = mainConfig.Theme.EnableAvatars.get();
|
|
-
|
|
- if (avatarsEnabled) {
|
|
- QString userFace = QStringLiteral("%1/.face.icon").arg(user->homeDir);
|
|
- QString systemFace = QStringLiteral("%1/%2.face.icon").arg(facesDir).arg(user->name);
|
|
-
|
|
- if (QFile::exists(userFace))
|
|
- user->icon = userFace;
|
|
- else if (QFile::exists(systemFace))
|
|
- user->icon = systemFace;
|
|
- else
|
|
- user->icon = defaultFace;
|
|
- } else {
|
|
- user->icon = defaultFace;
|
|
- }
|
|
+ user->icon = defaultFace;
|
|
|
|
// add user
|
|
d->users << user;
|
|
@@ -108,10 +95,26 @@ namespace SDDM {
|
|
// sort users by username
|
|
std::sort(d->users.begin(), d->users.end(), [&](const UserPtr &u1, const UserPtr &u2) { return u1->name < u2->name; });
|
|
|
|
+ bool avatarsEnabled = mainConfig.Theme.EnableAvatars.get();
|
|
+ if (avatarsEnabled && mainConfig.Theme.EnableAvatars.isDefault()) {
|
|
+ if (d->users.count() > mainConfig.Theme.DisableAvatarsThreshold.get()) avatarsEnabled=false;
|
|
+ }
|
|
+
|
|
// find out index of the last user
|
|
for (int i = 0; i < d->users.size(); ++i) {
|
|
- if (d->users.at(i)->name == stateConfig.Last.User.get())
|
|
+ UserPtr user { d->users.at(i) };
|
|
+ if (user->name == stateConfig.Last.User.get())
|
|
d->lastIndex = i;
|
|
+
|
|
+ if (avatarsEnabled) {
|
|
+ const QString userFace = QStringLiteral("%1/.face.icon").arg(user->homeDir);
|
|
+ const QString systemFace = QStringLiteral("%1/%2.face.icon").arg(facesDir).arg(user->name);
|
|
+
|
|
+ if (QFile::exists(userFace))
|
|
+ user->icon = userFace;
|
|
+ else if (QFile::exists(systemFace))
|
|
+ user->icon = systemFace;
|
|
+ }
|
|
}
|
|
}
|
|
|
|
@@ -165,4 +168,8 @@ namespace SDDM {
|
|
// return empty value
|
|
return QVariant();
|
|
}
|
|
+
|
|
+ int UserModel::disableAvatarsThreshold() const {
|
|
+ return mainConfig.Theme.DisableAvatarsThreshold.get();
|
|
+ }
|
|
}
|
|
diff --git a/src/greeter/UserModel.h b/src/greeter/UserModel.h
|
|
index e089b4d..1bbf77e 100644
|
|
--- a/src/greeter/UserModel.h
|
|
+++ b/src/greeter/UserModel.h
|
|
@@ -33,6 +33,7 @@ namespace SDDM {
|
|
Q_PROPERTY(int lastIndex READ lastIndex CONSTANT)
|
|
Q_PROPERTY(QString lastUser READ lastUser CONSTANT)
|
|
Q_PROPERTY(int count READ rowCount CONSTANT)
|
|
+ Q_PROPERTY(int disableAvatarsThreshold READ disableAvatarsThreshold CONSTANT)
|
|
public:
|
|
enum UserRoles {
|
|
NameRole = Qt::UserRole + 1,
|
|
@@ -53,6 +54,7 @@ namespace SDDM {
|
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
|
|
|
+ int disableAvatarsThreshold() const;
|
|
private:
|
|
UserModelPrivate *d { nullptr };
|
|
};
|
|
--
|
|
2.5.0
|
|
|