diff --git a/src/platformtheme/kfontsettingsdata.cpp b/src/platformtheme/kfontsettingsdata.cpp index ea95916..c8e3e81 100644 --- a/src/platformtheme/kfontsettingsdata.cpp +++ b/src/platformtheme/kfontsettingsdata.cpp @@ -1,114 +1,160 @@ /* This file is part of the KDE libraries Copyright (C) 2000, 2006 David Faure Copyright 2008 Friedrich W. H. Kossebau Copyright 2013 Aleix Pol Gonzalez This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kfontsettingsdata.h" #include #include #include #include #include #include +#include #include #include #include +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); for (int i = 0; i < FontTypesCount; ++i) { mFonts[i] = nullptr; } } KFontSettingsData::~KFontSettingsData() { for (int i = 0; i < FontTypesCount; ++i) { delete mFonts[i]; } } // NOTE: keep in sync with plasma-desktop/kcms/fonts/fonts.cpp static const char GeneralId[] = "General"; static const char DefaultFont[] = "Noto Sans"; static const KFontData DefaultFontData[KFontSettingsData::FontTypesCount] = { { GeneralId, "font", DefaultFont, 10, -1, QFont::SansSerif, "Regular" }, { GeneralId, "fixed", "Hack", 9, -1, QFont::Monospace, "Regular" }, { GeneralId, "toolBarFont", DefaultFont, 10, -1, QFont::SansSerif, "Regular" }, { GeneralId, "menuFont", DefaultFont, 10, -1, QFont::SansSerif, "Regular" }, { "WM", "activeFont", DefaultFont, 10, -1, QFont::SansSerif, "Regular" }, { GeneralId, "taskbarFont", DefaultFont, 10, -1, QFont::SansSerif, "Regular" }, { GeneralId, "smallestReadableFont", DefaultFont, 8, -1, QFont::SansSerif, "Regular" } }; QFont *KFontSettingsData::font(FontTypes fontType) { QFont *cachedFont = mFonts[fontType]; if (!cachedFont) { const KFontData &fontData = DefaultFontData[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 if (!fontInfo.isEmpty()) { cachedFont->fromString(fontInfo); } else { // set the canonical stylename here, where it cannot override // user-specific font attributes if those do not include a stylename. cachedFont->setStyleName(QLatin1String(fontData.StyleName)); } mFonts[fontType] = cachedFont; } return cachedFont; } void KFontSettingsData::dropFontSettingsCache() { mKdeGlobals->reparseConfiguration(); for (int i = 0; i < FontTypesCount; ++i) { delete mFonts[i]; mFonts[i] = nullptr; } QWindowSystemInterface::handleThemeChange(nullptr); if (qobject_cast(QCoreApplication::instance())) { QApplication::setFont(*font(KFontSettingsData::GeneralFont)); } else { QGuiApplication::setFont(*font(KFontSettingsData::GeneralFont)); } } 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 reply = QDBusConnection::sessionBus().call(message); + if (reply.isValid()) { + QDBusVariant result = qvariant_cast(reply.value()); + const QString resultStr = result.variant().toString(); + + if (!resultStr.isEmpty()) { + return resultStr; + } + } + } + + const KConfigGroup configGroup(mKdeGlobals, group); + return configGroup.readEntry(key, defaultValue); } diff --git a/src/platformtheme/kfontsettingsdata.h b/src/platformtheme/kfontsettingsdata.h index 96c785e..473b35a 100644 --- a/src/platformtheme/kfontsettingsdata.h +++ b/src/platformtheme/kfontsettingsdata.h @@ -1,72 +1,77 @@ /* This file is part of the KDE libraries Copyright (C) 2000, 2006 David Faure Copyright 2008 Friedrich W. H. Kossebau Copyright 2013 Aleix Pol Gonzalez This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KFONTSETTINGSDATA_H #define KFONTSETTINGSDATA_H +#include #include #include #include struct KFontData { const char *ConfigGroupKey; const char *ConfigKey; const char *FontName; int Size; int Weight; QFont::StyleHint StyleHint; const char *StyleName; }; class KFontSettingsData : public QObject { Q_OBJECT public: // if adding a new type here also add an entry to DefaultFontData enum FontTypes { GeneralFont = 0, FixedFont, ToolbarFont, MenuFont, WindowTitleFont, TaskbarFont, SmallestReadableFont, FontTypesCount }; public: KFontSettingsData(); ~KFontSettingsData() override; public Q_SLOTS: void dropFontSettingsCache(); 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; }; #endif // KFONTSETTINGSDATA_H diff --git a/src/platformtheme/khintssettings.cpp b/src/platformtheme/khintssettings.cpp index 906208f..7444c99 100644 --- a/src/platformtheme/khintssettings.cpp +++ b/src/platformtheme/khintssettings.cpp @@ -1,419 +1,521 @@ /* This file is part of the KDE libraries * Copyright 2013 Kevin Ottens * Copyright 2013 Aleix Pol Gonzalez * Copyright 2013 Alejandro Fiestas Olivares * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License or ( at * your option ) version 3 or, at the discretion of KDE e.V. ( which shall * act as a proxy as in section 14 of the GPLv3 ), any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "khintssettings.h" #include #include #include #include #include #include #include #include #include #include #include #include #include +#include +#include #include #include #include #include #include #include #include #ifdef UNIT_TEST #undef HAVE_X11 #define HAVE_X11 0 #endif #if HAVE_X11 #include #include #endif static const QString defaultLookAndFeelPackage = QStringLiteral("org.kde.breeze.desktop"); +const QDBusArgument &operator>>(const QDBusArgument &argument, QMap &map) +{ + argument.beginMap(); + map.clear(); + + while (!argument.atEnd()) { + QString key; + QVariantMap value; + argument.beginMapEntry(); + argument >> key >> value; + argument.endMapEntry(); + map.insert(key, value); + } + + argument.endMap(); + return argument; +} + +static inline bool checkUsePortalSupport() +{ + return !QStandardPaths::locate(QStandardPaths::RuntimeLocation, QStringLiteral("flatpak-info")).isEmpty() || qEnvironmentVariableIsSet("SNAP"); +} + KHintsSettings::KHintsSettings(KSharedConfig::Ptr kdeglobals) : QObject(nullptr) , mKdeGlobals(kdeglobals) + , mUsePortal(checkUsePortalSupport()) { if (!mKdeGlobals) { mKdeGlobals = KSharedConfig::openConfig(); } KConfigGroup cg(mKdeGlobals, "KDE"); + if (mUsePortal) { + updatePortalSetting(); + } + // try to extract the proper defaults file from a lookandfeel package - const QString looknfeel = cg.readEntry("LookAndFeelPackage", defaultLookAndFeelPackage); + const QString looknfeel = readConfigValue(cg, QStringLiteral("LookAndFeelPackage"), defaultLookAndFeelPackage).toString(); mDefaultLnfConfig = KSharedConfig::openConfig(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("plasma/look-and-feel/") + looknfeel + QStringLiteral("/contents/defaults"))); if (looknfeel != defaultLookAndFeelPackage) { mLnfConfig = KSharedConfig::openConfig(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("plasma/look-and-feel/") + defaultLookAndFeelPackage + QStringLiteral("/contents/defaults"))); } - const auto cursorBlinkRate = cg.readEntry("CursorBlinkRate", 1000); + const auto cursorBlinkRate = readConfigValue(cg, QStringLiteral("CursorBlinkRate"), 1000).toInt(); m_hints[QPlatformTheme::CursorFlashTime] = cursorBlinkRate > 0 ? qBound(200, cursorBlinkRate, 2000) : 0; // 0 => no blinking - m_hints[QPlatformTheme::MouseDoubleClickInterval] = cg.readEntry("DoubleClickInterval", 400); - m_hints[QPlatformTheme::StartDragDistance] = cg.readEntry("StartDragDist", 10); - m_hints[QPlatformTheme::StartDragTime] = cg.readEntry("StartDragTime", 500); + m_hints[QPlatformTheme::MouseDoubleClickInterval] = readConfigValue(cg, QStringLiteral("DoubleClickInterval"), 400); + m_hints[QPlatformTheme::StartDragDistance] = readConfigValue(cg, QStringLiteral("StartDragDist"), 10); + m_hints[QPlatformTheme::StartDragTime] = readConfigValue(cg, QStringLiteral("StartDragTime"), 500); KConfigGroup cgToolbar(mKdeGlobals, "Toolbar style"); m_hints[QPlatformTheme::ToolButtonStyle] = toolButtonStyle(cgToolbar); KConfigGroup cgToolbarIcon(mKdeGlobals, "MainToolbarIcons"); - m_hints[QPlatformTheme::ToolBarIconSize] = cgToolbarIcon.readEntry("Size", 22); + m_hints[QPlatformTheme::ToolBarIconSize] = readConfigValue(cgToolbarIcon, QStringLiteral("Size"), 22); - m_hints[QPlatformTheme::ItemViewActivateItemOnSingleClick] = cg.readEntry("SingleClick", true); + m_hints[QPlatformTheme::ItemViewActivateItemOnSingleClick] = readConfigValue(cg, QStringLiteral("SingleClick"), true); m_hints[QPlatformTheme::SystemIconThemeName] = readConfigValue(QStringLiteral("Icons"), QStringLiteral("Theme"), QStringLiteral("breeze")); m_hints[QPlatformTheme::SystemIconFallbackThemeName] = QStringLiteral("hicolor"); m_hints[QPlatformTheme::IconThemeSearchPaths] = xdgIconThemePaths(); QStringList styleNames{ QStringLiteral(BREEZE_STYLE_NAME), QStringLiteral("oxygen"), QStringLiteral("fusion"), QStringLiteral("windows") }; - const QString configuredStyle = cg.readEntry("widgetStyle", QString()); + const QString configuredStyle = readConfigValue(cg, QStringLiteral("widgetStyle"), QString()).toString(); if (!configuredStyle.isEmpty()) { styleNames.removeOne(configuredStyle); styleNames.prepend(configuredStyle); } const QString lnfStyle = readConfigValue(QStringLiteral("KDE"), QStringLiteral("widgetStyle"), QString()).toString(); if (!lnfStyle.isEmpty()) { styleNames.removeOne(lnfStyle); styleNames.prepend(lnfStyle); } m_hints[QPlatformTheme::StyleNames] = styleNames; m_hints[QPlatformTheme::DialogButtonBoxLayout] = QDialogButtonBox::KdeLayout; - m_hints[QPlatformTheme::DialogButtonBoxButtonsHaveIcons] = cg.readEntry("ShowIconsOnPushButtons", true); + m_hints[QPlatformTheme::DialogButtonBoxButtonsHaveIcons] = readConfigValue(cg, QStringLiteral("ShowIconsOnPushButtons"), true); m_hints[QPlatformTheme::UseFullScreenForPopupMenu] = true; m_hints[QPlatformTheme::KeyboardScheme] = QPlatformTheme::KdeKeyboardScheme; - m_hints[QPlatformTheme::UiEffects] = cg.readEntry("GraphicEffectsLevel", 0) != 0 ? QPlatformTheme::GeneralUiEffect : 0; + m_hints[QPlatformTheme::UiEffects] = readConfigValue(cg, QStringLiteral("GraphicEffectsLevel"), 0) != 0 ? QPlatformTheme::GeneralUiEffect : 0; m_hints[QPlatformTheme::IconPixmapSizes] = QVariant::fromValue(QList() << 512 << 256 << 128 << 64 << 32 << 22 << 16 << 8); - m_hints[QPlatformTheme::WheelScrollLines] = cg.readEntry("WheelScrollLines", 3); + m_hints[QPlatformTheme::WheelScrollLines] = readConfigValue(cg, QStringLiteral("WheelScrollLines"), 3); if (qobject_cast(QCoreApplication::instance())) { - QApplication::setWheelScrollLines(cg.readEntry("WheelScrollLines", 3)); + QApplication::setWheelScrollLines(readConfigValue(cg, QStringLiteral("WheelScrollLines"), 3).toInt()); } updateShowIconsInMenuItems(cg); m_hints[QPlatformTheme::ShowShortcutsInContextMenus] = true; QMetaObject::invokeMethod(this, "delayedDBusConnects", Qt::QueuedConnection); QMetaObject::invokeMethod(this, "setupIconLoader", Qt::QueuedConnection); loadPalettes(); } KHintsSettings::~KHintsSettings() { qDeleteAll(m_palettes); } QVariant KHintsSettings::readConfigValue(const QString &group, const QString &key, const QVariant &defaultValue) { KConfigGroup userCg(mKdeGlobals, group); - QVariant value = userCg.readEntry(key, QString()); + QVariant value = readConfigValue(userCg, key, QString()); if (!value.isNull()) { return value; } if (mLnfConfig) { KConfigGroup lnfCg(mLnfConfig, "kdeglobals"); lnfCg = KConfigGroup(&lnfCg, group); if (lnfCg.isValid()) { value = lnfCg.readEntry(key, defaultValue); if (!value.isNull()) { return value; } } } KConfigGroup lnfCg(mDefaultLnfConfig, "kdeglobals"); lnfCg = KConfigGroup(&lnfCg, group); if (lnfCg.isValid()) { - return lnfCg.readEntry(key, defaultValue); + return lnfCg.readEntry(key, defaultValue); } return defaultValue; } +QVariant KHintsSettings::readConfigValue(const KConfigGroup &cg, const QString &key, const QVariant &defaultValue) const +{ + if (mUsePortal) { + const QString settingName = QStringLiteral("org.kde.kdeglobals.%1").arg(cg.name()); + auto groupIt = mKdeGlobalsPortal.constFind(settingName); + if (groupIt != mKdeGlobalsPortal.constEnd()) { + auto valueIt = groupIt.value().constFind(key); + if (valueIt != groupIt.value().constEnd()) { + return valueIt.value(); + } + } + } + + return cg.readEntry(key, defaultValue); +} + QStringList KHintsSettings::xdgIconThemePaths() const { QStringList paths; // make sure we have ~/.local/share/icons in paths if it exists paths << QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("icons"), QStandardPaths::LocateDirectory); const QFileInfo homeIconDir(QDir::homePath() + QStringLiteral("/.icons")); if (homeIconDir.isDir()) { paths << homeIconDir.absoluteFilePath(); } return paths; } void KHintsSettings::delayedDBusConnects() { QDBusConnection::sessionBus().connect(QString(), QStringLiteral("/KToolBar"), QStringLiteral("org.kde.KToolBar"), QStringLiteral("styleChanged"), this, SLOT(toolbarStyleChanged())); QDBusConnection::sessionBus().connect(QString(), QStringLiteral("/KGlobalSettings"), QStringLiteral("org.kde.KGlobalSettings"), QStringLiteral("notifyChange"), this, SLOT(slotNotifyChange(int,int))); + 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 KHintsSettings::setupIconLoader() { connect(KIconLoader::global(), &KIconLoader::iconChanged, this, &KHintsSettings::iconChanged); } void KHintsSettings::toolbarStyleChanged() { mKdeGlobals->reparseConfiguration(); KConfigGroup cg(mKdeGlobals, "Toolbar style"); m_hints[QPlatformTheme::ToolButtonStyle] = toolButtonStyle(cg); //from gtksymbol.cpp QWidgetList widgets = QApplication::allWidgets(); for (int i = 0; i < widgets.size(); ++i) { QWidget *widget = widgets.at(i); if (qobject_cast(widget)) { QEvent event(QEvent::StyleChange); QApplication::sendEvent(widget, &event); } } } void KHintsSettings::slotNotifyChange(int type, int arg) { mKdeGlobals->reparseConfiguration(); KConfigGroup cg(mKdeGlobals, "KDE"); switch (type) { case PaletteChanged: { loadPalettes(); //QApplication::setPalette and QGuiApplication::setPalette are different functions //and non virtual. Call the correct one if (qobject_cast(QCoreApplication::instance())) { QPalette palette = *m_palettes[QPlatformTheme::SystemPalette]; QApplication::setPalette(palette); // QTBUG QGuiApplication::paletteChanged() signal is only emitted by QGuiApplication // so things like SystemPalette QtQuick item that use it won't notice a palette // change when a QApplication which causes e.g. QML System Settings modules to not update emit qApp->paletteChanged(palette); } else if (qobject_cast(QCoreApplication::instance())) { QGuiApplication::setPalette(*m_palettes[QPlatformTheme::SystemPalette]); } break; } case SettingsChanged: { SettingsCategory category = static_cast(arg); if (category == SETTINGS_QT || category == SETTINGS_MOUSE) { updateQtSettings(cg); } else if (category == SETTINGS_STYLE) { m_hints[QPlatformTheme::DialogButtonBoxButtonsHaveIcons] = cg.readEntry("ShowIconsOnPushButtons", true); m_hints[QPlatformTheme::UiEffects] = cg.readEntry("GraphicEffectsLevel", 0) != 0 ? QPlatformTheme::GeneralUiEffect : 0; updateShowIconsInMenuItems(cg); } break; } case ToolbarStyleChanged: { toolbarStyleChanged(); break; } case IconChanged: iconChanged(arg); //Once the KCM is ported to use IconChanged, this should not be needed break; case CursorChanged: updateCursorTheme(); break; case StyleChanged: { QApplication *app = qobject_cast(QCoreApplication::instance()); if (!app) { return; } - const QString theme = cg.readEntry("widgetStyle", QString()); + const QString theme = readConfigValue(cg, QStringLiteral("widgetStyle"), QString()).toString(); if (theme.isEmpty()) { return; } QStringList styleNames; - styleNames << cg.readEntry("widgetStyle", QString()) + styleNames << theme << QStringLiteral(BREEZE_STYLE_NAME) << QStringLiteral("oxygen") << QStringLiteral("fusion") << QStringLiteral("windows"); const QString lnfStyle = readConfigValue(QStringLiteral("KDE"), QStringLiteral("widgetStyle"), QString()).toString(); if (!lnfStyle.isEmpty() && !styleNames.contains(lnfStyle)) { styleNames.prepend(lnfStyle); } m_hints[QPlatformTheme::StyleNames] = styleNames; app->setStyle(theme); loadPalettes(); break; } default: qWarning() << "Unknown type of change in KGlobalSettings::slotNotifyChange: " << type; } } +void KHintsSettings::slotPortalSettingChanged(const QString &group, const QString &key, const QDBusVariant &value) +{ + if (group == QLatin1String("org.kde.kdeglobals.General") && key == QLatin1String("ColorScheme")) { + // For colors obtain complete configuration again + updatePortalSetting(); + slotNotifyChange(PaletteChanged, 0); + } else if (group == QLatin1String("org.kde.kdeglobals.KDE") && key == QLatin1String("widgetStyle")) { + mKdeGlobalsPortal[group][key] = value.variant().toString(); + slotNotifyChange(StyleChanged, 0); + } else if (group == QLatin1String("org.kde.kdeglobals.Icons") && key == QLatin1String("Theme")) { + mKdeGlobalsPortal[group][key] = value.variant().toString(); + // Change icons for each group + for (int i = 0; i <= 5; ++i) { + iconChanged(i); + } + } else if (group == QLatin1String("org.kde.kdeglobals.Toolbar style") && key == QLatin1String("ToolButtonStyle")) { + mKdeGlobalsPortal[group][key] = value.variant().toString(); + toolbarStyleChanged(); + } +} + void KHintsSettings::iconChanged(int group) { KIconLoader::Group iconGroup = (KIconLoader::Group) group; if (iconGroup != KIconLoader::MainToolbar) { m_hints[QPlatformTheme::SystemIconThemeName] = readConfigValue(QStringLiteral("Icons"), QStringLiteral("Theme"), QStringLiteral("breeze")); - return; } const int currentSize = KIconLoader::global()->currentSize(KIconLoader::MainToolbar); if (m_hints[QPlatformTheme::ToolBarIconSize] == currentSize) { return; } m_hints[QPlatformTheme::ToolBarIconSize] = currentSize; //If we are not a QApplication, means that we are a QGuiApplication, then we do nothing. if (!qobject_cast(QCoreApplication::instance())) { return; } QWidgetList widgets = QApplication::allWidgets(); Q_FOREACH (QWidget *widget, widgets) { if (qobject_cast(widget) || qobject_cast(widget)) { QEvent event(QEvent::StyleChange); QApplication::sendEvent(widget, &event); } } } void KHintsSettings::updateQtSettings(KConfigGroup &cg) { int flash = qBound(200, cg.readEntry("CursorBlinkRate", 1000), 2000); m_hints[QPlatformTheme::CursorFlashTime] = flash; int doubleClickInterval = cg.readEntry("DoubleClickInterval", 400); m_hints[QPlatformTheme::MouseDoubleClickInterval] = doubleClickInterval; int startDragDistance = cg.readEntry("StartDragDist", 10); m_hints[QPlatformTheme::StartDragDistance] = startDragDistance; int startDragTime = cg.readEntry("StartDragTime", 10); m_hints[QPlatformTheme::StartDragTime] = startDragTime; m_hints[QPlatformTheme::ItemViewActivateItemOnSingleClick] = cg.readEntry("SingleClick", true); updateShowIconsInMenuItems(cg); int wheelScrollLines = cg.readEntry("WheelScrollLines", 3); m_hints[QPlatformTheme::WheelScrollLines] = wheelScrollLines; QApplication *app = qobject_cast(QCoreApplication::instance()); if (app) { QApplication::setWheelScrollLines(cg.readEntry("WheelScrollLines", 3)); } } void KHintsSettings::updateShowIconsInMenuItems(KConfigGroup &cg) { - bool showIcons = cg.readEntry("ShowIconsInMenuItems", true); + bool showIcons = readConfigValue(cg, QStringLiteral("ShowIconsInMenuItems"), true).toBool(); QCoreApplication::setAttribute(Qt::AA_DontShowIconsInMenus, !showIcons); } -Qt::ToolButtonStyle KHintsSettings::toolButtonStyle(const KConfigGroup &cg) const +Qt::ToolButtonStyle KHintsSettings::toolButtonStyle(const KConfigGroup &cg) { - const QString buttonStyle = cg.readEntry("ToolButtonStyle", "TextBesideIcon").toLower(); + const QString buttonStyle = readConfigValue(cg, QStringLiteral("ToolButtonStyle"), QStringLiteral("TextBesideIcon")).toString().toLower(); return buttonStyle == QLatin1String("textbesideicon") ? Qt::ToolButtonTextBesideIcon : buttonStyle == QLatin1String("icontextright") ? Qt::ToolButtonTextBesideIcon : buttonStyle == QLatin1String("textundericon") ? Qt::ToolButtonTextUnderIcon : buttonStyle == QLatin1String("icontextbottom") ? Qt::ToolButtonTextUnderIcon : buttonStyle == QLatin1String("textonly") ? Qt::ToolButtonTextOnly : Qt::ToolButtonIconOnly; } void KHintsSettings::loadPalettes() { qDeleteAll(m_palettes); m_palettes.clear(); - if (mKdeGlobals->hasGroup("Colors:View")) { + if (mUsePortal && mKdeGlobalsPortal.contains(QStringLiteral("org.kde.kdeglobals.Colors:View"))) { + // Construct a temporary KConfig file containing color setting so we can create a KColorScheme from it + QTemporaryFile file; + file.open(); + + KSharedConfigPtr tempConfig = KSharedConfig::openConfig(file.fileName(), KConfig::SimpleConfig); + for (auto groupIt = mKdeGlobalsPortal.constBegin(); groupIt != mKdeGlobalsPortal.constEnd(); ++groupIt) { + if (groupIt.key().startsWith(QStringLiteral("org.kde.kdeglobals.Colors:"))) { + KConfigGroup tempGroup(tempConfig, groupIt.key().right(groupIt.key().length() - QStringLiteral("org.kde.kdeglobals.").length())); + for (auto valueIt = groupIt.value().constBegin(); valueIt != groupIt.value().constEnd(); ++valueIt) { + tempGroup.writeEntry(valueIt.key(), valueIt.value()); + } + } + } + m_palettes[QPlatformTheme::SystemPalette] = new QPalette(KColorScheme::createApplicationPalette(tempConfig)); + } else if (mKdeGlobals->hasGroup("Colors:View")) { m_palettes[QPlatformTheme::SystemPalette] = new QPalette(KColorScheme::createApplicationPalette(mKdeGlobals)); } else { - KConfigGroup cg(mKdeGlobals, "KDE"); - const QString looknfeel = cg.readEntry("LookAndFeelPackage", defaultLookAndFeelPackage); + const QString looknfeel = readConfigValue(cg, QStringLiteral("LookAndFeelPackage"), defaultLookAndFeelPackage).toString(); QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("plasma/look-and-feel/") + looknfeel + QStringLiteral("/contents/colors")); if (!path.isEmpty()) { m_palettes[QPlatformTheme::SystemPalette] = new QPalette(KColorScheme::createApplicationPalette(KSharedConfig::openConfig(path))); return; } const QString scheme = readConfigValue(QStringLiteral("General"), QStringLiteral("ColorScheme"), QStringLiteral("Breeze")).toString(); path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("color-schemes/") + scheme + QStringLiteral(".colors")); if (!path.isEmpty()) { m_palettes[QPlatformTheme::SystemPalette] = new QPalette(KColorScheme::createApplicationPalette(KSharedConfig::openConfig(path))); } } } void KHintsSettings::updateCursorTheme() { KConfig config(QStringLiteral("kcminputrc")); KConfigGroup g(&config, "Mouse"); int size = g.readEntry("cursorSize", -1); // Default cursor size is 16 points if (size == -1) { if (QScreen *s = QGuiApplication::primaryScreen()) { size = s->logicalDotsPerInchY() * 16 / 72; } else { size = 0; } } #if HAVE_X11 if (QX11Info::isPlatformX11()) { const QString theme = g.readEntry("cursorTheme", QString()); // Note that in X11R7.1 and earlier, calling XcursorSetTheme() // with a NULL theme would cause Xcursor to use "default", but // in 7.2 and later it will cause it to revert to the theme that // was configured when the application was started. XcursorSetTheme(QX11Info::display(), theme.isNull() ? "default" : QFile::encodeName(theme).constData()); XcursorSetDefaultSize(QX11Info::display(), size); } #endif } + +void KHintsSettings::updatePortalSetting() +{ + mKdeGlobalsPortal.clear(); + + QDBusMessage message = QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.portal.Desktop"), + QStringLiteral("/org/freedesktop/portal/desktop"), + QStringLiteral("org.freedesktop.portal.Settings"), + QStringLiteral("ReadAll")); + message << QStringList{QStringLiteral("org.kde.kdeglobals.*")}; + + // FIXME: async? + QDBusMessage resultMessage = QDBusConnection::sessionBus().call(message); + if (resultMessage.type() == QDBusMessage::ReplyMessage) { + QDBusArgument dbusArgument = resultMessage.arguments().at(0).value(); + dbusArgument >> mKdeGlobalsPortal; + } +} diff --git a/src/platformtheme/khintssettings.h b/src/platformtheme/khintssettings.h index d0b5622..0b85977 100644 --- a/src/platformtheme/khintssettings.h +++ b/src/platformtheme/khintssettings.h @@ -1,90 +1,96 @@ /* This file is part of the KDE libraries * Copyright 2013 Alejandro Fiestas Olivares * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License or ( at * your option ) version 3 or, at the discretion of KDE e.V. ( which shall * act as a proxy as in section 14 of the GPLv3 ), any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KHINTS_SETTINGS_H #define KHINTS_SETTINGS_H +#include #include #include #include #include class KConfigGroup; class QPalette; class KHintsSettings : public QObject { Q_OBJECT public: /** * An identifier for change signals. * @note Copied from KGlobalSettings */ enum ChangeType { PaletteChanged = 0, FontChanged, StyleChanged, SettingsChanged, IconChanged, CursorChanged, ToolbarStyleChanged, ClipboardConfigChanged, BlockShortcuts, NaturalSortingChanged }; /** * Valid values for the settingsChanged signal * @note Copied from KGlobalSettings */ enum SettingsCategory { SETTINGS_MOUSE, SETTINGS_COMPLETION, SETTINGS_PATHS, SETTINGS_POPUPMENU, SETTINGS_QT, SETTINGS_SHORTCUTS, SETTINGS_LOCALE, SETTINGS_STYLE }; explicit KHintsSettings(KSharedConfig::Ptr kdeglobals = KSharedConfig::Ptr()); ~KHintsSettings() override; inline QVariant hint(QPlatformTheme::ThemeHint hint) const { return m_hints[hint]; } inline QPalette *palette(QPlatformTheme::Palette type) const { return m_palettes[type]; } QStringList xdgIconThemePaths() const; private Q_SLOTS: void delayedDBusConnects(); 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 m_palettes; QHash m_hints; KSharedConfigPtr mKdeGlobals; KSharedConfigPtr mDefaultLnfConfig; KSharedConfigPtr mLnfConfig; + QMap mKdeGlobalsPortal; + bool mUsePortal; }; #endif //KHINTS_SETTINGS_H