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. 8
      src/gui/search/searchwidget.cpp

22
src/base/search/searchpluginmanager.cpp

@ -38,6 +38,7 @@
#include <QPointer> #include <QPointer>
#include <QProcess> #include <QProcess>
#include "base/global.h"
#include "base/logger.h" #include "base/logger.h"
#include "base/net/downloadmanager.h" #include "base/net/downloadmanager.h"
#include "base/net/downloadhandler.h" #include "base/net/downloadhandler.h"
@ -122,6 +123,27 @@ QStringList SearchPluginManager::supportedCategories() const
return result; 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 PluginInfo *SearchPluginManager::pluginInfo(const QString &name) const
{ {
return m_plugins.value(name); return m_plugins.value(name);

1
src/base/search/searchpluginmanager.h

@ -66,6 +66,7 @@ public:
QStringList allPlugins() const; QStringList allPlugins() const;
QStringList enabledPlugins() const; QStringList enabledPlugins() const;
QStringList supportedCategories() const; QStringList supportedCategories() const;
QStringList getPluginCategories(const QString &pluginName) const;
PluginInfo *pluginInfo(const QString &name) const; PluginInfo *pluginInfo(const QString &name) const;
void enablePlugin(const QString &name, bool enabled = true); void enablePlugin(const QString &name, bool enabled = true);

8
src/gui/search/searchwidget.cpp

@ -139,8 +139,8 @@ SearchWidget::SearchWidget(MainWindow *mainWindow)
auto *searchManager = new SearchPluginManager; auto *searchManager = new SearchPluginManager;
const auto onPluginChanged = [this]() const auto onPluginChanged = [this]()
{ {
fillCatCombobox();
fillPluginComboBox(); fillPluginComboBox();
fillCatCombobox();
selectActivePage(); selectActivePage();
}; };
connect(searchManager, &SearchPluginManager::pluginInstalled, this, onPluginChanged); 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->m_searchPattern, &LineEdit::textEdited, this, &SearchWidget::searchTextEdited);
connect(m_ui->selectPlugin, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged) connect(m_ui->selectPlugin, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged)
, this, &SearchWidget::selectMultipleBox); , this, &SearchWidget::selectMultipleBox);
connect(m_ui->selectPlugin, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged)
, this, &SearchWidget::fillCatCombobox);
} }
void SearchWidget::fillCatCombobox() void SearchWidget::fillCatCombobox()
@ -164,7 +166,7 @@ void SearchWidget::fillCatCombobox()
using QStrPair = QPair<QString, QString>; using QStrPair = QPair<QString, QString>;
QList<QStrPair> tmpList; QList<QStrPair> tmpList;
foreach (const QString &cat, SearchPluginManager::instance()->supportedCategories()) foreach (const QString &cat, SearchPluginManager::instance()->getPluginCategories(selectedPlugin()))
tmpList << qMakePair(SearchPluginManager::categoryFullName(cat), cat); 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); }); 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)); qDebug("Supported category: %s", qUtf8Printable(p.second));
m_ui->comboCategory->addItem(p.first, QVariant(p.second)); m_ui->comboCategory->addItem(p.first, QVariant(p.second));
} }
if (m_ui->comboCategory->count() > 1) if (m_ui->comboCategory->count() > 1)
m_ui->comboCategory->insertSeparator(1); m_ui->comboCategory->insertSeparator(1);
} }

Loading…
Cancel
Save