┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2011-03-10 23:17:55 +0100
committerPeter Penz <[email protected]>2011-03-10 23:21:42 +0100
commit984c20161bc71684325a1394cfbb292683c94d53 (patch)
tree8be45dd133b78acb2acbfa65a9d1bb49d8cf60be
parent6e0583f9888fcf46bb89735423b02b5ca53f1459 (diff)
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.
-rw-r--r--src/dolphinmainwindow.cpp15
-rw-r--r--src/panels/search/searchpanel.cpp93
-rw-r--r--src/panels/search/searchpanel.h20
-rw-r--r--src/search/dolphinsearchbox.cpp31
4 files changed, 102 insertions, 57 deletions
diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp
index f9c9bf0df..482a5b7e8 100644
--- a/src/dolphinmainwindow.cpp
+++ b/src/dolphinmainwindow.cpp
@@ -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
diff --git a/src/panels/search/searchpanel.cpp b/src/panels/search/searchpanel.cpp
index bfcaeacb7..21057f388 100644
--- a/src/panels/search/searchpanel.cpp
+++ b/src/panels/search/searchpanel.cpp
@@ -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;
- m_lastSetUrlStatJob = KIO::stat(url(), KIO::HideProgressInfo);
- connect(m_lastSetUrlStatJob, SIGNAL(result(KJob*)),
- this, SLOT(slotSetUrlStatFinished(KJob*)));
+ 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);
- }
+ const bool block = m_facetWidget->blockSignals(true);
+ m_unfacetedRestQuery = m_facetWidget->extractFacetsFromQuery(query);
+ m_facetWidget->setClientQuery(query);
+ m_facetWidget->blockSignals(block);
}
diff --git a/src/panels/search/searchpanel.h b/src/panels/search/searchpanel.h
index 2e0ef669b..9404b4f8c 100644
--- a/src/panels/search/searchpanel.h
+++ b/src/panels/search/searchpanel.h
@@ -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;
diff --git a/src/search/dolphinsearchbox.cpp b/src/search/dolphinsearchbox.cpp
index 8119e821f..17a691e44 100644
--- a/src/search/dolphinsearchbox.cpp
+++ b/src/search/dolphinsearchbox.cpp
@@ -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()) {
- QString regex = QRegExp::escape(text);
- regex.replace("\\*", QLatin1String(".*"));
- regex.replace("\\?", QLatin1String("."));
- regex.replace("\\", "\\\\");
- andTerm.addSubTerm(Nepomuk::Query::ComparisonTerm(
- Nepomuk::Vocabulary::NFO::fileName(),
- Nepomuk::Query::LiteralTerm(regex),
- Nepomuk::Query::ComparisonTerm::Regexp));
- } else {
+
+ // Search the text in the filename in any case
+ QString regex = QRegExp::escape(text);
+ regex.replace("\\*", QLatin1String(".*"));
+ regex.replace("\\?", QLatin1String("."));
+ regex.replace("\\", "\\\\");
+ orTerm.addSubTerm(Nepomuk::Query::ComparisonTerm(
+ Nepomuk::Vocabulary::NFO::fileName(),
+ Nepomuk::Query::LiteralTerm(regex),
+ Nepomuk::Query::ComparisonTerm::Regexp));
+
+ 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);