Changeset View
Changeset View
Standalone View
Standalone View
src/platformtheme/kfontsettingsdata.cpp
Show All 19 Lines | |||||
20 | 20 | | |||
21 | #include "kfontsettingsdata.h" | 21 | #include "kfontsettingsdata.h" | ||
22 | #include <QCoreApplication> | 22 | #include <QCoreApplication> | ||
23 | #include <QString> | 23 | #include <QString> | ||
24 | #include <QVariant> | 24 | #include <QVariant> | ||
25 | #include <QApplication> | 25 | #include <QApplication> | ||
26 | #include <QDBusMessage> | 26 | #include <QDBusMessage> | ||
27 | #include <QDBusConnection> | 27 | #include <QDBusConnection> | ||
28 | #include <QDBusReply> | ||||
28 | #include <qpa/qwindowsysteminterface.h> | 29 | #include <qpa/qwindowsysteminterface.h> | ||
29 | 30 | | |||
30 | #include <ksharedconfig.h> | 31 | #include <ksharedconfig.h> | ||
31 | #include <kconfiggroup.h> | 32 | #include <kconfiggroup.h> | ||
32 | 33 | | |||
34 | static inline bool checkUsePortalSupport() | ||||
35 | { | ||||
36 | return !QStandardPaths::locate(QStandardPaths::RuntimeLocation, QStringLiteral("flatpak-info")).isEmpty() || qEnvironmentVariableIsSet("SNAP"); | ||||
37 | } | ||||
38 | | ||||
33 | KFontSettingsData::KFontSettingsData() | 39 | KFontSettingsData::KFontSettingsData() | ||
34 | : QObject(nullptr), | 40 | : QObject(nullptr) | ||
35 | mKdeGlobals(KSharedConfig::openConfig()) | 41 | , mUsePortal(checkUsePortalSupport()) | ||
42 | , mKdeGlobals(KSharedConfig::openConfig()) | ||||
36 | { | 43 | { | ||
37 | QMetaObject::invokeMethod(this, "delayedDBusConnects", Qt::QueuedConnection); | 44 | QMetaObject::invokeMethod(this, "delayedDBusConnects", Qt::QueuedConnection); | ||
38 | 45 | | |||
39 | for (int i = 0; i < FontTypesCount; ++i) { | 46 | for (int i = 0; i < FontTypesCount; ++i) { | ||
40 | mFonts[i] = nullptr; | 47 | mFonts[i] = nullptr; | ||
41 | } | 48 | } | ||
42 | } | 49 | } | ||
43 | 50 | | |||
Show All 22 Lines | |||||
66 | { | 73 | { | ||
67 | QFont *cachedFont = mFonts[fontType]; | 74 | QFont *cachedFont = mFonts[fontType]; | ||
68 | 75 | | |||
69 | if (!cachedFont) { | 76 | if (!cachedFont) { | ||
70 | const KFontData &fontData = DefaultFontData[fontType]; | 77 | const KFontData &fontData = DefaultFontData[fontType]; | ||
71 | cachedFont = new QFont(QLatin1String(fontData.FontName), fontData.Size, fontData.Weight); | 78 | cachedFont = new QFont(QLatin1String(fontData.FontName), fontData.Size, fontData.Weight); | ||
72 | cachedFont->setStyleHint(fontData.StyleHint); | 79 | cachedFont->setStyleHint(fontData.StyleHint); | ||
73 | 80 | | |||
74 | const KConfigGroup configGroup(mKdeGlobals, fontData.ConfigGroupKey); | 81 | QString fontInfo = readConfigValue(QLatin1String(fontData.ConfigGroupKey), QLatin1String(fontData.ConfigKey)); | ||
broulik: `const` | |||||
75 | QString fontInfo = configGroup.readEntry(fontData.ConfigKey, QString()); | | |||
76 | 82 | | |||
77 | //If we have serialized information for this font, restore it | 83 | //If we have serialized information for this font, restore it | ||
78 | //NOTE: We are not using KConfig directly because we can't call QFont::QFont from here | 84 | //NOTE: We are not using KConfig directly because we can't call QFont::QFont from here | ||
79 | if (!fontInfo.isEmpty()) { | 85 | if (!fontInfo.isEmpty()) { | ||
80 | cachedFont->fromString(fontInfo); | 86 | cachedFont->fromString(fontInfo); | ||
81 | } else { | 87 | } else { | ||
82 | // set the canonical stylename here, where it cannot override | 88 | // set the canonical stylename here, where it cannot override | ||
83 | // user-specific font attributes if those do not include a stylename. | 89 | // user-specific font attributes if those do not include a stylename. | ||
Show All 22 Lines | 111 | } else { | |||
106 | QGuiApplication::setFont(*font(KFontSettingsData::GeneralFont)); | 112 | QGuiApplication::setFont(*font(KFontSettingsData::GeneralFont)); | ||
107 | } | 113 | } | ||
108 | } | 114 | } | ||
109 | 115 | | |||
110 | void KFontSettingsData::delayedDBusConnects() | 116 | void KFontSettingsData::delayedDBusConnects() | ||
111 | { | 117 | { | ||
112 | QDBusConnection::sessionBus().connect(QString(), QStringLiteral("/KDEPlatformTheme"), QStringLiteral("org.kde.KDEPlatformTheme"), | 118 | QDBusConnection::sessionBus().connect(QString(), QStringLiteral("/KDEPlatformTheme"), QStringLiteral("org.kde.KDEPlatformTheme"), | ||
113 | QStringLiteral("refreshFonts"), this, SLOT(dropFontSettingsCache())); | 119 | QStringLiteral("refreshFonts"), this, SLOT(dropFontSettingsCache())); | ||
120 | | ||||
121 | if (mUsePortal) { | ||||
122 | QDBusConnection::sessionBus().connect(QString(), QStringLiteral("/org/freedesktop/portal/desktop"), QStringLiteral("org.freedesktop.portal.Settings"), | ||||
123 | QStringLiteral("SettingChanged"), this, SLOT(slotPortalSettingChanged(QString,QString,QDBusVariant))); | ||||
124 | } | ||||
125 | } | ||||
126 | | ||||
127 | void KFontSettingsData::slotPortalSettingChanged(const QString &group, const QString &key, const QDBusVariant &value) | ||||
128 | { | ||||
129 | Q_UNUSED(value); | ||||
130 | | ||||
131 | if (group == QStringLiteral("org.kde.kdeglobals.General") && key == QStringLiteral("font")) { | ||||
broulik: Compare with `QLatin1String` | |||||
132 | dropFontSettingsCache(); | ||||
133 | } | ||||
134 | } | ||||
135 | | ||||
136 | QString KFontSettingsData::readConfigValue(const QString &group, const QString &key, const QString &defaultValue) | ||||
137 | { | ||||
138 | if (mUsePortal) { | ||||
139 | const QString settingName = QStringLiteral("org.kde.kdeglobals.%1").arg(group); | ||||
140 | QDBusMessage message = QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.portal.Desktop"), | ||||
141 | QStringLiteral("/org/freedesktop/portal/desktop"), | ||||
142 | QStringLiteral("org.freedesktop.portal.Settings"), | ||||
143 | QStringLiteral("Read")); | ||||
144 | message << settingName << key; | ||||
145 | | ||||
146 | // FIXME: async? | ||||
147 | QDBusReply<QVariant> reply = QDBusConnection::sessionBus().call(message); | ||||
148 | if (reply.isValid()) { | ||||
149 | QDBusVariant result = qvariant_cast<QDBusVariant>(reply.value()); | ||||
150 | const QString resultStr = result.variant().toString(); | ||||
151 | | ||||
152 | if (!resultStr.isEmpty()) { | ||||
153 | return resultStr; | ||||
154 | } | ||||
155 | } | ||||
156 | } | ||||
157 | | ||||
158 | const KConfigGroup configGroup(mKdeGlobals, group); | ||||
159 | return configGroup.readEntry(key, defaultValue); | ||||
114 | } | 160 | } |
const