quicksettings/screenrotation: Make available dbus call async

This commit is contained in:
Devin Lin 2023-02-09 23:00:45 -08:00
parent f8aeffa56d
commit f22b847009
2 changed files with 22 additions and 8 deletions

View file

@ -43,11 +43,22 @@ void ScreenRotationUtil::setScreenRotation(bool value)
bool ScreenRotationUtil::isAvailable() bool ScreenRotationUtil::isAvailable()
{ {
QDBusPendingReply<bool> reply = m_kscreenInterface->isAutoRotateAvailable(); QDBusPendingReply<bool> reply = m_kscreenInterface->isAutoRotateAvailable();
reply.waitForFinished(); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
if (reply.isError()) {
qWarning() << "Getting available failed:" << reply.error().name() << reply.error().message(); connect(watcher, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher *watcher) {
return false; QDBusPendingReply<bool> reply = *watcher;
} else { if (reply.isError()) {
return reply.value(); qWarning() << "Getting available failed:" << reply.error().name() << reply.error().message();
} } else {
// make sure we don't go into an infinite loop
if (m_available != reply.value()) {
Q_EMIT availableChanged(m_available);
}
m_available = reply.value();
}
watcher->deleteLater();
});
return m_available;
} }

View file

@ -14,7 +14,7 @@ class ScreenRotationUtil : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(bool screenRotationEnabled READ screenRotation WRITE setScreenRotation NOTIFY screenRotationChanged); Q_PROPERTY(bool screenRotationEnabled READ screenRotation WRITE setScreenRotation NOTIFY screenRotationChanged);
Q_PROPERTY(bool available READ isAvailable); Q_PROPERTY(bool available READ isAvailable NOTIFY availableChanged);
public: public:
ScreenRotationUtil(QObject *parent = nullptr); ScreenRotationUtil(QObject *parent = nullptr);
@ -26,7 +26,10 @@ public:
Q_SIGNALS: Q_SIGNALS:
void screenRotationChanged(bool value); void screenRotationChanged(bool value);
void availableChanged(bool value);
private: private:
org::kde::KScreen *m_kscreenInterface; org::kde::KScreen *m_kscreenInterface;
bool m_available;
}; };