Commit 790f1991 authored by Jan Blackquill's avatar Jan Blackquill 🌈
Browse files

[kcms/users]: Properly handle data changing in the model

Instead of resetting the model every time data changes, a more specific dataChanged signal is emitted.

BUG: 422172
parent 6dbf8d79
......@@ -37,7 +37,7 @@ void User::setUid(int value) {
return;
}
mUid = value;
Q_EMIT uidChanged(value);
Q_EMIT uidChanged();
}
QString User::name() const {
......@@ -50,7 +50,7 @@ void User::setName(const QString &value) {
return;
}
mName = value;
Q_EMIT nameChanged(value);
Q_EMIT nameChanged();
}
QString User::realName() const {
......@@ -63,7 +63,7 @@ void User::setRealName(const QString &value) {
return;
}
mRealName = value;
Q_EMIT realNameChanged(value);
Q_EMIT realNameChanged();
}
QString User::email() const {
......@@ -76,7 +76,7 @@ void User::setEmail(const QString &value) {
return;
}
mEmail = value;
Q_EMIT emailChanged(value);
Q_EMIT emailChanged();
}
QUrl User::face() const {
......@@ -94,8 +94,8 @@ void User::setFace(const QUrl &value) {
}
mFace = value;
mFaceValid = QFile::exists(value.path());
Q_EMIT faceValidChanged(mFaceValid);
Q_EMIT faceChanged(value);
Q_EMIT faceValidChanged();
Q_EMIT faceChanged();
}
bool User::administrator() const {
......@@ -107,7 +107,7 @@ void User::setAdministrator(bool value) {
return;
}
mAdministrator = value;
Q_EMIT administratorChanged(value);
Q_EMIT administratorChanged();
}
void User::setPath(const QDBusObjectPath &path) {
......@@ -125,35 +125,35 @@ void User::setPath(const QDBusObjectPath &path) {
if (mUid != m_dbusIface->uid()) {
mUid = m_dbusIface->uid();
userDataChanged = true;
Q_EMIT uidChanged(mUid);
Q_EMIT uidChanged();
}
if (mName != m_dbusIface->userName()) {
mName = m_dbusIface->userName();
userDataChanged = true;
Q_EMIT nameChanged(mName);
Q_EMIT nameChanged();
}
if (mFace != QUrl(m_dbusIface->iconFile())) {
mFace = QUrl(m_dbusIface->iconFile());
mFaceValid = QFileInfo::exists(mFace.toString());
userDataChanged = true;
Q_EMIT faceChanged(mFace);
Q_EMIT faceValidChanged(mFaceValid);
Q_EMIT faceChanged();
Q_EMIT faceValidChanged();
}
if (mRealName != m_dbusIface->realName()) {
mRealName = m_dbusIface->realName();
userDataChanged = true;
Q_EMIT realNameChanged(mRealName);
Q_EMIT realNameChanged();
}
if (mEmail != m_dbusIface->email()) {
mEmail = m_dbusIface->email();
userDataChanged = true;
Q_EMIT emailChanged(mEmail);
Q_EMIT emailChanged();
}
const auto administrator = (m_dbusIface->accountType() == 1);
if (mAdministrator != administrator) {
mAdministrator = administrator;
userDataChanged = true;
Q_EMIT administratorChanged(mAdministrator);
Q_EMIT administratorChanged();
}
const auto loggedIn = (mUid == getuid());
if (mLoggedIn != loggedIn) {
......
......@@ -98,13 +98,13 @@ public Q_SLOTS:
signals:
void dataChanged();
void uidChanged(int uid);
void nameChanged(const QString &name);
void realNameChanged(const QString &realName);
void emailChanged(const QString &email);
void faceChanged(const QUrl &face);
void faceValidChanged(bool faceValid);
void administratorChanged(bool administrator);
void uidChanged();
void nameChanged();
void realNameChanged();
void emailChanged();
void faceChanged();
void faceValidChanged();
void administratorChanged();
private:
int mUid = 0;
......
......@@ -68,10 +68,23 @@ UserModel::UserModel(QObject* parent)
for (const QDBusObjectPath& path: users) {
User *user = new User(this);
user->setPath(path);
connect(user, &User::dataChanged, [=]() {
beginResetModel();
endResetModel();
});
const std::list<QPair<void(User::*const)(),int>> set = {
{&User::uidChanged, UidRole},
{&User::nameChanged, NameRole},
{&User::faceValidChanged, FaceValidRole},
{&User::realNameChanged, RealNameRole},
{&User::emailChanged, EmailRole},
{&User::administratorChanged, AdministratorRole},
};
for (const auto &item: set) {
connect(user, item.first, [this, user, item]{
auto idx = index(m_userList.lastIndexOf(user));
Q_EMIT dataChanged(idx, idx, {item.second});
});
}
m_userList.append(user);
}
std::sort(m_userList.begin(), m_userList.end(), [](User *lhs, User *) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment