Changeset View
Changeset View
Standalone View
Standalone View
src/services/kplugininfo.cpp
Show First 20 Lines • Show All 272 Lines • ▼ Show 20 Line(s) | 271 | if (!d->metaData.isValid()) { | |||
---|---|---|---|---|---|
273 | d.reset(); | 273 | d.reset(); | ||
274 | } | 274 | } | ||
275 | } | 275 | } | ||
276 | 276 | | |||
277 | KPluginInfo::KPluginInfo(const QVariantList &args, const QString &libraryPath) | 277 | KPluginInfo::KPluginInfo(const QVariantList &args, const QString &libraryPath) | ||
278 | : d(new KPluginInfoPrivate) | 278 | : d(new KPluginInfoPrivate) | ||
279 | { | 279 | { | ||
280 | const QString metaData = QStringLiteral("MetaData"); | 280 | const QString metaData = QStringLiteral("MetaData"); | ||
281 | foreach (const QVariant &v, args) { | 281 | for (const QVariant &v : args) { | ||
282 | if (v.canConvert<QVariantMap>()) { | 282 | if (v.canConvert<QVariantMap>()) { | ||
283 | const QVariantMap &m = v.toMap(); | 283 | const QVariantMap &m = v.toMap(); | ||
284 | const QVariant &_metadata = m.value(metaData); | 284 | const QVariant &_metadata = m.value(metaData); | ||
285 | if (_metadata.canConvert<QVariantMap>()) { | 285 | if (_metadata.canConvert<QVariantMap>()) { | ||
286 | const QVariantMap &map = _metadata.toMap(); | 286 | const QVariantMap &map = _metadata.toMap(); | ||
287 | if (map.value(s_hiddenKey()).toBool()) { | 287 | if (map.value(s_hiddenKey()).toBool()) { | ||
288 | d->hidden = true; | 288 | d->hidden = true; | ||
289 | break; | 289 | break; | ||
Show All 20 Lines | 304 | { | |||
310 | if (service->isDeleted()) { | 310 | if (service->isDeleted()) { | ||
311 | d->hidden = true; | 311 | d->hidden = true; | ||
312 | return; | 312 | return; | ||
313 | } | 313 | } | ||
314 | 314 | | |||
315 | KSycoca::self()->ensureCacheValid(); | 315 | KSycoca::self()->ensureCacheValid(); | ||
316 | 316 | | |||
317 | QJsonObject json; | 317 | QJsonObject json; | ||
318 | foreach (const QString &key, service->propertyNames()) { | 318 | const auto propertyList = service->propertyNames(); | ||
319 | for (const QString &key : propertyList) { | ||||
319 | QVariant::Type t = KSycocaPrivate::self()->serviceTypeFactory()->findPropertyTypeByName(key); | 320 | QVariant::Type t = KSycocaPrivate::self()->serviceTypeFactory()->findPropertyTypeByName(key); | ||
320 | if (t == QVariant::Invalid) { | 321 | if (t == QVariant::Invalid) { | ||
321 | t = QVariant::String; // default to string if the type is not known | 322 | t = QVariant::String; // default to string if the type is not known | ||
322 | } | 323 | } | ||
323 | QVariant v = service->property(key, t); | 324 | QVariant v = service->property(key, t); | ||
324 | if (v.isValid()) { | 325 | if (v.isValid()) { | ||
325 | json[key] = QJsonValue::fromVariant(v); | 326 | json[key] = QJsonValue::fromVariant(v); | ||
326 | } | 327 | } | ||
327 | } | 328 | } | ||
328 | // reintroduce the separation between MimeType= and X-KDE-ServiceTypes= | 329 | // reintroduce the separation between MimeType= and X-KDE-ServiceTypes= | ||
329 | // we could do this by modifying KService and KSyCoCa, but as this is only compatibility | 330 | // we could do this by modifying KService and KSyCoCa, but as this is only compatibility | ||
330 | // code we just query QMimeDatabase whether a ServiceType is a valid MIME type. | 331 | // code we just query QMimeDatabase whether a ServiceType is a valid MIME type. | ||
331 | // TODO: should we also make sure invalid MimeType= entries end up in KPluginMetaData::mimeTypes()? | 332 | // TODO: should we also make sure invalid MimeType= entries end up in KPluginMetaData::mimeTypes()? | ||
332 | const QStringList services = service->serviceTypes(); | 333 | const QStringList services = service->serviceTypes(); | ||
333 | if (!services.isEmpty()) { | 334 | if (!services.isEmpty()) { | ||
334 | QMimeDatabase db; | 335 | QMimeDatabase db; | ||
335 | QStringList mimeTypes; | 336 | QStringList mimeTypes; | ||
336 | mimeTypes.reserve(services.size()); | 337 | mimeTypes.reserve(services.size()); | ||
337 | QStringList newServiceTypes; | 338 | QStringList newServiceTypes; | ||
338 | newServiceTypes.reserve(services.size()); | 339 | newServiceTypes.reserve(services.size()); | ||
339 | foreach (const QString& s, services) { | 340 | for (const QString& s : services) { | ||
340 | if (db.mimeTypeForName(s).isValid()) { | 341 | if (db.mimeTypeForName(s).isValid()) { | ||
341 | mimeTypes << s; | 342 | mimeTypes << s; | ||
342 | } else { | 343 | } else { | ||
343 | newServiceTypes << s; | 344 | newServiceTypes << s; | ||
344 | } | 345 | } | ||
345 | } | 346 | } | ||
346 | json[s_mimeTypeKey()] = QJsonArray::fromStringList(mimeTypes); | 347 | json[s_mimeTypeKey()] = QJsonArray::fromStringList(mimeTypes); | ||
347 | json[s_xKDEServiceTypes()] = QJsonArray::fromStringList(newServiceTypes); | 348 | json[s_xKDEServiceTypes()] = QJsonArray::fromStringList(newServiceTypes); | ||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Line(s) | 433 | { | |||
438 | } | 439 | } | ||
439 | return infolist; | 440 | return infolist; | ||
440 | } | 441 | } | ||
441 | 442 | | |||
442 | QList<KPluginInfo> KPluginInfo::fromKPartsInstanceName(const QString &name, const KConfigGroup &config) | 443 | QList<KPluginInfo> KPluginInfo::fromKPartsInstanceName(const QString &name, const KConfigGroup &config) | ||
443 | { | 444 | { | ||
444 | QStringList files; | 445 | QStringList files; | ||
445 | const QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, name + QStringLiteral("/kpartplugins"), QStandardPaths::LocateDirectory); | 446 | const QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, name + QStringLiteral("/kpartplugins"), QStandardPaths::LocateDirectory); | ||
446 | Q_FOREACH (const QString &dir, dirs) { | 447 | for (const QString &dir : dirs) { | ||
447 | QDirIterator it(dir, QStringList() << QStringLiteral("*.desktop")); | 448 | QDirIterator it(dir, QStringList() << QStringLiteral("*.desktop")); | ||
448 | while (it.hasNext()) { | 449 | while (it.hasNext()) { | ||
449 | files.append(it.next()); | 450 | files.append(it.next()); | ||
450 | } | 451 | } | ||
451 | } | 452 | } | ||
452 | return fromFiles(files, config); | 453 | return fromFiles(files, config); | ||
453 | } | 454 | } | ||
454 | 455 | | |||
▲ Show 20 Lines • Show All 168 Lines • ▼ Show 20 Line(s) | 623 | if (result.isValid()) { | |||
623 | KSycoca::self()->ensureCacheValid(); | 624 | KSycoca::self()->ensureCacheValid(); | ||
624 | const QVariant::Type t = KSycocaPrivate::self()->serviceTypeFactory()->findPropertyTypeByName(key); | 625 | const QVariant::Type t = KSycocaPrivate::self()->serviceTypeFactory()->findPropertyTypeByName(key); | ||
625 | 626 | | |||
626 | //special case if we want a stringlist: split values by ',' or ';' and construct the list | 627 | //special case if we want a stringlist: split values by ',' or ';' and construct the list | ||
627 | if (t == QVariant::StringList) { | 628 | if (t == QVariant::StringList) { | ||
628 | if (result.canConvert<QString>()) { | 629 | if (result.canConvert<QString>()) { | ||
629 | result = KPluginInfoPrivate::deserializeList(result.toString()); | 630 | result = KPluginInfoPrivate::deserializeList(result.toString()); | ||
630 | } else if (result.canConvert<QVariantList>()) { | 631 | } else if (result.canConvert<QVariantList>()) { | ||
631 | QVariantList list = result.toList(); | 632 | const QVariantList list = result.toList(); | ||
632 | QStringList newResult; | 633 | QStringList newResult; | ||
633 | foreach (const QVariant &value, list) { | 634 | for (const QVariant &value : list) { | ||
634 | newResult += value.toString(); | 635 | newResult += value.toString(); | ||
635 | } | 636 | } | ||
636 | result = newResult; | 637 | result = newResult; | ||
637 | } else | 638 | } else | ||
638 | qCWarning(SERVICES) << "Cannot interpret" << result << "into a string list"; | 639 | qCWarning(SERVICES) << "Cannot interpret" << result << "into a string list"; | ||
639 | } | 640 | } | ||
640 | return result; | 641 | return result; | ||
641 | } | 642 | } | ||
▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Line(s) | |||||
744 | { | 745 | { | ||
745 | return info.toMetaData(); | 746 | return info.toMetaData(); | ||
746 | } | 747 | } | ||
747 | 748 | | |||
748 | KPluginInfo::List KPluginInfo::fromMetaData(const QVector<KPluginMetaData> &list) | 749 | KPluginInfo::List KPluginInfo::fromMetaData(const QVector<KPluginMetaData> &list) | ||
749 | { | 750 | { | ||
750 | KPluginInfo::List ret; | 751 | KPluginInfo::List ret; | ||
751 | ret.reserve(list.size()); | 752 | ret.reserve(list.size()); | ||
752 | foreach(const KPluginMetaData &md, list) { | 753 | for(const KPluginMetaData &md : list) { | ||
753 | ret.append(KPluginInfo::fromMetaData(md)); | 754 | ret.append(KPluginInfo::fromMetaData(md)); | ||
754 | } | 755 | } | ||
755 | return ret; | 756 | return ret; | ||
756 | } | 757 | } | ||
757 | 758 | | |||
758 | QVector<KPluginMetaData> KPluginInfo::toMetaData(const KPluginInfo::List &list) | 759 | QVector<KPluginMetaData> KPluginInfo::toMetaData(const KPluginInfo::List &list) | ||
759 | { | 760 | { | ||
760 | QVector<KPluginMetaData> ret; | 761 | QVector<KPluginMetaData> ret; | ||
761 | ret.reserve(list.size()); | 762 | ret.reserve(list.size()); | ||
762 | foreach(const KPluginInfo &info, list) { | 763 | for(const KPluginInfo &info : list) { | ||
763 | ret.append(info.toMetaData()); | 764 | ret.append(info.toMetaData()); | ||
764 | } | 765 | } | ||
765 | return ret; | 766 | return ret; | ||
766 | } | 767 | } | ||
767 | 768 | | |||
768 | 769 | | |||
769 | #undef KPLUGININFO_ISVALID_ASSERTION | 770 | #undef KPLUGININFO_ISVALID_ASSERTION |