Merge pull request #8313 from Piccirello/search-categories

Calculate search categories based on selected plugin
This commit is contained in:
Vladimir Golovnev 2018-03-12 14:29:51 +03:00 committed by GitHub
commit 931af6c97e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 3 deletions

View File

@ -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
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);

View File

@ -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);

View File

@ -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<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()
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()
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);
}