Commit eab99e0c authored by Tomi Leppänen's avatar Tomi Leppänen

[nemo-systemsettings] Add updateCurrent to UserInfo. Contributes to JB#47825

Add updateCurrent to UserInfo. Checks if user is current and updates the
status.
Signed-off-by: Tomi Leppänen's avatarTomi Leppänen <tomi.leppanen@jolla.com>
parent 66e08cc6
...@@ -68,10 +68,10 @@ UserInfoPrivate::UserInfoPrivate(struct passwd *pwd) ...@@ -68,10 +68,10 @@ UserInfoPrivate::UserInfoPrivate(struct passwd *pwd)
: m_uid(pwd->pw_uid) : m_uid(pwd->pw_uid)
, m_username(QString::fromUtf8(pwd->pw_name)) , m_username(QString::fromUtf8(pwd->pw_name))
, m_name(nameFromGecos(pwd->pw_gecos)) , m_name(nameFromGecos(pwd->pw_gecos))
// require_active == false -> both online and active are logged in. // require_active == true -> only active user is logged in.
// Specifying seat should make sure that remote users are not // Specifying seat should make sure that remote users are not
// counted as they don't have seats. // counted as they don't have seats.
, m_loggedIn(sd_uid_is_on_seat(m_uid, 0, "seat0") > 0) , m_loggedIn(sd_uid_is_on_seat(m_uid, 1, "seat0") > 0)
{ {
} }
...@@ -113,9 +113,7 @@ void UserInfoPrivate::set(struct passwd *pwd) ...@@ -113,9 +113,7 @@ void UserInfoPrivate::set(struct passwd *pwd)
*/ */
UserInfo::UserInfo() UserInfo::UserInfo()
{ {
if (!UserInfoPrivate::s_current.isNull()) { d_ptr = UserInfoPrivate::s_current.toStrongRef();
d_ptr = QSharedPointer<UserInfoPrivate>(UserInfoPrivate::s_current);
}
if (d_ptr.isNull()) { if (d_ptr.isNull()) {
uid_t uid = InvalidId; uid_t uid = InvalidId;
struct passwd *pwd; struct passwd *pwd;
...@@ -251,10 +249,27 @@ bool UserInfo::current() const ...@@ -251,10 +249,27 @@ bool UserInfo::current() const
return d->m_loggedIn; return d->m_loggedIn;
} }
bool UserInfo::updateCurrent()
{
Q_D(UserInfo);
bool previous = d->m_loggedIn;
d->m_loggedIn = sd_uid_is_on_seat(d->m_uid, 1, "seat0") > 0;
if (d->m_loggedIn != previous) {
if (d->m_loggedIn)
UserInfoPrivate::s_current = d_ptr;
else if (UserInfoPrivate::s_current == d_ptr)
UserInfoPrivate::s_current.clear();
emit d_ptr->currentChanged();
return true;
}
return false;
}
void UserInfo::reset() void UserInfo::reset()
{ {
Q_D(UserInfo); Q_D(UserInfo);
d->set((isValid()) ? getpwuid(d->m_uid) : nullptr); d->set((isValid()) ? getpwuid(d->m_uid) : nullptr);
updateCurrent();
} }
UserInfo &UserInfo::operator=(const UserInfo &other) UserInfo &UserInfo::operator=(const UserInfo &other)
...@@ -286,4 +301,5 @@ void UserInfo::connectSignals() ...@@ -286,4 +301,5 @@ void UserInfo::connectSignals()
connect(d_ptr.data(), &UserInfoPrivate::usernameChanged, this, &UserInfo::usernameChanged); connect(d_ptr.data(), &UserInfoPrivate::usernameChanged, this, &UserInfo::usernameChanged);
connect(d_ptr.data(), &UserInfoPrivate::nameChanged, this, &UserInfo::nameChanged); connect(d_ptr.data(), &UserInfoPrivate::nameChanged, this, &UserInfo::nameChanged);
connect(d_ptr.data(), &UserInfoPrivate::uidChanged, this, &UserInfo::uidChanged); connect(d_ptr.data(), &UserInfoPrivate::uidChanged, this, &UserInfo::uidChanged);
connect(d_ptr.data(), &UserInfoPrivate::currentChanged, this, &UserInfo::currentChanged);
} }
...@@ -50,7 +50,7 @@ class SYSTEMSETTINGS_EXPORT UserInfo: public QObject ...@@ -50,7 +50,7 @@ class SYSTEMSETTINGS_EXPORT UserInfo: public QObject
Q_PROPERTY(QString name READ name NOTIFY nameChanged) Q_PROPERTY(QString name READ name NOTIFY nameChanged)
Q_PROPERTY(UserType type READ type CONSTANT) Q_PROPERTY(UserType type READ type CONSTANT)
Q_PROPERTY(int uid READ uid NOTIFY uidChanged) Q_PROPERTY(int uid READ uid NOTIFY uidChanged)
Q_PROPERTY(bool current READ current CONSTANT) Q_PROPERTY(bool current READ current NOTIFY currentChanged)
friend class UserModel; friend class UserModel;
...@@ -85,6 +85,7 @@ signals: ...@@ -85,6 +85,7 @@ signals:
void usernameChanged(); void usernameChanged();
void nameChanged(); void nameChanged();
void uidChanged(); void uidChanged();
void currentChanged();
private: private:
explicit UserInfo(int uid); explicit UserInfo(int uid);
...@@ -92,6 +93,7 @@ private: ...@@ -92,6 +93,7 @@ private:
void setUsername(QString username); void setUsername(QString username);
void setName(QString name); void setName(QString name);
bool updateCurrent();
void connectSignals(); void connectSignals();
......
...@@ -59,6 +59,7 @@ signals: ...@@ -59,6 +59,7 @@ signals:
void usernameChanged(); void usernameChanged();
void nameChanged(); void nameChanged();
void uidChanged(); void uidChanged();
void currentChanged();
}; };
#endif /* USERINFOPRIVATE_H */ #endif /* USERINFOPRIVATE_H */
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