diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 408d908c6..09d33dbc5 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -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}) diff --git a/app/view/containmentinterface.cpp b/app/view/containmentinterface.cpp index 00f28bb13..6c507cedf 100644 --- a/app/view/containmentinterface.cpp +++ b/app/view/containmentinterface.cpp @@ -27,7 +27,6 @@ #include #include #include -#include 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()) { @@ -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()) { @@ -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(m_plasmoid->property("configuration").value()); + m_configuration = qobject_cast(m_plasmoid->property("configuration").value()); 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(); 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((ai->property("configuration")).value()); + configuration = qobject_cast((ai->property("configuration")).value()); } } 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((subcai->property("configuration")).value()); + configuration = qobject_cast((subcai->property("configuration")).value()); } } } @@ -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(); diff --git a/app/view/containmentinterface.h b/app/view/containmentinterface.h index ee020e001..3cf5bf6fa 100644 --- a/app/view/containmentinterface.h +++ b/app/view/containmentinterface.h @@ -18,6 +18,9 @@ #include #include +// Legacy +#include + 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 toIntList(const QVariantList &list); @@ -201,7 +200,7 @@ private: //!follow containment plasmoid QPointer m_plasmoid; QPointer m_layoutManager; - QPointer m_configuration; + QPointer m_configuration; //!keep record of applet ids and avoid crashes when trying to access ids for already destroyed applets QHash m_expandedAppletIds; diff --git a/declarativeimports/core/iconitem.cpp b/declarativeimports/core/iconitem.cpp index 3dd64cbb7..d182c0ba0 100644 --- a/declarativeimports/core/iconitem.cpp +++ b/declarativeimports/core/iconitem.cpp @@ -358,13 +358,13 @@ QSGNode *IconItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *update return nullptr; } - ManagedTextureNode *textureNode = dynamic_cast(oldNode); + Latte::Legacy::ManagedTextureNode *textureNode = dynamic_cast(oldNode); if (!textureNode || m_textureChanged) { if (oldNode) delete oldNode; - textureNode = new ManagedTextureNode; + textureNode = new Latte::Legacy::ManagedTextureNode; textureNode->setTexture(QSharedPointer(window()->createTextureFromImage(m_iconPixmap.toImage(), QQuickWindow::TextureCanUseAtlas))); textureNode->setFiltering(smooth() ? QSGTexture::Linear : QSGTexture::Nearest); diff --git a/legacy/ManagedTextureNode.cpp b/legacy/ManagedTextureNode.cpp index 97bf2c61a..c1b3943ed 100644 --- a/legacy/ManagedTextureNode.cpp +++ b/legacy/ManagedTextureNode.cpp @@ -6,6 +6,9 @@ #include "ManagedTextureNode.h" +namespace Latte { +namespace Legacy { + ManagedTextureNode::ManagedTextureNode() { } @@ -15,3 +18,6 @@ void ManagedTextureNode::setTexture(QSharedPointer texture) m_texture = texture; QSGSimpleTextureNode::setTexture(texture.data()); } + +} +} diff --git a/legacy/ManagedTextureNode.h b/legacy/ManagedTextureNode.h index 969fb7611..64aa2e729 100644 --- a/legacy/ManagedTextureNode.h +++ b/legacy/ManagedTextureNode.h @@ -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 m_texture; }; +} +} + #endif diff --git a/legacy/configpropertymap.cpp b/legacy/configpropertymap.cpp new file mode 100644 index 000000000..2b6de3098 --- /dev/null +++ b/legacy/configpropertymap.cpp @@ -0,0 +1,160 @@ +/* + SPDX-FileCopyrightText: 2013 Marco Martin + SPDX-FileCopyrightText: 2020 David Edmundson + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ + +#include "configpropertymap.h" + +#include +#include +#include + +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 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()) { + return input.value().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; + } +} + +} +} diff --git a/legacy/configpropertymap.h b/legacy/configpropertymap.h new file mode 100644 index 000000000..5d4fee054 --- /dev/null +++ b/legacy/configpropertymap.h @@ -0,0 +1,85 @@ +/* + SPDX-FileCopyrightText: 2013 Marco Martin + SPDX-FileCopyrightText: 2020 David Edmundson + + SPDX-License-Identifier: LGPL-2.0-or-later +*/ + +#ifndef CONFIGPROPERTYMAP_H +#define CONFIGPROPERTYMAP_H + +#include + +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