Changeset View
Changeset View
Standalone View
Standalone View
src/widgets/kurifilter.cpp
Show All 17 Lines | |||||
18 | * Boston, MA 02110-1301, USA. | 18 | * Boston, MA 02110-1301, USA. | ||
19 | **/ | 19 | **/ | ||
20 | 20 | | |||
21 | #include "kurifilter.h" | 21 | #include "kurifilter.h" | ||
22 | 22 | | |||
23 | #include "hostinfo.h" | 23 | #include "hostinfo.h" | ||
24 | 24 | | |||
25 | #include <kiconloader.h> | 25 | #include <kiconloader.h> | ||
26 | #include <kservicetypetrader.h> | 26 | #include <kservice.h> | ||
27 | #include <kio/global.h> | 27 | #include <kio/global.h> | ||
28 | 28 | | |||
29 | #include <KPluginMetaData> | ||||
30 | | ||||
29 | #include <QtCore/QHashIterator> | 31 | #include <QtCore/QHashIterator> | ||
30 | #include <QtCore/QStringBuilder> | 32 | #include <QtCore/QStringBuilder> | ||
31 | #include <QtNetwork/QHostInfo> | 33 | #include <QtNetwork/QHostInfo> | ||
32 | #include <QtNetwork/QHostAddress> | 34 | #include <QtNetwork/QHostAddress> | ||
33 | 35 | | |||
34 | typedef QList<KUriFilterPlugin *> KUriFilterPluginList; | 36 | typedef QList<KUriFilterPlugin *> KUriFilterPluginList; | ||
35 | typedef QMap<QString, KUriFilterSearchProvider *> SearchProviderMap; | 37 | typedef QMap<QString, KUriFilterSearchProvider *> SearchProviderMap; | ||
36 | 38 | | |||
▲ Show 20 Lines • Show All 629 Lines • ▼ Show 20 Line(s) | |||||
666 | } | 668 | } | ||
667 | 669 | | |||
668 | QStringList KUriFilter::pluginNames() const | 670 | QStringList KUriFilter::pluginNames() const | ||
669 | { | 671 | { | ||
670 | return d->pluginNames; | 672 | return d->pluginNames; | ||
671 | } | 673 | } | ||
672 | 674 | | |||
673 | void KUriFilter::loadPlugins() | 675 | void KUriFilter::loadPlugins() | ||
674 | { | 676 | { | ||
675 | const KService::List offers = KServiceTypeTrader::self()->query(QStringLiteral("KUriFilter/Plugin")); | 677 | QVector<KPluginMetaData> plugins = KPluginLoader::findPlugins("kf5/urifilters"); | ||
elvisangelaccio: This comment looks outdated now, should probably be removed? | |||||
676 | 678 | // Sort the plugins by order of priority | |||
677 | // NOTE: Plugin priority is determined by the InitialPreference entry in | 679 | std::sort(plugins.begin(), plugins.end(), [](const KPluginMetaData &a, const KPluginMetaData &b) { | ||
678 | // the .desktop files, so the trader result is already sorted and should | 680 | return a.rawData().value("X-KDE-InitialPreference").toInt() > b.rawData().value("X-KDE-InitialPreference").toInt(); | ||
679 | // not be manually sorted. | 681 | }); | ||
680 | Q_FOREACH (const KService::Ptr &ptr, offers) { | 682 | | ||
681 | KUriFilterPlugin *plugin = ptr->createInstance<KUriFilterPlugin>(); | 683 | for (const KPluginMetaData &pluginMetaData : plugins) { | ||
684 | KPluginFactory *factory = qobject_cast<KPluginFactory *>(pluginMetaData.instantiate()); | ||||
685 | if (factory) { | ||||
686 | KUriFilterPlugin *plugin = factory->create<KUriFilterPlugin>(nullptr); | ||||
682 | if (plugin) { | 687 | if (plugin) { | ||
683 | const QString &pluginName = plugin->objectName(); | 688 | const QString &pluginName = plugin->objectName(); | ||
684 | Q_ASSERT(!pluginName.isEmpty()); | 689 | Q_ASSERT(!pluginName.isEmpty()); | ||
685 | d->plugins.insert(pluginName, plugin); | 690 | d->plugins.insert(pluginName, plugin); | ||
686 | // Needed to ensure the order of filtering is honored since | 691 | // Needed to ensure the order of filtering is honored since | ||
687 | // items are ordered arbitrarily in a QHash and QMap always | 692 | // items are ordered arbitrarily in a QHash and QMap always | ||
688 | // sorts by keys. Both undesired behavior. | 693 | // sorts by keys. Both undesired behavior. | ||
689 | d->pluginNames << pluginName; | 694 | d->pluginNames << pluginName; | ||
690 | } | 695 | } | ||
691 | } | 696 | } | ||
692 | } | 697 | } | ||
698 | } | ||||
693 | 699 | |
This comment looks outdated now, should probably be removed?