diff options
| author | Denis Steckelmacher <[email protected]> | 2014-09-10 10:16:11 +0200 |
|---|---|---|
| committer | Denis Steckelmacher <[email protected]> | 2014-09-10 10:16:11 +0200 |
| commit | e3578ee3b770a1b8f359ed1a3cc6e3ac7f6c700e (patch) | |
| tree | d12f42038fc7f1ccb66b4705bb8a9283ac6fc210 /src/search/dolphinsearchbox.cpp | |
| parent | 39cfd051ef25f3a90fdfa411325829ca119a421c (diff) | |
Use the Baloo Query Builder widget to add syntax-highlighting in Dolphin search
REVIEW: 112589
Diffstat (limited to 'src/search/dolphinsearchbox.cpp')
| -rw-r--r-- | src/search/dolphinsearchbox.cpp | 53 |
1 files changed, 39 insertions, 14 deletions
diff --git a/src/search/dolphinsearchbox.cpp b/src/search/dolphinsearchbox.cpp index ae93030ac..27a251b7d 100644 --- a/src/search/dolphinsearchbox.cpp +++ b/src/search/dolphinsearchbox.cpp @@ -40,8 +40,9 @@ #include <QToolButton> #include <QVBoxLayout> -#include <config-baloo.h> #ifdef HAVE_BALOO + #include <Baloo/NaturalFileQueryParser> + #include <Baloo/QueryBuilder> #include <Baloo/Query> #include <Baloo/Term> #include <Baloo/IndexerConfig> @@ -252,8 +253,10 @@ void DolphinSearchBox::slotConfigurationChanged() } } -void DolphinSearchBox::slotSearchTextChanged(const QString& text) +void DolphinSearchBox::slotSearchTextChanged() { + const QString text = m_searchInput->text(); + if (text.isEmpty()) { m_startSearchTimer->stop(); } else { @@ -262,10 +265,17 @@ void DolphinSearchBox::slotSearchTextChanged(const QString& text) emit searchTextChanged(text); } -void DolphinSearchBox::slotReturnPressed(const QString& text) +void DolphinSearchBox::slotReturnPressed() { emitSearchRequest(); - emit returnPressed(text); + emit returnPressed(m_searchInput->text()); +} + +void DolphinSearchBox::updateSearchInputParsing() +{ +#ifdef HAVE_NEPOMUK + m_searchInput->setParsingEnabled(m_contentButton->isChecked()); +#endif } void DolphinSearchBox::slotFacetsButtonToggled() @@ -306,6 +316,7 @@ void DolphinSearchBox::loadSettings() } m_facetsWidget->setVisible(SearchSettings::showFacetsWidget()); + updateSearchInputParsing(); } void DolphinSearchBox::saveSettings() @@ -329,15 +340,24 @@ void DolphinSearchBox::init() m_searchLabel = new QLabel(this); // Create search box +#ifdef HAVE_BALOO + m_queryParser.reset(new Baloo::NaturalFileQueryParser); + m_searchInput = new Baloo::QueryBuilder(m_queryParser.data(), this); + connect(m_searchInput, &Baloo::QueryBuilder::editingFinished, + this, &DolphinSearchBox::slotReturnPressed); + connect(m_searchInput, &Baloo::QueryBuilder::textChanged, + this, &DolphinSearchBox::slotSearchTextChanged); +#else m_searchInput = new KLineEdit(this); m_searchInput->installEventFilter(this); m_searchInput->setClearButtonShown(true); m_searchInput->setFont(KGlobalSettings::generalFont()); - setFocusProxy(m_searchInput); - connect(m_searchInput, static_cast<void(KLineEdit::*)(const QString&)>(&KLineEdit::returnPressed), + connect(m_searchInput, &KLineEdit::returnPressed, this, &DolphinSearchBox::slotReturnPressed); connect(m_searchInput, &KLineEdit::textChanged, this, &DolphinSearchBox::slotSearchTextChanged); +#endif + setFocusProxy(m_searchInput); // Apply layout for the search input QHBoxLayout* searchInputLayout = new QHBoxLayout(); @@ -358,6 +378,8 @@ void DolphinSearchBox::init() QButtonGroup* searchWhatGroup = new QButtonGroup(this); searchWhatGroup->addButton(m_fileNameButton); searchWhatGroup->addButton(m_contentButton); + connect(searchWhatGroup, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonClicked), + this, &DolphinSearchBox::updateSearchInputParsing); m_separator = new KSeparator(Qt::Vertical, this); @@ -434,28 +456,31 @@ KUrl DolphinSearchBox::balooUrlForSearching() const const QString text = m_searchInput->text(); Baloo::Query query; + + if (m_contentButton->isChecked()) { + query = m_queryParser->parse(text, Baloo::NaturalQueryParser::DetectFilenamePattern); + } else { + query.setTerm(Baloo::Term(QLatin1String("filename"), text)); + } + + // Configure the query so that it returns files and takes the rating into account query.addType("File"); query.addType(m_facetsWidget->facetType()); Baloo::Term term(Baloo::Term::And); - Baloo::Term ratingTerm = m_facetsWidget->ratingTerm(); + if (ratingTerm.isValid()) { + term.addSubTerm(query.term()); term.addSubTerm(ratingTerm); - } - if (m_contentButton->isChecked()) { - query.setSearchString(text); - } else if (!text.isEmpty()) { - term.addSubTerm(Baloo::Term(QLatin1String("filename"), text)); + query.setTerm(term); } if (m_fromHereButton->isChecked()) { query.addCustomOption("includeFolder", m_searchPath.toLocalFile()); } - query.setTerm(term); - return query.toSearchUrl(i18nc("@title UDS_DISPLAY_NAME for a KIO directory listing. %1 is the query the user entered.", "Query Results from '%1'", text)); #else |
