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