Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'jb49640' into 'master'
[lipstick] Listen to user-managerd for user switching. Contributes to JB#49640

See merge request mer-core/lipstick!140
  • Loading branch information
Tomin1 committed Apr 21, 2020
2 parents 1e4ffb0 + ea4226e commit b76c32d
Show file tree
Hide file tree
Showing 43 changed files with 748 additions and 694 deletions.
2 changes: 1 addition & 1 deletion plugin/plugin.pro
Expand Up @@ -16,7 +16,7 @@ INCLUDEPATH += ../src \
../src/utilities \
../src/xtools \
../src/compositor \
../src/qmsystem2 \
../src/devicestate \
../src/touchscreen

LIBS += -L../src -llipstick-qt5
Expand Down
2 changes: 2 additions & 0 deletions rpm/lipstick-qt5.spec
Expand Up @@ -14,6 +14,7 @@ Source0: %{name}-%{version}.tar.bz2
Source1: %{name}.privileges
Requires: mce >= 1.87.0
Requires: pulseaudio-modules-nemo-mainvolume >= 6.0.19
Requires: user-managerd >= 0.3.0
Requires(post): /sbin/ldconfig
Requires(postun): /sbin/ldconfig
BuildRequires: pkgconfig(Qt5Core)
Expand All @@ -40,6 +41,7 @@ BuildRequires: pkgconfig(wayland-server)
BuildRequires: pkgconfig(usb-moded-qt5) >= 1.8
BuildRequires: pkgconfig(systemsettings) >= 0.5.28
BuildRequires: pkgconfig(nemodevicelock)
BuildRequires: pkgconfig(sailfishusermanager)
BuildRequires: qt5-qttools-linguist
BuildRequires: qt5-qtgui-devel >= 5.2.1+git24
BuildRequires: qt5-qtwayland-wayland_egl-devel >= 5.4.0+git26
Expand Down
126 changes: 86 additions & 40 deletions src/qmsystem2/qmsystemstate.cpp → src/devicestate/devicestate.cpp
@@ -1,9 +1,11 @@
/*!
* @file qmsystemstate.cpp
* @brief QmSystemState
* @file devicestate.cpp
* @brief DeviceState
<p>
Copyright (c) 2009-2011 Nokia Corporation
Copyright (c) 2015 - 2020 Jolla Ltd.
Copyright (c) 2020 Open Mobile Platform LLC.
@author Antonio Aloisio <antonio.aloisio@nokia.com>
@author Ilya Dogolazky <ilya.dogolazky@nokia.com>
Expand All @@ -27,133 +29,177 @@
License along with SystemSW QtAPI. If not, see <http://www.gnu.org/licenses/>.
</p>
*/
#include "qmsystemstate.h"
#include "qmsystemstate_p.h"
#include "devicestate.h"
#include "devicestate_p.h"

#include <dsme/thermalmanager_dbus_if.h>
#include <sailfishusermanagerinterface.h>

#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <QDBusMessage>
#include <QDBusReply>
#include <QDBusServiceWatcher>
#include <QMetaMethod>


