diff --git a/src/search/dolphinsearchbox.h b/src/search/dolphinsearchbox.h --- a/src/search/dolphinsearchbox.h +++ b/src/search/dolphinsearchbox.h @@ -62,8 +62,8 @@ QString text() const; /** - * Sets the current path that is used as root for - * searching files, if "From Here" has been selected. + * Sets the current path that is used as root for searching files. + * If @url is the Home dir, "From Here" is selected instead. */ void setSearchPath(const QUrl& url); QUrl searchPath() const; diff --git a/src/search/dolphinsearchbox.cpp b/src/search/dolphinsearchbox.cpp --- a/src/search/dolphinsearchbox.cpp +++ b/src/search/dolphinsearchbox.cpp @@ -85,34 +85,36 @@ return; } + const QUrl cleanedUrl = url.adjusted(QUrl::RemoveUserInfo | QUrl::StripTrailingSlash); + + if (cleanedUrl.path() == QDir::homePath()) { + m_fromHereButton->setChecked(false); + m_everywhereButton->setChecked(true); + if (!m_searchPath.isEmpty()) { + return; + } + } else { + m_everywhereButton->setChecked(false); + m_fromHereButton->setChecked(true); + } + m_searchPath = url; QFontMetrics metrics(m_fromHereButton->font()); const int maxWidth = metrics.height() * 8; - const QUrl cleanedUrl = url.adjusted(QUrl::RemoveUserInfo | QUrl::StripTrailingSlash); QString location = cleanedUrl.fileName(); if (location.isEmpty()) { location = cleanedUrl.toString(QUrl::PreferLocalFile); } - if (m_fromHereButton->isChecked() && cleanedUrl.path() == QDir::homePath()) { - m_fromHereButton->setChecked(false); - m_everywhereButton->setChecked(true); - } else { - m_fromHereButton->setChecked(true); - m_everywhereButton->setChecked(false); - } - const QString elidedLocation = metrics.elidedText(location, Qt::ElideMiddle, maxWidth); m_fromHereButton->setText(i18nc("action:button", "From Here (%1)", elidedLocation)); m_fromHereButton->setToolTip(i18nc("action:button", "Limit search to '%1' and its subfolders", cleanedUrl.toString(QUrl::PreferLocalFile))); - - m_facetsWidget->setEnabled(isIndexingEnabled()); } QUrl DolphinSearchBox::searchPath() const { - return m_searchPath; + return m_everywhereButton->isChecked() ? QUrl::fromLocalFile(QDir::homePath()) : m_searchPath; } QUrl DolphinSearchBox::urlForSearching() const @@ -155,8 +157,11 @@ m_contentButton->setChecked(query.queryItemValue(QStringLiteral("checkContent")) == QLatin1String("yes")); } else { setText(QString()); + m_searchPath = QUrl(); setSearchPath(url); } + + m_facetsWidget->setEnabled(isIndexingEnabled()); } void DolphinSearchBox::selectAll() @@ -561,7 +566,7 @@ { #ifdef HAVE_BALOO const Baloo::IndexerConfig searchInfo; - return searchInfo.fileIndexingEnabled() && searchInfo.shouldBeIndexed(m_searchPath.toLocalFile()); + return searchInfo.fileIndexingEnabled() && searchInfo.shouldBeIndexed(searchPath().toLocalFile()); #else return false; #endif