[aurorae] Port loading of QML decos to KPackage

Another sycoca usage gone.
This commit is contained in:
Martin Gräßlin 2015-07-07 09:49:15 +02:00
parent 93ef184356
commit 06469f66a8
2 changed files with 14 additions and 11 deletions

View file

@ -18,7 +18,7 @@ target_link_libraries(kwin5_aurorae
KDecoration2::KDecoration KDecoration2::KDecoration
KF5::ConfigWidgets KF5::ConfigWidgets
KF5::I18n KF5::I18n
KF5::Service KF5::Package
KF5::WindowSystem KF5::WindowSystem
Qt5::Quick Qt5::Quick
Qt5::UiTools Qt5::UiTools

View file

@ -33,8 +33,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <KLocalizedTranslator> #include <KLocalizedTranslator>
#include <KPluginFactory> #include <KPluginFactory>
#include <KSharedConfig> #include <KSharedConfig>
#include <KService> #include <KPackage/PackageLoader>
#include <KServiceTypeTrader>
// Qt // Qt
#include <QDebug> #include <QDebug>
#include <QComboBox> #include <QComboBox>
@ -116,6 +115,7 @@ void Helper::unref()
} }
static const QString s_defaultTheme = QStringLiteral("kwin4_decoration_qml_plastik"); static const QString s_defaultTheme = QStringLiteral("kwin4_decoration_qml_plastik");
static const QString s_qmlPackageFolder = QStringLiteral(KWIN_NAME) + QStringLiteral("/decorations/");
/* /*
* KDecoration2::BorderSize doesn't map to the indices used for the Aurorae SVG Button Sizes. * KDecoration2::BorderSize doesn't map to the indices used for the Aurorae SVG Button Sizes.
* BorderSize defines None and NoSideBorder as index 0 and 1. These do not make sense for Button * BorderSize defines None and NoSideBorder as index 0 and 1. These do not make sense for Button
@ -166,17 +166,20 @@ QQmlComponent *Helper::loadComponent(const QString &themeName)
qCDebug(AURORAE) << "Trying to load QML Decoration " << themeName; qCDebug(AURORAE) << "Trying to load QML Decoration " << themeName;
const QString internalname = themeName.toLower(); const QString internalname = themeName.toLower();
QString constraint = QStringLiteral("[X-KDE-PluginInfo-Name] == '%1'").arg(internalname); const auto offers = KPackage::PackageLoader::self()->findPackages(QStringLiteral("KWin/Decoration"), s_qmlPackageFolder,
KService::List offers = KServiceTypeTrader::self()->query(QStringLiteral("KWin/Decoration"), constraint); [internalname] (const KPluginMetaData &data) {
return data.pluginId().compare(internalname, Qt::CaseInsensitive) == 0;
}
);
if (offers.isEmpty()) { if (offers.isEmpty()) {
qCCritical(AURORAE) << "Couldn't find QML Decoration " << themeName << endl; qCCritical(AURORAE) << "Couldn't find QML Decoration " << themeName << endl;
// TODO: what to do in error case? // TODO: what to do in error case?
return nullptr; return nullptr;
} }
KService::Ptr service = offers.first(); const KPluginMetaData &service = offers.first();
const QString pluginName = service->property(QStringLiteral("X-KDE-PluginInfo-Name")).toString(); const QString pluginName = service.pluginId();
const QString scriptName = service->property(QStringLiteral("X-Plasma-MainScript")).toString(); const QString scriptName = service.value(QStringLiteral("X-Plasma-MainScript"));
const QString file = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral(KWIN_NAME) + QStringLiteral("/decorations/") + pluginName + QStringLiteral("/contents/") + scriptName); const QString file = QStandardPaths::locate(QStandardPaths::GenericDataLocation, s_qmlPackageFolder + pluginName + QStringLiteral("/contents/") + scriptName);
if (file.isNull()) { if (file.isNull()) {
qCDebug(AURORAE) << "Could not find script file for " << pluginName; qCDebug(AURORAE) << "Could not find script file for " << pluginName;
// TODO: what to do in error case? // TODO: what to do in error case?
@ -623,9 +626,9 @@ void ThemeFinder::init()
void ThemeFinder::findAllQmlThemes() void ThemeFinder::findAllQmlThemes()
{ {
const KService::List offers = KServiceTypeTrader::self()->query(QStringLiteral("KWin/Decoration")); const auto offers = KPackage::PackageLoader::self()->findPackages(QStringLiteral("KWin/Decoration"), s_qmlPackageFolder);
for (const auto &offer : offers) { for (const auto &offer : offers) {
m_themes.insert(offer->name(), offer->property(QStringLiteral("X-KDE-PluginInfo-Name")).toString()); m_themes.insert(offer.name(), offer.pluginId());
} }
} }