Browse Source

Calculate supported categories based on selected plugin

adaptive-webui-19844
Thomas Piccirello 7 years ago
parent
commit
7278625f53
  1. 22
      src/base/search/searchpluginmanager.cpp
  2. 1
      src/base/search/searchpluginmanager.h
  3. 6
      src/gui/search/searchwidget.cpp

22
src/base/search/searchpluginmanager.cpp

@ -38,6 +38,7 @@ @@ -38,6 +38,7 @@
#include <QPointer>
#include <QProcess>
#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 @@ -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<QString> 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);

1
src/base/search/searchpluginmanager.h

@ -66,6 +66,7 @@ public: @@ -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);

6
src/gui/search/searchwidget.cpp

@ -139,8 +139,8 @@ SearchWidget::SearchWidget(MainWindow *mainWindow) @@ -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) @@ -155,6 +155,8 @@ SearchWidget::SearchWidget(MainWindow *mainWindow)
connect(m_ui->m_searchPattern, &LineEdit::textEdited, this, &SearchWidget::searchTextEdited);
connect(m_ui->selectPlugin, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged)
, this, &SearchWidget::selectMultipleBox);
connect(m_ui->selectPlugin, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged)
, this, &SearchWidget::fillCatCombobox);
}
void SearchWidget::fillCatCombobox()
@ -164,7 +166,7 @@ void SearchWidget::fillCatCombobox() @@ -164,7 +166,7 @@ void SearchWidget::fillCatCombobox()
using QStrPair = QPair<QString, QString>;
QList<QStrPair> 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); });

Loading…
Cancel
Save