diff --git a/quicksettings/screenrotation/screenrotationutil.cpp b/quicksettings/screenrotation/screenrotationutil.cpp index 8533bb3e..ef2d5eab 100644 --- a/quicksettings/screenrotation/screenrotationutil.cpp +++ b/quicksettings/screenrotation/screenrotationutil.cpp @@ -43,11 +43,22 @@ void ScreenRotationUtil::setScreenRotation(bool value) bool ScreenRotationUtil::isAvailable() { QDBusPendingReply reply = m_kscreenInterface->isAutoRotateAvailable(); - reply.waitForFinished(); - if (reply.isError()) { - qWarning() << "Getting available failed:" << reply.error().name() << reply.error().message(); - return false; - } else { - return reply.value(); - } + QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this); + + connect(watcher, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher *watcher) { + QDBusPendingReply reply = *watcher; + if (reply.isError()) { + 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; } diff --git a/quicksettings/screenrotation/screenrotationutil.h b/quicksettings/screenrotation/screenrotationutil.h index 89f8c87f..263cbb78 100644 --- a/quicksettings/screenrotation/screenrotationutil.h +++ b/quicksettings/screenrotation/screenrotationutil.h @@ -14,7 +14,7 @@ class ScreenRotationUtil : public QObject { Q_OBJECT 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: ScreenRotationUtil(QObject *parent = nullptr); @@ -26,7 +26,10 @@ public: Q_SIGNALS: void screenRotationChanged(bool value); + void availableChanged(bool value); private: org::kde::KScreen *m_kscreenInterface; + + bool m_available; };