Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 64002af6 authored by Jan Grulich's avatar Jan Grulich

Add support for settings portal

Summary:
Sandboxed applications usually don't have access to read kdeglobals configuration. For this
reason we introduced Settings portal, to be able to obtain most necessary configuration without
allowing applications access to hosts configuration. The Settings portal implementation in
xdg-desktop-portals-kde was develop mostly for plasma-integration needs so it allows to get
colors, fonts, widget theme and some other configuration from kdeglobals.

Reviewers: #plasma, broulik

Reviewed By: #plasma, broulik

Subscribers: broulik, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D17213
parent 05331afe
......@@ -25,14 +25,21 @@
#include <QApplication>
#include <QDBusMessage>
#include <QDBusConnection>
#include <QDBusReply>
#include <qpa/qwindowsysteminterface.h>
#include <ksharedconfig.h>
#include <kconfiggroup.h>
static inline bool checkUsePortalSupport()
{
return !QStandardPaths::locate(QStandardPaths::RuntimeLocation, QStringLiteral("flatpak-info")).isEmpty() || qEnvironmentVariableIsSet("SNAP");
}
KFontSettingsData::KFontSettingsData()
: QObject(nullptr),
mKdeGlobals(KSharedConfig::openConfig())
: QObject(nullptr)
, mUsePortal(checkUsePortalSupport())
, mKdeGlobals(KSharedConfig::openConfig())
{
QMetaObject::invokeMethod(this, "delayedDBusConnects", Qt::QueuedConnection);
......@@ -71,8 +78,7 @@ QFont *KFontSettingsData::font(FontTypes fontType)
cachedFont = new QFont(QLatin1String(fontData.FontName), fontData.Size, fontData.Weight);
cachedFont->setStyleHint(fontData.StyleHint);
const KConfigGroup configGroup(mKdeGlobals, fontData.ConfigGroupKey);
QString fontInfo = configGroup.readEntry(fontData.ConfigKey, QString());
const QString fontInfo = readConfigValue(QLatin1String(fontData.ConfigGroupKey), QLatin1String(fontData.ConfigKey));
//If we have serialized information for this font, restore it
//NOTE: We are not using KConfig directly because we can't call QFont::QFont from here
......@@ -111,4 +117,44 @@ void KFontSettingsData::delayedDBusConnects()
{
QDBusConnection::sessionBus().connect(QString(), QStringLiteral("/KDEPlatformTheme"), QStringLiteral("org.kde.KDEPlatformTheme"),
QStringLiteral("refreshFonts"), this, SLOT(dropFontSettingsCache()));
if (mUsePortal) {
QDBusConnection::sessionBus().connect(QString(), QStringLiteral("/org/freedesktop/portal/desktop"), QStringLiteral("org.freedesktop.portal.Settings"),
QStringLiteral("SettingChanged"), this, SLOT(slotPortalSettingChanged(QString,QString,QDBusVariant)));
}
}
void KFontSettingsData::slotPortalSettingChanged(const QString &group, const QString &key, const QDBusVariant &value)
{
Q_UNUSED(value);
if (group == QLatin1String("org.kde.kdeglobals.General") && key == QLatin1String("font")) {
dropFontSettingsCache();
}
}
QString KFontSettingsData::readConfigValue(const QString &group, const QString &key, const QString &defaultValue) const
{
if (mUsePortal) {
const QString settingName = QStringLiteral("org.kde.kdeglobals.%1").arg(group);
QDBusMessage message = QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.portal.Desktop"),
QStringLiteral("/org/freedesktop/portal/desktop"),
QStringLiteral("org.freedesktop.portal.Settings"),
QStringLiteral("Read"));
message << settingName << key;
// FIXME: async?
QDBusReply<QVariant> reply = QDBusConnection::sessionBus().call(message);
if (reply.isValid()) {
QDBusVariant result = qvariant_cast<QDBusVariant>(reply.value());
const QString resultStr = result.variant().toString();
if (!resultStr.isEmpty()) {
return resultStr;
}
}
}
const KConfigGroup configGroup(mKdeGlobals, group);
return configGroup.readEntry(key, defaultValue);
}
......@@ -21,6 +21,7 @@
#ifndef KFONTSETTINGSDATA_H
#define KFONTSETTINGSDATA_H
#include <QDBusVariant>
#include <QObject>
#include <QFont>
#include <ksharedconfig.h>
......@@ -60,11 +61,15 @@ public Q_SLOTS:
private Q_SLOTS:
void delayedDBusConnects();
void slotPortalSettingChanged(const QString &group, const QString &key, const QDBusVariant &value);
public: // access, is not const due to caching
QFont *font(FontTypes fontType);
private:
QString readConfigValue(const QString &group, const QString &key, const QString &defaultValue = QString()) const;
bool mUsePortal;
QFont *mFonts[FontTypesCount];
KSharedConfigPtr mKdeGlobals;
};
......
This diff is collapsed.
......@@ -21,6 +21,7 @@
#ifndef KHINTS_SETTINGS_H
#define KHINTS_SETTINGS_H
#include <QDBusVariant>
#include <QObject>
#include <QVariant>
......@@ -70,21 +71,26 @@ private Q_SLOTS:
void setupIconLoader();
void toolbarStyleChanged();
void slotNotifyChange(int type, int arg);
void slotPortalSettingChanged(const QString &group, const QString &key, const QDBusVariant &value);
private:
QVariant readConfigValue(const QString &group, const QString &key, const QVariant &defaultValue);
QVariant readConfigValue(const KConfigGroup &cg, const QString &key, const QVariant &defaultValue) const;
void loadPalettes();
void iconChanged(int group);
void updateQtSettings(KConfigGroup &cg);
void updateShowIconsInMenuItems(KConfigGroup &cg);
Qt::ToolButtonStyle toolButtonStyle(const KConfigGroup &cg) const;
Qt::ToolButtonStyle toolButtonStyle(const KConfigGroup &cg);
void updateCursorTheme();
void updatePortalSetting();
QHash<QPlatformTheme::Palette, QPalette *> m_palettes;
QHash<QPlatformTheme::ThemeHint, QVariant> m_hints;
KSharedConfigPtr mKdeGlobals;
KSharedConfigPtr mDefaultLnfConfig;
KSharedConfigPtr mLnfConfig;
QMap<QString, QVariantMap> mKdeGlobalsPortal;
bool mUsePortal;
};
#endif //KHINTS_SETTINGS_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment