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
This commit is contained in:
Aleix Pol 2020-01-12 02:28:31 +01:00
parent e5b1475e14
commit 591aceb3f9
14 changed files with 102 additions and 16 deletions

View File

@ -93,7 +93,7 @@ ecm_generate_export_header(KF5Plasma
GROUP_BASE_NAME KF GROUP_BASE_NAME KF
VERSION ${KF5_VERSION} VERSION ${KF5_VERSION}
DEPRECATED_BASE_VERSION 0 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 # 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 # needs fixing of undeprecated API being still implemented using own deprecated API

View File

@ -522,7 +522,7 @@ void Containment::setContainmentActions(const QString &trigger, const QString &p
ContainmentActions *plugin = nullptr; ContainmentActions *plugin = nullptr;
plugin = containmentActions().value(trigger); plugin = containmentActions().value(trigger);
if (plugin && plugin->pluginInfo().pluginName() != pluginName) { if (plugin && plugin->metadata().pluginId() != pluginName) {
containmentActions().remove(trigger); containmentActions().remove(trigger);
delete plugin; delete plugin;
plugin = nullptr; plugin = nullptr;

View File

@ -66,6 +66,11 @@ KPluginInfo ContainmentActions::pluginInfo() const
return KPluginInfo(d->containmentActionsDescription); return KPluginInfo(d->containmentActionsDescription);
} }
KPluginMetaData ContainmentActions::metadata() const
{
return d->containmentActionsDescription;
}
Containment *ContainmentActions::containment() Containment *ContainmentActions::containment()
{ {
if (d->containment) { if (d->containment) {

View File

@ -28,6 +28,7 @@
#include <plasma/version.h> #include <plasma/version.h>
class QAction; class QAction;
class KPluginMetaData;
namespace Plasma namespace Plasma
{ {
@ -63,12 +64,24 @@ public:
~ContainmentActions(); ~ContainmentActions();
#if PLASMA_ENABLE_DEPRECATED_SINCE(5, 64)
/** /**
* @return the plugin info for this ContainmentActions instance, * @return the plugin info for this ContainmentActions instance,
* including name, pluginName and icon * including name, pluginName and icon
* @since 5.0 * @since 5.0
*
* @deprecated since 5.67, use metadata
*/ */
PLASMA_DEPRECATED_VERSION(5, 67, "use metadata()")
KPluginInfo pluginInfo() const; 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. * This method should be called once the plugin is loaded or settings are changed.

View File

@ -49,6 +49,10 @@ namespace Plasma
{ {
DataEngine::DataEngine(const KPluginInfo &plugin, QObject *parent) DataEngine::DataEngine(const KPluginInfo &plugin, QObject *parent)
: DataEngine(plugin.toMetaData(), parent)
{}
DataEngine::DataEngine(const KPluginMetaData &plugin, QObject *parent)
: QObject(parent), : QObject(parent),
d(new DataEnginePrivate(this, plugin)) d(new DataEnginePrivate(this, plugin))
{ {
@ -63,7 +67,7 @@ DataEngine::DataEngine(const KPluginInfo &plugin, QObject *parent)
DataEngine::DataEngine(QObject *parent, const QVariantList &args) DataEngine::DataEngine(QObject *parent, const QVariantList &args)
: QObject(parent), : QObject(parent),
d(new DataEnginePrivate(this, KPluginInfo(args), args)) d(new DataEnginePrivate(this, KPluginInfo(args).toMetaData(), args))
{ {
if (d->script) { if (d->script) {
d->setupScriptSupport(); d->setupScriptSupport();
@ -99,6 +103,11 @@ Service *DataEngine::serviceForSource(const QString &source)
} }
KPluginInfo DataEngine::pluginInfo() const KPluginInfo DataEngine::pluginInfo() const
{
return KPluginInfo(d->dataEngineDescription);
}
KPluginMetaData DataEngine::metadata() const
{ {
return d->dataEngineDescription; return d->dataEngineDescription;
} }
@ -408,9 +417,9 @@ void DataEngine::setStorageEnabled(const QString &source, bool store)
} }
// Private class implementations // 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), : q(e),
dataEngineDescription(info), dataEngineDescription(md),
refCount(-1), // first ref refCount(-1), // first ref
checkSourcesTimerId(0), checkSourcesTimerId(0),
updateTimerId(0), updateTimerId(0),
@ -427,12 +436,12 @@ DataEnginePrivate::DataEnginePrivate(DataEngine *e, const KPluginInfo &info, con
} }
if (dataEngineDescription.isValid()) { if (dataEngineDescription.isValid()) {
QString api = dataEngineDescription.property(QStringLiteral("X-Plasma-API")).toString(); QString api = dataEngineDescription.value(QStringLiteral("X-Plasma-API"));
if (!api.isEmpty()) { if (!api.isEmpty()) {
const QString path = const QString path =
QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStandardPaths::locate(QStandardPaths::GenericDataLocation,
QStringLiteral(PLASMA_RELATIVE_DATA_INSTALL_DIR "/dataengines/") + dataEngineDescription.pluginName(), QStringLiteral(PLASMA_RELATIVE_DATA_INSTALL_DIR "/dataengines/") + dataEngineDescription.pluginId(),
QStandardPaths::LocateDirectory); QStandardPaths::LocateDirectory);
package = new Package(PluginLoader::self()->loadPackage(QStringLiteral("Plasma/DataEngine"), api)); package = new Package(PluginLoader::self()->loadPackage(QStringLiteral("Plasma/DataEngine"), api));
package->setPath(path); package->setPath(path);

View File

@ -67,13 +67,28 @@ public:
typedef QMapIterator<QString, QVariant> DataIterator; typedef QMapIterator<QString, QVariant> DataIterator;
typedef QHash<QString, DataContainer *> SourceDict; typedef QHash<QString, DataContainer *> SourceDict;
#if PLASMA_ENABLE_DEPRECATED_SINCE(5, 64)
/** /**
* Constructor. * Constructor.
* *
* @param parent The parent object. * @param parent The parent object.
* @param plugin plugin info that describes the engine * @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); 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()); explicit DataEngine(QObject *parent = nullptr, const QVariantList &args = QVariantList());
@ -95,10 +110,22 @@ public:
*/ */
Q_INVOKABLE virtual Service *serviceForSource(const QString &source); Q_INVOKABLE virtual Service *serviceForSource(const QString &source);
#if PLASMA_ENABLE_DEPRECATED_SINCE(5, 64)
/** /**
* @return description of the plugin that implements this DataEngine * @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; 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 * Connects a source to an object for data updates. The object must

View File

@ -22,7 +22,7 @@
#include <QElapsedTimer> #include <QElapsedTimer>
#include <kplugininfo.h> #include <KPluginMetaData>
namespace Plasma namespace Plasma
{ {
@ -32,7 +32,7 @@ class Service;
class DataEnginePrivate class DataEnginePrivate
{ {
public: public:
DataEnginePrivate(DataEngine *e, const KPluginInfo &info, const QVariantList &args = QVariantList()); DataEnginePrivate(DataEngine *e, const KPluginMetaData &info, const QVariantList &args = QVariantList());
~DataEnginePrivate(); ~DataEnginePrivate();
DataContainer *source(const QString &sourceName, bool createWhenMissing = true); DataContainer *source(const QString &sourceName, bool createWhenMissing = true);
void connectSource(DataContainer *s, QObject *visualization, uint pollingInterval, void connectSource(DataContainer *s, QObject *visualization, uint pollingInterval,
@ -90,7 +90,7 @@ public:
void scheduleSourcesUpdated(); void scheduleSourcesUpdated();
DataEngine *q; DataEngine *q;
KPluginInfo dataEngineDescription; KPluginMetaData dataEngineDescription;
int refCount; int refCount;
int checkSourcesTimerId; int checkSourcesTimerId;
int updateTimerId; int updateTimerId;

View File

@ -131,7 +131,7 @@ Storage::Storage(QObject *parent)
Plasma::DataEngine *engine = qobject_cast<Plasma::DataEngine *>(parentObject); Plasma::DataEngine *engine = qobject_cast<Plasma::DataEngine *>(parentObject);
if (engine) { if (engine) {
m_clientName = engine->pluginInfo().pluginName(); m_clientName = engine->metadata().pluginId();
break; break;
} }
} }

View File

@ -809,7 +809,7 @@ void ThemePrivate::setThemeName(const QString &tempThemeName, bool writeSettings
if (realTheme) { if (realTheme) {
const QString metadataPath(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String(PLASMA_RELATIVE_DATA_INSTALL_DIR "/desktoptheme/") % theme % QLatin1String("/metadata.desktop"))); const QString metadataPath(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QLatin1String(PLASMA_RELATIVE_DATA_INSTALL_DIR "/desktoptheme/") % theme % QLatin1String("/metadata.desktop")));
KConfig metadata(metadataPath, KConfig::SimpleConfig); KConfig metadata(metadataPath, KConfig::SimpleConfig);
pluginInfo = KPluginInfo(metadataPath); pluginMetaData = KPluginMetaData(metadataPath);
processContrastSettings(&metadata); processContrastSettings(&metadata);
processBlurBehindSettings(&metadata); processBlurBehindSettings(&metadata);

View File

@ -30,6 +30,7 @@
#include <kimagecache.h> #include <kimagecache.h>
#include <kshareddatacache.h> #include <kshareddatacache.h>
#include <kwindowsystem.h> #include <kwindowsystem.h>
#include <KPluginMetaData>
#include <QTimer> #include <QTimer>
#include <config-plasma.h> #include <config-plasma.h>
@ -110,7 +111,7 @@ public:
static QHash<QString, ThemePrivate *> themes; static QHash<QString, ThemePrivate *> themes;
QString themeName; QString themeName;
KPluginInfo pluginInfo; KPluginMetaData pluginMetaData;
QList<QString> fallbackThemes; QList<QString> fallbackThemes;
KSharedConfigPtr colors; KSharedConfigPtr colors;
KColorScheme colorScheme; KColorScheme colorScheme;

View File

@ -89,9 +89,14 @@ Package DataEngineScript::package() const
} }
KPluginInfo DataEngineScript::description() const KPluginInfo DataEngineScript::description() const
{
return KPluginInfo(metadata());
}
KPluginMetaData DataEngineScript::metadata() const
{ {
Q_ASSERT(d->dataEngine); Q_ASSERT(d->dataEngine);
return d->dataEngine->d->dataEngineDescription; return d->dataEngine->metadata();
} }
void DataEngineScript::setData(const QString &source, const QString &key, void DataEngineScript::setData(const QString &source, const QString &key,

View File

@ -110,10 +110,22 @@ protected:
*/ */
Package package() const override; 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; 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, void setData(const QString &source, const QString &key,
const QVariant &value); const QVariant &value);

View File

@ -443,7 +443,7 @@ void Theme::setCacheLimit(int kbytes)
KPluginInfo Theme::pluginInfo() const KPluginInfo Theme::pluginInfo() const
{ {
return d->pluginInfo; return KPluginInfo(d->pluginMetaData);
} }
QFont Theme::defaultFont() const QFont Theme::defaultFont() const

View File

@ -30,6 +30,8 @@
#include <plasma/plasma_export.h> #include <plasma/plasma_export.h>
class KPluginMetaData;
namespace Plasma namespace Plasma
{ {
@ -314,12 +316,24 @@ public:
*/ */
void releaseRectsCache(const QString &image); void releaseRectsCache(const QString &image);
#if PLASMA_ENABLE_DEPRECATED_SINCE(5, 64)
/** /**
* @return plugin info for this theme, with information such as * @return plugin info for this theme, with information such as
* name, description, author, website etc * name, description, author, website etc
* @since 5.0 * @since 5.0
*
* @deprecated since 5.67, use KPluginMetaData
*/ */
PLASMA_DEPRECATED_VERSION(5, 67, "Use KPluginMetaData metadata()")
KPluginInfo pluginInfo() const; 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 * @return The default application font