]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/search/dolphinsearchbox.cpp
Revert "Use the Baloo Query Builder widget to add syntax-highlighting in Dolphin...
[dolphin.git] / src / search / dolphinsearchbox.cpp
index de73c2c42d67ed34158502c20a21b3bdca410f5f..9e908de5d852283458407e88957b752ad5edab99 100644 (file)
 #include "dolphinfacetswidget.h"
 
 #include <QIcon>
-#include <KLineEdit>
-#include <KLocale>
+#include <QLineEdit>
+#include <KLocalizedString>
 #include <KSeparator>
-#include <KGlobalSettings>
 
 #include <QButtonGroup>
 #include <QDir>
 #include <QEvent>
-#include <QFormLayout>
 #include <QHBoxLayout>
 #include <QKeyEvent>
 #include <QLabel>
@@ -40,9 +38,8 @@
 #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>
@@ -84,7 +81,7 @@ QString DolphinSearchBox::text() const
     return m_searchInput->text();
 }
 
-void DolphinSearchBox::setSearchPath(const KUrl& url)
+void DolphinSearchBox::setSearchPath(const QUrl& url)
 {
     m_searchPath = url;
 
@@ -96,7 +93,7 @@ void DolphinSearchBox::setSearchPath(const KUrl& url)
         if (url.isLocalFile()) {
             location = QLatin1String("/");
         } else {
-            location = url.protocol() + QLatin1String(" - ") + url.host();
+            location = url.scheme() + QLatin1String(" - ") + url.host();
         }
     }
 
@@ -116,14 +113,14 @@ void DolphinSearchBox::setSearchPath(const KUrl& url)
     m_facetsWidget->setEnabled(hasFacetsSupport);
 }
 
-KUrl DolphinSearchBox::searchPath() const
+QUrl DolphinSearchBox::searchPath() const
 {
     return m_searchPath;
 }
 
