From 591aceb3f9265d1abcb82072d61f682368f90589 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Sun, 12 Jan 2020 02:28:31 +0100 Subject: [PATCH] Make use of KPluginMetaData where we can Summary: Instead of relying on the older KPluginInfo which is slower (parses de metadata twice) and comes from a much higher tier. Test Plan: Running plasmashell with it Reviewers: #plasma, mart Reviewed By: #plasma, mart Subscribers: kossebau, broulik, kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D23682 --- src/plasma/CMakeLists.txt | 2 +- src/plasma/containment.cpp | 2 +- src/plasma/containmentactions.cpp | 5 +++++ src/plasma/containmentactions.h | 13 +++++++++++ src/plasma/dataengine.cpp | 19 +++++++++++----- src/plasma/dataengine.h | 27 +++++++++++++++++++++++ src/plasma/private/dataengine_p.h | 6 ++--- src/plasma/private/storage.cpp | 2 +- src/plasma/private/theme_p.cpp | 2 +- src/plasma/private/theme_p.h | 3 ++- src/plasma/scripting/dataenginescript.cpp | 7 +++++- src/plasma/scripting/dataenginescript.h | 14 +++++++++++- src/plasma/theme.cpp | 2 +- src/plasma/theme.h | 14 ++++++++++++ 14 files changed, 102 insertions(+), 16 deletions(-) diff --git a/src/plasma/CMakeLists.txt b/src/plasma/CMakeLists.txt index 41edf273f..98b2e1b98 100644 --- a/src/plasma/CMakeLists.txt +++ b/src/plasma/CMakeLists.txt @@ -93,7 +93,7 @@ ecm_generate_export_header(KF5Plasma GROUP_BASE_NAME KF VERSION ${KF5_VERSION} DEPRECATED_BASE_VERSION 0 - DEPRECATION_VERSIONS 5.6 5.19 5.28 5.30 5.36 5.46 + DEPRECATION_VERSIONS 5.6 5.19 5.28 5.30 5.36 5.46 5.67 ) # TODO: add support for EXCLUDE_DEPRECATED_BEFORE_AND_AT to all Plasma libs # needs fixing of undeprecated API being still implemented using own deprecated API diff --git a/src/plasma/containment.cpp b/src/plasma/containment.cpp index 955c606e7..8557d27ba 100644 --- a/src/plasma/containment.cpp +++ b/src/plasma/containment.cpp @@ -522,7 +522,7 @@ void Containment::setContainmentActions(const QString &trigger, const QString &p ContainmentActions *plugin = nullptr; plugin = containmentActions().value(trigger); - if (plugin && plugin->pluginInfo().pluginName() != pluginName) { + if (plugin && plugin->metadata().pluginId() != pluginName) { containmentActions().remove(trigger); delete plugin; plugin = nullptr; diff --git a/src/plasma/containmentactions.cpp b/src/plasma/containmentactions.cpp index a80331cbe..468fe01a5 100644 --- a/src/plasma/containmentactions.cpp +++ b/src/plasma/containmentactions.cpp @@ -66,6 +66,11 @@ KPluginInfo ContainmentActions::pluginInfo() const return KPluginInfo(d->containmentActionsDescription); } +KPluginMetaData ContainmentActions::metadata() const +{ + return d->containmentActionsDescription; +} + Containment *ContainmentActions::containment() { if (d->containment) { diff --git a/src/plasma/containmentactions.h b/src/plasma/containmentactions.h index 61a4c7b52..e331992e5 100644 --- a/src/plasma/containmentactions.h +++ b/src/plasma/containmentactions.h @@ -28,6 +28,7 @@ #include class QAction; +class KPluginMetaData; namespace Plasma { @@ -63,12 +64,24 @@ public: ~ContainmentActions(); +#if PLASMA_ENABLE_DEPRECATED_SINCE(5, 64) /** * @return the plugin info for this ContainmentActions instance, * including name, pluginName and icon * @since 5.0 + * + * @deprecated since 5.67, use metadata */ + PLASMA_DEPRECATED_VERSION(5, 67, "use metadata()") KPluginInfo pluginInfo() const; +#endif + + /** + * @return metadata for this ContainmentActions instance + * including name, pluginName and icon + * @since 5.62 + */ + KPluginMetaData metadata() const; /** * This method should be called once the plugin is loaded or settings are changed. diff --git a/src/plasma/dataengine.cpp b/src/plasma/dataengine.cpp index ee86354b3..310bfae23 100644 --- a/src/plasma/dataengine.cpp +++ b/src/plasma/dataengine.cpp @@ -49,6 +49,10 @@ namespace Plasma { DataEngine::DataEngine(const KPluginInfo &plugin, QObject *parent) + : DataEngine(plugin.toMetaData(), parent) +{} + +DataEngine::DataEngine(const KPluginMetaData &plugin, QObject *parent) : QObject(parent), d(new DataEnginePrivate(this, plugin)) { @@ -63,7 +67,7 @@ DataEngine::DataEngine(const KPluginInfo &plugin, QObject *parent) DataEngine::DataEngine(QObject *parent, const QVariantList &args) : QObject(parent), - d(new DataEnginePrivate(this, KPluginInfo(args), args)) + d(new DataEnginePrivate(this, KPluginInfo(args).toMetaData(), args)) { if (d->script) { d->setupScriptSupport(); @@ -99,6 +103,11 @@ Service *DataEngine::serviceForSource(const QString &source) } KPluginInfo DataEngine::pluginInfo() const +{ + return KPluginInfo(d->dataEngineDescription); +} + +KPluginMetaData DataEngine::metadata() const { return d->dataEngineDescription; } @@ -408,9 +417,9 @@ void DataEngine::setStorageEnabled(const QString &source, bool store) } // Private class implementations -DataEnginePrivate::DataEnginePrivate(DataEngine *e, const KPluginInfo &info, const QVariantList &args) +DataEnginePrivate::DataEnginePrivate(DataEngine *e, const KPluginMetaData &md, const QVariantList &args) : q(e), - dataEngineDescription(info), + dataEngineDescription(md), refCount(-1), // first ref checkSourcesTimerId(0), updateTimerId(0), @@ -427,12 +436,12 @@ DataEnginePrivate::DataEnginePrivate(DataEngine *e, const KPluginInfo &info, con } if (dataEngineDescription.isValid()) { - QString api = dataEngineDescription.property(QStringLiteral("X-Plasma-API")).toString(); + QString api = dataEngineDescription.value(QStringLiteral("X-Plasma-API")); if (!api.isEmpty()) { const QString path = QStandardPaths::locate(QStandardPaths::GenericDataLocation, - QStringLiteral(PLASMA_RELATIVE_DATA_INSTALL_DIR "/dataengines/") + dataEngineDescription.pluginName(), + QStringLiteral(PLASMA_RELATIVE_DATA_INSTALL_DIR "/dataengines/") + dataEngineDescription.pluginId(), QStandardPaths::LocateDirectory); package = new Package(PluginLoader::self()->loadPackage(QStringLiteral("Plasma/DataEngine"), api)); package->setPath(path); diff --git a/src/plasma/dataengine.h b/src/plasma/dataengine.h index cc1f42a4d..d7db23478 100644 --- a/src/plasma/dataengine.h +++ b/src/plasma/dataengine.h @@ -67,13 +67,28 @@ public: typedef QMapIterator DataIterator; typedef QHash SourceDict; +#if PLASMA_ENABLE_DEPRECATED_SINCE(5, 64) /** * Constructor. * * @param parent The parent object. * @param plugin plugin info that describes the engine + * + * @deprecated since 5.67 **/ + PLASMA_DEPRECATED_VERSION(5, 67, "Use KPluginMetaData") explicit DataEngine(const KPluginInfo &plugin, QObject *parent = nullptr); +#endif + + /** + * Constructor. + * + * @param parent The parent object. + * @param plugin metadata that describes the engine + * + * @since 5.62 + */ + explicit DataEngine(const KPluginMetaData &plugin, QObject *parent = nullptr); explicit DataEngine(QObject *parent = nullptr, const QVariantList &args = QVariantList()); @@ -95,10 +110,22 @@ public: */ Q_INVOKABLE virtual Service *serviceForSource(const QString &source); +#if PLASMA_ENABLE_DEPRECATED_SINCE(5, 64) /** * @return description of the plugin that implements this DataEngine + * + * @deprecated since 5.67, use metadata */ + PLASMA_DEPRECATED_VERSION(5, 67, "Use metadata()") KPluginInfo pluginInfo() const; +#endif + + /** + * @return description of the plugin that implements this DataEngine + * + * @since 5.62 + */ + KPluginMetaData metadata() const; /** * Connects a source to an object for data updates. The object must diff --git a/src/plasma/private/dataengine_p.h b/src/plasma/private/dataengine_p.h index 9a4b22700..5394b405a 100644 --- a/src/plasma/private/dataengine_p.h +++ b/src/plasma/private/dataengine_p.h @@ -22,7 +22,7 @@ #include -#include +#include namespace Plasma { @@ -32,7 +32,7 @@ class Service; class DataEnginePrivate { public: - DataEnginePrivate(DataEngine *e, const KPluginInfo &info, const QVariantList &args = QVariantList()); + DataEnginePrivate(DataEngine *e, const KPluginMetaData &info, const QVariantList &args = QVariantList()); ~DataEnginePrivate(); DataContainer *source(const QString &sourceName, bool createWhenMissing = true); void connectSource(DataContainer *s, QObject *visualization, uint pollingInterval, @@ -90,7 +90,7 @@ public: void scheduleSourcesUpdated(); DataEngine *q; - KPluginInfo dataEngineDescription; + KPluginMetaData dataEngineDescription; int refCount; int checkSourcesTimerId; int updateTimerId; diff --git a/src/plasma/private/storage.cpp b/src/plasma/private/storage.cpp index 6d4c5c41d..06c1e82d6 100644 --- a/src/plasma/private/storage.cpp +++ b/src/plasma/private/storage.cpp @@ -131,7 +131,7 @@ Storage::Storage(QObject *parent) Plasma::DataEngine *engine = qobject_cast(parentObject); if (engine) { - m_clientName = engine->pluginInfo().pluginName(); + m_clientName = engine->metadata().pluginId(); break; } } diff --git a/src/plasma/private/theme_p.cpp b/src/plasma/private/theme_p.cpp index 804d1662a..b0731c8f3 100644 --- a/src/plasma/private/theme_p.cpp +++ b/src/plasma/private/theme_p.cpp @@ -809,7 +809,7 @@ void ThemePrivate::setThemeName(const QString &tempThemeName, bool writeSettings if (realTheme) { const QString metadataPath(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String(PLASMA_RELATIVE_DATA_INSTALL_DIR "/desktoptheme/") % theme % QLatin1String("/metadata.desktop"))); KConfig metadata(metadataPath, KConfig::SimpleConfig); - pluginInfo = KPluginInfo(metadataPath); + pluginMetaData = KPluginMetaData(metadataPath); processContrastSettings(&metadata); processBlurBehindSettings(&metadata); diff --git a/src/plasma/private/theme_p.h b/src/plasma/private/theme_p.h index 8f1676549..088053214 100644 --- a/src/plasma/private/theme_p.h +++ b/src/plasma/private/theme_p.h @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -110,7 +111,7 @@ public: static QHash themes; QString themeName; - KPluginInfo pluginInfo; + KPluginMetaData pluginMetaData; QList fallbackThemes; KSharedConfigPtr colors; KColorScheme colorScheme; diff --git a/src/plasma/scripting/dataenginescript.cpp b/src/plasma/scripting/dataenginescript.cpp index bf3013c07..ae97dd1b4 100644 --- a/src/plasma/scripting/dataenginescript.cpp +++ b/src/plasma/scripting/dataenginescript.cpp @@ -89,9 +89,14 @@ Package DataEngineScript::package() const } KPluginInfo DataEngineScript::description() const +{ + return KPluginInfo(metadata()); +} + +KPluginMetaData DataEngineScript::metadata() const { Q_ASSERT(d->dataEngine); - return d->dataEngine->d->dataEngineDescription; + return d->dataEngine->metadata(); } void DataEngineScript::setData(const QString &source, const QString &key, diff --git a/src/plasma/scripting/dataenginescript.h b/src/plasma/scripting/dataenginescript.h index aadcc3d3a..903066c3d 100644 --- a/src/plasma/scripting/dataenginescript.h +++ b/src/plasma/scripting/dataenginescript.h @@ -110,10 +110,22 @@ protected: */ Package package() const override; +#if PLASMA_ENABLE_DEPRECATED_SINCE(5, 67) /** - * @return the KPluginInfo associated with this plasmoid + * @return the KPluginInfo associated with this dataengine + * + * @deprecated since 5.67 use metadata() */ + PLASMA_DEPRECATED_VERSION(5, 67, "Use KPluginMetaData metadata()") KPluginInfo description() const; +#endif + + /** + * @return the KPluginMetaData associated with this dataengine + * + * @since 5.62 + */ + KPluginMetaData metadata() const; void setData(const QString &source, const QString &key, const QVariant &value); diff --git a/src/plasma/theme.cpp b/src/plasma/theme.cpp index 58bb7a15d..d581d5ab0 100644 --- a/src/plasma/theme.cpp +++ b/src/plasma/theme.cpp @@ -443,7 +443,7 @@ void Theme::setCacheLimit(int kbytes) KPluginInfo Theme::pluginInfo() const { - return d->pluginInfo; + return KPluginInfo(d->pluginMetaData); } QFont Theme::defaultFont() const diff --git a/src/plasma/theme.h b/src/plasma/theme.h index c65b8094d..80327281d 100644 --- a/src/plasma/theme.h +++ b/src/plasma/theme.h @@ -30,6 +30,8 @@ #include +class KPluginMetaData; + namespace Plasma { @@ -314,12 +316,24 @@ public: */ void releaseRectsCache(const QString &image); +#if PLASMA_ENABLE_DEPRECATED_SINCE(5, 64) /** * @return plugin info for this theme, with information such as * name, description, author, website etc * @since 5.0 + * + * @deprecated since 5.67, use KPluginMetaData */ + PLASMA_DEPRECATED_VERSION(5, 67, "Use KPluginMetaData metadata()") KPluginInfo pluginInfo() const; +#endif + + /** + * @return metadata for this theme, with information such as + * name, description, author, website etc + * @since 5.64 + */ + KPluginMetaData metadata() const; /** * @return The default application font