Browse Source

Merge pull request #8313 from Piccirello/search-categories

Calculate search categories based on selected plugin
adaptive-webui-19844
Vladimir Golovnev 7 years ago committed by GitHub
parent
commit
931af6c97e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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 @@ @@ -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);

8
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); });
@ -172,7 +174,7 @@ void SearchWidget::fillCatCombobox() @@ -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);
}

Loading…
Cancel
Save