┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/search
diff options
context:
space:
mode:
Diffstat (limited to 'src/search')
-rw-r--r--src/search/dolphinfacetswidget.cpp82
-rw-r--r--src/search/dolphinfacetswidget.h11
-rw-r--r--src/search/dolphinsearchbox.cpp86
-rw-r--r--src/search/dolphinsearchbox.h8
-rw-r--r--src/search/dolphinsearchinformation.cpp124
-rw-r--r--src/search/dolphinsearchinformation.h57
6 files changed, 73 insertions, 295 deletions
diff --git a/src/search/dolphinfacetswidget.cpp b/src/search/dolphinfacetswidget.cpp
index d786117c9..b7315a01c 100644
--- a/src/search/dolphinfacetswidget.cpp
+++ b/src/search/dolphinfacetswidget.cpp
@@ -27,18 +27,6 @@
#include <QHBoxLayout>
#include <QVBoxLayout>
-#ifdef HAVE_NEPOMUK
- #include <Nepomuk2/Query/AndTerm>
- #include <Nepomuk2/Query/ComparisonTerm>
- #include <Nepomuk2/Query/LiteralTerm>
- #include <Nepomuk2/Query/OrTerm>
- #include <Nepomuk2/Query/Query>
- #include <Nepomuk2/Query/ResourceTypeTerm>
- #include <Nepomuk2/Vocabulary/NFO>
- #include <Nepomuk2/Vocabulary/NIE>
- #include <Soprano/Vocabulary/NAO>
-#endif
-
DolphinFacetsWidget::DolphinFacetsWidget(QWidget* parent) :
QWidget(parent),
m_documents(0),
@@ -120,39 +108,9 @@ DolphinFacetsWidget::~DolphinFacetsWidget()
{
}
-#ifdef HAVE_NEPOMUK
-Nepomuk2::Query::Term DolphinFacetsWidget::facetsTerm() const
+#ifdef HAVE_BALOO
+Baloo::Term DolphinFacetsWidget::ratingTerm() const
{
- Nepomuk2::Query::AndTerm andTerm;
-
- const bool hasTypeFilter = m_documents->isChecked() ||
- m_images->isChecked() ||
- m_audio->isChecked() ||
- m_videos->isChecked();
- if (hasTypeFilter) {
- Nepomuk2::Query::OrTerm orTerm;
-
- if (m_documents->isChecked()) {
- orTerm.addSubTerm(Nepomuk2::Query::ResourceTypeTerm(Nepomuk2::Vocabulary::NFO::Document()));
- }
-
- if (m_images->isChecked()) {
- orTerm.addSubTerm(Nepomuk2::Query::ResourceTypeTerm(Nepomuk2::Vocabulary::NFO::Image()));
- }
-
- if (m_audio->isChecked()) {
- orTerm.addSubTerm(Nepomuk2::Query::ComparisonTerm(Nepomuk2::Vocabulary::NIE::mimeType(),
- Nepomuk2::Query::LiteralTerm("audio")));
- }
-
- if (m_videos->isChecked()) {
- orTerm.addSubTerm(Nepomuk2::Query::ComparisonTerm(Nepomuk2::Vocabulary::NIE::mimeType(),
- Nepomuk2::Query::LiteralTerm("video")));
- }
-
- andTerm.addSubTerm(orTerm);
- }
-
if (!m_anyRating->isChecked()) {
int stars = 1; // represents m_oneOrMore
if (m_twoOrMore->isChecked()) {
@@ -166,12 +124,15 @@ Nepomuk2::Query::Term DolphinFacetsWidget::facetsTerm() const
}
const int rating = stars * 2;
- Nepomuk2::Query::ComparisonTerm term(Soprano::Vocabulary::NAO::numericRating(),
- Nepomuk2::Query::LiteralTerm(rating),
- Nepomuk2::Query::ComparisonTerm::GreaterOrEqual);
- andTerm.addSubTerm(term);
+
+ Baloo::Term term("rating", rating, Baloo::Term::GreaterEqual);
+ return term;
}
+ return Baloo::Term();
+
+ /*
+ // FIXME: Handle date time filters
if (!m_anytime->isChecked()) {
QDate date = QDate::currentDate(); // represents m_today
if (m_yesterday->isChecked()) {
@@ -189,11 +150,34 @@ Nepomuk2::Query::Term DolphinFacetsWidget::facetsTerm() const
Nepomuk2::Query::ComparisonTerm::GreaterOrEqual);
andTerm.addSubTerm(term);
}
+ */
+}
+
+QStringList DolphinFacetsWidget::facetTypes() const
+{
+ QStringList types;
+ if (m_documents->isChecked()) {
+ types << "Document";
+ }
- return andTerm;
+ if (m_images->isChecked()) {
+ types << "Image";
+ }
+
+ if (m_audio->isChecked()) {
+ types << "Audio";
+ }
+
+ if (m_videos->isChecked()) {
+ types << "Video";
+ }
+
+ return types;
}
+
#endif
+
QCheckBox* DolphinFacetsWidget::createCheckBox(const QString& text)
{
QCheckBox* checkBox = new QCheckBox(text);
diff --git a/src/search/dolphinfacetswidget.h b/src/search/dolphinfacetswidget.h
index 57bed9e68..526fe1c79 100644
--- a/src/search/dolphinfacetswidget.h
+++ b/src/search/dolphinfacetswidget.h
@@ -22,9 +22,9 @@
#include <QWidget>
-#include <config-nepomuk.h>
-#ifdef HAVE_NEPOMUK
- #include <Nepomuk2/Query/Term>
+#include <config-baloo.h>
+#ifdef HAVE_BALOO
+ #include <baloo/term.h>
#endif
class QButtonGroup;
@@ -55,8 +55,9 @@ public:
explicit DolphinFacetsWidget(QWidget* parent = 0);
virtual ~DolphinFacetsWidget();
-#ifdef HAVE_NEPOMUK
- Nepomuk2::Query::Term facetsTerm() const;
+#ifdef HAVE_BALOO
+ Baloo::Term ratingTerm() const;
+ QStringList facetTypes() const;
#endif
signals:
diff --git a/src/search/dolphinsearchbox.cpp b/src/search/dolphinsearchbox.cpp
index cf1f0c8e5..e6377639b 100644
--- a/src/search/dolphinsearchbox.cpp
+++ b/src/search/dolphinsearchbox.cpp
@@ -21,7 +21,6 @@
#include "dolphin_searchsettings.h"
#include "dolphinfacetswidget.h"
-#include "dolphinsearchinformation.h"
#include <KIcon>
#include <KLineEdit>
@@ -40,18 +39,11 @@
#include <QToolButton>
#include <QVBoxLayout>
-#include <config-nepomuk.h>
-#ifdef HAVE_NEPOMUK
- #include <Nepomuk2/Query/AndTerm>
- #include <Nepomuk2/Query/FileQuery>
- #include <Nepomuk2/Query/LiteralTerm>
- #include <Nepomuk2/Query/OrTerm>
- #include <Nepomuk2/Query/Query>
- #include <Nepomuk2/Query/QueryParser>
- #include <Nepomuk2/Query/ResourceTypeTerm>
- #include <Nepomuk2/Query/ComparisonTerm>
- #include <Nepomuk2/ResourceManager>
- #include <Nepomuk2/Vocabulary/NFO>
+#include <config-baloo.h>
+#ifdef HAVE_BALOO
+ #include <baloo/query.h>
+ #include <baloo/term.h>
+ #include <baloo/indexerconfig.h>
#endif
DolphinSearchBox::DolphinSearchBox(QWidget* parent) :
@@ -115,8 +107,8 @@ void DolphinSearchBox::setSearchPath(const KUrl& url)
m_fromHereButton->setVisible(showSearchFromButtons);
m_everywhereButton->setVisible(showSearchFromButtons);
- const DolphinSearchInformation& searchInfo = DolphinSearchInformation::instance();
- const bool hasFacetsSupport = searchInfo.isIndexingEnabled() && searchInfo.isPathIndexed(m_searchPath);
+ const Baloo::IndexerConfig searchInfo;
+ const bool hasFacetsSupport = searchInfo.fileIndexingEnabled() && searchInfo.shouldBeIndexed(m_searchPath.toLocalFile());
m_facetsWidget->setEnabled(hasFacetsSupport);
}
@@ -128,9 +120,9 @@ KUrl DolphinSearchBox::searchPath() const
KUrl DolphinSearchBox::urlForSearching() const
{
KUrl url;
- const DolphinSearchInformation& searchInfo = DolphinSearchInformation::instance();
- if (searchInfo.isIndexingEnabled() && searchInfo.isPathIndexed(m_searchPath)) {
- url = nepomukUrlForSearching();
+ const Baloo::IndexerConfig searchInfo;
+ if (searchInfo.fileIndexingEnabled() && searchInfo.shouldBeIndexed(m_searchPath.toLocalFile())) {
+ url = balooUrlForSearching();
} else {
url.setProtocol("filenamesearch");
url.addQueryItem("search", m_searchInput->text());
@@ -430,52 +422,34 @@ void DolphinSearchBox::init()
applyReadOnlyState();
}
-KUrl DolphinSearchBox::nepomukUrlForSearching() const
+KUrl DolphinSearchBox::balooUrlForSearching() const
{
-#ifdef HAVE_NEPOMUK
- // Create the term for the text from the input-field
- // dependent on whether a searching for content or
- // filename is done
+#ifdef HAVE_BALOO
const QString text = m_searchInput->text();
- Nepomuk2::Query::Term searchLabelTerm;
- if (m_contentButton->isChecked()) {
- // Let Nepomuk parse the query
- searchLabelTerm = Nepomuk2::Query::QueryParser::parseQuery(text, Nepomuk2::Query::QueryParser::DetectFilenamePattern).term();
- } else {
- // Search the text in the filename only
- QString regex = QRegExp::escape(text);
- regex.replace("\\*", QLatin1String(".*"));
- regex.replace("\\?", QLatin1String("."));
- regex.replace("\\", "\\\\");
- searchLabelTerm = Nepomuk2::Query::ComparisonTerm(
- Nepomuk2::Vocabulary::NFO::fileName(),
- Nepomuk2::Query::LiteralTerm(regex),
- Nepomuk2::Query::ComparisonTerm::Regexp);
- }
- // Get the term from the facets and merge it with the
- // created term from the input-field.
- Nepomuk2::Query::Term facetsTerm = m_facetsWidget->facetsTerm();
+ Baloo::Query query;
+ query.addType("File");
+ query.addTypes(m_facetsWidget->facetTypes());
+
+ Baloo::Term term(Baloo::Term::And);
- Nepomuk2::Query::FileQuery fileQuery;
- fileQuery.setFileMode(Nepomuk2::Query::FileQuery::QueryFilesAndFolders);
- if (facetsTerm.isValid()) {
- Nepomuk2::Query::AndTerm andTerm;
- andTerm.addSubTerm(searchLabelTerm);
- andTerm.addSubTerm(facetsTerm);
- fileQuery.setTerm(andTerm);
+ Baloo::Term ratingTerm = m_facetsWidget->ratingTerm();
+ if (ratingTerm.isValid()) {
+ term.addSubTerm(ratingTerm);
+ }
+
+ if (m_contentButton->isChecked()) {
+ query.setSearchString(text);
} else {
- fileQuery.setTerm(searchLabelTerm);
+ term.addSubTerm(Baloo::Term("filename", text));
}
if (m_fromHereButton->isChecked()) {
- const bool recursive = true;
- fileQuery.addIncludeFolder(m_searchPath, recursive);
+ query.addCustomOption("includeFolder", m_searchPath.toLocalFile());
}
- return fileQuery.toSearchUrl(i18nc("@title UDS_DISPLAY_NAME for a KIO directory listing. %1 is the query the user entered.",
- "Query Results from '%1'",
- text));
+ 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();
#endif
@@ -483,9 +457,9 @@ KUrl DolphinSearchBox::nepomukUrlForSearching() const
void DolphinSearchBox::applyReadOnlyState()
{
-#ifdef HAVE_NEPOMUK
+#ifdef HAVE_BALOO
if (m_readOnly) {
- m_searchLabel->setText(Nepomuk2::Query::Query::titleFromQueryUrl(m_readOnlyQuery));
+ m_searchLabel->setText(Baloo::Query::titleFromQueryUrl(m_readOnlyQuery));
} else {
#else
{
diff --git a/src/search/dolphinsearchbox.h b/src/search/dolphinsearchbox.h
index e4c14b7cb..6dc09f19e 100644
--- a/src/search/dolphinsearchbox.h
+++ b/src/search/dolphinsearchbox.h
@@ -33,13 +33,13 @@ class QLabel;
class QVBoxLayout;
/**
- * @brief Input box for searching files with or without Nepomuk.
+ * @brief Input box for searching files with or without Baloo.
*
* The widget allows to specify:
* - Where to search: Everywhere or below the current directory
* - What to search: Filenames or content
*
- * If Nepomuk is available and the current folder is indexed, further
+ * If Baloo is available and the current folder is indexed, further
* options are offered.
*/
class DolphinSearchBox : public QWidget {
@@ -151,9 +151,9 @@ private:
void init();
/**
- * @return URL that represents the Nepomuk query for starting the search.
+ * @return URL that represents the Baloo query for starting the search.
*/
- KUrl nepomukUrlForSearching() const;
+ KUrl balooUrlForSearching() const;
void applyReadOnlyState();
diff --git a/src/search/dolphinsearchinformation.cpp b/src/search/dolphinsearchinformation.cpp
deleted file mode 100644
index b723f1ec0..000000000
--- a/src/search/dolphinsearchinformation.cpp
+++ /dev/null
@@ -1,124 +0,0 @@
-/***************************************************************************
- * Copyright (C) 2011 by Peter Penz <[email protected]> *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
- ***************************************************************************/
-
-#include "dolphinsearchinformation.h"
-
-#include <config-nepomuk.h>
-#ifdef HAVE_NEPOMUK
- #include <KConfig>
- #include <KConfigGroup>
- #include <Nepomuk2/ResourceManager>
-#endif
-
-#include <KGlobal>
-#include <KUrl>
-#include <QFileInfo>
-#include <QDir>
-
-struct DolphinSearchInformationSingleton
-{
- DolphinSearchInformation instance;
-};
-K_GLOBAL_STATIC(DolphinSearchInformationSingleton, s_dolphinSearchInformation)
-
-
-DolphinSearchInformation& DolphinSearchInformation::instance()
-{
- return s_dolphinSearchInformation->instance;
-}
-
-DolphinSearchInformation::~DolphinSearchInformation()
-{
-}
-
-bool DolphinSearchInformation::isIndexingEnabled() const
-{
- return m_indexingEnabled;
-}
-
-namespace {
- /// recursively check if a folder is hidden
- bool isDirHidden( QDir& dir ) {
- if (QFileInfo(dir.path()).isHidden()) {
- return true;
- } else if (dir.cdUp()) {
- return isDirHidden(dir);
- } else {
- return false;
- }
- }
-
- bool isDirHidden(const QString& path) {
- QDir dir(path);
- return isDirHidden(dir);
- }
-}
-
-bool DolphinSearchInformation::isPathIndexed(const KUrl& url) const
-{
-#ifdef HAVE_NEPOMUK
- const KConfig strigiConfig("nepomukstrigirc");
- const QStringList indexedFolders = strigiConfig.group("General").readPathEntry("folders", QStringList());
-
- // Nepomuk does not index hidden folders
- if (isDirHidden(url.toLocalFile())) {
- return false;
- }
-
- // Check whether the path is part of an indexed folder
- bool isIndexed = false;
- foreach (const QString& indexedFolder, indexedFolders) {
- const KUrl indexedPath(indexedFolder);
- if (indexedPath.isParentOf(url)) {
- isIndexed = true;
- break;
- }
- }
-
- if (isIndexed) {
- // The path is part of an indexed folder. Check whether no
- // excluded folder is part of the path.
- const QStringList excludedFolders = strigiConfig.group("General").readPathEntry("exclude folders", QStringList());
- foreach (const QString& excludedFolder, excludedFolders) {
- const KUrl excludedPath(excludedFolder);
- if (excludedPath.isParentOf(url)) {
- isIndexed = false;
- break;
- }
- }
- }
-
- return isIndexed;
-#else
- Q_UNUSED(url);
- return false;
-#endif
-}
-
-DolphinSearchInformation::DolphinSearchInformation() :
- m_indexingEnabled(false)
-{
-#ifdef HAVE_NEPOMUK
- if (Nepomuk2::ResourceManager::instance()->initialized()) {
- KConfig config("nepomukserverrc");
- m_indexingEnabled = config.group("Service-nepomukfileindexer").readEntry("autostart", true);
- }
-#endif
-}
-
diff --git a/src/search/dolphinsearchinformation.h b/src/search/dolphinsearchinformation.h
deleted file mode 100644
index 6fb1947ca..000000000
--- a/src/search/dolphinsearchinformation.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/***************************************************************************
- * Copyright (C) 2011 by Peter Penz <[email protected]> *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the *
- * Free Software Foundation, Inc., *
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
- ***************************************************************************/
-
-#ifndef DOLPHINSEARCHINFORMATION_H
-#define DOLPHINSEARCHINFORMATION_H
-
-class KUrl;
-
-/**
- * @brief Allows to access search-engine related information.
- */
-class DolphinSearchInformation
-{
-public:
- static DolphinSearchInformation& instance();
- virtual ~DolphinSearchInformation();
-
- /**
- * @return True if the Nepomuk indexer is enabled. If Nepomuk is
- * disabled, always false is returned.
- */
- bool isIndexingEnabled() const;
-
- /**
- * @return True if the complete directory tree specified by path
- * is indexed by the Nepomuk indexer. If Nepomuk is disabled,
- * always false is returned.
- */
- bool isPathIndexed(const KUrl& url) const;
-
-protected:
- DolphinSearchInformation();
-
-private:
- bool m_indexingEnabled;
-
- friend class DolphinSearchInformationSingleton;
-};
-
-#endif
-