presentation/SystemMotionPreference.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "SystemMotionPreference.h" | ||
| 2 | |||
| 3 | #include <QDBusConnection> | ||
| 4 | #include <QDBusInterface> | ||
| 5 | #include <QDBusReply> | ||
| 6 | #include <QVariant> | ||
| 7 | |||
| 8 | 896 | SystemMotionPreference::SystemMotionPreference(QObject *parent) | |
| 9 | 896 | : QObject(parent) { | |
| 10 | 896 | m_probe = queryPortal; | |
| 11 |
3/4✓ Branch 6 → 7 taken 896 times.
✓ Branch 7 → 8 taken 896 times.
✓ Branch 9 → 10 taken 896 times.
✗ Branch 9 → 35 not taken.
|
896 | if (QDBusConnection::sessionBus().isConnected()) |
| 12 |
3/3✓ Branch 10 → 11 taken 896 times.
✓ Branch 11 → 12 taken 896 times.
✓ Branch 24 → 25 taken 896 times.
|
2688 | QDBusConnection::sessionBus().connect( |
| 13 | 2688 | QStringLiteral("org.freedesktop.portal.Desktop"), QStringLiteral("/org/freedesktop/portal/desktop"), | |
| 14 | 2688 | QStringLiteral("org.freedesktop.portal.Settings"), QStringLiteral("SettingChanged"), this, | |
| 15 | SLOT(settingChanged(QString, QString, QDBusVariant))); | ||
| 16 | 896 | } | |
| 17 | |||
| 18 | 2 | void SystemMotionPreference::settingChanged(const QString &nameSpace, const QString &key, const QDBusVariant &) { | |
| 19 |
5/6✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 9 taken 1 time.
✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 9 not taken.
✓ Branch 10 → 11 taken 1 time.
✓ Branch 10 → 12 taken 1 time.
|
2 | if (nameSpace == QLatin1String("org.freedesktop.appearance") && key == QLatin1String("animations")) |
| 20 | 1 | refresh(); | |
| 21 | 2 | } | |
| 22 | |||
| 23 | 773 | std::optional<bool> SystemMotionPreference::queryPortal() { | |
| 24 | // Session bus only; a missing bus (headless/test) is "unknown", never an | ||
| 25 | // error the caller must handle. | ||
| 26 |
3/4✓ Branch 2 → 3 taken 773 times.
✓ Branch 3 → 4 taken 773 times.
✗ Branch 5 → 6 not taken.
✓ Branch 5 → 9 taken 773 times.
|
773 | if (!QDBusConnection::sessionBus().isConnected()) return std::nullopt; |
| 27 | 1546 | QDBusInterface portal(QStringLiteral("org.freedesktop.portal.Desktop"), | |
| 28 | 1546 | QStringLiteral("/org/freedesktop/portal/desktop"), | |
| 29 |
2/2✓ Branch 9 → 10 taken 773 times.
✓ Branch 19 → 20 taken 773 times.
|
3092 | QStringLiteral("org.freedesktop.portal.Settings")); |
| 30 |
2/3✓ Branch 27 → 28 taken 773 times.
✓ Branch 28 → 29 taken 773 times.
✗ Branch 28 → 32 not taken.
|
773 | if (!portal.isValid()) return std::nullopt; |
| 31 | ✗ | const QDBusReply<QDBusVariant> reply = portal.call( | |
| 32 | ✗ | QStringLiteral("ReadOne"), QStringLiteral("org.freedesktop.appearance"), | |
| 33 | ✗ | QStringLiteral("animations")); | |
| 34 | ✗ | if (!reply.isValid()) return std::nullopt; | |
| 35 | // The portal wraps values in a variant of variant; unwrap both shapes. | ||
| 36 | ✗ | QVariant value = reply.value().variant(); | |
| 37 | ✗ | if (value.canConvert<QVariant>()) | |
| 38 | ✗ | value = value.value<QVariant>(); | |
| 39 | ✗ | if (value.userType() == QMetaType::Bool) return value.toBool(); | |
| 40 | ✗ | return std::nullopt; | |
| 41 | 773 | } | |
| 42 | |||
| 43 | 7 | bool SystemMotionPreference::refresh() { | |
| 44 |
1/1✓ Branch 2 → 3 taken 7 times.
|
7 | const auto current = systemReducedMotion(); |
| 45 |
2/2✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 6 taken 6 times.
|
7 | if (current == m_last) return false; |
| 46 | 6 | m_last = current; | |
| 47 |
1/1✓ Branch 6 → 7 taken 6 times.
|
6 | emit changed(); |
| 48 | 6 | return true; | |
| 49 | } | ||
| 50 |