-KUrl DolphinSearchBox::urlForSearching() const
+QUrl DolphinSearchBox::urlForSearching() const
 {
-    KUrl url;
+    QUrl url;
     bool useBalooSearch = false;
 #ifdef HAVE_BALOO
     const Baloo::IndexerConfig searchInfo;
@@ -132,7 +129,7 @@ KUrl DolphinSearchBox::urlForSearching() const
     if (useBalooSearch) {
         url = balooUrlForSearching();
     } else {
-        url.setProtocol("filenamesearch");
+        url.setScheme("filenamesearch");
         url.addQueryItem("search", m_searchInput->text());
         if (m_contentButton->isChecked()) {
             url.addQueryItem("checkContent", "yes");
@@ -153,15 +150,14 @@ KUrl DolphinSearchBox::urlForSearching() const
     return url;
 }
 
-void DolphinSearchBox::fromSearchUrl(const KUrl& url)
+void DolphinSearchBox::fromSearchUrl(const QUrl& url)
 {
-    if (url.protocol() == "baloosearch") {
+    if (url.scheme() == "baloosearch") {
         fromBalooSearchUrl(url);
-    } else if (url.protocol() == "filenamesearch") {
-        const QMap<QString, QString>& queryItems = url.queryItems();
-        setText(queryItems.value("search"));
-        setSearchPath(queryItems.value("url"));
-        m_contentButton->setChecked(queryItems.value("checkContent") == "yes");
+    } else if (url.scheme() == "filenamesearch") {
+        setText(url.queryItemValue("search"));
+        setSearchPath(url.queryItemValue("url"));
+        m_contentButton->setChecked(url.queryItemValue("checkContent") == "yes");
     } else {
         setText(QString());
         setSearchPath(url);
@@ -254,9 +250,8 @@ void DolphinSearchBox::slotConfigurationChanged()
     }
 }
 
-void DolphinSearchBox::slotSearchTextChanged()
+void DolphinSearchBox::slotSearchTextChanged(const QString& text)
 {
-    const QString text = m_searchInput->text();
 
     if (text.isEmpty()) {
         m_startSearchTimer->stop();
@@ -269,14 +264,7 @@ void DolphinSearchBox::slotSearchTextChanged()
 void DolphinSearchBox::slotReturnPressed()
 {
     emitSearchRequest();
-    emit returnPressed(m_searchInput->text());
-}
-
-void DolphinSearchBox::updateSearchInputParsing()
-{
-#ifdef HAVE_BALOO
-    m_searchInput->setParsingEnabled(m_contentButton->isChecked());
-#endif
+    emit returnPressed();
 }
 
 void DolphinSearchBox::slotFacetsButtonToggled()
@@ -317,7 +305,6 @@ void DolphinSearchBox::loadSettings()
     }
 
     m_facetsWidget->setVisible(SearchSettings::showFacetsWidget());
-    updateSearchInputParsing();
 }
 
 void DolphinSearchBox::saveSettings()
@@ -341,23 +328,14 @@ 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 = new QLineEdit(this);
     m_searchInput->installEventFilter(this);
-    m_searchInput->setClearButtonShown(true);
+    m_searchInput->setClearButtonEnabled(true);
     m_searchInput->setFont(QFontDatabase::systemFont(QFontDatabase::GeneralFont));
-    connect(m_searchInput, &KLineEdit::returnPressed,
+    connect(m_searchInput, &QLineEdit::returnPressed,
             this, &DolphinSearchBox::slotReturnPressed);
-    connect(m_searchInput, &KLineEdit::textChanged,
+    connect(m_searchInput, &QLineEdit::textChanged,
             this, &DolphinSearchBox::slotSearchTextChanged);
-#endif
     setFocusProxy(m_searchInput);
 
     // Apply layout for the search input
@@ -379,8 +357,6 @@ 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);
 
@@ -451,45 +427,42 @@ void DolphinSearchBox::init()
     updateFacetsToggleButton();
 }
 
-KUrl DolphinSearchBox::balooUrlForSearching() const
+QUrl DolphinSearchBox::balooUrlForSearching() const
 {
 #ifdef HAVE_BALOO
     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();
 
+    Baloo::Term ratingTerm = m_facetsWidget->ratingTerm();
     if (ratingTerm.isValid()) {
-        term.addSubTerm(query.term());
         term.addSubTerm(ratingTerm);
+    }
 
-        query.setTerm(term);
+    if (m_contentButton->isChecked()) {
+        query.setSearchString(text);
+    } else if (!text.isEmpty()) {
+        term.addSubTerm(Baloo::Term(QLatin1String("filename"), text));
     }
 
     if (m_fromHereButton->isChecked()) {
-        query.addCustomOption("includeFolder", m_searchPath.toLocalFile());
+        query.setIncludeFolder(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
-    return KUrl();
+    return QUrl();
 #endif
 }
 
-void DolphinSearchBox::fromBalooSearchUrl(const KUrl& url)
+void DolphinSearchBox::fromBalooSearchUrl(const QUrl& url)
 {
 #ifdef HAVE_BALOO
     const Baloo::Query query = Baloo::Query::fromSearchUrl(url);
@@ -499,16 +472,14 @@ void DolphinSearchBox::fromBalooSearchUrl(const KUrl& url)
     // while we adjust the search text and the facet widget.
     blockSignals(true);
 
-    const QVariantMap customOptions = query.customOptions();
-    if (customOptions.contains("includeFolder")) {
-        setSearchPath(customOptions.value("includeFolder").toString());
+    const QString customDir = query.includeFolder();
+    if (!customDir.isEmpty()) {
+        setSearchPath(customDir);
     } else {
         setSearchPath(QDir::homePath());
     }
 
-    if (!query.searchString().isEmpty()) {
-        setText(query.searchString());
-    }
+    setText(query.searchString());
 
     QStringList types = query.types();
     types.removeOne("File"); // We are only interested in facet widget types
@@ -528,6 +499,8 @@ void DolphinSearchBox::fromBalooSearchUrl(const KUrl& url)
 
     m_startSearchTimer->stop();
     blockSignals(false);
+#else
+    Q_UNUSED(url);
 #endif
 }