┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/search/dolphinsearchbox.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/search/dolphinsearchbox.cpp')
-rw-r--r--src/search/dolphinsearchbox.cpp77
1 files changed, 51 insertions, 26 deletions
diff --git a/src/search/dolphinsearchbox.cpp b/src/search/dolphinsearchbox.cpp
index 46ca01a4c..0ab4d86cd 100644
--- a/src/search/dolphinsearchbox.cpp
+++ b/src/search/dolphinsearchbox.cpp
@@ -26,6 +26,7 @@
#include <KLineEdit>
#include <KLocale>
#include <KSeparator>
+#include <KGlobalSettings>
#include <QButtonGroup>
#include <QDir>
@@ -39,11 +40,12 @@
#include <QToolButton>
#include <QVBoxLayout>
-#include <config-baloo.h>
#ifdef HAVE_BALOO
- #include <baloo/query.h>
- #include <baloo/term.h>
- #include <baloo/indexerconfig.h>
+ #include <Baloo/NaturalFileQueryParser>
+ #include <Baloo/QueryBuilder>
+ #include <Baloo/Query>
+ #include <Baloo/Term>
+ #include <Baloo/IndexerConfig>
#endif
DolphinSearchBox::DolphinSearchBox(QWidget* parent) :
@@ -251,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 {
@@ -261,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_BALOO
+ m_searchInput->setParsingEnabled(m_contentButton->isChecked());
+#endif
}
void DolphinSearchBox::slotFacetsButtonToggled()
@@ -287,7 +298,7 @@ void DolphinSearchBox::initButton(QToolButton* button)
button->setAutoExclusive(true);
button->setAutoRaise(true);
button->setCheckable(true);
- connect(button, SIGNAL(clicked(bool)), this, SLOT(slotConfigurationChanged()));
+ connect(button, &QToolButton::clicked, this, &DolphinSearchBox::slotConfigurationChanged);
}
void DolphinSearchBox::loadSettings()
@@ -305,6 +316,7 @@ void DolphinSearchBox::loadSettings()
}
m_facetsWidget->setVisible(SearchSettings::showFacetsWidget());
+ updateSearchInputParsing();
}
void DolphinSearchBox::saveSettings()
@@ -322,21 +334,30 @@ void DolphinSearchBox::init()
closeButton->setAutoRaise(true);
closeButton->setIcon(KIcon("dialog-close"));
closeButton->setToolTip(i18nc("@info:tooltip", "Quit searching"));
- connect(closeButton, SIGNAL(clicked()), this, SLOT(emitCloseRequest()));
+ connect(closeButton, &QToolButton::clicked, this, &DolphinSearchBox::emitCloseRequest);
// Create search label
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());
+ connect(m_searchInput, &KLineEdit::returnPressed,
+ this, &DolphinSearchBox::slotReturnPressed);
+ connect(m_searchInput, &KLineEdit::textChanged,
+ this, &DolphinSearchBox::slotSearchTextChanged);
+#endif
setFocusProxy(m_searchInput);
- connect(m_searchInput, SIGNAL(returnPressed(QString)),
- this, SLOT(slotReturnPressed(QString)));
- connect(m_searchInput, SIGNAL(textChanged(QString)),
- this, SLOT(slotSearchTextChanged(QString)));
// Apply layout for the search input
QHBoxLayout* searchInputLayout = new QHBoxLayout();
@@ -357,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);
@@ -377,12 +400,12 @@ void DolphinSearchBox::init()
m_facetsToggleButton = new QToolButton(this);
m_facetsToggleButton->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
initButton(m_facetsToggleButton);
- connect(m_facetsToggleButton, SIGNAL(clicked()), this, SLOT(slotFacetsButtonToggled()));
+ connect(m_facetsToggleButton, &QToolButton::clicked, this, &DolphinSearchBox::slotFacetsButtonToggled);
m_facetsWidget = new DolphinFacetsWidget(this);
m_facetsWidget->installEventFilter(this);
m_facetsWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
- connect(m_facetsWidget, SIGNAL(facetChanged()), this, SLOT(slotFacetChanged()));
+ connect(m_facetsWidget, &DolphinFacetsWidget::facetChanged, this, &DolphinSearchBox::slotFacetChanged);
// Apply layout for the options
QHBoxLayout* optionsLayout = new QHBoxLayout();
@@ -422,7 +445,7 @@ void DolphinSearchBox::init()
m_startSearchTimer = new QTimer(this);
m_startSearchTimer->setSingleShot(true);
m_startSearchTimer->setInterval(1000);
- connect(m_startSearchTimer, SIGNAL(timeout()), this, SLOT(emitSearchRequest()));
+ connect(m_startSearchTimer, &QTimer::timeout, this, &DolphinSearchBox::emitSearchRequest);
updateFacetsToggleButton();
}
@@ -433,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
@@ -472,7 +498,7 @@ void DolphinSearchBox::fromBalooSearchUrl(const KUrl& url)
// while we adjust the search text and the facet widget.
blockSignals(true);
- const QVariantHash customOptions = query.customOptions();
+ const QVariantMap customOptions = query.customOptions();
if (customOptions.contains("includeFolder")) {
setSearchPath(customOptions.value("includeFolder").toString());
} else {
@@ -512,4 +538,3 @@ void DolphinSearchBox::updateFacetsToggleButton()
m_facetsToggleButton->setText(facetsIsVisible ? i18nc("action:button", "Fewer Options") : i18nc("action:button", "More Options"));
}
-#include "dolphinsearchbox.moc"