#include "dolphin_searchsettings.h"
#include "dolphinfacetswidget.h"
-#include "dolphinsearchinformation.h"
#include <KIcon>
#include <KLineEdit>
#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) :
QWidget(parent),
m_startedSearching(false),
m_readOnly(false),
+ m_active(true),
m_topLayout(0),
m_searchLabel(0),
m_searchInput(0),
m_fromHereButton->setVisible(showSearchFromButtons);
m_everywhereButton->setVisible(showSearchFromButtons);
- const DolphinSearchInformation& searchInfo = DolphinSearchInformation::instance();
- const bool hasFacetsSupport = searchInfo.isIndexingEnabled() && searchInfo.isPathIndexed(m_searchPath);
+ bool hasFacetsSupport = false;
+#ifdef HAVE_BALOO
+ const Baloo::IndexerConfig searchInfo;
+ hasFacetsSupport = searchInfo.fileIndexingEnabled() && searchInfo.shouldBeIndexed(m_searchPath.toLocalFile());
+#endif
m_facetsWidget->setEnabled(hasFacetsSupport);
}
KUrl DolphinSearchBox::urlForSearching() const
{
KUrl url;
- const DolphinSearchInformation& searchInfo = DolphinSearchInformation::instance();
- if (searchInfo.isIndexingEnabled() && searchInfo.isPathIndexed(m_searchPath)) {
- url = nepomukUrlForSearching();
+ bool useBalooSearch = false;
+#ifdef HAVE_BALOO
+ const Baloo::IndexerConfig searchInfo;
+ useBalooSearch = searchInfo.fileIndexingEnabled() && searchInfo.shouldBeIndexed(m_searchPath.toLocalFile());
+#endif
+ if (useBalooSearch) {
+ url = balooUrlForSearching();
} else {
url.setProtocol("filenamesearch");
url.addQueryItem("search", m_searchInput->text());
return m_readOnly;
}
+void DolphinSearchBox::setActive(bool active)
+{
+ if (active != m_active) {
+ m_active = active;
+
+ if (active) {
+ emit activated();
+ }
+ }
+}
+
+bool DolphinSearchBox::isActive() const
+{
+ return m_active;
+}
+
bool DolphinSearchBox::event(QEvent* event)
{
if (event->type() == QEvent::Polish) {
}
}
+bool DolphinSearchBox::eventFilter(QObject* obj, QEvent* event)
+{
+ switch (event->type()) {
+ case QEvent::FocusIn:
+ setActive(true);
+ setFocus();
+ break;
+
+ default:
+ break;
+ }
+
+ return QObject::eventFilter(obj, event);
+}
+
void DolphinSearchBox::emitSearchRequest()
{
m_startSearchTimer->stop();
void DolphinSearchBox::initButton(QToolButton* button)
{
+ button->installEventFilter(this);
button->setAutoExclusive(true);
button->setAutoRaise(true);
button->setCheckable(true);
// Create search box
m_searchInput = new KLineEdit(this);
+ m_searchInput->installEventFilter(this);
m_searchInput->setClearButtonShown(true);
m_searchInput->setFont(KGlobalSettings::generalFont());
setFocusProxy(m_searchInput);
connect(m_facetsToggleButton, SIGNAL(clicked()), this, SLOT(slotFacetsButtonToggled()));
m_facetsWidget = new DolphinFacetsWidget(this);
+ m_facetsWidget->installEventFilter(this);
m_facetsWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
connect(m_facetsWidget, SIGNAL(facetChanged()), this, SLOT(slotFacetChanged()));
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);
+
+ Baloo::Query query;
+ query.addType("File");
+ query.addTypes(m_facetsWidget->facetTypes());
+
+ Baloo::Term term(Baloo::Term::And);
+
+ Baloo::Term ratingTerm = m_facetsWidget->ratingTerm();
+ if (ratingTerm.isValid()) {
+ term.addSubTerm(ratingTerm);
}
- // Get the term from the facets and merge it with the
- // created term from the input-field.
- Nepomuk2::Query::Term facetsTerm = m_facetsWidget->facetsTerm();
-
- 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);
+ if (m_contentButton->isChecked()) {
+ query.setSearchString(text);
} else {
- fileQuery.setTerm(searchLabelTerm);
+ term.addSubTerm(Baloo::Term(QLatin1String("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));
+ query.setTerm(term);
+
+ 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
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
{