mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 18:32:49 +00:00
kutils: poll for state changes even if org.freedesktop.login1 interface is used
the state is tracked anyway and now the code path for both is the same Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
7372b01cdd
commit
0cdb519ddc
4 changed files with 26 additions and 24 deletions
|
@ -29,7 +29,7 @@ KPowerManagerImpl::KPowerManagerImpl(QObject *parent)
|
|||
m_serviceregistered(false),
|
||||
m_login1("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", QDBusConnection::systemBus()),
|
||||
m_consolekit("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager", QDBusConnection::systemBus()),
|
||||
m_consolekittimerid(0),
|
||||
m_timerid(0),
|
||||
m_canhibernate(false),
|
||||
m_canhybridsuspend(false),
|
||||
m_cansuspend(false),
|
||||
|
@ -59,22 +59,17 @@ KPowerManagerImpl::KPowerManagerImpl(QObject *parent)
|
|||
m_cansuspend = CanSuspend();
|
||||
m_powersavestatus = GetPowerSaveStatus();
|
||||
if (m_login1.isValid()) {
|
||||
connection = QDBusConnection::systemBus();
|
||||
connection.connect(
|
||||
"org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.DBus.Properties", "PropertiesChanged",
|
||||
this, SLOT(slotPropertiesChanged(QString,QVariantMap,QStringList))
|
||||
);
|
||||
connect(&m_login1, SIGNAL(PrepareForSleep(bool)), this, SLOT(slotPrepareForSleep(bool)));
|
||||
} else if (m_consolekit.isValid()) {
|
||||
connect(&m_consolekit, SIGNAL(PrepareForSleep(bool)), this, SLOT(slotPrepareForSleep(bool)));
|
||||
m_consolekittimerid = startTimer(2000);
|
||||
}
|
||||
m_timerid = startTimer(2000);
|
||||
}
|
||||
|
||||
KPowerManagerImpl::~KPowerManagerImpl()
|
||||
{
|
||||
if (m_consolekittimerid > 0) {
|
||||
killTimer(m_consolekittimerid);
|
||||
if (m_timerid > 0) {
|
||||
killTimer(m_timerid);
|
||||
}
|
||||
|
||||
if (m_serviceregistered) {
|
||||
|
@ -186,8 +181,11 @@ void KPowerManagerImpl::slotPrepareForSleep(bool start)
|
|||
|
||||
void KPowerManagerImpl::timerEvent(QTimerEvent *event)
|
||||
{
|
||||
if (event->timerId() == m_consolekittimerid) {
|
||||
if (event->timerId() == m_timerid) {
|
||||
emitSignals();
|
||||
event->accept();
|
||||
} else {
|
||||
event->ignore();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -202,6 +200,11 @@ void KPowerManagerImpl::emitSignals()
|
|||
m_cansuspend = CanSuspend();
|
||||
m_powersavestatus = GetPowerSaveStatus();
|
||||
|
||||
kDebug() << "old can hibernate" << oldcanhibernate << "new can hibernate" << m_canhibernate;
|
||||
kDebug() << "old can hybrid suspend" << oldcanhybridsuspend << "new can hybrid suspend" << m_canhybridsuspend;
|
||||
kDebug() << "old can can suspend" << oldcansuspend << "new can can suspend" << m_cansuspend;
|
||||
kDebug() << "old can power save status" << oldpowersavestatus << "new can power save status" << m_powersavestatus;
|
||||
|
||||
if (oldcanhibernate != m_canhibernate) {
|
||||
emit CanHibernateChanged(m_canhibernate);
|
||||
}
|
||||
|
|
|
@ -64,7 +64,7 @@ private:
|
|||
bool m_serviceregistered;
|
||||
QDBusInterface m_login1;
|
||||
QDBusInterface m_consolekit;
|
||||
int m_consolekittimerid;
|
||||
int m_timerid;
|
||||
bool m_canhibernate;
|
||||
bool m_canhybridsuspend;
|
||||
bool m_cansuspend;
|
||||
|
|
|
@ -61,7 +61,7 @@ KPowerManagerInhibitImpl::KPowerManagerInhibitImpl(QObject *parent)
|
|||
m_serviceregistered(false),
|
||||
m_login1("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", QDBusConnection::systemBus()),
|
||||
m_consolekit("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager", QDBusConnection::systemBus()),
|
||||
m_consolekittimerid(0),
|
||||
m_timerid(0),
|
||||
m_hasinhibit(false)
|
||||
{
|
||||
(void)new InhibitAdaptor(this);
|
||||
|
@ -84,23 +84,17 @@ KPowerManagerInhibitImpl::KPowerManagerInhibitImpl(QObject *parent)
|
|||
m_serviceregistered = true;
|
||||
|
||||
m_hasinhibit = HasInhibit();
|
||||
if (m_login1.isValid()) {
|
||||
connection = QDBusConnection::systemBus();
|
||||
connection.connect(
|
||||
"org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.DBus.Properties", "PropertiesChanged",
|
||||
this, SLOT(slotPropertiesChanged(QString,QVariantMap,QStringList))
|
||||
);
|
||||
} else if (m_consolekit.isValid()) {
|
||||
if (m_consolekit.isValid()) {
|
||||
qDBusRegisterMetaType<KInhibitor>();
|
||||
qDBusRegisterMetaType<QList<KInhibitor>>();
|
||||
m_consolekittimerid = startTimer(2000);
|
||||
}
|
||||
m_timerid = startTimer(2000);
|
||||
}
|
||||
|
||||
KPowerManagerInhibitImpl::~KPowerManagerInhibitImpl()
|
||||
{
|
||||
if (m_consolekittimerid > 0) {
|
||||
killTimer(m_consolekittimerid);
|
||||
if (m_timerid > 0) {
|
||||
killTimer(m_timerid);
|
||||
}
|
||||
|
||||
if (m_serviceregistered) {
|
||||
|
@ -205,8 +199,11 @@ void KPowerManagerInhibitImpl::slotPropertiesChanged(QString interface, QVariant
|
|||
|
||||
void KPowerManagerInhibitImpl::timerEvent(QTimerEvent *event)
|
||||
{
|
||||
if (event->timerId() == m_consolekittimerid) {
|
||||
if (event->timerId() == m_timerid) {
|
||||
emitSignals();
|
||||
event->accept();
|
||||
} else {
|
||||
event->ignore();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -215,6 +212,8 @@ void KPowerManagerInhibitImpl::emitSignals()
|
|||
const bool oldhasinhibit = m_hasinhibit;
|
||||
m_hasinhibit = HasInhibit();
|
||||
|
||||
kDebug() << "old has inhibit" << oldhasinhibit << "new has inhibit" << m_hasinhibit;
|
||||
|
||||
if (oldhasinhibit != m_hasinhibit) {
|
||||
emit HasInhibitChanged(m_hasinhibit);
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ private:
|
|||
bool m_serviceregistered;
|
||||
QDBusInterface m_login1;
|
||||
QDBusInterface m_consolekit;
|
||||
int m_consolekittimerid;
|
||||
int m_timerid;
|
||||
QMap<uint, int> m_cookies;
|
||||
bool m_hasinhibit;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue