Browse Source

Add combo box for fast search engine switch

adaptive-webui-19844
DoumanAsh 10 years ago
parent
commit
e357cf6231
  1. 3
      src/searchengine/search.ui
  2. 35
      src/searchengine/searchengine.cpp
  3. 3
      src/searchengine/searchengine.h
  4. 6
      src/searchengine/supportedengines.h

3
src/searchengine/search.ui

@ -19,6 +19,9 @@ @@ -19,6 +19,9 @@
<item>
<widget class="QComboBox" name="comboCategory"/>
</item>
<item>
<widget class="QComboBox" name="selectEngine"/>
</item>
<item>
<widget class="QPushButton" name="search_button">
<property name="maximumSize">

35
src/searchengine/searchengine.cpp

@ -92,8 +92,10 @@ SearchEngine::SearchEngine(MainWindow* parent) @@ -92,8 +92,10 @@ SearchEngine::SearchEngine(MainWindow* parent)
supported_engines = new SupportedEngines();
// Fill in category combobox
fillCatCombobox();
fillEngineComboBox();
connect(search_pattern, SIGNAL(textEdited(QString)), this, SLOT(searchTextEdited(QString)));
connect(selectEngine, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(selectMultipleBox(const QString&)));
}
void SearchEngine::fillCatCombobox() {
@ -106,10 +108,23 @@ void SearchEngine::fillCatCombobox() { @@ -106,10 +108,23 @@ void SearchEngine::fillCatCombobox() {
}
}
void SearchEngine::fillEngineComboBox() {
selectEngine->clear();
selectEngine->addItem("All enabled", QVariant("enabled"));
selectEngine->addItem("All engines", QVariant("all"));
foreach (QString engi, supported_engines->enginesEnabled())
selectEngine->addItem(engi, QVariant(engi));
selectEngine->addItem("Multiple...", QVariant("multi"));
}
QString SearchEngine::selectedCategory() const {
return comboCategory->itemData(comboCategory->currentIndex()).toString();
}
QString SearchEngine::selectedEngine() const {
return selectEngine->itemData(selectEngine->currentIndex()).toString();
}
SearchEngine::~SearchEngine() {
qDebug("Search destruction");
searchProcess->kill();
@ -131,21 +146,26 @@ SearchEngine::~SearchEngine() { @@ -131,21 +146,26 @@ SearchEngine::~SearchEngine() {
void SearchEngine::tab_changed(int t)
{//when we switch from a tab that is not empty to another that is empty the download button
//doesn't have to be available
if (t>-1)
{//-1 = no more tab
if (t>-1) {//-1 = no more tab
if (all_tab.at(tabWidget->currentIndex())->getCurrentSearchListModel()->rowCount()) {
download_button->setEnabled(true);
goToDescBtn->setEnabled(true);
} else {
}
else {
download_button->setEnabled(false);
goToDescBtn->setEnabled(false);
}
}
}
void SearchEngine::selectMultipleBox(const QString &text) {
if (text == "Multiple...") on_enginesButton_clicked();
}
void SearchEngine::on_enginesButton_clicked() {
engineSelectDlg *dlg = new engineSelectDlg(this, supported_engines);
connect(dlg, SIGNAL(enginesChanged()), this, SLOT(fillCatCombobox()));
connect(dlg, SIGNAL(enginesChanged()), this, SLOT(fillEngineComboBox()));
}
void SearchEngine::searchTextEdited(QString) {
@ -185,7 +205,7 @@ void SearchEngine::on_search_button_clicked() { @@ -185,7 +205,7 @@ void SearchEngine::on_search_button_clicked() {
return;
}
// Tab Addition
currentSearchTab=new SearchTab(this);
currentSearchTab = new SearchTab(this);
connect(currentSearchTab->header(), SIGNAL(sectionResized(int, int, int)), this, SLOT(propagateSectionResized(int,int,int)));
all_tab.append(currentSearchTab);
QString tabName = pattern;
@ -197,7 +217,10 @@ void SearchEngine::on_search_button_clicked() { @@ -197,7 +217,10 @@ void SearchEngine::on_search_button_clicked() {
QStringList params;
search_stopped = false;
params << fsutils::toNativePath(fsutils::searchEngineLocation() + "/nova2.py");
params << supported_engines->enginesEnabled().join(",");
if (selectedEngine() == "all") params << supported_engines->enginesAll().join(",");
else if (selectedEngine() == "enabled") params << supported_engines->enginesEnabled().join(",");
else if (selectedEngine() == "multi") params << supported_engines->enginesEnabled().join(",");
else params << selectedEngine();
qDebug("Search with category: %s", qPrintable(selectedCategory()));
params << selectedCategory();
params << pattern.split(" ");
@ -231,6 +254,7 @@ void SearchEngine::saveResultsColumnsWidth() { @@ -231,6 +254,7 @@ void SearchEngine::saveResultsColumnsWidth() {
if (!line.isEmpty()) {
width_list = line.split(' ');
}
for (short i=0; i<nbColumns; ++i) {
if (treeview->columnWidth(i)<1 && width_list.size() == nbColumns && width_list.at(i).toInt()>=1) {
// load the former width
@ -428,6 +452,7 @@ void SearchEngine::searchFinished(int exitcode,QProcess::ExitStatus) { @@ -428,6 +452,7 @@ void SearchEngine::searchFinished(int exitcode,QProcess::ExitStatus) {
}
}
}
if (currentSearchTab)
currentSearchTab->getCurrentLabel()->setText(tr("Results", "i.e: Search results")+QString::fromUtf8(" <i>(")+QString::number(nb_search_results)+QString::fromUtf8(")</i>:"));
search_button->setText(tr("Search"));

3
src/searchengine/searchengine.h

@ -60,6 +60,7 @@ public: @@ -60,6 +60,7 @@ public:
SearchEngine(MainWindow *mp_mainWindow);
~SearchEngine();
QString selectedCategory() const;
QString selectedEngine() const;
static qreal getPluginVersion(QString filePath) {
QFile plugin(filePath);
@ -98,11 +99,13 @@ protected slots: @@ -98,11 +99,13 @@ protected slots:
void readSearchOutput();
void searchStarted();
void updateNova();
void selectMultipleBox(const QString &text);
void on_enginesButton_clicked();
void propagateSectionResized(int index, int oldsize , int newsize);
void saveResultsColumnsWidth();
void downloadFinished(int exitcode, QProcess::ExitStatus);
void fillCatCombobox();
void fillEngineComboBox();
void searchTextEdited(QString);
private slots:

6
src/searchengine/supportedengines.h

@ -113,6 +113,12 @@ public: @@ -113,6 +113,12 @@ public:
qDeleteAll(this->values());
}
QStringList enginesAll() const {
QStringList engines;
foreach (const SupportedEngine *engine, values()) engines << engine->getName();
return engines;
}
QStringList enginesEnabled() const {
QStringList engines;
foreach (const SupportedEngine *engine, values()) {

Loading…
Cancel
Save