mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-26 14:23:09 +00:00
quicksettings/screenrotation: Make available dbus call async
This commit is contained in:
parent
f8aeffa56d
commit
f22b847009
2 changed files with 22 additions and 8 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue