summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleix Pol <[email protected]>2016-12-19 17:44:36 +0100
committerAleix Pol <[email protected]>2016-12-19 17:44:36 +0100
commit77937aedf81f70c61c560865e1fe2c085faa48df (patch)
treef5a98a7f517c365a4e62850fd75a42ee0d203266
parent1030b7d14d3c40c80e6854a63b81f6697ae823a7 (diff)
Let backends specify their own name
-rw-r--r--libdiscover/DiscoverBackendsFactory.cpp4
-rw-r--r--libdiscover/backends/KNSBackend/KNSBackend.cpp9
-rw-r--r--libdiscover/resources/AbstractResourcesBackend.h8
3 files changed, 12 insertions, 9 deletions
diff --git a/libdiscover/DiscoverBackendsFactory.cpp b/libdiscover/DiscoverBackendsFactory.cpp
index b6626f0..2b7246b 100644
--- a/libdiscover/DiscoverBackendsFactory.cpp
+++ b/libdiscover/DiscoverBackendsFactory.cpp
@@ -62,13 +62,11 @@ QVector<AbstractResourcesBackend*> DiscoverBackendsFactory::backendForFile(const
qWarning() << "error loading" << libname << loader->errorString() << loader->metaData();
return {};
}
- auto instances = f->newInstance(ResourcesModel::global());
+ auto instances = f->newInstance(ResourcesModel::global(), name);
if(instances.isEmpty()) {
qWarning() << "Couldn't find the backend: " << libname << "among" << allBackendNames(false) << "because" << loader->errorString();
return instances;
}
- for(auto instance: instances)
- instance->setName(name);
return instances;
}
diff --git a/libdiscover/backends/KNSBackend/KNSBackend.cpp b/libdiscover/backends/KNSBackend/KNSBackend.cpp
index 8c7e32f..c7a90ec 100644
--- a/libdiscover/backends/KNSBackend/KNSBackend.cpp
+++ b/libdiscover/backends/KNSBackend/KNSBackend.cpp
@@ -51,7 +51,7 @@ class KNSBackendFactory : public AbstractResourcesBackendFactory {
Q_PLUGIN_METADATA(IID "org.kde.muon.AbstractResourcesBackendFactory")
Q_INTERFACES(AbstractResourcesBackendFactory)
public:
- QVector<AbstractResourcesBackend*> newInstance(QObject* parent) const override {
+ QVector<AbstractResourcesBackend*> newInstance(QObject* parent, const QString &/*name*/) const override {
QVector<AbstractResourcesBackend*> ret;
for (const QString &path: QStandardPaths::standardLocations(QStandardPaths::GenericConfigLocation)) {
QDirIterator dirIt(path, {QStringLiteral("*.knsrc")}, QDir::Files);
@@ -62,6 +62,7 @@ class KNSBackendFactory : public AbstractResourcesBackendFactory {
continue;
auto bk = new KNSBackend(parent);
+ bk->setName(dirIt.fileName());
bk->setMetaData(QStringLiteral("plasma"), dirIt.filePath());
ret += bk;
}
@@ -123,7 +124,7 @@ void KNSBackend::setMetaData(const QString& iconName, const QString &knsrc)
m_manager->checkForInstalled();
const QVector<QPair<FilterType, QString>> filters = { {CategoryFilter, fileName } };
- const QSet<QString> potatoe = { QStringLiteral("potatoe") };
+ const QSet<QString> backendName = { name() };
QString displayName = group.readEntry("Name", QString());
if (displayName.isEmpty()) {
displayName = fileName.mid(0, fileName.indexOf(QLatin1Char('.')));
@@ -137,11 +138,11 @@ void KNSBackend::setMetaData(const QString& iconName, const QString &knsrc)
QStringLiteral("cgcgtk3.knsrc"), QStringLiteral("cgcicon.knsrc"), QStringLiteral("cgctheme.knsrc"), //GTK integration
QStringLiteral("kwinswitcher.knsrc"), QStringLiteral("kwineffect.knsrc"), QStringLiteral("kwinscripts.knsrc") //KWin
};
- auto actualCategory = new Category(displayName, QStringLiteral("plasma"), filters, potatoe, {}, QUrl(), true);
+ auto actualCategory = new Category(displayName, QStringLiteral("plasma"), filters, backendName, {}, QUrl(), true);
const auto topLevelName = knsrcPlasma.contains(fileName)? i18n("Plasma Addons") : i18n("Application Addons");
const QUrl decoration(knsrcPlasma.contains(fileName)? QStringLiteral("https://c2.staticflickr.com/4/3148/3042248532_20bd2e38f4_b.jpg") : QStringLiteral("https://c2.staticflickr.com/8/7067/6847903539_d9324dcd19_o.jpg"));
- auto addonsCategory = new Category(topLevelName, QStringLiteral("plasma"), filters, potatoe, {actualCategory}, decoration, true);
+ auto addonsCategory = new Category(topLevelName, QStringLiteral("plasma"), filters, backendName, {actualCategory}, decoration, true);
m_rootCategories = { addonsCategory };
}
diff --git a/libdiscover/resources/AbstractResourcesBackend.h b/libdiscover/resources/AbstractResourcesBackend.h
index 05788d5..0e5501b 100644
--- a/libdiscover/resources/AbstractResourcesBackend.h
+++ b/libdiscover/resources/AbstractResourcesBackend.h
@@ -245,7 +245,7 @@ class DISCOVERCOMMON_EXPORT AbstractResourcesBackendFactory : public QObject
{
Q_OBJECT
public:
- virtual QVector<AbstractResourcesBackend*> newInstance(QObject* parent) const = 0;
+ virtual QVector<AbstractResourcesBackend*> newInstance(QObject* parent, const QString &name) const = 0;
};
#define MUON_BACKEND_PLUGIN(ClassName)\
@@ -254,7 +254,11 @@ public:
Q_PLUGIN_METADATA(IID "org.kde.muon.AbstractResourcesBackendFactory")\
Q_INTERFACES(AbstractResourcesBackendFactory)\
public:\
- QVector<AbstractResourcesBackend*> newInstance(QObject* parent) const override { return {new ClassName(parent)}; }\
+ QVector<AbstractResourcesBackend*> newInstance(QObject* parent, const QString &name) const override {\
+ auto c = new ClassName(parent);\
+ c->setName(name);\
+ return {c};\
+ }\
};
Q_DECLARE_INTERFACE( AbstractResourcesBackendFactory, "org.kde.muon.AbstractResourcesBackendFactory" )