namespace MeeGo {
namespace DeviceState {

QmSystemState::QmSystemState(QObject *parent)
: QObject(parent) {
MEEGO_INITIALIZE(QmSystemState);
DeviceState::DeviceState(QObject *parent)
: QObject(parent)
, d_ptr(new DeviceStatePrivate) {
Q_D(DeviceState);

connect(priv, SIGNAL(systemStateChanged(MeeGo::QmSystemState::StateIndication)),
this, SIGNAL(systemStateChanged(MeeGo::QmSystemState::StateIndication)));
connect(d, SIGNAL(systemStateChanged(DeviceState::DeviceState::StateIndication)),
this, SIGNAL(systemStateChanged(DeviceState::DeviceState::StateIndication)));
connect(d, SIGNAL(nextUserChanged(uint)),
this, SIGNAL(nextUserChanged(uint)));
}

QmSystemState::~QmSystemState() {
MEEGO_PRIVATE(QmSystemState)
DeviceState::~DeviceState() {
Q_D(DeviceState);

disconnect(priv, SIGNAL(systemStateChanged(MeeGo::QmSystemState::StateIndication)),
this, SIGNAL(systemStateChanged(MeeGo::QmSystemState::StateIndication)));
disconnect(d, SIGNAL(systemStateChanged(DeviceState::DeviceState::StateIndication)),
this, SIGNAL(systemStateChanged(DeviceState::DeviceState::StateIndication)));
disconnect(d, SIGNAL(nextUserChanged(uint)),
this, SIGNAL(nextUserChanged(uint)));

MEEGO_UNINITIALIZE(QmSystemState);
delete d_ptr;
}

void QmSystemState::connectNotify(const QMetaMethod &signal) {
MEEGO_PRIVATE(QmSystemState)
void DeviceState::connectNotify(const QMetaMethod &signal) {
Q_D(DeviceState);

/* QObject::connect() needs to be thread-safe */
QMutexLocker locker(&priv->connectMutex);
QMutexLocker locker(&d->connectMutex);

if (signal == QMetaMethod::fromSignal(&QmSystemState::systemStateChanged)) {
if (0 == priv->connectCount[SIGNAL_SYSTEM_STATE]) {
if (signal == QMetaMethod::fromSignal(&DeviceState::systemStateChanged)) {
if (0 == d->connectCount[SIGNAL_SYSTEM_STATE]) {
QDBusConnection::systemBus().connect(dsme_service,
dsme_sig_path,
dsme_sig_interface,
dsme_shutdown_ind,
priv,
d,
SLOT(emitShutdown()));
QDBusConnection::systemBus().connect(dsme_service,
dsme_sig_path,
dsme_sig_interface,
dsme_save_unsaved_data_ind,
priv,
d,
SLOT(emitSaveData()));
QDBusConnection::systemBus().connect(dsme_service,
dsme_sig_path,
dsme_sig_interface,
dsme_battery_empty_ind,
priv,
d,
SLOT(emitBatteryShutdown()));
QDBusConnection::systemBus().connect(dsme_service,
dsme_sig_path,
dsme_sig_interface,
dsme_state_req_denied_ind,
priv,
d,
SLOT(emitShutdownDenied(QString, QString)));
QDBusConnection::systemBus().connect(dsme_service,
dsme_sig_path,
dsme_sig_interface,
dsme_state_change_ind,
priv,
d,
SLOT(emitStateChangeInd(QString)));
QDBusConnection::systemBus().connect(thermalmanager_service,
thermalmanager_path,
thermalmanager_interface,
thermalmanager_state_change_ind,
priv,
d,
SLOT(emitThermalShutdown(QString)));
d->userManagerWatcher = new QDBusServiceWatcher(SAILFISH_USERMANAGER_DBUS_INTERFACE,
QDBusConnection::systemBus(),
QDBusServiceWatcher::WatchForRegistration
| QDBusServiceWatcher::WatchForUnregistration,
this);
connect(d->userManagerWatcher, &QDBusServiceWatcher::serviceRegistered,
this, &DeviceState::connectUserManager);
connect(d->userManagerWatcher, &QDBusServiceWatcher::serviceUnregistered,
this, &DeviceState::disconnectUserManager);
if (QDBusConnection::systemBus().interface()->isServiceRegistered(SAILFISH_USERMANAGER_DBUS_INTERFACE))
connectUserManager();
}
priv->connectCount[SIGNAL_SYSTEM_STATE]++;
d->connectCount[SIGNAL_SYSTEM_STATE]++;
}
}

void QmSystemState::disconnectNotify(const QMetaMethod &signal) {
MEEGO_PRIVATE(QmSystemState)
void DeviceState::disconnectNotify(const QMetaMethod &signal) {
Q_D(DeviceState);

/* QObject::disconnect() needs to be thread-safe */
QMutexLocker locker(&priv->connectMutex);
QMutexLocker locker(&d->connectMutex);

if (signal == QMetaMethod::fromSignal(&QmSystemState::systemStateChanged)) {
priv->connectCount[SIGNAL_SYSTEM_STATE]--;
if (signal == QMetaMethod::fromSignal(&DeviceState::systemStateChanged)) {
d->connectCount[SIGNAL_SYSTEM_STATE]--;

if (0 == priv->connectCount[SIGNAL_SYSTEM_STATE]) {
if (0 == d->connectCount[SIGNAL_SYSTEM_STATE]) {
QDBusConnection::systemBus().disconnect(dsme_service,
dsme_sig_path,
dsme_sig_interface,
dsme_shutdown_ind,
priv,
d,
SLOT(emitShutdown()));
QDBusConnection::systemBus().disconnect(dsme_service,
dsme_sig_path,
dsme_sig_interface,
dsme_save_unsaved_data_ind,
priv,
d,
SLOT(emitSaveData()));
QDBusConnection::systemBus().disconnect(dsme_service,
dsme_sig_path,
dsme_sig_interface,
dsme_battery_empty_ind,
priv,
d,
SLOT(emitBatteryShutdown()));
QDBusConnection::systemBus().disconnect(dsme_service,
dsme_sig_path,
dsme_sig_interface,
dsme_state_req_denied_ind,
priv,
d,
SLOT(emitShutdownDenied(QString, QString)));
QDBusConnection::systemBus().disconnect(dsme_service,
dsme_sig_path,
dsme_sig_interface,
dsme_state_change_ind,
priv,
d,
SLOT(emitStateChangeInd(QString)));
QDBusConnection::systemBus().disconnect(thermalmanager_service,
thermalmanager_path,
thermalmanager_interface,
thermalmanager_state_change_ind,
priv,
d,
SLOT(emitThermalShutdown(QString)));
disconnectUserManager();
d->userManagerWatcher->deleteLater();
d->userManagerWatcher = nullptr;
}
}
}

} // MeeGo namespace
void DeviceState::connectUserManager()
{
Q_D(DeviceState);
QDBusConnection::systemBus().connect(SAILFISH_USERMANAGER_DBUS_INTERFACE,
SAILFISH_USERMANAGER_DBUS_OBJECT_PATH,
SAILFISH_USERMANAGER_DBUS_INTERFACE,
"aboutToChangeCurrentUser",
d,
SLOT(emitUserSwitching(uint)));
}

void DeviceState::disconnectUserManager()
{
Q_D(DeviceState);
QDBusConnection::systemBus().disconnect(SAILFISH_USERMANAGER_DBUS_INTERFACE,
SAILFISH_USERMANAGER_DBUS_OBJECT_PATH,
SAILFISH_USERMANAGER_DBUS_INTERFACE,
"aboutToChangeCurrentUser",
d,
SLOT(emitUserChanging(uint)));
}

} // DeviceState namespace
58 changes: 34 additions & 24 deletions src/qmsystem2/qmsystemstate.h → src/devicestate/devicestate.h
@@ -1,9 +1,11 @@
/*!
* @file qmsystemstate.h
* @brief Contains QmSystemState which provides information and actions on device state.
* @file devicestate.h
* @brief Contains DeviceState which provides information and actions on device state.
<p>
@copyright (C) 2009-2011 Nokia Corporation
Copyright (c) 2015 - 2020 Jolla Ltd.
Copyright (c) 2020 Open Mobile Platform LLC.
@license LGPL Lesser General Public License
@author Antonio Aloisio <antonio.aloisio@nokia.com>
Expand Down Expand Up @@ -32,25 +34,24 @@
License along with SystemSW QtAPI. If not, see <http://www.gnu.org/licenses/>.
</p>
*/
#ifndef QMSYSTEMSTATE_H
#define QMSYSTEMSTATE_H
#ifndef DEVICESTATE_H
#define DEVICESTATE_H

#include "system_global.h"
#include <QtCore/qobject.h>

QT_BEGIN_HEADER

namespace MeeGo {
namespace DeviceState {

class QmSystemStatePrivate;
class DeviceStatePrivate;

/*!
* @scope Nokia Meego
*
* @class QmSystemState
* @brief QmSystemState provides information and actions on device state.
* @class DeviceState
* @brief DeviceState provides information and actions on device state.
*/
class QmSystemState : public QObject
class DeviceState : public QObject
{
Q_OBJECT
Q_ENUMS(StateIndication)
Expand All @@ -59,44 +60,53 @@ class QmSystemState : public QObject
//! State indication
enum StateIndication
{
Shutdown = 0, //!< Normal shutdown
ThermalStateFatal, //!< Shutdown due to thermal state
BatteryStateEmpty, //!< Shutdown due battery empty within few seconds
Shutdown = 0, //!< Normal shutdown
ThermalStateFatal, //!< Shutdown due to thermal state
BatteryStateEmpty, //!< Shutdown due battery empty within few seconds
SaveData, //!< Save data
RebootDeniedUSB, //!< Reboot denied because USB is connected in mass storage mode
ShutdownDeniedUSB, //!< Shutdown denied because USB is connected in mass storage mode
Reboot //!< Reboot
Reboot, //!< Reboot
UserSwitching //!< User switching
};

public:
/*!
* @brief Constructor
* @param parent The possible parent object
*/
QmSystemState(QObject *parent = 0);
~QmSystemState();
DeviceState(QObject *parent = 0);
~DeviceState();

Q_SIGNALS:
/*!
* @brief Sent when device state indication has been received.
* @param what Received state indication type
*/
void systemStateChanged(MeeGo::QmSystemState::StateIndication what);
void systemStateChanged(DeviceState::DeviceState::StateIndication what);

/*!
* @brief Sent when user switching happens.
* @param uid User id of the user to switch to
*/
void nextUserChanged(uint uid);

protected:
void connectNotify(const QMetaMethod &signal);
void disconnectNotify(const QMetaMethod &signal);

private slots:
void connectUserManager();
void disconnectUserManager();

private:
Q_DISABLE_COPY(QmSystemState)
MEEGO_DECLARE_PRIVATE(QmSystemState)
Q_DISABLE_COPY(DeviceState)
Q_DECLARE_PRIVATE(DeviceState)
DeviceStatePrivate *d_ptr;
};

} // MeeGo namespace
} // DeviceState namespace

QT_END_HEADER

#endif // QMSYSTEMSTATE_H

// End of file

#endif // DEVICESTATE_H

0 comments on commit b76c32d

Please sign in to comment.