[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kcoreaddons] /: Add KPluginMetaData::formFactor API
From:       Sebastian_Kügler <sebas () kde ! org>
Date:       2015-06-29 22:44:35
Message-ID: E1Z9hn1-00054D-18 () scm ! kde ! org
[Download RAW message or body]

Git commit 499c15cccea14f97114a06a64082ac57660926bf by Sebastian Kügler.
Committed on 29/06/2015 at 22:41.
Pushed by sebas into branch 'master'.

Add KPluginMetaData::formFactor API

This is a new global key in the json metadata (or .desktop files) that returns a
stringlist of formfactors this plugin or application is useful for. It
may return any string in the list (we don't know yet which formfactors
may be useful in the future).

The usecase here is that some applications may want to load certain
plugins only on a given formfactor, or apps or plugins that should be
started with a different command line argument depending on the
formfactor. Also, app launcher or plugin listers may filter the list of
offered/shown plugins by this FormFactor key.

CHANGELOG:Allow filtering plugins and applications by formfactor
REVIEW:124066

M  +1    -1    autotests/data/fakeplugin.desktop
M  +5    -0    autotests/kpluginmetadatatest.cpp
M  +2    -0    src/lib/plugin/desktopfileparser.cpp
M  +5    -0    src/lib/plugin/kpluginmetadata.cpp
M  +9    -0    src/lib/plugin/kpluginmetadata.h

http://commits.kde.org/kcoreaddons/499c15cccea14f97114a06a64082ac57660926bf

diff --git a/autotests/data/fakeplugin.desktop b/autotests/data/fakeplugin.desktop
index f506e44..2e18686 100644
--- a/autotests/data/fakeplugin.desktop
+++ b/autotests/data/fakeplugin.desktop
@@ -69,7 +69,7 @@ Icon=preferences-system-time
 
 X-KDE-ServiceTypes=KService/NSA
 X-KDE-Library=fakeplugin
-
+X-KDE-FormFactors=mediacenter,desktop
 X-KDE-PluginInfo-Author=Sebastian Kügler
 X-KDE-PluginInfo-Email=sebas@kde.org
 X-KDE-PluginInfo-Name=fakeplugin
diff --git a/autotests/kpluginmetadatatest.cpp b/autotests/kpluginmetadatatest.cpp
index 231ac36..3af5e1b 100644
--- a/autotests/kpluginmetadatatest.cpp
+++ b/autotests/kpluginmetadatatest.cpp
@@ -210,6 +210,11 @@ private Q_SLOTS:
         QCOMPARE(md.isHidden(), false);
         QCOMPARE(md.serviceTypes(), QStringList("KService/NSA"));
 
+        auto kp = md.rawData()["KPlugin"].toObject();
+        QStringList formFactors = KPluginMetaData::readStringList(kp, QStringLiteral("FormFactors"));
+        QCOMPARE(formFactors, QStringList() << "mediacenter" << "desktop");
+        QCOMPARE(md.formFactors(), QStringList() << "mediacenter" << "desktop");
+
         const QString dfilehidden = QFINDTESTDATA("data/hiddenplugin.desktop");
         KPluginMetaData mdhidden(dfilehidden);
         QVERIFY(mdhidden.isValid());
diff --git a/src/lib/plugin/desktopfileparser.cpp b/src/lib/plugin/desktopfileparser.cpp
index b19da6b..0b03eb1 100644
--- a/src/lib/plugin/desktopfileparser.cpp
+++ b/src/lib/plugin/desktopfileparser.cpp
@@ -144,6 +144,8 @@ void DesktopFileParser::convertToJson(const QString &key, const QString &value,
     } else if (key == QLatin1String("X-KDE-ServiceTypes") || key == QLatin1String("ServiceTypes")) {
         // some .desktop files still use the legacy ServiceTypes= key
         kplugin[QStringLiteral("ServiceTypes")] = QJsonArray::fromStringList(deserializeList(value));
+    } else if (key == QLatin1String("X-KDE-FormFactors")) {
+        kplugin[QStringLiteral("FormFactors")] = QJsonArray::fromStringList(deserializeList(value));
     } else if (key == QLatin1String("X-KDE-PluginInfo-EnabledByDefault")) {
         bool boolValue = false;
         // should only be lower case, but be tolerant here
diff --git a/src/lib/plugin/kpluginmetadata.cpp b/src/lib/plugin/kpluginmetadata.cpp
index eaaf0b9..b13d6dd 100644
--- a/src/lib/plugin/kpluginmetadata.cpp
+++ b/src/lib/plugin/kpluginmetadata.cpp
@@ -270,6 +270,11 @@ QStringList KPluginMetaData::serviceTypes() const
     return readStringList(rootObject(), QStringLiteral("ServiceTypes"));
 }
 
+QStringList KPluginMetaData::formFactors() const
+{
+    return readStringList(rootObject(), QStringLiteral("FormFactors"));
+}
+
 bool KPluginMetaData::isEnabledByDefault() const
 {
     QJsonValue val = rootObject()[QStringLiteral("EnabledByDefault")];
diff --git a/src/lib/plugin/kpluginmetadata.h b/src/lib/plugin/kpluginmetadata.h
index 4572d36..183b0d0 100644
--- a/src/lib/plugin/kpluginmetadata.h
+++ b/src/lib/plugin/kpluginmetadata.h
@@ -268,6 +268,15 @@ public:
     QStringList serviceTypes() const;
 
     /**
+     * @return A string list of formfactors this plugin is useful for, e.g. desktop, tablet,
+     * handset, mediacenter, etc.
+     * The keys for this are not formally defined.
+     *
+     * @since 5.12
+     */
+    QStringList formFactors() const;
+
+    /**
      * @return whether the plugin should be enabled by default.
      * This is only a recommendation, applications can ignore this value if they want to.
      */
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic