Changeset View
Changeset View
Standalone View
Standalone View
src/plasma/pluginloader.cpp
Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | |||||
53 | { | 53 | { | ||
54 | public: | 54 | public: | ||
55 | PluginLoaderPrivate() | 55 | PluginLoaderPrivate() | ||
56 | : isDefaultLoader(false) | 56 | : isDefaultLoader(false) | ||
57 | { | 57 | { | ||
58 | } | 58 | } | ||
59 | 59 | | |||
60 | static QSet<QString> knownCategories(); | 60 | static QSet<QString> knownCategories(); | ||
61 | static QString parentAppConstraint(const QString &parentApp = QString()); | | |||
62 | 61 | | |||
63 | static QSet<QString> s_customCategories; | 62 | static QSet<QString> s_customCategories; | ||
64 | QHash<QString, QPointer<PackageStructure> > structures; | 63 | QHash<QString, QPointer<PackageStructure> > structures; | ||
65 | bool isDefaultLoader; | 64 | bool isDefaultLoader; | ||
66 | 65 | | |||
67 | static QString s_dataEnginePluginDir; | 66 | static QString s_dataEnginePluginDir; | ||
68 | static QString s_packageStructurePluginDir; | 67 | static QString s_packageStructurePluginDir; | ||
69 | static QString s_plasmoidsPluginDir; | 68 | static QString s_plasmoidsPluginDir; | ||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | 96 | categories << QStringLiteral(I18N_NOOP("Accessibility")).toLower() | |||
114 | << QStringLiteral(I18N_NOOP("System Information")).toLower() | 113 | << QStringLiteral(I18N_NOOP("System Information")).toLower() | ||
115 | << QStringLiteral(I18N_NOOP("Utilities")).toLower() | 114 | << QStringLiteral(I18N_NOOP("Utilities")).toLower() | ||
116 | << QStringLiteral(I18N_NOOP("Windows and Tasks")).toLower() | 115 | << QStringLiteral(I18N_NOOP("Windows and Tasks")).toLower() | ||
117 | << QStringLiteral(I18N_NOOP("Clipboard")).toLower() | 116 | << QStringLiteral(I18N_NOOP("Clipboard")).toLower() | ||
118 | << QStringLiteral(I18N_NOOP("Tasks")).toLower(); | 117 | << QStringLiteral(I18N_NOOP("Tasks")).toLower(); | ||
119 | return categories; | 118 | return categories; | ||
120 | } | 119 | } | ||
121 | 120 | | |||
122 | QString PluginLoaderPrivate::parentAppConstraint(const QString &parentApp) | | |||
123 | { | | |||
124 | if (parentApp.isEmpty()) { | | |||
125 | QCoreApplication *app = QCoreApplication::instance(); | | |||
126 | if (!app) { | | |||
127 | return QString(); | | |||
128 | } | | |||
129 | | ||||
130 | return QStringLiteral("((not exist [X-KDE-ParentApp] or [X-KDE-ParentApp] == '') or [X-KDE-ParentApp] == '%1')") | | |||
131 | .arg(app->applicationName()); | | |||
132 | } | | |||
133 | | ||||
134 | return QStringLiteral("[X-KDE-ParentApp] == '%1'").arg(parentApp); | | |||
135 | } | | |||
136 | | ||||
137 | PluginLoader::PluginLoader() | 121 | PluginLoader::PluginLoader() | ||
138 | : d(new PluginLoaderPrivate) | 122 | : d(new PluginLoaderPrivate) | ||
139 | { | 123 | { | ||
140 | } | 124 | } | ||
141 | 125 | | |||
142 | PluginLoader::~PluginLoader() | 126 | PluginLoader::~PluginLoader() | ||
143 | { | 127 | { | ||
144 | typedef QPointer<PackageStructure> pswp; | 128 | typedef QPointer<PackageStructure> pswp; | ||
▲ Show 20 Lines • Show All 385 Lines • ▼ Show 20 Line(s) | 512 | { | |||
530 | std::function<bool(const KPluginMetaData&)> filter; | 514 | std::function<bool(const KPluginMetaData&)> filter; | ||
531 | if (category.isEmpty()) { //use all but the excluded categories | 515 | if (category.isEmpty()) { //use all but the excluded categories | ||
532 | KConfigGroup group(KSharedConfig::openConfig(), "General"); | 516 | KConfigGroup group(KSharedConfig::openConfig(), "General"); | ||
533 | QStringList excluded = group.readEntry("ExcludeCategories", QStringList()); | 517 | QStringList excluded = group.readEntry("ExcludeCategories", QStringList()); | ||
534 | 518 | | |||
535 | filter = [excluded, parentApp](const KPluginMetaData &md) -> bool | 519 | filter = [excluded, parentApp](const KPluginMetaData &md) -> bool | ||
536 | { | 520 | { | ||
537 | const QString pa = md.value(QStringLiteral("X-KDE-ParentApp")); | 521 | const QString pa = md.value(QStringLiteral("X-KDE-ParentApp")); | ||
538 | return (pa.isEmpty() || pa == parentApp) && !excluded.contains(md.category()); | 522 | return (parentApp.isEmpty() || pa == parentApp) && !excluded.contains(md.category()); | ||
539 | }; | 523 | }; | ||
540 | } else { //specific category (this could be an excluded one - is that bad?) | 524 | } else { //specific category (this could be an excluded one - is that bad?) | ||
541 | 525 | | |||
542 | filter = [category, parentApp](const KPluginMetaData &md) -> bool | 526 | filter = [category, parentApp](const KPluginMetaData &md) -> bool | ||
543 | { | 527 | { | ||
544 | const QString pa = md.value(QStringLiteral("X-KDE-ParentApp")); | 528 | const QString pa = md.value(QStringLiteral("X-KDE-ParentApp")); | ||
545 | if (category == QLatin1String("Miscellaneous")) { | 529 | if (category == QLatin1String("Miscellaneous")) { | ||
546 | return (pa.isEmpty() || pa == parentApp) && (md.category() == category || md.category().isEmpty()); | 530 | return (parentApp.isEmpty() || pa == parentApp) && (md.category() == category || md.category().isEmpty()); | ||
547 | } else { | 531 | } else { | ||
548 | return (pa.isEmpty() || pa == parentApp) && md.category() == category; | 532 | return (parentApp.isEmpty() || pa == parentApp) && md.category() == category; | ||
549 | } | 533 | } | ||
550 | }; | 534 | }; | ||
551 | } | 535 | } | ||
552 | 536 | | |||
553 | QList<KPluginMetaData> list; | 537 | QList<KPluginMetaData> list; | ||
554 | if (!d->isDefaultLoader && (parentApp.isEmpty() || parentApp == QCoreApplication::instance()->applicationName())) { | 538 | if (!d->isDefaultLoader && (parentApp.isEmpty() || parentApp == QCoreApplication::instance()->applicationName())) { | ||
555 | list = KPluginInfo::toMetaData(internalAppletInfo(category)).toList(); | 539 | list = KPluginInfo::toMetaData(internalAppletInfo(category)).toList(); | ||
556 | } | 540 | } | ||
Show All 38 Lines | 577 | { | |||
595 | QCoreApplication *app = QCoreApplication::instance(); | 579 | QCoreApplication *app = QCoreApplication::instance(); | ||
596 | if (app) { | 580 | if (app) { | ||
597 | parentApp = app->applicationName(); | 581 | parentApp = app->applicationName(); | ||
598 | } | 582 | } | ||
599 | 583 | | |||
600 | auto filter = [&parentApp](const KPluginMetaData &md) -> bool | 584 | auto filter = [&parentApp](const KPluginMetaData &md) -> bool | ||
601 | { | 585 | { | ||
602 | const QString pa = md.value(QStringLiteral("X-KDE-ParentApp")); | 586 | const QString pa = md.value(QStringLiteral("X-KDE-ParentApp")); | ||
603 | return (pa.isEmpty() || pa == parentApp) && !KPluginMetaData::readStringList(md.rawData(), QStringLiteral("X-Plasma-DropUrlPatterns")).isEmpty(); | 587 | return (parentApp.isEmpty() || pa == parentApp) && !KPluginMetaData::readStringList(md.rawData(), QStringLiteral("X-Plasma-DropUrlPatterns")).isEmpty(); | ||
604 | }; | 588 | }; | ||
605 | const QList<KPluginMetaData> allApplets = KPackage::PackageLoader::self()->findPackages(QStringLiteral("Plasma/Applet"), QString(), filter); | 589 | const QList<KPluginMetaData> allApplets = KPackage::PackageLoader::self()->findPackages(QStringLiteral("Plasma/Applet"), QString(), filter); | ||
606 | 590 | | |||
607 | QList<KPluginMetaData> filtered; | 591 | QList<KPluginMetaData> filtered; | ||
608 | foreach (const KPluginMetaData &md, allApplets) { | 592 | foreach (const KPluginMetaData &md, allApplets) { | ||
609 | QStringList urlPatterns = KPluginMetaData::readStringList(md.rawData(), QStringLiteral("X-Plasma-DropUrlPatterns")); | 593 | QStringList urlPatterns = KPluginMetaData::readStringList(md.rawData(), QStringLiteral("X-Plasma-DropUrlPatterns")); | ||
610 | foreach (const QString &glob, urlPatterns) { | 594 | foreach (const QString &glob, urlPatterns) { | ||
611 | QRegExp rx(glob); | 595 | QRegExp rx(glob); | ||
Show All 17 Lines | |||||
629 | 613 | | |||
630 | QStringList PluginLoader::listAppletCategories(const QString &parentApp, bool visibleOnly) | 614 | QStringList PluginLoader::listAppletCategories(const QString &parentApp, bool visibleOnly) | ||
631 | { | 615 | { | ||
632 | KConfigGroup group(KSharedConfig::openConfig(), "General"); | 616 | KConfigGroup group(KSharedConfig::openConfig(), "General"); | ||
633 | const QStringList excluded = group.readEntry("ExcludeCategories", QStringList()); | 617 | const QStringList excluded = group.readEntry("ExcludeCategories", QStringList()); | ||
634 | auto filter = [&parentApp, &excluded, visibleOnly](const KPluginMetaData &md) -> bool | 618 | auto filter = [&parentApp, &excluded, visibleOnly](const KPluginMetaData &md) -> bool | ||
635 | { | 619 | { | ||
636 | const QString pa = md.value(QStringLiteral("X-KDE-ParentApp")); | 620 | const QString pa = md.value(QStringLiteral("X-KDE-ParentApp")); | ||
637 | return (pa.isEmpty() || pa == parentApp) | 621 | return (parentApp.isEmpty() || pa == parentApp) | ||
638 | && (excluded.isEmpty() || excluded.contains(md.value(QStringLiteral("X-KDE-PluginInfo-Category")))) | 622 | && (excluded.isEmpty() || excluded.contains(md.value(QStringLiteral("X-KDE-PluginInfo-Category")))) | ||
639 | && (!visibleOnly || !md.isHidden()); | 623 | && (!visibleOnly || !md.isHidden()); | ||
640 | }; | 624 | }; | ||
641 | const QList<KPluginMetaData> allApplets = KPackage::PackageLoader::self()->findPackages(QStringLiteral("Plasma/Applet"), QString(), filter); | 625 | const QList<KPluginMetaData> allApplets = KPackage::PackageLoader::self()->findPackages(QStringLiteral("Plasma/Applet"), QString(), filter); | ||
642 | 626 | | |||
643 | 627 | | |||
644 | QStringList categories; | 628 | QStringList categories; | ||
645 | foreach (auto& plugin, allApplets) { | 629 | foreach (auto& plugin, allApplets) { | ||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | 672 | KPluginInfo::List PluginLoader::listContainmentsOfType(const QString &type, | |||
690 | const QString &parentApp) | 674 | const QString &parentApp) | ||
691 | { | 675 | { | ||
692 | KConfigGroup group(KSharedConfig::openConfig(), "General"); | 676 | KConfigGroup group(KSharedConfig::openConfig(), "General"); | ||
693 | auto filter = [&type, &category, &parentApp](const KPluginMetaData &md) -> bool | 677 | auto filter = [&type, &category, &parentApp](const KPluginMetaData &md) -> bool | ||
694 | { | 678 | { | ||
695 | if (!md.serviceTypes().contains(QStringLiteral("Plasma/Containment"))) { | 679 | if (!md.serviceTypes().contains(QStringLiteral("Plasma/Containment"))) { | ||
696 | return false; | 680 | return false; | ||
697 | } | 681 | } | ||
698 | const QString pa = md.value(QStringLiteral("X-KDE-ParentApp")); | 682 | if (!parentApp.isEmpty() && md.value(QStringLiteral("X-KDE-ParentApp")) != parentApp) { | ||
699 | if (!pa.isEmpty() && pa != parentApp) { | | |||
700 | return false; | 683 | return false; | ||
701 | } | 684 | } | ||
702 | 685 | | |||
703 | if (!type.isEmpty() && md.value(QStringLiteral("X-Plasma-ContainmentType")) != type) { | 686 | if (!type.isEmpty() && md.value(QStringLiteral("X-Plasma-ContainmentType")) != type) { | ||
704 | return false; | 687 | return false; | ||
705 | } | 688 | } | ||
706 | 689 | | |||
707 | if (!category.isEmpty() && md.value(QStringLiteral("X-KDE-PluginInfo-Category")) != category) { | 690 | if (!category.isEmpty() && md.value(QStringLiteral("X-KDE-PluginInfo-Category")) != category) { | ||
Show All 36 Lines | |||||
744 | { | 727 | { | ||
745 | KPluginInfo::List list; | 728 | KPluginInfo::List list; | ||
746 | 729 | | |||
747 | if (!d->isDefaultLoader && (parentApp.isEmpty() || parentApp == QCoreApplication::instance()->applicationName())) { | 730 | if (!d->isDefaultLoader && (parentApp.isEmpty() || parentApp == QCoreApplication::instance()->applicationName())) { | ||
748 | list = internalDataEngineInfo(); | 731 | list = internalDataEngineInfo(); | ||
749 | } | 732 | } | ||
750 | 733 | | |||
751 | QString constraint; | 734 | QString constraint; | ||
752 | if (parentApp.isEmpty()) { | 735 | if (!parentApp.isEmpty()) { | ||
753 | constraint = QStringLiteral("not exist [X-KDE-ParentApp]"); | | |||
754 | } else { | | |||
755 | constraint = QLatin1String("[X-KDE-ParentApp] == '") + parentApp + QLatin1Char('\''); | 736 | constraint = QLatin1String("[X-KDE-ParentApp] == '") + parentApp + QLatin1Char('\''); | ||
756 | } | 737 | } | ||
757 | 738 | | |||
758 | list.append(KPluginTrader::self()->query(PluginLoaderPrivate::s_dataEnginePluginDir, QStringLiteral("Plasma/DataEngine"), constraint)); | 739 | list.append(KPluginTrader::self()->query(PluginLoaderPrivate::s_dataEnginePluginDir, QStringLiteral("Plasma/DataEngine"), constraint)); | ||
759 | return list; | 740 | return list; | ||
760 | } | 741 | } | ||
761 | 742 | | |||
762 | KPluginInfo::List PluginLoader::listContainmentActionsInfo(const QString &parentApp) | 743 | KPluginInfo::List PluginLoader::listContainmentActionsInfo(const QString &parentApp) | ||
763 | { | 744 | { | ||
764 | KPluginInfo::List list; | 745 | KPluginInfo::List list; | ||
765 | 746 | | |||
766 | if (!d->isDefaultLoader && (parentApp.isEmpty() || parentApp == QCoreApplication::instance()->applicationName())) { | 747 | if (!d->isDefaultLoader && (parentApp.isEmpty() || parentApp == QCoreApplication::instance()->applicationName())) { | ||
767 | list = internalContainmentActionsInfo(); | 748 | list = internalContainmentActionsInfo(); | ||
768 | } | 749 | } | ||
769 | 750 | | |||
770 | QString constraint; | 751 | QString constraint; | ||
771 | if (parentApp.isEmpty()) { | 752 | if (!parentApp.isEmpty()) { | ||
772 | constraint = QStringLiteral("not exist [X-KDE-ParentApp]"); | | |||
773 | } else { | | |||
774 | constraint = QLatin1String("[X-KDE-ParentApp] == '") + parentApp + QLatin1Char('\''); | 753 | constraint = QLatin1String("[X-KDE-ParentApp] == '") + parentApp + QLatin1Char('\''); | ||
775 | } | 754 | } | ||
776 | 755 | | |||
777 | list.append(KPluginTrader::self()->query(PluginLoaderPrivate::s_containmentActionsPluginDir, QStringLiteral("Plasma/ContainmentActions"), constraint)); | 756 | list.append(KPluginTrader::self()->query(PluginLoaderPrivate::s_containmentActionsPluginDir, QStringLiteral("Plasma/ContainmentActions"), constraint)); | ||
778 | 757 | | |||
779 | QSet<QString> knownPlugins; | 758 | QSet<QString> knownPlugins; | ||
780 | foreach (const KPluginInfo &p, list) { | 759 | foreach (const KPluginInfo &p, list) { | ||
781 | knownPlugins.insert(p.pluginName()); | 760 | knownPlugins.insert(p.pluginName()); | ||
▲ Show 20 Lines • Show All 136 Lines • Show Last 20 Lines |