diff --git a/src/base/search/searchpluginmanager.cpp b/src/base/search/searchpluginmanager.cpp index 7dd1faa30..0bf87fea3 100644 --- a/src/base/search/searchpluginmanager.cpp +++ b/src/base/search/searchpluginmanager.cpp @@ -38,6 +38,7 @@ #include #include +#include "base/global.h" #include "base/logger.h" #include "base/net/downloadmanager.h" #include "base/net/downloadhandler.h" @@ -122,6 +123,27 @@ QStringList SearchPluginManager::supportedCategories() const return result; } +QStringList SearchPluginManager::getPluginCategories(const QString &pluginName) const +{ + QStringList plugins; + if (pluginName == "all") + plugins = allPlugins(); + else if ((pluginName == "enabled") || (pluginName == "multi")) + plugins = enabledPlugins(); + else + plugins << pluginName.trimmed(); + + QSet categories; + for (const QString &pluginName : qAsConst(plugins)) { + const PluginInfo *plugin = pluginInfo(pluginName); + if (!plugin) continue; // plugin wasn't found + for (const QString &category : plugin->supportedCategories) + categories << category; + } + + return categories.toList(); +} + PluginInfo *SearchPluginManager::pluginInfo(const QString &name) const { return m_plugins.value(name); diff --git a/src/base/search/searchpluginmanager.h b/src/base/search/searchpluginmanager.h index e3723c540..536d012c7 100644 --- a/src/base/search/searchpluginmanager.h +++ b/src/base/search/searchpluginmanager.h @@ -66,6 +66,7 @@ public: QStringList allPlugins() const; QStringList enabledPlugins() const; QStringList supportedCategories() const; + QStringList getPluginCategories(const QString &pluginName) const; PluginInfo *pluginInfo(const QString &name) const; void enablePlugin(const QString &name, bool enabled = true); diff --git a/src/gui/search/searchwidget.cpp b/src/gui/search/searchwidget.cpp index 26995f171..b1ea6b0b7 100644 --- a/src/gui/search/searchwidget.cpp +++ b/src/gui/search/searchwidget.cpp @@ -139,8 +139,8 @@ SearchWidget::SearchWidget(MainWindow *mainWindow) auto *searchManager = new SearchPluginManager; const auto onPluginChanged = [this]() { - fillCatCombobox(); fillPluginComboBox(); + fillCatCombobox(); selectActivePage(); }; connect(searchManager, &SearchPluginManager::pluginInstalled, this, onPluginChanged); @@ -155,6 +155,8 @@ SearchWidget::SearchWidget(MainWindow *mainWindow) connect(m_ui->m_searchPattern, &LineEdit::textEdited, this, &SearchWidget::searchTextEdited); connect(m_ui->selectPlugin, static_cast(&QComboBox::currentIndexChanged) , this, &SearchWidget::selectMultipleBox); + connect(m_ui->selectPlugin, static_cast(&QComboBox::currentIndexChanged) + , this, &SearchWidget::fillCatCombobox); } void SearchWidget::fillCatCombobox() @@ -164,7 +166,7 @@ void SearchWidget::fillCatCombobox() using QStrPair = QPair; QList tmpList; - foreach (const QString &cat, SearchPluginManager::instance()->supportedCategories()) + foreach (const QString &cat, SearchPluginManager::instance()->getPluginCategories(selectedPlugin())) tmpList << qMakePair(SearchPluginManager::categoryFullName(cat), cat); std::sort(tmpList.begin(), tmpList.end(), [](const QStrPair &l, const QStrPair &r) { return (QString::localeAwareCompare(l.first, r.first) < 0); }); @@ -172,7 +174,7 @@ void SearchWidget::fillCatCombobox() qDebug("Supported category: %s", qUtf8Printable(p.second)); m_ui->comboCategory->addItem(p.first, QVariant(p.second)); } - + if (m_ui->comboCategory->count() > 1) m_ui->comboCategory->insertSeparator(1); }