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()
{
QDBusPendingReply<bool> 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<bool> 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;
}

View file

@ -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;
};