Commit 66203bda authored by Tomi Leppänen's avatar Tomi Leppänen

[nemo-systemsettings] Add displayName to UserInfo. Contributes to JB#49172

Add displayName to UserInfo and add default value for device owner.
Signed-off-by: Tomi Leppänen's avatarTomi Leppänen <tomi.leppanen@jolla.com>
parent 8518e1ec
......@@ -98,11 +98,14 @@ void UserInfoPrivate::set(struct passwd *pwd)
if (m_username != username) {
m_username = username;
emit usernameChanged();
if (m_name.isEmpty() && name.isEmpty())
emit displayNameChanged();
}
if (m_name != name) {
m_name = name;
emit nameChanged();
emit displayNameChanged();
}
}
......@@ -193,6 +196,20 @@ bool UserInfo::isValid() const
return d->m_uid != InvalidId;
}
QString UserInfo::displayName() const
{
Q_D(const UserInfo);
if (d->m_name.isEmpty()) {
if (type() == DeviceOwner) {
//: Default value for device owner's name when it is not set
//% "Device owner"
return qtTrId("systemsettings-li-device_owner");
}
return d->m_username;
}
return d->m_name;
}
QString UserInfo::username() const
{
Q_D(const UserInfo);
......@@ -205,6 +222,8 @@ void UserInfo::setUsername(QString username)
if (d->m_username != username) {
d->m_username = username;
emit d_ptr->usernameChanged();
if (d->m_name.isEmpty())
emit d_ptr->displayNameChanged();
}
}
......@@ -220,6 +239,7 @@ void UserInfo::setName(QString name)
if (d->m_name != name) {
d->m_name = name;
emit d_ptr->nameChanged();
emit d_ptr->displayNameChanged();
}
}
......@@ -298,6 +318,7 @@ bool UserInfo::operator!=(const UserInfo &other) const
void UserInfo::connectSignals()
{
connect(d_ptr.data(), &UserInfoPrivate::displayNameChanged, this, &UserInfo::displayNameChanged);
connect(d_ptr.data(), &UserInfoPrivate::usernameChanged, this, &UserInfo::usernameChanged);
connect(d_ptr.data(), &UserInfoPrivate::nameChanged, this, &UserInfo::nameChanged);
connect(d_ptr.data(), &UserInfoPrivate::uidChanged, this, &UserInfo::uidChanged);
......
......@@ -46,6 +46,7 @@ class SYSTEMSETTINGS_EXPORT UserInfo: public QObject
Q_OBJECT
Q_DECLARE_PRIVATE(UserInfo)
Q_PROPERTY(QString displayName READ displayName NOTIFY displayNameChanged)
Q_PROPERTY(QString username READ username NOTIFY usernameChanged)
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
Q_PROPERTY(UserType type READ type CONSTANT)
......@@ -69,6 +70,7 @@ public:
bool isValid() const;
QString displayName() const;
QString username() const;
QString name() const;
UserType type() const;
......@@ -82,6 +84,7 @@ public:
bool operator!=(const UserInfo &other) const;
signals:
void displayNameChanged();
void usernameChanged();
void nameChanged();
void uidChanged();
......
......@@ -56,6 +56,7 @@ public:
void set(struct passwd *pwd);
signals:
void displayNameChanged();
void usernameChanged();
void nameChanged();
void uidChanged();
......
......@@ -153,7 +153,7 @@ QVariant UserModel::data(const QModelIndex &index, int role) const
const UserInfo &user = m_users.at(index.row());
switch (role) {
case Qt::DisplayRole:
return (user.name().isEmpty()) ? user.username() : user.name();
return user.displayName();
case UsernameRole:
return user.username();
case NameRole:
......
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