Changeset View
Changeset View
Standalone View
Standalone View
src/plasma/pluginloader.cpp
Show First 20 Lines • Show All 128 Lines • ▼ Show 20 Line(s) | |||||
129 | PluginLoader::PluginLoader() | 129 | PluginLoader::PluginLoader() | ||
130 | : d(new PluginLoaderPrivate) | 130 | : d(new PluginLoaderPrivate) | ||
131 | { | 131 | { | ||
132 | } | 132 | } | ||
133 | 133 | | |||
134 | PluginLoader::~PluginLoader() | 134 | PluginLoader::~PluginLoader() | ||
135 | { | 135 | { | ||
136 | typedef QPointer<PackageStructure> pswp; | 136 | typedef QPointer<PackageStructure> pswp; | ||
137 | foreach (pswp wp, d->structures) { | 137 | for (pswp wp : qAsConst(d->structures)) { | ||
138 | delete wp.data(); | 138 | delete wp.data(); | ||
139 | } | 139 | } | ||
140 | delete d; | 140 | delete d; | ||
141 | } | 141 | } | ||
142 | 142 | | |||
143 | void PluginLoader::setPluginLoader(PluginLoader *loader) | 143 | void PluginLoader::setPluginLoader(PluginLoader *loader) | ||
144 | { | 144 | { | ||
145 | if (!s_pluginLoader) { | 145 | if (!s_pluginLoader) { | ||
▲ Show 20 Lines • Show All 121 Lines • ▼ Show 20 Line(s) | 261 | { | |||
267 | }; | 267 | }; | ||
268 | QVector<KPluginMetaData> plugins; | 268 | QVector<KPluginMetaData> plugins; | ||
269 | if (parentApp.isEmpty()) { | 269 | if (parentApp.isEmpty()) { | ||
270 | plugins = KPluginLoader::findPlugins(PluginLoaderPrivate::s_dataEnginePluginDir); | 270 | plugins = KPluginLoader::findPlugins(PluginLoaderPrivate::s_dataEnginePluginDir); | ||
271 | } else { | 271 | } else { | ||
272 | plugins = KPluginLoader::findPlugins(PluginLoaderPrivate::s_dataEnginePluginDir, filter); | 272 | plugins = KPluginLoader::findPlugins(PluginLoaderPrivate::s_dataEnginePluginDir, filter); | ||
273 | } | 273 | } | ||
274 | 274 | | |||
275 | foreach (auto& plugin, plugins) { | 275 | for (auto& plugin : qAsConst(plugins)) { | ||
276 | engines << plugin.pluginId(); | 276 | engines << plugin.pluginId(); | ||
277 | } | 277 | } | ||
278 | 278 | | |||
279 | const QList<KPluginMetaData> packagePlugins = KPackage::PackageLoader::self()->listPackages(QStringLiteral("Plasma/DataEngine")); | 279 | const QList<KPluginMetaData> packagePlugins = KPackage::PackageLoader::self()->listPackages(QStringLiteral("Plasma/DataEngine")); | ||
280 | for (auto& plugin : packagePlugins) { | 280 | for (const auto &plugin : packagePlugins) { | ||
ahmadsamir: Coding style, auto &plugin | |||||
281 | engines << plugin.pluginId(); | 281 | engines << plugin.pluginId(); | ||
282 | } | 282 | } | ||
283 | 283 | | |||
284 | return engines; | 284 | return engines; | ||
285 | } | 285 | } | ||
286 | 286 | | |||
287 | KPluginInfo::List PluginLoader::listEngineInfo(const QString &parentApp) | 287 | KPluginInfo::List PluginLoader::listEngineInfo(const QString &parentApp) | ||
288 | { | 288 | { | ||
▲ Show 20 Lines • Show All 213 Lines • ▼ Show 20 Line(s) | |||||
502 | 502 | | |||
503 | KPluginInfo::List PluginLoader::listAppletInfo(const QString &category, const QString &parentApp) | 503 | KPluginInfo::List PluginLoader::listAppletInfo(const QString &category, const QString &parentApp) | ||
504 | { | 504 | { | ||
505 | KPluginInfo::List list; | 505 | KPluginInfo::List list; | ||
506 | const auto plugins = listAppletMetaData(category, parentApp); | 506 | const auto plugins = listAppletMetaData(category, parentApp); | ||
507 | 507 | | |||
508 | //NOTE: it still produces kplugininfos from KServices because some user code expects | 508 | //NOTE: it still produces kplugininfos from KServices because some user code expects | ||
509 | //info.service() to be valid and would crash otherwise | 509 | //info.service() to be valid and would crash otherwise | ||
510 | foreach (auto& md, plugins) { | 510 | for (const auto &md : plugins) { | ||
apol: shouldn't it be const? | |||||
dfaure: (it is now) | |||||
ahmadsamir: Style, '&md' | |||||
511 | auto pi = md.metaDataFileName().endsWith(QLatin1String(".json")) ? KPluginInfo(md) : KPluginInfo(KService::serviceByStorageId(md.metaDataFileName())); | 511 | auto pi = md.metaDataFileName().endsWith(QLatin1String(".json")) ? KPluginInfo(md) : KPluginInfo(KService::serviceByStorageId(md.metaDataFileName())); | ||
512 | if (!pi.isValid()) { | 512 | if (!pi.isValid()) { | ||
513 | qCWarning(LOG_PLASMA) << "Could not load plugin info for plugin :" << md.pluginId() << "skipping plugin"; | 513 | qCWarning(LOG_PLASMA) << "Could not load plugin info for plugin :" << md.pluginId() << "skipping plugin"; | ||
514 | continue; | 514 | continue; | ||
515 | } | 515 | } | ||
516 | list << pi; | 516 | list << pi; | ||
517 | } | 517 | } | ||
518 | return list; | 518 | return list; | ||
Show All 24 Lines | 536 | { | |||
543 | auto filter = [&parentApp](const KPluginMetaData &md) -> bool | 543 | auto filter = [&parentApp](const KPluginMetaData &md) -> bool | ||
544 | { | 544 | { | ||
545 | const QString pa = md.value(QStringLiteral("X-KDE-ParentApp")); | 545 | const QString pa = md.value(QStringLiteral("X-KDE-ParentApp")); | ||
546 | return (parentApp.isEmpty() || pa == parentApp) && !KPluginMetaData::readStringList(md.rawData(), QStringLiteral("X-Plasma-DropUrlPatterns")).isEmpty(); | 546 | return (parentApp.isEmpty() || pa == parentApp) && !KPluginMetaData::readStringList(md.rawData(), QStringLiteral("X-Plasma-DropUrlPatterns")).isEmpty(); | ||
547 | }; | 547 | }; | ||
548 | const QList<KPluginMetaData> allApplets = KPackage::PackageLoader::self()->findPackages(QStringLiteral("Plasma/Applet"), QString(), filter); | 548 | const QList<KPluginMetaData> allApplets = KPackage::PackageLoader::self()->findPackages(QStringLiteral("Plasma/Applet"), QString(), filter); | ||
549 | 549 | | |||
550 | QList<KPluginMetaData> filtered; | 550 | QList<KPluginMetaData> filtered; | ||
551 | foreach (const KPluginMetaData &md, allApplets) { | 551 | for (const KPluginMetaData &md : allApplets) { | ||
552 | QStringList urlPatterns = KPluginMetaData::readStringList(md.rawData(), QStringLiteral("X-Plasma-DropUrlPatterns")); | 552 | const QStringList urlPatterns = KPluginMetaData::readStringList(md.rawData(), QStringLiteral("X-Plasma-DropUrlPatterns")); | ||
553 | foreach (const QString &glob, urlPatterns) { | 553 | for (const QString &glob : urlPatterns) { | ||
554 | QRegExp rx(glob); | 554 | QRegExp rx(glob); | ||
555 | rx.setPatternSyntax(QRegExp::Wildcard); | 555 | rx.setPatternSyntax(QRegExp::Wildcard); | ||
556 | if (rx.exactMatch(url.toString())) { | 556 | if (rx.exactMatch(url.toString())) { | ||
557 | #ifndef NDEBUG | 557 | #ifndef NDEBUG | ||
558 | // qCDebug(LOG_PLASMA) << md.name() << "matches" << glob << url; | 558 | // qCDebug(LOG_PLASMA) << md.name() << "matches" << glob << url; | ||
559 | #endif | 559 | #endif | ||
560 | filtered << md; | 560 | filtered << md; | ||
561 | } | 561 | } | ||
Show All 18 Lines | 578 | { | |||
580 | return (parentApp.isEmpty() || pa == parentApp) | 580 | return (parentApp.isEmpty() || pa == parentApp) | ||
581 | && (excluded.isEmpty() || excluded.contains(md.value(QStringLiteral("X-KDE-PluginInfo-Category")))) | 581 | && (excluded.isEmpty() || excluded.contains(md.value(QStringLiteral("X-KDE-PluginInfo-Category")))) | ||
582 | && (!visibleOnly || !md.isHidden()); | 582 | && (!visibleOnly || !md.isHidden()); | ||
583 | }; | 583 | }; | ||
584 | const QList<KPluginMetaData> allApplets = KPackage::PackageLoader::self()->findPackages(QStringLiteral("Plasma/Applet"), QString(), filter); | 584 | const QList<KPluginMetaData> allApplets = KPackage::PackageLoader::self()->findPackages(QStringLiteral("Plasma/Applet"), QString(), filter); | ||
585 | 585 | | |||
586 | 586 | | |||
587 | QStringList categories; | 587 | QStringList categories; | ||
588 | foreach (auto& plugin, allApplets) { | 588 | for (auto &plugin : allApplets) { | ||
ahmadsamir: const, and style '&plugin'. | |||||
589 | if (plugin.category().isEmpty()) { | 589 | if (plugin.category().isEmpty()) { | ||
590 | if (!categories.contains(i18nc("misc category", "Miscellaneous"))) { | 590 | if (!categories.contains(i18nc("misc category", "Miscellaneous"))) { | ||
591 | categories << i18nc("misc category", "Miscellaneous"); | 591 | categories << i18nc("misc category", "Miscellaneous"); | ||
592 | } | 592 | } | ||
593 | } else { | 593 | } else { | ||
594 | categories << plugin.category(); | 594 | categories << plugin.category(); | ||
595 | } | 595 | } | ||
596 | } | 596 | } | ||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Line(s) | 663 | return md.serviceTypes().contains(QLatin1String("Plasma/Containment")) | |||
664 | && KPluginMetaData::readStringList(md.rawData(), QStringLiteral("X-Plasma-DropMimeTypes")).contains(mimeType); | 664 | && KPluginMetaData::readStringList(md.rawData(), QStringLiteral("X-Plasma-DropMimeTypes")).contains(mimeType); | ||
665 | }; | 665 | }; | ||
666 | 666 | | |||
667 | return KPluginInfo::fromMetaData(KPackage::PackageLoader::self()->findPackages(QStringLiteral("Plasma/Applet"), QString(), filter).toVector()); | 667 | return KPluginInfo::fromMetaData(KPackage::PackageLoader::self()->findPackages(QStringLiteral("Plasma/Applet"), QString(), filter).toVector()); | ||
668 | } | 668 | } | ||
669 | 669 | | |||
670 | QStringList PluginLoader::listContainmentTypes() | 670 | QStringList PluginLoader::listContainmentTypes() | ||
671 | { | 671 | { | ||
672 | KPluginInfo::List containmentInfos = listContainments(); | 672 | const KPluginInfo::List containmentInfos = listContainments(); | ||
673 | QSet<QString> types; | 673 | QSet<QString> types; | ||
674 | 674 | | |||
675 | foreach (const KPluginInfo &containmentInfo, containmentInfos) { | 675 | for (const KPluginInfo &containmentInfo : containmentInfos) { | ||
676 | QStringList theseTypes = containmentInfo.service()->property(QStringLiteral("X-Plasma-ContainmentType")).toStringList(); | 676 | const QStringList theseTypes = containmentInfo.service()->property(QStringLiteral("X-Plasma-ContainmentType")).toStringList(); | ||
677 | foreach (const QString &type, theseTypes) { | 677 | for (const QString &type : theseTypes) { | ||
678 | types.insert(type); | 678 | types.insert(type); | ||
679 | } | 679 | } | ||
680 | } | 680 | } | ||
681 | 681 | | |||
682 | return types.values(); | 682 | return types.values(); | ||
683 | } | 683 | } | ||
684 | 684 | | |||
685 | KPluginInfo::List PluginLoader::listDataEngineInfo(const QString &parentApp) | 685 | KPluginInfo::List PluginLoader::listDataEngineInfo(const QString &parentApp) | ||
Show All 24 Lines | 703 | { | |||
710 | QString constraint; | 710 | QString constraint; | ||
711 | if (!parentApp.isEmpty()) { | 711 | if (!parentApp.isEmpty()) { | ||
712 | constraint = QLatin1String("[X-KDE-ParentApp] == '") + parentApp + QLatin1Char('\''); | 712 | constraint = QLatin1String("[X-KDE-ParentApp] == '") + parentApp + QLatin1Char('\''); | ||
713 | } | 713 | } | ||
714 | 714 | | |||
715 | list.append(KPluginTrader::self()->query(PluginLoaderPrivate::s_containmentActionsPluginDir, QStringLiteral("Plasma/ContainmentActions"), constraint)); | 715 | list.append(KPluginTrader::self()->query(PluginLoaderPrivate::s_containmentActionsPluginDir, QStringLiteral("Plasma/ContainmentActions"), constraint)); | ||
716 | 716 | | |||
717 | QSet<QString> knownPlugins; | 717 | QSet<QString> knownPlugins; | ||
718 | foreach (const KPluginInfo &p, list) { | 718 | for (const KPluginInfo &p : qAsConst(list)) { | ||
719 | knownPlugins.insert(p.pluginName()); | 719 | knownPlugins.insert(p.pluginName()); | ||
720 | } | 720 | } | ||
721 | 721 | | |||
722 | //FIXME: this is only for backwards compatibility, but probably will have to stay | 722 | //FIXME: this is only for backwards compatibility, but probably will have to stay | ||
723 | //for the time being | 723 | //for the time being | ||
724 | KService::List offers = KServiceTypeTrader::self()->query(QStringLiteral("Plasma/ContainmentActions"), constraint); | 724 | const KService::List offers = KServiceTypeTrader::self()->query(QStringLiteral("Plasma/ContainmentActions"), constraint); | ||
725 | foreach (KService::Ptr s, offers) { | 725 | for (KService::Ptr s : offers) { | ||
726 | if (!knownPlugins.contains(s->pluginKeyword())) { | 726 | if (!knownPlugins.contains(s->pluginKeyword())) { | ||
727 | list.append(KPluginInfo(s)); | 727 | list.append(KPluginInfo(s)); | ||
728 | } | 728 | } | ||
729 | } | 729 | } | ||
730 | return list; | 730 | return list; | ||
731 | } | 731 | } | ||
732 | 732 | | |||
733 | Applet *PluginLoader::internalLoadApplet(const QString &name, uint appletId, const QVariantList &args) | 733 | Applet *PluginLoader::internalLoadApplet(const QString &name, uint appletId, const QVariantList &args) | ||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Line(s) | |||||
790 | } | 790 | } | ||
791 | 791 | | |||
792 | static KPluginInfo::List standardInternalInfo(const QString &type, const QString &category = QString()) | 792 | static KPluginInfo::List standardInternalInfo(const QString &type, const QString &category = QString()) | ||
793 | { | 793 | { | ||
794 | QStringList files = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, | 794 | QStringList files = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, | ||
795 | QLatin1String(PLASMA_RELATIVE_DATA_INSTALL_DIR "/internal/") + type + QLatin1String("/*.desktop"), | 795 | QLatin1String(PLASMA_RELATIVE_DATA_INSTALL_DIR "/internal/") + type + QLatin1String("/*.desktop"), | ||
796 | QStandardPaths::LocateFile); | 796 | QStandardPaths::LocateFile); | ||
797 | 797 | | |||
798 | KPluginInfo::List allInfo = KPluginInfo::fromFiles(files); | 798 | const KPluginInfo::List allInfo = KPluginInfo::fromFiles(files); | ||
799 | 799 | | |||
800 | if (category.isEmpty() || allInfo.isEmpty()) { | 800 | if (category.isEmpty() || allInfo.isEmpty()) { | ||
801 | return allInfo; | 801 | return allInfo; | ||
802 | } | 802 | } | ||
803 | 803 | | |||
804 | KPluginInfo::List matchingInfo; | 804 | KPluginInfo::List matchingInfo; | ||
805 | foreach (const KPluginInfo &info, allInfo) { | 805 | for (const KPluginInfo &info : allInfo) { | ||
806 | if (info.category().compare(category, Qt::CaseInsensitive) == 0) { | 806 | if (info.category().compare(category, Qt::CaseInsensitive) == 0) { | ||
807 | matchingInfo << info; | 807 | matchingInfo << info; | ||
808 | } | 808 | } | ||
809 | } | 809 | } | ||
810 | 810 | | |||
811 | return matchingInfo; | 811 | return matchingInfo; | ||
812 | } | 812 | } | ||
813 | 813 | | |||
▲ Show 20 Lines • Show All 88 Lines • Show Last 20 Lines |
Coding style, auto &plugin