1
0
mirror of https://github.com/KDE/latte-dock.git synced 2025-03-03 20:58:25 +03:00

Copy ConfigPropertyMap from KDeclaractive

This commit is contained in:
Lana Black 2024-06-15 16:18:51 +00:00
parent 2e1ed61ae5
commit c1f760e952
8 changed files with 285 additions and 26 deletions

View File

@ -7,6 +7,7 @@ set(lattedock-app_SRCS
primaryoutputwatcher.cpp
main.cpp
coretypes.h
../legacy/configpropertymap.cpp
)
add_subdirectory(data)
@ -50,6 +51,7 @@ ki18n_wrap_ui(lattedock-app_SRCS settings/screensdialog/screensdialog.ui)
ki18n_wrap_ui(lattedock-app_SRCS settings/settingsdialog/settingsdialog.ui)
ki18n_wrap_ui(lattedock-app_SRCS settings/viewsdialog/viewsdialog.ui)
include_directories(../legacy)
add_executable(latte-dock ${lattedock-app_SRCS})

View File

@ -27,7 +27,6 @@
#include <KDesktopFile>
#include <KLocalizedString>
#include <KPluginMetaData>
#include <KDeclarative/ConfigPropertyMap>
namespace Latte {
namespace ViewPart {
@ -180,7 +179,7 @@ int ContainmentInterface::applicationLauncherId() const
auto launcherId{-1};
for (auto applet : applets) {
const auto provides = applet->kPackage().metadata().value(QStringLiteral("X-Plasma-Provides"));
const auto provides = applet->pluginMetaData().value(QStringLiteral("X-Plasma-Provides"));
if (provides.contains(QLatin1String("org.kde.plasma.launchermenu"))) {
if (!applet->globalShortcut().isEmpty()) {
@ -203,7 +202,7 @@ bool ContainmentInterface::updateBadgeForLatteTask(const QString identifier, con
const auto &applets = m_view->containment()->applets();
for (auto *applet : applets) {
KPluginMetaData meta = applet->kPackage().metadata();
KPluginMetaData meta = applet->pluginMetaData();
if (meta.pluginId() == QLatin1String("org.kde.latte.plasmoid")) {
@ -252,7 +251,8 @@ bool ContainmentInterface::activatePlasmaTask(const int index)
const auto &applets = m_view->containment()->applets();
for (auto *applet : applets) {
const auto &provides = KPluginMetaData::readStringList(applet->pluginMetaData().rawData(), QStringLiteral("X-Plasma-Provides"));
const KPluginMetaData& metadata = applet->pluginMetaData();
const QStringList& provides = metadata.value(QStringLiteral("X-Plasma-Provides"), QStringList{});
if (provides.contains(QLatin1String("org.kde.plasma.multitasking"))) {
if (QQuickItem *appletInterface = applet->property("_plasma_graphicObject").value<QQuickItem *>()) {
@ -262,7 +262,7 @@ bool ContainmentInterface::activatePlasmaTask(const int index)
continue;
}
KPluginMetaData meta = applet->kPackage().metadata();
KPluginMetaData meta = applet->pluginMetaData();
for (QQuickItem *item : childItems) {
if (auto *metaObject = item->metaObject()) {
@ -299,7 +299,8 @@ bool ContainmentInterface::newInstanceForPlasmaTask(const int index)
const auto &applets = m_view->containment()->applets();
for (auto *applet : applets) {
const auto &provides = KPluginMetaData::readStringList(applet->pluginMetaData().rawData(), QStringLiteral("X-Plasma-Provides"));
const KPluginMetaData& metadata = applet->pluginMetaData();
const QStringList& provides = metadata.value(QStringLiteral("X-Plasma-Provides"), QStringList{});
if (provides.contains(QLatin1String("org.kde.plasma.multitasking"))) {
if (QQuickItem *appletInterface = applet->property("_plasma_graphicObject").value<QQuickItem *>()) {
@ -309,7 +310,7 @@ bool ContainmentInterface::newInstanceForPlasmaTask(const int index)
continue;
}
KPluginMetaData meta = applet->kPackage().metadata();
KPluginMetaData meta = applet->pluginMetaData();
for (QQuickItem *item : childItems) {
if (auto *metaObject = item->metaObject()) {
@ -540,7 +541,7 @@ void ContainmentInterface::setPlasmoid(QObject *plasmoid)
m_plasmoid = plasmoid;
if (m_plasmoid) {
m_configuration = qobject_cast<KDeclarative::ConfigPropertyMap *>(m_plasmoid->property("configuration").value<QObject *>());
m_configuration = qobject_cast<Latte::Legacy::ConfigPropertyMap *>(m_plasmoid->property("configuration").value<QObject *>());
if (m_configuration) {
connect(m_configuration, &QQmlPropertyMap::valueChanged, this, &ContainmentInterface::containmentConfigPropertyChanged);
@ -908,7 +909,7 @@ void ContainmentInterface::updateAppletDelayedConfiguration()
}
}
void ContainmentInterface::initAppletConfigurationSignals(const int &id, KDeclarative::ConfigPropertyMap *configuration)
void ContainmentInterface::initAppletConfigurationSignals(const int &id, Latte::Legacy::ConfigPropertyMap *configuration)
{
if (!configuration) {
return;
@ -921,7 +922,7 @@ void ContainmentInterface::initAppletConfigurationSignals(const int &id, KDeclar
});
}
KDeclarative::ConfigPropertyMap *ContainmentInterface::appletConfiguration(const Plasma::Applet *applet)
Latte::Legacy::ConfigPropertyMap *ContainmentInterface::appletConfiguration(const Plasma::Applet *applet)
{
if (!m_view->containment() || !applet) {
return nullptr;
@ -930,13 +931,13 @@ KDeclarative::ConfigPropertyMap *ContainmentInterface::appletConfiguration(const
PlasmaQuick::AppletQuickItem *ai = applet->property("_plasma_graphicObject").value<PlasmaQuick::AppletQuickItem *>();
bool isSubContainment = Layouts::Storage::self()->isSubContainment(m_view->corona(), applet); //we use corona() to make sure that returns true even when it is first created from user
int currentAppletId = applet->id();
KDeclarative::ConfigPropertyMap *configuration{nullptr};
Latte::Legacy::ConfigPropertyMap *configuration{nullptr};
//! set configuration object properly for applets and subcontainments
if (!isSubContainment) {
int metaconfigindex = ai->metaObject()->indexOfProperty("configuration");
if (metaconfigindex >=0 ){
configuration = qobject_cast<KDeclarative::ConfigPropertyMap *>((ai->property("configuration")).value<QObject *>());
configuration = qobject_cast<Latte::Legacy::ConfigPropertyMap *>((ai->property("configuration")).value<QObject *>());
}
} else {
Plasma::Containment *subcontainment = Layouts::Storage::self()->subContainmentOf(m_view->corona(), applet);
@ -946,7 +947,7 @@ KDeclarative::ConfigPropertyMap *ContainmentInterface::appletConfiguration(const
if (subcai) {
int metaconfigindex = subcai->metaObject()->indexOfProperty("configuration");
if (metaconfigindex >=0 ){
configuration = qobject_cast<KDeclarative::ConfigPropertyMap *>((subcai->property("configuration")).value<QObject *>());
configuration = qobject_cast<Latte::Legacy::ConfigPropertyMap *>((subcai->property("configuration")).value<QObject *>());
}
}
}
@ -993,8 +994,8 @@ void ContainmentInterface::onAppletAdded(Plasma::Applet *applet)
}
}
} else if (ai) {
KPluginMetaData meta = applet->kPackage().metadata();
const auto &provides = KPluginMetaData::readStringList(meta.rawData(), QStringLiteral("X-Plasma-Provides"));
KPluginMetaData meta = applet->pluginMetaData();
const QStringList& provides = meta.value(QStringLiteral("X-Plasma-Provides"), QStringList{});
if (meta.pluginId() == QLatin1String("org.kde.latte.plasmoid")) {
//! populate latte tasks applet
@ -1016,7 +1017,7 @@ void ContainmentInterface::onAppletAdded(Plasma::Applet *applet)
if (ai) {
bool initializing{!m_appletData.contains(currentAppletId)};
KPluginMetaData meta = applet->kPackage().metadata();
KPluginMetaData meta = applet->pluginMetaData();
ViewPart::AppletInterfaceData data;
data.id = currentAppletId;
data.plugin = meta.pluginId();

View File

@ -18,6 +18,9 @@
#include <QTimer>
#include <QUrl>
// Legacy
#include <configpropertymap.h>
namespace Plasma {
class Applet;
}
@ -26,10 +29,6 @@ namespace PlasmaQuick {
class AppletQuickItem;
}
namespace KDeclarative {
class ConfigPropertyMap;
}
namespace Latte {
class Corona;
class View;
@ -45,7 +44,7 @@ struct AppletInterfaceData
int lastValidIndex{-1};
Plasma::Applet *applet{nullptr};
PlasmaQuick::AppletQuickItem *plasmoid{nullptr};
KDeclarative::ConfigPropertyMap *configuration{nullptr};
Latte::Legacy::ConfigPropertyMap *configuration{nullptr};
};
class ContainmentInterface: public QObject
@ -170,11 +169,11 @@ private slots:
private:
void addExpandedApplet(PlasmaQuick::AppletQuickItem * appletQuickItem);
void removeExpandedApplet(PlasmaQuick::AppletQuickItem *appletQuickItem);
void initAppletConfigurationSignals(const int &id, KDeclarative::ConfigPropertyMap *configuration);
void initAppletConfigurationSignals(const int &id, Latte::Legacy::ConfigPropertyMap *configuration);
bool appletIsExpandable(PlasmaQuick::AppletQuickItem *appletQuickItem) const;
KDeclarative::ConfigPropertyMap *appletConfiguration(const Plasma::Applet *applet);
Latte::Legacy::ConfigPropertyMap *appletConfiguration(const Plasma::Applet *applet);
QList<int> toIntList(const QVariantList &list);
@ -201,7 +200,7 @@ private:
//!follow containment plasmoid
QPointer<QObject> m_plasmoid;
QPointer<QObject> m_layoutManager;
QPointer<KDeclarative::ConfigPropertyMap> m_configuration;
QPointer<Latte::Legacy::ConfigPropertyMap> m_configuration;
//!keep record of applet ids and avoid crashes when trying to access ids for already destroyed applets
QHash<PlasmaQuick::AppletQuickItem *, int> m_expandedAppletIds;

View File

@ -358,13 +358,13 @@ QSGNode *IconItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *update
return nullptr;
}
ManagedTextureNode *textureNode = dynamic_cast<ManagedTextureNode *>(oldNode);
Latte::Legacy::ManagedTextureNode *textureNode = dynamic_cast<Latte::Legacy::ManagedTextureNode *>(oldNode);
if (!textureNode || m_textureChanged) {
if (oldNode)
delete oldNode;
textureNode = new ManagedTextureNode;
textureNode = new Latte::Legacy::ManagedTextureNode;
textureNode->setTexture(QSharedPointer<QSGTexture>(window()->createTextureFromImage(m_iconPixmap.toImage(), QQuickWindow::TextureCanUseAtlas)));
textureNode->setFiltering(smooth() ? QSGTexture::Linear : QSGTexture::Nearest);

View File

@ -6,6 +6,9 @@
#include "ManagedTextureNode.h"
namespace Latte {
namespace Legacy {
ManagedTextureNode::ManagedTextureNode()
{
}
@ -15,3 +18,6 @@ void ManagedTextureNode::setTexture(QSharedPointer<QSGTexture> texture)
m_texture = texture;
QSGSimpleTextureNode::setTexture(texture.data());
}
}
}

View File

@ -17,6 +17,9 @@
// I promise I will get rid of it.
// - L.B.
namespace Latte {
namespace Legacy {
/**
* @class ManagedTextureNode managedtexturenode.h KQuickAddons/ManagedTextureNode
*
@ -45,4 +48,7 @@ private:
QSharedPointer<QSGTexture> m_texture;
};
}
}
#endif

View File

@ -0,0 +1,160 @@
/*
SPDX-FileCopyrightText: 2013 Marco Martin <notmart@gmail.com>
SPDX-FileCopyrightText: 2020 David Edmundson <davidedmundson@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "configpropertymap.h"
#include <KCoreConfigSkeleton>
#include <QJSValue>
#include <QPointer>
namespace Latte {
namespace Legacy {
class ConfigPropertyMapPrivate
{
public:
ConfigPropertyMapPrivate(ConfigPropertyMap *map)
: q(map)
{
}
enum LoadConfigOption {
DontEmitValueChanged,
EmitValueChanged,
};
void loadConfig(LoadConfigOption option);
void writeConfig();
void writeConfigValue(const QString &key, const QVariant &value);
ConfigPropertyMap *q;
QPointer<KCoreConfigSkeleton> config;
bool updatingConfigValue = false;
bool autosave = true;
bool notify = false;
};
ConfigPropertyMap::ConfigPropertyMap(KCoreConfigSkeleton *config, QObject *parent)
: QQmlPropertyMap(this, parent)
, d(new ConfigPropertyMapPrivate(this))
{
d->config = config;
// Reload the config only if the change signal has *not* been emitted by ourselves updating the config
connect(config, &KCoreConfigSkeleton::configChanged, this, [this]() {
if (!d->updatingConfigValue) {
d->loadConfig(ConfigPropertyMapPrivate::EmitValueChanged);
}
});
connect(this, &ConfigPropertyMap::valueChanged, this, [this](const QString &key, const QVariant &value) {
d->writeConfigValue(key, value);
});
d->loadConfig(ConfigPropertyMapPrivate::DontEmitValueChanged);
}
ConfigPropertyMap::~ConfigPropertyMap()
{
if (d->autosave) {
d->writeConfig();
}
delete d;
}
bool ConfigPropertyMap::isAutosave() const
{
return d->autosave;
}
void ConfigPropertyMap::setAutosave(bool autosave)
{
d->autosave = autosave;
}
bool ConfigPropertyMap::isNotify() const
{
return d->notify;
}
void ConfigPropertyMap::setNotify(bool notify)
{
d->notify = notify;
}
QVariant ConfigPropertyMap::updateValue(const QString &key, const QVariant &input)
{
Q_UNUSED(key);
if (input.userType() == qMetaTypeId<QJSValue>()) {
return input.value<QJSValue>().toVariant();
}
return input;
}
bool ConfigPropertyMap::isImmutable(const QString &key) const
{
KConfigSkeletonItem *item = d->config.data()->findItem(key);
if (item) {
return item->isImmutable();
}
return false;
}
void ConfigPropertyMapPrivate::loadConfig(ConfigPropertyMapPrivate::LoadConfigOption option)
{
if (!config) {
return;
}
const auto &items = config.data()->items();
for (KConfigSkeletonItem *item : items) {
q->insert(item->key() + QStringLiteral("Default"), item->getDefault());
q->insert(item->key(), item->property());
if (option == EmitValueChanged) {
Q_EMIT q->valueChanged(item->key(), item->property());
}
}
}
void ConfigPropertyMapPrivate::writeConfig()
{
if (!config) {
return;
}
const auto lstItems = config.data()->items();
for (KConfigSkeletonItem *item : lstItems) {
item->setWriteFlags(notify ? KConfigBase::Notify : KConfigBase::Normal);
item->setProperty(q->value(item->key()));
}
if (autosave) {
updatingConfigValue = true;
config.data()->save();
updatingConfigValue = false;
}
}
void ConfigPropertyMapPrivate::writeConfigValue(const QString &key, const QVariant &value)
{
KConfigSkeletonItem *item = config.data()->findItem(key);
if (item) {
updatingConfigValue = true;
item->setWriteFlags(notify ? KConfigBase::Notify : KConfigBase::Normal);
item->setProperty(value);
if (autosave) {
config.data()->save();
// why read? read will update KConfigSkeletonItem::mLoadedValue,
// allowing a write operation to be performed next time
config.data()->read();
}
updatingConfigValue = false;
}
}
}
}

View File

@ -0,0 +1,85 @@
/*
SPDX-FileCopyrightText: 2013 Marco Martin <notmart@gmail.com>
SPDX-FileCopyrightText: 2020 David Edmundson <davidedmundson@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef CONFIGPROPERTYMAP_H
#define CONFIGPROPERTYMAP_H
#include <QQmlPropertyMap>
class KCoreConfigSkeleton;
namespace Latte {
namespace Legacy {
class ConfigPropertyMapPrivate;
/**
* @class KDeclarative::ConfigPropertyMap configpropertymap.h KDeclarative/ConfigPropertyMap
*
* An object that (optionally) automatically saves changes in a
* property map to a configuration object (e.g. a KConfig file).
* @deprecated Since 5.91, use KConfigPropertyMap from KConfig KConfigQml module instead.
* The replacement class does not provide any autosave behavior, instead it requires
* an explicit writeConfig call.
*/
class ConfigPropertyMap : public QQmlPropertyMap
{
Q_OBJECT
public:
ConfigPropertyMap(KCoreConfigSkeleton *config, QObject *parent = nullptr);
~ConfigPropertyMap() override;
/**
* Indicates if the map calls save() on the config object on each write or not
*
* @return true if the map automatically saves (the default), false otherwise
* @since 5.65
*/
bool isAutosave() const;
/**
* Allows to set the map into autosave mode or not
*
* @param autosave the new value for autosaving
* @since 5.65
*/
void setAutosave(bool autosave);
/**
* Whether notifications on config changes are enabled. Disabled by default.
* @see KConfigBase::Notify
* @return true if writes send (dbus) notifications
* @since 5.73
*/
bool isNotify() const;
/**
* Enable or disable notifications on config changes.
* @see KConfigBase::Notify
* @param notify whether to send notifications
* @since 5.73
*/
void setNotify(bool notify);
/**
* @brief Whether the value at the given key is immutable
*
* @return true if the value is immutable, false if it isn't or it doesn't exist
*/
Q_INVOKABLE bool isImmutable(const QString &key) const;
protected:
QVariant updateValue(const QString &key, const QVariant &input) override;
private:
ConfigPropertyMapPrivate *const d;
};
}
}
#endif