Skip to content

Commit

Permalink
Merge branch 'jb49640' into 'master'
Browse files Browse the repository at this point in the history
[lipstick] Set user to uid of current or next user. Contributes to JB#49640

See merge request mer-core/lipstick!141
  • Loading branch information
Tomin1 committed Apr 23, 2020
2 parents b76c32d + 6213585 commit 59c5e7b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
23 changes: 8 additions & 15 deletions src/shutdownscreen.cpp
Expand Up @@ -26,17 +26,17 @@
#include "homeapplication.h"
#include "shutdownscreen.h"
#include "lipstickqmlpath.h"
#include <pwd.h>
#include <sys/types.h>
#include <unistd.h>

ShutdownScreen::ShutdownScreen(QObject *parent) :
QObject(parent),
QDBusContext(),
m_window(0),
m_systemState(new DeviceState::DeviceState(this))
m_systemState(new DeviceState::DeviceState(this)),
m_user(getuid())
{
connect(m_systemState, SIGNAL(systemStateChanged(DeviceState::DeviceState::StateIndication)), this, SLOT(applySystemState(DeviceState::DeviceState::StateIndication)));
connect(m_systemState, SIGNAL(nextUserChanged(uint)), this, SLOT(setNextUser(uint)));
connect(m_systemState, &DeviceState::DeviceState::systemStateChanged, this, &ShutdownScreen::applySystemState);
connect(m_systemState, &DeviceState::DeviceState::nextUserChanged, this, &ShutdownScreen::setUser);
}

void ShutdownScreen::setWindowVisible(bool visible)
Expand All @@ -50,7 +50,7 @@ void ShutdownScreen::setWindowVisible(bool visible)
m_window->setContextProperty("initialSize", QGuiApplication::primaryScreen()->size());
m_window->setContextProperty("shutdownScreen", this);
m_window->setContextProperty("shutdownMode", m_shutdownMode);
m_window->setContextProperty("nextUser", m_nextUser);
m_window->setContextProperty("user", m_user);
m_window->setSource(QmlPath::to("system/ShutdownScreen.qml"));
m_window->installEventFilter(new CloseEventEater(this));
}
Expand Down Expand Up @@ -112,16 +112,9 @@ void ShutdownScreen::applySystemState(DeviceState::DeviceState::StateIndication
}
}

void ShutdownScreen::setNextUser(uint uid)
void ShutdownScreen::setUser(uint uid)
{
struct passwd *pwd = getpwuid((uid_t)uid);
if (pwd) {
QString name = QString::fromUtf8(pwd->pw_gecos);
int i = name.indexOf(QStringLiteral(","));
if (i != -1)
name.truncate(i);
m_nextUser = name;
}
m_user = uid;
}

void ShutdownScreen::createAndPublishNotification(const QString &category, const QString &body)
Expand Down
9 changes: 5 additions & 4 deletions src/shutdownscreen.h
Expand Up @@ -66,11 +66,12 @@ private slots:
void applySystemState(DeviceState::DeviceState::StateIndication what);

/*!
* Sets nextUser to name of the user that is about to be switched to.
* Sets user to uid of the user whose information may be shown on
* ShutdownScreen.
*
* \param uid user id of the user
*/
void setNextUser(uint uid);
void setUser(uint uid);

private:
/*!
Expand All @@ -90,8 +91,8 @@ private slots:
//! The shutdown mode to be communicated to the UI
QString m_shutdownMode;

//! Next user to login, empty if the user session is not about to end
QString m_nextUser;
//! Uid of current user or uid of next user to login if that is happening
uint m_user;

#ifdef UNIT_TEST
friend class Ut_ShutdownScreen;
Expand Down

0 comments on commit 59c5e7b

Please sign in to comment.