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 @@
<item> <item>
<widget class="QComboBox" name="comboCategory"/> <widget class="QComboBox" name="comboCategory"/>
</item> </item>
<item>
<widget class="QComboBox" name="selectEngine"/>
</item>
<item> <item>
<widget class="QPushButton" name="search_button"> <widget class="QPushButton" name="search_button">
<property name="maximumSize"> <property name="maximumSize">

35
src/searchengine/searchengine.cpp

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

3
src/searchengine/searchengine.h

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

6
src/searchengine/supportedengines.h

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

Loading…
Cancel
Save