mirror of
https://invent.kde.org/system/dolphin
synced 2024-11-05 18:47:12 +00:00
Add search modes for the Search Panel
The search panel must get a hint whether clicking on the facets should result in searching everywhere or from the current folder. It is not sufficient to check the search-settings of the "Find:"-box, as when the "Find:"-box is invisible there is no hint for the user what kind of searching is done and the setting must be ignored.
This commit is contained in:
parent
6e0583f988
commit
984c20161b
4 changed files with 102 additions and 57 deletions
|
@ -51,6 +51,7 @@
|
|||
|
||||
#include "dolphin_generalsettings.h"
|
||||
#include "dolphin_iconsmodesettings.h"
|
||||
#include "dolphin_searchsettings.h"
|
||||
|
||||
#include <KAction>
|
||||
#include <KActionCollection>
|
||||
|
@ -1247,6 +1248,20 @@ void DolphinMainWindow::slotSearchModeChanged(bool enabled)
|
|||
}
|
||||
m_searchDockIsTemporaryVisible = false;
|
||||
}
|
||||
|
||||
SearchPanel* searchPanel = qobject_cast<SearchPanel*>(searchDock->widget());
|
||||
if (searchPanel) {
|
||||
// Per default any search-operation triggered by the Search Panel is done
|
||||
// "Everywhere".
|
||||
SearchPanel::SearchMode searchMode = SearchPanel::Everywhere;
|
||||
|
||||
if (enabled && (SearchSettings::location() == QLatin1String("FromHere"))) {
|
||||
// Only if the search-mode is enabled it is visible for the user whether
|
||||
// a searching is done "Everywhere" or "From Here" (= current directory).
|
||||
searchMode = SearchPanel::FromCurrentDir;
|
||||
}
|
||||
searchPanel->setSearchMode(searchMode);
|
||||
}
|
||||
#else
|
||||
Q_UNUSED(enabled);
|
||||
#endif
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
SearchPanel::SearchPanel(QWidget* parent) :
|
||||
Panel(parent),
|
||||
m_initialized(false),
|
||||
m_searchMode(Everywhere),
|
||||
m_lastSetUrlStatJob(0),
|
||||
m_startedFromDir(),
|
||||
m_facetWidget(0),
|
||||
|
@ -62,13 +63,28 @@ SearchPanel::~SearchPanel()
|
|||
{
|
||||
}
|
||||
|
||||
void SearchPanel::setSearchMode(SearchMode mode)
|
||||
{
|
||||
m_searchMode = mode;
|
||||
}
|
||||
|
||||
SearchPanel::SearchMode SearchPanel::searchMode() const
|
||||
{
|
||||
return m_searchMode;
|
||||
}
|
||||
|
||||
bool SearchPanel::urlChanged()
|
||||
{
|
||||
if (!url().protocol().startsWith(QLatin1String("nepomuk"))) {
|
||||
const bool isNepomukUrl = url().protocol().startsWith(QLatin1String("nepomuk"));
|
||||
if (!isNepomukUrl) {
|
||||
// Remember the current directory before a searching is started.
|
||||
// This is required to restore the directory in case that all facets
|
||||
// have been reset by the user (see slotQueryTermChanged()).
|
||||
m_startedFromDir = url();
|
||||
|
||||
const DolphinSearchInformation& searchInfo = DolphinSearchInformation::instance();
|
||||
setEnabled(searchInfo.isIndexingEnabled() &&
|
||||
searchInfo.isPathIndexed(m_startedFromDir));
|
||||
}
|
||||
|
||||
if (isVisible() && DolphinSearchInformation::instance().isIndexingEnabled()) {
|
||||
|
@ -79,14 +95,19 @@ bool SearchPanel::urlChanged()
|
|||
return true;
|
||||
}
|
||||
|
||||
// Reset the current query and disable the facet-widget until
|
||||
// the new query has been determined by KIO::stat():
|
||||
setQuery(Nepomuk::Query::Query());
|
||||
delete m_lastSetUrlStatJob;
|
||||
|
||||
if (isNepomukUrl) {
|
||||
// Reset the current query and disable the facet-widget until
|
||||
// the new query has been determined by KIO::stat():
|
||||
m_lastSetUrlStatJob = KIO::stat(url(), KIO::HideProgressInfo);
|
||||
connect(m_lastSetUrlStatJob, SIGNAL(result(KJob*)),
|
||||
this, SLOT(slotSetUrlStatFinished(KJob*)));
|
||||
setEnabled(false);
|
||||
} else {
|
||||
// Reset the search panel because a "normal" directory is shown.
|
||||
setQuery(Nepomuk::Query::Query());
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -141,21 +162,12 @@ void SearchPanel::showEvent(QShowEvent* event)
|
|||
m_facetWidget->addFacet(Nepomuk::Utils::Facet::createRatingFacet());
|
||||
m_facetWidget->addFacet(Nepomuk::Utils::Facet::createTagFacet());
|
||||
|
||||
Q_ASSERT(!m_lastSetUrlStatJob);
|
||||
m_lastSetUrlStatJob = KIO::stat(url(), KIO::HideProgressInfo);
|
||||
connect(m_lastSetUrlStatJob, SIGNAL(result(KJob*)),
|
||||
this, SLOT(slotSetUrlStatFinished(KJob*)));
|
||||
|
||||
connect(m_facetWidget, SIGNAL(queryTermChanged(Nepomuk::Query::Term)),
|
||||
this, SLOT(slotQueryTermChanged(Nepomuk::Query::Term)));
|
||||
|
||||
m_initialized = true;
|
||||
}
|
||||
|
||||
const DolphinSearchInformation& searchInfo = DolphinSearchInformation::instance();
|
||||
setEnabled(searchInfo.isIndexingEnabled() &&
|
||||
searchInfo.isPathIndexed(m_startedFromDir));
|
||||
|
||||
Panel::showEvent(event);
|
||||
}
|
||||
|
||||
|
@ -184,6 +196,10 @@ void SearchPanel::slotSetUrlStatFinished(KJob* job)
|
|||
{
|
||||
m_lastSetUrlStatJob = 0;
|
||||
|
||||
const DolphinSearchInformation& searchInfo = DolphinSearchInformation::instance();
|
||||
setEnabled(searchInfo.isIndexingEnabled() &&
|
||||
searchInfo.isPathIndexed(m_startedFromDir));
|
||||
|
||||
const KIO::UDSEntry uds = static_cast<KIO::StatJob*>(job)->statResult();
|
||||
const QString nepomukQueryStr = uds.stringValue(KIO::UDSEntry::UDS_NEPOMUK_QUERY);
|
||||
const Nepomuk::Query::Term facetQueryTerm = m_facetWidget->queryTerm();
|
||||
|
@ -191,17 +207,7 @@ void SearchPanel::slotSetUrlStatFinished(KJob* job)
|
|||
if (!nepomukQueryStr.isEmpty()) {
|
||||
// Always merge the query that has been retrieved by SearchPanel::setUrl() with
|
||||
// the current facet-query, so that the user settings don't get lost.
|
||||
nepomukQuery = Nepomuk::Query::Query::fromString(nepomukQueryStr) && facetQueryTerm;
|
||||
} else if (url().isLocalFile()) {
|
||||
// Fallback query for local file URLs: List all files
|
||||
Nepomuk::Query::ComparisonTerm compTerm(
|
||||
Nepomuk::Vocabulary::NFO::fileName(),
|
||||
Nepomuk::Query::Term());
|
||||
nepomukQuery.setFileMode(Nepomuk::Query::FileQuery::QueryFiles);
|
||||
if (SearchSettings::location() == QLatin1String("FromHere")) {
|
||||
nepomukQuery.addIncludeFolder(url(), true);
|
||||
}
|
||||
nepomukQuery.setTerm(compTerm);
|
||||
nepomukQuery = Nepomuk::Query::Query::fromString(nepomukQueryStr) && m_facetWidget->queryTerm();
|
||||
}
|
||||
|
||||
setQuery(nepomukQuery);
|
||||
|
@ -216,6 +222,20 @@ void SearchPanel::slotQueryTermChanged(const Nepomuk::Query::Term& term)
|
|||
{
|
||||
if (term.isValid()) {
|
||||
// Default case: A facet has been changed by the user to restrict the query.
|
||||
if ((m_searchMode == FromCurrentDir) && !m_unfacetedRestQuery.isValid()) {
|
||||
// Adjust the query to respect the FromCurrentDir setting
|
||||
Nepomuk::Query::ComparisonTerm compTerm(
|
||||
Nepomuk::Vocabulary::NFO::fileName(),
|
||||
Nepomuk::Query::Term());
|
||||
|
||||
Nepomuk::Query::FileQuery subDirsQuery;
|
||||
subDirsQuery.setFileMode(Nepomuk::Query::FileQuery::QueryFiles);
|
||||
subDirsQuery.addIncludeFolder(m_startedFromDir, true);
|
||||
subDirsQuery.setTerm(compTerm);
|
||||
|
||||
setQuery(subDirsQuery);
|
||||
}
|
||||
|
||||
Nepomuk::Query::FileQuery query(m_unfacetedRestQuery && term);
|
||||
emit urlActivated(query.toSearchUrl());
|
||||
return;
|
||||
|
@ -241,19 +261,8 @@ void SearchPanel::slotQueryTermChanged(const Nepomuk::Query::Term& term)
|
|||
|
||||
void SearchPanel::setQuery(const Nepomuk::Query::Query& query)
|
||||
{
|
||||
if (query.isValid()) {
|
||||
const bool block = m_facetWidget->blockSignals(true);
|
||||
|
||||
m_unfacetedRestQuery = m_facetWidget->extractFacetsFromQuery(query);
|
||||
m_facetWidget->setClientQuery(query);
|
||||
|
||||
const DolphinSearchInformation& searchInfo = DolphinSearchInformation::instance();
|
||||
setEnabled(searchInfo.isIndexingEnabled() &&
|
||||
searchInfo.isPathIndexed(m_startedFromDir));
|
||||
|
||||
m_facetWidget->blockSignals(block);
|
||||
} else {
|
||||
m_unfacetedRestQuery = Nepomuk::Query::Query();
|
||||
setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,16 +32,33 @@ namespace Nepomuk {
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Allows the filtering of search results.
|
||||
* @brief Allows to search for files by enabling generic search patterns (= facets).
|
||||
*
|
||||
* For example it is possible to search for images, documents or specific tags.
|
||||
* The search panel can be adjusted to search only from the current folder or everywhere.
|
||||
*/
|
||||
class SearchPanel : public Panel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum SearchMode
|
||||
{
|
||||
Everywhere,
|
||||
FromCurrentDir
|
||||
};
|
||||
|
||||
SearchPanel(QWidget* parent = 0);
|
||||
virtual ~SearchPanel();
|
||||
|
||||
/**
|
||||
* Specifies whether a searching is done in all folders (= Everywhere)
|
||||
* or from the current directory (= FromCurrentDir). The current directory
|
||||
* is automatically determined when setUrl() has been called.
|
||||
*/
|
||||
void setSearchMode(SearchMode mode);
|
||||
SearchMode searchMode() const;
|
||||
|
||||
signals:
|
||||
void urlActivated(const KUrl& url);
|
||||
|
||||
|
@ -67,6 +84,7 @@ private:
|
|||
|
||||
private:
|
||||
bool m_initialized;
|
||||
SearchMode m_searchMode;
|
||||
KJob* m_lastSetUrlStatJob;
|
||||
|
||||
KUrl m_startedFromDir;
|
||||
|
|
|
@ -42,9 +42,9 @@
|
|||
|
||||
#include <config-nepomuk.h>
|
||||
#ifdef HAVE_NEPOMUK
|
||||
#include <Nepomuk/Query/AndTerm>
|
||||
#include <Nepomuk/Query/FileQuery>
|
||||
#include <Nepomuk/Query/LiteralTerm>
|
||||
#include <Nepomuk/Query/OrTerm>
|
||||
#include <Nepomuk/Query/Query>
|
||||
#include <Nepomuk/Query/QueryParser>
|
||||
#include <Nepomuk/Query/ResourceTypeTerm>
|
||||
|
@ -349,28 +349,31 @@ void DolphinSearchBox::init()
|
|||
KUrl DolphinSearchBox::nepomukUrlForSearching() const
|
||||
{
|
||||
#ifdef HAVE_NEPOMUK
|
||||
Nepomuk::Query::AndTerm andTerm;
|
||||
Nepomuk::Query::OrTerm orTerm;
|
||||
|
||||
const QString text = m_searchInput->text();
|
||||
if (m_fileNameButton->isChecked()) {
|
||||
|
||||
// Search the text in the filename in any case
|
||||
QString regex = QRegExp::escape(text);
|
||||
regex.replace("\\*", QLatin1String(".*"));
|
||||
regex.replace("\\?", QLatin1String("."));
|
||||
regex.replace("\\", "\\\\");
|
||||
andTerm.addSubTerm(Nepomuk::Query::ComparisonTerm(
|
||||
orTerm.addSubTerm(Nepomuk::Query::ComparisonTerm(
|
||||
Nepomuk::Vocabulary::NFO::fileName(),
|
||||
Nepomuk::Query::LiteralTerm(regex),
|
||||
Nepomuk::Query::ComparisonTerm::Regexp));
|
||||
} else {
|
||||
|
||||
if (m_contentButton->isChecked()) {
|
||||
// Search the text also in the content of the files
|
||||
const Nepomuk::Query::Query customQuery = Nepomuk::Query::QueryParser::parseQuery(text, Nepomuk::Query::QueryParser::DetectFilenamePattern);
|
||||
if (customQuery.isValid()) {
|
||||
andTerm.addSubTerm(customQuery.term());
|
||||
orTerm.addSubTerm(customQuery.term());
|
||||
}
|
||||
}
|
||||
|
||||
Nepomuk::Query::FileQuery fileQuery;
|
||||
fileQuery.setFileMode(Nepomuk::Query::FileQuery::QueryFilesAndFolders);
|
||||
fileQuery.setTerm(andTerm);
|
||||
fileQuery.setTerm(orTerm);
|
||||
if (m_fromHereButton->isChecked()) {
|
||||
const bool recursive = true;
|
||||
fileQuery.addIncludeFolder(m_searchPath, recursive);
|
||||
|
|
Loading…
Reference in a new issue