Changeset View
Changeset View
Standalone View
Standalone View
src/plasma/pluginloader.cpp
Show First 20 Lines • Show All 136 Lines • ▼ Show 20 Line(s) | |||||
137 | PluginLoader::PluginLoader() | 137 | PluginLoader::PluginLoader() | ||
138 | : d(new PluginLoaderPrivate) | 138 | : d(new PluginLoaderPrivate) | ||
139 | { | 139 | { | ||
140 | } | 140 | } | ||
141 | 141 | | |||
142 | PluginLoader::~PluginLoader() | 142 | PluginLoader::~PluginLoader() | ||
143 | { | 143 | { | ||
144 | typedef QPointer<PackageStructure> pswp; | 144 | typedef QPointer<PackageStructure> pswp; | ||
145 | foreach (pswp wp, d->structures) { | 145 | for (pswp wp : qAsConst(d->structures)) { | ||
146 | delete wp.data(); | 146 | delete wp.data(); | ||
147 | } | 147 | } | ||
148 | delete d; | 148 | delete d; | ||
149 | } | 149 | } | ||
150 | 150 | | |||
151 | void PluginLoader::setPluginLoader(PluginLoader *loader) | 151 | void PluginLoader::setPluginLoader(PluginLoader *loader) | ||
152 | { | 152 | { | ||
153 | if (!s_pluginLoader) { | 153 | if (!s_pluginLoader) { | ||
▲ Show 20 Lines • Show All 161 Lines • ▼ Show 20 Line(s) | 309 | { | |||
315 | }; | 315 | }; | ||
316 | QVector<KPluginMetaData> plugins; | 316 | QVector<KPluginMetaData> plugins; | ||
317 | if (parentApp.isEmpty()) { | 317 | if (parentApp.isEmpty()) { | ||
318 | plugins = KPluginLoader::findPlugins(PluginLoaderPrivate::s_dataEnginePluginDir); | 318 | plugins = KPluginLoader::findPlugins(PluginLoaderPrivate::s_dataEnginePluginDir); | ||
319 | } else { | 319 | } else { | ||
320 | plugins = KPluginLoader::findPlugins(PluginLoaderPrivate::s_dataEnginePluginDir, filter); | 320 | plugins = KPluginLoader::findPlugins(PluginLoaderPrivate::s_dataEnginePluginDir, filter); | ||
321 | } | 321 | } | ||
322 | 322 | | |||
323 | foreach (auto& plugin, plugins) { | 323 | for (auto& plugin : qAsConst(plugins)) { | ||
324 | engines << plugin.pluginId(); | 324 | engines << plugin.pluginId(); | ||
325 | } | 325 | } | ||
326 | 326 | | |||
327 | const QList<KPluginMetaData> packagePlugins = KPackage::PackageLoader::self()->listPackages(QStringLiteral("Plasma/DataEngine")); | 327 | const QList<KPluginMetaData> packagePlugins = KPackage::PackageLoader::self()->listPackages(QStringLiteral("Plasma/DataEngine")); | ||
328 | for (auto& plugin : packagePlugins) { | 328 | for (auto& plugin : packagePlugins) { | ||
ahmadsamir: Coding style, auto &plugin | |||||
329 | engines << plugin.pluginId(); | 329 | engines << plugin.pluginId(); | ||
330 | } | 330 | } | ||
331 | 331 | | |||
332 | return engines; | 332 | return engines; | ||
333 | } | 333 | } | ||
334 | 334 | | |||
335 | KPluginInfo::List PluginLoader::listEngineInfo(const QString &parentApp) | 335 | KPluginInfo::List PluginLoader::listEngineInfo(const QString &parentApp) | ||
336 | { | 336 | { | ||
▲ Show 20 Lines • Show All 222 Lines • ▼ Show 20 Line(s) | |||||
559 | 559 | | |||
560 | KPluginInfo::List PluginLoader::listAppletInfo(const QString &category, const QString &parentApp) | 560 | KPluginInfo::List PluginLoader::listAppletInfo(const QString &category, const QString &parentApp) | ||
561 | { | 561 | { | ||
562 | KPluginInfo::List list; | 562 | KPluginInfo::List list; | ||
563 | const auto plugins = listAppletMetaData(category, parentApp); | 563 | const auto plugins = listAppletMetaData(category, parentApp); | ||
564 | 564 | | |||
565 | //NOTE: it still produces kplugininfos from KServices because some user code expects | 565 | //NOTE: it still produces kplugininfos from KServices because some user code expects | ||
566 | //info.service() to be valid and would crash otherwise | 566 | //info.service() to be valid and would crash otherwise | ||
567 | foreach (auto& md, plugins) { | 567 | for (const auto& md : plugins) { | ||
apol: shouldn't it be const? | |||||
dfaure: (it is now) | |||||
ahmadsamir: Style, '&md' | |||||
568 | auto pi = md.metaDataFileName().endsWith(QLatin1String(".json")) ? KPluginInfo(md) : KPluginInfo(KService::serviceByStorageId(md.metaDataFileName())); | 568 | auto pi = md.metaDataFileName().endsWith(QLatin1String(".json")) ? KPluginInfo(md) : KPluginInfo(KService::serviceByStorageId(md.metaDataFileName())); | ||
569 | if (!pi.isValid()) { | 569 | if (!pi.isValid()) { | ||
570 | qCWarning(LOG_PLASMA) << "Could not load plugin info for plugin :" << md.pluginId() << "skipping plugin"; | 570 | qCWarning(LOG_PLASMA) << "Could not load plugin info for plugin :" << md.pluginId() << "skipping plugin"; | ||
571 | continue; | 571 | continue; | ||
572 | } | 572 | } | ||
573 | list << pi; | 573 | list << pi; | ||
574 | } | 574 | } | ||
575 | return list; | 575 | return list; | ||
Show All 24 Lines | 593 | { | |||
600 | auto filter = [&parentApp](const KPluginMetaData &md) -> bool | 600 | auto filter = [&parentApp](const KPluginMetaData &md) -> bool | ||
601 | { | 601 | { | ||
602 | const QString pa = md.value(QStringLiteral("X-KDE-ParentApp")); | 602 | const QString pa = md.value(QStringLiteral("X-KDE-ParentApp")); | ||
603 | return (pa.isEmpty() || pa == parentApp) && !KPluginMetaData::readStringList(md.rawData(), QStringLiteral("X-Plasma-DropUrlPatterns")).isEmpty(); | 603 | return (pa.isEmpty() || pa == parentApp) && !KPluginMetaData::readStringList(md.rawData(), QStringLiteral("X-Plasma-DropUrlPatterns")).isEmpty(); | ||
604 | }; | 604 | }; | ||
605 | const QList<KPluginMetaData> allApplets = KPackage::PackageLoader::self()->findPackages(QStringLiteral("Plasma/Applet"), QString(), filter); | 605 | const QList<KPluginMetaData> allApplets = KPackage::PackageLoader::self()->findPackages(QStringLiteral("Plasma/Applet"), QString(), filter); | ||
606 | 606 | | |||
607 | QList<KPluginMetaData> filtered; | 607 | QList<KPluginMetaData> filtered; | ||
608 | foreach (const KPluginMetaData &md, allApplets) { | 608 | for (const KPluginMetaData &md : allApplets) { | ||
609 | QStringList urlPatterns = KPluginMetaData::readStringList(md.rawData(), QStringLiteral("X-Plasma-DropUrlPatterns")); | 609 | const QStringList urlPatterns = KPluginMetaData::readStringList(md.rawData(), QStringLiteral("X-Plasma-DropUrlPatterns")); | ||
610 | foreach (const QString &glob, urlPatterns) { | 610 | for (const QString &glob : urlPatterns) { | ||
611 | QRegExp rx(glob); | 611 | QRegExp rx(glob); | ||
612 | rx.setPatternSyntax(QRegExp::Wildcard); | 612 | rx.setPatternSyntax(QRegExp::Wildcard); | ||
613 | if (rx.exactMatch(url.toString())) { | 613 | if (rx.exactMatch(url.toString())) { | ||
614 | #ifndef NDEBUG | 614 | #ifndef NDEBUG | ||
615 | // qCDebug(LOG_PLASMA) << md.name() << "matches" << glob << url; | 615 | // qCDebug(LOG_PLASMA) << md.name() << "matches" << glob << url; | ||
616 | #endif | 616 | #endif | ||
617 | filtered << md; | 617 | filtered << md; | ||
618 | } | 618 | } | ||
Show All 18 Lines | 635 | { | |||
637 | return (pa.isEmpty() || pa == parentApp) | 637 | return (pa.isEmpty() || pa == parentApp) | ||
638 | && (excluded.isEmpty() || excluded.contains(md.value(QStringLiteral("X-KDE-PluginInfo-Category")))) | 638 | && (excluded.isEmpty() || excluded.contains(md.value(QStringLiteral("X-KDE-PluginInfo-Category")))) | ||
639 | && (!visibleOnly || !md.isHidden()); | 639 | && (!visibleOnly || !md.isHidden()); | ||
640 | }; | 640 | }; | ||
641 | const QList<KPluginMetaData> allApplets = KPackage::PackageLoader::self()->findPackages(QStringLiteral("Plasma/Applet"), QString(), filter); | 641 | const QList<KPluginMetaData> allApplets = KPackage::PackageLoader::self()->findPackages(QStringLiteral("Plasma/Applet"), QString(), filter); | ||
642 | 642 | | |||
643 | 643 | | |||
644 | QStringList categories; | 644 | QStringList categories; | ||
645 | foreach (auto& plugin, allApplets) { | 645 | for (auto& plugin : allApplets) { | ||
ahmadsamir: const, and style '&plugin'. | |||||
646 | if (plugin.category().isEmpty()) { | 646 | if (plugin.category().isEmpty()) { | ||
647 | if (!categories.contains(i18nc("misc category", "Miscellaneous"))) { | 647 | if (!categories.contains(i18nc("misc category", "Miscellaneous"))) { | ||
648 | categories << i18nc("misc category", "Miscellaneous"); | 648 | categories << i18nc("misc category", "Miscellaneous"); | ||
649 | } | 649 | } | ||
650 | } else { | 650 | } else { | ||
651 | categories << plugin.category(); | 651 | categories << plugin.category(); | ||
652 | } | 652 | } | ||
653 | } | 653 | } | ||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Line(s) | 721 | return md.serviceTypes().contains(QLatin1String("Plasma/Containment")) | |||
722 | && KPluginMetaData::readStringList(md.rawData(), QStringLiteral("X-Plasma-DropMimeTypes")).contains(mimeType); | 722 | && KPluginMetaData::readStringList(md.rawData(), QStringLiteral("X-Plasma-DropMimeTypes")).contains(mimeType); | ||
723 | }; | 723 | }; | ||
724 | 724 | | |||
725 | return KPluginInfo::fromMetaData(KPackage::PackageLoader::self()->findPackages(QStringLiteral("Plasma/Applet"), QString(), filter).toVector()); | 725 | return KPluginInfo::fromMetaData(KPackage::PackageLoader::self()->findPackages(QStringLiteral("Plasma/Applet"), QString(), filter).toVector()); | ||
726 | } | 726 | } | ||
727 | 727 | | |||
728 | QStringList PluginLoader::listContainmentTypes() | 728 | QStringList PluginLoader::listContainmentTypes() | ||
729 | { | 729 | { | ||
730 | KPluginInfo::List containmentInfos = listContainments(); | 730 | const KPluginInfo::List containmentInfos = listContainments(); | ||
731 | QSet<QString> types; | 731 | QSet<QString> types; | ||
732 | 732 | | |||
733 | foreach (const KPluginInfo &containmentInfo, containmentInfos) { | 733 | for (const KPluginInfo &containmentInfo : containmentInfos) { | ||
734 | QStringList theseTypes = containmentInfo.service()->property(QStringLiteral("X-Plasma-ContainmentType")).toStringList(); | 734 | const QStringList theseTypes = containmentInfo.service()->property(QStringLiteral("X-Plasma-ContainmentType")).toStringList(); | ||
735 | foreach (const QString &type, theseTypes) { | 735 | for (const QString &type : theseTypes) { | ||
736 | types.insert(type); | 736 | types.insert(type); | ||
737 | } | 737 | } | ||
738 | } | 738 | } | ||
739 | 739 | | |||
740 | return types.toList(); | 740 | return types.toList(); | ||
741 | } | 741 | } | ||
742 | 742 | | |||
743 | KPluginInfo::List PluginLoader::listDataEngineInfo(const QString &parentApp) | 743 | KPluginInfo::List PluginLoader::listDataEngineInfo(const QString &parentApp) | ||
Show All 28 Lines | 771 | if (parentApp.isEmpty()) { | |||
772 | constraint = QStringLiteral("not exist [X-KDE-ParentApp]"); | 772 | constraint = QStringLiteral("not exist [X-KDE-ParentApp]"); | ||
773 | } else { | 773 | } else { | ||
774 | constraint = QLatin1String("[X-KDE-ParentApp] == '") + parentApp + QLatin1Char('\''); | 774 | constraint = QLatin1String("[X-KDE-ParentApp] == '") + parentApp + QLatin1Char('\''); | ||
775 | } | 775 | } | ||
776 | 776 | | |||
777 | list.append(KPluginTrader::self()->query(PluginLoaderPrivate::s_containmentActionsPluginDir, QStringLiteral("Plasma/ContainmentActions"), constraint)); | 777 | list.append(KPluginTrader::self()->query(PluginLoaderPrivate::s_containmentActionsPluginDir, QStringLiteral("Plasma/ContainmentActions"), constraint)); | ||
778 | 778 | | |||
779 | QSet<QString> knownPlugins; | 779 | QSet<QString> knownPlugins; | ||
780 | foreach (const KPluginInfo &p, list) { | 780 | for (const KPluginInfo &p : qAsConst(list)) { | ||
781 | knownPlugins.insert(p.pluginName()); | 781 | knownPlugins.insert(p.pluginName()); | ||
782 | } | 782 | } | ||
783 | 783 | | |||
784 | //FIXME: this is only for backwards compatibility, but probably will have to stay | 784 | //FIXME: this is only for backwards compatibility, but probably will have to stay | ||
785 | //for the time being | 785 | //for the time being | ||
786 | KService::List offers = KServiceTypeTrader::self()->query(QStringLiteral("Plasma/ContainmentActions"), constraint); | 786 | const KService::List offers = KServiceTypeTrader::self()->query(QStringLiteral("Plasma/ContainmentActions"), constraint); | ||
787 | foreach (KService::Ptr s, offers) { | 787 | for (KService::Ptr s : offers) { | ||
788 | if (!knownPlugins.contains(s->pluginKeyword())) { | 788 | if (!knownPlugins.contains(s->pluginKeyword())) { | ||
789 | list.append(KPluginInfo(s)); | 789 | list.append(KPluginInfo(s)); | ||
790 | } | 790 | } | ||
791 | } | 791 | } | ||
792 | return list; | 792 | return list; | ||
793 | } | 793 | } | ||
794 | 794 | | |||
795 | Applet *PluginLoader::internalLoadApplet(const QString &name, uint appletId, const QVariantList &args) | 795 | Applet *PluginLoader::internalLoadApplet(const QString &name, uint appletId, const QVariantList &args) | ||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Line(s) | |||||
854 | } | 854 | } | ||
855 | 855 | | |||
856 | static KPluginInfo::List standardInternalInfo(const QString &type, const QString &category = QString()) | 856 | static KPluginInfo::List standardInternalInfo(const QString &type, const QString &category = QString()) | ||
857 | { | 857 | { | ||
858 | QStringList files = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, | 858 | QStringList files = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, | ||
859 | QLatin1String(PLASMA_RELATIVE_DATA_INSTALL_DIR "/internal/") + type + QLatin1String("/*.desktop"), | 859 | QLatin1String(PLASMA_RELATIVE_DATA_INSTALL_DIR "/internal/") + type + QLatin1String("/*.desktop"), | ||
860 | QStandardPaths::LocateFile); | 860 | QStandardPaths::LocateFile); | ||
861 | 861 | | |||
862 | KPluginInfo::List allInfo = KPluginInfo::fromFiles(files); | 862 | const KPluginInfo::List allInfo = KPluginInfo::fromFiles(files); | ||
863 | 863 | | |||
864 | if (category.isEmpty() || allInfo.isEmpty()) { | 864 | if (category.isEmpty() || allInfo.isEmpty()) { | ||
865 | return allInfo; | 865 | return allInfo; | ||
866 | } | 866 | } | ||
867 | 867 | | |||
868 | KPluginInfo::List matchingInfo; | 868 | KPluginInfo::List matchingInfo; | ||
869 | foreach (const KPluginInfo &info, allInfo) { | 869 | for (const KPluginInfo &info : allInfo) { | ||
870 | if (info.category().compare(category, Qt::CaseInsensitive) == 0) { | 870 | if (info.category().compare(category, Qt::CaseInsensitive) == 0) { | ||
871 | matchingInfo << info; | 871 | matchingInfo << info; | ||
872 | } | 872 | } | ||
873 | } | 873 | } | ||
874 | 874 | | |||
875 | return matchingInfo; | 875 | return matchingInfo; | ||
876 | } | 876 | } | ||
877 | 877 | | |||
Show All 40 Lines |
Coding style, auto &plugin