| 1 | // Copyright (C) 2025 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QGNOMEPORTALINTERFACE_P_H |
| 5 | #define QGNOMEPORTALINTERFACE_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtCore/qtconfigmacros.h> |
| 19 | QT_REQUIRE_CONFIG(dbus); |
| 20 | |
| 21 | #include <QtCore/QObject> |
| 22 | #include <QtGui/private/qdbuslistener_p.h> |
| 23 | |
| 24 | QT_BEGIN_NAMESPACE |
| 25 | |
| 26 | class Q_GUI_EXPORT QGnomePortalInterface : public QObject |
| 27 | { |
| 28 | Q_OBJECT |
| 29 | |
| 30 | public: |
| 31 | QGnomePortalInterface(QObject *parent = nullptr); |
| 32 | ~QGnomePortalInterface() = default; |
| 33 | |
| 34 | Qt::ColorScheme colorScheme(Qt::ColorScheme fallback = Qt::ColorScheme::Unknown) const; |
| 35 | Qt::ContrastPreference contrastPreference( |
| 36 | Qt::ContrastPreference fallback = Qt::ContrastPreference::NoPreference) const; |
| 37 | |
| 38 | private: |
| 39 | void querySettings(); |
| 40 | void updateColorScheme(Qt::ColorScheme colorScheme); |
| 41 | void updateContrast(Qt::ContrastPreference contrast); |
| 42 | |
| 43 | Q_SIGNALS: |
| 44 | void colorSchemeChanged(Qt::ColorScheme); |
| 45 | void contrastChanged(Qt::ContrastPreference); |
| 46 | void themeNameChanged(const QString &themeName); |
| 47 | |
| 48 | private Q_SLOTS: |
| 49 | void dbusSettingChanged(QDBusListener::Provider, QDBusListener::Setting, const QVariant &value); |
| 50 | |
| 51 | private: |
| 52 | mutable uint m_version = 0; // cached version value |
| 53 | std::optional<Qt::ColorScheme> m_colorScheme; |
| 54 | std::optional<Qt::ContrastPreference> m_contrast; |
| 55 | std::unique_ptr<QDBusListener> m_dbus; |
| 56 | static constexpr QLatin1StringView s_service{ "org.freedesktop.portal.Desktop"}; |
| 57 | static constexpr QLatin1StringView s_path{ "/org/freedesktop/portal/desktop"}; |
| 58 | static constexpr QLatin1StringView s_interface{ "org.freedesktop.portal.Settings"}; |
| 59 | }; |
| 60 | |
| 61 | QT_END_NAMESPACE |
| 62 | |
| 63 | #endif // QGNOMEPORTALINTERFACE_P_H |
| 64 |
