mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-29 15:03: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()
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue