File: lidwatcher.cpp

package info (click to toggle)
cutefish-core 0.8-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 2,076 kB
  • sloc: cpp: 11,327; xml: 443; sh: 29; makefile: 6
file content (43 lines) | stat: -rw-r--r-- 1,486 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "lidwatcher.h"
#include <QDebug>

LidWatcher::LidWatcher(QObject *parent)
    : QObject(parent)
{
    m_uPowerIface = new QDBusInterface("org.freedesktop.UPower",
                                       "/org/freedesktop/UPower",
                                       "org.freedesktop.UPower", QDBusConnection::systemBus(), this);

    m_uPowerPropertiesIface = new QDBusInterface("org.freedesktop.UPower",
                                                 "/org/freedesktop/UPower",
                                                 "org.freedesktop.DBus.Properties",
                                                 QDBusConnection::systemBus(), this);

    QDBusConnection::systemBus().connect("org.freedesktop.UPower",
                                         "/org/freedesktop/UPower",
                                         "org.freedesktop.DBus.Properties",
                                         "PropertiesChanged",
                                         this, SLOT(onPropertiesChanged()));

    m_lidClosed = m_uPowerPropertiesIface->property("LidIsClosed").toBool();
}

bool LidWatcher::existLid() const
{
    return m_uPowerIface->property("LidIsPresent").toBool();
}

bool LidWatcher::lidClosed() const
{
    return m_lidClosed;
}

void LidWatcher::onPropertiesChanged()
{
    bool isLidClosed = m_uPowerIface->property("LidIsClosed").toBool();

    if (isLidClosed != m_lidClosed) {
        m_lidClosed = isLidClosed;
        emit lidClosedChanged();
    }
}