Commit 694ab684 authored by Nicolas Fella's avatar Nicolas Fella

[widgetsexplorer] Port away from KPluginInfo

And use KPluginMetaData instead. It's what we get from the PackageLoader anyway.

Unlike KPluginInfo KPluginMetaData supports multiple authors. To keep the current behaviour of the model the code picks the first one and ignores the potential others.
parent 11405d77
......@@ -23,23 +23,23 @@
#include <QFileInfo>
#include <QMimeData>
#include <KAboutData>
#include <KLocalizedString>
#include <KServiceTypeTrader>
#include <KSycoca>
#include <KConfig>
#include "config-workspace.h"
#include <KPackage/PackageLoader>
#include <KDeclarative/KDeclarative>
PlasmaAppletItem::PlasmaAppletItem(const KPluginInfo& info):
PlasmaAppletItem::PlasmaAppletItem(const KPluginMetaData& info):
AbstractItem(),
m_info(info),
m_runningCount(0),
m_local(false)
{
const QString api(m_info.property(QStringLiteral("X-Plasma-API")).toString());
const QString api(m_info.value(QStringLiteral("X-Plasma-API")));
if (!api.isEmpty()) {
const QString _f = PLASMA_RELATIVE_DATA_INSTALL_DIR "/plasmoids/" + info.pluginName() + '/';
const QString _f = PLASMA_RELATIVE_DATA_INSTALL_DIR "/plasmoids/" + info.pluginId() + '/';
QFileInfo dir(QStandardPaths::locate(QStandardPaths::QStandardPaths::GenericDataLocation,
_f,
QStandardPaths::LocateDirectory));
......@@ -49,31 +49,31 @@ PlasmaAppletItem::PlasmaAppletItem(const KPluginInfo& info):
//attrs.insert("recommended", flags & Recommended ? true : false);
setText(m_info.name() + " - "+ m_info.category().toLower());
if (QIcon::hasThemeIcon(info.pluginName())) {
setIcon(QIcon::fromTheme(info.pluginName()));
} else if (!m_info.icon().isEmpty()) {
setIcon(QIcon::fromTheme(info.icon()));
if (QIcon::hasThemeIcon(info.pluginId())) {
setIcon(QIcon::fromTheme(info.pluginId()));
} else if (!m_info.iconName().isEmpty()) {
setIcon(QIcon::fromTheme(info.iconName()));
} else {
setIcon(QIcon::fromTheme(QStringLiteral("application-x-plasma")));
}
//set plugininfo parts as roles in the model, only way qml can understand it
setData(info.name(), PlasmaAppletItemModel::NameRole);
setData(info.pluginName(), PlasmaAppletItemModel::PluginNameRole);
setData(info.comment(), PlasmaAppletItemModel::DescriptionRole);
setData(info.category().toLower(), PlasmaAppletItemModel::CategoryRole);
setData(info.license(), PlasmaAppletItemModel::LicenseRole);
setData(info.website(), PlasmaAppletItemModel::WebsiteRole);
setData(info.version(), PlasmaAppletItemModel::VersionRole);
setData(info.author(), PlasmaAppletItemModel::AuthorRole);
setData(info.email(), PlasmaAppletItemModel::EmailRole);
setData(name(), PlasmaAppletItemModel::NameRole);
setData(pluginName(), PlasmaAppletItemModel::PluginNameRole);
setData(description(), PlasmaAppletItemModel::DescriptionRole);
setData(category().toLower(), PlasmaAppletItemModel::CategoryRole);
setData(license(), PlasmaAppletItemModel::LicenseRole);
setData(website(), PlasmaAppletItemModel::WebsiteRole);
setData(version(), PlasmaAppletItemModel::VersionRole);
setData(author(), PlasmaAppletItemModel::AuthorRole);
setData(email(), PlasmaAppletItemModel::EmailRole);
setData(0, PlasmaAppletItemModel::RunningRole);
setData(m_local, PlasmaAppletItemModel::LocalRole);
}
QString PlasmaAppletItem::pluginName() const
{
return m_info.pluginName();
return m_info.pluginId();
}
QString PlasmaAppletItem::name() const
......@@ -83,7 +83,7 @@ QString PlasmaAppletItem::name() const
QString PlasmaAppletItem::description() const
{
return m_info.comment();
return m_info.description();
}
QString PlasmaAppletItem::license() const
......@@ -108,12 +108,20 @@ QString PlasmaAppletItem::version() const
QString PlasmaAppletItem::author() const
{
return m_info.author();
if (m_info.authors().isEmpty()) {
return QString();
}
return m_info.authors().first().name();
}
QString PlasmaAppletItem::email() const
{
return m_info.email();
if (m_info.authors().isEmpty()) {
return QString();
}
return m_info.authors().first().emailAddress();
}
int PlasmaAppletItem::running() const
......@@ -130,12 +138,12 @@ void PlasmaAppletItem::setRunning(int count)
bool PlasmaAppletItem::matches(const QString &pattern) const
{
if (m_info.service()) {
const QStringList keywords = m_info.property(QStringLiteral("Keywords")).toStringList();
foreach (const QString &keyword, keywords) {
if (keyword.startsWith(pattern, Qt::CaseInsensitive)) {
return true;
}
const QString keywordsList = KPluginMetaData::readTranslatedString(m_info.rawData(), QStringLiteral("Keywords"));
const auto keywords = keywordsList.splitRef(QLatin1Char(';'), Qt::SkipEmptyParts);
for (const auto keyword : keywords) {
if (keyword.startsWith(pattern, Qt::CaseInsensitive)) {
return true;
}
}
......@@ -185,7 +193,7 @@ QVariant PlasmaAppletItem::data(int role) const
if (m_screenshot.isNull()) {
KPackage::Package pkg = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/Applet"));
pkg.setDefaultPackageRoot(QStringLiteral("plasma/plasmoids"));
pkg.setPath(m_info.pluginName());
pkg.setPath(m_info.pluginId());
if (pkg.isValid()) {
const_cast<PlasmaAppletItem *>(this)->m_screenshot = pkg.filePath("screenshot");
} else {
......@@ -201,7 +209,7 @@ QVariant PlasmaAppletItem::data(int role) const
if (m_icon.isNull()) {
KPackage::Package pkg = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/Applet"));
pkg.setDefaultPackageRoot(QStringLiteral("plasma/plasmoids"));
pkg.setPath(m_info.pluginName());
pkg.setPath(m_info.pluginId());
if (pkg.isValid() && pkg.metadata().iconName().startsWith(QLatin1String("/"))) {
const_cast<PlasmaAppletItem *>(this)->m_icon = pkg.filePath("", pkg.metadata().iconName().toUtf8());
} else {
......@@ -294,7 +302,7 @@ void PlasmaAppletItemModel::populateModel(const QStringList &whatChanged)
const QList<KPluginMetaData> packages = KPackage::PackageLoader::self()->findPackages(QStringLiteral("Plasma/Applet"), QStringLiteral("plasma/plasmoids"), filter);
for (const KPluginMetaData &plugin : packages) {
appendRow(new PlasmaAppletItem(KPluginInfo(plugin)));
appendRow(new PlasmaAppletItem(plugin));
}
emit modelPopulated();
......
......@@ -20,8 +20,8 @@
#ifndef PLASMA_PLASMAAPPLETITEMMODEL_P_H
#define PLASMA_PLASMAAPPLETITEMMODEL_P_H
#include <KPluginInfo>
#include <Plasma/Applet>
#include <KPluginMetaData>
#include <KConfigGroup>
#include "kcategorizeditemsviewmodels_p.h"
class PlasmaAppletItemModel;
......@@ -32,7 +32,7 @@ class PlasmaAppletItemModel;
class PlasmaAppletItem : public KCategorizedItemsViewModels::AbstractItem
{
public:
explicit PlasmaAppletItem(const KPluginInfo& info);
explicit PlasmaAppletItem(const KPluginMetaData& info);
QString pluginName() const;
QString name() const override;
......@@ -56,7 +56,7 @@ public:
QStringList mimeTypes() const;
private:
KPluginInfo m_info;
KPluginMetaData m_info;
QString m_screenshot;
QString m_icon;
int m_runningCount;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment