X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/de3e2ae40f626c1368dfd40bace54ef3e7815833..1fac8a7bbac28ea871f0a95dfe0b7d6ddcb2512a:/src/search/dolphinsearchbox.cpp diff --git a/src/search/dolphinsearchbox.cpp b/src/search/dolphinsearchbox.cpp index ae93030ac..524c4462f 100644 --- a/src/search/dolphinsearchbox.cpp +++ b/src/search/dolphinsearchbox.cpp @@ -22,16 +22,14 @@ #include "dolphin_searchsettings.h" #include "dolphinfacetswidget.h" -#include -#include -#include +#include +#include +#include #include -#include #include #include #include -#include #include #include #include @@ -39,6 +37,7 @@ #include #include #include +#include #include #ifdef HAVE_BALOO @@ -46,6 +45,7 @@ #include #include #endif +#include DolphinSearchBox::DolphinSearchBox(QWidget* parent) : QWidget(parent), @@ -82,7 +82,7 @@ QString DolphinSearchBox::text() const return m_searchInput->text(); } -void DolphinSearchBox::setSearchPath(const KUrl& url) +void DolphinSearchBox::setSearchPath(const QUrl& url) { m_searchPath = url; @@ -94,7 +94,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(); } } @@ -114,14 +114,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; @@ -130,10 +130,12 @@ KUrl DolphinSearchBox::urlForSearching() const if (useBalooSearch) { url = balooUrlForSearching(); } else { - url.setProtocol("filenamesearch"); - url.addQueryItem("search", m_searchInput->text()); + url.setScheme("filenamesearch"); + + QUrlQuery query; + query.addQueryItem("search", m_searchInput->text()); if (m_contentButton->isChecked()) { - url.addQueryItem("checkContent", "yes"); + query.addQueryItem("checkContent", "yes"); } QString encodedUrl; @@ -145,21 +147,23 @@ KUrl DolphinSearchBox::urlForSearching() const } else { encodedUrl = m_searchPath.url(); } - url.addQueryItem("url", encodedUrl); + query.addQueryItem("url", encodedUrl); + + url.setQuery(query); } 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& queryItems = url.queryItems(); - setText(queryItems.value("search")); - setSearchPath(queryItems.value("url")); - m_contentButton->setChecked(queryItems.value("checkContent") == "yes"); + } else if (url.scheme() == "filenamesearch") { + const QUrlQuery query(url); + setText(query.queryItemValue("search")); + setSearchPath(QUrl::fromUserInput(query.queryItemValue("url"), QString(), QUrl::AssumeLocalFile)); + m_contentButton->setChecked(query.queryItemValue("checkContent") == "yes"); } else { setText(QString()); setSearchPath(url); @@ -254,6 +258,7 @@ void DolphinSearchBox::slotConfigurationChanged() void DolphinSearchBox::slotSearchTextChanged(const QString& text) { + if (text.isEmpty()) { m_startSearchTimer->stop(); } else { @@ -262,10 +267,10 @@ void DolphinSearchBox::slotSearchTextChanged(const QString& text) emit searchTextChanged(text); } -void DolphinSearchBox::slotReturnPressed(const QString& text) +void DolphinSearchBox::slotReturnPressed() { emitSearchRequest(); - emit returnPressed(text); + emit returnPressed(); } void DolphinSearchBox::slotFacetsButtonToggled() @@ -313,7 +318,7 @@ void DolphinSearchBox::saveSettings() SearchSettings::setLocation(m_fromHereButton->isChecked() ? "FromHere" : "Everywhere"); SearchSettings::setWhat(m_fileNameButton->isChecked() ? "FileName" : "Content"); SearchSettings::setShowFacetsWidget(m_facetsToggleButton->isChecked()); - SearchSettings::self()->writeConfig(); + SearchSettings::self()->save(); } void DolphinSearchBox::init() @@ -321,7 +326,7 @@ void DolphinSearchBox::init() // Create close button QToolButton* closeButton = new QToolButton(this); closeButton->setAutoRaise(true); - closeButton->setIcon(KIcon("dialog-close")); + closeButton->setIcon(QIcon::fromTheme("dialog-close")); closeButton->setToolTip(i18nc("@info:tooltip", "Quit searching")); connect(closeButton, &QToolButton::clicked, this, &DolphinSearchBox::emitCloseRequest); @@ -329,15 +334,15 @@ void DolphinSearchBox::init() m_searchLabel = new QLabel(this); // Create search box - m_searchInput = new KLineEdit(this); + m_searchInput = new QLineEdit(this); m_searchInput->installEventFilter(this); - m_searchInput->setClearButtonShown(true); - m_searchInput->setFont(KGlobalSettings::generalFont()); - setFocusProxy(m_searchInput); - connect(m_searchInput, static_cast(&KLineEdit::returnPressed), + m_searchInput->setClearButtonEnabled(true); + m_searchInput->setFont(QFontDatabase::systemFont(QFontDatabase::GeneralFont)); + connect(m_searchInput, &QLineEdit::returnPressed, this, &DolphinSearchBox::slotReturnPressed); - connect(m_searchInput, &KLineEdit::textChanged, + connect(m_searchInput, &QLineEdit::textChanged, this, &DolphinSearchBox::slotSearchTextChanged); + setFocusProxy(m_searchInput); // Apply layout for the search input QHBoxLayout* searchInputLayout = new QHBoxLayout(); @@ -428,7 +433,7 @@ void DolphinSearchBox::init() updateFacetsToggleButton(); } -KUrl DolphinSearchBox::balooUrlForSearching() const +QUrl DolphinSearchBox::balooUrlForSearching() const { #ifdef HAVE_BALOO const QString text = m_searchInput->text(); @@ -451,7 +456,7 @@ KUrl DolphinSearchBox::balooUrlForSearching() const } if (m_fromHereButton->isChecked()) { - query.addCustomOption("includeFolder", m_searchPath.toLocalFile()); + query.setIncludeFolder(m_searchPath.toLocalFile()); } query.setTerm(term); @@ -459,11 +464,11 @@ KUrl DolphinSearchBox::balooUrlForSearching() const 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); @@ -473,16 +478,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(QUrl::fromLocalFile(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 @@ -502,6 +505,8 @@ void DolphinSearchBox::fromBalooSearchUrl(const KUrl& url) m_startSearchTimer->stop(); blockSignals(false); +#else + Q_UNUSED(url); #endif } @@ -509,7 +514,7 @@ void DolphinSearchBox::updateFacetsToggleButton() { const bool facetsIsVisible = SearchSettings::showFacetsWidget(); m_facetsToggleButton->setChecked(facetsIsVisible ? true : false); - m_facetsToggleButton->setIcon(KIcon(facetsIsVisible ? "arrow-up-double" : "arrow-down-double")); + m_facetsToggleButton->setIcon(QIcon::fromTheme(facetsIsVisible ? "arrow-up-double" : "arrow-down-double")); m_facetsToggleButton->setText(facetsIsVisible ? i18nc("action:button", "Fewer Options") : i18nc("action:button", "More Options")); }