| 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 | #include "qdbussettings_p.h" |
| 5 | #include <QtCore/qvariant.h> |
| 6 | |
| 7 | QT_BEGIN_NAMESPACE |
| 8 | |
| 9 | namespace QDBusSettings::XdgSettings { |
| 10 | // https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Settings.html |
| 11 | enum class ColorScheme : uint { NoPreference, PreferDark, PreferLight }; |
| 12 | } // namespace QDBusSettings::XdgSettings |
| 13 | |
| 14 | Qt::ContrastPreference QDBusSettings::XdgSettings::convertContrastPreference(const QVariant &value) |
| 15 | { |
| 16 | // XDG portal provides the contrast preference value as uint: |
| 17 | // 0 for no-preference, and, 1 for high-contrast. |
| 18 | if (!value.isValid()) |
| 19 | return Qt::ContrastPreference::NoPreference; |
| 20 | return static_cast<Qt::ContrastPreference>(value.toUInt()); |
| 21 | } |
| 22 | |
| 23 | Qt::ColorScheme QDBusSettings::XdgSettings::convertColorScheme(const QVariant &value) |
| 24 | { |
| 25 | switch (ColorScheme{ value.toUInt() }) { |
| 26 | case ColorScheme::NoPreference: |
| 27 | return Qt::ColorScheme::Unknown; |
| 28 | case ColorScheme::PreferDark: |
| 29 | return Qt::ColorScheme::Dark; |
| 30 | case ColorScheme::PreferLight: |
| 31 | return Qt::ColorScheme::Light; |
| 32 | } |
| 33 | Q_UNREACHABLE_RETURN(Qt::ColorScheme::Unknown); |
| 34 | } |
| 35 | |
| 36 | Qt::ContrastPreference |
| 37 | QDBusSettings::GnomeSettings::convertContrastPreference(const QVariant &value) |
| 38 | { |
| 39 | // GSetting provides the contrast value as boolean: |
| 40 | // true for enabled high-contrast, and, false for disabled high-contrast. |
| 41 | if (!value.isValid()) |
| 42 | return Qt::ContrastPreference::NoPreference; |
| 43 | return value.toBool() ? Qt::ContrastPreference::HighContrast |
| 44 | : Qt::ContrastPreference::NoPreference; |
| 45 | } |
| 46 | |
| 47 | QT_END_NAMESPACE |
| 48 |
