Fix orientation sensor DBus

Summary:
Firstly, it was completely broken, no-one called registerObject.

Secondly deleting the adaptor doesn't really make sense, you'd still
leave the object valid, only have it broken. Docs of
QDBusAbstractAdaptor do say not to ever delete it manually.

Thirdly we don't need Q_CLASSINFO setting the DBus interface on the
exported item when we use an adaptor.

Test Plan:
Manually added some setEnabled/disabled
Could now see the path

Reviewers: #kwin

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D23610
This commit is contained in:
David Edmundson 2019-08-31 18:36:26 +01:00
parent 2f010926d5
commit 76645f3c1b
2 changed files with 4 additions and 6 deletions

View file

@ -36,6 +36,8 @@ OrientationSensor::OrientationSensor(QObject *parent)
{
connect(m_sensor, &QOrientationSensor::readingChanged, this, &OrientationSensor::updateState);
connect(m_sensor, &QOrientationSensor::activeChanged, this, &OrientationSensor::refresh);
new OrientationSensorAdaptor(this);
}
void OrientationSensor::updateState()
@ -133,12 +135,11 @@ void OrientationSensor::setEnabled(bool enabled)
if (m_enabled) {
loadConfig();
refresh();
m_adaptor = new OrientationSensorAdaptor(this);
QDBusConnection::sessionBus().registerObject(QStringLiteral("/Orientation"), this);
} else {
QDBusConnection::sessionBus().unregisterObject(QStringLiteral("/Orientation"));
delete m_sni;
m_sni = nullptr;
delete m_adaptor;
m_adaptor = nullptr;
}
startStopSensor();
}

View file

@ -35,7 +35,6 @@ namespace KWin
class KWIN_EXPORT OrientationSensor : public QObject
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.kde.kwin.OrientationSensor")
Q_PROPERTY(bool userEnabled READ isUserEnabled WRITE setUserEnabled NOTIFY userEnabledChanged)
public:
explicit OrientationSensor(QObject *parent = nullptr);
@ -88,8 +87,6 @@ private:
Orientation m_orientation = Orientation::Undefined;
KStatusNotifierItem *m_sni = nullptr;
KSharedConfig::Ptr m_config;
OrientationSensorAdaptor *m_adaptor = nullptr;
};
}