Browse Source

[Search] Add seperator for categories & plugins

Sort categories & plugins entries
Rename & reorder entries
Use full name for plugins
adaptive-webui-19844
Chocobo1 9 years ago
parent
commit
a52f9d4ef9
  1. 5
      src/base/searchengine.cpp
  2. 1
      src/base/searchengine.h
  3. 37
      src/gui/search/searchwidget.cpp
  4. 2
      src/gui/search/searchwidget.h

5
src/base/searchengine.cpp

@ -295,6 +295,11 @@ QString SearchEngine::categoryFullName(const QString &categoryName)
return tr(m_categoryNames.value(categoryName).toUtf8().constData()); return tr(m_categoryNames.value(categoryName).toUtf8().constData());
} }
QString SearchEngine::pluginFullName(const QString &pluginName)
{
return pluginInfo(pluginName) ? pluginInfo(pluginName)->fullName : QString();
}
QString SearchEngine::pluginsLocation() QString SearchEngine::pluginsLocation()
{ {
return QString("%1/engines").arg(engineLocation()); return QString("%1/engines").arg(engineLocation());

1
src/base/searchengine.h

@ -86,6 +86,7 @@ public:
static qreal getPluginVersion(QString filePath); static qreal getPluginVersion(QString filePath);
static QString categoryFullName(const QString &categoryName); static QString categoryFullName(const QString &categoryName);
QString pluginFullName(const QString &pluginName);
static QString pluginsLocation(); static QString pluginsLocation();
signals: signals:

37
src/gui/search/searchwidget.cpp

@ -121,27 +121,43 @@ SearchWidget::SearchWidget(MainWindow *mainWindow)
fillPluginComboBox(); fillPluginComboBox();
connect(m_searchPattern, SIGNAL(textEdited(QString)), this, SLOT(searchTextEdited(QString))); connect(m_searchPattern, SIGNAL(textEdited(QString)), this, SLOT(searchTextEdited(QString)));
connect(selectPlugin, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(selectMultipleBox(const QString &))); connect(selectPlugin, SIGNAL(currentIndexChanged(int)), this, SLOT(selectMultipleBox(int)));
} }
void SearchWidget::fillCatCombobox() void SearchWidget::fillCatCombobox()
{ {
comboCategory->clear(); comboCategory->clear();
comboCategory->addItem(SearchEngine::categoryFullName("all"), QVariant("all")); comboCategory->addItem(SearchEngine::categoryFullName("all"), QVariant("all"));
foreach (QString cat, m_searchEngine->supportedCategories()) { comboCategory->insertSeparator(1);
qDebug("Supported category: %s", qPrintable(cat));
comboCategory->addItem(SearchEngine::categoryFullName(cat), QVariant(cat)); using QStrPair = QPair<QString, QString>;
QList<QStrPair> tmpList;
foreach (const QString &cat, m_searchEngine->supportedCategories())
tmpList << qMakePair(SearchEngine::categoryFullName(cat), cat);
std::sort(tmpList.begin(), tmpList.end(), [](const QStrPair &l, const QStrPair &r) { return (l.first < r.first); } );
foreach (const QStrPair &p, tmpList) {
qDebug("Supported category: %s", qPrintable(p.second));
comboCategory->addItem(p.first, QVariant(p.second));
} }
} }
void SearchWidget::fillPluginComboBox() void SearchWidget::fillPluginComboBox()
{ {
selectPlugin->clear(); selectPlugin->clear();
selectPlugin->addItem(tr("All enabled"), QVariant("enabled"));
selectPlugin->addItem(tr("All plugins"), QVariant("all")); selectPlugin->addItem(tr("All plugins"), QVariant("all"));
foreach (QString name, m_searchEngine->enabledPlugins()) selectPlugin->addItem(tr("Only enabled"), QVariant("enabled"));
selectPlugin->addItem(name, QVariant(name)); selectPlugin->addItem(tr("Select..."), QVariant("multi"));
selectPlugin->addItem(tr("Multiple..."), QVariant("multi")); selectPlugin->insertSeparator(3);
using QStrPair = QPair<QString, QString>;
QList<QStrPair> tmpList;
foreach (const QString &name, m_searchEngine->enabledPlugins())
tmpList << qMakePair(m_searchEngine->pluginFullName(name), name);
std::sort(tmpList.begin(), tmpList.end(), [](const QStrPair &l, const QStrPair &r) { return (l.first < r.first); } );
foreach (const QStrPair &p, tmpList)
selectPlugin->addItem(p.first, QVariant(p.second));
} }
QString SearchWidget::selectedCategory() const QString SearchWidget::selectedCategory() const
@ -180,9 +196,10 @@ void SearchWidget::tab_changed(int t)
} }
} }
void SearchWidget::selectMultipleBox(const QString &text) void SearchWidget::selectMultipleBox(int index)
{ {
if (text == tr("Multiple...")) Q_UNUSED(index);
if (selectedPlugin() == "multi")
on_pluginsButton_clicked(); on_pluginsButton_clicked();
} }

2
src/gui/search/searchwidget.h

@ -71,7 +71,7 @@ private slots:
void searchStarted(); void searchStarted();
void searchFinished(bool cancelled); void searchFinished(bool cancelled);
void searchFailed(); void searchFailed();
void selectMultipleBox(const QString &text); void selectMultipleBox(int index);
void saveResultsColumnsWidth(); void saveResultsColumnsWidth();
void fillCatCombobox(); void fillCatCombobox();

Loading…
Cancel
Save